diff --git a/jeecg-module-custom/pom.xml b/jeecg-module-custom/pom.xml index cb96770..9a831aa 100644 --- a/jeecg-module-custom/pom.xml +++ b/jeecg-module-custom/pom.xml @@ -29,6 +29,12 @@ alanpoi-common 1.3.4 + + + net.coobird + thumbnailator + 0.4.14 + diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/OcrApplication.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/OcrApplication.java deleted file mode 100644 index c2ce61f..0000000 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/OcrApplication.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.jeecg.module.custom.ocr; - -public class OcrApplication { -} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/PrevailCloudApi.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/PrevailCloudApi.java index 087f43b..fb26e15 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/PrevailCloudApi.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/PrevailCloudApi.java @@ -1,8 +1,8 @@ package org.jeecg.module.custom.ocr.api; +import org.jeecg.module.custom.ocr.api.entity.FormRecord; import org.jeecg.module.custom.ocr.api.entity.PictureSourceParameter; -import org.jeecg.module.custom.ocr.api.entity.PictureSourceResult; import org.jeecg.module.custom.ocr.common.entity.ApiPage; /** @@ -21,5 +21,5 @@ public interface PrevailCloudApi { * @param pictureSourceParameter * @return */ - ApiPage pullPictureSourceAll(PictureSourceParameter pictureSourceParameter) throws Exception; + ApiPage pullPictureSourceAll(PictureSourceParameter pictureSourceParameter) throws Exception; } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/BaseResult.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/BaseResult.java index a46c612..4f4ce16 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/BaseResult.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/BaseResult.java @@ -1,9 +1,11 @@ package org.jeecg.module.custom.ocr.api.entity; +import lombok.Builder; import lombok.Data; +@Builder @Data -public class BaseResult { +public class BaseResult { /** * 状态 */ @@ -27,5 +29,5 @@ public class BaseResult { /** * 数据 */ - String data; + T data; } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/FormConfigResult.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/FormConfigResult.java index 9de42d6..c142f3e 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/FormConfigResult.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/FormConfigResult.java @@ -6,7 +6,7 @@ import java.util.List; import java.util.Map; @Data -public class FormConfigResult extends BaseResult{ +public class FormConfigResult { /** * 租户雪花no */ 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 8ea8769..676427a 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 @@ -1,7 +1,11 @@ package org.jeecg.module.custom.ocr.api.entity; +import com.fasterxml.jackson.annotation.JsonAnySetter; import lombok.Data; +import java.util.HashMap; +import java.util.Map; + @Data public class FormRecord { @@ -85,4 +89,19 @@ public class FormRecord { */ private Long submitTime; + /** + * 拍照打卡 + */ + private LivePhoto livePhoto; + + // 使用 Map 捕获动态字段 + private Map dynamicFields; + + @JsonAnySetter + public void setDynamicField(String key, Object value) { + if (dynamicFields == null) { + dynamicFields = new HashMap<>(); + } + dynamicFields.put(key, value); + } } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/LivePhoto.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/LivePhoto.java new file mode 100644 index 0000000..39ac909 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/LivePhoto.java @@ -0,0 +1,22 @@ +package org.jeecg.module.custom.ocr.api.entity; + +import lombok.Data; + +@Data +public class LivePhoto { + + /** + * 图片NO + */ + private Long imgNo; + + /** + * 图片地址 + */ + private String imgUrl; + + /** + * 本地图片地址 + */ + private String localImgUrl; +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/PictureSourceResult.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/PictureSourceResult.java index c69bd56..196223a 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/PictureSourceResult.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/entity/PictureSourceResult.java @@ -1,219 +1,219 @@ -package org.jeecg.module.custom.ocr.api.entity; - -import lombok.Data; - -import java.util.List; -import java.util.Map; - -/** - * 图片数据源api 请求参数实体 - * - * @author hugh(shuli.yao) 1397940314@qq.com - * @version 1.0 - * @date 2024/3/14 10:19 - */ -@Data -public class PictureSourceResult { - /** - * id - */ - Long id; - /** - * 租户no - */ - Long tenantNo; - - /** - * 租户名称 - */ - String tenantName; - - /** - * 租户状态 - */ - Integer tenantStatus; - - /** - * 业务主体no - */ - Long accountNo; - - /** - * 业务主体名称 - */ - String accountName; - - /** - * 业务主体状态 - */ - Integer accountStatus; - - /** - * 项目ID - */ - Long projectNo; - - /** - * 项目名称 - */ - String projectName; - - /** - * 项目状态 - */ - Integer projectStatus; - - /** - * 所属主计划ID - */ - Long planNo; - - /** - * 所属主计划名称 - */ - String planName; - /** - * 所属主计划状态 - */ - String planstatus; - - /** - * 所属子计划ID - */ - Long planChildNo; - - /** - * 所属子计划名称 - */ - String planChildName; - - /** - * 所属子计划状态 - */ - String planChildStatus; - - /** - * 任务ID - */ - Long taskId; - - /** - * 任务名称 - */ - String taskName; - - /** - * 任务状态 - */ - Integer taskStatus; - - /** - * 提报人no - */ - Long userNo; - - /** - * 提报人名称 - */ - String userName; - - /** - * 拜访省份/直辖市 - */ - Map province; - - /** - * 拜访城市 - */ - Map city; - - /** - * 拜访客户类型 - */ - Map terminalType; - - /** - * 拜访客户级别 - */ - Map terminalLevel; - - /** - * 拜访客户名称 - */ - Map customerName; - - /** - * 拜访项目 - */ - Map projectType; - - /** - * 品牌卡片 - */ - List> productCard; - - /** - * 拜访品种 - */ - Map productName; - - /** - * 拜访部门 - */ - String companyDepartment; - /** - * 厂商 - */ - Object manufacturer; - - /** - * 拜访小节 - */ - String discoveredIssues; - - /** - * 客户反馈/评价 - */ - String feedback; - - /** - * 定位 - */ - Map location; - - /** - * 定位距离 - */ - String distance; - - /** - * 拜访日期 - */ - String visitDate; - - /** - * 图片列表(拍照打卡(图片)) - */ - List> livePhoto; - - - /** - * 扩展字段 - */ - Map extendedField; - - /** - * 任务提交时间(提报日期时间戳) - */ - Long submitTime; - - /** - * 请求参数 存log用 - */ - PictureSourceParameter requestParam; - - /** - * 备注 - */ - String comment; -} +//package org.jeecg.module.custom.ocr.api.entity; +// +//import lombok.Data; +// +//import java.util.List; +//import java.util.Map; +// +///** +// * 图片数据源api 请求参数实体 +// * +// * @author hugh(shuli.yao) 1397940314@qq.com +// * @version 1.0 +// * @date 2024/3/14 10:19 +// */ +//@Data +//public class PictureSourceResult { +// /** +// * id +// */ +// Long id; +// /** +// * 租户no +// */ +// Long tenantNo; +// +// /** +// * 租户名称 +// */ +// String tenantName; +// +// /** +// * 租户状态 +// */ +// Integer tenantStatus; +// +// /** +// * 业务主体no +// */ +// Long accountNo; +// +// /** +// * 业务主体名称 +// */ +// String accountName; +// +// /** +// * 业务主体状态 +// */ +// Integer accountStatus; +// +// /** +// * 项目ID +// */ +// Long projectNo; +// +// /** +// * 项目名称 +// */ +// String projectName; +// +// /** +// * 项目状态 +// */ +// Integer projectStatus; +// +// /** +// * 所属主计划ID +// */ +// Long planNo; +// +// /** +// * 所属主计划名称 +// */ +// String planName; +// /** +// * 所属主计划状态 +// */ +// String planstatus; +// +// /** +// * 所属子计划ID +// */ +// Long planChildNo; +// +// /** +// * 所属子计划名称 +// */ +// String planChildName; +// +// /** +// * 所属子计划状态 +// */ +// String planChildStatus; +// +// /** +// * 任务ID +// */ +// Long taskId; +// +// /** +// * 任务名称 +// */ +// String taskName; +// +// /** +// * 任务状态 +// */ +// Integer taskStatus; +// +// /** +// * 提报人no +// */ +// Long userNo; +// +// /** +// * 提报人名称 +// */ +// String userName; +// +// /** +// * 拜访省份/直辖市 +// */ +// Map province; +// +// /** +// * 拜访城市 +// */ +// Map city; +// +// /** +// * 拜访客户类型 +// */ +// Map terminalType; +// +// /** +// * 拜访客户级别 +// */ +// Map terminalLevel; +// +// /** +// * 拜访客户名称 +// */ +// Map customerName; +// +// /** +// * 拜访项目 +// */ +// Map projectType; +// +// /** +// * 品牌卡片 +// */ +// List> productCard; +// +// /** +// * 拜访品种 +// */ +// Map productName; +// +// /** +// * 拜访部门 +// */ +// String companyDepartment; +// /** +// * 厂商 +// */ +// Object manufacturer; +// +// /** +// * 拜访小节 +// */ +// String discoveredIssues; +// +// /** +// * 客户反馈/评价 +// */ +// String feedback; +// +// /** +// * 定位 +// */ +// Map location; +// +// /** +// * 定位距离 +// */ +// String distance; +// +// /** +// * 拜访日期 +// */ +// String visitDate; +// +// /** +// * 图片列表(拍照打卡(图片)) +// */ +// List> livePhoto; +// +// +// /** +// * 扩展字段 +// */ +// Map extendedField; +// +// /** +// * 任务提交时间(提报日期时间戳) +// */ +// Long submitTime; +// +// /** +// * 请求参数 存log用 +// */ +// PictureSourceParameter requestParam; +// +// /** +// * 备注 +// */ +// String comment; +//} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/impl/PrevailCloudApiImpl.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/impl/PrevailCloudApiImpl.java index 5e5b134..cec0bb8 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/impl/PrevailCloudApiImpl.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/impl/PrevailCloudApiImpl.java @@ -4,8 +4,8 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import org.jeecg.module.custom.ocr.api.PrevailCloudApi; +import org.jeecg.module.custom.ocr.api.entity.FormRecord; import org.jeecg.module.custom.ocr.api.entity.PictureSourceParameter; -import org.jeecg.module.custom.ocr.api.entity.PictureSourceResult; import org.jeecg.module.custom.ocr.base.constant.PrevailCloudConstant; import org.jeecg.module.custom.ocr.common.entity.ApiPage; import org.jeecg.module.custom.ocr.common.entity.RequestData; @@ -51,7 +51,7 @@ public class PrevailCloudApiImpl implements PrevailCloudApi { @Override - public ApiPage pullPictureSourceAll(PictureSourceParameter pictureSourceParameter) throws Exception { + public ApiPage pullPictureSourceAll(PictureSourceParameter pictureSourceParameter) throws Exception { //1.检查api配置是否正常 if (!apiConfig.checkConfig()) { throw new Exception("api config 配置错误!"); @@ -92,7 +92,7 @@ public class PrevailCloudApiImpl implements PrevailCloudApi { prevailCloudLog.setResponseParam("msg:"+resultData.getMessage()+",status:"+resultData.getStatus()); prevailCloudLog.setStatus(resultData.getStatus()); //定义返回对象 - ApiPage resultApiPage = null; + ApiPage resultApiPage = null; //解密请求数据 if (resultData.getStatus() == 100) { //解析基础数据 @@ -102,7 +102,7 @@ public class PrevailCloudApiImpl implements PrevailCloudApi { prevailCloudLog.setResponseParam(prevailCloudLog.getResponseParam()+",拉取数量:"+apiPage.getTotal()); if(apiPage.getTotal()!=0){ //解析数据结果为List - List listResult = JSONUtil.toList(JSONObject.toJSONString(apiPage.getRecords()), PictureSourceResult.class); + List listResult = JSONUtil.toList(JSONObject.toJSONString(apiPage.getRecords()), FormRecord.class); resultApiPage = new ApiPage<>(); resultApiPage.setPageNo(apiPage.getPageNo()); resultApiPage.setPageSize(apiPage.getPageSize()); diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/PullAllPictureSourceThread.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/PullAllPictureSourceThread.java index fb2fbb6..3b05592 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/PullAllPictureSourceThread.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/PullAllPictureSourceThread.java @@ -4,20 +4,18 @@ import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import org.apache.commons.lang.time.DateFormatUtils; import org.jeecg.module.custom.ocr.api.PrevailCloudApi; +import org.jeecg.module.custom.ocr.api.entity.FormRecord; import org.jeecg.module.custom.ocr.api.entity.PictureSourceAllPullMsg; import org.jeecg.module.custom.ocr.api.entity.PictureSourceParameter; -import org.jeecg.module.custom.ocr.api.entity.PictureSourceResult; import org.jeecg.module.custom.ocr.common.entity.ApiPage; import org.jeecg.module.custom.ocr.config.ApiConfig; -import org.jeecg.module.custom.ocr.service.OcrPictureService; import org.jeecg.module.custom.ocr.service.OcrPrevailCloudLogService; import org.jeecg.module.custom.ocr.utils.SpringUtils; -import org.jeecg.module.custom.ocr.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.time.Instant; -import java.util.*; +import java.util.Date; /** * 拉取无量云全量任务数据线程 @@ -84,7 +82,6 @@ public class PullAllPictureSourceThread implements Runnable{ @Override public void run() { - OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService"); OcrPrevailCloudLogService ocrPrevailCloudLogService = SpringUtils.getBean("ocrPrevailCloudLogService"); //记录执行参数 @@ -122,7 +119,7 @@ public class PullAllPictureSourceThread implements Runnable{ try { //调用无量云api,全量查询方法 - ApiPage apiPage = prevailCloudApi.pullPictureSourceAll(pictureSourceParameter); + ApiPage apiPage = prevailCloudApi.pullPictureSourceAll(pictureSourceParameter); if(apiPage==null){ logger.error("批量拉取无量云数据错误,参数:"+pictureSourceParameter); break; @@ -134,22 +131,12 @@ public class PullAllPictureSourceThread implements Runnable{ pictureSourceAllPullMsg.setPullTaskCount(pictureSourceAllPullMsg.getPullTaskCount()+apiPage.getRecords().size()); pictureSourceAllPullMsg.setTimeTaskCount(apiPage.getTotal()); //将结果加入队列中。 - for (PictureSourceResult pictureSourceResult : apiPage.getRecords()) { + for (FormRecord formRecord : apiPage.getRecords()) { int retryCount = 0; boolean addedToQueue = false; - //如果不存在图片默认一个默认图片,方便走测试。 - if (pictureSourceResult.getLivePhoto() == null) { - List> livePhoto = new ArrayList<>(); - Map map = new HashMap<>(); - map.put("imgUrl", StringUtils.isEmpty(apiConfig.getDefaultPictureImg()) ? "http://47.93.59.251/api/image/default.png" : apiConfig.getDefaultPictureImg()); - map.put("imgName", "default.png"); - livePhoto.add(map); - pictureSourceResult.setLivePhoto(livePhoto); - } // 将数据放入队列,最多重试5次 while (!addedToQueue && retryCount < 5) { - pictureSourceResult.setRequestParam(pictureSourceParameter); - addedToQueue = TaskQueue.pictureDisposePushData(pictureSourceResult, ocrPictureService, ocrPrevailCloudLogService); + addedToQueue = TaskQueue.pictureDisposePushData(formRecord, ocrPrevailCloudLogService); if (!addedToQueue) { Thread.sleep(60000); retryCount++; diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskQueue.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskQueue.java index 38eaf70..165cf51 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskQueue.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskQueue.java @@ -2,12 +2,9 @@ package org.jeecg.module.custom.ocr.api.thread; import com.google.common.collect.Sets; -import org.jeecg.module.custom.ocr.api.entity.PictureSourceResult; +import org.jeecg.module.custom.ocr.api.entity.FormRecord; import org.jeecg.module.custom.ocr.base.constant.PrevailCloudConstant; -import org.jeecg.module.custom.ocr.dataobject.OcrPicture; import org.jeecg.module.custom.ocr.dataobject.OcrPrevailCloudLog; -import org.jeecg.module.custom.ocr.dataobject.OcrTaskchildPicture; -import org.jeecg.module.custom.ocr.service.OcrPictureService; import org.jeecg.module.custom.ocr.service.OcrPrevailCloudLogService; import java.util.Set; @@ -27,51 +24,38 @@ public class TaskQueue { */ public static LinkedBlockingQueue pictureDisposeQueue = new LinkedBlockingQueue(); + /** + * picture图片转储到本地 任务队列 + */ + public static LinkedBlockingQueue pictureImgToLocalQueue = new LinkedBlockingQueue(); + public static volatile Set resultSet = Sets.newConcurrentHashSet(); /** * 无量云接口数据处理 push 队列值 * - * @param pictureSourceResult //三方拉取 获取到的图片对象 + * @param formRecord //三方拉取 获取到的图片对象 * @return */ - public static boolean pictureDisposePushData(PictureSourceResult pictureSourceResult, OcrPictureService ocrPictureService, OcrPrevailCloudLogService ocrPrevailCloudLogService) { + public static boolean pictureDisposePushData(FormRecord formRecord, OcrPrevailCloudLogService ocrPrevailCloudLogService) { try { - Long taskId = pictureSourceResult.getTaskId(); - OcrPicture ocrPicture = ocrPictureService.selectByRemark(String.valueOf(taskId)); - if (ocrPicture != null) { - OcrTaskchildPicture taskchildPicture = ocrPictureService.getOcrTaskChildPictureByPictureId(ocrPicture.getId().toString()); - if (taskchildPicture != null && pictureSourceResult.getTaskStatus() != null - && (pictureSourceResult.getTaskStatus() == 6 || pictureSourceResult.getTaskStatus() == 7) && (taskchildPicture.getStates() == 5 || taskchildPicture.getStates() == 3)) { - if (taskchildPicture.getStates() == 5) { - String result = ocrPictureService.getPictureApproveResult(ocrPicture.getId()); - pictureSourceResult.setComment(result); - } else { - pictureSourceResult.setComment("ocr审批全部通过,由无量云发起了重置审批流程的操作。"); - } - ocrPictureService.deletePictureInfo(ocrPicture.getId()); - pictureSourceResult.setId(ocrPicture.getId()); - } else { - return true; - } - } + Long taskId = formRecord.getTaskId(); + //添加日志 OcrPrevailCloudLog ocrPrevailCloudLog = OcrPrevailCloudLog.builder() - .formId(pictureSourceResult.getTaskId()) - .requestParam(pictureSourceResult.getRequestParam().toString()) - .responseParam(pictureSourceResult.toString()) + .formId(formRecord.getTaskId()) + .responseParam(formRecord.toString()) .type(PrevailCloudConstant.DISPOSE_PICTURE_SOURCE) .status(100) .time(0) .build(); ocrPrevailCloudLogService.save(ocrPrevailCloudLog); resultSet.add(String.valueOf(taskId)); - pictureDisposeQueue.put(pictureSourceResult); + pictureDisposeQueue.put(formRecord); } catch (InterruptedException e) { OcrPrevailCloudLog ocrPrevailCloudLog = OcrPrevailCloudLog.builder() - .formId(pictureSourceResult.getTaskId()) - .requestParam(pictureSourceResult.getRequestParam().toString()) - .responseParam(pictureSourceResult.toString()) + .formId(formRecord.getTaskId()) + .responseParam(formRecord.toString()) .type(PrevailCloudConstant.DISPOSE_PICTURE_SOURCE) .status(500) .time(0) @@ -82,4 +66,37 @@ public class TaskQueue { return true; } + /** + * 图片缓存本地队列 push 队列值 + * + * @param formRecord //图片下载对象 + * @return + */ + public static boolean pictureImgToLocalPushData(FormRecord formRecord) { + try { + pictureImgToLocalQueue.put(formRecord); + } catch (InterruptedException e) { + return false; + } + return true; + } + + /** + * 无量云接口数据处理 拉取队列值 + * + * @return + */ + public static FormRecord pictureDisposePullData() { + return (FormRecord) pictureDisposeQueue.poll(); + } + + /** + * 无量云接口图片数据处理 拉取队列值 + * + * @return + */ + public static FormRecord pictureImgToLocalPullData() { + return (FormRecord) pictureImgToLocalQueue.poll(); + } + } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskRunner.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskRunner.java new file mode 100644 index 0000000..a185a81 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskRunner.java @@ -0,0 +1,22 @@ +package org.jeecg.module.custom.ocr.api.thread; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +/** + * 初始化执行器 + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/03/14 3:08 + */ +@Component +public class TaskRunner implements CommandLineRunner { + + @Override + public void run(String... args) throws Exception { + TaskThreadPool taskThreadPool = new TaskThreadPool(); + taskThreadPool.startPictureDisposePull(); + taskThreadPool.startPictureImgToLocalPull(); + } +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskThreadPool.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskThreadPool.java new file mode 100644 index 0000000..9be1bd2 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/TaskThreadPool.java @@ -0,0 +1,99 @@ +package org.jeecg.module.custom.ocr.api.thread; + +import lombok.SneakyThrows; +import org.jeecg.module.custom.ocr.api.entity.FormRecord; +import org.jeecg.module.custom.ocr.api.thread.tasks.PictureDisposeTask; +import org.jeecg.module.custom.ocr.api.thread.tasks.PictureImgToLocalTask; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.*; + +/** + * 任务线程池 + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/03/14 3:08 + */ +public class TaskThreadPool { + + private static Logger logger = LoggerFactory.getLogger(TaskQueue.class); + ExecutorService threadPool = null; + ExecutorService threadPoolImg = null; + + public TaskThreadPool() { + if (threadPool == null) { + threadPool = new ThreadPoolExecutor( + 10, + 40, + 3, + TimeUnit.SECONDS, + new LinkedBlockingDeque<>(), + Executors.defaultThreadFactory(), + new ThreadPoolExecutor.DiscardOldestPolicy()); + + threadPoolImg = new ThreadPoolExecutor( + 10, + 40, + 3, + TimeUnit.SECONDS, + new LinkedBlockingDeque<>(), + Executors.defaultThreadFactory(), + new ThreadPoolExecutor.DiscardOldestPolicy()); + } + } + + /** + * 启动任务 入库消费者 + */ + public void startPictureDisposePull() { + Runnable runnable = new Runnable() { + @SneakyThrows + @Override + public void run() { + while (true) { + logger.debug("无量云接口数据处理消费线程检测中...,队列数量:{}",TaskQueue.pictureDisposeQueue.size()); + FormRecord pictureSourceResult = TaskQueue.pictureDisposePullData(); + if (pictureSourceResult != null) { + threadPool.execute(new PictureDisposeTask(pictureSourceResult)); + } else { + Thread.sleep(5000); + } + } + } + }; + Thread thread = new Thread(runnable); + thread.start(); + } + + /** + * 启动任务 入库消费者 + */ + public void startPictureImgToLocalPull() { + Runnable runnable = new Runnable() { + @SneakyThrows + @Override + public void run() { + while (true) { + logger.debug("图片下载消费线程检测中...,队列数量:{}",TaskQueue.pictureImgToLocalQueue.size()); + try { + FormRecord pictureImgToLocalEntity = TaskQueue.pictureImgToLocalPullData(); + if (pictureImgToLocalEntity != null) { + threadPoolImg.execute(new PictureImgToLocalTask(pictureImgToLocalEntity)); + } else { + Thread.sleep(5000); + } + } catch (Exception e) { + logger.error("图片下载消费线程报错{}", e.getMessage()); + Thread.sleep(5000); + } + + } + } + }; + Thread thread = new Thread(runnable); + thread.start(); + } + +} 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 new file mode 100644 index 0000000..055c367 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureDisposeTask.java @@ -0,0 +1,55 @@ +package org.jeecg.module.custom.ocr.api.thread.tasks; + +import org.jeecg.module.custom.ocr.api.entity.FormRecord; +import org.jeecg.module.custom.ocr.api.entity.LivePhoto; +import org.jeecg.module.custom.ocr.dataobject.OcrPicture; +import org.jeecg.module.custom.ocr.service.OcrPictureService; +import org.jeecg.module.custom.ocr.utils.SpringUtils; +import org.jeecg.module.custom.ocr.utils.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * 无量云接口 数据处理队列 + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/3/14 11:15 + */ +public class PictureDisposeTask implements Runnable { + protected Logger logger = LoggerFactory.getLogger(getClass()); + + private FormRecord pictureSourceResult; + + public PictureDisposeTask(FormRecord pictureSourceResult) { + this.pictureSourceResult = pictureSourceResult; + } + + @Override + public void run() { + //1.对图片对象进行入库操作 + OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService"); + + //获取当前任务中有多少图片 + LivePhoto livePhoto = pictureSourceResult.getLivePhoto(); + + //定义新增集合对象 + List ocrPictureList = new ArrayList<>(); + + //检查图片地址是否为空 + if (StringUtils.isEmpty(livePhoto.getImgUrl())) { + OcrPicture picture = new OcrPicture(); + // TODO: 字段对应转换 + picture.setCreateBy("1"); + picture.setImgurl(livePhoto.getImgUrl()); + picture.setHistory(true); + ocrPictureList.add(picture); + } + + //调用图片入库方法 + int size = ocrPictureService.savePictures(ocrPictureList); + } +} 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 new file mode 100644 index 0000000..f17ff24 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/api/thread/tasks/PictureImgToLocalTask.java @@ -0,0 +1,85 @@ +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.api.thread.TaskQueue; +import org.jeecg.module.custom.ocr.dataobject.OcrPicture; +import org.jeecg.module.custom.ocr.service.OcrPictureService; +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 java.io.File; +import java.io.IOException; +import java.util.Map; + + +/** + * 无量云接口 数据处理队列 + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/3/14 11:15 + */ +@Slf4j +public class PictureImgToLocalTask implements Runnable { + protected Logger logger = LoggerFactory.getLogger(getClass()); + + private FormRecord pictureImgToLocal; + + public PictureImgToLocalTask(FormRecord pictureImgToLocal) { + this.pictureImgToLocal = pictureImgToLocal; + } + + @Override + public void run() { + OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService"); + OcrPicture picture = ocrPictureService.getById(pictureImgToLocal.getLivePhoto().getImgNo()); + //1.开始转储图片 + Boolean result = true; + //检查是否已经存在本地图片,存在则不进行转储了。 + File file = new File(pictureImgToLocal.getLivePhoto().getLocalImgUrl()); + if(!file.isFile()){ + result = DownloadImgUtil.downloadImage(pictureImgToLocal.getLivePhoto().getImgUrl(), pictureImgToLocal.getLivePhoto().getLocalImgUrl()); + } + if (Boolean.TRUE.equals(result)) { + if (ObjectUtil.isNotEmpty(picture)) { + picture.setLocalpictrueurl(pictureImgToLocal.getLivePhoto().getLocalImgUrl()); + picture.setIsdownload(1); + try { + picture.setLocalThumbnailUrl(ImageUtils.generateThumbnail(pictureImgToLocal.getLivePhoto().getLocalImgUrl(),182)); +// picture.setServerThumbnailUrl(ocrPictureService.getServerUrl()+ImageUtils.getFileName(picture.getLocalThumbnailUrl())); + } catch (IOException e) { + throw new RuntimeException(e); + } + Map ocrPictureClassifyAndHash = ocrPictureService.getOcrPictureClassifyAndHash(picture.getLocalpictrueurl()); + if(ocrPictureClassifyAndHash!=null){ + picture.setImgHash(ocrPictureClassifyAndHash.get("hash")); + picture.setClassificationid(ocrPictureClassifyAndHash.get("classId")); + } + + ocrPictureService.updateById(picture); + logger.info("图片本地化,回写数据完成!"); + logger.info("开启获取图片信息操作!"); + ocrPictureService.savePicturesInfo(picture); + logger.info("获取图片信息操作,结束!"); + } + }else{ + //判断是否是第一次失败! + if(picture.getDownloadErrorCount()==null){ + picture.setDownloadErrorCount(0); + } + //判断如果没超过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/config/ApiConfig.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/config/ApiConfig.java index c0fc28b..736e244 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/config/ApiConfig.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/config/ApiConfig.java @@ -71,6 +71,11 @@ public class ApiConfig { */ private String tenantSourceUrl = "/pangu/jingwei/ocr/query/pb/tenant/info"; + /** + * 表单配置 + */ + private String formConfigUrl = ""; + /** * 检查配置文件是否 正确注入 * @return diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/FormConfigController.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/FormConfigController.java index 209f945..e4731a4 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/FormConfigController.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/FormConfigController.java @@ -1,13 +1,37 @@ package org.jeecg.module.custom.ocr.controller; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.jeecg.module.custom.ocr.api.entity.BaseResult; +import org.jeecg.module.custom.ocr.api.entity.FormConfigResult; +import org.jeecg.module.custom.ocr.controller.dto.FormSyncRequest; +import org.jeecg.module.custom.ocr.service.FormConfigService; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; + @Api(tags = "ocr_表单字段配置信息") @Slf4j @RestController @RequestMapping("/form/config") public class FormConfigController { + + @Resource + private FormConfigService formConfigService; + + /** + * 拉取无量云全量任务数据,根据业务主体 + * + * @param request + * @return + */ + @ApiOperation(value = "同步配置", notes = "同步配置") + @PostMapping("/sync") + public BaseResult sync(@RequestBody FormSyncRequest request) { + return formConfigService.sync(request); + } } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/FormConfigSyncData.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/FormConfigSyncData.java new file mode 100644 index 0000000..7cb9257 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/FormConfigSyncData.java @@ -0,0 +1,26 @@ +package org.jeecg.module.custom.ocr.controller.dto; + +import lombok.Data; + +@Data +public class FormConfigSyncData { + /** + * 业务主体 + */ + private Long accountNo; + + /** + * 租户 + */ + private Long tenantNo; + + /** + * 项目no + */ + private Long projectNo; + + /** + * 表单no + */ + private Long taskFormNo; +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/FormConfigSyncRequest.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/FormConfigSyncRequest.java new file mode 100644 index 0000000..e269e15 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/FormConfigSyncRequest.java @@ -0,0 +1,17 @@ +package org.jeecg.module.custom.ocr.controller.dto; + +import lombok.Data; + +@Data +public class FormConfigSyncRequest { + + private String tenantCode; + + private String accessKey; + + private Long timestamp; + + private String signature; + + private FormConfigSyncData data; +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/FormSyncRequest.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/FormSyncRequest.java new file mode 100644 index 0000000..13bd27f --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/controller/dto/FormSyncRequest.java @@ -0,0 +1,28 @@ +package org.jeecg.module.custom.ocr.controller.dto; + +import lombok.Data; +import org.springframework.validation.annotation.Validated; + +import javax.validation.constraints.NotNull; + +@Validated +@Data +public class FormSyncRequest { + /** + * 租户 + */ + @NotNull + private Long tenantNo; + + /** + * 项目no + */ + @NotNull + private Long projectNo; + + /** + * 表单no + */ + @NotNull + private Long taskFormNo; +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/OcrDictionaryDao.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/OcrDictionaryDao.java new file mode 100644 index 0000000..13021f0 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/OcrDictionaryDao.java @@ -0,0 +1,12 @@ +package org.jeecg.module.custom.ocr.dataDao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.jeecg.module.custom.ocr.dataobject.OcrDictionary; + +/** + * + */ +@Mapper +public interface OcrDictionaryDao extends BaseMapper { +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/OcrDictionaryGroupDao.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/OcrDictionaryGroupDao.java new file mode 100644 index 0000000..1df7333 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataDao/OcrDictionaryGroupDao.java @@ -0,0 +1,12 @@ +package org.jeecg.module.custom.ocr.dataDao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.jeecg.module.custom.ocr.dataobject.OcrDictionaryGroup; + +/** + * + */ +@Mapper +public interface OcrDictionaryGroupDao extends BaseMapper { +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrDictionary.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrDictionary.java new file mode 100644 index 0000000..3918567 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrDictionary.java @@ -0,0 +1,98 @@ +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 io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.jeecg.module.custom.ocr.common.dto.BaseDto; +import org.jeecg.module.custom.ocr.utils.requestFormat.SearchQuery; + +import java.util.AbstractMap; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * TODO + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/3/16 12:40 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "业务数据字典值表", title = "业务数据字典值表") +@ApiModel(value="业务数据字典值表", description="业务数据字典值表") +@TableName(value = "ocr_dictionary") +public class OcrDictionary implements BaseDto,java.io.Serializable{ + + @ApiModelProperty(value ="主键") + @TableId(value = "id",type = IdType.ASSIGN_ID) + @JsonSerialize(using = ToStringSerializer.class) + @TableField(value="id") + private Long id; + + @ApiModelProperty(value ="三方系统 原始id 可为空") + @TableField(value="source_id") + private Long sourceId; + + @ApiModelProperty(value ="字典值") + @TableField(value="value") + private String value; + + @ApiModelProperty(value ="描述") + @TableField(value="lable") + private String lable; + + @ApiModelProperty(value ="租户id") + @TableField(value="tenant_id") + @JsonSerialize(using = ToStringSerializer.class) + private Long tenantId; + + @ApiModelProperty(value ="租户名称") + @TableField(exist = false) + private String tenantName; + + @ApiModelProperty(value ="字典组") + @TableField(value="group_id") + private Long groupId; + + + @TableField(exist = false) + @JsonIgnore + private final Map query = Stream.of( + new AbstractMap.SimpleEntry<>("ID","id"), + new AbstractMap.SimpleEntry<>("DISTIONATYGROUPID","group_id"), + new AbstractMap.SimpleEntry<>("CODENO","value"), + new AbstractMap.SimpleEntry<>("NAME","lable") + ) + .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); + + + @Override + public String getQueryFiled(String filedname){ + String obj = null; + if(null != query && query.size() > 0){ + obj = query.get(filedname); + } + return obj; + } + + + //保存当前登录用户的数据权限范围的搜索条件 + @TableField(exist = false) + @JsonIgnore + private SearchQuery searchQueryrolesShowleave; +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrDictionaryGroup.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrDictionaryGroup.java new file mode 100644 index 0000000..aee65ad --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrDictionaryGroup.java @@ -0,0 +1,87 @@ +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 io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.jeecg.module.custom.ocr.common.dto.BaseDto; +import org.jeecg.module.custom.ocr.utils.requestFormat.SearchQuery; + +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * TODO + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/3/16 12:40 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "业务数据字典组表", title = "业务数据字典组表") +@ApiModel(value="业务数据字典组表", description="业务数据字典组表") +@TableName(value = "ocr_dictionary_group") +public class OcrDictionaryGroup implements BaseDto,java.io.Serializable { + @ApiModelProperty(value ="主键") + @TableId(value = "id",type = IdType.ASSIGN_ID) + @JsonSerialize(using = ToStringSerializer.class) + @TableField(value="id") + private Long id; + + @ApiModelProperty(value ="字典组中文描述") + @TableField(value="label") + private String label; + + @ApiModelProperty(value ="对应属性字段名称") + @TableField(value="field") + private String field; + + @ApiModelProperty(value ="备注") + @TableField(value="remark") + private String remark; + + + @TableField(exist = false) + private List distionaryList; + + + //保存当前登录用户的数据权限范围的搜索条件 + @TableField(exist = false) + @JsonIgnore + private SearchQuery searchQueryrolesShowleave; + + + @TableField(exist = false) + @JsonIgnore + private final Map query = Stream.of( + new AbstractMap.SimpleEntry<>("listdept","deptid"), + new AbstractMap.SimpleEntry<>("ID","id"), + new AbstractMap.SimpleEntry<>("CODENO","field"), + new AbstractMap.SimpleEntry<>("GROUPNAME","label") + ) + .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); + @Override + public String getQueryFiled(String filedname){ + String obj = null; + if(null != query && query.size() > 0){ + obj = query.get(filedname); + } + return obj; + } +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrPicture.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrPicture.java index 400fda3..2448a06 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrPicture.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/dataobject/OcrPicture.java @@ -378,6 +378,11 @@ public class OcrPicture implements BaseDto, java.io.Serializable { @TableField(value = "complete_similar_group_id") private Long completeSimilarGroupId; + @ApiModelProperty(value = "是否为历史图") + @Schema(description = "是否为历史图") + @TableField(value = "history") + private Boolean history; + @ApiModelProperty(value = "节点状态") @TableField(exist = false) private Integer historyStates; diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/FormConfigService.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/FormConfigService.java index 7d6aa8d..75c9f9d 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/FormConfigService.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/FormConfigService.java @@ -1,7 +1,11 @@ package org.jeecg.module.custom.ocr.service; import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.module.custom.ocr.api.entity.BaseResult; +import org.jeecg.module.custom.ocr.api.entity.FormConfigResult; +import org.jeecg.module.custom.ocr.controller.dto.FormSyncRequest; import org.jeecg.module.custom.ocr.dataobject.FormConfig; public interface FormConfigService extends IService { + BaseResult sync(FormSyncRequest request); } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/IOcrCheckDuplicateResultService.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/IOcrCheckDuplicateResultService.java deleted file mode 100644 index 01177bc..0000000 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/IOcrCheckDuplicateResultService.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.jeecg.module.custom.ocr.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import org.jeecg.module.custom.ocr.dataobject.OcrCheckDuplicateResult; - -/** - *

- * 服务类 - *

- * - * @author author - * @since 2024-03-24 - */ -public interface IOcrCheckDuplicateResultService extends IService { -} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/IOcrPictureDuplicateHisService.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/IOcrPictureDuplicateHisService.java deleted file mode 100644 index 4c56436..0000000 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/IOcrPictureDuplicateHisService.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.jeecg.module.custom.ocr.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import org.jeecg.module.custom.ocr.dataobject.OcrPictureDuplicateHis; - -/** - *

- * 图片比对历史信息表 服务类 - *

- * - * @author author - * @since 2024-03-24 - */ -public interface IOcrPictureDuplicateHisService extends IService { -} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrCheckDescribeHisService.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrCheckDescribeHisService.java deleted file mode 100644 index bdd75a6..0000000 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrCheckDescribeHisService.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.jeecg.module.custom.ocr.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import org.jeecg.module.custom.ocr.dataobject.OcrCheckDescribeHis; - -/** -* ClassName: $className$.java -* Description: -* Author: scl. -* Date: 2024/4/18 22:57 -*/ -public interface OcrCheckDescribeHisService extends IService{ - - -} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrDictionaryService.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrDictionaryService.java new file mode 100644 index 0000000..a4d2bdb --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrDictionaryService.java @@ -0,0 +1,30 @@ +package org.jeecg.module.custom.ocr.service; + +import org.jeecg.module.custom.ocr.base.BaseService; +import org.jeecg.module.custom.ocr.dataobject.OcrDictionary; +import org.jeecg.module.custom.ocr.dataobject.OcrDictionaryGroup; + +/** + * 业务向 数据字典 操作接口 + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/3/16 12:48 + */ +public interface OcrDictionaryService extends BaseService { + /** + * 根据 字组标识、字典值、租户过滤当前字典是否存在此字典值。 + * @param groupId 字典组标识 + * @param value 字典值 + * @param tenantId 租户 + * @return + */ + boolean isValueExists(Long groupId, String value, Long tenantId); + + /** + * 获取字典组信息 + * @param field + * @return + */ + OcrDictionaryGroup queryGroupByField(String field); +} 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 75e704c..8f163d1 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 @@ -2,24 +2,23 @@ package org.jeecg.module.custom.ocr.service; import org.jeecg.module.custom.ocr.base.BaseService; import org.jeecg.module.custom.ocr.dataobject.OcrPicture; -import org.jeecg.module.custom.ocr.dataobject.OcrTaskchildPicture; + +import java.util.List; +import java.util.Map; /** * 业务层 */ public interface OcrPictureService extends BaseService { - - String getPictureApproveResult(Long id); - - void deletePictureInfo(Long id); - /** - * 根据任务id查询图片信息 + * 批量保存 图片信息 * - * @param remark + * @param ocrPictureList * @return */ - OcrPicture selectByRemark(String remark); + int savePictures(List ocrPictureList); + + Map getOcrPictureClassifyAndHash(String img); - OcrTaskchildPicture getOcrTaskChildPictureByPictureId(String pictureId); + void savePicturesInfo(OcrPicture ocrPicture); } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrTaskchildPictureService.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrTaskchildPictureService.java index 835f810..50a2158 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrTaskchildPictureService.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/OcrTaskchildPictureService.java @@ -1,10 +1,18 @@ package org.jeecg.module.custom.ocr.service; import org.jeecg.module.custom.ocr.base.BaseService; +import org.jeecg.module.custom.ocr.dataobject.OcrPicture; import org.jeecg.module.custom.ocr.dataobject.OcrTaskchildPicture; /** * 业务层 */ public interface OcrTaskchildPictureService extends BaseService { + + /** + * 根据picture创建任务,针对无量云已经审核过的历史数据 + * @param picture + * @return + */ + boolean createTaskOldPicture(OcrPicture picture); } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/UserapproveService.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/UserapproveService.java deleted file mode 100644 index 34c1268..0000000 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/UserapproveService.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.jeecg.module.custom.ocr.service; - - -import org.jeecg.module.custom.ocr.base.BaseService; -import org.jeecg.module.custom.ocr.dataobject.Userapprove; - -/** -* 业务层 -*/ -public interface UserapproveService extends BaseService { - /** - * 删除审批人员于业务表单的关联 - * @param formid 业务表单主键 - * @return 成功返回true,否则返回false - */ - public boolean delete(String formid); -} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/FormConfigServiceImpl.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/FormConfigServiceImpl.java new file mode 100644 index 0000000..204b72c --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/FormConfigServiceImpl.java @@ -0,0 +1,94 @@ +package org.jeecg.module.custom.ocr.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.module.custom.ocr.api.entity.BaseResult; +import org.jeecg.module.custom.ocr.api.entity.FormConfigResult; +import org.jeecg.module.custom.ocr.common.entity.RequestData; +import org.jeecg.module.custom.ocr.common.entity.ResultData; +import org.jeecg.module.custom.ocr.config.ApiConfig; +import org.jeecg.module.custom.ocr.controller.dto.FormSyncRequest; +import org.jeecg.module.custom.ocr.dataDao.FormConfigMapper; +import org.jeecg.module.custom.ocr.dataobject.FormConfig; +import org.jeecg.module.custom.ocr.service.FormConfigService; +import org.jeecg.module.custom.ocr.utils.ApiHelper; +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; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Map; + +@Slf4j +@Service +public class FormConfigServiceImpl extends ServiceImpl implements FormConfigService { + + /** + * 注入api 配置信息 + */ + @Autowired + private ApiConfig apiConfig; + + @Transactional(rollbackFor = Exception.class) + @SneakyThrows + @Override + public BaseResult sync(FormSyncRequest request) { + //2.对象转map + Map queryParam = BeanUtil.beanToMap(request); + + //加密请求参数 + String tenantNo = request.getTenantNo().toString(); + String json = JSONObject.toJSONString(queryParam); + RequestData requestData = ApiHelper.buildRequest(tenantNo, apiConfig.getAccessKey(), apiConfig.getAccessCode(), json); + //组装请求参数 + String url = apiConfig.getInterfaceDomain() + apiConfig.getFormConfigUrl(); + String requestBodyJson = JSONObject.toJSONString(requestData); + //入参 + HttpParamers httpParamers = new HttpParamers(HttpMethod.POST); + httpParamers.setJsonParamer(requestBodyJson); + //发起请求 + String responseJsonStr = HttpClient.doPost(url, httpParamers, null, apiConfig.getConnectTimeout(), apiConfig.getReadTimeout()); + ResultData resultData = JSONUtil.toBean(responseJsonStr, ResultData.class); + //定义返回对象 + FormConfigResult formConfigResult = null; + BaseResult baseResult = null; + //解密请求数据 + if (resultData.getStatus() == 100) { + //解析基础数据 + String data = ApiHelper.decryptResponse(apiConfig.getAccessCode(), resultData); + baseResult = JSONUtil.toBean(data, BaseResult.class); + if ("200".equals(baseResult.getStatus())) { + formConfigResult = baseResult.getData(); + FormConfig formConfig = FormConfig.builder() + .status(baseResult.getStatus()) + .message(baseResult.getMessage()) + .timestamp(baseResult.getTimeStamp()) + .signature(baseResult.getSignature()) + .data(JSONObject.toJSONString(baseResult.getData())) + .tenantNo(formConfigResult.getTenantNo()) + .accountNo(formConfigResult.getAccountNo()) + .projectNo(formConfigResult.getProjectNo()) + .taskFormNo(formConfigResult.getTaskFormNo()) + .fieldList(JSONObject.toJSONString(formConfigResult.getFieldList())) + .type(formConfigResult.getType()) + .fieldCode(formConfigResult.getFieldCode()) + .fieldName(formConfigResult.getFieldName()) + .parentFileCode(formConfigResult.getParentFileCode()) + .level(formConfigResult.getLevel()) + .build(); + this.save(formConfig); + } + + } else { + log.error("请求图片接口数据失败,参数:{},返回值:{}", json, responseJsonStr); + } + + return baseResult; + } +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrCheckDescribeHisServiceImpl.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrCheckDescribeHisServiceImpl.java deleted file mode 100644 index 1643c1d..0000000 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrCheckDescribeHisServiceImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.jeecg.module.custom.ocr.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.jeecg.module.custom.ocr.dataDao.OcrCheckDescribeHisMapper; -import org.jeecg.module.custom.ocr.dataobject.OcrCheckDescribeHis; -import org.jeecg.module.custom.ocr.service.OcrCheckDescribeHisService; -import org.springframework.stereotype.Service; - -/** - * ClassName: $className$.java - * Description: - * Author: scl. - * Date: 2024/4/18 22:57 - */ -@Service -public class OcrCheckDescribeHisServiceImpl extends ServiceImpl implements OcrCheckDescribeHisService { - -} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrDictionaryServiceImpl.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrDictionaryServiceImpl.java new file mode 100644 index 0000000..baaf296 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrDictionaryServiceImpl.java @@ -0,0 +1,50 @@ +package org.jeecg.module.custom.ocr.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.module.custom.ocr.base.BaseServiceImpl; +import org.jeecg.module.custom.ocr.dataDao.OcrDictionaryDao; +import org.jeecg.module.custom.ocr.dataDao.OcrDictionaryGroupDao; +import org.jeecg.module.custom.ocr.dataobject.OcrDictionary; +import org.jeecg.module.custom.ocr.dataobject.OcrDictionaryGroup; +import org.jeecg.module.custom.ocr.service.OcrDictionaryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 业务向 数据字典 操作接口实现类 + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/3/16 12:48 + */ +@Service +@Slf4j +public class OcrDictionaryServiceImpl extends BaseServiceImpl implements OcrDictionaryService { + + @Autowired + private OcrDictionaryGroupDao ocrDictionaryGroupDao; + + @Override + public boolean isValueExists(Long groupId, String value, Long tenantId) { + QueryWrapper queryWrapper =new QueryWrapper(); + queryWrapper.eq("group_id",groupId); + queryWrapper.eq("value",value); + queryWrapper.eq("tenant_id",groupId); + Long count = baseMapper.selectCount(queryWrapper); + return count>0 ? false:true; + } + + @Override + public OcrDictionaryGroup queryGroupByField(String field) { + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("field",field); + List ocrDictionaryGroupList = ocrDictionaryGroupDao.selectList(queryWrapper); + if(ocrDictionaryGroupList!=null && ocrDictionaryGroupList.size()>0){ + return ocrDictionaryGroupList.get(0); + } + return null; + } +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrPictureDuplicateHisServiceImpl.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrPictureDuplicateHisServiceImpl.java deleted file mode 100644 index 436724f..0000000 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrPictureDuplicateHisServiceImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.jeecg.module.custom.ocr.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.jeecg.module.custom.ocr.dataDao.OcrPictureDuplicateHisMapper; -import org.jeecg.module.custom.ocr.dataobject.OcrPictureDuplicateHis; -import org.jeecg.module.custom.ocr.service.IOcrPictureDuplicateHisService; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - *

- * 图片比对历史信息表 服务实现类 - *

- * - * @author author - * @since 2024-03-24 - */ -@Service -public class OcrPictureDuplicateHisServiceImpl extends ServiceImpl implements IOcrPictureDuplicateHisService { - - -} 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 40ceaca..5269020 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 @@ -1,21 +1,35 @@ package org.jeecg.module.custom.ocr.service.impl; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.jeecg.module.custom.ocr.api.entity.FormRecord; +import org.jeecg.module.custom.ocr.api.entity.LivePhoto; +import org.jeecg.module.custom.ocr.api.thread.TaskQueue; import org.jeecg.module.custom.ocr.base.BaseServiceImpl; +import org.jeecg.module.custom.ocr.config.ApiConfig; import org.jeecg.module.custom.ocr.dataDao.OcrPictureMybatisDao; -import org.jeecg.module.custom.ocr.dataobject.*; -import org.jeecg.module.custom.ocr.service.*; +import org.jeecg.module.custom.ocr.dataobject.OcrPicture; +import org.jeecg.module.custom.ocr.dataobject.OcrPictureInfo; +import org.jeecg.module.custom.ocr.service.OcrPictureInfoService; +import org.jeecg.module.custom.ocr.service.OcrPictureService; +import org.jeecg.module.custom.ocr.service.OcrTaskchildPictureService; +import org.jeecg.module.custom.ocr.utils.DataDictionaryUtil; +import org.jeecg.module.custom.ocr.utils.ImageClassUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.Arrays; +import javax.imageio.ImageIO; +import java.awt.color.ColorSpace; +import java.awt.image.BufferedImage; +import java.io.File; +import java.net.URL; +import java.net.URLConnection; +import java.util.HashMap; import java.util.List; -import java.util.Set; +import java.util.Map; /** * 业务层实现 @@ -24,90 +38,198 @@ import java.util.Set; @Slf4j public class OcrPictureServiceImpl extends BaseServiceImpl implements OcrPictureService { - @Resource - OcrPictureMybatisDao pictureMybatisDao; - @Resource private OcrTaskchildPictureService ocrTaskchildPictureService; - @Resource - private OcrPictureInfoService ocrPictureInfoService; + /** + * 注入api 配置信息 + */ + @Autowired + private ApiConfig apiConfig; - @Resource - private OcrCheckDescribeHisService ocrCheckDescribeHisService; + /** + * 字典数据添加工具类 + */ + @Autowired + DataDictionaryUtil dataDictionaryUtil; - @Resource - private IOcrCheckDuplicateResultService ocrCheckDuplicateResultService; + @Value("${image.classifyPath}") + private String classifyPath; @Resource - private IOcrPictureDuplicateHisService ocrPictureDuplicateHisService; + private OcrPictureInfoService ocrPictureInfoService; - @Autowired - private UserapproveService userapproveService; + private Object lock = new Object(); - @Override - public String getPictureApproveResult(Long id) { - return pictureMybatisDao.getPictureApproveResult(id); - } @Override - public void deletePictureInfo(Long id) { - //删除图片表 - pictureMybatisDao.deleteById(id); - //删除图片信息表 - ocrPictureInfoService.remove(new LambdaQueryWrapper().eq(OcrPictureInfo::getPictureId, id)); - OcrTaskchildPicture taskchildPicture = ocrTaskchildPictureService.getOne(new LambdaQueryWrapper().eq(OcrTaskchildPicture::getPictureid, id)); - //删除任务表 - ocrTaskchildPictureService.remove(new LambdaQueryWrapper().eq(OcrTaskchildPicture::getPictureid, id)); - //删除审批记录表 - userapproveService.delete(taskchildPicture.getId().toString()); - //小结查重记录 - OcrCheckDescribeHis checkDescribeHis = ocrCheckDescribeHisService.getOne(new LambdaQueryWrapper().eq(OcrCheckDescribeHis::getPictureId, id)); - if (checkDescribeHis != null) { - String checkResult = checkDescribeHis.getCheckResult(); - if (StringUtils.isNotBlank(checkResult)) { - String[] checkResultPictureIds = checkResult.split(","); - List checkDescribes = ocrCheckDescribeHisService.list(new LambdaQueryWrapper().in(OcrCheckDescribeHis::getPictureId, checkResultPictureIds)); - for (OcrCheckDescribeHis checkDescribe : checkDescribes) { - String[] split = checkDescribe.getCheckResult().split(","); - List list = Arrays.asList(split); - list.remove(id.toString()); - checkDescribe.setCheckResult(String.join(",", list)); - } - ocrCheckDescribeHisService.updateBatchById(checkDescribes); - } - ocrCheckDescribeHisService.remove(new LambdaQueryWrapper().eq(OcrCheckDescribeHis::getPictureId, id)); + public int savePictures(List ocrPictureList) { + //1.字典数据 解析入库 + boolean b = dataDictionaryUtil.pictureDataDictionarySaveArray(ocrPictureList); + + //2.调整图片地址,补齐域名 + for (OcrPicture picture : ocrPictureList) { + picture.setCreateTime(System.currentTimeMillis()); //获取创建时间戳 } - //图片对比记录 - OcrPictureDuplicateHis hisServiceOne = ocrPictureDuplicateHisService.getOne(new LambdaQueryWrapper().eq(OcrPictureDuplicateHis::getPictureId, id)); - if (null != hisServiceOne) { - String checkDuplicateResultHisJson = hisServiceOne.getCheckDuplicateResultHisJson(); - if (StringUtils.isNotBlank(checkDuplicateResultHisJson)) { - JSONObject jsonObject = JSON.parseObject(checkDuplicateResultHisJson); - Set keyList = jsonObject.keySet(); - List list = ocrPictureDuplicateHisService.list(new LambdaQueryWrapper().in(OcrPictureDuplicateHis::getPictureId, keyList)); - for (OcrPictureDuplicateHis ocrPictureDuplicateHis : list) { - String checkDuplicateResultHis = ocrPictureDuplicateHis.getCheckDuplicateResultHisJson(); - JSONObject json = JSON.parseObject(checkDuplicateResultHis); - json.remove(id.toString()); - ocrPictureDuplicateHis.setCheckDuplicateResultHisJson(JSON.toJSONString(json)); + + try { + boolean saveBatch = false; + synchronized (lock) { + // 同步的代码块 + saveBatch = this.saveOrUpdateBatch(ocrPictureList); + //通过与不通过的任务需要直接创建任务。 + for (OcrPicture picture : ocrPictureList) { + if ("8".equals(picture.getTaskstatus()) || "9".equals(picture.getTaskstatus()) || "10".equals(picture.getTaskstatus())) { + boolean taskSaveResult = ocrTaskchildPictureService.createTaskOldPicture(picture); + if (!taskSaveResult) { + log.error("旧数据创建任务失败,任务id:{}", picture.getTaskId()); + } + } } - ocrPictureDuplicateHisService.updateBatchById(list); + } - ocrPictureDuplicateHisService.remove(new LambdaQueryWrapper().eq(OcrPictureDuplicateHis::getPictureId, id)); + + //3.添加图片信息 + if (saveBatch) { +// this.savePicturesInfo(ocrPictureList); + this.convertImage(ocrPictureList); + return ocrPictureList.size(); + } + log.error("存储图片失败:{}", JSONObject.toJSON(ocrPictureList)); + } catch (Exception e) { + log.error("存储图片异常:{}", e.getMessage()); } - ocrCheckDuplicateResultService.remove(new LambdaQueryWrapper().eq(OcrCheckDuplicateResult::getPictureId, id)); + return 0; } - @Override - public OcrPicture selectByRemark(String remark) { - return pictureMybatisDao.selectByRemark(remark); + public Map getOcrPictureClassifyAndHash(String img) { + JSONObject jsonObjectSimi = ImageClassUtil.getClassify(img, "1", classifyPath); + //返回内容为零,表示成功,否则表示失败 + if (null != jsonObjectSimi && jsonObjectSimi.getString("code").equals("0") && jsonObjectSimi.get("data") != null && jsonObjectSimi.getJSONArray("data").size() > 0) { + JSONObject data = jsonObjectSimi.getJSONArray("data").getJSONObject(0); + Map map = new HashMap(); + map.put("classId", data.getString("classId")); + map.put("hash", data.getString("hash")); + return map; + } else { + return null; + } } + /** + * 新增图片信息表 + * + * @param ocrPicture + */ @Override - public OcrTaskchildPicture getOcrTaskChildPictureByPictureId(String pictureId) { - return ocrTaskchildPictureService.getOne(new LambdaQueryWrapper().eq(OcrTaskchildPicture::getPictureid, pictureId)); + public void savePicturesInfo(OcrPicture ocrPicture) { + boolean isConnection = true; + String url = ocrPicture.getImgurl(); + if (!StringUtils.isEmpty(ocrPicture.getLocalpictrueurl())) { + url = ocrPicture.getLocalpictrueurl(); + isConnection = false; + } + OcrPictureInfo imageInfo = getImageInfo(url, isConnection); + imageInfo.setPictureId(ocrPicture.getId()); + imageInfo.setImgName(ocrPicture.getImgname()); + ocrPictureInfoService.save(imageInfo); + } + + /** + * 获取图片信息 + * + * @param imageUrl 图片地址 两种 网络或者本地图片 + * @param isConnection 是否是url 开启网络请求 + * @return + */ + private OcrPictureInfo getImageInfo(String imageUrl, boolean isConnection) { + + try { + BufferedImage image = null; + Integer imageSize = 0; + if (isConnection) { + // 创建URL对象 + URL url = new URL(imageUrl); + // 打开连接 + URLConnection urlConnection = url.openConnection(); + // 获取图片大小 + imageSize = urlConnection.getContentLength(); + // 使用ImageIO读取图片 + image = ImageIO.read(url); + } else { + File file = new File(imageUrl); + image = ImageIO.read(file); + imageSize = (int) file.length(); + } + + if (image != null) { + OcrPictureInfo info = new OcrPictureInfo(); + // 获取图片宽度和高度 + int width = image.getWidth(); + int height = image.getHeight(); + + // 获取色彩空间类型 + ColorSpace colorSpace = image.getColorModel().getColorSpace(); + String colorSpaceType; + switch (colorSpace.getType()) { + case ColorSpace.TYPE_RGB: + colorSpaceType = "RGB"; + break; + case ColorSpace.TYPE_GRAY: + colorSpaceType = "Grayscale"; + break; + case ColorSpace.TYPE_CMYK: + colorSpaceType = "CMYK"; + break; + default: + colorSpaceType = "Other"; + break; + } + String formatName = ImageIO.getImageReadersByMIMEType("image/jpeg").next().getFormatName(); + info.setCreateTime(System.currentTimeMillis()); + info.setUploadTime(System.currentTimeMillis()); + info.setTagTime(System.currentTimeMillis()); + info.setImgSpace(colorSpaceType); + info.setImgSize(imageSize.toString()); + info.setImgMeasure(width + "x" + height); + info.setImgFormat(formatName); + info.setSource("无量云2.0"); + return info; + } else { + log.info("Cannot read image from URL."); + return null; + } + } catch (Exception e) { + log.error("Error: " + e.getMessage()); + } + return null; + } + + private void convertImage(List list) { + for (OcrPicture ocrPicture : list) { + FormRecord entity = new FormRecord(); + LivePhoto livePhoto = new LivePhoto(); + livePhoto.setImgNo(ocrPicture.getId()); + livePhoto.setImgUrl(ocrPicture.getImgurl()); + + String imgurl = ocrPicture.getImgurl(); + livePhoto.setLocalImgUrl(apiConfig.getLocalImagePath() + imgurl.substring(imgurl.lastIndexOf("/"))); + + entity.setLivePhoto(livePhoto); + boolean addedToQueue = false; + while (!addedToQueue) { + try { + addedToQueue = TaskQueue.pictureImgToLocalPushData(entity); + if (addedToQueue) { + break; + } + Thread.sleep(5000); + } catch (InterruptedException e) { + log.error("放入图片下载队列,等待休眠异常:{}", e.getMessage()); + } + } + } } } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrTaskchildPictureServiceImpl.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrTaskchildPictureServiceImpl.java index 09512a3..2fabe90 100644 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrTaskchildPictureServiceImpl.java +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/OcrTaskchildPictureServiceImpl.java @@ -3,6 +3,7 @@ package org.jeecg.module.custom.ocr.service.impl; import lombok.extern.slf4j.Slf4j; import org.jeecg.module.custom.ocr.base.BaseServiceImpl; import org.jeecg.module.custom.ocr.dataDao.OcrTaskchildPictureMybatisDao; +import org.jeecg.module.custom.ocr.dataobject.OcrPicture; import org.jeecg.module.custom.ocr.dataobject.OcrTaskchildPicture; import org.jeecg.module.custom.ocr.service.OcrTaskchildPictureService; import org.springframework.stereotype.Service; @@ -13,4 +14,42 @@ import org.springframework.stereotype.Service; @Service("ocrTaskchildPictureService") @Slf4j public class OcrTaskchildPictureServiceImpl extends BaseServiceImpl implements OcrTaskchildPictureService { + + @Override + public boolean createTaskOldPicture(OcrPicture picture) { + OcrTaskchildPicture taskchildPicture = new OcrTaskchildPicture(); + taskchildPicture.setTenantid(picture.getTenantId()); + taskchildPicture.setPictureid(picture.getId()); + taskchildPicture.setCategoryid(picture.getCategoryid()); + int states = 0; + if ("8".equals(picture.getTaskstatus())) { + states = 3; + } else if ("9".equals(picture.getTaskstatus()) || "10".equals(picture.getTaskstatus())) { + states = 5; + } else { + return false; + } + taskchildPicture.setStates(states); + taskchildPicture.setAssignee("admin"); + taskchildPicture.setAssigneename("全量拉取"); + taskchildPicture.setGuidang(1); + taskchildPicture.setCreateuser("admin"); + taskchildPicture.setCreatedate(System.currentTimeMillis()); + taskchildPicture.setFromtaskid(picture.getTaskId()); + taskchildPicture.setFromtaskname(picture.getTaskname()); + taskchildPicture.setFromuserid(picture.getUpuserid()); + taskchildPicture.setFromusername(picture.getUpname()); + taskchildPicture.setFromuptime(picture.getSubmitDateTimestamp()); + taskchildPicture.setFromplanid(picture.getPlanid()); + taskchildPicture.setFromprojectid(picture.getProjectid()); + taskchildPicture.setFromprojectname(picture.getProjectidname()); + taskchildPicture.setFromsourceid(picture.getField4()); + taskchildPicture.setFinishtime(System.currentTimeMillis()); + taskchildPicture.setIsFinal(1); + taskchildPicture.setTaskNode("finale_judgment"); + taskchildPicture.setIsRepeatedNodules(0); + taskchildPicture.setSendResult(0); + return this.save(taskchildPicture); + } + } diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/UserapproveServiceImpl.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/UserapproveServiceImpl.java deleted file mode 100644 index effa9f8..0000000 --- a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/service/impl/UserapproveServiceImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.jeecg.module.custom.ocr.service.impl; - - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import lombok.extern.slf4j.Slf4j; -import org.jeecg.module.custom.ocr.base.BaseServiceImpl; -import org.jeecg.module.custom.ocr.dataDao.UserapproveMybatisDao; -import org.jeecg.module.custom.ocr.dataobject.Userapprove; -import org.jeecg.module.custom.ocr.service.UserapproveService; -import org.springframework.stereotype.Service; - -/** - * 业务层实现 - */ -@Service -@Slf4j -public class UserapproveServiceImpl extends BaseServiceImpl implements UserapproveService { - @Override - public boolean delete(String formid) { - - QueryWrapper queryWrapper = new QueryWrapper(); - queryWrapper.eq("FORMID", formid); - - return this.remove(queryWrapper); - } -} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/DataDictionaryUtil.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/DataDictionaryUtil.java new file mode 100644 index 0000000..0be7da1 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/DataDictionaryUtil.java @@ -0,0 +1,258 @@ +package org.jeecg.module.custom.ocr.utils; + +import org.jeecg.module.custom.ocr.dataobject.OcrDictionary; +import org.jeecg.module.custom.ocr.dataobject.OcrDictionaryGroup; +import org.jeecg.module.custom.ocr.dataobject.OcrPicture; +import org.jeecg.module.custom.ocr.service.OcrDictionaryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 字典数据报错工具类 + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/3/16 11:18 + */ +@Component +public class DataDictionaryUtil { + + /** + * 任务计划 + */ + @Autowired + private OcrDictionaryService ocrDictionaryService; + + /** + * 图片数据,字典关联检查新增 集合排查 + * + * @param ocrPictureList + * @return + */ + public boolean pictureDataDictionarySaveArray(List ocrPictureList) { + for (OcrPicture picture : ocrPictureList) { + //1.检查提报人字典是否包含数据 + if (picture.getUpname() != null && picture.getUpuserid() != null) { + OcrDictionaryGroup upNameDG = ocrDictionaryService.queryGroupByField("person"); + if (upNameDG != null && ocrDictionaryService.isValueExists(upNameDG.getId(), picture.getUpname(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getUpname()); + dictionary.setValue(picture.getUpuserid()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(upNameDG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + + } + } + + + //2.任务计划 + if (picture.getPlanname() != null && picture.getPlanid() != null) { + OcrDictionaryGroup planNameDG = ocrDictionaryService.queryGroupByField("plan"); + if (planNameDG != null && ocrDictionaryService.isValueExists(planNameDG.getId(), picture.getPlanname(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getPlanname()); + dictionary.setValue(picture.getPlanid()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(planNameDG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + //3.拜访客户类型 + if (picture.getField2() != null) { + OcrDictionaryGroup field2DG = ocrDictionaryService.queryGroupByField("izcustomtype"); + if (field2DG != null && ocrDictionaryService.isValueExists(field2DG.getId(), picture.getField2(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getField2()); + dictionary.setValue(picture.getField2()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(field2DG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + + //4.拜访客户名称 + if (picture.getField3() != null) { + OcrDictionaryGroup field3DG = ocrDictionaryService.queryGroupByField("izcustomname"); + if (field3DG != null && ocrDictionaryService.isValueExists(field3DG.getId(), picture.getField3(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getField3()); + dictionary.setValue(picture.getField3()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(field3DG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + + //5.任务来源 + if (picture.getField4() != null) { + OcrDictionaryGroup field4DG = ocrDictionaryService.queryGroupByField("iztaskrrom"); + if (field4DG != null && ocrDictionaryService.isValueExists(field4DG.getId(), picture.getField4(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getField4()); + dictionary.setValue(picture.getField4()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(field4DG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + //6.厂商 + if (picture.getField5() != null) { + OcrDictionaryGroup field5DG = ocrDictionaryService.queryGroupByField("izfirm"); + if (field5DG != null && ocrDictionaryService.isValueExists(field5DG.getId(), picture.getField5(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getField5()); + dictionary.setValue(picture.getField5()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(field5DG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + //7.拜访客户级别 + if (picture.getField6() != null) { + OcrDictionaryGroup field6DG = ocrDictionaryService.queryGroupByField("izcustomlevel"); + if (field6DG != null && ocrDictionaryService.isValueExists(field6DG.getId(), picture.getField6(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getField6()); + dictionary.setValue(picture.getField6()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(field6DG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + //8.拜访项目类别 + if (picture.getField17() != null) { + OcrDictionaryGroup field17DG = ocrDictionaryService.queryGroupByField("izprojecttype"); + if (field17DG != null && ocrDictionaryService.isValueExists(field17DG.getId(), picture.getField17(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getField17()); + dictionary.setValue(picture.getField17()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(field17DG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + + //9.任务状态 + if (picture.getTaskstatus() != null) { + OcrDictionaryGroup taskStatusDG = ocrDictionaryService.queryGroupByField("iztaskstatus"); + if (taskStatusDG != null && ocrDictionaryService.isValueExists(taskStatusDG.getId(), picture.getTaskstatus(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getTaskstatus()); + dictionary.setValue(picture.getTaskstatus()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(taskStatusDG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + + //10.产品名称 + if (picture.getField9() != null) { + OcrDictionaryGroup field9DG = ocrDictionaryService.queryGroupByField("izproductname"); + if (field9DG != null && ocrDictionaryService.isValueExists(field9DG.getId(), picture.getField9(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getField9()); + dictionary.setValue(picture.getField9()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(field9DG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + + //11.地区(城市信息) + if (picture.getReleasearea() != null) { + OcrDictionaryGroup releaseAreaDG = ocrDictionaryService.queryGroupByField("izvisitcity"); + if (releaseAreaDG != null && ocrDictionaryService.isValueExists(releaseAreaDG.getId(), picture.getReleasearea(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getReleasearea()); + dictionary.setValue(picture.getReleasearea()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(releaseAreaDG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + + //12.地区(省信息) + if (picture.getReleaseprovince() != null) { + OcrDictionaryGroup releaseProvinceDG = ocrDictionaryService.queryGroupByField("izvisitpro"); + if (releaseProvinceDG != null && ocrDictionaryService.isValueExists(releaseProvinceDG.getId(), picture.getReleaseprovince(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getReleaseprovince()); + dictionary.setValue(picture.getReleaseprovince()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(releaseProvinceDG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + + //13.项目信息 + if (picture.getProjectidname() != null) { + OcrDictionaryGroup projectNameDG = ocrDictionaryService.queryGroupByField("project"); + if (projectNameDG != null && ocrDictionaryService.isValueExists(projectNameDG.getId(), picture.getProjectidname(), picture.getTenantId())) { + OcrDictionary dictionary = new OcrDictionary(); + dictionary.setLable(picture.getProjectidname()); + dictionary.setValue(picture.getProjectidname()); + dictionary.setTenantId(picture.getTenantId()); + dictionary.setGroupId(projectNameDG.getId()); + try { + ocrDictionaryService.save(dictionary); + } catch (Exception e) { + + } + } + } + + } + return true; + } +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/DownloadImgUtil.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/DownloadImgUtil.java new file mode 100644 index 0000000..1053710 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/DownloadImgUtil.java @@ -0,0 +1,59 @@ +package org.jeecg.module.custom.ocr.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.net.URL; + +/** + * 转储图片工具类 + * + * @author hugh(shuli.yao) 1397940314@qq.com + * @version 1.0 + * @date 2024/3/16 18:37 + */ +public class DownloadImgUtil { + private static Logger logger = LoggerFactory.getLogger(DownloadImgUtil.class); + + /** + * 下载网络图片缓存到本地服务器 + * + * @param imageUrl + * @param destinationFile + */ + public static Boolean downloadImage(String imageUrl, String destinationFile) { + //检查路径是否存在,不存在测进行新建 + if(destinationFile.lastIndexOf(File.separator)!=-1){ + String directoryUrl = destinationFile.substring(0,destinationFile.lastIndexOf(File.separator)); + File file = new File(directoryUrl); + if(!file.isDirectory()){ + file.mkdirs(); + } + } + + try (InputStream in = new URL(imageUrl).openStream(); + FileOutputStream out = new FileOutputStream(destinationFile)) { + + byte[] buffer = new byte[4096]; + int n; + while ((n = in.read(buffer)) != -1) { + out.write(buffer, 0, n); + } + out.flush(); + } catch (Exception e) { + logger.error("转储异常问题msg:{}",e.getMessage()); + logger.error("转储异常问题json:{}",e.getStackTrace()); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + String exceptionDetails = sw.toString();// 包含堆栈跟踪信息的字符串 + logger.error("图片本地化,转储图片异常:{}",exceptionDetails); + + return false; + } + return true; + } + + +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ImageClassUtil.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ImageClassUtil.java new file mode 100644 index 0000000..543072e --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ImageClassUtil.java @@ -0,0 +1,65 @@ +package org.jeecg.module.custom.ocr.utils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.jeecg.module.custom.ocr.utils.httputil.HttpClient; +import org.jeecg.module.custom.ocr.utils.httputil.HttpHeader; +import org.jeecg.module.custom.ocr.utils.httputil.HttpParamers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ImageClassUtil { + private static Logger logger = LoggerFactory.getLogger(ImageClassUtil.class); + + /** + * 类型检查 + * 接口文档 + * https://console-docs.apipost.cn/preview/7add2088a9a191d5/874020cbfba4287b + * @param imgurl + * @param taskId + * @return { + * "code": 0, + * "data": [ + * { + * "imgs": "/server/data/images/1754716707781476352.jpg", + * "classId": 704, + * "scores": 0.11721831560134888, + * "hash": "0000000000000000110001101111111111100110111011101111110011110000" + * } + * ], + * "taskId": "1" + * } + */ + public static JSONObject getClassify(String imgurl,String taskId,String serverurl){ + if(StringUtils.isBlank(serverurl)){ + serverurl = "http://47.93.59.251/ai/api/classify/"; + } + + //类型检查 + JSONObject jsonObjectVi = new JSONObject(); + jsonObjectVi.put("taskId",taskId); + JSONArray jsonArrayVi = new JSONArray(); + jsonArrayVi.add(imgurl); + jsonObjectVi.put("imgUrls",jsonArrayVi); + + HttpParamers paramersVi = HttpParamers.httpPostParamers(); + paramersVi.setJsonParamer(jsonObjectVi.toJSONString()); + HttpHeader headerVi = null; + String responseDataVi = ""; + try { + responseDataVi = HttpClient.doService(serverurl, paramersVi, headerVi, 15000, 30000); + JSONObject jsonObjectSimi = JSON.parseObject(responseDataVi); + if (null != jsonObjectSimi && jsonObjectSimi.getString("code").equals("0") && jsonObjectSimi.get("data") != null && jsonObjectSimi.getJSONArray("data").size() > 0) { + } else { + } + } catch (Exception e) { + logger.error("classify={}", e); + } + + JSONObject jsonObject = JSON.parseObject(responseDataVi); + return jsonObject; + } + +} diff --git a/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ImageUtils.java b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ImageUtils.java new file mode 100644 index 0000000..43cb082 --- /dev/null +++ b/jeecg-module-custom/src/main/java/org/jeecg/module/custom/ocr/utils/ImageUtils.java @@ -0,0 +1,55 @@ +package org.jeecg.module.custom.ocr.utils; + +import net.coobird.thumbnailator.Thumbnails; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/** + * @Title: + * @Description: 图片设置 + * @Author 郭向斌 + * @Date 2024-03-18 15:29 + * @Version V1.0 + */ +public class ImageUtils { + public static String generateThumbnail(String inputImagePath, Integer newWidth) throws IOException { + if(newWidth==null){ + newWidth=182; + } + String directoryPath = inputImagePath.substring(0, inputImagePath.lastIndexOf("/") + 1); + File inputFile = new File(inputImagePath); + String outputImagePath = directoryPath+ "thumbnail_" + inputFile.getName(); + BufferedImage bufferedImage = Thumbnails.of(inputFile).scale(1).asBufferedImage(); + int width = bufferedImage.getWidth(); + int height = bufferedImage.getHeight(); + int newHeight = (int) Math.round((double) height * newWidth / width); + + Thumbnails.of(inputFile).size(newWidth, newHeight).outputFormat( getFileExtension(inputFile.getName())).toFile(new File(outputImagePath)); + return outputImagePath; + } + + + public static String getFileExtension(String fileName) { + if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) { + return fileName.substring(fileName.lastIndexOf(".") + 1); + } else { + return "jpg"; // 没有后缀名或者文件名以点号开头 + } + } + + public static void main(String[] args) throws IOException { + String url="C:\\Users\\郭向斌\\Downloads\\1-星浩.png"; + String s = generateThumbnail(url,180); + System.out.println(s); + String st="http://47.93.59.251/api/image/"; + String s1 = ImageUtils.generateThumbnail(url, 182); + String stri=st+getFileName(s1); + System.out.println(stri); + } + public static String getFileName(String filePath) { + File file = new File(filePath); + return file.getName(); + } +}