|
|
@@ -1,11 +1,13 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.util.alarm;
|
|
|
|
|
|
+import android.annotation.TargetApi;
|
|
|
import android.app.Service;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
import android.os.AsyncTask;
|
|
|
+import android.os.Build;
|
|
|
import android.os.Handler;
|
|
|
import android.os.IBinder;
|
|
|
import android.os.Message;
|
|
|
@@ -22,6 +24,7 @@ import com.xzjmyk.pm.activity.ui.erp.activity.oa.MissionPlanActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.activity.oa.SigninActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.entity.MissionPlanEntity;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
+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.JsonValidator;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
|
|
|
@@ -34,19 +37,29 @@ import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static com.xzjmyk.pm.activity.ui.erp.util.CommonUtil.getSharedPreferencesBoolean;
|
|
|
+
|
|
|
|
|
|
public class AlarmService extends Service {
|
|
|
+ public static final String UPDATA_MISSION_PLAN = "UPDATA_MISSION_PLAN";//更新外勤计划
|
|
|
+ public static final String UPDATA_MISSION_SET = "UPDATA_MISSION_SET";//更新外勤设置
|
|
|
public static long intervalTime = 1 * 60 * 1000;//轮询时间间隔,初始化1分钟,外勤时候为6分钟
|
|
|
- public static int aralmType = 1;//提醒类型 1.内勤 2.外勤
|
|
|
+
|
|
|
+ public static int aralmType = 1;//提醒类型 1.内勤 2.外勤 0.无内勤,无外勤
|
|
|
+
|
|
|
private AlarmTask alarmTask;
|
|
|
- private AlarmManage iManage;
|
|
|
- private NotificationManage manage;
|
|
|
+ private AlarmManage alarmManage;
|
|
|
+ private NotificationManage notificationManage;
|
|
|
+ private CommonInterfaceUtil commonInterfaceUtil;
|
|
|
|
|
|
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
- if (intent != null) {
|
|
|
+ if (intent == null) return;
|
|
|
+ if (intent.getAction().equals(UPDATA_MISSION_PLAN))//更新外勤计划
|
|
|
loadIsMission();
|
|
|
+ else if (intent.getAction().equals(UPDATA_MISSION_SET)) {//获取外勤设置
|
|
|
+ loadMissionSet();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
@@ -66,6 +79,7 @@ public class AlarmService extends Service {
|
|
|
if (object.containsKey("isOffline")) {
|
|
|
try {
|
|
|
int isOffline = Integer.valueOf(object.getString("isOffline"));
|
|
|
+ //当判断到外勤计划为有值 1.外勤计划有 2.自动外勤
|
|
|
aralmType = isOffline > 0 ? 2 : 1;
|
|
|
if (aralmType == 2) {
|
|
|
intervalTime = 6 * 60000;
|
|
|
@@ -104,25 +118,55 @@ public class AlarmService extends Service {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {//每次启动服务
|
|
|
- IntentFilter filter = new IntentFilter();
|
|
|
- filter.addAction("com.xzjmyk.pm.activity.ui.erp.util.alarm");
|
|
|
- registerReceiver(receiver, filter);
|
|
|
- if (iManage == null) iManage = new AlarmManage();
|
|
|
- if (manage == null) manage = new NotificationManage();
|
|
|
+ initBroadcast();
|
|
|
+ init();
|
|
|
+ return super.onStartCommand(intent, flags, startId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //初始化数据
|
|
|
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
|
+ private void init() {
|
|
|
+ //初始化任务线程
|
|
|
if (alarmTask == null) {
|
|
|
alarmTask = new AlarmTask();
|
|
|
- alarmTask.execute();
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
|
|
+ alarmTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
+ else
|
|
|
+ alarmTask.execute();
|
|
|
} else {
|
|
|
if (alarmTask.isCancelled()) {
|
|
|
alarmTask = new AlarmTask();
|
|
|
- alarmTask.execute();
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
|
|
+ alarmTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
+ else
|
|
|
+ alarmTask.execute();
|
|
|
}
|
|
|
}
|
|
|
- loadIsMission();
|
|
|
- return super.onStartCommand(intent, flags, startId);
|
|
|
+ if (alarmManage == null) alarmManage = new AlarmManage();
|
|
|
+ if (notificationManage == null) notificationManage = new NotificationManage();
|
|
|
+ if (commonInterfaceUtil == null) commonInterfaceUtil = new CommonInterfaceUtil();
|
|
|
+ loadMissionSet();
|
|
|
+ commonInterfaceUtil.getOutSetInfo(new CommonInterfaceUtil.OnResultListener() {
|
|
|
+ @Override
|
|
|
+ public void result(int code, String result) {
|
|
|
+ if (code == 200) {
|
|
|
+ boolean isAuto = CommonUtil.getSharedPreferencesBoolean(MyApplication.getInstance(), AppConfig.AUTO_MISSION, false);
|
|
|
+ if (isAuto)
|
|
|
+ loadIsMission();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //注册广播
|
|
|
+ private void initBroadcast() {
|
|
|
+ IntentFilter filter = new IntentFilter();
|
|
|
+ filter.addAction(UPDATA_MISSION_PLAN);
|
|
|
+ filter.addAction(UPDATA_MISSION_SET);
|
|
|
+ registerReceiver(receiver, filter);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -153,7 +197,7 @@ public class AlarmService extends Service {
|
|
|
if (aralmType == 1) {//内勤签到
|
|
|
Log.i("gongpengming", "内勤签到计算");
|
|
|
//1.自动打卡 2.提醒上班 3.提醒下班
|
|
|
- int i = getiManage().reckonNextAlarm();//获取签到还是提醒,当为-1时候为错误
|
|
|
+ int i = getAlarmManage().reckonNextAlarm();//获取签到还是提醒,当为-1时候为错误
|
|
|
Log.i("gongpengming", "自动打卡i==" + i);
|
|
|
if (i != -1 || i != 0) {
|
|
|
map.clear();
|
|
|
@@ -163,15 +207,15 @@ public class AlarmService extends Service {
|
|
|
} else if (aralmType == 2) {//外勤签到
|
|
|
Log.i("gongpengming", "进来外勤签到计算");
|
|
|
//判断是否自动外勤
|
|
|
- boolean isAuto = CommonUtil.getSharedPreferencesBoolean(MyApplication.getInstance(), AppConfig.AUTO_MISSION, false);
|
|
|
+ boolean isAuto = getSharedPreferencesBoolean(MyApplication.getInstance(), AppConfig.AUTO_MISSION, false);
|
|
|
//判断是否外勤提醒
|
|
|
- boolean isAlarm = CommonUtil.getSharedPreferencesBoolean(MyApplication.getInstance(), AppConfig.ALARM_MISSION, false);
|
|
|
+ boolean isAlarm = getSharedPreferencesBoolean(MyApplication.getInstance(), AppConfig.ALARM_MISSION, false);
|
|
|
List<MissionPlanEntity> plans = MissionDao.getInstance().queryByEnCode();
|
|
|
if (ListUtils.isEmpty(plans)) Log.i("gongpengming", "plans是空");
|
|
|
MissionPlanEntity mission = null;
|
|
|
if (isAuto) {
|
|
|
Log.i("gongpengming", "自动外勤");
|
|
|
- mission = getiManage().reckonMission(plans);
|
|
|
+ mission = getAlarmManage().reckonMission(plans);
|
|
|
if (mission != null) {//如果返回不为空,打卡
|
|
|
Log.i("gongpengming", "符合打卡");
|
|
|
map.clear();
|
|
|
@@ -179,7 +223,7 @@ public class AlarmService extends Service {
|
|
|
map.put("data", mission);
|
|
|
publishProgress(map);
|
|
|
} else if (isAlarm) {//如果为空,且提醒
|
|
|
- mission = getiManage().alarmMission(plans);
|
|
|
+ mission = getAlarmManage().alarmMission(plans);
|
|
|
if (mission != null) {
|
|
|
Log.i("gongpengming", "符合提醒");
|
|
|
map.clear();
|
|
|
@@ -189,7 +233,7 @@ public class AlarmService extends Service {
|
|
|
}
|
|
|
}
|
|
|
} else if (isAlarm) {//且提醒
|
|
|
- mission = getiManage().alarmMission(plans);
|
|
|
+ mission = getAlarmManage().alarmMission(plans);
|
|
|
if (mission != null) {
|
|
|
map.clear();
|
|
|
map.put("type", 5);
|
|
|
@@ -221,10 +265,10 @@ public class AlarmService extends Service {
|
|
|
util.autoSignin();
|
|
|
break;
|
|
|
case 2://上班提醒
|
|
|
- getManage().sendNotification(MyApplication.getInstance(), "上班时间快到了,请及时打卡", SigninActivity.class);
|
|
|
+ getNotificationManage().sendNotification(MyApplication.getInstance(), "上班时间快到了,请及时打卡", SigninActivity.class);
|
|
|
break;
|
|
|
case 3://下班提醒
|
|
|
- getManage().sendNotification(MyApplication.getInstance(), "下班时间已到了,请及时打卡", SigninActivity.class);
|
|
|
+ getNotificationManage().sendNotification(MyApplication.getInstance(), "下班时间已到了,请及时打卡", SigninActivity.class);
|
|
|
break;
|
|
|
case 4://自动外勤
|
|
|
MissionPlanEntity bean = (MissionPlanEntity) map.get("data");
|
|
|
@@ -238,7 +282,7 @@ public class AlarmService extends Service {
|
|
|
boolean isOk = updateDB(bean1.getId(), 3);
|
|
|
if (isOk)
|
|
|
Log.i("gongpengming", "更新完成" + bean1.getCompanyName());
|
|
|
- getManage().sendNotification(MyApplication.getInstance(),
|
|
|
+ getNotificationManage().sendNotification(MyApplication.getInstance(),
|
|
|
"您的外勤" + bean1.getCompanyName() + "已到达时间", MissionPlanActivity.class);
|
|
|
break;
|
|
|
default:
|
|
|
@@ -250,6 +294,10 @@ public class AlarmService extends Service {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //获取外勤设置
|
|
|
+ private void loadMissionSet() {
|
|
|
+ getCommonInterfaceUtil().getOutSetInfo(null);
|
|
|
+ }
|
|
|
|
|
|
//获取是否有外勤计划
|
|
|
private void loadIsMission() {
|
|
|
@@ -308,15 +356,22 @@ public class AlarmService extends Service {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private NotificationManage getManage() {
|
|
|
- if (manage == null)
|
|
|
- manage = new NotificationManage();
|
|
|
- return manage;
|
|
|
+ //防止空值
|
|
|
+ private NotificationManage getNotificationManage() {
|
|
|
+ if (notificationManage == null)
|
|
|
+ notificationManage = new NotificationManage();
|
|
|
+ return notificationManage;
|
|
|
+ }
|
|
|
+
|
|
|
+ private CommonInterfaceUtil getCommonInterfaceUtil() {
|
|
|
+ if (commonInterfaceUtil == null)
|
|
|
+ commonInterfaceUtil = new CommonInterfaceUtil();
|
|
|
+ return commonInterfaceUtil;
|
|
|
}
|
|
|
|
|
|
- public AlarmManage getiManage() {
|
|
|
- if (iManage == null)
|
|
|
- iManage = new AlarmManage();
|
|
|
- return iManage;
|
|
|
+ private AlarmManage getAlarmManage() {
|
|
|
+ if (alarmManage == null)
|
|
|
+ alarmManage = new AlarmManage();
|
|
|
+ return alarmManage;
|
|
|
}
|
|
|
}
|