RefreshController.java
6.44 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
package com.ruoyi.controller;
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.scheduling.LinggangScheduling;
import com.ruoyi.equipment.domain.Equipment;
import com.ruoyi.equipment.service.IEquipmentService;
import com.ruoyi.job.DriverJob;
import com.ruoyi.service.driver.NewDriverService;
import com.ruoyi.service.key.location.LinggangKeyWorkLocationService;
import com.ruoyi.service.scheduling.LinggangSchedulingService;
import com.ruoyi.utils.DateUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Set;
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;
@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 = "/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(file.getName(), "."));
dto.setStaffCode(jobCode);
NewDriver driver = newDriverService.getOne(jobCode);
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();
}
@GetMapping(value = "/jar/class/path")
public ResponseResult<String> getJarClassPath() {
String path = StringUtils.join(System.getProperty("user.dir"), File.separator, "images");
ResponseResult<String> responseResult = ResponseResult.success();
responseResult.setData(path);
return responseResult;
}
}