Commit 90a4f2083ac4a80b2672b2b22b7c85fb01a8df7c
1 parent
ee908e27
设备和场地
Showing
14 changed files
with
146 additions
and
65 deletions
Bsth-admin/src/main/java/com/ruoyi/controller/dss/DssCarInfoController.java
| ... | ... | @@ -26,13 +26,13 @@ import java.util.stream.Collectors; |
| 26 | 26 | */ |
| 27 | 27 | @RestController |
| 28 | 28 | @RequestMapping("/dss") |
| 29 | -@Api(tags = "【蓝斯一期】岗前设备报警信息") | |
| 29 | +@Api(tags = "【蓝斯一期】车辆信息") | |
| 30 | 30 | public class DssCarInfoController { |
| 31 | 31 | @Autowired |
| 32 | 32 | private CarInfoService carInfoService; |
| 33 | 33 | |
| 34 | 34 | @GetMapping(value = "/device/getPlates") |
| 35 | - @ApiModelProperty("模糊查询车辆车牌列表") | |
| 35 | + @ApiModelProperty(value="模糊查询车辆车牌列表") | |
| 36 | 36 | public ResponseResult<Set<String>> getPlates(@Valid @RequestBody GetPlatesDTO dto, BindingResult bindingResult) { |
| 37 | 37 | if (bindingResult.hasErrors()) { |
| 38 | 38 | return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage()); | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/controller/dss/DssDriverController.java
| ... | ... | @@ -88,11 +88,6 @@ public class DssDriverController extends BaseController { |
| 88 | 88 | if (bindingResult.hasErrors()) { |
| 89 | 89 | return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage()); |
| 90 | 90 | } |
| 91 | -// Integer id = checkFace(); | |
| 92 | -// if (Objects.isNull(id)) { | |
| 93 | -// return AjaxResult.error("登陆数据错误,无法识别人脸"); | |
| 94 | -// } | |
| 95 | -// NewDriver newDriver = newDriverService.getById(id); | |
| 96 | 91 | NewDriver driver = faceService.checkFace(convertLoginDriverDTO(loginDriverDTO)); |
| 97 | 92 | return ResponseResult.success(convertNewDriver(driver)); |
| 98 | 93 | } |
| ... | ... | @@ -106,10 +101,22 @@ public class DssDriverController extends BaseController { |
| 106 | 101 | SignIn signIn = convertSignIn(dto); |
| 107 | 102 | try { |
| 108 | 103 | AjaxResult ajaxResult = signInService.addSignIn(signIn); |
| 109 | - if (ajaxResult.isSuccess()) { | |
| 104 | + if (Objects.nonNull(ajaxResult) && ajaxResult.isSuccess()) { | |
| 105 | +// if(Objects.nonNull(ajaxResult.get(AjaxResult.MSG_TAG))){ | |
| 106 | +// String msg = ajaxResult.get(AjaxResult.MSG_TAG).toString(); | |
| 107 | +// if(StringUtils.isNotEmpty(msg)){ | |
| 108 | +// return ResponseResult.error(Convert.toInt(ajaxResult.get(AjaxResult.CODE_TAG)), Convert.toStr(ajaxResult.get(AjaxResult.MSG_TAG))); | |
| 109 | +// } | |
| 110 | +// } | |
| 111 | + SysDictData sysDictData = new SysDictData(); | |
| 112 | + sysDictData.setDictType("drinking"); | |
| 113 | + SysDictData dictData = sysDictDataService.getOne(sysDictData); | |
| 114 | + | |
| 110 | 115 | SignInResponseVo responseVo = (SignInResponseVo) ajaxResult.get(AjaxResult.DATA_TAG); |
| 111 | 116 | if (Objects.nonNull(responseVo)) { |
| 112 | - return ResponseResult.success(convertSignInVo(responseVo)); | |
| 117 | + ResponseResult<DssSignVo> responseResult = ResponseResult.success(convertSignInVo(responseVo,dto,dictData)); | |
| 118 | + responseResult.setMsg(Convert.toStr(ajaxResult.get(AjaxResult.MSG_TAG))); | |
| 119 | + return responseResult; | |
| 113 | 120 | } |
| 114 | 121 | } |
| 115 | 122 | |
| ... | ... | @@ -132,7 +139,12 @@ public class DssDriverController extends BaseController { |
| 132 | 139 | try { |
| 133 | 140 | AjaxResult ajaxResult = signInService.addSignIn(signIn); |
| 134 | 141 | if (Objects.nonNull(ajaxResult) && ajaxResult.isSuccess()) { |
| 135 | - return ResponseResult.success(convertSignOutVo(dto)); | |
| 142 | + SignInResponseVo responseVo = (SignInResponseVo) ajaxResult.get(AjaxResult.DATA_TAG); | |
| 143 | + if (Objects.nonNull(responseVo)) { | |
| 144 | + ResponseResult<SignOutVo> responseResult = ResponseResult.success(convertSignOutVo(dto,responseVo)); | |
| 145 | + responseResult.setMsg(Convert.toStr(ajaxResult.get(AjaxResult.MSG_TAG))); | |
| 146 | + return responseResult; | |
| 147 | + } | |
| 136 | 148 | } |
| 137 | 149 | |
| 138 | 150 | return ResponseResult.error(Convert.toInt(ajaxResult.get(AjaxResult.CODE_TAG)), Convert.toStr(ajaxResult.get(AjaxResult.MSG_TAG))); |
| ... | ... | @@ -149,6 +161,8 @@ public class DssDriverController extends BaseController { |
| 149 | 161 | return ResponseResult.error(bindingResult.getFieldError().getDefaultMessage()); |
| 150 | 162 | } |
| 151 | 163 | |
| 164 | + | |
| 165 | + | |
| 152 | 166 | SignIn signIn = convertSignIn(dto); |
| 153 | 167 | SignIn dataSignIn = signInService.getLastOne(signIn); |
| 154 | 168 | return ResponseResult.success(convertGetWineRecordVo(dataSignIn)); |
| ... | ... | @@ -259,7 +273,7 @@ public class DssDriverController extends BaseController { |
| 259 | 273 | */ |
| 260 | 274 | private LoginDriverVo convertNewDriver(NewDriver newDriver) { |
| 261 | 275 | LoginDriverVo loginDriverVo = new LoginDriverVo(); |
| 262 | - loginDriverVo.setDriverCode(newDriver.getIcRfid()); | |
| 276 | + loginDriverVo.setDriverCode(newDriver.getIcCardCode()); | |
| 263 | 277 | loginDriverVo.setDriverName(newDriver.getPersonnelName()); |
| 264 | 278 | loginDriverVo.setWorkCode(newDriver.getJobCode()); |
| 265 | 279 | loginDriverVo.setStaffCode(newDriver.getJobCode()); |
| ... | ... | @@ -289,7 +303,7 @@ public class DssDriverController extends BaseController { |
| 289 | 303 | LoginUserInfoVo loginUserInfoVo = new LoginUserInfoVo(); |
| 290 | 304 | loginUserInfoVo.setStaffId(Convert.toStr(newDriver.getId())); |
| 291 | 305 | loginUserInfoVo.setStaffName(newDriver.getPersonnelName()); |
| 292 | - loginUserInfoVo.setIcCardNo(newDriver.getIcRfid()); | |
| 306 | + loginUserInfoVo.setIcCardNo(newDriver.getIcCardCode()); | |
| 293 | 307 | loginUserInfoVo.setFacePhotoPath(newDriver.getImage()); |
| 294 | 308 | |
| 295 | 309 | loginDriverVo.setUserInfo(loginUserInfoVo); |
| ... | ... | @@ -420,6 +434,14 @@ public class DssDriverController extends BaseController { |
| 420 | 434 | return signIn; |
| 421 | 435 | } |
| 422 | 436 | |
| 437 | +// private LinggangScheduling convertLinggangScheduling(DssGetWineRecordDTO dto) { | |
| 438 | +// SignIn signIn = new SignIn(); | |
| 439 | +// signIn.setJobCode(dto.getStaffCode()); | |
| 440 | +// signIn.setDeviceId(dto.getDevice()); | |
| 441 | +// | |
| 442 | +// return signIn; | |
| 443 | +// } | |
| 444 | + | |
| 423 | 445 | private List<LinggangSignInResource> convertLinggangSignInResource(UpLoadPictureDTO dto) { |
| 424 | 446 | if (CollectionUtils.isEmpty(dto.getPicData())) { |
| 425 | 447 | return Collections.emptyList(); |
| ... | ... | @@ -452,12 +474,15 @@ public class DssDriverController extends BaseController { |
| 452 | 474 | return resource; |
| 453 | 475 | } |
| 454 | 476 | |
| 455 | - private DssSignVo convertSignInVo(SignInResponseVo responseVo) { | |
| 477 | + private DssSignVo convertSignInVo(SignInResponseVo responseVo,DssSignDTO dto,SysDictData dictData ) { | |
| 456 | 478 | DssSignVo vo = new DssSignVo(); |
| 457 | 479 | vo.setTestId(Convert.toStr(responseVo.getId())); |
| 458 | 480 | |
| 459 | 481 | Integer testResult = Objects.equals(responseVo.getExType(), 3) ? 2 : 0; |
| 460 | 482 | vo.setTestResult(testResult); |
| 483 | + if(Objects.isNull(dictData) || Objects.equals(testResult,0) && dto.getTestValue()>Convert.toLong(dictData.getDictValue())){ | |
| 484 | + vo.setTestResult(1); | |
| 485 | + } | |
| 461 | 486 | |
| 462 | 487 | Integer result = Objects.isNull(responseVo.getStatus()) ? 0 : responseVo.getStatus() - 1; |
| 463 | 488 | vo.setResult(result); |
| ... | ... | @@ -465,8 +490,8 @@ public class DssDriverController extends BaseController { |
| 465 | 490 | return vo; |
| 466 | 491 | } |
| 467 | 492 | |
| 468 | - private SignOutVo convertSignOutVo(DssSignOutDTO dto) { | |
| 469 | - return new SignOutVo(dto.getDevice(), dto.getDriverCode(), dto.getLogoutTime()); | |
| 493 | + private SignOutVo convertSignOutVo(DssSignOutDTO dto,SignInResponseVo vo) { | |
| 494 | + return new SignOutVo(dto.getDevice(), dto.getDriverCode(), dto.getLogoutTime(),vo.getId()); | |
| 470 | 495 | } |
| 471 | 496 | |
| 472 | 497 | private GetWineRecordVo convertGetWineRecordVo(SignIn signIn) { | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/controller/dss/DssFaceController.java
| ... | ... | @@ -133,7 +133,8 @@ public class DssFaceController extends BaseController { |
| 133 | 133 | |
| 134 | 134 | private NewDriver convertNewDriver(ResDataDriveDTO dto) { |
| 135 | 135 | NewDriver newDriver = new NewDriver(); |
| 136 | - newDriver.setJobCode(dto.getStaffId()); | |
| 136 | + newDriver.setId(Convert.toInt(dto.getStaffId())); | |
| 137 | + newDriver.setJobCode(dto.getStaffCode()); | |
| 137 | 138 | newDriver.setPersonnelName(dto.getStaffName()); |
| 138 | 139 | newDriver.setIcCardCode(dto.getIcCardNo()); |
| 139 | 140 | newDriver.setImage(dto.getFacePhotoPath()); |
| ... | ... | @@ -142,15 +143,16 @@ public class DssFaceController extends BaseController { |
| 142 | 143 | newDriver.setInteger(dto.getInteger()); |
| 143 | 144 | newDriver.setSyncontent((dto.getSynContent())); |
| 144 | 145 | newDriver.setCsn(dto.getCsn()); |
| 146 | + newDriver.setImageVersion(dto.getVersionNo()); | |
| 145 | 147 | |
| 146 | 148 | return newDriver; |
| 147 | 149 | } |
| 148 | 150 | |
| 149 | 151 | private NewDriver convertFaceRegister(FaceRegisterDTO dto) { |
| 150 | 152 | NewDriver newDriver = new NewDriver(); |
| 151 | - newDriver.setIcCardCode(dto.getFaceValue()); | |
| 153 | + newDriver.setIcCardCode(dto.getDriverCode()); | |
| 152 | 154 | newDriver.setFaceSignIn(1); |
| 153 | - newDriver.setSignInEquipment(dto.getDriverCode()); | |
| 155 | + newDriver.setSignInEquipment(dto.getDevice()); | |
| 154 | 156 | newDriver.setImage(dto.getFaceValue()); |
| 155 | 157 | |
| 156 | 158 | return newDriver; | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/domain/driver/NewDriver.java
Bsth-admin/src/main/java/com/ruoyi/domain/driver/dss/syn/res/dto/FaceCheckDTO.java
| ... | ... | @@ -11,6 +11,7 @@ import lombok.NoArgsConstructor; |
| 11 | 11 | import lombok.experimental.Accessors; |
| 12 | 12 | |
| 13 | 13 | import javax.validation.constraints.NotEmpty; |
| 14 | +import javax.validation.constraints.NotNull; | |
| 14 | 15 | import java.util.Date; |
| 15 | 16 | |
| 16 | 17 | /** |
| ... | ... | @@ -32,7 +33,7 @@ public class FaceCheckDTO implements java.io.Serializable { |
| 32 | 33 | @ApiModelProperty(value = "IC卡号", required = true) |
| 33 | 34 | private String driverCode; |
| 34 | 35 | |
| 35 | - @NotEmpty(message = "时间不能为空") | |
| 36 | + @NotNull(message = "时间不能为空") | |
| 36 | 37 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| 37 | 38 | @ApiModelProperty(value = "时间", required = true) |
| 38 | 39 | private Date checkTime; | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/domain/dss/sign/vo/SignOutVo.java
Bsth-admin/src/main/java/com/ruoyi/in/domain/SignIn.java
| 1 | 1 | package com.ruoyi.in.domain; |
| 2 | 2 | |
| 3 | +import com.baomidou.mybatisplus.annotation.TableField; | |
| 3 | 4 | import com.ruoyi.common.annotation.Excel; |
| 4 | 5 | import com.ruoyi.common.core.domain.BaseEntity; |
| 5 | 6 | import io.swagger.annotations.ApiModel; |
| ... | ... | @@ -33,6 +34,7 @@ public class SignIn extends BaseEntity { |
| 33 | 34 | @Excel(name = "工号") |
| 34 | 35 | @ApiModelProperty("工号") |
| 35 | 36 | @NotBlank(message = "工号不能为空") |
| 37 | + @TableField(value = "jobCode") | |
| 36 | 38 | private String jobCode; |
| 37 | 39 | |
| 38 | 40 | @Excel(name = "设备号") | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/in/service/impl/SignInServiceImpl.java
| ... | ... | @@ -193,6 +193,7 @@ public class SignInServiceImpl extends ServiceImpl<SignInMapper, SignIn> impleme |
| 193 | 193 | List<DriverScheduling> dto = schedulingService.queryScheduling(signIn.getJobCode(), now); |
| 194 | 194 | handleSignBody(signIn, driver, globalIndex, now, dto); |
| 195 | 195 | |
| 196 | + log.info("签到的数据为:[{}]",dto.get(globalIndex.getIndex())); | |
| 196 | 197 | if (PERSONNEL_POSTS_DRIVER.equals(driver.getPosts()) && Objects.equals(dto.get(globalIndex.getIndex()).getBcType(), BC_TYPE_OUT)) { |
| 197 | 198 | AjaxResult result = getAjaxResultByDriverSignInfo(signIn, vo); |
| 198 | 199 | if (!Objects.isNull(result)) { |
| ... | ... | @@ -201,16 +202,20 @@ public class SignInServiceImpl extends ServiceImpl<SignInMapper, SignIn> impleme |
| 201 | 202 | return result; |
| 202 | 203 | } |
| 203 | 204 | } |
| 204 | - | |
| 205 | - uploadImage(signIn, vo); | |
| 205 | + if(org.apache.commons.lang3.StringUtils.isNotEmpty(signIn.getImage())){ | |
| 206 | + uploadImage(signIn, vo); | |
| 207 | + } | |
| 208 | + signIn.setSchedulingId(dto.get(globalIndex.getIndex()).getId()); | |
| 206 | 209 | signInMapper.insertSignIn(signIn); |
| 207 | 210 | // 更新考勤 |
| 208 | 211 | schedulingService.computedSignInBySignIn(dto, signIn, globalIndex); |
| 209 | - | |
| 212 | + vo.setId(signIn.getId()); | |
| 210 | 213 | if (TempCache.checkJobCodeExist(signIn.getJobCode())) { |
| 211 | 214 | TempCache.updateSignStatus(signIn.getJobCode()); |
| 212 | 215 | } |
| 213 | 216 | |
| 217 | + | |
| 218 | + | |
| 214 | 219 | // 异常保存到异常异常中 |
| 215 | 220 | threadJobService.asyncInsertExceptionRecord(signIn, driver, dto, globalIndex); |
| 216 | 221 | |
| ... | ... | @@ -239,9 +244,9 @@ public class SignInServiceImpl extends ServiceImpl<SignInMapper, SignIn> impleme |
| 239 | 244 | if (SIGN_IN_SUCCESS.equals(signIn.getStatus())) { |
| 240 | 245 | String prompt = signIn.getRemark().replace("正常", ""); |
| 241 | 246 | if (signIn.getType().equals(SIGN_OUT)) { |
| 242 | - return AjaxResult.success(SIGN_OUT_SUCCESS_STRING + prompt, vo); | |
| 247 | + return AjaxResult.success(null, vo); | |
| 243 | 248 | } else { |
| 244 | - return AjaxResult.success(SIGN_IN_SUCCESS_STRING + prompt, vo); | |
| 249 | + return AjaxResult.success(null, vo); | |
| 245 | 250 | } |
| 246 | 251 | } else { |
| 247 | 252 | if (signIn.getType().equals(SIGN_OUT)) { |
| ... | ... | @@ -482,7 +487,7 @@ public class SignInServiceImpl extends ServiceImpl<SignInMapper, SignIn> impleme |
| 482 | 487 | redisCache.setCacheObject(key, ++count, 1, TimeUnit.DAYS); |
| 483 | 488 | } |
| 484 | 489 | if (SIGN_IN_ERROR_COUNT.compareTo(count) <= 0) { |
| 485 | - return AjaxResult.success(SIGN_IN_ERROR + ": " + signIn.getRemark() + "酒精测试不通过" + count + "次请更换车辆驾驶员。", vo); | |
| 490 | + return AjaxResult.error(SIGN_IN_ERROR + ": " + signIn.getRemark() + "酒精测试不通过" + count + "次请更换车辆驾驶员。", vo); | |
| 486 | 491 | } |
| 487 | 492 | return null; |
| 488 | 493 | } |
| ... | ... | @@ -673,8 +678,8 @@ public class SignInServiceImpl extends ServiceImpl<SignInMapper, SignIn> impleme |
| 673 | 678 | if (BC_TYPE_OUT.equals(currentScheduling.getBcType())) { |
| 674 | 679 | LocalDateTime time = ConstDateUtil.stringTransformLocalDateTime(ConstDateUtil.formatDate("yyyy-MM-dd HH:mm:ss", new Date(currentScheduling.getTimestamps())), "yyyy-MM-dd HH:mm:ss"); |
| 675 | 680 | LocalDateTime subHours = time.plusHours(-1); |
| 676 | - return "请在" + ConstDateUtil.formatDate("HH:mm", time) + "到" | |
| 677 | - + ConstDateUtil.formatDate("HH:mm", subHours) + "之间打卡"; | |
| 681 | + return "请在" + ConstDateUtil.formatDate("HH:mm", subHours) + "到" | |
| 682 | + + ConstDateUtil.formatDate("HH:mm", time) + "之间打卡"; | |
| 678 | 683 | } else { |
| 679 | 684 | // 延后一小时 |
| 680 | 685 | LocalDateTime time = ConstDateUtil.stringTransformLocalDateTime(ConstDateUtil.formatDate("yyyy-MM-dd HH:mm:ss", new Date(currentScheduling.getTimestamps())), "yyyy-MM-dd HH:mm:ss"); | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/pojo/response/SignInResponseVo.java
| 1 | 1 | package com.ruoyi.pojo.response; |
| 2 | -import java.math.BigDecimal; | |
| 3 | -import java.util.Date; | |
| 4 | -import com.google.common.collect.Maps; | |
| 5 | 2 | |
| 6 | 3 | import com.alibaba.excel.annotation.ExcelIgnore; |
| 7 | -import com.alibaba.excel.annotation.ExcelProperty; | |
| 8 | 4 | import com.ruoyi.common.annotation.Excel; |
| 9 | 5 | import com.ruoyi.in.domain.SignIn; |
| 10 | 6 | import lombok.Data; |
| ... | ... | @@ -30,6 +26,7 @@ public class SignInResponseVo extends SignIn { |
| 30 | 26 | */ |
| 31 | 27 | String date; |
| 32 | 28 | |
| 29 | + | |
| 33 | 30 | public SignInResponseVo(SignIn signIn){ |
| 34 | 31 | this.setDeviceId(signIn.getDeviceId()); |
| 35 | 32 | this.setId(signIn.getId()); | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/service/impl/driver/NewDriverServiceImpl.java
| ... | ... | @@ -173,7 +173,10 @@ public class NewDriverServiceImpl extends ServiceImpl<NewDriverMapper, NewDriver |
| 173 | 173 | @Override |
| 174 | 174 | public TipEnum updateClient(NewDriver entity) { |
| 175 | 175 | NewDriver driver = new NewDriver(); |
| 176 | - driver.setJobCode(entity.getJobCode()); | |
| 176 | + if(StringUtils.isNotEmpty(entity.getJobCode())) { | |
| 177 | + driver.setJobCode(entity.getJobCode()); | |
| 178 | + } | |
| 179 | + driver.setId(entity.getId()); | |
| 177 | 180 | NewDriver source = getOne(driver); |
| 178 | 181 | if (Objects.isNull(source)) { |
| 179 | 182 | log.info("[{}]找不到数据", entity); |
| ... | ... | @@ -185,7 +188,8 @@ public class NewDriverServiceImpl extends ServiceImpl<NewDriverMapper, NewDriver |
| 185 | 188 | wrapper.set(NewDriver::getImage, entity.getImage()).set(NewDriver::getFaceFeature, entity.getFaceFeature()) |
| 186 | 189 | .set(NewDriver::getBlueTooth, entity.getBlueTooth()).set(NewDriver::getInteger, entity.getInteger()) |
| 187 | 190 | .set(NewDriver::getSyncontent, entity.getSyncontent()).set(NewDriver::getCsn, entity.getCsn()) |
| 188 | - .eq(NewDriver::getId, entity.getJobCode()); | |
| 191 | + .set(NewDriver::getIcCardCode,entity.getIcCardCode()).set(NewDriver::getImageVersion,entity.getImageVersion()) | |
| 192 | + .eq(NewDriver::getId, entity.getId()); | |
| 189 | 193 | boolean flag = update(wrapper); |
| 190 | 194 | return flag ? TipEnum.TIP_200 : TipEnum.TIP_500; |
| 191 | 195 | } |
| ... | ... | @@ -193,7 +197,7 @@ public class NewDriverServiceImpl extends ServiceImpl<NewDriverMapper, NewDriver |
| 193 | 197 | @Override |
| 194 | 198 | public TipEnum faceRegister(NewDriver entity) { |
| 195 | 199 | NewDriver driver = new NewDriver(); |
| 196 | - driver.setIdRfid(entity.getIcCardCode()); | |
| 200 | + driver.setIcCardCode(entity.getIcCardCode()); | |
| 197 | 201 | NewDriver source = getOne(driver); |
| 198 | 202 | if (Objects.isNull(source)) { |
| 199 | 203 | log.info("[{}]找不到数据", entity); | ... | ... |
Bsth-admin/src/main/java/com/ruoyi/service/impl/dss/FaceServiceImpl.java
| 1 | 1 | package com.ruoyi.service.impl.dss; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.codec.Base64; | |
| 4 | 3 | import com.arcsoft.face.FaceEngine; |
| 5 | 4 | import com.arcsoft.face.FaceFeature; |
| 6 | 5 | import com.arcsoft.face.FaceInfo; |
| 7 | 6 | import com.arcsoft.face.FaceSimilar; |
| 8 | 7 | import com.arcsoft.face.enums.ErrorInfo; |
| 8 | +import com.arcsoft.face.toolkit.ImageFactory; | |
| 9 | 9 | import com.arcsoft.face.toolkit.ImageInfo; |
| 10 | +import com.ruoyi.common.utils.file.FileUploadUtils; | |
| 10 | 11 | import com.ruoyi.config.BsthSystemConfig; |
| 11 | 12 | import com.ruoyi.domain.driver.NewDriver; |
| 12 | 13 | import com.ruoyi.service.driver.NewDriverService; |
| 13 | 14 | import com.ruoyi.service.dss.FaceService; |
| 14 | 15 | import lombok.extern.slf4j.Slf4j; |
| 15 | 16 | import org.apache.commons.collections4.CollectionUtils; |
| 17 | +import org.apache.commons.io.IOUtils; | |
| 16 | 18 | import org.apache.commons.lang3.StringUtils; |
| 17 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
| 18 | 20 | import org.springframework.stereotype.Service; |
| 19 | 21 | |
| 22 | +import javax.imageio.ImageIO; | |
| 23 | +import java.awt.image.BufferedImage; | |
| 24 | +import java.io.ByteArrayInputStream; | |
| 20 | 25 | import java.io.File; |
| 26 | +import java.io.IOException; | |
| 21 | 27 | import java.util.*; |
| 22 | 28 | |
| 23 | 29 | import static com.arcsoft.face.toolkit.ImageFactory.getRGBData; |
| ... | ... | @@ -47,24 +53,41 @@ public class FaceServiceImpl implements FaceService { |
| 47 | 53 | if (CollectionUtils.isEmpty(drivers)) { |
| 48 | 54 | return null; |
| 49 | 55 | } |
| 50 | - | |
| 51 | - ImageInfo sourceImage = new ImageInfo(); | |
| 52 | - | |
| 53 | - byte[] sourceImageData = Base64.decode(sourceDriver.getImage()); | |
| 54 | - sourceImage.setImageData(sourceImageData); | |
| 55 | - FaceFeature sourceFaceFeature = generateFaceFeature(sourceDriver, sourceImage); | |
| 56 | - if (Objects.isNull(sourceFaceFeature)) { | |
| 56 | + if (StringUtils.isEmpty(sourceDriver.getImage())) { | |
| 57 | 57 | return null; |
| 58 | 58 | } |
| 59 | - | |
| 60 | - | |
| 61 | - Optional<NewDriver> optional = drivers.stream().map(dr -> { | |
| 62 | - float imageScore = checkFaceScore(dr, sourceFaceFeature); | |
| 63 | - dr.setImageScore(imageScore); | |
| 64 | - | |
| 65 | - return dr; | |
| 66 | - }).max(Comparator.comparing(NewDriver::getImageScore)); | |
| 67 | - return optional.isPresent() ? optional.get() : null; | |
| 59 | + ByteArrayInputStream byteArrayInputStream = null; | |
| 60 | + BufferedImage bufferedImage = null; | |
| 61 | + try { | |
| 62 | + String content = FileUploadUtils.choosePrictureContent(sourceDriver.getImage()); | |
| 63 | + byte[] sourceImageData = cn.hutool.core.codec.Base64.decode(content); | |
| 64 | + byteArrayInputStream = new ByteArrayInputStream(sourceImageData); | |
| 65 | + bufferedImage = ImageIO.read(byteArrayInputStream); | |
| 66 | + ImageInfo sourceImage = ImageFactory.bufferedImage2ImageInfo(bufferedImage); | |
| 67 | + | |
| 68 | + | |
| 69 | + FaceFeature sourceFaceFeature = generateFaceFeature(sourceDriver, sourceImage); | |
| 70 | + if (Objects.isNull(sourceFaceFeature)) { | |
| 71 | + return null; | |
| 72 | + } | |
| 73 | + | |
| 74 | + | |
| 75 | + Optional<NewDriver> optional = drivers.stream().map(dr -> { | |
| 76 | + float imageScore = checkFaceScore(dr, sourceFaceFeature); | |
| 77 | + dr.setImageScore(imageScore); | |
| 78 | + | |
| 79 | + return dr; | |
| 80 | + }).max(Comparator.comparing(NewDriver::getImageScore)); | |
| 81 | + | |
| 82 | + bufferedImage.flush(); | |
| 83 | + return optional.isPresent() ? optional.get() : null; | |
| 84 | + } catch (IOException e) { | |
| 85 | + sourceDriver.setImage(null); | |
| 86 | + log.error("图片校验异常:[{}]", sourceDriver, e); | |
| 87 | + } finally { | |
| 88 | + IOUtils.closeQuietly(byteArrayInputStream); | |
| 89 | + } | |
| 90 | + return null; | |
| 68 | 91 | } |
| 69 | 92 | |
| 70 | 93 | private float checkFaceScore(NewDriver dr, FaceFeature sourceFaceFeature) { |
| ... | ... | @@ -104,14 +127,14 @@ public class FaceServiceImpl implements FaceService { |
| 104 | 127 | List<FaceInfo> faceInfoList = new ArrayList<>(); |
| 105 | 128 | int errorCode = faceEngine.detectFaces(image.getImageData(), image.getWidth(), image.getHeight(), image.getImageFormat(), faceInfoList); |
| 106 | 129 | if (errorCode != ErrorInfo.MOK.getValue()) { |
| 107 | - log.error("人脸对比失败,请检查数据:[{}]", driver); | |
| 130 | + log.error("人脸对比失败,请检查数据:[{}];错误代码:[{}]", driver,errorCode); | |
| 108 | 131 | return null; |
| 109 | 132 | } |
| 110 | 133 | |
| 111 | 134 | FaceFeature faceFeature = new FaceFeature(); |
| 112 | 135 | errorCode = faceEngine.extractFaceFeature(image.getImageData(), image.getWidth(), image.getHeight(), image.getImageFormat(), faceInfoList.get(0), faceFeature); |
| 113 | 136 | if (errorCode != ErrorInfo.MOK.getValue()) { |
| 114 | - log.error("提取对比特征失败,请检查数据:[{}]", driver); | |
| 137 | + log.error("提取对比特征失败,请检查数据:[{}];错误代码:[{}]", driver,errorCode); | |
| 115 | 138 | return null; |
| 116 | 139 | } |
| 117 | 140 | return faceFeature; | ... | ... |
Bsth-admin/src/main/resources/application-druid-devTest.yml
| ... | ... | @@ -207,8 +207,8 @@ bsth: |
| 207 | 207 | app: |
| 208 | 208 | id: 8jPk3SNnaoGsd9SidMefgZXg1zbst64jB44vVyx9Cijq |
| 209 | 209 | sdk: |
| 210 | - # key: C21s5J1n1rHwXPkvVjubKshtfYuvuSe2GHus41Q1NPcT | |
| 211 | - key: C21s5J1n1rHwXPkvVjubKshtofV5sHXvyUQqSWYxHp2b | |
| 210 | + key: C21s5J1n1rHwXPkvVjubKshtfYuvuSe2GHus41Q1NPcT | |
| 211 | + # key: C21s5J1n1rHwXPkvVjubKshtofV5sHXvyUQqSWYxHp2b | |
| 212 | 212 | lib: |
| 213 | - # path: /data/test/bath-alcoho-sign/LINUX64 | |
| 214 | - path: D:/work/code/jienengjiancha/bsth-alcohol-sign/Bsth-admin/src/main/resources/libs/WIN64 | |
| 213 | + path: /data/test/bath-alcoho-sign/LINUX64 | |
| 214 | + # path: D:/work/code/jienengjiancha/bsth-alcohol-sign/Bsth-admin/src/main/resources/libs/WIN64 | ... | ... |
Bsth-admin/src/main/resources/mapper/driver/NewDriverMapper.xml
| ... | ... | @@ -29,7 +29,7 @@ |
| 29 | 29 | <result column="integer" jdbcType="INTEGER" property="integer"/> |
| 30 | 30 | <result column="synContent" jdbcType="VARCHAR" property="syncontent"/> |
| 31 | 31 | <result column="csn" jdbcType="VARCHAR" property="csn"/> |
| 32 | - <result column="image_version" jdbcType="INTEGER" property="imageVersion"/> | |
| 32 | + <result column="image_version" jdbcType="VARCHAR" property="imageVersion"/> | |
| 33 | 33 | </resultMap> |
| 34 | 34 | |
| 35 | 35 | <insert id="insertSelective" keyColumn="job_code" keyProperty="jobCode" useGeneratedKeys="true" |
| ... | ... | @@ -176,7 +176,7 @@ |
| 176 | 176 | <if test="null!=integer">integer = #{integer,jdbcType=INTEGER},</if> |
| 177 | 177 | <if test="null!=syncontent">synContent = #{syncontent,jdbcType=VARCHAR},</if> |
| 178 | 178 | <if test="null!=csn">csn = #{csn,jdbcType=VARCHAR},</if> |
| 179 | - <if test="null!=imageVersion">image_version = #{imageVersion,jdbcType=INTEGER},</if> | |
| 179 | + <if test="null!=imageVersion">image_version = #{imageVersion,jdbcType=VARCHAR},</if> | |
| 180 | 180 | </set> |
| 181 | 181 | </sql> |
| 182 | 182 | |
| ... | ... | @@ -208,6 +208,6 @@ |
| 208 | 208 | <if test="null!=integer">AND integer = #{integer,jdbcType=INTEGER},</if> |
| 209 | 209 | <if test="null!=syncontent">AND synContent = #{syncontent,jdbcType=VARCHAR},</if> |
| 210 | 210 | <if test="null!=csn">AND csn = #{csn,jdbcType=VARCHAR},</if> |
| 211 | - <if test="null!=imageVersion">AND image_version = #{imageVersion,jdbcType=INTEGER},</if> | |
| 211 | + <if test="null!=imageVersion">AND image_version = #{imageVersion,jdbcType=VARCHAR},</if> | |
| 212 | 212 | </sql> |
| 213 | 213 | </mapper> |
| 214 | 214 | \ No newline at end of file | ... | ... |
Bsth-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
| ... | ... | @@ -47,6 +47,7 @@ public class FileUploadUtils { |
| 47 | 47 | * 默认上传的地址 |
| 48 | 48 | */ |
| 49 | 49 | private static String defaultBaseDir = RuoYiConfig.getProfile(); |
| 50 | + private static String uploadContent; | |
| 50 | 51 | |
| 51 | 52 | public static void setDefaultBaseDir(String defaultBaseDir) { |
| 52 | 53 | FileUploadUtils.defaultBaseDir = defaultBaseDir; |
| ... | ... | @@ -128,17 +129,23 @@ public class FileUploadUtils { |
| 128 | 129 | * @return ResponseResult 文件上传成功返回文件路径;上传异常返回500;文件超大返回1;不是图片返回2 |
| 129 | 130 | */ |
| 130 | 131 | public static ResponseResult<String> uploadBase64OfImage(String filePath, String fileName, String type, String uploadContent) { |
| 132 | + FileUploadUtils.uploadContent = uploadContent; | |
| 131 | 133 | ByteArrayInputStream byteArrayInputStream = null; |
| 132 | 134 | BufferedImage bufferedImage = null; |
| 133 | 135 | try { |
| 136 | + if (org.apache.commons.lang3.StringUtils.isEmpty(uploadContent)) { | |
| 137 | + return new ResponseResult<>(2, "请上传图片"); | |
| 138 | + } | |
| 139 | + | |
| 140 | + uploadContent = choosePrictureContent(uploadContent); | |
| 134 | 141 | File file = new File(filePath); |
| 135 | 142 | if (!file.isDirectory()) { |
| 136 | 143 | FileUtils.forceMkdir(file); |
| 137 | 144 | } |
| 145 | + | |
| 138 | 146 | byte[] content = Base64.decode(uploadContent); |
| 139 | 147 | if (ArrayUtils.getLength(content) > DEFAULT_MAX_SIZE) { |
| 140 | - LOGGER.info("[{}]上传的图片超过了50M", filePath); | |
| 141 | - return new ResponseResult<>(1); | |
| 148 | + | |
| 142 | 149 | } |
| 143 | 150 | byteArrayInputStream = new ByteArrayInputStream(content); |
| 144 | 151 | bufferedImage = ImageIO.read(byteArrayInputStream); |
| ... | ... | @@ -158,15 +165,28 @@ public class FileUploadUtils { |
| 158 | 165 | boolean flag = ImageIO.write(bufferedImage, type, new File(path.toString())); |
| 159 | 166 | bufferedImage.flush(); |
| 160 | 167 | |
| 161 | - return flag ? ResponseResult.success(path.toString()) : new ResponseResult<>(500); | |
| 168 | + if (Objects.equals(Boolean.FALSE, flag)) { | |
| 169 | + return new ResponseResult<>(500); | |
| 170 | + } | |
| 171 | + ResponseResult<String> responseResult = ResponseResult.success(); | |
| 172 | + responseResult.setData(path.toString()); | |
| 173 | + | |
| 174 | + return responseResult; | |
| 162 | 175 | } catch (Exception e) { |
| 163 | - LOGGER.error("上传图片异常,上传的路径为:[{}]", filePath); | |
| 176 | + LOGGER.error("上传图片异常,上传的路径为:[{}]", filePath, e); | |
| 164 | 177 | } finally { |
| 165 | 178 | IOUtils.closeQuietly(byteArrayInputStream); |
| 166 | 179 | } |
| 167 | 180 | return new ResponseResult<>(500); |
| 168 | 181 | } |
| 169 | 182 | |
| 183 | + public static String choosePrictureContent(String uploadContent) { | |
| 184 | + if (org.apache.commons.lang3.StringUtils.indexOf(uploadContent, ";base64,")>0) { | |
| 185 | + uploadContent = org.apache.commons.lang3.StringUtils.substringAfter(uploadContent, ";base64,"); | |
| 186 | + } | |
| 187 | + return uploadContent; | |
| 188 | + } | |
| 189 | + | |
| 170 | 190 | /** |
| 171 | 191 | * 编码文件名 |
| 172 | 192 | */ | ... | ... |