From b425a1eed1f1c4b25823c88ad5fc8a43e7d1bed2 Mon Sep 17 00:00:00 2001 From: Vincent <19330835921@163.com> Date: Wed, 25 Jun 2025 11:30:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E8=B6=B3=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ocr/api/entity/TaskCompletionRequest.java | 25 +++++++++++- .../ocr/api/thread/DuplicateTaskRunner.java | 28 ++++++++----- .../module/custom/ocr/utils/JsonUtil.java | 40 +++++++++++++++++++ 3 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/JsonUtil.java diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/TaskCompletionRequest.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/TaskCompletionRequest.java index c547f7f..62d9d9e 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/TaskCompletionRequest.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/TaskCompletionRequest.java @@ -71,8 +71,8 @@ public class TaskCompletionRequest { @Data public static class PictureRepeat { - @JSONField(name = "imgNo") - private Long imgNo; + @JSONField(name = "imgName") + private String imgName; @JSONField(name = "imgUrl") private String imgUrl; @@ -86,14 +86,35 @@ public class TaskCompletionRequest { @Data public static class HisPictureRepeat { + @JSONField(name = "hisTaskId") + private Long hisTaskId; + @JSONField(name = "hisTaskNo") private Long hisTaskNo; @JSONField(name = "hisRepeatImgNo") private Long hisRepeatImgNo; + @JSONField(name = "hisRepeatSubmitTime") + private Long hisRepeatSubmitTime; + + @JSONField(name = "hisRepeatImgName") + private String hisRepeatImgName; + + @JSONField(name = "hisRepeatTaskId") + private Long hisRepeatTaskId; + @JSONField(name = "hisRepeatImgUrl") private String hisRepeatImgUrl; + + @JSONField(name = "hisRepeatSignAccountName") + private String hisRepeatSignAccountName; + + @JSONField(name = "hisRepeatFillUserName") + private String hisRepeatFillUserName; + + @JSONField(name = "hisRepeatTask") + private String hisRepeatTask; } @Data diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/DuplicateTaskRunner.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/DuplicateTaskRunner.java index 4f4a338..db0aa2c 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/DuplicateTaskRunner.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/DuplicateTaskRunner.java @@ -17,10 +17,7 @@ import org.jeecg.module.custom.ocr.dataDao.TaskMapper; import org.jeecg.module.custom.ocr.dataobject.*; import org.jeecg.module.custom.ocr.service.OcrPictureInfoService; import org.jeecg.module.custom.ocr.service.OcrPictureService; -import org.jeecg.module.custom.ocr.utils.ApiHelper; -import org.jeecg.module.custom.ocr.utils.HashCompareUtil; -import org.jeecg.module.custom.ocr.utils.NameConverterUtil; -import org.jeecg.module.custom.ocr.utils.StringUtils; +import org.jeecg.module.custom.ocr.utils.*; import org.jeecg.module.custom.ocr.utils.httputil.HttpClient; import org.jeecg.module.custom.ocr.utils.httputil.HttpMethod; import org.jeecg.module.custom.ocr.utils.httputil.HttpParamers; @@ -32,10 +29,7 @@ import org.springframework.util.CollectionUtils; import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -157,6 +151,12 @@ public class DuplicateTaskRunner { Set pictureIds = Sets.newHashSet(); List taskNoList = tasks.stream().map(Task::getTaskNo).distinct().collect(Collectors.toList()); + Map taskMap = tasks.stream() + .collect(Collectors.toMap( + Task::getTaskNo, // Key mapper - taskNo + task -> task, // Value mapper - the task itself + (existing, replacement) -> existing // Merge function - keep the existing one if duplicates + )); List pictures = ocrPictureInfoMapper.selectByTaskNos(taskNoList); if (!CollectionUtils.isEmpty(pictures)) { pictures = pictures.stream().filter(item -> queryConfig.getValidateColumn().contains(item.getType())).collect(Collectors.toList()); @@ -175,9 +175,19 @@ public class DuplicateTaskRunner { double similarityValue = Double.parseDouble(similarityScore); if (!pictureIds.contains(first.getId()) && similarityValue > queryConfig.getConfidenceLevel()) { TaskCompletionRequest.HisPictureRepeat hisPictureRepeat = new TaskCompletionRequest.HisPictureRepeat(); + Task task = taskMap.get(first.getTaskNo()); + hisPictureRepeat.setHisTaskId(task.getTaskId()); + hisPictureRepeat.setHisRepeatSubmitTime(task.getSubmitTime()); + Map stringStringMap = JsonUtil.jsonToMap(task.getDynamicFields()); + hisPictureRepeat.setHisRepeatFillUserName(stringStringMap.get("fillUserName")); + hisPictureRepeat.setHisRepeatSignAccountName(stringStringMap.get("signAccountName")); + hisPictureRepeat.setHisRepeatTask(JSONObject.toJSONString(task)); + hisPictureRepeat.setHisTaskNo(first.getTaskNo()); hisPictureRepeat.setHisRepeatImgUrl(first.getImageUrl()); hisPictureRepeat.setHisRepeatImgNo(first.getId()); + hisPictureRepeat.setHisRepeatImgName(first.getImgName()); + hisPictureRepeat.setHisRepeatTaskId(first.getTaskNo()); pictureIds.add(first.getId()); historyLists.add(hisPictureRepeat); } @@ -230,7 +240,7 @@ public class DuplicateTaskRunner { List pictureRepeatList = pictures.stream() .map(p -> { TaskCompletionRequest.PictureRepeat repeat = new TaskCompletionRequest.PictureRepeat(); - repeat.setImgNo(p.getId()); + repeat.setImgName(p.getImgName()); repeat.setImgUrl(p.getImageUrl()); repeat.setDynamicFields(new HashMap<>()); // 动态字段待补充 repeat.setHisPictureRepeatList(historyLists); diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/JsonUtil.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/JsonUtil.java new file mode 100644 index 0000000..2c7bdf3 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/JsonUtil.java @@ -0,0 +1,40 @@ +package org.jeecg.module.custom.ocr.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.type.TypeReference; +import java.util.Map; +import java.util.HashMap; + +public class JsonUtil { + private static final ObjectMapper objectMapper = new ObjectMapper(); + + public static Map jsonToMap(String jsonString) { + try { + // 先将JSON字符串转换为Map + Map originalMap = objectMapper.readValue( + jsonString, + new TypeReference>() {} + ); + + // 转换为Map + Map resultMap = new HashMap<>(); + for (Map.Entry entry : originalMap.entrySet()) { + Object value = entry.getValue(); + // 处理不同类型的值 + if (value == null) { + resultMap.put(entry.getKey(), null); + } else if (value instanceof String || + value instanceof Number || + value instanceof Boolean) { + resultMap.put(entry.getKey(), value.toString()); + } else { + // 对于复杂对象(Map、List等),转换为JSON字符串 + resultMap.put(entry.getKey(), objectMapper.writeValueAsString(value)); + } + } + return resultMap; + } catch (Exception e) { + throw new RuntimeException("Failed to convert JSON to Map", e); + } + } +}