|
@@ -1,14 +1,211 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.util;
|
|
package com.xzjmyk.pm.activity.ui.erp.util;
|
|
|
|
|
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.database.SQLException;
|
|
|
|
|
+import android.os.Handler;
|
|
|
|
|
+import android.os.Message;
|
|
|
|
|
+import android.util.Log;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+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.bean.oa.SigninBean;
|
|
|
|
|
+import com.xzjmyk.pm.activity.db.dao.SigninDao;
|
|
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.activity.oa.SigninActivity;
|
|
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.alarm.NotificationManage;
|
|
|
|
|
+import com.xzjmyk.pm.activity.util.BaiduMapUtil;
|
|
|
|
|
+import com.xzjmyk.pm.activity.util.TimeUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+import static com.alibaba.fastjson.JSON.parseObject;
|
|
|
|
|
+import static com.xzjmyk.pm.activity.ui.erp.util.CommonUtil.getSharedPreferences;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 签到工具类
|
|
|
|
|
+ * 自动外勤和自动签到
|
|
|
|
|
+ * 0x11:自动打卡
|
|
|
|
|
+ * 0x12:打卡列表
|
|
|
* Created by Bitliker on 2016/11/25.
|
|
* Created by Bitliker on 2016/11/25.
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
public class SigninUtil {
|
|
public class SigninUtil {
|
|
|
|
|
|
|
|
|
|
+ private NotificationManage notificationManage;
|
|
|
|
|
+ private Context ct;
|
|
|
|
|
+ private String baseUrl;
|
|
|
|
|
+
|
|
|
|
|
+ public SigninUtil() {
|
|
|
|
|
+ notificationManage = new NotificationManage();
|
|
|
|
|
+ ct = MyApplication.getInstance();
|
|
|
|
|
+ baseUrl = CommonUtil.getSharedPreferences(ct, "erp_baseurl");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Handler handler = new Handler() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
|
|
+ String message = msg.getData().getString("result");
|
|
|
|
|
+ JsonValidator validator = new JsonValidator();
|
|
|
|
|
+ boolean isJSON = validator.validate(message);
|
|
|
|
|
+ switch (msg.what) {
|
|
|
|
|
+ case 0x11://打卡
|
|
|
|
|
+ loadLog();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 0x12://获取打卡列表
|
|
|
|
|
+ if (isJSON && parseObject(message).containsKey("listdata")) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ saveSignin2DB(parseObject(message).getJSONArray("listdata"));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ if (AppConfig.DEBUG && e != null)
|
|
|
|
|
+ Log.i("gongpengming", "Exception=" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 0x13:
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 0x14:
|
|
|
|
|
+ break;
|
|
|
|
|
+ case Constants.APP_SOCKETIMEOUTEXCEPTION://请求超时
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//1.外勤签到
|
|
//1.外勤签到
|
|
|
public void missionSignin() {
|
|
public void missionSignin() {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //2.内勤签到
|
|
|
|
|
+ public void autoSignin( ) {
|
|
|
|
|
+ //获取id
|
|
|
|
|
+ CodeUtil.getInstance().getCode(MyApplication.getInstance(), "CardLog", new CodeUtil.OnCodeLinstener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void callBack(String code) {
|
|
|
|
|
+ doSignin(ct, code);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //签到
|
|
|
|
|
+ private void doSignin(Context ct, String code) {
|
|
|
|
|
+ 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(ct, form);
|
|
|
|
|
+ if (!isp) return;//不符合打卡
|
|
|
|
|
+ String formStore = StringUtils.mapToJson(form);
|
|
|
|
|
+ param.put("caller", "CardLog");
|
|
|
|
|
+ param.put("formStore", formStore);
|
|
|
|
|
+ param.put("emcode", getSharedPreferences(ct, "erp_username"));
|
|
|
|
|
+ net(ct, "mobile/saveCardLog.action", param, 0x11);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*判断是否符合打卡*/
|
|
|
|
|
+ private boolean isPlay(Context ct, Map<String, Object> form) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //判断是否符合打卡
|
|
|
|
|
+ BdLocationHelper helper = MyApplication.getInstance().getBdLocationHelper();
|
|
|
|
|
+ form.put("cl_address", helper.getAddress());
|
|
|
|
|
+ form.put("cl_location", helper.getName());
|
|
|
|
|
+ int comDistance = CommonUtil.getSharedPreferencesInt(ct, "distance", 0);
|
|
|
|
|
+ String distance = BaiduMapUtil.getInstence().getDistance();
|
|
|
|
|
+ if (comDistance < Float.valueOf(distance)) {//规定地址<实际地址 不符合
|
|
|
|
|
+ notificationManage.sendNotification(ct, "当前位置距离考勤地点太远,打卡失败", SigninActivity.class);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ form.put("cl_distance", distance);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取打卡记录
|
|
|
|
|
+ private void loadLog() {
|
|
|
|
|
+ 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"));
|
|
|
|
|
+ net(ct, "mobile/oa/workdata.action", param, 0x12);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //保存到数据库
|
|
|
|
|
+ private void saveSignin2DB(JSONArray array) throws Exception {
|
|
|
|
|
+ //取最后一个
|
|
|
|
|
+ JSONObject object = array.getJSONObject(array.size() - 1);
|
|
|
|
|
+ String time = object.getString("cl_time");//获取最后一次打卡信息,班次打卡信息
|
|
|
|
|
+ time = TimeUtils.clearDay(time);//获取到的
|
|
|
|
|
+ if (StringUtils.isEmpty(time)) return;
|
|
|
|
|
+ SigninDao dao = new SigninDao(MyApplication.getInstance());
|
|
|
|
|
+ List<SigninBean> list = dao.queryByEmcode();
|
|
|
|
|
+ if (ListUtils.isEmpty(list)) return;//TODO数据库中获取的班次表为null
|
|
|
|
|
+ for (SigninBean e : list) {
|
|
|
|
|
+ //判断在那个班次
|
|
|
|
|
+ //1.班次没有上班和下班打卡范围
|
|
|
|
|
+ if (StringUtils.isEmpty(e.getStartTime()) || StringUtils.isEmpty(e.getEndTime()) ||
|
|
|
|
|
+ StringUtils.isEmpty(e.getWorkTime()) || StringUtils.isEmpty(e.getOffTime()))
|
|
|
|
|
+ continue;
|
|
|
|
|
+ //2.该打卡时间在上班之前或下班之后
|
|
|
|
|
+ if (time.compareTo(e.getStartTime()) < 0 || time.compareTo(e.getEndTime()) > 0)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ //符合该班次打卡时间
|
|
|
|
|
+ //上班打过卡
|
|
|
|
|
+ if (time.compareTo(e.getWorkTime()) < 0) {
|
|
|
|
|
+ //TODO 符合上班打卡
|
|
|
|
|
+ e.setWorkSignin(time);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (time.compareTo(e.getOffTime()) > 0) {
|
|
|
|
|
+ //TODO 符合下班打卡
|
|
|
|
|
+ e.setOffSignin(time);
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean saveOk = dao.updateByBrean(e);
|
|
|
|
|
+ if (saveOk) {
|
|
|
|
|
+ getManage().sendNotification(MyApplication.getInstance(), R.string.auto_signin, SigninActivity.class);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void net(Context ct, String action, Map<String, Object> param, int what) {
|
|
|
|
|
+ LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
|
|
+ headers.put("Cookie", "JSESSIONID=" + getSharedPreferences(ct, "sessionId"));
|
|
|
|
|
+ if (StringUtils.isEmpty(baseUrl)) {
|
|
|
|
|
+ baseUrl = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_baseurl");
|
|
|
|
|
+ }
|
|
|
|
|
+ String url = baseUrl + action;
|
|
|
|
|
+ com.xzjmyk.pm.activity.ui.erp.net.ViewUtil.httpSendRequest(MyApplication.getInstance(), url, param, handler, headers, what, null, null, "post");
|
|
|
|
|
+ }
|
|
|
|
|
+ private NotificationManage getManage() {
|
|
|
|
|
+ if (notificationManage == null)
|
|
|
|
|
+ notificationManage = new NotificationManage();
|
|
|
|
|
+ return notificationManage;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|