RefreshController.java
9.95 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
package com.ruoyi.controller;
import com.alibaba.fastjson2.JSON;
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.collections4.CollectionUtils;
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.*;
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(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"), File.separator, "images");
ResponseResult<String> responseResult = ResponseResult.success();
responseResult.setData(path);
return responseResult;
}
}