Commit b1aa1c06ca4c9a32039e4de59b01da11c6561b4b

Authored by guzijian
1 parent 75bf6eaa

fix: 人脸注册更新

ruoyi-admin/src/main/java/com/ruoyi/common/global/Result.java 0 → 100644
  1 +package com.ruoyi.common.global;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +
  7 +import static com.ruoyi.common.global.ResultCode.CODE_200;
  8 +import static com.ruoyi.common.global.ResultCode.CODE_500;
  9 +
  10 +
  11 +/**
  12 + * 返回结果
  13 + * @author 20412
  14 + */
  15 +@Data
  16 +@ApiModel("返回结果")
  17 +public class Result<T extends Object> {
  18 +
  19 + @ApiModelProperty(value = "是否成功")
  20 + private Boolean success;
  21 +
  22 + @ApiModelProperty(value = "状态码")
  23 + private Integer code;
  24 +
  25 + @ApiModelProperty(value = "返回消息")
  26 + private String msg;
  27 +
  28 + @ApiModelProperty(value = "返回对象")
  29 + private T data ;
  30 +
  31 + private Result() {}
  32 +
  33 + /** 成功静态方法 */
  34 + public static Result OK() {
  35 + Result r = new Result();
  36 + r.setSuccess(true);
  37 + r.setCode(CODE_200.getCode());
  38 + r.setMsg("成功");
  39 + return r;
  40 + }
  41 +
  42 + /** 成功静态方法 */
  43 + public static <T> Result<T> OK(T data) {
  44 + Result r = new Result();
  45 + r.setSuccess(true);
  46 + r.setCode(CODE_200.getCode());
  47 + r.setData(data);
  48 + r.setMsg("成功");
  49 + return r;
  50 + }
  51 +
  52 + /** 成功静态方法 */
  53 + public static <T> Result<T> OK(T data, String message) {
  54 + Result r = new Result();
  55 + r.setSuccess(true);
  56 + r.setCode(CODE_200.getCode());
  57 + r.setData(data);
  58 + r.setMsg(message);
  59 + return r;
  60 + }
  61 +
  62 + /** 失败静态方法 */
  63 + public static Result ERROR() {
  64 + Result r = new Result();
  65 + r.setSuccess(false);
  66 + r.setCode(CODE_500.getCode());
  67 + r.setMsg("失败");
  68 + return r;
  69 + }
  70 +
  71 + /** 失败静态方法 */
  72 + public static Result ERROR(String message) {
  73 + Result r = new Result();
  74 + r.setSuccess(false);
  75 + r.setCode(CODE_500.getCode());
  76 + r.setMsg(message);
  77 + return r;
  78 + }
  79 +
  80 + /** 设置状态码 */
  81 + public Result code(Integer code){
  82 + this.setCode(code);
  83 + return this;
  84 + }
  85 +
  86 + /** 设置集合 */
  87 + public Result<T> data(T map){
  88 + this.setData(map);
  89 + return this;
  90 + }
  91 +}
... ...
ruoyi-admin/src/main/java/com/ruoyi/common/global/ResultCode.java 0 → 100644
  1 +package com.ruoyi.common.global;
  2 +
  3 +public enum ResultCode {
  4 +
  5 + /*
  6 + * 错误信息
  7 + * */
  8 + CODE_200(200, "操作成功"),
  9 + CODE_201(201,"对象创建成功"),
  10 + CODE_202(202,"请求已经被接受"),
  11 + CODE_400(400,"参数列表错误(缺少,格式不匹配)"),
  12 + CODE_401(401,"未授权"),
  13 + CODE_403(403,"访问受限,授权过期"),
  14 + CODE_404(404,"资源,服务未找到"),
  15 + CODE_500(500,"操作失败"),
  16 + ;
  17 +
  18 + private Integer Code;
  19 + private String Msg;
  20 + ResultCode(Integer Code, String Msg) {
  21 + this.Code = Code;
  22 + this.Msg = Msg;
  23 + }
  24 + public Integer getCode() {
  25 + return Code;
  26 + }
  27 + public String getMsg() {
  28 + return Msg;
  29 + }
  30 +}
0 31 \ No newline at end of file
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/controller/DriverController.java
... ... @@ -4,6 +4,8 @@ import java.util.List;
4 4 import javax.servlet.http.HttpServletRequest;
5 5 import javax.servlet.http.HttpServletResponse;
6 6  
  7 +import com.ruoyi.common.global.Result;
  8 +import com.ruoyi.pojo.request.DriverSignInRequestVo;
7 9 import com.ruoyi.pojo.request.FaceRegistrationFeedbackVo;
8 10 import com.ruoyi.pojo.request.FaceUpdateReqVo;
9 11 import io.swagger.annotations.Api;
... ... @@ -113,6 +115,19 @@ public class DriverController extends BaseController {
113 115 }
114 116  
115 117  
  118 + /**
  119 + * 新增驾驶员信息
  120 + */
  121 +// @PreAuthorize("@ss.hasPermi('driver:driver:add')")
  122 +// @Log(title = "驾驶员信息", businessType = BusinessType.INSERT)
  123 + @PostMapping("/driver/sign")
  124 + @ApiOperation("新增驾驶员信息(设备传入)")
  125 + public Result<?> addNewDriver(@ApiParam @RequestBody @Validated DriverSignInRequestVo vo) {
  126 + driverService.saveDriverSignInfo(vo);
  127 + return Result.OK();
  128 + }
  129 +
  130 +
