parent
bd9f88d48a
commit
260061ef31
@ -1,4 +0,0 @@
|
|||||||
package org.jeecg.module.custom.ocr;
|
|
||||||
|
|
||||||
public class OcrApplication {
|
|
||||||
}
|
|
@ -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;
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,11 @@
|
|||||||
package org.jeecg.module.custom.ocr.service;
|
package org.jeecg.module.custom.ocr.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
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;
|
import org.jeecg.module.custom.ocr.dataobject.FormConfig;
|
||||||
|
|
||||||
public interface FormConfigService extends IService<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> {
|
|
||||||
}
|
|
@ -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);
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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,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,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…
Reference in new issue