|
|
@@ -6,21 +6,24 @@ 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;
|
|
|
import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
-import android.widget.Button;
|
|
|
+import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.baidu.mapapi.model.LatLng;
|
|
|
import com.baidu.mapapi.search.core.PoiInfo;
|
|
|
+import com.lidroid.xutils.ViewUtils;
|
|
|
+import com.lidroid.xutils.view.annotation.ViewInject;
|
|
|
import com.xzjmyk.pm.activity.MyApplication;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.bean.oa.Signin;
|
|
|
import com.xzjmyk.pm.activity.bean.oa.SigninBean;
|
|
|
+import com.xzjmyk.pm.activity.db.dao.SigninDao;
|
|
|
import com.xzjmyk.pm.activity.ui.base.EasyFragment;
|
|
|
import com.xzjmyk.pm.activity.ui.calendar.cons.DPMode;
|
|
|
import com.xzjmyk.pm.activity.ui.calendar.utils.OnDatePickedListener;
|
|
|
@@ -32,6 +35,7 @@ import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
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;
|
|
|
+import com.xzjmyk.pm.activity.ui.tool.ThreadPool;
|
|
|
import com.xzjmyk.pm.activity.util.BaiduMapUtil;
|
|
|
import com.xzjmyk.pm.activity.util.CalendarUtils;
|
|
|
import com.xzjmyk.pm.activity.util.TimeUtils;
|
|
|
@@ -49,18 +53,45 @@ import java.util.Map;
|
|
|
* Created by gongpm on 2016/7/5.
|
|
|
*/
|
|
|
public class SigninFragment extends EasyFragment {
|
|
|
+ @ViewInject(R.id.location_tv)
|
|
|
+ private TextView location_tv;
|
|
|
+ @ViewInject(R.id.newtime_tv)
|
|
|
+ private TextView newtime_tv;
|
|
|
+ @ViewInject(R.id.time0fwork_tv)
|
|
|
+ private TextView time0fwork_tv;
|
|
|
+ @ViewInject(R.id.signin0fwork_tv)
|
|
|
+ private TextView signin0fwork_tv;
|
|
|
+ @ViewInject(R.id.time0fuwork_tv)
|
|
|
+ private TextView time0fuwork_tv;
|
|
|
+ @ViewInject(R.id.signin0fuwork_tv)
|
|
|
+ private TextView signin0fuwork_tv;
|
|
|
+ @ViewInject(R.id.untime_signin)
|
|
|
+ private TextView untime_signin;
|
|
|
+ @ViewInject(R.id.office_addr)
|
|
|
+ private TextView office_addr;
|
|
|
+ @ViewInject(R.id.unoffice_mm)
|
|
|
+ private TextView unoffice_mm;
|
|
|
+ @ViewInject(R.id.signin_btn)
|
|
|
+ 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 TextView location_tv;
|
|
|
+
|
|
|
private int requcode = 0x11;
|
|
|
private PoiInfo myPoInfo;
|
|
|
private String baseUrl;
|
|
|
private int uHH, uMM, dHH, dMM;//上下班的时分
|
|
|
private int hh, mm;//距离时间
|
|
|
- private final int whatLoad = 0x11;
|
|
|
- private final int whatSignin = 0x12;
|
|
|
- private final int thrad = 0x13;
|
|
|
- private boolean isPlay = false;
|
|
|
+ private boolean isPlay = false;//是否已经签到
|
|
|
private Handler handler = new Handler() {
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
@@ -86,29 +117,38 @@ public class SigninFragment extends EasyFragment {
|
|
|
}
|
|
|
break;
|
|
|
case whatSignin:
|
|
|
- Log.i("gongpengming", "msg.what == whatSignin");
|
|
|
long time = System.currentTimeMillis();
|
|
|
Calendar mCalendar = Calendar.getInstance();
|
|
|
mCalendar.setTimeInMillis(time);
|
|
|
- int mHour = mCalendar.get(Calendar.HOUR);
|
|
|
+ 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;
|
|
|
- if (h < m) {
|
|
|
+ int k = SigninDao.getInstance(ct).getDateStatus(em_code, TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
+ if (k == 0) {
|
|
|
signin0fwork_tv.setText(strTime);
|
|
|
+ ToastUtil.showToast(ct, "上班打卡成功");
|
|
|
} else {
|
|
|
signin0fuwork_tv.setText(strTime);
|
|
|
+ ToastUtil.showToast(ct, "下班打卡成功");
|
|
|
}
|
|
|
- isPlay = true;
|
|
|
- ToastUtil.showToast(ct, "签到成功");
|
|
|
- signinAble(false);
|
|
|
+ Signin bean = new Signin();
|
|
|
+ bean.setCode(em_code);
|
|
|
+ bean.setDate(TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
+ bean.setDtime(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
+ bean.setUtime(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
+ SigninDao.getInstance(ct).updata(bean);
|
|
|
+ signinAble(false);//关闭签到入口
|
|
|
break;
|
|
|
case thrad:
|
|
|
String str = message.getString("result");
|
|
|
if (str == null) return;
|
|
|
untime_signin.setText(str);
|
|
|
break;
|
|
|
+ case NEW_TIME_WHAT:
|
|
|
+ newtime_tv.setText(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
+ break;
|
|
|
case Constants.HTTP_SUCCESS_INIT:
|
|
|
break;
|
|
|
case Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
@@ -116,8 +156,29 @@ public class SigninFragment extends EasyFragment {
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
+ private String em_code;
|
|
|
+ long distanceTime = 60 * 1000 * 20;//允许提前20分钟签到
|
|
|
+
|
|
|
+ private void signinAble() {
|
|
|
+ int k = SigninDao.getInstance(ct).getDateStatus(em_code, TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
+ if (k == 2) {
|
|
|
+ signinAble(false);
|
|
|
+ } else {
|
|
|
+ LatLng lalat = new LatLng(MyApplication.getInstance().getBdLocationHelper().getLatitude(),
|
|
|
+ MyApplication.getInstance().getBdLocationHelper().getLongitude());
|
|
|
+ String str = BaiduMapUtil.getInstence().getDistance(lalat, location);
|
|
|
+ unoffice_mm.setText("距离考勤地点:" + str + "米");
|
|
|
+ if (BaiduMapUtil.getInstence().getDistanceD(lalat, location) < 500) {
|
|
|
+ //TODO 在允许的距离内签到
|
|
|
+ signinAble(true);
|
|
|
+ } else {
|
|
|
+ signinAble(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private void signinAble(boolean b) {
|
|
|
+ isPlay = !b;
|
|
|
signin_btn.setFocusable(b);
|
|
|
signin_btn.setClickable(b);
|
|
|
if (b) {
|
|
|
@@ -127,14 +188,6 @@ public class SigninFragment extends EasyFragment {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private TextView time0fwork_tv;
|
|
|
- private TextView signin0fwork_tv;
|
|
|
- private TextView time0fuwork_tv;
|
|
|
- private TextView signin0fuwork_tv;
|
|
|
- private TextView untime_signin;
|
|
|
- private TextView office_addr;
|
|
|
- private TextView unoffice_mm;
|
|
|
- private Button signin_btn;
|
|
|
|
|
|
@Override
|
|
|
protected int inflateLayoutId() {
|
|
|
@@ -149,7 +202,7 @@ public class SigninFragment extends EasyFragment {
|
|
|
|
|
|
//开启线程计算时间
|
|
|
private void startThrad() {
|
|
|
- new Thread(new Runnable() {
|
|
|
+ ThreadPool.getThreadPool().addTask(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
long time = System.currentTimeMillis();
|
|
|
@@ -158,7 +211,6 @@ public class SigninFragment extends EasyFragment {
|
|
|
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) {//
|
|
|
@@ -172,16 +224,12 @@ public class SigninFragment extends EasyFragment {
|
|
|
} else {//当前时间在上班时间和下班时间之后 当天打卡时间已过
|
|
|
sendHandle(-1, -1);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- }).start();
|
|
|
-
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void endTheTime(int mHour, int mMin, int mSecond) {
|
|
|
try {
|
|
|
- Log.i("gongpengming", "mHour=" + mHour + "@@mMin=" + mMin);
|
|
|
- Log.i("gongpengming", "dHH=" + dHH + "@@dMM=" + dMM);
|
|
|
int m = dMM - mMin;
|
|
|
int h = dHH - mHour;
|
|
|
while (true) {
|
|
|
@@ -248,6 +296,7 @@ public class SigninFragment extends EasyFragment {
|
|
|
@Override
|
|
|
protected void onCreateView(Bundle savedInstanceState, boolean createView) {
|
|
|
setHasOptionsMenu(true);
|
|
|
+ ViewUtils.inject(getmRootView());
|
|
|
long time = System.currentTimeMillis();
|
|
|
ct.getSupportActionBar().setTitle(TimeUtils.day_long_2_str(time) + " " + TimeUtils.getWeek(time));
|
|
|
baseUrl = CommonUtil.getSharedPreferences(ct, "erp_baseurl");
|
|
|
@@ -260,19 +309,31 @@ public class SigninFragment extends EasyFragment {
|
|
|
ct.progressDialog.show();
|
|
|
//获取网络数据
|
|
|
String url = baseUrl + "mobile/getWorkDate.action";
|
|
|
- String em_code = CommonUtil.getSharedPreferences(ct, "erp_username");
|
|
|
+ if (em_code == null)
|
|
|
+ em_code = CommonUtil.getSharedPreferences(ct, "erp_username");
|
|
|
int date = TimeUtils.int_long_2_str(System.currentTimeMillis());
|
|
|
String sessionId = CommonUtil.getSharedPreferences(ct, "sessionId");
|
|
|
final Map<String, Object> param = new HashMap<>();
|
|
|
param.put("emcode", em_code);
|
|
|
param.put("date", date);
|
|
|
param.put("sessionId", sessionId);
|
|
|
- Log.i("gongpengming", url + "?emcode=" + em_code + "&date=" + date + "sessionId=" + sessionId);
|
|
|
LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
ViewUtil.httpSendRequest(ct, url, param, handler, headers, whatLoad, null, null, "post");
|
|
|
}
|
|
|
|
|
|
+ public String getLocation() {
|
|
|
+ String temp = location_tv.getText().toString();
|
|
|
+ String locationStr = "";
|
|
|
+ if (temp.length() > 8) {
|
|
|
+ locationStr = temp.substring(0, 7);
|
|
|
+ }
|
|
|
+ if (temp.length() <= 0) {
|
|
|
+ locationStr = "未捕获位置名称";
|
|
|
+ }
|
|
|
+ return locationStr;
|
|
|
+ }
|
|
|
+
|
|
|
private void doSignin() {
|
|
|
//获取网络数据
|
|
|
String url = baseUrl + "mobile/saveCardLog.action";
|
|
|
@@ -283,7 +344,7 @@ public class SigninFragment extends EasyFragment {
|
|
|
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("test地址");
|
|
|
+ bean.setCl_location(getLocation());
|
|
|
bean.setCl_phone(MyApplication.getInstance().mLoginUser.getTelephone());
|
|
|
String formStore = FlexJsonUtil.toJson(bean);
|
|
|
String caller = "CardLog";
|
|
|
@@ -296,26 +357,48 @@ public class SigninFragment extends EasyFragment {
|
|
|
}
|
|
|
|
|
|
private void initView() {
|
|
|
- //上班和签到时间
|
|
|
- time0fwork_tv = (TextView) findViewById(R.id.time0fwork_tv);
|
|
|
- signin0fwork_tv = (TextView) findViewById(R.id.signin0fwork_tv);
|
|
|
- time0fuwork_tv = (TextView) findViewById(R.id.time0fuwork_tv);
|
|
|
- signin0fuwork_tv = (TextView) findViewById(R.id.signin0fuwork_tv);
|
|
|
+ setListener();
|
|
|
+ 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()));
|
|
|
+ if (bean != null) {
|
|
|
+ if (bean.getSigninNum() >= 1) {
|
|
|
+ //只打一次卡
|
|
|
+ signin0fwork_tv.setText(TimeUtils.long2str(TimeUtils.f_str_2_long(bean.getUtime()), "HH:mm"));
|
|
|
+ }
|
|
|
+ if (bean.getSigninNum() == 2) {
|
|
|
+ signin0fuwork_tv.setText(TimeUtils.long2str(TimeUtils.f_str_2_long(bean.getDtime()), "HH:mm"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断考勤距离
|
|
|
+ LatLng lalat = new LatLng(MyApplication.getInstance().getBdLocationHelper().getLatitude(),
|
|
|
+ MyApplication.getInstance().getBdLocationHelper().getLongitude());
|
|
|
+ String str = BaiduMapUtil.getInstence().getDistance(lalat, location);
|
|
|
+ unoffice_mm.setText("距离考勤地点:" + str + "米");
|
|
|
+ signinAble();
|
|
|
+ }
|
|
|
|
|
|
- untime_signin = (TextView) findViewById(R.id.untime_signin);//距离考勤时间
|
|
|
- office_addr = (TextView) findViewById(R.id.office_addr);//考勤地点
|
|
|
- unoffice_mm = (TextView) findViewById(R.id.unoffice_mm);//区里考勤距离
|
|
|
- signin_btn = (Button) findViewById(R.id.signin_btn);
|
|
|
+ private void setListener() {
|
|
|
+ ThreadPool.getThreadPool().addTask(new Runnable() {//开启线程进入时间显示
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ while (true) {
|
|
|
+ if (isPlay) break;
|
|
|
+ try {
|
|
|
+ handler.sendEmptyMessage(NEW_TIME_WHAT);
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
signin_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
doSignin();
|
|
|
}
|
|
|
});
|
|
|
-// signin_btn.setClickable(false);
|
|
|
-// signin_btn.setFocusable(false);
|
|
|
- location_tv = (TextView) findViewById(R.id.location_tv);
|
|
|
- location_tv.setText(MyApplication.getInstance().getBdLocationHelper().getAddress());
|
|
|
findViewById(R.id.addr_rl).setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
@@ -324,7 +407,6 @@ public class SigninFragment extends EasyFragment {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void showDateDalog() {
|
|
|
//显示日期选择窗口
|
|
|
if (dateDialog == null)
|
|
|
@@ -338,6 +420,7 @@ public class SigninFragment extends EasyFragment {
|
|
|
@Override
|
|
|
public void onDatePicked(String date) {
|
|
|
ct.getSupportActionBar().setTitle(TimeUtils.day_long_2_str(TimeUtils.s_str_2_long(date)) + " " + TimeUtils.getWeek(date));
|
|
|
+ updataUIByDate(TimeUtils.day_long_2_str(TimeUtils.s_str_2_long(date)));
|
|
|
dateDialog.dismiss();
|
|
|
}
|
|
|
});
|
|
|
@@ -347,6 +430,31 @@ public class SigninFragment extends EasyFragment {
|
|
|
dateDialog.getWindow().setGravity(Gravity.CENTER);
|
|
|
}
|
|
|
|
|
|
+ private void updataUIByDate(String date) {
|
|
|
+ //当日期改变时候更新ui
|
|
|
+ if (!date.equals(TimeUtils.day_long_2_str(System.currentTimeMillis())))
|
|
|
+ signinAble(false);//选择时间非当日,不给签到
|
|
|
+ Signin bean = SigninDao.getInstance(ct).query(em_code, TimeUtils.s_long_2_str(System.currentTimeMillis()));
|
|
|
+ if (bean == null) {
|
|
|
+ signin0fwork_tv.setText("--:--");
|
|
|
+ signin0fuwork_tv.setText("--:--");
|
|
|
+ newtime_tv.setText(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (bean.getSigninNum() >= 1) {
|
|
|
+ signin0fwork_tv.setText(TimeUtils.long2str(TimeUtils.f_str_2_long(bean.getUtime()), "HH:mm"));
|
|
|
+ newtime_tv.setText(bean.getUtime());
|
|
|
+ }
|
|
|
+ if (bean.getSigninNum() == 2) {
|
|
|
+ signin0fuwork_tv.setText(TimeUtils.long2str(TimeUtils.f_str_2_long(bean.getDtime()), "HH:mm"));
|
|
|
+ newtime_tv.setText(bean.getDtime());
|
|
|
+ } else {
|
|
|
+ signin0fwork_tv.setText("--:--");
|
|
|
+ signin0fuwork_tv.setText("--:--");
|
|
|
+ newtime_tv.setText(TimeUtils.f_long_2_str(System.currentTimeMillis()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
inflater.inflate(R.menu.menu_oa_signin, menu);
|
|
|
@@ -370,9 +478,11 @@ public class SigninFragment extends EasyFragment {
|
|
|
if (resultCode == LocationMapActivity.REQUCODE) {//地图选择返回
|
|
|
myPoInfo = data.getParcelableExtra(LocationMapActivity.REQUESTNAME);
|
|
|
location_tv.setText(myPoInfo.name);
|
|
|
- LatLng location = new LatLng(MyApplication.getInstance().getBdLocationHelper().getLatitude(), MyApplication.getInstance().getBdLocationHelper().getLongitude());
|
|
|
+ if (location == null)
|
|
|
+ location = new LatLng(X, Y);
|
|
|
String str = BaiduMapUtil.getInstence().getDistance(myPoInfo.location, location);
|
|
|
unoffice_mm.setText("距离考勤地点:" + str + "米");
|
|
|
+ signinAble();
|
|
|
}
|
|
|
}
|
|
|
}
|