feat: 完整全量拉取和字段配置同步接口

feature/task-zhanglin
Vincent 1 month ago
parent bd9f88d48a
commit 260061ef31

@ -29,6 +29,12 @@
<artifactId>alanpoi-common</artifactId>
<version>1.3.4</version>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.14</version> <!-- 或者最新版本 -->
</dependency>
</dependencies>
</project>

@ -1,4 +0,0 @@
package org.jeecg.module.custom.ocr;
public class OcrApplication {
}

@ -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<PictureSourceResult> pullPictureSourceAll(PictureSourceParameter pictureSourceParameter) throws Exception;
ApiPage<FormRecord> pullPictureSourceAll(PictureSourceParameter pictureSourceParameter) throws Exception;
}

@ -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<T> {
/**
*
*/
@ -27,5 +29,5 @@ public class BaseResult {
/**
*
*/
String data;
T data;
}

@ -6,7 +6,7 @@ import java.util.List;
import java.util.Map;
@Data
public class FormConfigResult extends BaseResult{
public class FormConfigResult {
/**
* no
*/

@ -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<String, Object> dynamicFields;
@JsonAnySetter
public void setDynamicField(String key, Object value) {
if (dynamicFields == null) {
dynamicFields = new HashMap<>();
}
dynamicFields.put(key, value);
}
}

@ -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;
}

@ -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<String,Object> province;
/**
* 访
*/
Map<String,Object> city;
/**
* 访
*/
Map<String,Object> terminalType;
/**
* 访
*/
Map<String,Object> terminalLevel;
/**
* 访
*/
Map<String,Object> customerName;
/**
* 访
*/
Map<String,Object> projectType;
/**
*
*/
List<Map<String,Object>> productCard;
/**
* 访
*/
Map<String,Object> productName;
/**
* 访
*/
String companyDepartment;
/**
*
*/
Object manufacturer;
/**
* 访
*/
String discoveredIssues;
/**
* /
*/
String feedback;
/**
*
*/
Map<String,Object> location;
/**
*
*/
String distance;
/**
* 访
*/
String visitDate;
/**
*
*/
List<Map<String,Object>> livePhoto;
/**
*
*/
Map<String,Object> 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<String,Object> province;
//
// /**
// * 拜访城市
// */
// Map<String,Object> city;
//
// /**
// * 拜访客户类型
// */
// Map<String,Object> terminalType;
//
// /**
// * 拜访客户级别
// */
// Map<String,Object> terminalLevel;
//
// /**
// * 拜访客户名称
// */
// Map<String,Object> customerName;
//
// /**
// * 拜访项目
// */
// Map<String,Object> projectType;
//
// /**
// * 品牌卡片
// */
// List<Map<String,Object>> productCard;
//
// /**
// * 拜访品种
// */
// Map<String,Object> productName;
//
// /**
// * 拜访部门
// */
// String companyDepartment;
// /**
// * 厂商
// */
// Object manufacturer;
//
// /**
// * 拜访小节
// */
// String discoveredIssues;
//
// /**
// * 客户反馈/评价
// */
// String feedback;
//
// /**
// * 定位
// */
// Map<String,Object> location;
//
// /**
// * 定位距离
// */
// String distance;
//
// /**
// * 拜访日期
// */
// String visitDate;
//
// /**
// * 图片列表(拍照打卡(图片))
// */
// List<Map<String,Object>> livePhoto;
//
//
// /**
// * 扩展字段
// */
// Map<String,Object> extendedField;
//
// /**
// * 任务提交时间(提报日期时间戳)
// */
// Long submitTime;
//
// /**
// * 请求参数 存log用
// */
// PictureSourceParameter requestParam;
//
// /**
// * 备注
// */
// String comment;
//}

@ -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<PictureSourceResult> pullPictureSourceAll(PictureSourceParameter pictureSourceParameter) throws Exception {
public ApiPage<FormRecord> 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<PictureSourceResult> resultApiPage = null;
ApiPage<FormRecord> 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<PictureSourceResult> listResult = JSONUtil.toList(JSONObject.toJSONString(apiPage.getRecords()), PictureSourceResult.class);
List<FormRecord> listResult = JSONUtil.toList(JSONObject.toJSONString(apiPage.getRecords()), FormRecord.class);
resultApiPage = new ApiPage<>();
resultApiPage.setPageNo(apiPage.getPageNo());
resultApiPage.setPageSize(apiPage.getPageSize());

@ -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<PictureSourceResult> apiPage = prevailCloudApi.pullPictureSourceAll(pictureSourceParameter);
ApiPage<FormRecord> 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<Map<String, Object>> livePhoto = new ArrayList<>();
Map<String, Object> 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++;

@ -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<String> 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();
}
}

