From c3bc2e094d62c6a5bb939dbbd543f8825f3cf703 Mon Sep 17 00:00:00 2001 From: Vincent <19330835921@163.com> Date: Tue, 10 Jun 2025 14:09:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8E=A5=E5=8F=A3=E8=81=94=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/ocr/api/entity/FormRecord.java | 38 +- .../api/thread/tasks/PictureDisposeTask.java | 18 +- .../thread/tasks/PictureImgToLocalTask.java | 82 ++-- .../controller/PrevailCloudApiController.java | 86 +++- .../ocr/controller/dto/DeleteTaskData.java | 15 + .../ocr/controller/dto/DeleteTaskRequest.java | 16 +- .../custom/ocr/controller/dto/TaskDTO.java | 39 +- .../controller/dto/enc/AddTaskEncRequest.java | 16 + .../dto/enc/DeleteEncTaskRequest.java | 16 + .../dto/enc/DuplicateTaskEncRequest.java | 32 ++ .../module/custom/ocr/dataDao/TaskMapper.java | 7 +- .../custom/ocr/dataobject/OcrPictureBak.java | 405 ++++++++++++++++++ .../module/custom/ocr/dataobject/Task.java | 20 + .../custom/ocr/service/OcrPictureService.java | 3 + .../custom/ocr/service/TaskService.java | 8 + .../service/impl/OcrPictureServiceImpl.java | 18 +- .../ocr/service/impl/TaskServiceImpl.java | 30 +- .../module/custom/ocr/utils/ApiHelper.java | 61 +++ .../src/main/resources/application.yml | 1 + .../src/main/resources/mapper/TaskMapper.xml | 9 +- 20 files changed, 861 insertions(+), 59 deletions(-) create mode 100644 jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/DeleteTaskData.java create mode 100644 jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/AddTaskEncRequest.java create mode 100644 jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/DeleteEncTaskRequest.java create mode 100644 jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/DuplicateTaskEncRequest.java create mode 100644 jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrPictureBak.java diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/FormRecord.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/FormRecord.java index cca6f13..4e88823 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/FormRecord.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/FormRecord.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import lombok.Data; import java.util.HashMap; +import java.util.List; import java.util.Map; @Data @@ -94,7 +95,42 @@ public class FormRecord { /** * 拍照打卡 */ - private LivePhoto livePhoto; + private List livePhoto; + + /** + * 拍照打卡 + */ + private List drt0011; + + /** + * 拍照打卡 + */ + private List drt0013; + + /** + * 拍照打卡 + */ + private List drt0014; + + /** + * 本地图片地址 + */ + private String localImageUrl; + + /** + * 图片hash + */ + private String imgHash; + + /** + * 图片地址 + */ + private String imageUrl; + + /** + * 图片编号或名称 + */ + private String imageNo; // 使用 Map 捕获动态字段 private Map dynamicFields; diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureDisposeTask.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureDisposeTask.java index fa78b93..51c9c77 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureDisposeTask.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureDisposeTask.java @@ -34,18 +34,20 @@ public class PictureDisposeTask implements Runnable { OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService"); //获取当前任务中有多少图片 - LivePhoto livePhoto = pictureSourceResult.getLivePhoto(); + List livePhotos = pictureSourceResult.getLivePhoto(); //定义新增集合对象 List ocrPictureList = new ArrayList<>(); - //检查图片地址是否为空 - if (StringUtils.isEmpty(livePhoto.getFileUrl())) { - OcrPicture picture = new OcrPicture(); - // TODO: 字段对应转换 - picture.setImageUrl(livePhoto.getFileUrl()); - picture.setHistory(true); - ocrPictureList.add(picture); + for (LivePhoto livePhoto : livePhotos) { + //检查图片地址是否为空 + if (StringUtils.isEmpty(livePhoto.getFileUrl())) { + OcrPicture picture = new OcrPicture(); + // TODO: 字段对应转换 + picture.setImageUrl(livePhoto.getFileUrl()); + picture.setHistory(true); + ocrPictureList.add(picture); + } } //调用图片入库方法 diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureImgToLocalTask.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureImgToLocalTask.java index 5ff5192..36bace3 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureImgToLocalTask.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureImgToLocalTask.java @@ -3,16 +3,20 @@ package org.jeecg.module.custom.ocr.api.thread.tasks; import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; import org.jeecg.module.custom.ocr.api.entity.FormRecord; -import org.jeecg.module.custom.ocr.dataobject.OcrPicture; +import org.jeecg.module.custom.ocr.api.entity.LivePhoto; +import org.jeecg.module.custom.ocr.dataobject.Task; import org.jeecg.module.custom.ocr.service.OcrPictureService; +import org.jeecg.module.custom.ocr.service.TaskService; import org.jeecg.module.custom.ocr.utils.DownloadImgUtil; import org.jeecg.module.custom.ocr.utils.ImageUtils; import org.jeecg.module.custom.ocr.utils.SpringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.util.CollectionUtils; import java.io.File; import java.io.IOException; +import java.util.List; import java.util.Map; @@ -36,50 +40,70 @@ public class PictureImgToLocalTask implements Runnable { @Override public void run() { OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService"); - OcrPicture picture = ocrPictureService.getById(pictureImgToLocal.getId()); +// OcrPicture picture = ocrPictureService.getById(pictureImgToLocal.getId()); + TaskService taskService = SpringUtils.getBean("taskServiceImpl"); + Task task = taskService.getById(pictureImgToLocal.getId()); //1.开始转储图片 Boolean result = true; - //检查是否已经存在本地图片,存在则不进行转储了。 - File file = new File(pictureImgToLocal.getLivePhoto().getFileUrl()); - // pictureImgToLocal.getLivePhoto().getLocalImgUrl() - if(!file.isFile()){ - result = DownloadImgUtil.downloadImage(pictureImgToLocal.getLivePhoto().getFileUrl(), pictureImgToLocal.getLivePhoto().getLocalImgUrl()); -// result = DownloadImgUtil.downloadImage(pictureImgToLocal.getLivePhoto().getFileUrl(), "D:\\code\\ocr-activity-backend\\1.jpeg"); + + handlePicture(result, task, ocrPictureService, taskService, pictureImgToLocal.getLivePhoto()); + handlePicture(result, task, ocrPictureService, taskService, pictureImgToLocal.getDrt0011()); + handlePicture(result, task, ocrPictureService, taskService, pictureImgToLocal.getDrt0013()); + handlePicture(result, task, ocrPictureService, taskService, pictureImgToLocal.getDrt0014()); + } + + private void handlePicture(Boolean result, Task task, OcrPictureService ocrPictureService, TaskService taskService, List livePhotos) { + if (CollectionUtils.isEmpty(livePhotos)) { + return; } - if (Boolean.TRUE.equals(result)) { - if (ObjectUtil.isNotEmpty(picture)) { - picture.setLocalImageUrl(pictureImgToLocal.getLivePhoto().getFileUrl()); - try { + + for (LivePhoto livePhoto : livePhotos) { + //检查是否已经存在本地图片,存在则不进行转储了。 + if (ObjectUtil.isNotEmpty(livePhoto)) { + File file = new File(livePhoto.getFileUrl()); + // pictureImgToLocal.getLivePhoto().getLocalImgUrl() + if (!file.isFile()) { + result = DownloadImgUtil.downloadImage(livePhoto.getFileUrl().replaceAll("https://https://", "https://"), livePhoto.getFileName()); +// result = DownloadImgUtil.downloadImage(pictureImgToLocal.getLivePhoto().getFileUrl(), "D:\\code\\ocr-activity-backend\\1.jpeg"); + } + } + + if (Boolean.TRUE.equals(result)) { + if (ObjectUtil.isNotEmpty(task)) { + task.setLocalImageUrl(livePhoto.getFileUrl()); + try { // picture.setLocalImageUrl(ImageUtils.generateThumbnail("D:\\code\\ocr-activity-backend\\1.jpeg",182)); - picture.setLocalImageUrl(ImageUtils.generateThumbnail(pictureImgToLocal.getLivePhoto().getLocalImgUrl(),182)); + task.setLocalImageUrl(ImageUtils.generateThumbnail(livePhoto.getFileName(), 182)); // picture.setServerThumbnailUrl(ocrPictureService.getServerUrl()+ImageUtils.getFileName(picture.getLocalThumbnailUrl())); - } catch (IOException e) { - throw new RuntimeException(e); - } - Map ocrPictureClassifyAndHash = ocrPictureService.getOcrPictureClassifyAndHash(picture.getLocalImageUrl()); - if(ocrPictureClassifyAndHash!=null){ - picture.setImgHash(ocrPictureClassifyAndHash.get("hash")); - } + } catch (IOException e) { + throw new RuntimeException(e); + } + Map ocrPictureClassifyAndHash = ocrPictureService.getOcrPictureClassifyAndHash(task.getLocalImageUrl()); + if (ocrPictureClassifyAndHash != null) { + task.setImgHash(ocrPictureClassifyAndHash.get("hash")); + } - ocrPictureService.updateById(picture); - logger.info("图片本地化,回写数据完成!"); - logger.info("开启获取图片信息操作!"); - ocrPictureService.savePicturesInfo(picture); - logger.info("获取图片信息操作,结束!"); - } - }else{ - //判断是否是第一次失败! + taskService.updateById(task); + logger.info("图片本地化,回写数据完成!"); + logger.info("开启获取图片信息操作!"); + ocrPictureService.savePicturesInfo(task); + logger.info("获取图片信息操作,结束!"); + } + } else { + //判断是否是第一次失败! // if(picture.getDownloadErrorCount()==null){ // picture.setDownloadErrorCount(0); // } - //判断如果没超过5次则放回队列进行重试 + //判断如果没超过5次则放回队列进行重试 // if( picture.getDownloadErrorCount()!=null && picture.getDownloadErrorCount()<5){ // TaskQueue.pictureImgToLocalPushData(pictureImgToLocal); // picture.setDownloadErrorCount(picture.getDownloadErrorCount()+1); // } // ocrPictureService.updateById(picture); + } } + } } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/PrevailCloudApiController.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/PrevailCloudApiController.java index 263fc0e..31900a4 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/PrevailCloudApiController.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/PrevailCloudApiController.java @@ -2,25 +2,31 @@ package org.jeecg.module.custom.ocr.controller; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.jeecg.module.custom.ocr.api.PrevailCloudApi; import org.jeecg.module.custom.ocr.api.entity.PictureSourceAllPullMsg; import org.jeecg.module.custom.ocr.api.thread.PullAllPictureSourceThread; +import org.jeecg.module.custom.ocr.common.entity.RequestData; import org.jeecg.module.custom.ocr.config.ApiConfig; -import org.jeecg.module.custom.ocr.controller.dto.AddTaskRequest; -import org.jeecg.module.custom.ocr.controller.dto.DeleteTaskRequest; -import org.jeecg.module.custom.ocr.controller.dto.DuplicateTaskRequest; +import org.jeecg.module.custom.ocr.controller.dto.*; +import org.jeecg.module.custom.ocr.controller.dto.enc.AddTaskEncRequest; +import org.jeecg.module.custom.ocr.controller.dto.enc.DeleteEncTaskRequest; +import org.jeecg.module.custom.ocr.controller.dto.enc.DuplicateTaskEncRequest; import org.jeecg.module.custom.ocr.service.DuplicateTaskService; import org.jeecg.module.custom.ocr.service.TaskService; +import org.jeecg.module.custom.ocr.utils.ApiHelper; import org.jeecg.module.custom.ocr.utils.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.List; import java.util.concurrent.*; @@ -42,6 +48,9 @@ public class PrevailCloudApiController { @Autowired private DuplicateTaskService duplicateTaskService; + @Value("${accessCode}") + private String accessCode; + /** * 用于执行全量拉取的定长线程池 */ @@ -116,8 +125,18 @@ public class PrevailCloudApiController { */ @ApiOperation(value = "添加任务", notes = "添加任务") @PostMapping("/addTask") - public void addTask(@RequestBody AddTaskRequest request) { - taskService.save(request); + public void addTask(@RequestBody AddTaskEncRequest request) { + try { + RequestData requestData = JSON.parseObject(JSON.toJSONString(request), RequestData.class); + String decryptRequest = ApiHelper.decryptRequest(accessCode, requestData); + List taskDTOS = JSON.parseArray(decryptRequest, TaskDTO.class); + + AddTaskRequest addTaskRequest = convertToAddTaskRequest(request); + addTaskRequest.getData().setRecords(taskDTOS); + taskService.save(addTaskRequest); + } catch (Exception e) { + throw new RuntimeException(e); + } } /** @@ -128,8 +147,18 @@ public class PrevailCloudApiController { */ @ApiOperation(value = "删除任务", notes = "删除任务") @PostMapping("/deleteTask") - public void deleteTask(@RequestBody @Validated DeleteTaskRequest request) { - taskService.deleteTask(request.getTaskNo()); + public void deleteTask(@RequestBody @Validated DeleteEncTaskRequest request) { + try { + DeleteTaskRequest deleteTaskRequest = convertToDeleteTaskRequest(request); + RequestData requestData = JSON.parseObject(JSON.toJSONString(request), RequestData.class); + String decryptRequest = ApiHelper.decryptRequest(accessCode, requestData); + DeleteTaskData deleteTaskData = JSON.parseObject(decryptRequest, DeleteTaskData.class); + deleteTaskRequest.setData(deleteTaskData); + + taskService.deleteTasks(deleteTaskData.getTaskNos()); + } catch (Exception e) { + throw new RuntimeException(e); + } } /** @@ -140,7 +169,46 @@ public class PrevailCloudApiController { */ @ApiOperation(value = "查重", notes = "查重") @PostMapping("/checkDuplicate") - public void checkDuplicate(@RequestBody @Validated DuplicateTaskRequest request) { - duplicateTaskService.save(request); + public void checkDuplicate(@RequestBody @Validated DuplicateTaskEncRequest request) { + try { + DuplicateTaskRequest duplicateTaskRequest = convertToDuplicateTaskRequest(request); + RequestData requestData = JSON.parseObject(JSON.toJSONString(request), RequestData.class); + String decryptRequest = ApiHelper.decryptRequest(accessCode, requestData); + DuplicateTaskData duplicateTaskData = JSON.parseObject(decryptRequest, DuplicateTaskData.class); + + duplicateTaskRequest.setData(duplicateTaskData); + duplicateTaskService.save(duplicateTaskRequest); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static AddTaskRequest convertToAddTaskRequest(AddTaskEncRequest encRequest) { + AddTaskRequest request = new AddTaskRequest(); + request.setTenantCode(encRequest.getTenantCode()); + request.setAccessKey(encRequest.getAccessKey()); + request.setTimestamp(encRequest.getTimestamp()); + request.setSignature(encRequest.getSignature()); + request.setData(new AddTaskData()); + return request; + } + + private static DuplicateTaskRequest convertToDuplicateTaskRequest(DuplicateTaskEncRequest encRequest) { + DuplicateTaskRequest request = new DuplicateTaskRequest(); + request.setTenantCode(encRequest.getTenantCode()); + request.setAccessKey(encRequest.getAccessKey()); + request.setTimestamp(encRequest.getTimestamp()); + request.setSignature(encRequest.getSignature()); + request.setData(new DuplicateTaskData()); + return request; + } + + private static DeleteTaskRequest convertToDeleteTaskRequest(DeleteEncTaskRequest encRequest) { + DeleteTaskRequest request = new DeleteTaskRequest(); + request.setTenantCode(encRequest.getTenantCode()); + request.setAccessKey(encRequest.getAccessKey()); + request.setTimestamp(encRequest.getTimestamp()); + request.setSignature(encRequest.getSignature()); + return request; } } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/DeleteTaskData.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/DeleteTaskData.java new file mode 100644 index 0000000..9db59d5 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/DeleteTaskData.java @@ -0,0 +1,15 @@ +package org.jeecg.module.custom.ocr.controller.dto; + +import lombok.Data; + +import java.util.List; + +@Data +public class DeleteTaskData { + + private String accountNo; + + private String tenantNo; + + private List taskNos; +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/DeleteTaskRequest.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/DeleteTaskRequest.java index 34e3b60..9460247 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/DeleteTaskRequest.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/DeleteTaskRequest.java @@ -2,14 +2,16 @@ package org.jeecg.module.custom.ocr.controller.dto; import lombok.Data; -import javax.validation.constraints.NotNull; - @Data public class DeleteTaskRequest { - /** - * 任务NO - */ - @NotNull - private Long taskNo; + private String tenantCode; + + private String accessKey; + + private Long timestamp; + + private String signature; + + private DeleteTaskData data; } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/TaskDTO.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/TaskDTO.java index 443a3ca..94a6c7a 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/TaskDTO.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/TaskDTO.java @@ -5,6 +5,7 @@ import com.google.common.collect.Maps; import lombok.Data; import org.jeecg.module.custom.ocr.api.entity.LivePhoto; +import java.util.List; import java.util.Map; @Data @@ -93,7 +94,43 @@ public class TaskDTO { /** * 拍照打卡 */ - private LivePhoto livePhoto; + private List livePhoto; + + /** + * 拍照打卡 + */ + private List drt0011; + + /** + * 拍照打卡 + */ + private List drt0013; + + /** + * 拍照打卡 + */ + private List drt0014; + + /** + * 本地图片地址 + */ + private String localImageUrl; + + /** + * 图片hash + */ + private String imgHash; + + /** + * 图片地址 + */ + private String imageUrl; + + /** + * 图片编号或名称 + */ + private String imageNo; + // 使用 Map 捕获动态字段 private Map dynamicFields = Maps.newHashMap(); diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/AddTaskEncRequest.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/AddTaskEncRequest.java new file mode 100644 index 0000000..6cffc11 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/AddTaskEncRequest.java @@ -0,0 +1,16 @@ +package org.jeecg.module.custom.ocr.controller.dto.enc; + +import lombok.Data; + +@Data +public class AddTaskEncRequest { + private String tenantCode; + + private String accessKey; + + private Long timestamp; + + private String signature; + + private String data; +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/DeleteEncTaskRequest.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/DeleteEncTaskRequest.java new file mode 100644 index 0000000..0f37449 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/DeleteEncTaskRequest.java @@ -0,0 +1,16 @@ +package org.jeecg.module.custom.ocr.controller.dto.enc; + +import lombok.Data; + +@Data +public class DeleteEncTaskRequest { + private String tenantCode; + + private String accessKey; + + private Long timestamp; + + private String signature; + + private String data; +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/DuplicateTaskEncRequest.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/DuplicateTaskEncRequest.java new file mode 100644 index 0000000..5615c4f --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/enc/DuplicateTaskEncRequest.java @@ -0,0 +1,32 @@ +package org.jeecg.module.custom.ocr.controller.dto.enc; + +import lombok.Data; +import org.jeecg.module.custom.ocr.controller.dto.DuplicateTaskData; + +@Data +public class DuplicateTaskEncRequest { + /** + * 租户代码,必填 + */ + private String tenantCode; + + /** + * 访问标识,必填 + */ + private String accessKey; + + /** + * 请求时间戳,必填 + */ + private Long timestamp; + + /** + * 签名,必填 + */ + private String signature; + + /** + * 加密的请求数据,必填 + */ + private String data; +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/TaskMapper.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/TaskMapper.java index 411c7c5..e57b502 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/TaskMapper.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/TaskMapper.java @@ -1,10 +1,15 @@ package org.jeecg.module.custom.ocr.dataDao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; import org.jeecg.module.custom.ocr.dataobject.Task; +import java.util.List; + public interface TaskMapper extends BaseMapper { void save(Task task); - void deleteByTaskNo(Long taskNo); + void deleteByTaskNo(@Param("taskNo") Long taskNo); + + void deleteByTaskNos(@Param("taskNos") List taskNos); } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrPictureBak.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrPictureBak.java new file mode 100644 index 0000000..0a09946 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrPictureBak.java @@ -0,0 +1,405 @@ +package org.jeecg.module.custom.ocr.dataobject; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.jeecg.module.custom.ocr.base.jsonDomain.DateSerializer; +import org.jeecg.module.custom.ocr.common.dto.BaseDto; +import org.jeecg.module.custom.ocr.jsonDomain.DateNotimeSerializer; +import org.jeecg.module.custom.ocr.utils.requestFormat.SearchQuery; + +import java.util.List; + +/** + * 图片信息表 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@ApiModel(value = "图片信息表", description = "图片信息表") +@TableName(value = "ocr_task") +public class OcrPictureBak implements BaseDto, java.io.Serializable { + + private static final long serialVersionUID = -10378331243377607L; + @ApiModelProperty(value = "主键") + @TableId(value = "id", type = IdType.ASSIGN_ID) + @JsonSerialize(using = ToStringSerializer.class) + @TableField(value = "ID") + private Long id; + + @ApiModelProperty(value = "创建人") + @TableField(value = "create_by") + private String createBy; + + @ApiModelProperty(value = "创建时间") + @TableField(value = "create_time") + @JsonSerialize(using = DateSerializer.class) + private Long createTime; + + @ApiModelProperty(value = "修改人") + @TableField(value = "update_by") + private String updateBy; + + @ApiModelProperty(value = "修改时间") + @TableField(value = "update_time") + @JsonSerialize(using = DateSerializer.class) + private Long updateTime; + + @ApiModelProperty(value = "分类表主键--通过“图片分类”字段做匹配,如果没有自动添加") + @TableField(value = "classificationid") + private String classificationid; + + @ApiModelProperty(value = "图片类型--通过“AI图片分类接口获得”") + @TableField(value = "pictureclassid") + private String pictureclassid; + + @ApiModelProperty(value = "图片类型相似度,图片类型--通过“AI图片分类接口获得”") + @TableField(value = "pictureclassscores") + private String pictureclassscores; + + @ApiModelProperty(value = "图片真假0:假,1:真") + @TableField(value = "iztrueorfalse") + private Integer iztrueorfalse; + + @ApiModelProperty(value = "选判真假原因id,从字典表中获得,其他时,当前字段为零") + @TableField(value = "judgeid") + @JsonSerialize(using = ToStringSerializer.class) + private Long judgeid; + + @ApiModelProperty(value = "图片为假的其他原因,长度不超过50个汉字") + @TableField(value = "judgedesc") + private String judgedesc; + + @ApiModelProperty(value = "公司ID") + @JsonSerialize(using = ToStringSerializer.class) + @TableField(value = "tenant_id") + private Long tenantId; + + @ApiModelProperty(value = "公司状态") + @TableField(value = "tenantstatus") + private String tenantstatus; + + @ApiModelProperty(value = "公司代码,第三方系统") + @TableField(value = "plantCode") + private String plantcode; + + @ApiModelProperty(value = "公司名称") + @TableField(value = "tenantname") + private String tenantname; + + @ApiModelProperty(value = "业务主体ID--图片主键") + @TableField(value = "pictureid") + private String pictureid; + + @ApiModelProperty(value = "业务主体名称--图片成名") + @TableField(value = "picturename") + private String picturename; + + @ApiModelProperty(value = "图片名称") + @TableField(value = "imgName") + private String imgname; + + @ApiModelProperty(value = "图片地址") + @TableField(value = "imgUrl") + private String imgurl; + + @ApiModelProperty(value = "业务主体状态") + @TableField(value = "picturestatus") + private String picturestatus; + + @ApiModelProperty(value = "源项目id") + @TableField(value = "projectId") + private String projectid; + + @ApiModelProperty(value = "项目名称") + @TableField(value = "projectIdName") + private String projectidname; + + @ApiModelProperty(value = "项目状态") + @TableField(value = "projectstatus") + private String projectstatus; + + @ApiModelProperty(value = "源计划id") + @TableField(value = "planId") + private String planid; + + @ApiModelProperty(value = "计划名称") + @TableField(value = "planName") + private String planname; + + @ApiModelProperty(value = "计划状态") + @TableField(value = "planstatus") + private String planstatus; + + @ApiModelProperty(value = "所属子计划ID") + @TableField(value = "planchildid") + private String planchildid; + + @ApiModelProperty(value = "所属子计划名称") + @TableField(value = "planchildname") + private String planchildname; + + @ApiModelProperty(value = "所属子计划状态") + @TableField(value = "planchildstatus") + private String planchildstatus; + + @ApiModelProperty(value = "上传时间") + @JsonSerialize(using = DateNotimeSerializer.class) + @TableField(value = "upTime") + private Long uptime; + + @ApiModelProperty(value = "生成时间") + @JsonSerialize(using = DateNotimeSerializer.class) + @TableField(value = "genTime") + private Long gentime; + + @ApiModelProperty(value = "色彩空间") + @TableField(value = "space") + private String space; + + @ApiModelProperty(value = "来源") + @TableField(value = "source") + private String source; + + @ApiModelProperty(value = "上报者头像--接口传送") + @TableField(value = "upHead") + private String uphead; + + @ApiModelProperty(value = "上报人主键") + @TableField(value = "upuserid") + private String upuserid; + + @ApiModelProperty(value = "上报者名称--接口传送") + @TableField(value = "upName") + private String upname; + + @ApiModelProperty(value = "发布地区,拜访城市,城市名称,例如:北京市、天津市、石家庄市") + @TableField(value = "releaseArea") + private String releasearea; + + @ApiModelProperty(value = "拜访省份") + @TableField(value = "releaseProvince") + private String releaseprovince; + + @ApiModelProperty(value = "任务id") + @TableField(value = "remark") + private String remark; + + @ApiModelProperty(value = "任务名称,源系统") + @TableField(value = "taskName") + private String taskname; + + @ApiModelProperty(value = "是否已经生成任务,0:否,1:是") + @TableField(value = "taskstatus") + private String taskstatus; + + @ApiModelProperty(value = "是否已经审批,0:未生成,1:审批中,2:已审批") + @TableField(value = "work_status") + private String workStatus; + + @ApiModelProperty(value = "现项目ID") + @TableField(value = "categoryid") + private Long categoryid; + + @ApiModelProperty(value = "任务-工单主键") + @TableField(value = "taskchildpictureid") + private String taskchildpictureid; + + @ApiModelProperty(value = "提报人") + @TableField(value = "field1") + private String field1; + + @ApiModelProperty(value = "拜访客户类型") + @TableField(value = "field2") + private String field2; + + @ApiModelProperty(value = "拜访客户名称,终端名称,例如中日友好医院") + @TableField(value = "field3") + private String field3; + + @ApiModelProperty(value = "任务来源") + @TableField(value = "field4") + private String field4; + + @ApiModelProperty(value = "厂商") + @TableField(value = "field5") + private String field5; + + @ApiModelProperty(value = "拜访客户级别") + @TableField(value = "field6") + private String field6; + + @ApiModelProperty(value = "科室名称") + @TableField(value = "field7") + private String field7; + + @ApiModelProperty(value = "拜访小结") + @TableField(value = "field8") + private String field8; + + @ApiModelProperty(value = "产品名称") + @TableField(value = "field9") + private String field9; + + @ApiModelProperty(value = "地区,定位信息,例如北京市朝阳区文苑路10号") + @TableField(value = "field10") + private String field10; + + @ApiModelProperty(value = "拜访日期") + @TableField(value = "field11") + private String field11; + + @ApiModelProperty(value = "定位距离") + @TableField(value = "field12") + private String field12; + + @ApiModelProperty(value = "病历号") + @TableField(value = "field13") + private String field13; + + @ApiModelProperty(value = "是否重复") + @TableField(value = "field14") + private String field14; + + @ApiModelProperty(value = "任务类型") + @TableField(value = "field15") + private String field15; + + @ApiModelProperty(value = "任务状态") + @TableField(value = "field16") + private String field16; + + @ApiModelProperty(value = "拜访项目类别") + @TableField(value = "field17") + private String field17; + + @ApiModelProperty(value = "备用字段") + @TableField(value = "field18") + private String field18; + + @ApiModelProperty(value = "本地图片地址") + @TableField(value = "local_pictrue_url") + private String localpictrueurl; + + @ApiModelProperty(value = "是否已下载到本地") + @TableField(value = "is_download") + private Integer isdownload; + + @ApiModelProperty(value = "图片hash值") + @TableField(value = "img_hash") + private String imgHash; + + @ApiModelProperty(value = "相似度数值") + @TableField(value = "similarity_score") + private Integer similarityscore; + + @ApiModelProperty(value = "下载到本地,失败次数") + @TableField(value = "download_error_count") + private Integer downloadErrorCount; + + @ApiModelProperty(value = "图片查重的比对图片集合") + @TableField(exist = false) + private List listCom; + + @ApiModelProperty(value = "非历史图片主键集合") + @TableField(exist = false) + private List picturecompareList; + + @ApiModelProperty(value = "图片对应的工单对象") + @TableField(exist = false) + private OcrTaskchildPicture ocrTaskchildPicture; + + @ApiModelProperty(value = "当前图片与参考图比对结果") + //当前图片与参考图比对结果 + @TableField(exist = false) + private String result; + + @ApiModelProperty(value = "缩略图服务器绝对路径") + @TableField(value = "local_thumbnail_url") + private String localThumbnailUrl; + + @ApiModelProperty(value = "缩略图请求地址") + @TableField(value = "server_thumbnail_url") + private String serverThumbnailUrl; + + @ApiModelProperty(value = "提报日期时间戳") + @TableField(value = "submit_date_timestamp") + private Long submitDateTimestamp; + + @ApiModelProperty(value = "是否重复,0.不重复 1.重复 (历史比对中阈值存在100的会显示此值)") + @TableField(value = "is_repeat") + private Integer isRepeat; + + @ApiModelProperty(value = "任务状态") + @TableField(exist = false) + private Integer states; + + @ApiModelProperty(value = "可疑文件夹 0:不在,1:在") + @TableField(value = "suspiciousfile") + private Integer suspiciousfile; + + @ApiModelProperty(value = "定位") + @TableField(value = "location") + private String location; + + @ApiModelProperty(value = "备注") + @TableField(value = "comment") + private String comment; + + @ApiModelProperty(value = "拍照时间") + @TableField(value = "photo_date_timestamp") + @JsonSerialize(using = DateSerializer.class) + private Long photoDateTimestamp; + + @ApiModelProperty(value = "完全相似分组id") + @TableField(value = "complete_similar_group_id") + private Long completeSimilarGroupId; + + @ApiModelProperty(value = "是否为历史图") + @TableField(value = "history") + private Boolean history; + + @ApiModelProperty(value = "节点状态") + @TableField(exist = false) + private Integer historyStates; + + @ApiModelProperty(value = "节点状态") + @TableField(exist = false) + private String taskId; + + @ApiModelProperty(value = "是否是历史重复,一键查重图片墙,检索结果阈值100无相同图片时使用") + @TableField(exist = false) + private Integer isRepeatHis; + + @ApiModelProperty(value = "图片信息-宽") + @TableField(exist = false) + private String wide; + + @ApiModelProperty(value = "图片信息-高") + @TableField(exist = false) + private String high; + + //保存当前登录用户的数据权限范围的搜索条件 + @TableField(exist = false) + @JsonIgnore + private SearchQuery searchQueryrolesShowleave; + + @TableField(exist = false) + private OcrPictureInfo pictureInfo; + + @Override + public String getQueryFiled(String filedname) { + return ""; + } +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/Task.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/Task.java index d3b8d0d..d107d2c 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/Task.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/Task.java @@ -100,6 +100,26 @@ public class Task { */ private String livePhoto; + /** + * 本地图片地址 + */ + private String localImageUrl; + + /** + * 图片hash + */ + private String imgHash; + + /** + * 图片地址 + */ + private String imageUrl; + + /** + * 图片编号或名称 + */ + private String imageNo; + // 使用 Map 捕获动态字段 private String dynamicFields; } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrPictureService.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrPictureService.java index fa5f6ec..8f7b0ae 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrPictureService.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrPictureService.java @@ -3,6 +3,7 @@ package org.jeecg.module.custom.ocr.service; import com.baomidou.mybatisplus.core.conditions.Wrapper; import org.jeecg.module.custom.ocr.base.BaseService; import org.jeecg.module.custom.ocr.dataobject.OcrPicture; +import org.jeecg.module.custom.ocr.dataobject.Task; import java.util.List; import java.util.Map; @@ -27,4 +28,6 @@ public interface OcrPictureService extends BaseService { void savePicturesInfo(OcrPicture ocrPicture); OcrPicture getByTaskId(Long taskId); + + void savePicturesInfo(Task task); } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/TaskService.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/TaskService.java index 7caa440..3e029e7 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/TaskService.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/TaskService.java @@ -1,12 +1,20 @@ package org.jeecg.module.custom.ocr.service; import org.jeecg.module.custom.ocr.controller.dto.AddTaskRequest; +import org.jeecg.module.custom.ocr.dataobject.Task; import javax.validation.constraints.NotNull; +import java.util.List; public interface TaskService { void save(AddTaskRequest request); void deleteTask(Long taskNo); + + Task getById(Long id); + + void updateById(Task task); + + void deleteTasks(List taskNos); } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrPictureServiceImpl.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrPictureServiceImpl.java index 61d5818..bd219db 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrPictureServiceImpl.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrPictureServiceImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.module.custom.ocr.api.entity.FormRecord; @@ -14,6 +15,7 @@ import org.jeecg.module.custom.ocr.config.ApiConfig; import org.jeecg.module.custom.ocr.dataDao.OcrPictureMybatisDao; import org.jeecg.module.custom.ocr.dataobject.OcrPicture; import org.jeecg.module.custom.ocr.dataobject.OcrPictureInfo; +import org.jeecg.module.custom.ocr.dataobject.Task; import org.jeecg.module.custom.ocr.service.OcrPictureInfoService; import org.jeecg.module.custom.ocr.service.OcrPictureService; import org.jeecg.module.custom.ocr.service.OcrTaskchildPictureService; @@ -161,6 +163,20 @@ public class OcrPictureServiceImpl extends BaseServiceImpl taskNos) { + taskMapper.deleteByTaskNos(taskNos); + } + private Task toTask(AddTaskRequest request) { Task task = new Task(); @@ -73,6 +90,10 @@ public class TaskServiceImpl implements TaskService { task.setUserName(taskDTO.getUserName()); task.setSubmitTime(taskDTO.getSubmitTime()); task.setLivePhoto(JSONObject.toJSONString(taskDTO.getLivePhoto())); + task.setLocalImageUrl(taskDTO.getLocalImageUrl()); + task.setImgHash(taskDTO.getImgHash()); + task.setImageUrl(taskDTO.getImageUrl()); + task.setImageNo(taskDTO.getImageNo()); // 将 Map 转换为 JSON 字符串 try { @@ -114,6 +135,13 @@ public class TaskServiceImpl implements TaskService { formRecord.setUserName(taskDTO.getUserName()); formRecord.setSubmitTime(taskDTO.getSubmitTime()); formRecord.setLivePhoto(taskDTO.getLivePhoto()); + formRecord.setDrt0011(taskDTO.getDrt0011()); + formRecord.setDrt0013(taskDTO.getDrt0013()); + formRecord.setDrt0014(taskDTO.getDrt0014()); + formRecord.setLocalImageUrl(taskDTO.getLocalImageUrl()); + formRecord.setImgHash(taskDTO.getImgHash()); + formRecord.setImageUrl(taskDTO.getImageUrl()); + formRecord.setImageNo(taskDTO.getImageNo()); formRecord.setDynamicFields(taskDTO.getDynamicFields()); } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ApiHelper.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ApiHelper.java index 72aeef8..8dafe96 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ApiHelper.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ApiHelper.java @@ -1,5 +1,6 @@ package org.jeecg.module.custom.ocr.utils; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; @@ -454,6 +455,66 @@ public class ApiHelper { return mapper.readValue(decrypedData, clazz); } + /** + * do verify signature then decrypt + * + * @param accessCode access code + * @param resultData {@link ResultData} which to be decrypted + * @param clazz class use for {@link ObjectMapper#readValue(String, Class)} to convert JSON to object + * @return decrypted string + * @throws Exception + */ + public @Nullable static T decryptResponse(String accessCode, Long time, String data, String signature, + Class clazz) throws Exception { + String decrypedData = null; + // 1. verify signature + String timestamp = String.valueOf(time); + if (!verifySignature(accessCode, timestamp, data, signature)) { + throw new Exception(String.format("illegal signature: %s", signature)); + } + + // 2. do decrypt + byte[] bytes = decrypt(accessCode, timestamp, data); + if (bytes != null) { + decrypedData = new String(bytes, StandardCharsets.UTF_8); + } + + // 3. convert to object + if (clazz.equals(String.class)) { + return (T) decrypedData; + } + ObjectMapper mapper = new ObjectMapper(); + + return mapper.readValue(decrypedData, clazz); + } + + public @Nullable static List decryptListResponse(String accessCode, Long time, String data, String signature, + Class clazz) throws Exception { + String decrypedData = null; + // 1. 验证签名 + String timestamp = String.valueOf(time); + if (!verifySignature(accessCode, timestamp, data, signature)) { + throw new Exception(String.format("非法签名: %s", signature)); + } + + // 2. 解密 + byte[] bytes = decrypt(accessCode, timestamp, data); + if (bytes != null) { + decrypedData = new String(bytes, StandardCharsets.UTF_8); + } + + // 3. 转换为对象 + if (clazz.equals(String.class)) { + return Collections.singletonList((T) decrypedData); + } + + ObjectMapper mapper = new ObjectMapper(); + // 反序列化为指定类型的列表 + JavaType listType = mapper.getTypeFactory().constructCollectionType(List.class, clazz); + return mapper.readValue(decrypedData, listType); + } + + /** * do AES encrypt * diff --git a/jeecg-module-custom/src/main/resources/application.yml b/jeecg-module-custom/src/main/resources/application.yml index 1ee8479..f6603d6 100644 --- a/jeecg-module-custom/src/main/resources/application.yml +++ b/jeecg-module-custom/src/main/resources/application.yml @@ -268,3 +268,4 @@ image: classifyPath: http://47.103.213.109/ai/api/classify/ serverUrl: http://81.70.154.131/api/image/ classifyBaseUrl: http://47.93.59.251/ai/api/classify/ +accessCode: ED6F7B39768AF95E87AEA8ACCCC71A6F diff --git a/jeecg-module-custom/src/main/resources/mapper/TaskMapper.xml b/jeecg-module-custom/src/main/resources/mapper/TaskMapper.xml index bc58bb9..3addc56 100644 --- a/jeecg-module-custom/src/main/resources/mapper/TaskMapper.xml +++ b/jeecg-module-custom/src/main/resources/mapper/TaskMapper.xml @@ -65,6 +65,13 @@ - DELETE FROM task WHERE task_no = #{taskNo,jdbcType=BIGINT} + DELETE FROM task WHERE task_no = #{taskNo} + + + + DELETE FROM task WHERE task_no IN + + #{taskNo} +