|
@@ -12,12 +12,9 @@ import com.xhly.corelib.network.RetrofitService
|
12
|
12
|
import com.xhly.corelib.utils.AppUtils
|
13
|
13
|
import com.xhly.corelib.utils.LogShow
|
14
|
14
|
import com.xhly.corelib.utils.SharedPreferencesUtils
|
15
|
|
-import com.xhly.corelib.utils.SystemUtil
|
16
|
15
|
import com.xhly.corelib.utils.toFormat
|
17
|
16
|
import com.xhly.manageapp.ManageApplication
|
18
|
|
-import com.xhly.manageapp.bean.PadLocationConst
|
19
|
17
|
import com.xhly.manageapp.bean.log.LogAppStartBean
|
20
|
|
-import com.xhly.manageapp.bean.log.PadLocationBean
|
21
|
18
|
import com.xhly.manageapp.bean.user.UserBean
|
22
|
19
|
import com.xhly.manageapp.network.log.LogService
|
23
|
20
|
import com.xhly.manageapp.service.websocket.AppSocket
|
|
@@ -26,7 +23,6 @@ import kotlinx.coroutines.CoroutineScope
|
26
|
23
|
import kotlinx.coroutines.MainScope
|
27
|
24
|
import kotlinx.coroutines.cancel
|
28
|
25
|
import kotlinx.coroutines.launch
|
29
|
|
-import org.json.JSONObject
|
30
|
26
|
import java.util.Calendar
|
31
|
27
|
|
32
|
28
|
/**
|
|
@@ -35,73 +31,76 @@ import java.util.Calendar
|
35
|
31
|
class TimingWorker(context: Context, workerParams: WorkerParameters) :
|
36
|
32
|
Worker(context, workerParams) {
|
37
|
33
|
private val loginService by lazy { RetrofitService.create<LoginService>() }
|
38
|
|
- private val logService by lazy { RetrofitService.create<LogService>() }
|
|
34
|
+ private val logService by lazy { RetrofitService.create<LogService>() }
|
39
|
35
|
private val serviceScope = CoroutineScope(MainScope().coroutineContext)
|
40
|
36
|
private val spUtils by lazy {
|
41
|
37
|
SharedPreferencesUtils.getInstance(context)
|
42
|
38
|
}
|
43
|
39
|
|
44
|
|
- companion object{
|
45
|
|
- private var lastTime=0L
|
|
40
|
+ companion object {
|
|
41
|
+ private var lastTime = 0L
|
|
42
|
+
|
|
43
|
+ //上次策略请求时间
|
|
44
|
+ private var StrategyTime = 0L
|
46
|
45
|
}
|
47
|
46
|
|
48
|
47
|
override fun doWork(): Result {
|
49
|
48
|
val result: Result = Result.success()
|
50
|
49
|
serviceScope.launch {
|
51
|
50
|
LogShow("执行定时任务吧")
|
52
|
|
- var userBean:UserBean?=null
|
|
51
|
+ var userBean: UserBean? = null
|
53
|
52
|
try {
|
54
|
53
|
val fromJson = spUtils.getFromJson(Const.USERINFO, UserBean().javaClass)
|
55
|
|
- userBean= fromJson as UserBean?
|
56
|
|
- }catch (e:Exception){
|
|
54
|
+ userBean = fromJson as UserBean?
|
|
55
|
+ } catch (e: Exception) {
|
57
|
56
|
|
58
|
57
|
}
|
59
|
58
|
val appInfo = getAppInfo()
|
60
|
59
|
if (appInfo.size > 0) {
|
61
|
60
|
logService.postLogAppStartAdd(appInfo)
|
62
|
61
|
}
|
63
|
|
-/*
|
64
|
|
- try {
|
65
|
|
- val location = PadLocationConst.currentLocation
|
66
|
|
- val lastLocation = PadLocationConst.lastLocation
|
67
|
|
- if (location.lat!=null&&location.lon!=null&&(lastLocation.lon!=location.lon&&lastLocation.lat!=location.lat)){
|
68
|
|
- lastLocation.lat=location.lat
|
69
|
|
- lastLocation.lon=location.lon
|
70
|
|
- ManageApplication.getDeviceInfo()?.let {
|
71
|
|
- location.sn=it
|
72
|
|
- }
|
73
|
|
- userBean?.let {
|
74
|
|
- location.userid=it.userid
|
75
|
|
- }
|
76
|
|
- logService.postPadLocation(location)
|
77
|
|
- LogShow("真没有位置")
|
78
|
|
- }else{
|
79
|
|
- LogShow("没有位置")
|
80
|
|
- }
|
81
|
|
- }catch (e:Exception){
|
82
|
|
- LogShow("没有位置问题"+e.toString())
|
83
|
|
- }
|
84
|
|
-*/
|
|
62
|
+ /*
|
|
63
|
+ try {
|
|
64
|
+ val location = PadLocationConst.currentLocation
|
|
65
|
+ val lastLocation = PadLocationConst.lastLocation
|
|
66
|
+ if (location.lat!=null&&location.lon!=null&&(lastLocation.lon!=location.lon&&lastLocation.lat!=location.lat)){
|
|
67
|
+ lastLocation.lat=location.lat
|
|
68
|
+ lastLocation.lon=location.lon
|
|
69
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
70
|
+ location.sn=it
|
|
71
|
+ }
|
|
72
|
+ userBean?.let {
|
|
73
|
+ location.userid=it.userid
|
|
74
|
+ }
|
|
75
|
+ logService.postPadLocation(location)
|
|
76
|
+ LogShow("真没有位置")
|
|
77
|
+ }else{
|
|
78
|
+ LogShow("没有位置")
|
|
79
|
+ }
|
|
80
|
+ }catch (e:Exception){
|
|
81
|
+ LogShow("没有位置问题"+e.toString())
|
|
82
|
+ }
|
|
83
|
+ */
|
85
|
84
|
UIEvent(Const.STARTLOCATION).post()
|
86
|
85
|
userBean?.let {
|
87
|
|
- val map=HashMap<String,Any>()
|
88
|
|
- map["sn"]=ManageApplication.getDeviceInfo()?:""
|
|
86
|
+ val map = HashMap<String, Any>()
|
|
87
|
+ map["sn"] = ManageApplication.getDeviceInfo() ?: ""
|
89
|
88
|
val postCheckSn = loginService.postCheckSn(map)
|
90
|
|
- if (postCheckSn.code==0&&postCheckSn.obj){
|
|
89
|
+ if (postCheckSn.code == 0 && postCheckSn.obj) {
|
91
|
90
|
UIEvent(Const.ACCOUNTLOGINOUTSUCESS).post()
|
92
|
91
|
}
|
93
|
92
|
}
|
94
|
93
|
//校验登录
|
95
|
94
|
userBean?.let {
|
96
|
|
- val map=HashMap<String,Any>()
|
97
|
|
- map["userid"]=userBean.userid
|
98
|
|
- map["loginpwd"]=userBean.loginpwd
|
|
95
|
+ val map = HashMap<String, Any>()
|
|
96
|
+ map["userid"] = userBean.userid
|
|
97
|
+ map["loginpwd"] = userBean.loginpwd
|
99
|
98
|
try {
|
100
|
99
|
val postLoginCheck = loginService.postLoginCheck(map)
|
101
|
|
- if (postLoginCheck.code==0&&postLoginCheck.obj.needLogin){
|
|
100
|
+ if (postLoginCheck.code == 0 && postLoginCheck.obj.needLogin) {
|
102
|
101
|
UIEvent(Const.ACCOUNTLOGINOUT).post()
|
103
|
102
|
}
|
104
|
|
- }catch (e:Exception){
|
|
103
|
+ } catch (e: Exception) {
|
105
|
104
|
LogShow("解析异常")
|
106
|
105
|
}
|
107
|
106
|
}
|
|
@@ -111,6 +110,13 @@ class TimingWorker(context: Context, workerParams: WorkerParameters) :
|
111
|
110
|
AppSocket.startSocket(it)
|
112
|
111
|
}
|
113
|
112
|
}
|
|
113
|
+ //超出30分钟则请求策略
|
|
114
|
+ if (StrategyTime == 0L) {
|
|
115
|
+ StrategyTime = System.currentTimeMillis()
|
|
116
|
+ } else if (System.currentTimeMillis() - StrategyTime >= 30 * 60 * 1000) {
|
|
117
|
+ StrategyTime = System.currentTimeMillis()
|
|
118
|
+ UIEvent(Const.CODE2004.toString()).post()
|
|
119
|
+ }
|
114
|
120
|
}
|
115
|
121
|
return result
|
116
|
122
|
}
|
|
@@ -121,11 +127,11 @@ class TimingWorker(context: Context, workerParams: WorkerParameters) :
|
121
|
127
|
val instance = Calendar.getInstance()
|
122
|
128
|
instance.set(Calendar.MILLISECOND, 0)
|
123
|
129
|
val currentTime = instance.timeInMillis
|
124
|
|
- if (lastTime==0L){
|
125
|
|
- lastTime=currentTime
|
126
|
|
- }else{
|
127
|
|
- LogShow("上次时间"+ lastTime.toFormat()+"|||本次时间"+currentTime.toFormat())
|
128
|
|
- lastTime=currentTime
|
|
130
|
+ if (lastTime == 0L) {
|
|
131
|
+ lastTime = currentTime
|
|
132
|
+ } else {
|
|
133
|
+ LogShow("上次时间" + lastTime.toFormat() + "|||本次时间" + currentTime.toFormat())
|
|
134
|
+ lastTime = currentTime
|
129
|
135
|
}
|
130
|
136
|
val timeInMillis = currentTime - 1000 * 60 * 5
|
131
|
137
|
val usageManager =
|