RefreshController.java
19.9 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
package com.ruoyi.controller;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.common.utils.sign.Base64;
import com.ruoyi.controller.dss.DssFaceController;
import com.ruoyi.domain.driver.NewDriver;
import com.ruoyi.domain.driver.dss.syn.res.dto.FaceRegisterDTO;
import com.ruoyi.domain.dss.app.vo.SignReportGroupByVo;
import com.ruoyi.domain.scheduling.LinggangScheduling;
import com.ruoyi.domain.sign.in.resource.LinggangSignInResource;
import com.ruoyi.domain.sign.in.summary.SignReportDaySummary;
import com.ruoyi.equipment.domain.Equipment;
import com.ruoyi.equipment.service.IEquipmentService;
import com.ruoyi.job.DriverJob;
import com.ruoyi.job.SignReportSummerJob;
import com.ruoyi.service.SignReportServer;
import com.ruoyi.service.driver.NewDriverService;
import com.ruoyi.service.key.location.LinggangKeyWorkLocationService;
import com.ruoyi.service.scheduling.LinggangSchedulingService;
import com.ruoyi.service.sign.in.resource.LinggangSignInResourceService;
import com.ruoyi.service.sign.in.summary.SignReportDaySummaryService;
import com.ruoyi.utils.DateUtil;
import com.ruoyi.utils.HttpClientUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.io.*;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author liujun
* @date 2024年07月30日 14:37
*/
@Slf4j
@RestController
@RequestMapping("/refresh")
public class RefreshController {
@Autowired
private DriverJob driverJob;
@Autowired
private LinggangKeyWorkLocationService keyWorkLocationService;
@Autowired
private NewDriverService newDriverService;
@Autowired
private LinggangSchedulingService linggangSchedulingService;
@Autowired
private DssFaceController dssFaceController;
@Autowired
private IEquipmentService equipmentService;
@Autowired
private SignReportDaySummaryService signReportDaySummaryService;
@Autowired
private SignReportServer signReportServer;
@Autowired
private SignReportSummerJob signReportSummerJob;
@Autowired
private HttpClientUtil httpClientUtil;
@Autowired
private LinggangSignInResourceService signInResourceService;
@GetMapping(value = "/scheduling")
@ApiOperation("scheduling")
// @PreAuthorize("@ss.hasPermi('refresh:scheduling')")
public ResponseResult<Boolean> test() {
Date date = new Date();
for (int i = 0; i < 2; i++) {
driverJob.runScheduling(DateUtils.addDays(date, i).getTime());
}
return ResponseResult.success();
}
@GetMapping(value = "/scheduling/{dateStr}")
@ApiOperation("scheduling")
// @PreAuthorize("@ss.hasPermi('refresh:scheduling')")
public ResponseResult<Boolean> scheduling(@PathVariable String dateStr) throws ParseException {
Date date = DateUtil.YYYY_MM_DD_LINK_HH_MM_SS.parse(dateStr);
driverJob.runScheduling(date.getTime());
return ResponseResult.success();
}
@GetMapping(value = "/key/info/local")
@ApiOperation("/key/info/local")
//@PreAuthorize("@ss.hasPermi('refresh:key:info:local')")
public ResponseResult<Boolean> testKeyInfoLocal(@RequestParam(value = "dateStr", required = false) String dateStr) throws ParseException {
if (StringUtils.isEmpty(dateStr)) {
dateStr = DateUtil.YYYY_MM_DD_LINK.format(new Date());
}
Date date = DateUtil.YYYY_MM_DD_LINK.parse(dateStr);
LinggangScheduling scheduling = new LinggangScheduling();
scheduling.setStartScheduleDate(DateUtil.shortDate(date));
scheduling.setEndScheduleDate(DateUtils.addDays(scheduling.getStartScheduleDate(), 1));
scheduling.setType(100);
List<LinggangScheduling> linggangSchedulings = linggangSchedulingService.list(scheduling);
Set<Long> idSets = linggangSchedulings.stream().map(LinggangScheduling::getId).collect(Collectors.toSet());
keyWorkLocationService.insertJob(dateStr, null, idSets);
log.info("钥匙存放信息处理完毕");
return ResponseResult.success();
}
@GetMapping(value = "/driver")
@ApiOperation("driver")
//@PreAuthorize("@ss.hasPermi('refresh:driver')")
public ResponseResult<Boolean> insertDriver() {
newDriverService.insertJob();
log.info("人员信息同步完毕");
return ResponseResult.success();
}
@PostMapping(value = "/driver/init/image")
@ApiOperation("driver/init/image")
// @PreAuthorize("@ss.hasPermi('refresh:driver:init:image')")
public ResponseResult<Boolean> insertDriverInitImage(@RequestParam("imagePath") String imagePath, @RequestParam("device") String device) {
if (StringUtils.isEmpty(device)) {
return ResponseResult.error("注册设备号不能为空");
}
if (StringUtils.isEmpty(imagePath)) {
String path = StringUtils.join(System.getProperty("user.dir"), File.pathSeparator, "images");
;
log.info("[{}]", path);
imagePath = path;
}
File file = new File(imagePath);
if (!file.exists()) {
return ResponseResult.error("文件路径不存在");
}
if (!file.isDirectory()) {
return ResponseResult.error("文件路径不是文件夹路径");
}
File[] fs = file.listFiles();
int length = ArrayUtils.getLength(fs);
if (0 == length) {
return ResponseResult.error("文件路径下没有文件");
}
Equipment equipment = equipmentService.getOneByDeviceId(device);
if (Objects.isNull(equipment)) {
return ResponseResult.error("设备号不正确,请确认设备信息");
}
for (int i = 0; i < length; i++) {
FaceRegisterDTO dto = new FaceRegisterDTO();
dto.setDevice(device);
String jobCode = StringUtils.trim(StringUtils.substringBeforeLast(fs[i].getName(), "."));
dto.setStaffCode(jobCode);
NewDriver driver = newDriverService.getOne(jobCode);
if (Objects.isNull(driver)) {
log.info("没有人员信息:[{}]", dto);
continue;
}
if (StringUtils.isNotEmpty(driver.getImage())) {
log.info("人脸数据已经存在:[{}]", dto);
continue;
}
dto.setRegTime(DateUtil.shortDate(new Date()));
try {
byte[] bytes = FileUtils.readFileToByteArray(fs[i]);
String imageContent = Base64.encode(bytes);
dto.setFaceValue(imageContent);
} catch (IOException e) {
throw new RuntimeException(e);
}
ResponseResult<Object> responseResult = dssFaceController.faceRegister(dto);
if (Objects.isNull(responseResult) || !responseResult.isSuccess()) {
log.warn("[{}]数据没有执行成功;返回值为:[{}]", dto, responseResult);
}
}
log.info("人员信息同步完毕");
return ResponseResult.success();
}
@PostMapping(value = "/driver/init/image/name")
@ApiOperation("driver/init/image/name")
// @PreAuthorize("@ss.hasPermi('refresh:driver:init:image:name')")
public ResponseResult<Object> insertDriverInitImageOfName(@RequestParam("imagePath") String imagePath, @RequestParam("device") String device) {
if (StringUtils.isEmpty(device)) {
return ResponseResult.error("注册设备号不能为空");
}
if (StringUtils.isEmpty(imagePath)) {
String path = StringUtils.join(System.getProperty("user.dir"), File.pathSeparator, "images");
log.info("[{}]", path);
imagePath = path;
}
File file = new File(imagePath);
if (!file.exists()) {
return ResponseResult.error("文件路径不存在");
}
if (!file.isDirectory()) {
return ResponseResult.error("文件路径不是文件夹路径");
}
File[] fs = file.listFiles();
int length = ArrayUtils.getLength(fs);
if (0 == length) {
return ResponseResult.error("文件路径下没有文件");
}
Equipment equipment = equipmentService.getOneByDeviceId(device);
if (Objects.isNull(equipment)) {
return ResponseResult.error("设备号不正确,请确认设备信息");
}
List<String> errors = new ArrayList<>();
for (int i = 0; i < length; i++) {
FaceRegisterDTO dto = new FaceRegisterDTO();
dto.setDevice(device);
String name = StringUtils.trim(StringUtils.substringBeforeLast(fs[i].getName(), "."));
NewDriver source = new NewDriver();
source.setPersonnelName(name);
List<NewDriver> drivers = newDriverService.list(source);
int size = CollectionUtils.size(drivers);
if (size == 0) {
errors.add(StringUtils.join(file.getName(), "没有找到用户"));
continue;
} else if (size > 1) {
errors.add(StringUtils.join(file.getName(), "找到多个数据:", JSON.toJSONString(drivers)));
continue;
}
NewDriver driver = drivers.get(0);
if (StringUtils.isNotEmpty(driver.getImage())) {
log.info("人脸数据已经存在:[{}]", driver);
continue;
}
dto.setRegTime(DateUtil.shortDate(new Date()));
dto.setStaffCode(driver.getJobCode());
try {
byte[] bytes = FileUtils.readFileToByteArray(fs[i]);
String imageContent = Base64.encode(bytes);
dto.setFaceValue(imageContent);
} catch (IOException e) {
throw new RuntimeException(e);
}
ResponseResult<Object> responseResult = dssFaceController.faceRegister(dto);
if (Objects.isNull(responseResult) || !responseResult.isSuccess()) {
log.warn("[{}]数据没有执行成功;返回值为:[{}]", dto, responseResult);
errors.add(StringUtils.join(file.getName(), "数据没有执行成功:", JSON.toJSONString(driver)));
}
}
if (CollectionUtils.isNotEmpty(errors)) {
return ResponseResult.error(JSON.toJSONString(errors));
}
log.info("人员信息同步完毕");
return ResponseResult.success();
}
@GetMapping(value = "/jar/class/path")
public ResponseResult<String> getJarClassPath() {
String path = StringUtils.join(System.getProperty("user.dir"), "/images");
ResponseResult<String> responseResult = ResponseResult.success();
responseResult.setData(path);
return responseResult;
}
@GetMapping(value = "/sign/report/summary/{startMonth}")
@ApiOperation("/sign/report/summary")
public ResponseResult<String> signReportSummary(@PathVariable("startMonth") String startMonth) throws ParseException {
Date now = DateUtil.shortDate(new Date());
String dateStr = startMonth + "-01";
Date startDate = DateUtil.YYYY_MM_DD_LINK.parse(dateStr);
int index = -1;
boolean flag = false;
while (true) {
index++;
Date startDate1 = DateUtils.addMonths(startDate, index);
dateStr = DateUtil.YYYY_MM_LINK.format(startDate1);
List<SignReportGroupByVo> signReportGroupByVos = signReportServer.querySignReportGroupByDateStrVo(dateStr);
if (CollectionUtils.isNotEmpty(signReportGroupByVos)) {
for (SignReportGroupByVo byVo : signReportGroupByVos) {
Date date = DateUtil.YYYY_MM_DD_LINK.parse(byVo.getDateStr());
if (DateUtils.isSameDay(now, date)) {
flag = true;
break;
} else if (date.getTime() >= now.getTime()) {
flag = true;
break;
}
SignReportDaySummary summary = new SignReportDaySummary();
summary.setDatestr(byVo.getDateStr());
List<SignReportDaySummary> summaries = signReportDaySummaryService.list(summary);
if (CollectionUtils.isNotEmpty(summaries)) {
Set<Integer> ids = summaries.stream().map(SignReportDaySummary::getId).collect(Collectors.toSet());
signReportDaySummaryService.removeByIds(ids);
}
BeanUtils.copyProperties(byVo, summary);
try {
signReportDaySummaryService.save(summary);
} catch (Exception e) {
log.error("保存签到汇总异常:[{}]", dateStr, e);
}
}
}
if (flag) {
break;
}
}
return ResponseResult.success();
}
@GetMapping(value = "/sign/report/summary/day")
@ApiOperation("/sign/report/summary/day")
public ResponseResult<String> signReportSummary1() throws ParseException {
signReportSummerJob.calSignReportSummary();
return ResponseResult.success();
}
@GetMapping("/init/driver/data")
public ResponseResult<Boolean> initDriverData() {
LambdaQueryWrapper<NewDriver> ndWrapper = new LambdaQueryWrapper<>();
ndWrapper.isNotNull(NewDriver::getFaceFeature);
List<NewDriver> drivers = newDriverService.list(ndWrapper);
if (CollectionUtils.isEmpty(drivers)) {
return ResponseResult.success(Boolean.TRUE);
}
String basePath = "C:\\Users\\密码:0000\\Desktop\\fsdownload\\uploadPath\\upload\\image\\";
String basePath1 = "C:\\Users\\密码:0000\\Desktop\\fsdownload\\uploadPath\\upload\\image\\";
String token = getToken();
Map<String, Object> headMap = new HashMap<>();
headMap.put("Content-Type", "application/json");
headMap.put("Authorization", token);
for (NewDriver driver : drivers) {
StringBuilder path = new StringBuilder();
path.append(basePath);
path.append(driver.getImage());
InputStream inputStream = null;
try {
File file = new File(path.toString());
inputStream = new FileInputStream(file);
String content = cn.hutool.core.codec.Base64.encode(inputStream);
Map<String, Object> pms = new HashMap<>();
pms.put("device", "10001");
pms.put("regTime", DateUtil.YYYY_MM_DD_LINK_HH_MM_SS.format(new Date()));
pms.put("staffCode", driver.getJobCode());
pms.put("faceValue", content);
String json = httpClientUtil.doPost("http://10.10.150.173:8102/dss/Face/FaceRegister", pms, headMap);
log.info("[{}],[{}]", json, JSON.toJSONString(pms));
} catch (Exception e) {
log.error("读取图片异常", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
return ResponseResult.success(Boolean.TRUE);
}
@GetMapping("/init/driver/sign/resource/{dateStr}")
public ResponseResult<Boolean> initDriverSignResource(@PathVariable String dateStr) {
LambdaQueryWrapper<LinggangSignInResource> wrapper = new LambdaQueryWrapper<>();
wrapper.ge(LinggangSignInResource::getTime, dateStr);
List<LinggangSignInResource> sources = signInResourceService.list(wrapper);
if (CollectionUtils.isEmpty(sources)) {
return ResponseResult.success(Boolean.TRUE);
}
String token = getToken();
String basePath = "C:\\Users\\密码:0000\\Desktop\\fsdownload\\uploadPath\\upload\\image\\";
for (LinggangSignInResource source : sources) {
if (Objects.equals(source.getResourceType(), 2)) {
uploadSignResource2(source, token, basePath);
} else {
uploadSignResource(source, token, basePath);
}
}
return ResponseResult.success(Boolean.TRUE);
}
private String uploadSignResource(LinggangSignInResource source, String token, String basePath) {
Map<String, Object> headMap = new HashMap<>();
headMap.put("Content-Type", "application/json");
headMap.put("Authorization", token);
Map<String, Object> pms = new HashMap<>();
pms.put("device", "10001");
pms.put("driverCode", "10001");
pms.put("testId", source.getSignId());
pms.put("time", DateUtil.YYYY_MM_DD_LINK_HH_MM_SS.format(source.getTime()));
List<Map<String, Object>> lists = new ArrayList<>();
Map<String, Object> pms1 = new HashMap<>();
pms1.put("index", source.getIndex1());
pms1.put("time", DateUtil.YYYY_MM_DD_LINK_HH_MM_SS.format(source.getTime()));
InputStream inputStream = null;
try {
StringBuilder path = new StringBuilder();
path.append(basePath);
path.append(source.getPath());
inputStream = new FileInputStream(new File(path.toString()));
String content = cn.hutool.core.codec.Base64.encode(inputStream);
pms1.put("pic", content);
lists.add(pms1);
pms.put("picData", lists);
String json = httpClientUtil.doPost("http://10.10.150.173:8102/dss/Driver/UpLoadPicture", pms, headMap);
log.info("[{}],[{}]", json, JSON.toJSONString(pms));
return json;
} catch (Exception e) {
log.error("读取图片异常", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
return null;
}
private String uploadSignResource2(LinggangSignInResource source, String token, String basePath) {
Map<String, Object> headMap = new HashMap<>();
headMap.put("Content-Type", "application/json");
headMap.put("Authorization", token);
Map<String, Object> pms = new HashMap<>();
pms.put("device", "10001");
pms.put("driverCode", "10001");
pms.put("testId", source.getSignId());
pms.put("time", DateUtil.YYYY_MM_DD_LINK_HH_MM_SS.format(source.getTime()));
InputStream inputStream = null;
try {
StringBuilder path = new StringBuilder();
path.append(basePath);
path.append(source.getPath());
inputStream = new FileInputStream(new File(path.toString()));
String content = cn.hutool.core.codec.Base64.encode(inputStream);
pms.put("video", content);
String json = httpClientUtil.doPost("http://10.10.150.173:8102/dss/Driver/UpLoadVideo", pms, headMap);
log.info("[{}],[{}]", json, JSON.toJSONString(pms));
return json;
} catch (Exception e) {
log.error("读取图片异常", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
return null;
}
private String getToken() {
Map<String, Object> pms = new HashMap<>();
pms.put("authTime", DateUtil.YYYY_MM_DD_LINK_HH_MM_SS.format(new Date()));
pms.put("device", "10001");
String json = httpClientUtil.doPost("http://10.10.150.173:8102/dss/Driver/Auth", pms, null);
JSONObject jsonObject = JSON.parseObject(json);
JSONObject jsonObject1 = jsonObject.getJSONObject("data");
return jsonObject1.getString("access_token");
}
}