116 131  
117 132 /**
118 133 * 修改驾驶员信息
... ... @@ -163,6 +178,7 @@ public class DriverController extends BaseController {
163 178 return driverService.checkJobCode(driver);
164 179 }
165 180  
  181 +
166 182 @PostMapping("/upload")
167 183 @ApiOperation("驾驶员人脸上传接口")
168 184 public AjaxResult uploadImage(MultipartFile file) {
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/service/IDriverService.java
... ... @@ -6,6 +6,7 @@ import java.util.List;
6 6 import com.ruoyi.common.core.domain.AjaxResult;
7 7 import com.ruoyi.common.exception.file.InvalidExtensionException;
8 8 import com.ruoyi.driver.domain.Driver;
  9 +import com.ruoyi.pojo.request.DriverSignInRequestVo;
9 10 import com.ruoyi.pojo.request.FaceUpdateReqVo;
10 11 import com.ruoyi.pojo.response.ResponseScheduling;
11 12 import org.springframework.web.multipart.MultipartFile;
... ... @@ -95,4 +96,6 @@ public interface IDriverService
95 96 void updateDriverByComputed();
96 97  
97 98 void updateFaceByJob(HttpServletRequest request, FaceUpdateReqVo vo);
  99 +
  100 + void saveDriverSignInfo(DriverSignInRequestVo vo);
98 101 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/service/impl/DriverServiceImpl.java
... ... @@ -17,8 +17,10 @@ import com.ruoyi.common.utils.file.FileUtils;
17 17 import com.ruoyi.common.utils.file.MimeTypeUtils;
18 18 import com.ruoyi.equipment.mapper.EquipmentMapper;
19 19 import com.ruoyi.framework.config.ServerConfig;
  20 +import com.ruoyi.in.domain.SignIn;
20 21 import com.ruoyi.job.DriverJob;
21 22 import com.ruoyi.pojo.domain.EquipmentDriverExpand;
  23 +import com.ruoyi.pojo.request.DriverSignInRequestVo;
22 24 import com.ruoyi.pojo.request.FaceUpdateReqVo;
23 25 import com.ruoyi.pojo.response.ResponseScheduling;
24 26 import com.ruoyi.service.ThreadJobService;
... ... @@ -42,6 +44,7 @@ import javax.servlet.http.HttpServletResponse;
42 44  
43 45 import static com.ruoyi.common.ApiProperties.PERSONNEL_API_KEY;
44 46 import static com.ruoyi.common.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE;
  47 +import static com.ruoyi.in.service.impl.SignInServiceImpl.checkImageBase64Format;
45 48  
46 49 /**
47 50 * 驾驶员信息Service业务层处理
... ... @@ -312,6 +315,29 @@ public class DriverServiceImpl implements IDriverService {
312 315 log.info("删除注册表中对应工号的数据结束");
313 316 }
314 317  
  318 + @Override
  319 + public void saveDriverSignInfo(DriverSignInRequestVo vo) {
  320 + Driver driver = new Driver();
  321 + driver.setJobCode(vo.getJobCode());
  322 + driver.setPersonnelName(vo.getName());
  323 + driver.setPosts(vo.getPosts());
  324 + String base64 = vo.getImage();
  325 + String fileName = vo.getJobCode() + ".png";
  326 + String filePath = new File(RuoYiConfig.getUploadPath() + headImagePre + "/" + fileName + File.separator).getAbsolutePath();
  327 + try {
  328 + fileName = FileUploadUtils.getPathFileName(RuoYiConfig.getUploadPath() + headImagePre, fileName);
  329 + } catch (IOException e) {
  330 + throw new RuntimeException(e);
  331 + }
  332 + driver.setImage(fileName);
  333 + driver.setUpdateTime(new Date());
  334 + int result = driverMapper.insertDriver(driver);
  335 + if (result == 0) driverMapper.updateDriversByJobCodes(new ArrayList<>(Arrays.asList(driver)));
  336 + log.info("开始上传签到图片");
  337 + // 异步上传文件
  338 + threadJobService.asyncStartUploadBase64Image(filePath, base64);
  339 + }
  340 +
315 341 /**
316 342 * 获取新的imageUrl
317 343 *
... ...
ruoyi-admin/src/main/java/com/ruoyi/in/service/impl/SignInServiceImpl.java
... ... @@ -243,7 +243,7 @@ public class SignInServiceImpl implements ISignInService {
243 243 // 酒精测试校验 确定 且员工工种是驾驶员
244 244 if (ALCOHOL_FLAG_YES.equals(signIn.getAlcoholFlag()) && PERSONNEL_POSTS_DRIVER.equals(driver.getPosts())) {
245 245 if (new BigDecimal(20).compareTo(signIn.getAlcoholIntake()) <= 0) {
246   - signIn.setRemark(signIn.getRemark() + ALCOHOL_SIGN_IN_ERROR);
  246 + signIn.setRemark(signIn.getRemark() + ALCOHOL_SIGN_IN_ERROR + "," + signIn.getAlcoholIntake().toString() +"mg/100ml");
247 247 result = false;
248 248 }
249 249 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/pojo/request/DriverSignInRequestVo.java 0 → 100644
  1 +package com.ruoyi.pojo.request;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +
  7 +import javax.validation.constraints.NotBlank;
  8 +
  9 +/**
  10 + *
  11 + * @author 20412
  12 + */
  13 +@Data
  14 +@ApiModel("注册对象")
  15 +public class DriverSignInRequestVo {
  16 + @NotBlank
  17 + @ApiModelProperty("工号")
  18 + String jobCode;
  19 + @NotBlank
  20 + @ApiModelProperty("姓名")
  21 + String name;
  22 + @NotBlank
  23 + @ApiModelProperty("工种")
  24 + String posts;
  25 + @ApiModelProperty("图片")
  26 + String image;
  27 +}
... ...