@ -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();
}
}

@ -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();
}
}

@ -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<OcrPicture> 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);
}
}

@ -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<String, String> 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);
}
}
}

@ -71,6 +71,11 @@ public class ApiConfig {
*/
private String tenantSourceUrl = "/pangu/jingwei/ocr/query/pb/tenant/info";
/**
*
*/
private String formConfigUrl = "";
/**
*
* @return

@ -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<FormConfigResult> sync(@RequestBody FormSyncRequest request) {
return formConfigService.sync(request);
}
}

@ -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;
}

@ -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;
}

@ -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;
}

@ -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<OcrDictionary> {
}

@ -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<OcrDictionaryGroup> {
}

@ -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<String,String> 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;
}

@ -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<OcrDictionary> distionaryList;
//保存当前登录用户的数据权限范围的搜索条件
@TableField(exist = false)
@JsonIgnore
private SearchQuery searchQueryrolesShowleave;
@TableField(exist = false)
@JsonIgnore
private final Map<String,String> 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;
}
}

@ -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;

@ -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<FormConfig> {
BaseResult<FormConfigResult> sync(FormSyncRequest request);
}

@ -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;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-03-24
*/
public interface IOcrCheckDuplicateResultService extends IService<OcrCheckDuplicateResult> {
}

@ -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;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-03-24
*/
public interface IOcrPictureDuplicateHisService extends IService<OcrPictureDuplicateHis> {
}

@ -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<OcrCheckDescribeHis>{
}

@ -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<OcrDictionary> {
/**
*
* @param groupId
* @param value
* @param tenantId
* @return
*/
boolean isValueExists(Long groupId, String value, Long tenantId);
/**
*
* @param field
* @return
*/
OcrDictionaryGroup queryGroupByField(String field);
}

@ -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<OcrPicture> {
String getPictureApproveResult(Long id);
void deletePictureInfo(Long id);
/**
* id
*
*
* @param remark
* @param ocrPictureList
* @return
*/
OcrPicture selectByRemark(String remark);
int savePictures(List<OcrPicture> ocrPictureList);
Map<String, String> getOcrPictureClassifyAndHash(String img);
OcrTaskchildPicture getOcrTaskChildPictureByPictureId(String pictureId);
void savePicturesInfo(OcrPicture ocrPicture);
}

@ -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<OcrTaskchildPicture> {
/**
* picture
* @param picture
* @return
*/
boolean createTaskOldPicture(OcrPicture picture);
}

@ -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<Userapprove> {
/**
*
* @param formid
* @return truefalse
*/
public boolean delete(String formid);
}

@ -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<FormConfigMapper, FormConfig> implements FormConfigService {
/**
* api
*/
@Autowired
private ApiConfig apiConfig;
@Transactional(rollbackFor = Exception.class)
@SneakyThrows
@Override
public BaseResult<FormConfigResult> sync(FormSyncRequest request) {
//2.对象转map
Map<String, Object> 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<String> resultData = JSONUtil.toBean(responseJsonStr, ResultData.class);
//定义返回对象
FormConfigResult formConfigResult = null;
BaseResult<FormConfigResult> 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;
}
}

@ -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<OcrCheckDescribeHisMapper, OcrCheckDescribeHis> implements OcrCheckDescribeHisService {
}

@ -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<OcrDictionaryDao, OcrDictionary> 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<OcrDictionaryGroup> ocrDictionaryGroupList = ocrDictionaryGroupDao.selectList(queryWrapper);
if(ocrDictionaryGroupList!=null && ocrDictionaryGroupList.size()>0){
return ocrDictionaryGroupList.get(0);
}
return 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;
/**
* <p>
*
* </p>
*
* @author author
* @since 2024-03-24
*/
@Service
public class OcrPictureDuplicateHisServiceImpl extends ServiceImpl<OcrPictureDuplicateHisMapper, OcrPictureDuplicateHis> implements IOcrPictureDuplicateHisService {
}

@ -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<OcrPictureMybatisDao, OcrPicture> 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<OcrPictureInfo>().eq(OcrPictureInfo::getPictureId, id));
OcrTaskchildPicture taskchildPicture = ocrTaskchildPictureService.getOne(new LambdaQueryWrapper<OcrTaskchildPicture>().eq(OcrTaskchildPicture::getPictureid, id));
//删除任务表
ocrTaskchildPictureService.remove(new LambdaQueryWrapper<OcrTaskchildPicture>().eq(OcrTaskchildPicture::getPictureid, id));
//删除审批记录表
userapproveService.delete(taskchildPicture.getId().toString());
//小结查重记录
OcrCheckDescribeHis checkDescribeHis = ocrCheckDescribeHisService.getOne(new LambdaQueryWrapper<OcrCheckDescribeHis>().eq(OcrCheckDescribeHis::getPictureId, id));
if (checkDescribeHis != null) {
String checkResult = checkDescribeHis.getCheckResult();
if (StringUtils.isNotBlank(checkResult)) {
String[] checkResultPictureIds = checkResult.split(",");
List<OcrCheckDescribeHis> checkDescribes = ocrCheckDescribeHisService.list(new LambdaQueryWrapper<OcrCheckDescribeHis>().in(OcrCheckDescribeHis::getPictureId, checkResultPictureIds));
for (OcrCheckDescribeHis checkDescribe : checkDescribes) {
String[] split = checkDescribe.getCheckResult().split(",");
List<String> list = Arrays.asList(split);
list.remove(id.toString());
checkDescribe.setCheckResult(String.join(",", list));
}
ocrCheckDescribeHisService.updateBatchById(checkDescribes);
}
ocrCheckDescribeHisService.remove(new LambdaQueryWrapper<OcrCheckDescribeHis>().eq(OcrCheckDescribeHis::getPictureId, id));
public int savePictures(List<OcrPicture> ocrPictureList) {
//1.字典数据 解析入库
boolean b = dataDictionaryUtil.pictureDataDictionarySaveArray(ocrPictureList);
//2.调整图片地址,补齐域名
for (OcrPicture picture : ocrPictureList) {
picture.setCreateTime(System.currentTimeMillis()); //获取创建时间戳
}
//图片对比记录
OcrPictureDuplicateHis hisServiceOne = ocrPictureDuplicateHisService.getOne(new LambdaQueryWrapper<OcrPictureDuplicateHis>().eq(OcrPictureDuplicateHis::getPictureId, id));
if (null != hisServiceOne) {
String checkDuplicateResultHisJson = hisServiceOne.getCheckDuplicateResultHisJson();
if (StringUtils.isNotBlank(checkDuplicateResultHisJson)) {
JSONObject jsonObject = JSON.parseObject(checkDuplicateResultHisJson);
Set<String> keyList = jsonObject.keySet();
List<OcrPictureDuplicateHis> list = ocrPictureDuplicateHisService.list(new LambdaQueryWrapper<OcrPictureDuplicateHis>().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<OcrPictureDuplicateHis>().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<OcrCheckDuplicateResult>().eq(OcrCheckDuplicateResult::getPictureId, id));
return 0;
}
@Override
public OcrPicture selectByRemark(String remark) {
return pictureMybatisDao.selectByRemark(remark);
public Map<String, String> 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<String, String> 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<OcrTaskchildPicture>().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<OcrPicture> 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());
}
}
}
}
}

@ -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<OcrTaskchildPictureMybatisDao, OcrTaskchildPicture> 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);
}
}

@ -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<UserapproveMybatisDao, Userapprove> implements UserapproveService {
@Override
public boolean delete(String formid) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("FORMID", formid);
return this.remove(queryWrapper);
}
}

@ -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<OcrPicture> 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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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();
}
}
Loading…
Cancel
Save