Commit 5ece0d69c7c7b7bf1cd4fcff8257070ead8428d6

Authored by liujun001
1 parent 13160947

添加设备操作异常警报

Bsth-admin/src/main/java/com/ruoyi/config/FaceEngineConfig.java
... ... @@ -64,7 +64,7 @@ public class FaceEngineConfig {
64 64 errorCode = faceEngine.init(engineConfiguration);
65 65  
66 66 if (errorCode != ErrorInfo.MOK.getValue()) {
67   - throw new InterruptException("初始化引擎失败,错误编码:"+errorCode);
  67 + throw new InterruptException("初始化引擎失败,错误编码:"+errorCode);
68 68 }
69 69  
70 70 return faceEngine;
... ...
Bsth-admin/src/main/java/com/ruoyi/controller/RefreshController.java
1 1 package com.ruoyi.controller;
2 2  
3 3 import com.ruoyi.common.core.domain.ResponseResult;
  4 +import com.ruoyi.common.utils.sign.Base64;
  5 +import com.ruoyi.controller.dss.DssFaceController;
  6 +import com.ruoyi.domain.driver.NewDriver;
  7 +import com.ruoyi.domain.driver.dss.syn.res.dto.FaceRegisterDTO;
4 8 import com.ruoyi.domain.scheduling.LinggangScheduling;
  9 +import com.ruoyi.equipment.domain.Equipment;
  10 +import com.ruoyi.equipment.service.IEquipmentService;
5 11 import com.ruoyi.job.DriverJob;
6 12 import com.ruoyi.service.driver.NewDriverService;
7 13 import com.ruoyi.service.key.location.LinggangKeyWorkLocationService;
8 14 import com.ruoyi.service.scheduling.LinggangSchedulingService;
9 15 import com.ruoyi.utils.DateUtil;
10 16 import io.swagger.annotations.ApiOperation;
  17 +import lombok.extern.slf4j.Slf4j;
  18 +import org.apache.commons.io.FileUtils;
  19 +import org.apache.commons.lang3.ArrayUtils;
  20 +import org.apache.commons.lang3.StringUtils;
11 21 import org.apache.commons.lang3.time.DateUtils;
12 22 import org.springframework.beans.factory.annotation.Autowired;
13   -import org.springframework.web.bind.annotation.GetMapping;
14   -import org.springframework.web.bind.annotation.RequestMapping;
15   -import org.springframework.web.bind.annotation.RequestParam;
16   -import org.springframework.web.bind.annotation.RestController;
  23 +import org.springframework.security.access.prepost.PreAuthorize;
  24 +import org.springframework.web.bind.annotation.*;
17 25  
  26 +import java.io.File;
  27 +import java.io.IOException;
18 28 import java.text.ParseException;
19 29 import java.util.Date;
20 30 import java.util.List;
  31 +import java.util.Objects;
21 32 import java.util.Set;
22 33 import java.util.stream.Collectors;
23 34  
... ... @@ -25,6 +36,7 @@ import java.util.stream.Collectors;
25 36 * @author liujun
26 37 * @date 2024年07月30日 14:37
27 38 */
  39 +@Slf4j
28 40 @RestController
29 41 @RequestMapping("/refresh")
30 42 public class RefreshController {
... ... @@ -36,21 +48,31 @@ public class RefreshController {
36 48 private NewDriverService newDriverService;
37 49 @Autowired
38 50 private LinggangSchedulingService linggangSchedulingService;
  51 + @Autowired
  52 + private DssFaceController dssFaceController;
  53 + @Autowired
  54 + private IEquipmentService equipmentService;
39 55  
40 56 @GetMapping(value = "/scheduling")
41 57 @ApiOperation("scheduling")
  58 + @PreAuthorize("@ss.hasPermi('refresh:scheduling')")
42 59 public ResponseResult<Boolean> test() {
43 60 Date date = new Date();
44 61 for (int i = 0; i < 2; i++) {
45 62 driverJob.runScheduling(DateUtils.addDays(date, i).getTime());
46 63 }
47 64  
  65 +
48 66 return ResponseResult.success();
49 67 }
50 68  
51 69 @GetMapping(value = "/key/info/local")
52 70 @ApiOperation("/key/info/local")
53   - public ResponseResult<Boolean> testKeyInfoLocal(@RequestParam("dateStr") String dateStr) throws ParseException {
  71 + @PreAuthorize("@ss.hasPermi('refresh:key:info:local')")
  72 + public ResponseResult<Boolean> testKeyInfoLocal(@RequestParam(value = "dateStr",required = false) String dateStr) throws ParseException {
  73 + if(StringUtils.isEmpty(dateStr)){
  74 + dateStr = DateUtil.YYYY_MM_DD_LINK.format(new Date());
  75 + }
54 76 Date date = DateUtil.YYYY_MM_DD_LINK.parse(dateStr);
55 77  
56 78 LinggangScheduling scheduling = new LinggangScheduling();
... ... @@ -60,14 +82,94 @@ public class RefreshController {
60 82  
61 83 List<LinggangScheduling> linggangSchedulings = linggangSchedulingService.list(scheduling);
62 84 Set<Long> idSets = linggangSchedulings.stream().map(LinggangScheduling::getId).collect(Collectors.toSet());
63   - keyWorkLocationService.insertJob(dateStr,null, idSets);
  85 + keyWorkLocationService.insertJob(dateStr, null, idSets);
  86 +
  87 + log.info("钥匙存放信息处理完毕");
64 88 return ResponseResult.success();
65 89 }
66 90  
67 91 @GetMapping(value = "/driver")
68 92 @ApiOperation("driver")
  93 + @PreAuthorize("@ss.hasPermi('refresh:driver')")
69 94 public ResponseResult<Boolean> insertDriver() {
70 95 newDriverService.insertJob();
  96 + log.info("人员信息同步完毕");
71 97 return ResponseResult.success();
72 98 }
  99 +
  100 + @PostMapping(value = "/driver/init/image")
  101 + @ApiOperation("driver/init/image")
  102 + @PreAuthorize("@ss.hasPermi('refresh:driver:init:image')")
  103 + public ResponseResult<Boolean> insertDriverInitImage(@RequestParam("imagePath") String imagePath, @RequestParam("device") String device) {
  104 + if (StringUtils.isEmpty(device)) {
  105 + return ResponseResult.error("注册设备号不能为空");
  106 + }
  107 +
  108 + if (StringUtils.isEmpty(imagePath)) {
  109 + String path = StringUtils.join(System.getProperty("user.dir"), File.pathSeparator, "images");
  110 + ;
  111 + log.info("[{}]", path);
  112 + imagePath = path;
  113 + }
  114 +
  115 + File file = new File(imagePath);
  116 + if (!file.exists()) {
  117 + return ResponseResult.error("文件路径不存在");
  118 + }
  119 + if (!file.isDirectory()) {
  120 + return ResponseResult.error("文件路径不是文件夹路径");
  121 + }
  122 +
  123 + File[] fs = file.listFiles();
  124 + int length = ArrayUtils.getLength(fs);
  125 + if (0 == length) {
  126 + return ResponseResult.error("文件路径下没有文件");
  127 + }
  128 +
  129 + Equipment equipment = equipmentService.getOneByDeviceId(device);
  130 + if (Objects.isNull(equipment)) {
  131 + return ResponseResult.error("设备号不正确,请确认设备信息");
  132 + }
  133 +
  134 +
  135 + for (int i = 0; i < length; i++) {
  136 + FaceRegisterDTO dto = new FaceRegisterDTO();
  137 + dto.setDevice(device);
  138 +
  139 + String jobCode = StringUtils.trim(StringUtils.substringBeforeLast(file.getName(), "."));
  140 + dto.setStaffCode(jobCode);
  141 +
  142 +
  143 + NewDriver driver = newDriverService.getOne(jobCode);
  144 + if (StringUtils.isNotEmpty(driver.getImage())) {
  145 + log.info("人脸数据已经存在:[{}]", dto);
  146 + continue;
  147 + }
  148 + dto.setRegTime(DateUtil.shortDate(new Date()));
  149 + try {
  150 + byte[] bytes = FileUtils.readFileToByteArray(fs[i]);
  151 + String imageContent = Base64.encode(bytes);
  152 + dto.setFaceValue(imageContent);
  153 + } catch (IOException e) {
  154 + throw new RuntimeException(e);
  155 + }
  156 + ResponseResult<Object> responseResult = dssFaceController.faceRegister(dto);
  157 + if (Objects.isNull(responseResult) || !responseResult.isSuccess()) {
  158 + log.warn("[{}]数据没有执行成功;返回值为:[{}]", dto, responseResult);
  159 + }
  160 + }
  161 +
  162 + log.info("人员信息同步完毕");
  163 + return ResponseResult.success();
  164 + }
  165 +
  166 + @GetMapping(value = "/jar/class/path")
  167 + public ResponseResult<String> getJarClassPath() {
  168 + String path = StringUtils.join(System.getProperty("user.dir"), File.separator, "images");
  169 +
  170 + ResponseResult<String> responseResult = ResponseResult.success();
  171 + responseResult.setData(path);
  172 + return responseResult;
  173 + }
  174 +
73 175 }
... ...
Bsth-admin/src/main/java/com/ruoyi/controller/dss/DssFaceController.java
... ... @@ -70,9 +70,9 @@ public class DssFaceController extends BaseController {
70 70 }
71 71  
72 72 String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
73   - if(StringUtils.isNotEmpty(msg)){
  73 + if (StringUtils.isNotEmpty(msg)) {
74 74 log.info(msg);
75   - return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
  75 + return ResponseResult.error(TipEnum.TIP_401.getCode(), TipEnum.TIP_401.getMsg());
76 76 }
77 77  
78 78 NewDriver driver = new NewDriver();
... ... @@ -91,13 +91,13 @@ public class DssFaceController extends BaseController {
91 91 return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
92 92 }
93 93 String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
94   - if(StringUtils.isNotEmpty(msg)){
  94 + if (StringUtils.isNotEmpty(msg)) {
95 95 log.info(msg);
96   - return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
  96 + return ResponseResult.error(TipEnum.TIP_401.getCode(), TipEnum.TIP_401.getMsg());
97 97 }
98 98  
99 99 List<NewDriver> drivers = newDriverService.list();
100   - return ResponseResult.success(convertDssDriveVo(drivers));
  100 + return ResponseResult.success(convertDssDriveVo(drivers));
101 101 }
102 102  
103 103 @ApiOperation("终端同步人脸数据结果上报")
... ... @@ -108,12 +108,12 @@ public class DssFaceController extends BaseController {
108 108 }
109 109  
110 110 String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
111   - if(StringUtils.isNotEmpty(msg)){
  111 + if (StringUtils.isNotEmpty(msg)) {
112 112 log.info(msg);
113   - return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
  113 + return ResponseResult.error(TipEnum.TIP_401.getCode(), TipEnum.TIP_401.getMsg());
114 114 }
115 115  
116   - log.info("client data:[{}]",dto);
  116 + log.info("client data:[{}]", dto);
117 117 // NewDriver newDriver = convertNewDriver(dto);
118 118 // TipEnum errorTipEnum = newDriverService.updateClient(newDriver);
119 119 return ResponseResult.success();
... ... @@ -127,11 +127,36 @@ public class DssFaceController extends BaseController {
127 127 }
128 128  
129 129 String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
130   - if(StringUtils.isNotEmpty(msg)){
  130 + if (StringUtils.isNotEmpty(msg)) {
131 131 log.info(msg);
132   - return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
  132 + return ResponseResult.error(TipEnum.TIP_401.getCode(), TipEnum.TIP_401.getMsg());
133 133 }
134 134  
  135 + return faceRegister(dto);
  136 + }
  137 +
  138 +
  139 +
  140 + @ApiOperation("人脸校验")
  141 + @PostMapping(value = "/Driver/FaceCheck")
  142 + public ResponseResult<FaceCheckVo> faceCheck(@Valid @RequestBody FaceCheckDTO dto, BindingResult bindingResult) {
  143 + if (bindingResult.hasErrors()) {
  144 + return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
  145 + }
  146 +
  147 + String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
  148 + if (StringUtils.isNotEmpty(msg)) {
  149 + log.info(msg);
  150 + return ResponseResult.error(TipEnum.TIP_401.getCode(), TipEnum.TIP_401.getMsg());
  151 + }
  152 +
  153 + NewDriver driver = convertNewDriver(dto);
  154 + driver = faceService.checkFace(driver);
  155 +
  156 + return Objects.isNull(driver) ? ResponseResult.error("登陆匹配失败") : ResponseResult.success(convertFaceCheckVo(driver));
  157 + }
  158 +
  159 + public ResponseResult<Object> faceRegister(FaceRegisterDTO dto) {
135 160 Map<String, Object> parentMap = new HashMap<>();
136 161 parentMap.put("method", "getfacelitefeature");
137 162 parentMap.put("faceid", "1");
... ... @@ -146,15 +171,15 @@ public class DssFaceController extends BaseController {
146 171 log.warn("获取面部特征失败,请检查数据:[{}]", json);
147 172 return ResponseResult.error("获取面部特征失败,请稍后再试");
148 173 }
149   - json = StringUtils.substringAfter(json,"{");
150   - json = StringUtils.substringBeforeLast(json,"}");
151   - String [] results = StringUtils.split(json,",");
152   - Map<String,String> resultMap = new HashMap<>();
  174 + json = StringUtils.substringAfter(json, "{");
  175 + json = StringUtils.substringBeforeLast(json, "}");
  176 + String[] results = StringUtils.split(json, ",");
  177 + Map<String, String> resultMap = new HashMap<>();
153 178 for (String result : results) {
154   - result = StringUtils.replace(result,"\\\"","");
155   - String key = StringUtils.trim(StringUtils.substringBefore(result,":"));
156   - String value = StringUtils.trim(StringUtils.substringAfter(result,":"));
157   - resultMap.put(key,value);
  179 + result = StringUtils.replace(result, "\\\"", "");
  180 + String key = StringUtils.trim(StringUtils.substringBefore(result, ":"));
  181 + String value = StringUtils.trim(StringUtils.substringAfter(result, ":"));
  182 + resultMap.put(key, value);
158 183 }
159 184  
160 185  
... ... @@ -163,37 +188,18 @@ public class DssFaceController extends BaseController {
163 188 return ResponseResult.error("获取面部特征失败,请稍后再试");
164 189 }
165 190 faceFeature = Convert.toStr(resultMap.get("strlitefeature"));
166   - }catch (Exception e){
167   - log.error("获取面部特征异常,返回的结果是:[{}]",json,e);
  191 + } catch (Exception e) {
  192 + log.error("获取面部特征异常,返回的结果是:[{}]", json, e);
168 193 return ResponseResult.error("获取面部特征异常,请稍后再试");
169 194 }
170 195  
171 196  
172   - NewDriver newDriver = convertFaceRegister(dto,faceFeature);
  197 + NewDriver newDriver = convertFaceRegister(dto, faceFeature);
173 198  
174 199 TipEnum errorTipEnum = newDriverService.faceRegister(newDriver);
175 200 return new ResponseResult<>(errorTipEnum.getCode(), errorTipEnum.getMsg());
176 201 }
177 202  
178   - @ApiOperation("人脸校验")
179   - @PostMapping(value = "/Driver/FaceCheck")
180   - public ResponseResult<FaceCheckVo> faceCheck(@Valid @RequestBody FaceCheckDTO dto, BindingResult bindingResult) {
181   - if (bindingResult.hasErrors()) {
182   - return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
183   - }
184   -
185   - String msg = JwtAuthenticationTokenFilter.validateDevice(dto.getDevice());
186   - if(StringUtils.isNotEmpty(msg)){
187   - log.info(msg);
188   - return ResponseResult.error(TipEnum.TIP_401.getCode(),TipEnum.TIP_401.getMsg());
189   - }
190   -
191   - NewDriver driver = convertNewDriver(dto);
192   - driver = faceService.checkFace(driver);
193   -
194   - return Objects.isNull(driver) ? ResponseResult.error("登陆匹配失败") : ResponseResult.success(convertFaceCheckVo(driver));
195   - }
196   -
197 203  
198 204 private List<DssDriveVo> convertDssDriveVo(List<NewDriver> newDrivers) {
199 205 if (CollectionUtils.isEmpty(newDrivers)) {
... ... @@ -238,7 +244,7 @@ public class DssFaceController extends BaseController {
238 244 return newDriver;
239 245 }
240 246  
241   - private NewDriver convertFaceRegister(FaceRegisterDTO dto,String faceFeature) {
  247 + private NewDriver convertFaceRegister(FaceRegisterDTO dto, String faceFeature) {
242 248 NewDriver newDriver = new NewDriver();
243 249 newDriver.setIcCardCode(dto.getDriverCode());
244 250 newDriver.setFaceSignIn(1);
... ... @@ -285,6 +291,8 @@ public class DssFaceController extends BaseController {
285 291 }).collect(Collectors.toList());
286 292 }
287 293  
  294 +
  295 +
288 296 private Set<Integer> switchPostion(String post) {
289 297  
290 298 Set<Integer> postSet = new LinkedHashSet<>();
... ...
Bsth-admin/src/main/java/com/ruoyi/service/ThreadJobService.java
... ... @@ -548,6 +548,8 @@ public class ThreadJobService {
548 548 keyWorkLocationService.insertJob(dateStr1, schedulings, null);
549 549 }
550 550 log.info("当天排班数据获取完毕,共:{}条", bcList.size());
  551 +
  552 + log.info("排班信息同步完毕");
551 553 }
552 554  
553 555 private <T> String combitionKey(T s1) {
... ...
Bsth-admin/src/main/resources/application.yml
... ... @@ -167,4 +167,10 @@ api:
167 167 appKey: dingsclwvxui5zilg1xk
168 168 appSecret: ckV20k3jMKJpUkfXXSGhLk077rQQjsSaAusiSVY-nm4glwweCmb_SMJ62Cpf4YQ5
169 169 log:
170   - path: E:/ruoyi/logs
171 170 \ No newline at end of file
  171 + path: E:/ruoyi/logs
  172 +
  173 +management:
  174 + endpoints:
  175 + web:
  176 + exposure:
  177 + include: "*"
172 178 \ No newline at end of file
... ...