|
|
|
@ -2,7 +2,6 @@ package cn.jyjz.xiaoyao.ocr.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.jyjz.flowable.domain.vo.FlowInstanceVo;
|
|
|
|
|
import cn.jyjz.flowable.service.IFlowInstanceService;
|
|
|
|
|
import cn.jyjz.xiaoyao.abase.service.SeqManageService;
|
|
|
|
|
import cn.jyjz.xiaoyao.admin.service.LogService;
|
|
|
|
@ -18,36 +17,31 @@ 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 cn.jyjz.xiaoyao.ocr.util.httputil.HttpClient;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.httputil.HttpHeader;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.httputil.HttpParamers;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
|
|
|
import org.apache.commons.lang.time.DateFormatUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.poi.hpsf.Decimal;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.security.core.parameters.P;
|
|
|
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.mybatisplus.base.BaseServiceImpl;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 业务层实现
|
|
|
|
|
*/
|
|
|
|
@ -94,6 +88,7 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
|
|
|
|
|
*/
|
|
|
|
|
@Autowired
|
|
|
|
|
DataDictionaryUtil dataDictionaryUtil;
|
|
|
|
|
|
|
|
|
|
public ResultVo createTaskChild(List<OcrPicture> ocrPictureList, String tenantId, UserToken sysUser, String search_month, HttpServletRequest request, String buessinessno) {
|
|
|
|
|
|
|
|
|
|
//图片错误信息
|
|
|
|
@ -278,6 +273,160 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
|
|
|
|
|
}
|
|
|
|
|
return ResultVoUtil.error("失败。");
|
|
|
|
|
}
|
|
|
|
|
public ResultVo createTaskChild(List<OcrPicture> ocrPictureList, String tenantId) {
|
|
|
|
|
|
|
|
|
|
//图片错误信息
|
|
|
|
|
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任务包");
|
|
|
|
|
|
|
|
|
|
//用于标记相似度是否存在百分百的情况
|
|
|
|
|
|
|
|
|
|
List<OcrPicture> newList = new ArrayList<>();
|
|
|
|
|
for (OcrPicture ocrPicture : ocrPictureList) {
|
|
|
|
|
//图片查重的比对图片集合
|
|
|
|
|
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(),
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
UserToken userToken = new UserToken();
|
|
|
|
|
userToken.setLoginname("admin");
|
|
|
|
|
userToken.setUsername("admin");
|
|
|
|
|
//创建工单,如果创建成功,增加标志,用于过滤条件使用
|
|
|
|
|
OcrTaskchildPicture ocrTaskchildPicture = this.ocrTaskchildPictureService.create(ocrPicture, tenantId, userToken, null, null);
|
|
|
|
|
if (null != ocrTaskchildPicture) {
|
|
|
|
|
//发起流程
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
|
|
|
|
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
|
|
|
|
|
flowInstanceService.startProcessInstanceById(
|
|
|
|
|
category.getProcessdefinitionid(),
|
|
|
|
|
null,
|
|
|
|
|
request,
|
|
|
|
|
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("失败。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void bubbleSortOpt(List<OcrPicture> compareList) {
|
|
|
|
|
|
|
|
|
|
if (null == compareList) {
|
|
|
|
@ -294,8 +443,10 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存接口传来的json数据
|
|
|
|
|
*
|
|
|
|
|
* @param jsonArray
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -305,6 +456,7 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<OcrPicture> listPage(Wrapper<OcrPicture> queryWrapper) {
|
|
|
|
|
|
|
|
|
|
long count = this.count(queryWrapper);
|
|
|
|
@ -353,6 +505,7 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询工单图片信息
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<OcrPicture> listByTaskChild(List<String> pictureidlist) {
|
|
|
|
@ -381,6 +534,7 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询工单下的图片以及查重结果
|
|
|
|
|
*
|
|
|
|
|
* @param ocrTaskchildPicture
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -537,6 +691,9 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
|
|
|
|
|
//3.添加图片信息
|
|
|
|
|
if (this.saveBatch(ocrPictureList)) {
|
|
|
|
|
|
|
|
|
|
this.createTaskChild(ocrPictureList, ocrPictureList.get(0).getTenantId().toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ocrPictureList.size();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
@ -544,6 +701,7 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 格式化筛选关系
|
|
|
|
|
*
|
|
|
|
|
* @param queryWrapper
|
|
|
|
|
* @param usersearchchild
|
|
|
|
|
* @return
|
|
|
|
@ -567,6 +725,7 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 格式化查询类型
|
|
|
|
|
*
|
|
|
|
|
* @param queryWrapper
|
|
|
|
|
* @param usersearchchild
|
|
|
|
|
* @return
|
|
|
|
|