|
|
@@ -0,0 +1,722 @@
|
|
|
+package com.xzjmyk.pm.activity.ui.erp.util.attendance;
|
|
|
+
|
|
|
+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;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baidu.mapapi.model.LatLng;
|
|
|
+import com.baidu.mapapi.search.route.DrivingRouteLine;
|
|
|
+import com.baidu.mapapi.search.route.DrivingRouteResult;
|
|
|
+import com.xzjmyk.pm.activity.AppConfig;
|
|
|
+import com.xzjmyk.pm.activity.BdLocationHelper;
|
|
|
+import com.xzjmyk.pm.activity.MyApplication;
|
|
|
+import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.db.dao.MissionDao;
|
|
|
+import com.xzjmyk.pm.activity.db.dao.WorkModelDao;
|
|
|
+import com.xzjmyk.pm.activity.ui.MainActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.activity.oa.MissionActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.activity.oa.OutSigninOKActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.activity.oa.WorkActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.model.MissionModel;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.model.WorkModel;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.CommonInterfaceUtil;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.auto.HttpHandler;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.auto.NotificationManage;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.baidu.OnGetDrivingRouteResult;
|
|
|
+import com.xzjmyk.pm.activity.ui.tool.ThreadUtil;
|
|
|
+import com.xzjmyk.pm.activity.util.BaiduMapUtil;
|
|
|
+import com.xzjmyk.pm.activity.util.MacAndIDUtil;
|
|
|
+import com.xzjmyk.pm.activity.util.PreferenceUtils;
|
|
|
+import com.xzjmyk.pm.activity.util.TimeUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static com.xzjmyk.pm.activity.ui.erp.util.CommonUtil.getSharedPreferences;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 负责签到 内外勤
|
|
|
+ * Created by Bitliker on 2016/12/20.
|
|
|
+ */
|
|
|
+public class AutoErpSigninUitl implements HttpHandler.OnResultListener {
|
|
|
+
|
|
|
+ private final int MAC_VAL = 0x11;//判断mac地址
|
|
|
+ private final int SIGNING = 0x12;//内勤签到
|
|
|
+ private final int LOAD_WORKLOG = 0x13;//打卡列表
|
|
|
+ private final int SIGNIN_MISSION = 0x14;//外勤签到
|
|
|
+ private final int HAVE_OUT_PLAN = 0x15;//还有未拜访外勤计划
|
|
|
+
|
|
|
+ private final int WORK_DATA = 0x16;//内勤列表
|
|
|
+ private final int WORK_LOG = 0x17;//下拉列表时候的获取打卡列表
|
|
|
+ private final int LOAD_PLAN = 0x18;
|
|
|
+
|
|
|
+ private NotificationManage notificationManage;
|
|
|
+
|
|
|
+ public AutoErpSigninUitl() {
|
|
|
+ notificationManage = new NotificationManage();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 签到内勤
|
|
|
+ *
|
|
|
+ * @param model 签到班次对象
|
|
|
+ */
|
|
|
+ public void signinWork(WorkModel model) {
|
|
|
+ //1.判读mac地址是否符合 3.签到
|
|
|
+ MacAndIDUtil util = new MacAndIDUtil();
|
|
|
+ String macAddress = util.getMac(MyApplication.getInstance());
|
|
|
+ if (StringUtils.isEmpty(macAddress)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ validatorMac(model, macAddress);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 签到外勤
|
|
|
+ *
|
|
|
+ * @param model 签到对象
|
|
|
+ */
|
|
|
+ public void signinMissio(MissionModel model) {
|
|
|
+ if (model == null) return;
|
|
|
+ Context ct = MyApplication.getInstance();
|
|
|
+ if (!MyApplication.getInstance().isNetworkActive()) {
|
|
|
+ notificationManage.sendNotification(ct, R.string.out_net_signin, OutSigninOKActivity.class);
|
|
|
+ }
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ Map<String, Object> formStore = new HashMap<>();
|
|
|
+ String emconde = CommonUtil.getSharedPreferences(ct, "erp_username");
|
|
|
+ String name = CommonUtil.getSharedPreferences(ct, "erp_emname");
|
|
|
+ if (StringUtils.isEmpty(name))
|
|
|
+ name = MyApplication.getInstance().mLoginUser.getNickName();
|
|
|
+ formStore.put("mo_address", model.getCompanyAddr());//TODO 当前地址
|
|
|
+ formStore.put("mo_mancode", emconde);//人员编号
|
|
|
+ formStore.put("mo_man", name);//人员编号
|
|
|
+ formStore.put("mo_remark", "自动外勤签到");//备注
|
|
|
+ formStore.put("mo_company", model.getCompanyName());//TODO 当前公司
|
|
|
+ param.put("caller", "Mobile_outsign");
|
|
|
+ param.put("mpd_id", model.getId());
|
|
|
+ param.put("formStore", StringUtils.mapToJson(formStore));
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putParcelable("data", model);
|
|
|
+ HttpHandler.getInstance().loadERPByNet(SIGNIN_MISSION, "mobile/addAutoSign.action",
|
|
|
+ param, bundle, this);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void validatorMac(WorkModel model, String macAddress) {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("macAddress", macAddress);
|
|
|
+ param.put("emcode", CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username"));
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putParcelable("data", model);
|
|
|
+ HttpHandler.getInstance().loadERPByNet(MAC_VAL, "mobile/addMobileMac.action",
|
|
|
+ param, bundle, this);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //签到
|
|
|
+ private void signinWork(Bundle bunder, String code) {
|
|
|
+ Context ct = MyApplication.getInstance();
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ Map<String, Object> form = new HashMap<>();
|
|
|
+ form.put("cl_code", code);
|
|
|
+ form.put("cl_phone", MyApplication.getInstance().mLoginUser.getTelephone());
|
|
|
+ form.put("cl_emcode", getSharedPreferences(ct, "erp_username"));
|
|
|
+ String emname = getSharedPreferences(ct, "erp_emname");
|
|
|
+ if (StringUtils.isEmpty(emname)) {
|
|
|
+ emname = MyApplication.getInstance().mLoginUser.getNickName().trim();
|
|
|
+ }
|
|
|
+ form.put("cl_emname", emname);
|
|
|
+ boolean isp = isPlay(form);
|
|
|
+ if (!isp) {
|
|
|
+ return;//不符合打卡
|
|
|
+ }
|
|
|
+ String formStore = StringUtils.mapToJson(form);
|
|
|
+ param.put("caller", "CardLog");
|
|
|
+ param.put("formStore", formStore);
|
|
|
+ param.put("emcode", getSharedPreferences(ct, "erp_username"));
|
|
|
+ HttpHandler.getInstance().loadERPByNet(SIGNING, "mobile/saveCardLog.action",
|
|
|
+ param, bunder, this);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*判断是否符合打卡*/
|
|
|
+ private boolean isPlay(Map<String, Object> form) {
|
|
|
+ try {
|
|
|
+ //判断是否符合打卡
|
|
|
+ BdLocationHelper helper = MyApplication.getInstance().getBdLocationHelper();
|
|
|
+ form.put("cl_address", helper.getAddress());
|
|
|
+ form.put("cl_location", helper.getName());
|
|
|
+ int comDistance = PreferenceUtils.getInt("distance", 0);
|
|
|
+ float distance = BaiduMapUtil.getInstence().getDistance();
|
|
|
+ if (comDistance < distance) {
|
|
|
+ //TODO 规定地址<实际地址 不符合
|
|
|
+ //判断是否有外勤
|
|
|
+ boolean isOutPlan = PreferenceUtils.getBoolean(AppConfig.HAVE_OUT_PLAN, false);
|
|
|
+ if (!isOutPlan) {
|
|
|
+ //TODO 没有自动外勤
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ form.put("cl_distance", distance);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ return false;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取打卡记录
|
|
|
+ private void loadLog(Bundle bunder) throws Exception {
|
|
|
+ String date = TimeUtils.s_long_2_str(System.currentTimeMillis());
|
|
|
+ //获取网络数据
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ String code = getSharedPreferences(MyApplication.getInstance(), "erp_username");
|
|
|
+ param.put("currentMaster", getSharedPreferences(MyApplication.getInstance(), "erp_master"));
|
|
|
+ param.put("page", 1);
|
|
|
+ param.put("pageSize", 1);
|
|
|
+ param.put("condition", "cl_emcode='" + code + "' and to_char(cl_time,'yyyy-MM-dd')='" + date + "'");
|
|
|
+ param.put("caller", "CardLog");
|
|
|
+ param.put("emcode", code);
|
|
|
+ param.put("master", getSharedPreferences(MyApplication.getInstance(), "erp_master"));
|
|
|
+ HttpHandler.getInstance().loadERPByNet(LOAD_WORKLOG, "mobile/oa/workdata.action",
|
|
|
+ param, bunder, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取是否有外勤计划
|
|
|
+ public void loadIsMission(MissionModel model) {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("emcode", CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username"));
|
|
|
+ Bundle bunder = new Bundle();
|
|
|
+ bunder.putParcelable("data", model);
|
|
|
+ HttpHandler.getInstance().loadERPByNet(HAVE_OUT_PLAN, "mobile/yesornoplan.action",
|
|
|
+ param, bunder, this);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*****************
|
|
|
+ * 下拉列表
|
|
|
+ ***********************/
|
|
|
+ /**
|
|
|
+ * 下拉内勤数据
|
|
|
+ */
|
|
|
+ public void loadWorkData() {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("date", TimeUtils.int_long_2_str(System.currentTimeMillis()));
|
|
|
+ param.put("emcode", CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username"));
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ HttpHandler.getInstance().loadERPByNet(WORK_DATA, "mobile/getWorkDate.action", param, bundle, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadLog(ArrayList<WorkModel> models) {
|
|
|
+ String date = TimeUtils.s_long_2_str(System.currentTimeMillis());
|
|
|
+ //获取网络数据
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ String code = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username");
|
|
|
+ param.put("currentMaster", CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_master"));
|
|
|
+ param.put("page", 1);
|
|
|
+ param.put("pageSize", 100);
|
|
|
+ param.put("condition", "cl_emcode='" + code + "' and to_char(cl_time,'yyyy-MM-dd')='" + date + "'");
|
|
|
+ param.put("caller", "CardLog");
|
|
|
+ param.put("emcode", code);
|
|
|
+ param.put("master", CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_master"));
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putParcelableArrayList("models", models);
|
|
|
+ HttpHandler.getInstance().loadERPByNet(WORK_LOG, "mobile/oa/workdata.action", param, bundle, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取外勤计划列表
|
|
|
+ public void loadMissionPlan() {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("emcode",
|
|
|
+ CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username"));
|
|
|
+ HttpHandler.getInstance().loadERPByNet(LOAD_PLAN, "mobile/mobileoutplan.action", param, null, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void result(int what, boolean isJSON, String message, final Bundle bundle) {
|
|
|
+ try {
|
|
|
+ switch (what) {
|
|
|
+ case MAC_VAL://判断mac地址
|
|
|
+ if (isJSON && JSON.parseObject(message).containsKey("success") &&
|
|
|
+ JSON.parseObject(message).getBoolean("success")) {
|
|
|
+ CommonInterfaceUtil util = new CommonInterfaceUtil();
|
|
|
+ util.getCodeByNet("CardLog", new CommonInterfaceUtil.OnResultListener() {
|
|
|
+ @Override
|
|
|
+ public void result(int code, String result) {
|
|
|
+ signinWork(bundle, result);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case SIGNING:
|
|
|
+ loadLog(bundle);
|
|
|
+ break;
|
|
|
+ case LOAD_WORKLOG:
|
|
|
+ if (isJSON && JSON.parseObject(message).containsKey("listdata")) {
|
|
|
+ saveSignin2DB(bundle, JSON.parseObject(message).getJSONArray("listdata"));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case SIGNIN_MISSION:
|
|
|
+ if (isJSON) {
|
|
|
+ if (JSON.parseObject(message).containsKey("success") && JSON.parseObject(message).getBoolean("success")) {
|
|
|
+ //成功 更新数据库
|
|
|
+ if (bundle == null) return;
|
|
|
+ MissionModel mission = bundle.getParcelable("data");
|
|
|
+ if (mission == null) return;
|
|
|
+ updataMissonDB(mission);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case HAVE_OUT_PLAN:
|
|
|
+ if (!isJSON) return;
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ if (!object.containsKey("success") || !object.getBoolean("success")) return;
|
|
|
+ if (object.containsKey("isOffline")) {
|
|
|
+ int isOffline = Integer.valueOf(object.getString("isOffline"));
|
|
|
+ //当判断到外勤计划为有值 1.外勤计划有 2.自动外勤
|
|
|
+ if (bundle != null && bundle.getParcelable("data") != null) {
|
|
|
+ MissionModel model = bundle.getParcelable("data");
|
|
|
+ if (model == null) {
|
|
|
+ log("model==null");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean saveOk = MissionDao.getInstance().updata(model);
|
|
|
+ if (isOffline > 0) {//还有外勤计划
|
|
|
+ if (saveOk)
|
|
|
+ notificationManage.sendNotification(MyApplication.getInstance(),
|
|
|
+ "对" + model.getCompanyName() + "外勤签退成功", MissionActivity.class);
|
|
|
+ } else {//没有外勤计划
|
|
|
+ endMission(model, saveOk);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case WORK_DATA://打卡班次
|
|
|
+ handlerWorkData(isJSON, message);
|
|
|
+ break;
|
|
|
+ case WORK_LOG://
|
|
|
+ ArrayList<WorkModel> models = null;
|
|
|
+ if (bundle != null) models = bundle.getParcelableArrayList("models");
|
|
|
+ handlerWorkLog(isJSON, message, models);
|
|
|
+ break;
|
|
|
+ case LOAD_PLAN:
|
|
|
+ JSONArray array = null;
|
|
|
+ if (isJSON && JSON.parseObject(message).get("data") instanceof JSONArray) {
|
|
|
+ array = JSON.parseObject(message).getJSONArray("data");
|
|
|
+ } else if (JSON.parseObject(message).get("success") instanceof JSONArray) {
|
|
|
+ array = JSON.parseObject(message).getJSONArray("success");
|
|
|
+ }
|
|
|
+ handlerData(array);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (e != null)
|
|
|
+ log("result=" + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void error(int what, int statuCode, String message, Bundle bundle) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 外勤签到签退处理
|
|
|
+ * 1.签退:status==1&&离开范围之内==》mission.setStatus(2) ,先把状态设置位2在传进来签退
|
|
|
+ * 2.签到:在范围之内,status不做任何改变 传进来签到
|
|
|
+ *
|
|
|
+ * @param mission 传进来的对象
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void updataMissonDB(MissionModel mission) throws Exception {
|
|
|
+ //更新数据库
|
|
|
+ if (mission == null) return;//如果数据库没有,一般不会出现这样的情况
|
|
|
+ if (mission.getStatus() == 2) {//进来签退
|
|
|
+ Log.i("gongpengming", "进来签退");
|
|
|
+ mission.setRealLeave(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
+ loadIsMission(mission);
|
|
|
+ } else {//签到
|
|
|
+ Log.i("gongpengming", "签到");
|
|
|
+ mission.setRealTime(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
+ if (mission.getStatus() != 1) {
|
|
|
+ mission.setStatus(1);//说明没有打过卡 TODO 可以通过判断签到时间是否存在来判断是否提示签到
|
|
|
+ boolean saveOk = MissionDao.getInstance().updata(mission);
|
|
|
+ if (saveOk)
|
|
|
+ notificationManage.sendNotification(MyApplication.getInstance(), "外勤签到成功",
|
|
|
+ MissionActivity.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 外勤签退后判断时候还有外勤计划,如果没有,判断是否符合返回公司 返回提示请返回公司签到
|
|
|
+ *
|
|
|
+ * @param model
|
|
|
+ * @param saveOk
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void endMission(final MissionModel model, final boolean saveOk) throws Exception {
|
|
|
+ //TODO 英唐大厦应该改为公司名称
|
|
|
+ BaiduMapUtil.getInstence().getDrivingRoute(MyApplication.getInstance().
|
|
|
+ getBdLocationHelper().getCityName(), MyApplication.getInstance().
|
|
|
+ getBdLocationHelper().getName(), "英唐大厦", new OnGetDrivingRouteResult() {
|
|
|
+ @Override
|
|
|
+ public void onGetDrivingRouteResult(DrivingRouteResult drivingRouteResult) {
|
|
|
+ List<DrivingRouteLine> list = drivingRouteResult.getRouteLines();
|
|
|
+ if (ListUtils.isEmpty(list)) {//获取路线列表为空
|
|
|
+ if (saveOk)
|
|
|
+ notificationManage.sendNotification(MyApplication.getInstance(), "对" + model.getCompanyName() + "外勤签退成功",
|
|
|
+ MissionActivity.class);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int minTime = 0;
|
|
|
+ for (DrivingRouteLine e : list) {//TODO 获取最优最快路线及时间
|
|
|
+ if (minTime == 0 || minTime > e.getDuration()) {
|
|
|
+ minTime = e.getDuration();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log("最短时间为" + minTime);
|
|
|
+ //获取使用时间为。。。。
|
|
|
+ //当前时间
|
|
|
+ List<WorkModel> models = WorkModelDao.getInstance().query(true);
|
|
|
+ if (ListUtils.isEmpty(models)) {
|
|
|
+ log("数据库中的班次为空的");
|
|
|
+ if (saveOk)
|
|
|
+ notificationManage.sendNotification(MyApplication.getInstance(),
|
|
|
+ "对" + model.getCompanyName() + "外勤签退成功", MissionActivity.class);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String lastTime = null;
|
|
|
+ for (WorkModel e : models) {
|
|
|
+ if (StringUtils.isEmpty(e.getOffTime())) continue;
|
|
|
+ if (StringUtils.isEmpty(lastTime) || e.getOffTime().compareTo(lastTime) > 0)
|
|
|
+ lastTime = e.getOffTime();
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(lastTime)) {
|
|
|
+ if (saveOk)
|
|
|
+ notificationManage.sendNotification(MyApplication.getInstance(),
|
|
|
+ "对" + model.getCompanyName() + "外勤签退成功", MissionActivity.class);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int time = getTime(lastTime);
|
|
|
+ log("与下班时间相差" + time);
|
|
|
+ int deTime = PreferenceUtils.getInt(AppConfig.AUTO_MISSION_TIME, 10);
|
|
|
+ if ((minTime + deTime * 60) < time) {
|
|
|
+ notificationManage.sendNotification(MyApplication.getInstance(),
|
|
|
+ "外勤签退成功,您还有时间返回公司,请回公司签到", MainActivity.class);
|
|
|
+ } else {
|
|
|
+ Log.i("gongpengming", "时间不符合");
|
|
|
+ if (saveOk)
|
|
|
+ notificationManage.sendNotification(MyApplication.getInstance(),
|
|
|
+ "外勤签退成功,当天任务已结束", MissionActivity.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存到数据库
|
|
|
+ private void saveSignin2DB(Bundle bundle, JSONArray array) throws Exception {
|
|
|
+ WorkModel model = null;
|
|
|
+ if (bundle != null && bundle.getParcelable("data") != null) {
|
|
|
+ model = bundle.getParcelable("data");
|
|
|
+ } else {
|
|
|
+ List<WorkModel> models = WorkModelDao.getInstance().query(false);
|
|
|
+ if (ListUtils.isEmpty(models)) return;
|
|
|
+ String time = TimeUtils.long2str(System.currentTimeMillis(), "HH:mm");
|
|
|
+ for (WorkModel m : models) {
|
|
|
+ //当前时间位于该班次之间
|
|
|
+ if (m.getWorkStart().compareTo(time) < 0 && m.getOffend().compareTo(time) > 0) {
|
|
|
+ model = m;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //取最后一个
|
|
|
+ JSONObject object = array.getJSONObject(array.size() - 1);
|
|
|
+ String time = object.getString("cl_time");//获取最后一次打卡信息,班次打卡信息
|
|
|
+ time = TimeUtils.clearDay(time);//获取到的
|
|
|
+ if (StringUtils.isEmpty(time) || model == null) return;
|
|
|
+ if (StringUtils.isEmpty(model.getWorkSignin()) && model.getWorkStart().compareTo(time) < 0
|
|
|
+ && model.getWorkTime().compareTo(time) > 0) {
|
|
|
+ model.setWorkSignin(time);
|
|
|
+ long i = WorkModelDao.getInstance().update(model);
|
|
|
+ notificationManage.sendNotification(MyApplication.getInstance(),
|
|
|
+ R.string.auto_signin, WorkActivity.class);
|
|
|
+ } else if (StringUtils.isEmpty(model.getOffSignin()) && model.getOffTime().compareTo(time) < 0
|
|
|
+ && model.getOffend().compareTo(time) > 0) {
|
|
|
+ model.setOffSignin(time);
|
|
|
+ long i = WorkModelDao.getInstance().update(model);
|
|
|
+ notificationManage.sendNotification(MyApplication.getInstance(),
|
|
|
+ R.string.auto_signin, WorkActivity.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void log(String message) {
|
|
|
+ try {
|
|
|
+ if (!AppConfig.DEBUG || StringUtils.isEmpty(message)) return;
|
|
|
+ Log.i("gongpengming", message);
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (e != null)
|
|
|
+ Log.i("gongpengming", "show Exception" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理打卡签到
|
|
|
+ *
|
|
|
+ * @param isJSON
|
|
|
+ * @param message
|
|
|
+ */
|
|
|
+ private void handlerWorkData(boolean isJSON, String message) throws Exception {
|
|
|
+ if (!isJSON) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ boolean comaddressset = object.getBooleanValue("comaddressset");
|
|
|
+ double companyLongitude = 0;
|
|
|
+ double companyLatitude = 0;
|
|
|
+ int companyDistance = 0;
|
|
|
+ if (comaddressset) {
|
|
|
+ companyLongitude = object.getDoubleValue("longitude");
|
|
|
+ companyLatitude = object.getDoubleValue("latitude");
|
|
|
+ companyDistance = object.getIntValue("distance");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ PreferenceUtils.putInt("distance", companyDistance);
|
|
|
+ PreferenceUtils.putFloat("longitude", (float) companyLongitude);
|
|
|
+ PreferenceUtils.putFloat("latitude", (float) companyLatitude);
|
|
|
+ } catch (ClassCastException e) {
|
|
|
+ if (e != null)
|
|
|
+ log("handlerWorkData ClassCastException=" + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (e != null)
|
|
|
+ log("handlerWorkData Exception=" + e.getMessage());
|
|
|
+ }
|
|
|
+ ArrayList<WorkModel> models = new ArrayList<>();
|
|
|
+ if (object.containsKey("wd_degree")) {//有排班
|
|
|
+ if (object.containsKey("Class1")) {
|
|
|
+ handlerByClass(models, object.getJSONObject("Class1"));
|
|
|
+ }
|
|
|
+ if (object.containsKey("Class2")) {
|
|
|
+ handlerByClass(models, object.getJSONObject("Class2"));
|
|
|
+ }
|
|
|
+ if (object.containsKey("Class3")) {
|
|
|
+ handlerByClass(models, object.getJSONObject("Class3"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ListUtils.isEmpty(models)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ loadLog(models);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理班次情况,简化代码 分开函数
|
|
|
+ *
|
|
|
+ * @param models
|
|
|
+ * @param object
|
|
|
+ */
|
|
|
+ private void handlerByClass(ArrayList<WorkModel> models, JSONObject object) {
|
|
|
+ String wd_onbeg = object.getString("wd_onbeg");
|
|
|
+ String wd_onduty = object.getString("wd_onduty");
|
|
|
+ String wd_offduty = object.getString("wd_offduty");
|
|
|
+ String wd_offend = object.getString("wd_offend");
|
|
|
+ if (StringUtils.isEmpty(wd_onbeg)
|
|
|
+ || StringUtils.isEmpty(wd_onduty)
|
|
|
+ || StringUtils.isEmpty(wd_offduty)
|
|
|
+ || StringUtils.isEmpty(wd_offend)) return;
|
|
|
+ WorkModel model = new WorkModel();
|
|
|
+ model.setWorkStart(wd_onbeg);
|
|
|
+ model.setWorkTime(wd_onduty);
|
|
|
+ String rangeTime = null;
|
|
|
+ try {
|
|
|
+ rangeTime = getStartAndEndTime(true, wd_onduty);
|
|
|
+ if (!StringUtils.isEmpty(rangeTime)) {
|
|
|
+ model.setWorkend(rangeTime);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ model.setOffTime(wd_offduty);
|
|
|
+ model.setOffend(wd_offend);
|
|
|
+ try {
|
|
|
+ rangeTime = getStartAndEndTime(false, wd_offduty);
|
|
|
+ if (!StringUtils.isEmpty(rangeTime)) {
|
|
|
+ model.setOffStart(rangeTime);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ models.add(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理打卡签到列表,建议在线程钟使用
|
|
|
+ *
|
|
|
+ * @param isJSON 是否是json数据
|
|
|
+ * @param message 返回信息
|
|
|
+ * @param models 获取班次信息时候的数据
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void handlerWorkLog(boolean isJSON, String message, final ArrayList<WorkModel> models) throws Exception {
|
|
|
+ if (!isJSON || ListUtils.isEmpty(models)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ JSONArray listdata = object.getJSONArray("listdata");
|
|
|
+ if (ListUtils.isEmpty(listdata)) {
|
|
|
+ log("ListUtils.isEmpty(listdata) 数据为空,容错处理");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String timeLog = null;
|
|
|
+ for (int i = 0; i < listdata.size(); i++) {
|
|
|
+ timeLog = getMinTime(listdata.getJSONObject(i).getString("cl_time"));
|
|
|
+ for (int j = 0; j < models.size(); j++) {
|
|
|
+ WorkModel e = models.get(j);
|
|
|
+ if (StringUtils.isEmpty(e.getWorkStart()) || StringUtils.isEmpty(e.getWorkTime()) ||
|
|
|
+ StringUtils.isEmpty(e.getOffend()) || StringUtils.isEmpty(e.getOffTime()))
|
|
|
+ continue;
|
|
|
+ if (e.getWorkStart().compareTo(timeLog) <= 0 && e.getOffend().compareTo(timeLog) >= 0) {
|
|
|
+ //符合该班次
|
|
|
+ if (e.getWorkend().compareTo(timeLog) >= 0) {
|
|
|
+ if (StringUtils.isEmpty(e.getWorkSignin()) || e.getWorkSignin().compareTo(timeLog) >= 0) {
|
|
|
+ models.get(j).setWorkSignin(timeLog);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (e.getOffStart().compareTo(timeLog) <= 0) {
|
|
|
+ if (StringUtils.isEmpty(e.getOffSignin()) || e.getOffSignin().compareTo(timeLog) <= 0) {
|
|
|
+ models.get(j).setOffSignin(timeLog);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //下拉数据后保存到数据库
|
|
|
+ if (!ListUtils.isEmpty(models)) {
|
|
|
+ //当天日期数据
|
|
|
+ ThreadUtil.getInstance().addTask(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ List<WorkModel> saveModels = new ArrayList<>();
|
|
|
+ for (WorkModel e : models)
|
|
|
+ saveModels.add(e);
|
|
|
+ boolean saveOK = WorkModelDao.getInstance().createOrUpdata(saveModels);
|
|
|
+ //TODO 保存成功知会服务
|
|
|
+ if (saveOK) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setAction(AutoErpService.SAVE_WORK_ACTION);
|
|
|
+ MyApplication.getInstance().sendBroadcast(intent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析处理外勤计划列表并保存到数据库
|
|
|
+ *
|
|
|
+ * @param array
|
|
|
+ */
|
|
|
+ private void handlerData(JSONArray array) throws Exception {
|
|
|
+ if (ListUtils.isEmpty(array)) {
|
|
|
+ return; //获取到拜访计划数据
|
|
|
+ } else {
|
|
|
+ JSONObject object = null;
|
|
|
+ MissionModel entity = null;
|
|
|
+ final List<MissionModel> entities = new ArrayList<>();
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ object = array.getJSONObject(i);
|
|
|
+ entity = new MissionModel();
|
|
|
+ entity.setId(object.getInteger("MPD_ID"));
|
|
|
+ entity.setCompanyName(object.getString("MPD_COMPANY"));
|
|
|
+ entity.setCompanyAddr(object.getString("MPD_ADDRESS"));
|
|
|
+ double longitude = object.getDoubleValue("MD_LONGITUDE");
|
|
|
+ double latitude = object.getDoubleValue("MD_LATITUDE");
|
|
|
+ if (longitude > 0 && latitude > 0) {
|
|
|
+ entity.setLatLng(new LatLng(latitude, longitude));
|
|
|
+ }
|
|
|
+ if (object.containsKey("MPD_ARRIVEDATE")) {
|
|
|
+ entity.setVisitTime(object.getString("MPD_ARRIVEDATE"));
|
|
|
+ } else if (object.containsKey("TO_CHAR(MPD_ARRIVEDATE,'YYYY-MM-DDHH24:MI:SS')")) {
|
|
|
+ entity.setVisitTime(object.getString("TO_CHAR(MPD_ARRIVEDATE,'YYYY-MM-DDHH24:MI:SS')"));
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ long mpd_actdate = object.getLongValue("MPD_ACTDATE");
|
|
|
+ long mpd_outdate = object.getLongValue("MPD_OUTDATE");
|
|
|
+ if (mpd_actdate != 0)
|
|
|
+ entity.setRealTime(TimeUtils.f_long_2_str(mpd_actdate));
|
|
|
+ if (mpd_outdate != 0)
|
|
|
+ entity.setRealLeave(TimeUtils.f_long_2_str(mpd_outdate));
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ entity.setStatus(1);
|
|
|
+ entity.setDistance(object.getDoubleValue("MPD_DISTANCE"));
|
|
|
+ entity.setLocation(object.getString("MPD_LOCATION"));
|
|
|
+ entity.setRecorddate(object.getString("MPD_RECORDDATE"));
|
|
|
+ entities.add(entity);
|
|
|
+ }
|
|
|
+ if (!ListUtils.isEmpty(entities)) {
|
|
|
+ //TODO 保存到数据库
|
|
|
+ ThreadUtil.getInstance().addTask(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ boolean saveOk = MissionDao.getInstance().updataOrCreate(entities);
|
|
|
+ if (saveOk) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setAction(AutoErpService.SAVE_MISSION_ACTION);
|
|
|
+ MyApplication.getInstance().sendBroadcast(intent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取截至时间
|
|
|
+ *
|
|
|
+ * @param isWork 是否上班
|
|
|
+ * @param workTime 时间 (上班时间||下班时间)
|
|
|
+ * @return 服务器没有给的时间
|
|
|
+ */
|
|
|
+ private String getStartAndEndTime(boolean isWork, String workTime) throws Exception {
|
|
|
+ long dayTime = TimeUtils.f_str_2_long(TimeUtils.s_long_2_str(System.currentTimeMillis()) + " " + workTime + ":00");//获取当前天的workTime
|
|
|
+ long time = isWork ? dayTime + 90 * 60 * 1000 : dayTime - 90 * 60 * 1000;
|
|
|
+ return TimeUtils.long2str(time, "HH:mm");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getMinTime(String time) {
|
|
|
+ if (StringUtils.isEmpty(time)) {
|
|
|
+ return "";
|
|
|
+ } else {
|
|
|
+ return TimeUtils.long2str(TimeUtils.f_str_2_long(time), "HH:mm");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取当前时间鱼下班时间的差
|
|
|
+ private int getTime(String lastTime) {
|
|
|
+ long time = TimeUtils.f_str_2_long(TimeUtils.s_long_2_str(System.currentTimeMillis())
|
|
|
+ + " " + lastTime + ":00");
|
|
|
+ long time2 = time - System.currentTimeMillis();
|
|
|
+ if (time < 0) return 0;
|
|
|
+ return (int) (time2 / 1000);
|
|
|
+ }
|
|
|
+}
|