Merge branch 'dev'

# Conflicts:
#	jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/controller/OcrPictureController.java
#	runstart/src/main/resources/application-dev.yml
pull/1/head
sunchenliang 1 year ago
commit 6b10a0ac43

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import cn.jyjz.xiaoyao.admin.service.LogService;
import cn.jyjz.xiaoyao.common.base.util.RequestBaseUtil;
import cn.jyjz.xiaoyao.common.base.vo.UserToken;
@ -57,6 +58,7 @@ public class OcrPictureController extends BaseController{
private UserService userService;
@Resource
private LogService logService;
/**
*
*
@ -73,10 +75,11 @@ public class OcrPictureController extends BaseController{
/**
* @MM1vvPNHRprA7ScHnwE+WG6yz7hcA/u3tzMj6pSdvwc=
*@MM1vvPNHRprA7ScHnwE+WG6yz7hcA/u3tzMj6pSdvwc=
*
* @param ocrPicture
* @param req
* @return
* @MM1vvPNHRprA7ScHnwE+WG6yz7hcA/u3tzMj6pSdvwc=
*/
//@AutoLog(value = "ocr_picture-分页列表查询")
@ApiOperation(value = "任务查询", notes = "任务查询")
@ -169,14 +172,12 @@ public class OcrPictureController extends BaseController{
queryWrapper = SearchParaFormatting.searchParaParse(queryWrapper, paraMap);
queryWrapper.eq("tenant_id", tenantId);
List<OcrPicture> pageList = ocrPictureService.listPage(queryWrapper);
if (null != pageList && !pageList.isEmpty()) {
if (pageList.size() == 1) {
return ResultVoUtil.error("查重数据至少要有两条。");
} else {
return ocrPictureService.createTaskChild(pageList,tenantId,userToken,search_month, req,buessinessno);
return ocrPictureService.createPackageTask(pageList, tenantId, userToken, search_month, req, buessinessno);
}
} else {
return ResultVoUtil.error("没有查重数据。");

@ -26,7 +26,6 @@ import java.util.stream.Stream;
import java.util.stream.Collectors;
@Data
@Builder
@NoArgsConstructor
@ -294,6 +293,14 @@ public class OcrPicture implements BaseDto,java.io.Serializable {
@TableField(value = "field18")
private String field18;
@Schema(description = "本地图片地址")
@TableField(value = "local_pictrue_url")
private String localpictrueurl;
@Schema(description = "是否已下载到本地")
@TableField(value = "is_download")
private Integer isdownload;
@ApiModelProperty(value = "图片查重的比对图片集合")
@TableField(exist = false)
private List<OcrPicture> listCom;
@ -384,9 +391,11 @@ public class OcrPicture implements BaseDto,java.io.Serializable {
new SimpleEntry<>("field15", "field15"),
new SimpleEntry<>("field16", "field16"),
new SimpleEntry<>("field17", "field17"),
new SimpleEntry<>("field18","field18")
new SimpleEntry<>("field18", "field18"),
new SimpleEntry<>("localpictrueurl", "localpictrueurl")
)
.collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue));
@Override
public String getQueryFiled(String filedname) {
String obj = null;

@ -96,4 +96,6 @@ public interface OcrPictureService extends BaseService<OcrPicture> {
* @return
*/
int savePictures(List<OcrPicture> ocrPictureList);
ResultVo createPackageTask(List<OcrPicture> pageList, String tenantId, UserToken userToken, String searchMonth, HttpServletRequest req, String buessinessno);
}

@ -13,12 +13,15 @@ import cn.jyjz.xiaoyao.oa.from.service.CategoryService;
import cn.jyjz.xiaoyao.ocr.dataDao.OcrPictureMybatisDao;
import cn.jyjz.xiaoyao.ocr.dataobject.*;
import cn.jyjz.xiaoyao.ocr.service.*;
import cn.jyjz.xiaoyao.ocr.thread.TaskQueue;
import cn.jyjz.xiaoyao.ocr.thread.entity.PictureImgToLocalEntity;
import cn.jyjz.xiaoyao.ocr.util.DataDictionaryUtil;
import cn.jyjz.xiaoyao.ocr.util.ImageClassUtil;
import cn.jyjz.xiaoyao.ocr.util.SearchEnum;
import cn.jyjz.xiaoyao.ocr.util.SearchParaFormatting;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -48,6 +51,9 @@ import java.util.List;
@Service("ocrPictureService")
@Slf4j
public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao, OcrPicture> implements OcrPictureService {
@Value("${ocr.api.wly.localImagePath}")
private String localImagePath;
@Resource
private OcrPictureMybatisDao ocrpicturemybatisdao;
@ -273,79 +279,175 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
}
return ResultVoUtil.error("失败。");
}
public ResultVo createTaskChild(List<OcrPicture> ocrPictureList, String tenantId) {
public ResultVo createPackageTask(List<OcrPicture> ocrPictureList, String tenantId, UserToken sysUser, String search_month, HttpServletRequest request, String buessinessno) {
//图片错误信息
StringBuffer error = new StringBuffer();
//项目错误信息
StringBuffer errorProject = new StringBuffer();
//流程错误信息
StringBuffer errorFlow = new StringBuffer();
//记录任务相似度为百分百的任务主键
List<Long> pointsList = new ArrayList<>();
//图片信息不能为空
if (null != ocrPictureList && !ocrPictureList.isEmpty()) {
//生成任务包
//String packageName = seqManageService.getSeqNextNo("AI任务包");
//创建任务包
OcrPackagetask ocrPackagetask = this.ocrPackagetaskService.create(buessinessno, tenantId, sysUser);
if (null == ocrPackagetask) {
return ResultVoUtil.error("失败。");
}
//用于标记相似度是否存在百分百的情况
List<OcrPicture> newList = new ArrayList<>();
for (OcrPicture ocrPicture : ocrPictureList) {
//如果当前图片已经生成任务包,直接跳过
if (ocrPicture.getTaskstatus().equals("1")) {
continue;
}
//图片查重的比对图片集合
List<OcrPicture> compareList = new ArrayList<>();
//非历史图片主键集合
List<String> picturecompareList = new ArrayList<>();
boolean havePoint = false;
//二次遍历进行比对
for (OcrPicture ocrPictureNext : ocrPictureList) {
if (ocrPictureNext.getId().longValue() == ocrPicture.getId().longValue()) {
continue;
}
//TODO 接口请求判断重复情况
JSONObject jsonObjectSimi = ImageClassUtil.getSimilarity(ocrPicture.getImgurl(),
ocrPictureNext.getImgurl(),
logService.addLog(103, "AI获取图片相似度接口", sysUser, "sendParams");
JSONObject jsonObjectSimi = ImageClassUtil.getSimilarity(StringUtils.isBlank(ocrPicture.getLocalpictrueurl()) ? ocrPicture.getImgurl() : ocrPicture.getLocalpictrueurl(),
StringUtils.isBlank(ocrPicture.getLocalpictrueurl()) ? ocrPictureNext.getImgurl() : ocrPicture.getLocalpictrueurl(),
null);
System.out.println("responseDataXs--code = [" + jsonObjectSimi.get("code") + "]");
System.out.println("responseDataXs--similarity = [" + jsonObjectSimi.get("similarity") + "]");
String resultValue = "";
//返回内容为零,表示成功,否则表示失败
if (null != jsonObjectSimi && jsonObjectSimi.getString("code").equals("0")) {
resultValue = jsonObjectSimi.getString("similarity");
ocrPictureNext.setResult(resultValue);
} else {
resultValue = "0";
ocrPictureNext.setResult(resultValue);
}
BigDecimal b1 = new BigDecimal(resultValue);
BigDecimal b2 = new BigDecimal("100");
int val = b1.compareTo(b2);
if (val == 0) {
havePoint = true;
}
//如果当前图片未生成任务需要临时保存
if (ocrPictureNext.getTaskstatus().equals("0")) {
picturecompareList.add(ocrPictureNext.getId().toString());
}
compareList.add(ocrPictureNext);
}
bubbleSortOpt(compareList);
//从大到小进行排序
ocrPicture.setListCom(compareList);
//非历史图片主键集合
ocrPicture.setPicturecompareList(picturecompareList);
//查询项目对象
if (null == ocrPicture.getCategoryid()) {
//TODO 没有对应项目,返回提示信息
if (null != error && error.length() > 1) {
error.append("," + ocrPicture.getImgname());
} else {
error.append(ocrPicture.getImgname());
}
continue;
}
Category category = categoryService.getById(ocrPicture.getCategoryid());
if (null == category) {
if (null != errorProject && errorProject.length() > 1) {
errorProject.append("," + ocrPicture.getImgname());
} else {
errorProject.append(ocrPicture.getImgname());
}
continue;
} else if (StringUtils.isBlank(category.getProcessdefinitionid())) {
if (null != errorFlow && errorFlow.length() > 1) {
errorFlow.append("," + category.getCategoryname());
} else {
errorFlow.append(category.getCategoryname());
}
continue;
}
//创建工单,如果创建成功,增加标志,用于过滤条件使用
OcrTaskchildPicture ocrTaskchildPicture = this.updateTaskChild(ocrPicture, ocrPackagetask.getId(), buessinessno);
if (null != ocrTaskchildPicture) {
if (havePoint) {
pointsList.add(ocrTaskchildPicture.getId());
}
}
newList.add(ocrPicture);
}
//批量更新 pointsList 主键相似度为百分百的数据
if (null != pointsList && !pointsList.isEmpty()) {
this.ocrTaskchildPictureService.markPoint(pointsList);
}
if (StringUtils.isNotBlank(search_month)) {
if (StringUtils.isNotBlank(search_month) && Integer.parseInt(search_month) <= 12 && Integer.parseInt(search_month) > 0) {
ocrPackagetask.setSearchtimes(SearchEnum.getName(Integer.parseInt(search_month)));
} else if (StringUtils.isNotBlank(search_month) && Integer.parseInt(search_month) > 20) {
ocrPackagetask.setSearchtimes(SearchEnum.getName((Integer.parseInt(search_month) - 20)));
}
}
ocrPackagetask.setPictureno(ocrPictureList.size());
this.ocrPackagetaskService.updateById(ocrPackagetask);
//原主图设置为任务包已经生成
for (OcrPicture ocrPicture : newList) {
ocrPicture.setTaskstatus("1");
this.updateById(ocrPicture);
}
if (StringUtils.isBlank(error) && StringUtils.isBlank(errorProject) && StringUtils.isBlank(errorFlow)) {
return ResultVoUtil.success();
} else {
String msg = (StringUtils.isBlank(error)) ? "" : error.toString() + ",图片没有对应项目,无法查重。";
msg = msg + ((StringUtils.isBlank(errorProject)) ? "" : errorProject.toString() + ",图片没有对应项目,无法查重。");
msg = msg + ((StringUtils.isBlank(errorFlow)) ? "" : errorFlow.toString() + ",项目没有配置审批流程,无法查重。");
return ResultVoUtil.success(msg);
}
}
return ResultVoUtil.error("失败。");
}
public OcrTaskchildPicture updateTaskChild(OcrPicture ocrPicture, Long packageid, String buessinessno) {
OcrTaskchildPicture ocrTaskchildPicture = ocrTaskchildPictureService.getOne(new LambdaQueryWrapper<OcrTaskchildPicture>().eq(OcrTaskchildPicture::getPictureid, ocrPicture.getId()));
ocrTaskchildPicture.setBuessinessno(buessinessno);
ocrTaskchildPicture.setPackageid(packageid);
StringBuffer pcid = new StringBuffer();
StringBuffer result = new StringBuffer();
for (OcrPicture comp : ocrPicture.getListCom()) {
if (null == pcid || pcid.toString().length() < 1) {
pcid.append(comp.getId());
result.append(comp.getResult());
} else {
pcid.append("," + comp.getId());
result.append("," + comp.getResult());
}
}
ocrTaskchildPicture.setOcpictureid(pcid.toString());
ocrTaskchildPicture.setPictureresult(result.toString());
ocrTaskchildPicture.setPicturecompare(String.join(",", ocrPicture.getPicturecompareList()));
return ocrTaskchildPictureService.updateById(ocrTaskchildPicture) ? ocrTaskchildPicture : null;
}
public ResultVo createTaskChild(List<OcrPicture> ocrPictureList, String tenantId) {
//图片错误信息
StringBuffer error = new StringBuffer();
//项目错误信息
StringBuffer errorProject = new StringBuffer();
//流程错误信息
StringBuffer errorFlow = new StringBuffer();
//图片信息不能为空
if (null != ocrPictureList && !ocrPictureList.isEmpty()) {
//用于标记相似度是否存在百分百的情况
List<OcrPicture> newList = new ArrayList<>();
for (OcrPicture ocrPicture : ocrPictureList) {
boolean havePoint = false;
//查询项目对象
if (null == ocrPicture.getCategoryid()) {
//TODO 没有对应项目,返回提示信息
@ -388,41 +490,19 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
ocrTaskchildPicture.getId().toString(),
category.getServicename()
);
if (havePoint) {
pointsList.add(ocrTaskchildPicture.getId());
}
//TODO 需要测试
ocrPicture.setTaskchildpictureid(ocrTaskchildPicture.getId().toString());
ocrPicture.setWorkStatus("1");
this.updateById(ocrPicture);
}
newList.add(ocrPicture);
}
//批量更新 pointsList 主键相似度为百分百的数据
if (null != pointsList && !pointsList.isEmpty()) {
this.ocrTaskchildPictureService.markPoint(pointsList);
}
//原主图设置为任务包已经生成
for (OcrPicture ocrPicture : newList) {
ocrPicture.setTaskstatus("1");
this.updateById(ocrPicture);
}
if (StringUtils.isBlank(error) && StringUtils.isBlank(errorProject) && StringUtils.isBlank(errorFlow)) {
return ResultVoUtil.success();
} else {
String msg = (StringUtils.isBlank(error)) ? "" : error.toString() + ",图片没有对应项目,无法查重。";
msg = msg + ((StringUtils.isBlank(errorProject)) ? "" : errorProject.toString() + ",图片没有对应项目,无法查重。");
msg = msg + ((StringUtils.isBlank(errorFlow)) ? "" : errorFlow.toString() + ",项目没有配置审批流程,无法查重。");
return ResultVoUtil.success(msg);
}
}
return ResultVoUtil.error("失败。");
}
@ -675,7 +755,6 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
}
@Override
@Transactional(rollbackFor = Exception.class)
public int savePictures(List<OcrPicture> ocrPictureList) {
//1.字典数据 解析入库
boolean b = dataDictionaryUtil.pictureDataDictionarySaveArray(ocrPictureList);
@ -687,18 +766,27 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
picture.setImgurl(interfaceDomain + picture.getImgurl());
}
boolean saveBatch = this.saveBatch(ocrPictureList);
//3.添加图片信息
if (this.saveBatch(ocrPictureList)) {
if (saveBatch) {
this.convertImage(ocrPictureList);
this.createTaskChild(ocrPictureList, ocrPictureList.get(0).getTenantId().toString());
return ocrPictureList.size();
}
return 0;
}
private void convertImage(List<OcrPicture> list) {
for (OcrPicture ocrPicture : list) {
PictureImgToLocalEntity entity = new PictureImgToLocalEntity();
entity.setPictureId(ocrPicture.getId());
entity.setImgUrl(ocrPicture.getImgurl());
String imgurl = ocrPicture.getImgurl();
entity.setLocalPath(localImagePath + imgurl.substring(imgurl.lastIndexOf("/")));
TaskQueue.pictureImgToLocalPushData(entity);
}
}
/**
*
*

@ -455,21 +455,21 @@ public class OcrTaskchildPictureServiceImpl extends BaseServiceImpl<OcrTaskchild
ocrTaskchildPicture.setFromprojectid(ocrPicture.getProjectid());
ocrTaskchildPicture.setFromuserid(ocrPicture.getUpuserid());
StringBuffer pcid = new StringBuffer();
StringBuffer result = new StringBuffer();
for(OcrPicture comp:ocrPicture.getListCom()){
if(null == pcid || pcid.toString().length() < 1){
pcid.append(comp.getId());
result.append(comp.getResult());
}else{
pcid.append("," + comp.getId());
result.append("," + comp.getResult());
}
}
ocrTaskchildPicture.setOcpictureid(pcid.toString());
ocrTaskchildPicture.setPictureresult(result.toString());
ocrTaskchildPicture.setPicturecompare(String.join(",",ocrPicture.getPicturecompareList()));
// StringBuffer pcid = new StringBuffer();
// StringBuffer result = new StringBuffer();
// for(OcrPicture comp:ocrPicture.getListCom()){
// if(null == pcid || pcid.toString().length() < 1){
// pcid.append(comp.getId());
// result.append(comp.getResult());
// }else{
// pcid.append("," + comp.getId());
// result.append("," + comp.getResult());
// }
// }
//
// ocrTaskchildPicture.setOcpictureid(pcid.toString());
// ocrTaskchildPicture.setPictureresult(result.toString());
// ocrTaskchildPicture.setPicturecompare(String.join(",",ocrPicture.getPicturecompareList()));
return this.save(ocrTaskchildPicture)?ocrTaskchildPicture:null;
}

@ -68,10 +68,10 @@ public class TaskQueue {
}
/**
*
*
* @return
*/
public static PictureImgToLocalEntity pictureImgToLocalPullData(){
return (PictureImgToLocalEntity) pictureDisposeQueue.poll();
return (PictureImgToLocalEntity) pictureImgToLocalQueue.poll();
}
}

@ -1,4 +1,5 @@
package cn.jyjz.xiaoyao.ocr.thread;
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceResult;
import cn.jyjz.xiaoyao.ocr.thread.entity.PictureImgToLocalEntity;
import cn.jyjz.xiaoyao.ocr.thread.tasks.PictureDisposeTask;
@ -36,6 +37,7 @@ public class TaskThreadPool {
/**
*
*
* @return
*/
public boolean startPictureDisposePull() {
@ -61,6 +63,7 @@ public class TaskThreadPool {
/**
*
*
* @return
*/
public boolean startPictureImgToLocalPull() {
@ -69,13 +72,20 @@ public class TaskThreadPool {
@Override
public void run() {
logger.debug("图片下载消费线程检测中...");
while (true) {
try {
PictureImgToLocalEntity pictureImgToLocalEntity = TaskQueue.pictureImgToLocalPullData();
if (pictureImgToLocalEntity != null) {
threadPool.execute(new PictureImgToLocalTask(pictureImgToLocalEntity));
} else {
Thread.sleep(5000);
}
} catch (Exception e) {
logger.error("图片下载消费线程报错{}", e.getMessage());
Thread.sleep(5000);
}
}
}
};

@ -1,5 +1,7 @@
package cn.jyjz.xiaoyao.ocr.thread.tasks;
import cn.hutool.core.util.ObjectUtil;
import cn.jyjz.xiaoyao.common.base.util.ObjectUtils;
import cn.jyjz.xiaoyao.common.base.util.SpringUtils;
import cn.jyjz.xiaoyao.common.base.util.StringUtils;
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceResult;
@ -32,8 +34,17 @@ public class PictureImgToLocalTask implements Runnable{
@Override
public void run() {
OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService");
OcrPicture picture = ocrPictureService.getById(pictureImgToLocal.getPictureId());
//1.开始转储图片
DownloadImgUtil.downloadImage(pictureImgToLocal.getImgUrl(), pictureImgToLocal.getLocalPath());
Boolean result = DownloadImgUtil.downloadImage(pictureImgToLocal.getImgUrl(), pictureImgToLocal.getLocalPath());
if (Boolean.TRUE.equals(result)) {
if (ObjectUtil.isNotEmpty(picture)) {
picture.setLocalpictrueurl(pictureImgToLocal.getLocalPath());
picture.setIsdownload(1);
ocrPictureService.updateById(picture);
}
}
}

@ -19,10 +19,11 @@ public class DownloadImgUtil {
/**
*
*
* @param imageUrl
* @param destinationFile
*/
public static void downloadImage(String imageUrl, String destinationFile) {
public static Boolean downloadImage(String imageUrl, String destinationFile) {
try (InputStream in = new URL(imageUrl).openStream();
FileOutputStream out = new FileOutputStream(destinationFile)) {
@ -33,7 +34,9 @@ public class DownloadImgUtil {
}
} catch (Exception e) {
logger.error(e.getMessage());
return false;
}
return true;
}

@ -1,4 +1,3 @@
server:
compression:
enabled: true
@ -282,3 +281,4 @@ ocr:
accessCode: ED6F7B39768AF95E87AEA8ACCCC71A6F #秘钥编码
connectTimeout: 5000 #请求超时时间 毫秒
readTimeout: 60000 #接收超时时间 毫秒
localImagePath: /server/data/images #图片本地存储地址

@ -285,5 +285,5 @@ ocr:
accessCode: ED6F7B39768AF95E87AEA8ACCCC71A6F #秘钥编码
connectTimeout: 5000 #请求超时时间 毫秒
readTimeout: 60000 #接收超时时间 毫秒
localImagePath: /server/data/images #图片本地存储地址

Loading…
Cancel
Save