Просмотр исходного кода

修改自动外勤和自动打卡

Bitlikr 9 лет назад
Родитель
Сommit
1ffe420eed

+ 48 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/db/dao/MissionDao.java

@@ -117,6 +117,54 @@ public class MissionDao {
         }
     }
 
+    public boolean updataOrCreate(MissionModel mission) {
+        if (mission == null || StringUtils.isEmpty(mission.getVisitTime()))return false;
+        show("updataOrCreate");
+        SQLiteDatabase db = null;
+        long i = 0;
+        try {
+            String master = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_master");
+            String emcode = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username");
+            if (StringUtils.isEmpty(master) || StringUtils.isEmpty(emcode)) return false;
+            db = helper.getWritableDatabase();
+            ContentValues values = null;
+            show("MissionPlanEntity");
+            //对象为空或是拜访时间没有情况下不插入数据库
+            values = new ContentValues();
+            values.put("id", mission.getId());
+            values.put("master", master);
+            values.put("emcode", emcode);
+            values.put("company", mission.getCompanyName());
+            values.put("companyAddr", mission.getCompanyAddr());
+            if (mission.getLatLng() != null) {
+                values.put("latitude", mission.getLatLng().latitude);
+                values.put("longitude", mission.getLatLng().longitude);
+            }
+            values.put("visittime", mission.getVisitTime());
+            values.put("realvisitTime", mission.getRealTime());
+            values.put("realLeaveTime", mission.getRealLeave());
+            values.put("distance", mission.getDistance());
+            values.put("location", mission.getLocation());
+            values.put("recorddate", mission.getRecorddate());
+            values.put("date", getDateByString(mission.getVisitTime()));//拜访日期
+            i = db.insert(tibleName, "status", values);
+            if (i == -1) {
+                String where = "master=? and emcode=? and id=? ";
+                String[] whereArgs = {master, emcode, String.valueOf(mission.getId())};
+                i = db.update(tibleName, values, where, whereArgs);
+                show("update i=" + i);
+            }
+            show("i====" + i);
+        } catch (android.database.SQLException e) {
+            show("SQLException=" + e.getMessage());
+        } catch (Exception e) {
+            show("Exception=" + e.getMessage());
+        } finally {
+            if (db != null)
+                db.close();
+            return i > 0;
+        }
+    }
 
     public boolean updataOrCreate(List<MissionModel> entities) {
         if (ListUtils.isEmpty(entities)) return false;

+ 22 - 4
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/presenter/MissionPresenter.java

@@ -3,6 +3,7 @@ package com.xzjmyk.pm.activity.ui.erp.presenter;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.util.Log;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -157,6 +158,7 @@ public class MissionPresenter implements IMissionPresenter, HttpHandler.OnResult
         param.put("param", "[" + StringUtils.mapToJson(params) + "]");
         Bundle bundle = new Bundle();
         bundle.putInt("position", position);
+        bundle.putParcelable("data", entity);
         HttpHandler.getInstance().loadERPByNet(SAVE_PLAN, "mobile/addOutPlan.action", param, bundle, this);
         saveOutAddress(entity);
     }
@@ -234,10 +236,26 @@ public class MissionPresenter implements IMissionPresenter, HttpHandler.OnResult
                         handlerData(array);
                         break;
                     case SAVE_PLAN:
-                        //TODO 保存成功后将对象添加到数据库中 并更新任务
-                        Intent intent = new Intent();
-                        intent.setAction(AutoErpService.INIT_MISSION_TASK);
-                        MyApplication.getInstance().sendBroadcast(intent);
+                        if (isJSON && JSON.parseObject(message).getBoolean("success")) {
+                            int mpd_id = JSON.parseObject(message).getIntValue("mpd_id");
+                            MissionModel entity = bundle.getParcelable("data");
+                            Log.i("gongpengming", "SAVE_PLAN");
+                            if (mpd_id != 0 && entity != null) {//保存数据库
+                                entity.setId(mpd_id);
+                                Log.i("gongpengming", "entity != null");
+                                boolean saveOk = MissionDao.getInstance().updataOrCreate(entity);
+                                Log.i("gongpengming", "saveOk=" + saveOk);
+                                if (saveOk) {
+                                    Intent intent = new Intent();
+                                    intent.setAction(AutoErpService.SAVE_MISSION_ACTION);
+                                    MyApplication.getInstance().sendBroadcast(intent);
+                                }
+                            }
+                        }
+//                        //TODO 保存成功后将对象添加到数据库中 并更新任务
+//                        Intent intent = new Intent();
+//                        intent.setAction(AutoErpService.INIT_MISSION_TASK);
+//                        MyApplication.getInstance().sendBroadcast(intent);
                         if (iMission != null) iMission.dimssLoading();
                         int position = bundle.getInt("position", -1);//成功保存第几个目标
                         if (iMission != null) iMission.showToast("保存成功", R.color.load_submit);

+ 3 - 5
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/presenter/WorkPresenter.java

@@ -170,10 +170,6 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
                             if (ListUtils.isEmpty(pois)) return;
                             for (int i = 0; i < pois.size(); i++) {
                                 double dis = BaiduMapUtil.getInstence().distance(compayLng, pois.get(i).location);
-                                log("dis=" + dis);
-                                log("pois.get(i).name=" + pois.get(i).name);
-                                log("pois.get(i).address=" + pois.get(i).address);
-                                log("_________________________________");
                                 if (companyDistance < dis) {
                                     pois.remove(i);
                                     i--;
@@ -547,6 +543,8 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
     @Override
     public void error(int what, int statuCode, String message, Bundle bundle) {
         try {
+            if (iWorkView != null) iWorkView.dimssLoading();
+
             if (StringUtils.isInclude(message, "该设备不是考勤打卡常用设备")) {
                 if (iWorkView != null) iWorkView.showErrorMac();
             } else if (StringUtils.isInclude(message, "设备正处于申请变更绑定阶段")) {
@@ -566,7 +564,7 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
             } else {
                 String mes = StringUtils.getChinese(message);
                 if (!StringUtils.isEmpty(mes) && iWorkView != null)
-                    iWorkView.showToast(R.string.mac_changing, R.color.load_warning);
+                    iWorkView.showToast(mes, R.color.load_warning);
             }
         } catch (Exception e) {
             if (e != null) log("Error Exception =" + e.getMessage());

+ 1 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/util/attendance/AutoErpService.java

@@ -255,6 +255,7 @@ public class AutoErpService extends Service {
                             isMissionRuning = false;
                             break;
                         }
+
                         log("startMissionTask run");
                         List<MissionModel> plans = MissionDao.getInstance().queryByEnCode();
                         log("自动外勤 plans==" + (ListUtils.isEmpty(plans) ? 0 : plans.size()));