|
|
@@ -6,6 +6,7 @@ import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
+import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuInflater;
|
|
|
@@ -32,6 +33,7 @@ import com.xzjmyk.pm.activity.ui.erp.activity.oa.AlarmaActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.activity.oa.LocationMapActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.activity.oa.SigninActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.CodeUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.Constants;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.FlexJsonUtil;
|
|
|
@@ -53,6 +55,15 @@ import java.util.Map;
|
|
|
* Created by gongpm on 2016/7/5.
|
|
|
*/
|
|
|
public class SigninFragment extends EasyFragment {
|
|
|
+ private static final int NEW_TIME_WHAT = 0x10;
|
|
|
+ private static final int whatLoad = 0x11;
|
|
|
+ private static final int whatSignin = 0x12;
|
|
|
+ private static final int thrad = 0x13;
|
|
|
+ private static final int requcode = 0x14;
|
|
|
+ private static final int whatLog = 0x15;
|
|
|
+ private static final double X = 22.540551;
|
|
|
+ private static final double Y = 113.953345;
|
|
|
+
|
|
|
@ViewInject(R.id.location_tv)
|
|
|
private TextView location_tv;
|
|
|
@ViewInject(R.id.newtime_tv)
|
|
|
@@ -75,40 +86,35 @@ public class SigninFragment extends EasyFragment {
|
|
|
private LinearLayout signin_btn;
|
|
|
|
|
|
private LatLng location;
|
|
|
- private static final int NEW_TIME_WHAT = 0x10;
|
|
|
- private final int whatLoad = 0x11;
|
|
|
- private final int whatSignin = 0x12;
|
|
|
- private final int thrad = 0x13;
|
|
|
- private static final double X = 22.540551;
|
|
|
- private static final double Y = 113.953345;
|
|
|
+
|
|
|
private AlertDialog dateDialog;
|
|
|
private SigninActivity ct;
|
|
|
- private int requcode = 0x11;
|
|
|
private PoiInfo myPoInfo;
|
|
|
private String baseUrl;
|
|
|
- private int uHH, uMM, dHH, dMM;//上下班的时分
|
|
|
- private int hh, mm;//距离时间
|
|
|
private boolean isPlay = false;//是否已经签到
|
|
|
private Handler handler = new Handler() {
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
ct.progressDialog.dismiss();
|
|
|
- Bundle message = msg.getData();
|
|
|
+ String message = msg.getData().getString("result");
|
|
|
switch (msg.what) {
|
|
|
+ case whatLog:
|
|
|
+
|
|
|
+ break;
|
|
|
case whatLoad:
|
|
|
try {
|
|
|
//获取到当前时间
|
|
|
- JSONObject object = new JSONObject(message.getString("result"));
|
|
|
+ JSONObject object = new JSONObject(message);
|
|
|
String u = object.isNull("ondutytime") ? "00:00" : object.getString("ondutytime");
|
|
|
String d = object.isNull("offdutytime") ? "00:00" : object.getString("offdutytime");
|
|
|
- uHH = Integer.parseInt(u.split(":")[0]);
|
|
|
- uMM = Integer.parseInt(u.split(":")[1]);
|
|
|
- dHH = Integer.parseInt(d.split(":")[0]);
|
|
|
- dMM = Integer.parseInt(d.split(":")[1]);
|
|
|
+ int uHH = Integer.parseInt(u.split(":")[0]);
|
|
|
+ int uMM = Integer.parseInt(u.split(":")[1]);
|
|
|
+ int dHH = Integer.parseInt(d.split(":")[0]);
|
|
|
+ int dMM = Integer.parseInt(d.split(":")[1]);
|
|
|
time0fwork_tv.setText((uHH < 10 ? "0" : "") + uHH + ":" + (uMM < 10 ? "0" : "") + uMM);
|
|
|
time0fuwork_tv.setText((dHH < 10 ? "0" : "") + dHH + ":" + (dMM < 10 ? "0" : "") + dMM);
|
|
|
//获取到签到时间后开线程计算距离签到时间
|
|
|
- startThrad();
|
|
|
+ startThrad(time0fwork_tv.getText().toString().trim() + ":00", time0fuwork_tv.getText().toString().trim() + ":00");
|
|
|
} catch (JSONException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -119,8 +125,6 @@ public class SigninFragment extends EasyFragment {
|
|
|
mCalendar.setTimeInMillis(time);
|
|
|
int mHour = mCalendar.get(Calendar.HOUR_OF_DAY);
|
|
|
int mMin = mCalendar.get(Calendar.MINUTE);
|
|
|
- int h = Math.abs(mHour - uHH);
|
|
|
- int m = Math.abs(mHour - dHH);
|
|
|
String strTime = (mHour < 10 ? "0" : "") + mHour + ":" + (mMin < 10 ? "0" : "") + mMin;
|
|
|
int k = SigninDao.getInstance(ct).getDateStatus(em_code, TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
if (k == 0) {
|
|
|
@@ -139,9 +143,8 @@ public class SigninFragment extends EasyFragment {
|
|
|
signinAble(false);//关闭签到入口
|
|
|
break;
|
|
|
case thrad:
|
|
|
- String str = message.getString("result");
|
|
|
- if (str == null) return;
|
|
|
- untime_signin.setText(str);
|
|
|
+ if (message == null) return;
|
|
|
+ untime_signin.setText(message);
|
|
|
break;
|
|
|
case NEW_TIME_WHAT:
|
|
|
newtime_tv.setText(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
@@ -155,6 +158,7 @@ public class SigninFragment extends EasyFragment {
|
|
|
};
|
|
|
private String em_code;
|
|
|
long distanceTime = 60 * 1000 * 20;//允许提前20分钟签到
|
|
|
+ private int signinNum;//打卡次数
|
|
|
|
|
|
private void signinAble() {
|
|
|
int k = SigninDao.getInstance(ct).getDateStatus(em_code, TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
@@ -166,7 +170,6 @@ public class SigninFragment extends EasyFragment {
|
|
|
String str = BaiduMapUtil.getInstence().getDistance(lalat, location);
|
|
|
unoffice_mm.setText("距离考勤地点:" + str + "米");
|
|
|
if (BaiduMapUtil.getInstence().getDistanceD(lalat, location) < 500) {
|
|
|
- //TODO 在允许的距离内签到
|
|
|
signinAble(true);
|
|
|
} else {
|
|
|
signinAble(false);
|
|
|
@@ -198,95 +201,60 @@ public class SigninFragment extends EasyFragment {
|
|
|
}
|
|
|
|
|
|
//开启线程计算时间
|
|
|
- private void startThrad() {
|
|
|
+ private void startThrad(final String uTime, final String dTime) {
|
|
|
ThreadPool.getThreadPool().addTask(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- long time = System.currentTimeMillis();
|
|
|
- Calendar mCalendar = Calendar.getInstance();
|
|
|
- mCalendar.setTimeInMillis(time);
|
|
|
- int mHour = mCalendar.get(Calendar.HOUR);
|
|
|
- int mMin = mCalendar.get(Calendar.MINUTE);
|
|
|
- int mSecond = mCalendar.get(Calendar.SECOND);
|
|
|
- if (mHour < uHH) {//当前时间在上班时间之前
|
|
|
- beforeTheTime(mHour, mMin, mSecond);
|
|
|
- } else if (mHour == uHH) {//
|
|
|
- if (mMin < uMM) {//还没到上班考勤时间
|
|
|
- beforeTheTime(mHour, mMin, mSecond);
|
|
|
- } else {//过了上班考勤时间
|
|
|
- endTheTime(mHour, mMin, mSecond);
|
|
|
- }
|
|
|
- } else if (mHour < dHH && mHour > uHH) {//当前时间在上班时间之后在下班时间之前
|
|
|
- endTheTime(mHour, mMin, mSecond);
|
|
|
- } else {//当前时间在上班时间和下班时间之后 当天打卡时间已过
|
|
|
- sendHandle(-1, -1);
|
|
|
+ long distance = -1;
|
|
|
+ if (signinNum == 0) {//没有打过卡,那当前时间和上班时间对比
|
|
|
+ distance = getDistanceTime(uTime);
|
|
|
+ } else {//打了上班卡,拿当前时间和下班时间对比
|
|
|
+ distance = getDistanceTime(dTime);
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
- private void endTheTime(int mHour, int mMin, int mSecond) {
|
|
|
- try {
|
|
|
- int m = dMM - mMin;
|
|
|
- int h = dHH - mHour;
|
|
|
- while (true) {
|
|
|
- if (isPlay) break;
|
|
|
- m--;
|
|
|
- if (m < 0) {
|
|
|
- h--;
|
|
|
- m = 60 + m;
|
|
|
- if (h < 0) {
|
|
|
- sendHandle(00, 00);
|
|
|
- break;//退出
|
|
|
+ long unit;
|
|
|
+ if (distance > 0) {//当前时间超过指定签到时间,要不断加
|
|
|
+ unit = 1000;
|
|
|
+ } else {//当前时间还没到签到时间,要减
|
|
|
+ unit = -1000;
|
|
|
+ }
|
|
|
+ distance = Math.abs(distance);
|
|
|
+ try {
|
|
|
+ while (distance > 0) {
|
|
|
+ distance -= unit;
|
|
|
+ sendHandle(distance);
|
|
|
+ Thread.sleep(1000);
|
|
|
}
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- sendHandle(h, m);
|
|
|
- Thread.sleep(1000 * 60);
|
|
|
}
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mHour 当前时
|
|
|
- * @param mMin 当前分
|
|
|
- * @param mSecond 当前秒
|
|
|
+ * 获取当天的指定时分秒和当前的时间差
|
|
|
+ *
|
|
|
+ * @param time 时分秒 "HH:mm:ss"
|
|
|
+ * @return 相差时间long(指定时间去减当前时间)
|
|
|
*/
|
|
|
- private void beforeTheTime(int mHour, int mMin, int mSecond) {//当前时间在上班时间之前
|
|
|
- try {
|
|
|
- int m = mMin - uMM;
|
|
|
- int h = uHH - mHour;
|
|
|
-
|
|
|
- while (true) {
|
|
|
- if (isPlay) break;
|
|
|
- m--;
|
|
|
- if (m < 0) {
|
|
|
- h--;
|
|
|
- m = 60 + m;
|
|
|
- if (h < 0) {
|
|
|
- sendHandle(00, 00);
|
|
|
- break;//退出
|
|
|
- }
|
|
|
- }
|
|
|
- sendHandle(h, m);
|
|
|
- Thread.sleep(1000 * 60);
|
|
|
- }
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ private long getDistanceTime(String time) {
|
|
|
+ String temp = TimeUtils.s_long_2_str(System.currentTimeMillis()) + " " + time;
|
|
|
+ return TimeUtils.f_str_2_long(temp) - System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
- private void sendHandle(int h, int m) {
|
|
|
+ private void sendHandle(long distance) {
|
|
|
Message message = handler.obtainMessage();
|
|
|
message.what = thrad;
|
|
|
- String time;
|
|
|
- if (h == -1 && m == -1) {
|
|
|
- time = "今天打开时间已经过了";
|
|
|
- } else {
|
|
|
- time = (h < 10 ? "0" : "") + h + ":" + (m < 10 ? "0" : "") + m;
|
|
|
- }
|
|
|
- message.getData().putString("result", time);
|
|
|
+ Log.i("gongpengming", "distance=" + distance);
|
|
|
+ int d = (int) distance / 1000;
|
|
|
+ int h = d / 3600;
|
|
|
+ int m = (d % 3600) / 60;
|
|
|
+ int s = ((d % 3600) % 60);
|
|
|
+ String str = (h < 10 ? "0" : "") + h + ":" + (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s;
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putString("result", str);
|
|
|
+ message.setData(bundle);
|
|
|
handler.sendMessage(message);
|
|
|
}
|
|
|
|
|
|
@@ -299,6 +267,7 @@ public class SigninFragment extends EasyFragment {
|
|
|
baseUrl = CommonUtil.getSharedPreferences(ct, "erp_baseurl");
|
|
|
initView();
|
|
|
loadNetData();
|
|
|
+ loadLog();
|
|
|
}
|
|
|
|
|
|
//获取网络数据
|
|
|
@@ -319,6 +288,27 @@ public class SigninFragment extends EasyFragment {
|
|
|
ViewUtil.httpSendRequest(ct, url, param, handler, headers, whatLoad, null, null, "post");
|
|
|
}
|
|
|
|
|
|
+ private void loadLog() {
|
|
|
+ ct.progressDialog.show();
|
|
|
+ //获取网络数据
|
|
|
+ String url = baseUrl + "mobile/common/list.action";
|
|
|
+ int date = TimeUtils.int_long_2_str(System.currentTimeMillis());
|
|
|
+ String emcode = CommonUtil.getSharedPreferences(ct, "erp_username");
|
|
|
+ String sessionId = CommonUtil.getSharedPreferences(ct, "sessionId");
|
|
|
+ final Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("emcode", emcode);
|
|
|
+ param.put("currentMaster", CommonUtil.getSharedPreferences(ct, "erp_master"));
|
|
|
+ param.put("page", 1);
|
|
|
+ param.put("pageSize", 10);
|
|
|
+ param.put("condition", "1=1");
|
|
|
+ param.put("sessionId", sessionId);
|
|
|
+ param.put("caller", "CardLog");
|
|
|
+ param.put("sessionId", sessionId);
|
|
|
+ LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
+ headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
+ ViewUtil.httpSendRequest(ct, url, param, handler, headers, whatLog, null, null, "get");
|
|
|
+ }
|
|
|
+
|
|
|
public String getLocation() {
|
|
|
String temp = location_tv.getText().toString();
|
|
|
String locationStr = "";
|
|
|
@@ -331,17 +321,18 @@ public class SigninFragment extends EasyFragment {
|
|
|
return locationStr;
|
|
|
}
|
|
|
|
|
|
- private void doSignin() {
|
|
|
+ private void doSignin(String code) {
|
|
|
//获取网络数据
|
|
|
String url = baseUrl + "mobile/saveCardLog.action";
|
|
|
final Map<String, Object> param = new HashMap<>();
|
|
|
SigninBean bean = new SigninBean();
|
|
|
+ bean.setCl_code(code);
|
|
|
bean.setCl_address(office_addr.getText().toString());
|
|
|
bean.setCl_distance(300);
|
|
|
bean.setCl_emcode(CommonUtil.getSharedPreferences(ct, "erp_username"));
|
|
|
- bean.setCl_emname(MyApplication.getInstance().mLoginUser.getNickName());
|
|
|
bean.setCl_time(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
bean.setCl_location(getLocation());
|
|
|
+ bean.setCl_emname(MyApplication.getInstance().mLoginUser.getNickName());
|
|
|
bean.setCl_phone(MyApplication.getInstance().mLoginUser.getTelephone());
|
|
|
String formStore = FlexJsonUtil.toJson(bean);
|
|
|
String caller = "CardLog";
|
|
|
@@ -358,12 +349,14 @@ public class SigninFragment extends EasyFragment {
|
|
|
location_tv.setText(MyApplication.getInstance().getBdLocationHelper().getAddress());
|
|
|
em_code = CommonUtil.getSharedPreferences(ct, "erp_username");
|
|
|
Signin bean = SigninDao.getInstance(ct).query(em_code, TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
+ signinNum = 0;
|
|
|
if (bean != null) {
|
|
|
- if (bean.getSigninNum() >= 1) {
|
|
|
+ signinNum = bean.getSigninNum();
|
|
|
+ if (signinNum >= 1) {
|
|
|
//只打一次卡
|
|
|
signin0fwork_tv.setText(TimeUtils.long2str(TimeUtils.f_str_2_long(bean.getUtime()), "HH:mm"));
|
|
|
}
|
|
|
- if (bean.getSigninNum() == 2) {
|
|
|
+ if (signinNum == 2) {
|
|
|
signin0fuwork_tv.setText(TimeUtils.long2str(TimeUtils.f_str_2_long(bean.getDtime()), "HH:mm"));
|
|
|
}
|
|
|
}
|
|
|
@@ -393,7 +386,13 @@ public class SigninFragment extends EasyFragment {
|
|
|
signin_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
- doSignin();
|
|
|
+ CodeUtil.getInstance().getCode(ct, "CardLog", new CodeUtil.OnCodeLinstener() {
|
|
|
+ @Override
|
|
|
+ public void callBack(String code) {
|
|
|
+ doSignin(code);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
findViewById(R.id.addr_rl).setOnClickListener(new View.OnClickListener() {
|