DssFaceController.java
13 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
package com.ruoyi.controller.dss;
import cn.hutool.core.convert.Convert;
import com.ruoyi.common.TipEnum;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.config.BsthSystemConfig;
import com.ruoyi.domain.driver.NewDriver;
import com.ruoyi.domain.driver.dss.syn.DrivePosEnum;
import com.ruoyi.domain.driver.dss.syn.dto.DssDriveQueryDTO;
import com.ruoyi.domain.driver.dss.syn.res.dto.FaceCheckDTO;
import com.ruoyi.domain.driver.dss.syn.res.dto.FaceRegisterDTO;
import com.ruoyi.domain.driver.dss.syn.res.dto.ReqDataDTO;
import com.ruoyi.domain.driver.dss.syn.res.dto.ResDataDriveDTO;
import com.ruoyi.domain.driver.dss.syn.res.vo.FaceCheckVo;
import com.ruoyi.domain.driver.dss.syn.res.vo.ReqDataVo;
import com.ruoyi.domain.driver.dss.syn.vo.DssDriveVo;
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
import com.ruoyi.service.driver.NewDriverService;
import com.ruoyi.service.dss.FaceService;
import com.ruoyi.utils.HttpClientUtil;
import com.ruoyi.utils.UploadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author liujun
* @date 2024年07月11日 14:07
*/
@Slf4j
@RestController
@RequestMapping("/dss")
@Api(tags = "【蓝斯一期】人脸信息")
public class DssFaceController extends BaseController {
@Autowired
private NewDriverService newDriverService;
@Autowired
private FaceService faceService;
@Autowired
private HttpClientUtil httpClientUtil;
@Autowired
private BsthSystemConfig bsthSystemConfig;
@Autowired
private UploadUtil uploadUtil;
@ApiOperation(value = "05.终端同步人脸数据")
@PostMapping(value = "/face/syn/reqData")
public ResponseResult<List<ReqDataVo>> reqData(@Valid @RequestBody ReqDataDTO dto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
if(StringUtils.isNotEmpty(msg)){
log.info(msg);
return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
}
NewDriver driver = new NewDriver();
driver.setPosts("驾驶员");
List<NewDriver> drivers = newDriverService.list(driver);
List<ReqDataVo> vos = convertReqDataVo(drivers);
return ResponseResult.success(vos);
}
@PostMapping("/Driver/syn/reqData")
@ApiOperation("获取数据库人员信息")
public ResponseResult<List<DssDriveVo>> queryDriver(@Valid @RequestBody DssDriveQueryDTO dto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
if(StringUtils.isNotEmpty(msg)){
log.info(msg);
return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
}
List<NewDriver> drivers = newDriverService.list();
return ResponseResult.success(convertDssDriveVo(drivers));
}
@ApiOperation("终端同步人脸数据结果上报")
@PostMapping(value = "/face/syn/resData")
public ResponseResult<Object> insertDriver(@Valid @RequestBody ResDataDriveDTO dto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
if(StringUtils.isNotEmpty(msg)){
log.info(msg);
return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
}
log.info("client data:[{}]",dto);
// NewDriver newDriver = convertNewDriver(dto);
// TipEnum errorTipEnum = newDriverService.updateClient(newDriver);
return ResponseResult.success();
}
@ApiOperation(("人脸注册"))
@PostMapping(value = "/Face/FaceRegister")
public ResponseResult<Object> faceRegister(@Valid @RequestBody FaceRegisterDTO dto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
if(StringUtils.isNotEmpty(msg)){
log.info(msg);
return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
}
Map<String, Object> parentMap = new HashMap<>();
parentMap.put("method", "getfacelitefeature");
parentMap.put("faceid", "1");
String faceValue = FileUploadUtils.choosePrictureContent(dto.getFaceValue());
parentMap.put("data", faceValue);
String faceFeature = null;
String json = null;
try {
json = httpClientUtil.doPost(bsthSystemConfig.getFaceFeatureURL(), parentMap, null);
if (StringUtils.isEmpty(json)) {
log.warn("获取面部特征失败,请检查数据:[{}]", json);
return ResponseResult.error("获取面部特征失败,请稍后再试");
}
json = StringUtils.substringAfter(json,"{");
json = StringUtils.substringBeforeLast(json,"}");
String [] results = StringUtils.split(json,",");
Map<String,String> resultMap = new HashMap<>();
for (String result : results) {
result = StringUtils.replace(result,"\\\"","");
String key = StringUtils.trim(StringUtils.substringBefore(result,":"));
String value = StringUtils.trim(StringUtils.substringAfter(result,":"));
resultMap.put(key,value);
}
if (!StringUtils.equalsIgnoreCase(resultMap.get("result"), "ok")) {
log.warn("获取面部特征不成功,,请检查数据:[{}]", json);
return ResponseResult.error("获取面部特征失败,请稍后再试");
}
faceFeature = Convert.toStr(resultMap.get("strlitefeature"));
}catch (Exception e){
log.error("获取面部特征异常,返回的结果是:[{}]",json,e);
return ResponseResult.error("获取面部特征异常,请稍后再试");
}
NewDriver newDriver = convertFaceRegister(dto,faceFeature);
TipEnum errorTipEnum = newDriverService.faceRegister(newDriver);
return new ResponseResult<>(errorTipEnum.getCode(), errorTipEnum.getMsg());
}
@ApiOperation("人脸校验")
@PostMapping(value = "/Driver/FaceCheck")
public ResponseResult<FaceCheckVo> faceCheck(@Valid @RequestBody FaceCheckDTO dto, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
}
String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
if(StringUtils.isNotEmpty(msg)){
log.info(msg);
return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
}
NewDriver driver = convertNewDriver(dto);
driver = faceService.checkFace(driver);
return Objects.isNull(driver) ? ResponseResult.error("登陆匹配失败") : ResponseResult.success(convertFaceCheckVo(driver));
}
private List<DssDriveVo> convertDssDriveVo(List<NewDriver> newDrivers) {
if (CollectionUtils.isEmpty(newDrivers)) {
return Collections.emptyList();
}
return newDrivers.stream().map(driver -> {
DssDriveVo vo = new DssDriveVo();
vo.setStaffId(driver.getJobCode());
vo.setStaffName(driver.getPersonnelName());
vo.setIcCardNo(driver.getIcCardCode());
vo.setFacePhotoPath(driver.getImage());
vo.setCsn(driver.getIdRfid());
vo.setFaceFeature(driver.getFaceFeature());
vo.setBlueTooth(driver.getBlueTooth());
vo.setSynContent(driver.getSyncontent());
Integer post = DrivePosEnum.getObjValueOfLabel(driver.getPosts());
Set<Integer> posts = new HashSet<>();
posts.add(post);
vo.setStaffTypeItem(posts);
return vo;
}).collect(Collectors.toList());
}
private NewDriver convertNewDriver(ResDataDriveDTO dto) {
NewDriver newDriver = new NewDriver();
newDriver.setId(Convert.toInt(dto.getStaffId()));
newDriver.setJobCode(dto.getStaffCode());
newDriver.setPersonnelName(dto.getStaffName());
newDriver.setIcCardCode(dto.getIcCardNo());
newDriver.setImage(dto.getFacePhotoPath());
newDriver.setFaceFeature(dto.getFaceFeature());
newDriver.setBlueTooth(dto.getBlueTooth());
newDriver.setInteger(dto.getInteger());
newDriver.setSyncontent((dto.getSynContent()));
newDriver.setCsn(dto.getCsn());
newDriver.setImageVersion(dto.getVersionNo());
return newDriver;
}
private NewDriver convertFaceRegister(FaceRegisterDTO dto,String faceFeature) {
NewDriver newDriver = new NewDriver();
newDriver.setIcCardCode(dto.getDriverCode());
newDriver.setFaceSignIn(1);
newDriver.setSignInEquipment(dto.getDevice());
newDriver.setImage(dto.getFaceValue());
newDriver.setJobCode(dto.getStaffCode());
newDriver.setFaceFeature(faceFeature);
return newDriver;
}
private NewDriver convertNewDriver(FaceCheckDTO dto) {
NewDriver driver = new NewDriver();
driver.setImage(dto.getFaceValue());
return driver;
}
private FaceCheckVo convertFaceCheckVo(NewDriver driver) {
FaceCheckVo faceCheckVo = new FaceCheckVo();
faceCheckVo.setDriverCode(driver.getIcRfid());
return faceCheckVo;
}
private List<ReqDataVo> convertReqDataVo(List<NewDriver> drivers) {
if (CollectionUtils.isEmpty(drivers)) {
return Collections.emptyList();
}
return drivers.stream().map(d -> {
ReqDataVo vo = new ReqDataVo();
vo.setVersionNo(Convert.toStr(d.getImageVersion()));
vo.setStaffId(Convert.toStr(d.getId()));
vo.setStaffName(d.getPersonnelName());
vo.setIcCardNo(d.getIcCardCode());
vo.setFacePhotoPath(d.getImage());
vo.setFaceFeature(d.getFaceFeature());
vo.setStaffCode(d.getJobCode());
// vo.setSynState(d.getS)
vo.setSynContent(d.getSyncontent());
vo.setStaffTypeItem(switchPostion(d.getPosts()));
return vo;
}).collect(Collectors.toList());
}
private Set<Integer> switchPostion(String post) {
Set<Integer> postSet = new LinkedHashSet<>();
if (StringUtils.indexOf(post, "驾驶员") > -1) {
postSet.add(2);
}
if (StringUtils.indexOf(post, "集调中心") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "稽查") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "行管员") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "副队长") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "调度") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "科员") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "队长") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "车队支部书记") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "部门副经理") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "副总经理") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "部门经理") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "办公室主任") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "办公室副主任") > -1) {
postSet.add(3);
}
if (StringUtils.indexOf(post, "工会副主席") > -1) {
postSet.add(3);
}
if (CollectionUtils.isEmpty(postSet)) {
postSet.add(1);
}
return postSet;
}
}