Commit 85dca6513325171a39c92303ff0294184b3444fa
1 parent
e195407a
fix: 更新人脸数据接口
Showing
8 changed files
with
142 additions
and
24 deletions
ruoyi-admin/src/main/java/com/ruoyi/common/ApiProperties.java
0 → 100644
ruoyi-admin/src/main/java/com/ruoyi/driver/controller/DriverController.java
| 1 | package com.ruoyi.driver.controller; | 1 | package com.ruoyi.driver.controller; |
| 2 | 2 | ||
| 3 | import java.util.List; | 3 | import java.util.List; |
| 4 | +import javax.servlet.http.HttpServletRequest; | ||
| 4 | import javax.servlet.http.HttpServletResponse; | 5 | import javax.servlet.http.HttpServletResponse; |
| 5 | 6 | ||
| 6 | import com.ruoyi.pojo.request.FaceRegistrationFeedbackVo; | 7 | import com.ruoyi.pojo.request.FaceRegistrationFeedbackVo; |
| @@ -9,6 +10,7 @@ import io.swagger.annotations.Api; | @@ -9,6 +10,7 @@ import io.swagger.annotations.Api; | ||
| 9 | import io.swagger.annotations.ApiOperation; | 10 | import io.swagger.annotations.ApiOperation; |
| 10 | import io.swagger.annotations.ApiParam; | 11 | import io.swagger.annotations.ApiParam; |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 13 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | import org.springframework.web.bind.annotation.*; | 14 | import org.springframework.web.bind.annotation.*; |
| 13 | import com.ruoyi.common.annotation.Log; | 15 | import com.ruoyi.common.annotation.Log; |
| 14 | import com.ruoyi.common.core.controller.BaseController; | 16 | import com.ruoyi.common.core.controller.BaseController; |
| @@ -126,12 +128,14 @@ public class DriverController extends BaseController { | @@ -126,12 +128,14 @@ public class DriverController extends BaseController { | ||
| 126 | 128 | ||
| 127 | /** | 129 | /** |
| 128 | * 人脸数据更新接口 | 130 | * 人脸数据更新接口 |
| 131 | + * @param request 请求头 | ||
| 129 | * @param vo 更新实际数据 | 132 | * @param vo 更新实际数据 |
| 130 | */ | 133 | */ |
| 134 | + @ApiOperation("人脸数据更新接口") | ||
| 131 | @PostMapping("/update/face") | 135 | @PostMapping("/update/face") |
| 132 | - public AjaxResult updateFaceByJob(List<FaceUpdateReqVo> vo){ | 136 | + public AjaxResult updateFaceByJob(HttpServletRequest request, @ApiParam @Validated @RequestBody List<FaceUpdateReqVo> vo){ |
| 133 | // TODO 人脸数据更新接口 | 137 | // TODO 人脸数据更新接口 |
| 134 | - driverService.updateFaceByJob(vo); | 138 | + driverService.updateFaceByJob(request,vo); |
| 135 | return AjaxResult.success(); | 139 | return AjaxResult.success(); |
| 136 | } | 140 | } |
| 137 | 141 |
ruoyi-admin/src/main/java/com/ruoyi/driver/mapper/DriverMapper.java
| @@ -102,4 +102,8 @@ public interface DriverMapper | @@ -102,4 +102,8 @@ public interface DriverMapper | ||
| 102 | Integer insertDriverFace(@Param("deviceId") String deviceId, @Param("jobCodes")List<String> jobCodes); | 102 | Integer insertDriverFace(@Param("deviceId") String deviceId, @Param("jobCodes")List<String> jobCodes); |
| 103 | 103 | ||
| 104 | void updateDriverByComputed(@Param("count")Integer count); | 104 | void updateDriverByComputed(@Param("count")Integer count); |
| 105 | + | ||
| 106 | + void updateDriversByJobCodes(@Param("list") List<Driver> list); | ||
| 107 | + | ||
| 108 | + void deleteDeviceIdAssociatedJobCode(@Param("jobCodes") List<String> jobCodes); | ||
| 105 | } | 109 | } |
ruoyi-admin/src/main/java/com/ruoyi/driver/service/IDriverService.java
| @@ -10,6 +10,7 @@ import com.ruoyi.pojo.request.FaceUpdateReqVo; | @@ -10,6 +10,7 @@ import com.ruoyi.pojo.request.FaceUpdateReqVo; | ||
| 10 | import com.ruoyi.pojo.response.ResponseScheduling; | 10 | import com.ruoyi.pojo.response.ResponseScheduling; |
| 11 | import org.springframework.web.multipart.MultipartFile; | 11 | import org.springframework.web.multipart.MultipartFile; |
| 12 | 12 | ||
| 13 | +import javax.servlet.http.HttpServletRequest; | ||
| 13 | import javax.servlet.http.HttpServletResponse; | 14 | import javax.servlet.http.HttpServletResponse; |
| 14 | 15 | ||
| 15 | /** | 16 | /** |
| @@ -93,5 +94,5 @@ public interface IDriverService | @@ -93,5 +94,5 @@ public interface IDriverService | ||
| 93 | 94 | ||
| 94 | void updateDriverByComputed(); | 95 | void updateDriverByComputed(); |
| 95 | 96 | ||
| 96 | - void updateFaceByJob(List<FaceUpdateReqVo> vo); | 97 | + void updateFaceByJob(HttpServletRequest request, List<FaceUpdateReqVo> vo); |
| 97 | } | 98 | } |
ruoyi-admin/src/main/java/com/ruoyi/driver/service/impl/DriverServiceImpl.java
| @@ -2,6 +2,7 @@ package com.ruoyi.driver.service.impl; | @@ -2,6 +2,7 @@ package com.ruoyi.driver.service.impl; | ||
| 2 | 2 | ||
| 3 | import java.io.File; | 3 | import java.io.File; |
| 4 | import java.io.IOException; | 4 | import java.io.IOException; |
| 5 | +import java.io.InputStream; | ||
| 5 | import java.nio.file.Paths; | 6 | import java.nio.file.Paths; |
| 6 | import java.util.*; | 7 | import java.util.*; |
| 7 | import java.util.stream.Collectors; | 8 | import java.util.stream.Collectors; |
| @@ -21,9 +22,12 @@ import com.ruoyi.pojo.request.FaceUpdateReqVo; | @@ -21,9 +22,12 @@ import com.ruoyi.pojo.request.FaceUpdateReqVo; | ||
| 21 | import com.ruoyi.pojo.response.ResponseScheduling; | 22 | import com.ruoyi.pojo.response.ResponseScheduling; |
| 22 | import com.ruoyi.service.ThreadJobService; | 23 | import com.ruoyi.service.ThreadJobService; |
| 23 | import com.ruoyi.utils.ConstDateUtil; | 24 | import com.ruoyi.utils.ConstDateUtil; |
| 25 | +import com.ruoyi.utils.HttpUtils; | ||
| 24 | import com.ruoyi.utils.ListUtils; | 26 | import com.ruoyi.utils.ListUtils; |
| 25 | import org.apache.commons.io.FilenameUtils; | 27 | import org.apache.commons.io.FilenameUtils; |
| 26 | import org.apache.tomcat.util.buf.StringUtils; | 28 | import org.apache.tomcat.util.buf.StringUtils; |
| 29 | +import org.slf4j.Logger; | ||
| 30 | +import org.slf4j.LoggerFactory; | ||
| 27 | import org.springframework.beans.factory.annotation.Autowired; | 31 | import org.springframework.beans.factory.annotation.Autowired; |
| 28 | import org.springframework.beans.factory.annotation.Value; | 32 | import org.springframework.beans.factory.annotation.Value; |
| 29 | import org.springframework.stereotype.Service; | 33 | import org.springframework.stereotype.Service; |
| @@ -33,8 +37,10 @@ import com.ruoyi.driver.service.IDriverService; | @@ -33,8 +37,10 @@ import com.ruoyi.driver.service.IDriverService; | ||
| 33 | import org.springframework.web.multipart.MultipartFile; | 37 | import org.springframework.web.multipart.MultipartFile; |
| 34 | 38 | ||
| 35 | import javax.servlet.ServletOutputStream; | 39 | import javax.servlet.ServletOutputStream; |
| 40 | +import javax.servlet.http.HttpServletRequest; | ||
| 36 | import javax.servlet.http.HttpServletResponse; | 41 | import javax.servlet.http.HttpServletResponse; |
| 37 | 42 | ||
| 43 | +import static com.ruoyi.common.ApiProperties.PERSONNEL_API_KEY; | ||
| 38 | import static com.ruoyi.common.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE; | 44 | import static com.ruoyi.common.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE; |
| 39 | 45 | ||
| 40 | /** | 46 | /** |
| @@ -46,6 +52,8 @@ import static com.ruoyi.common.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE | @@ -46,6 +52,8 @@ import static com.ruoyi.common.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE | ||
| 46 | @Service | 52 | @Service |
| 47 | public class DriverServiceImpl implements IDriverService { | 53 | public class DriverServiceImpl implements IDriverService { |
| 48 | 54 | ||
| 55 | + private Logger log = LoggerFactory.getLogger(DriverServiceImpl.class); | ||
| 56 | + | ||
| 49 | @Autowired | 57 | @Autowired |
| 50 | private EquipmentMapper equipmentMapper; | 58 | private EquipmentMapper equipmentMapper; |
| 51 | @Value("${api.url.getSchedulingInfo}") | 59 | @Value("${api.url.getSchedulingInfo}") |
| @@ -264,8 +272,64 @@ public class DriverServiceImpl implements IDriverService { | @@ -264,8 +272,64 @@ public class DriverServiceImpl implements IDriverService { | ||
| 264 | } | 272 | } |
| 265 | 273 | ||
| 266 | @Override | 274 | @Override |
| 267 | - public void updateFaceByJob(List<FaceUpdateReqVo> vo) { | ||
| 268 | -// if () | 275 | + public void updateFaceByJob(HttpServletRequest request, List<FaceUpdateReqVo> faceDataList) { |
| 276 | + // 获取校验 | ||
| 277 | + String header = request.getHeader("X-TOKEN-AUTHORIZATION"); | ||
| 278 | + if (!PERSONNEL_API_KEY.equals(header)){ | ||
| 279 | + throw new RuntimeException("X-TOKEN-AUTHORIZATION value error"); | ||
| 280 | + } | ||
| 281 | + Date date = new Date(); | ||
| 282 | + List<Driver> drivers = faceDataList.stream().map(item -> { | ||
| 283 | + Driver driver = new Driver(); | ||
| 284 | + driver.setPosts(item.getPosts()); | ||
| 285 | + driver.setJobCode(item.getJobCode()); | ||
| 286 | + try { | ||
| 287 | + driver.setImage(getNewImageUrl(item.getJobCode(),item.getImageUrl())); | ||
| 288 | + } catch (IOException e) { | ||
| 289 | + log.info(e.getMessage()); | ||
| 290 | + throw new RuntimeException(e); | ||
| 291 | + } | ||
| 292 | + driver.setPersonnelName(item.getName()); | ||
| 293 | + driver.setUpdateTime(date); | ||
| 294 | + return driver; | ||
| 295 | + }).collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(s -> s.getJobCode()))), ArrayList::new)); | ||
| 296 | + List<List<Driver>> lists = ListUtils.splitList(drivers, 400); | ||
| 297 | + log.info("开始人脸数据更新"); | ||
| 298 | + // 数据更新 更新人脸注册标识 更新基本数据 | ||
| 299 | + for (List<Driver> list : lists) { | ||
| 300 | + driverMapper.updateDriversByJobCodes(list); | ||
| 301 | + } | ||
| 302 | + log.info("人脸数据更新完成"); | ||
| 303 | + // 删除注册表中对应工号的数据 | ||
| 304 | + List<String> jobCodes = drivers.stream().map(Driver::getJobCode).collect(Collectors.toList()); | ||
| 305 | + log.info("开始删除注册表中对应工号的数据"); | ||
| 306 | + driverMapper.deleteDeviceIdAssociatedJobCode(jobCodes); | ||
| 307 | + log.info("删除注册表中对应工号的数据结束"); | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + /** | ||
| 311 | + * 获取新的imageUrl | ||
| 312 | + * | ||
| 313 | + * @param jobCode | ||
| 314 | + * @param url | ||
| 315 | + * @return | ||
| 316 | + */ | ||
| 317 | + private String getNewImageUrl(String jobCode,String url) throws IOException { | ||
| 318 | + // 生成文件路径 | ||
| 319 | + String fileName = jobCode + ".png"; | ||
| 320 | + String filePath = RuoYiConfig.getUploadPath() + headImagePre + "/" + fileName; | ||
| 321 | + try { | ||
| 322 | + fileName = FileUploadUtils.getPathFileName(RuoYiConfig.getUploadPath() + headImagePre, fileName); | ||
| 323 | + } catch (IOException e) { | ||
| 324 | + throw new RuntimeException(e); | ||
| 325 | + } | ||
| 326 | + log.debug("图片开始上传"); | ||
| 327 | + // 获取图片数据 | ||
| 328 | + InputStream is = HttpUtils.doGet(url, new HashMap<>()); | ||
| 329 | + // 上传图片 | ||
| 330 | + ThreadJobService.uploadImage(is, filePath); | ||
| 331 | + log.debug("图片上传完毕"); | ||
| 332 | + return fileName; | ||
| 269 | } | 333 | } |
| 270 | 334 | ||
| 271 | private File getLocationFile(String jobCode) { | 335 | private File getLocationFile(String jobCode) { |
ruoyi-admin/src/main/java/com/ruoyi/pojo/request/FaceUpdateReqVo.java
| 1 | package com.ruoyi.pojo.request; | 1 | package com.ruoyi.pojo.request; |
| 2 | 2 | ||
| 3 | +import io.swagger.annotations.ApiModel; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 3 | import lombok.Data; | 5 | import lombok.Data; |
| 4 | 6 | ||
| 5 | import javax.validation.constraints.NotBlank; | 7 | import javax.validation.constraints.NotBlank; |
| 8 | +import javax.validation.constraints.NotEmpty; | ||
| 9 | +import java.util.List; | ||
| 6 | 10 | ||
| 7 | /** | 11 | /** |
| 8 | * 人脸更新数据 | 12 | * 人脸更新数据 |
| 9 | * @author 20412 | 13 | * @author 20412 |
| 10 | */ | 14 | */ |
| 11 | @Data | 15 | @Data |
| 16 | +@ApiModel("人脸更新数据") | ||
| 12 | public class FaceUpdateReqVo { | 17 | public class FaceUpdateReqVo { |
| 13 | - /** | ||
| 14 | - * 工号 | ||
| 15 | - */ | ||
| 16 | - @NotBlank | ||
| 17 | - String jobCode; | ||
| 18 | - /** | ||
| 19 | - * 图片base64 | ||
| 20 | - */ | ||
| 21 | - String imageUrl; | ||
| 22 | - /** | ||
| 23 | - * 姓名 | ||
| 24 | - */ | ||
| 25 | - String name; | ||
| 26 | - /** | ||
| 27 | - * 工种 | ||
| 28 | - */ | ||
| 29 | - String posts; | 18 | + /** |
| 19 | + * 工号 | ||
| 20 | + */ | ||
| 21 | + @ApiModelProperty("工号") | ||
| 22 | + @NotBlank(message = "工号不能为空") | ||
| 23 | + String jobCode; | ||
| 24 | + /** | ||
| 25 | + * 图片url不能为空 | ||
| 26 | + */ | ||
| 27 | + @ApiModelProperty("图片url") | ||
| 28 | + @NotBlank(message = "图片url不能为空") | ||
| 29 | + String imageUrl; | ||
| 30 | + /** | ||
| 31 | + * 姓名 | ||
| 32 | + */ | ||
| 33 | + @ApiModelProperty("姓名") | ||
| 34 | + @NotBlank(message = "姓名不能为空") | ||
| 35 | + String name; | ||
| 36 | + /** | ||
| 37 | + * 工种 | ||
| 38 | + */ | ||
| 39 | + @ApiModelProperty("工种") | ||
| 40 | + @NotBlank(message = "工种不能为空") | ||
| 41 | + String posts; | ||
| 30 | } | 42 | } |
ruoyi-admin/src/main/java/com/ruoyi/service/ThreadJobService.java
| @@ -126,14 +126,22 @@ public class ThreadJobService { | @@ -126,14 +126,22 @@ public class ThreadJobService { | ||
| 126 | // 获取图片数据 | 126 | // 获取图片数据 |
| 127 | InputStream is = HttpUtils.doGet(imageUrl, new HashMap<>()); | 127 | InputStream is = HttpUtils.doGet(imageUrl, new HashMap<>()); |
| 128 | // 上传图片 | 128 | // 上传图片 |
| 129 | - uploadImage(is, filePath); | 129 | + try { |
| 130 | + uploadImage(is, filePath); | ||
| 131 | + } catch (IOException e) { | ||
| 132 | + log.error(e.getMessage()); | ||
| 133 | + throw new RuntimeException(e); | ||
| 134 | + } | ||
| 130 | log.debug("图片上传完毕"); | 135 | log.debug("图片上传完毕"); |
| 131 | } | 136 | } |
| 132 | 137 | ||
| 133 | 138 | ||
| 134 | } | 139 | } |
| 135 | 140 | ||
| 136 | - private void uploadImage(InputStream is, String filePath) { | 141 | + public static void uploadImage(InputStream is, String filePath) throws IOException { |
| 142 | + if (Objects.isNull(is)){ | ||
| 143 | + throw new IOException("图片数据不存在"); | ||
| 144 | + } | ||
| 137 | File file = new File(filePath + File.separator); | 145 | File file = new File(filePath + File.separator); |
| 138 | log.info("文件路径:{}",file.getPath()); | 146 | log.info("文件路径:{}",file.getPath()); |
| 139 | if (!file.exists()) { | 147 | if (!file.exists()) { |
ruoyi-admin/src/main/resources/mapper/driver/DriverMapper.xml
| @@ -245,6 +245,13 @@ | @@ -245,6 +245,13 @@ | ||
| 245 | HAVING COUNT(*) = #{count} | 245 | HAVING COUNT(*) = #{count} |
| 246 | ); | 246 | ); |
| 247 | </update> | 247 | </update> |
| 248 | + <update id="updateDriversByJobCodes"> | ||
| 249 | + <foreach collection="list" item="item" separator=";"> | ||
| 250 | + update driver set face_sign_in = 1, | ||
| 251 | + personnel_name = #{item.personnelName,jdbcType=VARCHAR},posts = #{item.posts,jdbcType=VARCHAR},image = #{item.image,jdbcType=VARCHAR},update_time = #{item.updateTime} | ||
| 252 | + where job_code = #{item.jobCode,jdbcType=VARCHAR} | ||
| 253 | + </foreach> | ||
| 254 | + </update> | ||
| 248 | <insert id="saveDriverScheduling"> | 255 | <insert id="saveDriverScheduling"> |
| 249 | INSERT INTO driver_scheduling ( | 256 | INSERT INTO driver_scheduling ( |
| 250 | id, scheduleDate, lineName, lineCode, lpName, | 257 | id, scheduleDate, lineName, lineCode, lpName, |
| @@ -301,6 +308,13 @@ | @@ -301,6 +308,13 @@ | ||
| 301 | #{id} | 308 | #{id} |
| 302 | </foreach> | 309 | </foreach> |
| 303 | </delete> | 310 | </delete> |
| 311 | + <delete id="deleteDeviceIdAssociatedJobCode"> | ||
| 312 | + delete from driver where | ||
| 313 | + job_code in | ||
| 314 | + ( <foreach collection="jobCodes" item="item" separator=","> | ||
| 315 | + #{item} | ||
| 316 | + </foreach> ) | ||
| 317 | + </delete> | ||
| 304 | 318 | ||
| 305 | 319 | ||
| 306 | <insert id="saveDrivers"> | 320 | <insert id="saveDrivers"> |