DriverTask.java
18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
package com.trash.quartz.task;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.trash.activiti.service.IActTaskService;
import com.trash.business.domain.CompanyCredit;
import com.trash.business.domain.DriverCredit;
import com.trash.business.domain.SupervisionTrack;
import com.trash.business.domain.TruckCredit;
import com.trash.business.mapper.CompanyCreditMapper;
import com.trash.business.service.ICompanyCreditService;
import com.trash.business.service.IDriverCreditService;
import com.trash.business.service.ISupervisionThreestepService;
import com.trash.business.service.ISupervisionTrackService;
import com.trash.business.service.ITruckActivateService;
import com.trash.business.service.ITruckCreditService;
import com.trash.casefile.domain.KafkaCompensation;
import com.trash.casefile.domain.ViolationCaseFile;
import com.trash.casefile.kafka.Consumer;
import com.trash.casefile.mapper.KafkaCompensationMapper;
import com.trash.casefile.mapper.ViolationCaseFileMapper;
import com.trash.casefile.service.IViolationCaseFileService;
import com.trash.common.config.trashConfig;
import com.trash.common.core.redis.RedisCache;
import com.trash.common.utils.LogUtils;
import com.trash.common.utils.RemoteServerUtils;
import com.trash.common.utils.file.FileUploadUtils;
import com.trash.common.utils.spring.SpringUtils;
import com.trash.office.domain.UploadFile;
import com.trash.office.mapper.UploadFileMapper;
import com.trash.workflow.service.IWorkflowService;
/**
* 定时任务调度测试
*
* @author trash
*/
@Component("DriverTask")
public class DriverTask {
String TOKEN;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/** 系统基础配置 */
@Autowired
private trashConfig trashConfig;
@Autowired
private RedisCache redisCache;
public void getUpCase(){
JSONArray array = RemoteServerUtils.getCaseList();
if(array != null && array.size() > 0){
for(Object object:array){
JSONObject json = (JSONObject) object;
try {
ViolationCaseFile caseFile = new ViolationCaseFile(json);
for (Object fileObj : json.getJSONArray("attchList")) {
JSONObject fileJSON = (JSONObject)fileObj;
UploadFile uploadFile = new UploadFile();
uploadFile.setTableName("violation_case_file");
uploadFile.setTableNumber(caseFile.getId().toString());
uploadFile.setFileName(fileJSON.getString("attchFileName"));
uploadFile.setFilePath(fileJSON.getString("attchFilePath"));
SpringUtils.getBean(UploadFileMapper.class).insertUploadFile(uploadFile);
}
SpringUtils.getBean(ViolationCaseFileMapper.class).insertViolationCaseFile(caseFile);
} catch (BeansException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Map<String, String> paramsMap = new HashMap<String, String>();
public void createTrackData() {
File file = new File("./settings.txt");
String params = "2 1 10 2 1 10 2 1 10 2 1 10 2 1 10 2 1 10 2 1 10 2 1 10";
if (!file.exists()) {
try {
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(params.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
try {
FileInputStream fis = new FileInputStream(file);
byte[] bs = new byte[fis.available()];
fis.read(bs);
params = new String(bs);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String[] arr = params.split(" ");
for (int i = 0; i < 8; i++) {
paramsMap.put("type_" + i + "_timeout", arr[i * 3]);
paramsMap.put("type_" + i + "_season", arr[i * 3 + 1]);
paramsMap.put("type_" + i + "_pect", arr[i * 3 + 2]);
}
JSONArray areas = redisCache.getCacheObject("areaList");
Gson g = new Gson();
JSONArray array;
Map<String, String> area = new HashMap<>();
for (Object object : areas) {
JSONObject json = (JSONObject) object;
area.put(json.getString("code"), json.getString("name"));
}
array = redisCache.getCacheObject("truckList");// 车辆
if (array != null && array.size() > 0) {
int type = 4;
List<JSONObject> list = ShuffleData(g, array, type);
for (JSONObject json : list) {
try {
insertData(json.getString("id"), json.getString("licenseplateNo"), type, "行业事务部",
json.getString("areaName"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
array = redisCache.getCacheObject("contractList");// 合同
if (array != null && array.size() > 0) {
int type = 3;
List<JSONObject> list = ShuffleData(g, array, type);
for (JSONObject json : list) {
try {
insertData(json.getString("id"), json.getString("constructionSiteName"), type, "综合管理部",
area.get(json.getString("earthSiteAreaCode")));
} catch (Exception e) {
e.printStackTrace();
}
}
}
array = redisCache.getCacheObject("companyList");// 公司
if (array != null && array.size() > 0) {
int type = 2;
List<JSONObject> list = ShuffleData(g, array, type);
for (JSONObject json : list) {
try {
insertData(json.getString("id"), json.getString("name"), type, "行业事务部",
area.get(json.getString("areaCode")));
} catch (Exception e) {
e.printStackTrace();
}
}
}
array = redisCache.getCacheObject("constructionList");// 工地
if (array != null && array.size() > 0) {
int type = 0;
List<JSONObject> list = ShuffleData(g, array, type);
for (JSONObject json : list) {
try {
insertData(json.getString("id"), json.getString("name"), type, "勘察事务部",
area.get(json.getString("areaCode").split("\\.")[0]));
} catch (Exception e) {
e.printStackTrace();
}
}
}
array = redisCache.getCacheObject("earthSitesList"); // 消纳场
if (array != null && array.size() > 0) {
int type = 1;
List<JSONObject> list = ShuffleData(g, array, type);
for (JSONObject json : list) {
try {
insertData(json.getString("id"), json.getString("name"), type, "消纳事务部",
area.get(json.getString("areaCode")));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public List ShuffleData(Gson g, JSONArray array, int type) {
List<JSONObject> list = g.fromJson(array.toJSONString(), new TypeToken<List<JSONObject>>() {
}.getType());
Collections.shuffle(list);
double pect = Double.parseDouble(paramsMap.get("type_" + type + "_pect")) / 100;
list = list.subList(0, (int) (list.size() * pect));
return list;
}
public void insertData(String id, String name, int type, String dept, String place) {
try {
SupervisionTrack track = new SupervisionTrack();
track.setObjectId(id);
track.setTitle(name);
track.setType(type);
track.setCreateTime(new Date());
track.setCreateBy("长沙市建筑垃圾智慧监管平台");
track.setDept(dept);
track.setPlace(place);
SpringUtils.getBean(ISupervisionTrackService.class).insertSupervisionTrack(track);
} catch (Exception e) {
e.printStackTrace();
}
}
public void checkCredit() {
if (RemoteServerUtils.remote == null) {
RemoteServerUtils.remote = trashConfig.getRemotePath();
}
if (TOKEN == null) {
TOKEN = trashConfig.getToken();
}
LogUtils.getBlock("=================== checkCredit 定时器执行 当前时间: " + simpleDateFormat.format(new Date()));
try {
checkTruckActive();
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
private void checkTruckActive() {
if (TOKEN == null) {
TOKEN = trashConfig.getToken();
}
try {
SpringUtils.getBean(ISupervisionThreestepService.class).checkDataToActiveTruck(TOKEN);
} catch (Exception e) {
// TODO: handle exception
}
}
private void checkDriverCredit() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if (RemoteServerUtils.remote == null) {
RemoteServerUtils.remote = trashConfig.getRemotePath();
}
if (TOKEN == null) {
TOKEN = trashConfig.getToken();
}
JSONArray drivers = RemoteServerUtils.getDriverList(TOKEN);
for (Object object : drivers) {
JSONObject json = (JSONObject) object;
try {
if (sdf.parse(json.getString("endAt")).getTime() < sdf.parse(sdf.format(new Date())).getTime()
|| sdf.parse(json.getString("qualificationCertValidEndAt")).getTime() < sdf
.parse(sdf.format(new Date())).getTime()) {
DriverCredit driver = new DriverCredit();
driver.setIdNumber(json.getString("identityNo"));
driver.setName(json.getString("name"));
driver.setCreateBy("长沙市建筑垃圾智慧监管平台");
driver.setReason("证件过期");
driver.setTime(new Date());
driver.setStatus(0L);
driver.setObjectId(json.getString("id"));
SpringUtils.getBean(IDriverCreditService.class).insertDriverCredit(driver);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void checkTruckCredit() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Map map = new HashMap<>();
map.put("size", 9999);
map.put("valid", 0);
map.put("page", 1);
JSONArray trucks = RemoteServerUtils.getTruckList(map, TOKEN);
List<Map> listParam = new ArrayList<Map>();
if (trucks != null) {
for (Object jsonObject : trucks) {
JSONObject truck = (JSONObject) jsonObject;
try {
if (sdf.parse(truck.getString("transportCertValid")).getTime() < sdf.parse(sdf.format(new Date()))
.getTime()
|| sdf.parse(truck.getString("licenseValid")).getTime() < sdf.parse(sdf.format(new Date()))
.getTime()) {
TruckCredit truckCredit = new TruckCredit();
truckCredit.setTime(new Date());
truckCredit.setCreateBy("长沙市建筑垃圾智慧监管平台");
truckCredit.setReason("道路运输证有效期:" + truck.getString("transportCertValid") + " 行驶证有效期:"
+ truck.getString("licenseValid") + ",证件过期");
truckCredit.setLostCredit(1L);
truckCredit.setObjectId(truck.getString("id"));
truckCredit.setLicensePlate(truck.getString("licenseplateNo"));
truckCredit.setCompanyId(truck.getString("companyName"));
truckCredit.setStatus(0L);
Map param = new HashMap<>();
param.put("id", truck.getString("id"));
param.put("creditStatus", 1);
listParam.add(param);
SpringUtils.getBean(ITruckCreditService.class).insertTruckCredit(truckCredit);
}
} catch (BeansException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (listParam.size() > 0)
RemoteServerUtils.updateTruckList(listParam, TOKEN);
}
}
public void checkCompanyCredit() {
try {
checkTruckCredit();
} catch (Exception e) {
e.printStackTrace();
}
try {
checkDriverCredit(); // 检查驾驶员信用
} catch (Exception e) {
e.printStackTrace();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Map map = new HashMap<>();
map.put("size", 9999);
map.put("page", 1);
JSONArray companys = RemoteServerUtils.getCompanyList(map, TOKEN);
if (companys != null) {
for (Object jsonObject : companys) {
JSONObject company = (JSONObject) jsonObject;
try {
if (sdf.parse(company.getString("registrationValidTime")).getTime() < sdf
.parse(sdf.format(new Date())).getTime()
|| sdf.parse(company.getString("businessLicenseValidTime")).getTime() < sdf
.parse(sdf.format(new Date())).getTime()) {
CompanyCredit companyCredit = new CompanyCredit();
companyCredit.setTime(new Date());
companyCredit.setCreateBy("长沙市建筑垃圾智慧监管平台");
companyCredit.setReason("企业道路运输经营许可证有效期:" + company.getString("businessLicenseValidTime")
+ " 企业营业执照有效期:" + company.getString("registrationValidTime") + ",证件过期");
companyCredit.setLostCredit(1L);
companyCredit.setObjectId(company.getString("id"));
companyCredit.setName(company.getString("name"));
companyCredit.setPlace(company.getString("areaName"));
companyCredit.setStatus(0L);
SpringUtils.getBean(ICompanyCreditService.class).insertCompanyCredit(companyCredit, TOKEN);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
CompanyCredit companyCredit = new CompanyCredit();
companyCredit.setLostCredit(1L);
companyCredit.setStatus(0L);
List<CompanyCredit> companyList = SpringUtils.getBean(CompanyCreditMapper.class)
.selectCompanyCreditList(companyCredit);
for (CompanyCredit c : companyList) {
SpringUtils.getBean(ICompanyCreditService.class).updateRemoteCompanyAndTruck(c, TOKEN);
}
}
public void checkAllTask() {
LogUtils.getBlock("=================== 删除超时报工数据 定时器执行 当前时间: " + simpleDateFormat.format(new Date()));
if (TOKEN == null) {
TOKEN = trashConfig.getToken();
}
try {
SpringUtils.getBean(ISupervisionThreestepService.class).updateTodayData(TOKEN);
} catch (Exception e) {
e.printStackTrace();
}
try {
SpringUtils.getBean(IActTaskService.class).endAllThreesteptask("workflow_threestep");
} catch (Exception e) {
e.printStackTrace();
}
try {
SpringUtils.getBean(IWorkflowService.class).deleteWorkflowByName("workflow_threestep");
} catch (Exception e) {
e.printStackTrace();
}
try {
SpringUtils.getBean(ITruckActivateService.class).endAllTruckUnActive();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* kafka补偿机制,每半小时一次
*
* @throws InterruptedException
*/
public void kafkaCompensation() throws InterruptedException, IOException {
KafkaCompensation kafkaCompensation = new KafkaCompensation();
kafkaCompensation.setStatus(0);
List<KafkaCompensation> kafkaCompensationList = SpringUtils.getBean(KafkaCompensationMapper.class)
.selectKafkaCompensationList(kafkaCompensation);
for (KafkaCompensation k : kafkaCompensationList) {
SpringUtils.getBean(Consumer.class).autoViolationWarning(k.getData(), k.getId().toString());
}
}
/**
* 每分钟更新一次公司列表
*/
public void getCompanyList() {
if (RemoteServerUtils.remote == null) {
RemoteServerUtils.remote = trashConfig.getRemotePath();
}
Map<String, Object> map = new HashMap<>();
map.put("size", 99999);
map.put("page", 1);
JSONArray jsonArray = RemoteServerUtils.getCompanyList(map, trashConfig.getToken());
redisCache.setCacheObject("companyList", jsonArray);
}
public void getContractList() {
if (RemoteServerUtils.remote == null) {
RemoteServerUtils.remote = trashConfig.getRemotePath();
}
Map<String, Object> map = new HashMap<>();
map.put("size", 99999);
map.put("page", 1);
map.put("contractStatus", 1);
map.put("auditStatus", 1);
JSONArray jsonArray = RemoteServerUtils.getContractList(map, trashConfig.getToken());
redisCache.setCacheObject("contractList", jsonArray);
}
/**
* 每分钟更新一次工地列表
*/
public void getConstructionList() {
if (RemoteServerUtils.remote == null) {
RemoteServerUtils.remote = trashConfig.getRemotePath();
}
Map<String, Object> map = new HashMap<>();
map.put("size", 99999);
map.put("page", 1);
JSONArray jsonArray = RemoteServerUtils.getConstructionList(map, trashConfig.getToken());
redisCache.setCacheObject("constructionList", jsonArray);
}
/**
* 每分钟更新一次消纳场列表
*/
public void getEarthSitesList() {
if (RemoteServerUtils.remote == null) {
RemoteServerUtils.remote = trashConfig.getRemotePath();
}
Map<String, Object> map = new HashMap<>();
map.put("size", 99999);
map.put("page", 1);
JSONArray jsonArray = RemoteServerUtils.getEarthSitesList(map, trashConfig.getToken());
redisCache.setCacheObject("earthSitesList", jsonArray);
}
/**
* 每分钟更新一次区域列表
*/
public void getTruckList() {
if (RemoteServerUtils.remote == null) {
RemoteServerUtils.remote = trashConfig.getRemotePath();
}
Map<String, Object> map = new HashMap<>();
map.put("size", 99999);
map.put("valid", 0);
map.put("page", 1);
JSONArray jsonArray = RemoteServerUtils.getTruckList(map, trashConfig.getToken());
redisCache.setCacheObject("truckList", jsonArray);
}
/**
* 每分钟更新一次区域列表
*/
public void getAreaList() {
if (RemoteServerUtils.remote == null) {
RemoteServerUtils.remote = trashConfig.getRemotePath();
}
Map<String, Object> map = new HashMap<>();
map.put("size", 99999);
map.put("page", 1);
JSONArray jsonArray = RemoteServerUtils.getAreas(trashConfig.getToken());
redisCache.setCacheObject("areaList", jsonArray);
}
}