Merge remote-tracking branch 'origin/master'

master
LiZhong 1 year ago
commit b1c3c21d02

@ -15,6 +15,7 @@ import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.ModuleType;
import org.jeecg.common.constant.enums.OperateTypeEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.IpUtils;
@ -52,17 +53,18 @@ public class AutoLogAspect {
}
@Around("logPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
public void around(ProceedingJoinPoint point) throws Throwable {
long beginTime = System.currentTimeMillis();
//执行方法
Object result = point.proceed();
//执行时长(毫秒)
long time = System.currentTimeMillis() - beginTime;
//保存日志
saveSysLog(point, time, result);
return result;
try{
Object result = point.proceed();
long time = System.currentTimeMillis() - beginTime;
saveSysLog(point, time, result);
}catch (Exception e){
long time = System.currentTimeMillis() - beginTime;
saveSysLog(point, time, e.getMessage());
throw new JeecgBootException(e.getMessage());
}
}
private void saveSysLog(ProceedingJoinPoint joinPoint, long time, Object obj) {
@ -95,6 +97,8 @@ public class AutoLogAspect {
//获取request
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
dto.setRequestUrl(request.getRequestURL().toString());
dto.setRequestType(request.getMethod());
//请求的参数
dto.setRequestParam(getReqestParams(request,joinPoint));
//设置IP地址

@ -3,12 +3,16 @@ package org.jeecg.modules.api.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.ModuleType;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.*;
import org.jeecg.modules.ocr.entity.OcrIdentify;
@ -18,6 +22,7 @@ import org.jeecg.modules.ocr.service.IOcrIdentifyDetailService;
import org.jeecg.modules.ocr.service.IOcrIdentifyService;
import org.jeecg.modules.ocr.service.IOcrRuleCheckService;
import org.jeecg.modules.ocr.service.impl.TaskService;
import org.jeecg.modules.ocr.utils.CallBackWlyUtils;
import org.jeecg.modules.ocr.utils.FileOUtils;
import org.jeecg.modules.ocr.utils.ImageUtils;
import org.jeecg.modules.ocr.dto.OcrIdentifyDTO;
@ -33,6 +38,7 @@ import javax.annotation.Resource;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -57,14 +63,18 @@ public class ApiController {
private TaskService taskService;
@Value("${spring.profiles.active}")
private String profiles;
@Value("${system.project.wlyCallback}")
private String wlyCallback;
@ApiOperation(value = "通用识别")
@RequestMapping("/identify")
@Transactional
@ResponseBody
@AutoLog(value = "api接口-通用识别",logType = CommonConstant.LOG_TYPE_2,operateType=CommonConstant.OPERATE_TYPE_1)
public Result<?> pushSemantic(@RequestBody JSONObject requestBody) throws InterruptedException {
if (!"test".equals(profiles)) {
return Result.error("当前环境不支持该功能,请访问测试环境");
}
// if (!"test".equals(profiles)) {
// return Result.error("当前环境不支持该功能,请访问测试环境");
// }
log.info("api接口-通用识别请求开始,{}",requestBody);
if (requestBody == null) {
return Result.error("请输入请求参数");
}
@ -80,6 +90,7 @@ public class ApiController {
//=============================================================
//2.参数判断
AssertUtils.notNull(requestId, "[requestId]-不可为空");
AssertUtils.notTrue(ocrIdentifyService.calculateTimeDifferenceByRequestId(requestId)<=10,"[requestId]-"+taskName+" 短时间内已存在,不可再次请求");
AssertUtils.notTrue(!"door".equals(scenes), String.format("暂不支持该场景类型[%s]", scenes));
AssertUtils.notNull(ruleId, "[ruleId]-不可为空");
OcrRuleCheckDTO ruleCheck = ocrRuleCheckService.findById(ruleId);
@ -130,9 +141,10 @@ public class ApiController {
ocrIdentify.setSourceJson(requestBody.getJSONArray("sourceJson").toJSONString());//校验数据源
ocrIdentifyService.save(ocrIdentify);
}
log.info("api接口-通用识别请求结束,{}",requestBody);
Thread.sleep(1000L);
//3.请求python ocr识别异步执行
taskService.postSemantic(ocrIdentify,fileList);
//taskService.postSemantic(ocrIdentify,fileList);
//ocrIdentifyService.postSemantic(ocrIdentify, fileList);
return Result.OK("请求成功");
}
@ -255,7 +267,11 @@ public class ApiController {
//ocrIdentifyService.getSemanticInfo(semanticResponseJson);
/*OcrRuleCheckVo ocrRuleCheckVo = byId.getOcrRuleCheckVo();
Map<String, String> configRuleMap = ocrRuleCheckVo.getConfigRuleMap();*/
OcrIdentifyDTO identifyDTO = ocrIdentifyService.findById("1702560400245035009");
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(identifyDTO.getId());
CallBackWlyUtils.callbackWly(wlyCallback,identifyDTO,identifyDetailList);
return Result.OK("");
}
}

@ -149,10 +149,11 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
// @RequiresPermissions("org.jeecg.modules.ocr:ocr_identify:add")
@PostMapping(value = "/add")
public Result<String> add(@RequestBody OcrIdentify ocrIdentify) {
if (!"test".equals(profiles)) {
return Result.error("当前环境不支持该功能,请访问测试环境");
}
// if (!"test".equals(profiles)) {
// return Result.error("当前环境不支持该功能,请访问测试环境");
// }
AssertUtils.notEmpty(ocrIdentify.getTaskName(), "[任务名称]-不可为空");
AssertUtils.notTrue(ocrIdentifyService.calculateTimeDifferenceByTaskName(ocrIdentify.getTaskName())<=10,"[任务名称]-"+ocrIdentify.getTaskName()+" 短时间内已存在,不可再次请求");
AssertUtils.notEmpty(ocrIdentify.getIdentifyUrl(), "[识别路径]不可为空");
AssertUtils.notEmpty(ocrIdentify.getRuleCheck(), "请选择[规则检查配置]");
AssertUtils.notEmpty(ocrIdentify.getPriority(), "请选择[优先级]");
@ -182,7 +183,7 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
ocrIdentify.setStatus("0");
ocrIdentifyService.save(ocrIdentify);
//3.请求python ocr识别异步执行
taskService.postSemantic(ocrIdentify, fileList);
//taskService.postSemantic(ocrIdentify, fileList);
return Result.OK("添加成功!");
}
@ -427,4 +428,5 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
}
return Result.OK("操作成功");
}
}

@ -41,6 +41,8 @@ public class OcrIdentifyDetailController extends JeecgController<OcrIdentifyDeta
//系统环境
@Value("${system.project.env}")
private String systemProjectEnv;
@Value("${system.project.fileReviewUrlPrefix}")
private String fileReviewUrlPrefix;
/**
*
@ -65,14 +67,14 @@ public class OcrIdentifyDetailController extends JeecgController<OcrIdentifyDeta
if (StringUtils.isNotBlank(record.getImageUrl())&&"customer_test".equals(systemProjectEnv)) {
//客户测试服务器
if (!record.getImageUrl().contains("http:")&&!record.getImageUrl().contains("https:")) {
String imagePreviewUrl="http://47.103.213.109:8072/files"+record.getImageUrl();
String imagePreviewUrl=fileReviewUrlPrefix+record.getImageUrl();
record.setImagePreviewUrl(imagePreviewUrl);
//压缩图片
if (StringUtils.isNotBlank(record.getThumbnailImageUrl())) {
File file=new File(record.getThumbnailImageUrl());
//当原图片存在时.
if (file.exists()) {
record.setThumbnailImagePreviewUrl("http://47.103.213.109:8072/files"+record.getThumbnailImageUrl());
record.setThumbnailImagePreviewUrl(fileReviewUrlPrefix+record.getThumbnailImageUrl());
}
}
//虚线图片
@ -80,8 +82,8 @@ public class OcrIdentifyDetailController extends JeecgController<OcrIdentifyDeta
File file=new File(record.getDrawDashedImageUrl());
//当虚线图片存在时,替换原图字段
if (file.exists()) {
record.setDrawDashedImagePreviewUrl("http://47.103.213.109:8072/files"+record.getDrawDashedImageUrl());
record.setImagePreviewUrl("http://47.103.213.109:8072/files"+record.getDrawDashedImageUrl());
record.setDrawDashedImagePreviewUrl(fileReviewUrlPrefix+record.getDrawDashedImageUrl());
record.setImagePreviewUrl(fileReviewUrlPrefix+record.getDrawDashedImageUrl());
}
}
}else{

@ -51,9 +51,9 @@ public class OcrSimulatorController{
@ApiOperation(value = "场景识别")
@PostMapping(value = "/identify")
public Result<?> identify(@RequestBody JSONObject requestBody) {
if (!"test".equals(profiles)) {
return Result.error("当前环境不支持该功能,请访问测试环境");
}
// if (!"test".equals(profiles)) {
// return Result.error("当前环境不支持该功能,请访问测试环境");
// }
JSONObject responseBody = new JSONObject();
JSONArray images = requestBody.getJSONArray("images");
AssertUtils.hasSize(images,"请先上传图片");
@ -115,5 +115,14 @@ public class OcrSimulatorController{
AssertUtils.hasSize(identifyDetailIdList,"请先上传图片");
return Result.OK(ocrIdentifyService.simulateChecks(simulateChecksVO));
}
@ApiOperation(value = "模拟检查G")
@PostMapping(value = "/simulateChecksV01")
public Result<?> simulateChecksV01(@RequestBody SimulateChecksVO simulateChecksVO) {
//规则检查配置id
String ruleCheckId = simulateChecksVO.getRuleCheckId();
List<String> identifyDetailIdList = simulateChecksVO.getIdentifyDetailIdList();
AssertUtils.notEmpty(ruleCheckId, "请选择[规则扫描器]");
AssertUtils.hasSize(identifyDetailIdList,"请先上传图片");
return Result.OK(ocrIdentifyService.simulateChecksV01(simulateChecksVO));
}
}

@ -22,7 +22,7 @@ public class OcrRuleCheckDTO extends OcrRuleCheck {
@ApiModelProperty(value = "元数据配置名称")
@Excel(name = "元数据配置名称", width = 15)
private String metadataConfigName;
private String configRuleAdapter;
private Map<String,String> configRuleMap=new LinkedHashMap<>();
private Map<String,String> fieldMap=new LinkedHashMap<>();

@ -51,6 +51,7 @@ public class HandleCallbacklnit implements ApplicationRunner {
@Override
@Async
public void run(ApplicationArguments args) throws UnknownHostException {
log.info("---------------------回调任务开启{}---------------------",enableHandleTask);
if (enableHandleTask) {
List<DictModel> callbackApiConfigs = sysDictService.queryDictItemsByCode("callback_api_config");
Integer autoPushNoticeMaxNum=10;//自动请求最大次数.
@ -62,7 +63,7 @@ public class HandleCallbacklnit implements ApplicationRunner {
autoPushNoticeMaxNum = Integer.valueOf(callbackApiConfig.getValue());
}
}
log.info(pushTimeInterval+"秒请求一次回调");
while (true){
try {
Thread.sleep(pushTimeInterval*1000);
@ -72,7 +73,9 @@ public class HandleCallbacklnit implements ApplicationRunner {
List<OcrIdentify> ocrIdentifyList = ocrIdentifyService.findNeNoticeList(autoPushNoticeMaxNum);
for (OcrIdentify ocrIdentify : ocrIdentifyList) {
try {
log.info("回调:{}",ocrIdentify.getIdentifyUrl());
ocrIdentifyService.callbackWly(ocrIdentify.getId());
log.info("回调结束:{}",ocrIdentify.getIdentifyUrl());
Thread.sleep(pushTimeInterval*1000);
} catch (InterruptedException e) {
log.error(e.getMessage());

@ -0,0 +1,161 @@
package org.jeecg.modules.ocr.init;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.jeecg.common.constant.OcrConstant;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.AssertUtils;
import org.jeecg.common.util.RestUtil;
import org.jeecg.modules.ocr.dto.OcrIdentifyDTO;
import org.jeecg.modules.ocr.entity.OcrIdentify;
import org.jeecg.modules.ocr.service.IOcrIdentifyDetailService;
import org.jeecg.modules.ocr.service.IOcrIdentifyService;
import org.jeecg.modules.ocr.service.impl.TaskService;
import org.jeecg.modules.ocr.utils.FileOUtils;
import org.jeecg.modules.system.entity.SysLog;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecg.modules.system.service.ISysLogService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/9/20 17:53
*/
@Configuration
@Slf4j
public class HandleTaskInit implements ApplicationRunner {
@Resource
IOcrIdentifyService ocrIdentifyService;
@Resource
IOcrIdentifyDetailService ocrIdentifyDetailService;
@Resource
TaskService taskService;
@Resource
private ISysDictService sysDictService;
@Resource
private ISysLogService sysLogService;
@Value("${system.project.enableHandleTask}")
private boolean enableHandleTask;
@Override
@Async
public void run(ApplicationArguments args) throws Exception {
if(enableHandleTask){
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
while (true) {
try {
Thread.sleep(10000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("---------检测是否有任务...");
//获取任务
List<OcrIdentify> list= ocrIdentifyService.getSemanticTaskList();
if (CollectionUtils.isEmpty(list)) {
continue;
}
//获取相对路径
List<DictModel> ocr_relative_path = sysDictService.queryDictItemsByCode("ocr_relative_path");
String relativePath = null;
if (ocr_relative_path != null && ocr_relative_path.size() > 0) {
for (DictModel dictModel : ocr_relative_path) {
if (dictModel.getValue().equals("0")) {
relativePath = dictModel.getText();
}
}
}
//获取识别的图片
List<String> fileList=null;
//临时变量
List<String> fileUrlList;
String image;//图片
//执行获取到的任务
identifyFor: for (OcrIdentify ocrIdentify : list) {
//过滤不需要的任务批次
if(ocrIdentify.getRequestId().contains("c1b1f298e7ab4ba59103081e55f9cd01")){
continue;
}
image=null;
fileList=new ArrayList<>();
//识别的图片路径
String imageUrl = ocrIdentify.getIdentifyUrl();
//判断是不是网络图片
Boolean onlineFile = FileOUtils.isOnlineFile(ocrIdentify.getIdentifyUrl());
//把过去执行过的明细给删掉
ocrIdentifyDetailService.deleteByOcrIdentifyId(ocrIdentify.getId());
//更新开始时间
ocrIdentifyService.updateMasterTaskStartTime(ocrIdentify.getId());
//最终要请求ocr识别的图片对象
JSONObject requestBody = new JSONObject();
if (onlineFile) {
//如果是网络图片,则将图片下载
image = FileOUtils.downLoadFromUrl(imageUrl, FileOUtils.getFileName(imageUrl), OcrConstant.FILE_DOWNLOAD_URL_PREFIX);
fileList.add(image);
}else{
//路径下识别到的图片集合
fileUrlList = FileOUtils.fileLists(relativePath, ocrIdentify.getIdentifyUrl());
AssertUtils.notNull(fileUrlList, "图片地址不存在");
for (String fileUrl : fileUrlList) {
//判断附件是否是 图片格式
if (fileUrl.lastIndexOf(".png") != -1 || fileUrl.lastIndexOf(".jpg") != -1 || fileUrl.lastIndexOf(".jpeg") != -1) {
fileList.add(fileUrl);
}
}
}
//最终要识别哪些图片
int i=0;
for (String img : fileList) {
i++;
requestBody.put("task_id", ocrIdentify.getId()+"_"+i);
requestBody.put("img_path", img);
log.info("----------------------请求参数");
log.info(requestBody.toJSONString());
try {
log.info("----------------------请求参数");
log.info(requestBody.toJSONString());
JSONObject semanticResponseJson = RestUtil.post(OcrConstant.api_test2_identify_url, requestBody);
semanticResponseJson.put("identifyId", ocrIdentify.getId());
log.info("ocr识别返回数据:");
log.info(semanticResponseJson.toJSONString());
ocrIdentifyService.getSemanticInfo(semanticResponseJson);
}catch (Exception e){
log.error("识别图片失败:");
SysLog sysLog=new SysLog();
sysLog.setLogType(2);
sysLog.setLogContent(img+"_识别图片失败:"+e.getMessage());
sysLog.setOperateType(2);
sysLogService.save(sysLog);
log.error(e.getMessage());
log.error("正在重试...");
continue identifyFor;
}
}
//更改任务状态
ocrIdentifyService.updateOcrIdentifyStatus(ocrIdentify.getId(), "1");
}
}
}
}
}

@ -48,8 +48,9 @@ public class HandleTransInit implements ApplicationRunner {
@Override
@Async
@Deprecated
public void run(ApplicationArguments args) throws UnknownHostException {
if (enableHandleTask) {
if (false) {
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {

@ -18,4 +18,6 @@ public interface IOcrIdentifyDetailService extends IService<OcrIdentifyDetail> {
* @return
*/
List<OcrIdentifyDetail> listByIdentifyId(String identifyId);
boolean deleteByOcrIdentifyId(String id);
}

@ -49,6 +49,12 @@ public interface IOcrIdentifyService extends IService<OcrIdentify> {
*/
Result pushTask(JSONObject jsonObject);
/**
*
*/
void updateOcrIdentifyStartTime(String id);
@Deprecated
void updateMasterTaskStartTime(String id);
/**
@ -62,4 +68,21 @@ public interface IOcrIdentifyService extends IService<OcrIdentify> {
* @param simulateChecksVO
*/
JSONObject simulateChecks(SimulateChecksVO simulateChecksVO);
/**
*
* @return
*/
List<OcrIdentify> getSemanticTaskList();
/**
*
* @return
*/
long calculateTimeDifferenceByRequestId(String requestId);
JSONObject simulateChecksV01(SimulateChecksVO simulateChecksVO);
long calculateTimeDifferenceByTaskName(String taskName);
}

@ -78,4 +78,5 @@ public interface IOcrRuleCheckService extends IService<OcrRuleCheck> {
boolean copy(OcrRuleCheck ocrRuleCheck);
OcrRuleCheckDTO findByIdV01(String ruleCheckId);
}

@ -23,4 +23,11 @@ public class OcrIdentifyDetailServiceImpl extends ServiceImpl<OcrIdentifyDetailM
List<OcrIdentifyDetail> list = super.list(new LambdaQueryWrapper<OcrIdentifyDetail>().eq(OcrIdentifyDetail::getIdentifyId, identifyId));
return list;
}
@Override
public boolean deleteByOcrIdentifyId(String identifyId) {
LambdaQueryWrapper<OcrIdentifyDetail> queryWrapper=new LambdaQueryWrapper<>();
queryWrapper.eq(OcrIdentifyDetail::getIdentifyId,identifyId);
return this.remove(queryWrapper);
}
}

@ -3,6 +3,7 @@ package org.jeecg.modules.ocr.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
@ -10,6 +11,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.OcrConstant;
import org.jeecg.common.util.AssertUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.RestUtil;
import org.jeecg.modules.ocr.dto.OcrIdentifyDTO;
@ -25,6 +27,7 @@ import org.jeecg.modules.ocr.model.TaskModel;
import org.jeecg.modules.ocr.service.*;
import org.jeecg.modules.ocr.utils.*;
import org.jeecg.modules.ocr.vo.SimulateChecksVO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
@ -61,7 +64,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
RedisUtil redisUtil;
@Resource
IOcrIdentifyCallbackLogService ocrIdentifyCallbackLogService;
@Value("${system.project.fileReviewUrlPrefix}")
private String fileReviewUrlPrefix;
@Value("${system.project.wlyCallback}")
private String wlyCallback;
@Override
public OcrIdentifyDTO findById(String id) {
OcrIdentifyDTO ocrIdentifyDTO = baseMapper.findById(id);
@ -87,13 +93,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
log.debug("打印 ocr 结果:" + responseBody.toString());
String identifyId = responseBody.getString("identifyId");//任务id
String imgPath = responseBody.getString("img_path");//图片路径
String imgName = null;//图片名称
if (StringUtils.isNotBlank(imgPath)) {
imgName = imgPath.substring(imgPath.lastIndexOf("/") + 1, imgPath.length());
} else {
log.error("异常,识别图片地址为空");
return;
}
AssertUtils.notEmpty(imgPath,"异常,识别图片地址为空");
String imgName = imgPath.substring(imgPath.lastIndexOf("/") + 1, imgPath.length());//图片名称
String message = responseBody.getString("message");//描述
String taskStatus = responseBody.getString("taskStatus");//任务是否完成
Double ocrTime = responseBody.getDouble("ocr_time");//OCR识别时长
@ -248,8 +249,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo);
} else if (StringUtils.isBlank(inputText)) {
//没有输入值.
fieldRightMap.put(field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true, ruleInfo);
fieldRightMap.put(field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo);
} else if ("0".equals(ruleInfo)) {
//不必校验,有识别到就行,通过
fieldRightMap.put(field, true);
@ -354,8 +355,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
@Override
@Async
public void updateOcrIdentifyStatus(String id, String status) {
log.info("id:{}",id);
//4.更新主任务状态
OcrIdentifyDTO ocrIdentifyDTO = this.findById(id);
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(OcrIdentify::getId, id);
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
@ -366,7 +367,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
/////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的.
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
String dataStructured = ocrIdentifyDetail.getDataStructured();
if (org.apache.commons.lang.StringUtils.isNotBlank(dataStructured)) {
if (StringUtils.isNotBlank(dataStructured)) {
JSONArray jsonArray = JSONObject.parseArray(dataStructured);
List<OcrResultDTO> resultList = jsonArray.toJavaList(OcrResultDTO.class);
for (OcrResultDTO result : resultList) {
@ -377,7 +378,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
fieldRightMap.put(tag, result);
} else if (lastResult == null || !lastResult.getRuleValidation()) {
//失败时就是未获取到结果
result.setFailureReason(result.getTagName() + "未获取到结果");
result.setFailureReason(result.getTagName() + "不匹配");
fieldRightMap.put(tag, result);
}
}
@ -420,7 +421,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
public void callbackWly(String ocrIdentifyId) {
OcrIdentifyCallbackLog ocrIdentifyCallbackLog = new OcrIdentifyCallbackLog();
ocrIdentifyCallbackLog.setIdentifyId(ocrIdentifyId);
Date date = new Date();
ocrIdentifyCallbackLog.setCreateTime(date);
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
@ -430,8 +430,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
OcrIdentify ocrIdentify = super.getById(ocrIdentifyId);
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyId);
ocrIdentifyCallbackLog.setStartTime(date);
boolean b = CallBackWlyUtils.callbackWly(ocrIdentify, identifyDetailList);
ocrIdentifyCallbackLog.setStatus(b?1:0);
boolean b = CallBackWlyUtils.callbackWly(wlyCallback,ocrIdentify, identifyDetailList);
ocrIdentifyCallbackLog.setStatus(b?1:0);//0-失败1-成功
ocrIdentifyCallbackLog.setEndTime(new Date());
ocrIdentifyCallbackLogService.save(ocrIdentifyCallbackLog);
if (b) {
@ -456,7 +456,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
*
* @param ruleValidationValue
*/
public static void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d, String ruleValidationValue) {
public void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d, String ruleValidationValue) {
OcrResultDTO ocrResultDTO = new OcrResultDTO();
ocrResultDTO.setTag(field);
ocrResultDTO.setTagName(fieldName);
@ -476,7 +476,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
sourceImage.setPath(imgPath);
int i = imgPath.lastIndexOf("/");
sourceImage.setFileName(imgPath.substring(i + 1, imgPath.length()));
sourceImage.setPreviewUrl(OcrConstant.FILE_REVIEW_URL_PREFIX+imgPath);
sourceImage.setPreviewUrl(fileReviewUrlPrefix+imgPath);
ocrResultDTO.setSourceImage(sourceImage);
}
ocrResultDTO.setFailureReason(failureReason);
@ -505,13 +505,45 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
/**
* OcrResult, ocrResultList
*/
public static void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, String ruleValidationValue) {
public void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, String ruleValidationValue) {
if (ruleValidation) {
ocrResultAdd(ocrResultDTOList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 100d,ruleValidationValue);
} else {
ocrResultAdd(ocrResultDTOList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 0d,ruleValidationValue);
}
}
/**
* OcrResult, ocrResultList
*/
public static void ocrResultAddV01(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d) {
OcrResultDTO ocrResultDTO = new OcrResultDTO();
ocrResultDTO.setTag(field);
ocrResultDTO.setTagName(fieldName);
ocrResultDTO.setOcrText(ocrText);
ocrResultDTO.setInputText(inputText);
ocrResultDTO.setOcrPrecisionRate(ocrPrecisionRate == null ? 0d : ocrPrecisionRate);
if (d == null) {
ocrResultDTO.setTextRate(0d);
} else {
ocrResultDTO.setTextRate(new BigDecimal(d).setScale(2, RoundingMode.HALF_UP).doubleValue());
}
/*System.out.println("-----------------");
System.out.println(failureReason);
System.out.println("-----------------");*/
if (StringUtils.isNotBlank(imgPath)) {
SourceImage sourceImage = new SourceImage();
sourceImage.setPath(imgPath);
int i = imgPath.lastIndexOf("/");
sourceImage.setFileName(imgPath.substring(i + 1, imgPath.length()));
sourceImage.setPreviewUrl(OcrConstant.FILE_REVIEW_URL_PREFIX+imgPath);
ocrResultDTO.setSourceImage(sourceImage);
}
ocrResultDTO.setFailureReason(failureReason);
if (ocrResultDTOList == null) {
ocrResultDTOList = new ArrayList<>();
}
ocrResultDTOList.add(ocrResultDTO);
}
/**
* checkSemanticModelMap
@ -520,8 +552,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
* @param fieldMap map
*/
public Map<String, CheckSemanticModel> getCheckSemanticModelMap(Map<String, String> configRuleMap, Map<String, String> fieldMap, List<JSONObject> sourceJsonObjects) {
if (configRuleMap!=null) {
for (String s : configRuleMap.keySet()) {
if (configRuleMap!=null && CollectionUtils.isNotEmpty(configRuleMap.keySet())) {
//将 configRuleMap的 key 创建一个Set
Set<String> keySet = new HashSet<>(configRuleMap.keySet());
//循环keySet判断字段是否是缩写如果是缩写就把缩写的全称put一下
for (String s : keySet) {
String value = configRuleMap.get(s);
if ("hn".equals(s)) {
configRuleMap.put("hospitalName",value);
@ -529,8 +564,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
configRuleMap.put("doctorName", value);
}else if("dmn".equals(s)) {
configRuleMap.put("departmentName", value);
}else if("time".equals(s)) {
}else if("tm".equals(s) || ("time".equals(s))) {
configRuleMap.put("time", value);
}else{
configRuleMap.put(s,value);
}
}
}
@ -656,6 +693,15 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
return Result.OK("已追加到任务");
}
@Override
public void updateOcrIdentifyStartTime(String id) {
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(OcrIdentify::getStartTime, new Date());
updateWrapper.set(OcrIdentify::getEndTime,null);
updateWrapper.eq(OcrIdentify::getId, id);
super.update(updateWrapper);
}
@Override
public void updateMasterTaskStartTime(String id) {
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
@ -694,7 +740,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
i1++;
String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
String imgPath = ocrIdentifyDetail.getImageUrl();
if (StringUtils.isBlank(semanticResultJson)) continue;
if (StringUtils.isBlank(semanticResultJson)) {continue;}
String doctorName = simulateChecksVO.getDoctorName();
String hospitalName = simulateChecksVO.getHospitalName();
String departmentName = simulateChecksVO.getDepartmentName();
@ -769,7 +815,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
StringBuilder rMessage = new StringBuilder();
//==========================
for (CheckSemanticModel value : checkSemanticModelMap.values()) {
String field = value.getField();
String field = value.getField();//字段 name.
String fieldName = value.getFieldName();//校验的字段名称
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断1-不绝对判断
String inputText = value.getInputText();//校验文本 ocr识别的文本如果不包含该内容则算作失败
@ -816,6 +862,46 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
break;
}
}
}else if (Arrays.asList("患者姓名","患者").contains(s)) {
for (String s1 : Arrays.asList("患者姓名","患者")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("病历号").contains(s)) {
for (String s1 : Arrays.asList("病历号")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("入院日期").contains(s)) {
for (String s1 : Arrays.asList("入院日期")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("出生日期").contains(s)) {
for (String s1 : Arrays.asList("出生日期")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("年龄").contains(s)) {
for (String s1 : Arrays.asList("年龄")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else{
jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s);
}
@ -853,8 +939,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo);
} else if (StringUtils.isBlank(inputText)) {
//没有输入值.
fieldRightMap.put(field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true, ruleInfo);
fieldRightMap.put(field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo);
} else if ("0".equals(ruleInfo)) {
//不必校验,有识别到就行,通过
fieldRightMap.put(field, true);
@ -935,6 +1021,35 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
}else{
newResultDTOList.add(o);
}
//脱敏处理
String tagName = o.getTagName();
String ocrText = o.getOcrText();
StringBuilder sb = new StringBuilder();
if ("患者姓名".equals(tagName)) {
// 保留第一个字,其余用 "*" 替代
int length = Math.max(0, ocrText.length() - 1);
for (int i = 0; i < length; i++) {
sb.append("*");
}
String desensitizedText = ocrText.substring(0, 1) + sb.toString();
o.setOcrText(desensitizedText);
}
if ("联系方式".equals(tagName) || "身份证号".equals(tagName)){
String desensitizedText = desensitizeText(ocrText); // 自定义的脱敏方法
// 更新脱敏后的值
o.setOcrText(desensitizedText);
}
if ("家庭住址".equals(tagName) || "工作地址".equals(tagName) || "病情陈述人".equals(tagName)
|| "户籍地".equals(tagName)){
sb.append(ocrText.charAt(0));
for (int i = 1; i < ocrText.length() - 1; i++) {
sb.append("*");
}
sb.append(ocrText.charAt(ocrText.length() - 1));
String desensitizedText= sb.toString();
o.setOcrText(desensitizedText);
}
}
ocrResultDTOList = newResultDTOList;
}
@ -949,10 +1064,409 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
responseBody.put("min",min);
responseBody.put("max",max);
responseBody.put("detailList", ocrResultDTOList);
return responseBody;
}
@Override
public List<OcrIdentify> getSemanticTaskList() {
LambdaQueryWrapper<OcrIdentify> queryWrapper=new LambdaQueryWrapper<>();
queryWrapper.in(OcrIdentify::getStatus,0,2);
queryWrapper.orderByDesc(OcrIdentify::getPriority);//优先 加急 1>0 不加急
queryWrapper.ne(OcrIdentify::getTaskSource,"模拟实验");//不获取模拟实验室的数据
return this.list(queryWrapper);
}
@Override
public JSONObject simulateChecksV01(SimulateChecksVO simulateChecksVO) {
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIds(simulateChecksVO.getIdentifyDetailIdList());
System.out.println("1111111111111111111111111111111");
//遍历任务,做匹配
int i1=1;
//用于数据结构化的对象
List<OcrResultDTO> ocrResultDTOList = new ArrayList<>();
Date startDataCheckTime = new Date();
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
i1++;
String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
String imgPath = ocrIdentifyDetail.getImageUrl();
if (StringUtils.isBlank(semanticResultJson)) {continue;}
String doctorName = simulateChecksVO.getDoctorName();
String hospitalName = simulateChecksVO.getHospitalName();
String departmentName = simulateChecksVO.getDepartmentName();
String time = simulateChecksVO.getTime();
List<JSONObject> sourceJson = new ArrayList<>();
if (StringUtils.isNotBlank(doctorName)) {
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"doctorName\", \"inputText\":\"%s\"}", doctorName)));
}
if (StringUtils.isNotBlank(hospitalName)) {
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"hospitalName\", \"inputText\":\"%s\"}", hospitalName)));
}
if (StringUtils.isNotBlank(departmentName)) {
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"departmentName\", \"inputText\":\"%s\"}", departmentName)));
}
if (StringUtils.isNotBlank(time)) {
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"time\", \"inputText\":\"%s\"}", time)));
}
JSONObject semanticResult = JSONObject.parseObject(ocrIdentifyDetail.getSemanticResult());
//判断是不是网络图片
Boolean onlineFile = FileOUtils.isOnlineFile(imgPath);
if (onlineFile) {
//如果是网络图片,则将图片下载
imgPath = FileOUtils.downLoadFromUrl(imgPath, FileOUtils.getFileName(imgPath), OcrConstant.FILE_DOWNLOAD_URL_PREFIX);
}
File file = new File(imgPath);
//当原图片存在时.
if (file.exists()) {
int i = imgPath.lastIndexOf("/");
//压缩图片
/*if (true) {
String fileUrl = "/data/ocrImage/thumbnail" + imgPath.substring(0, i);
//判断新目录是否存在,不存在则新建
FileOUtils.folderCreate(fileUrl);
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
File thumbnailFile = new File(outputImagePath);
//如果上次生成过缩率图,就不生成了
if (!thumbnailFile.exists()) {
ImageUtils.compressImage(file.getAbsolutePath(), outputImagePath, 0.3f, 0.3f);
}
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
}*/
//============================绘制虚线
JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
//判断新目录是否存在,不存在则新建
FileOUtils.folderCreate(fileUrl);
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
if (semanticResult2!=null) {
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2);
boolean hasPoints=true;
if (CollectionUtils.isNotEmpty(resultToPoints)) {
for (List<Point> resultToPoint : resultToPoints) {
if (CollectionUtils.isEmpty(resultToPoint)) {
hasPoints=false;
}
}
if (hasPoints){
ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath,"green");
imgPath = outputImagePath;
}
}
}
//============================
}
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckService.findByIdV01(simulateChecksVO.getRuleCheckId());
// Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMapV0(ocrRuleCheckVo.getConfigRule(), ocrRuleCheckVo.getFieldMap(), sourceJson);
String text = null;//ocr 识别的文本
Double probability = 0d;
StringBuilder rMessage = new StringBuilder();
//==========================
for (String key : ocrRuleCheckVo.getFieldMap().keySet()) {
CheckSemanticModel checkSemanticModel=new CheckSemanticModel();
for(JSONObject jsonObject:sourceJson){
Object tag = jsonObject.get("tag");
if(tag.equals(key)){
checkSemanticModel.setField(key);
checkSemanticModel.setFieldName(ocrRuleCheckVo.getFieldMap().get(key));
checkSemanticModel.setInputText(jsonObject.getString("inputText"));
}
}
String field = key;//字段 name.
String fieldName = checkSemanticModel.getFieldName();//校验的字段名称
// String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断1-不绝对判断
String inputText = checkSemanticModel.getInputText();//校验文本 ocr识别的文本如果不包含该内容则算作失败
if (StringUtils.isBlank(fieldName)) {
continue;
}
List<String> fieldNameList = Arrays.asList(fieldName.split(","));
text = null;
//boolean b = ArrayOUtils.containsStringList(fieldNameList, new ArrayList<>(semanticResult.getJSONObject("semantic_result").keySet()));
//查看ocr识别返回的字段名称中是否有当前这个字段名称
//TODO 注意ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确
List<JSONObject> ocrArray = new ArrayList<>();
for (String s : fieldNameList) {
JSONArray jsonArray = new JSONArray();
if (Arrays.asList("医生名称","姓名","医生").contains(s)) {
for (String s1 : Arrays.asList("医生名称", "姓名", "医生")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("科室名称","科室").contains(s)) {
for (String s1 : Arrays.asList("科室名称","科室")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("医院名称","医院").contains(s)) {
for (String s1 : Arrays.asList("医院名称", "医院")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("日期", "时间").contains(s)) {
for (String s1 : Arrays.asList("日期", "时间")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("患者姓名","患者").contains(s)) {
for (String s1 : Arrays.asList("患者姓名","患者")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("病历号").contains(s)) {
for (String s1 : Arrays.asList("病历号")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("入院日期").contains(s)) {
for (String s1 : Arrays.asList("入院日期")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("出生日期").contains(s)) {
for (String s1 : Arrays.asList("出生日期")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else if (Arrays.asList("年龄").contains(s)) {
for (String s1 : Arrays.asList("年龄")) {
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
if (CollectionUtils.isNotEmpty(semantic_result)) {
jsonArray.addAll(semantic_result);
break;
}
}
}else{
jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s);
}
if (jsonArray != null && jsonArray.size() > 0) {
ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
}
}
if (ocrArray.size() > 0) {
for (JSONObject ocrItem : ocrArray) {
text = ocrItem.getString("text");//ocr 识别的文本
probability = ocrItem.getDouble("probability");//置信度
double v = StrCharUtil.similarityRatio(inputText, text);
this.ocrResultAddV01(ocrResultDTOList, checkSemanticModel.getFieldName(), field, inputText, text, probability, imgPath, checkSemanticModel.getFieldName() + "参数未获取到结果", false,v);
}
}
}
}
Date overDataCheckTime = new Date();
JSONObject responseBody=new JSONObject();
//OCR和NlU执行时间总和
double ocrAndNluTimeSum = identifyDetailList.stream().mapToDouble(i -> (i.getOcrTime() == null ? 0 : i.getOcrTime()) + (i.getNluTime() == null ? 0 : i.getNluTime())).sum();
//执行时间(毫秒)
double dataStructuredTime = new BigDecimal(overDataCheckTime.getTime() - startDataCheckTime.getTime()).setScale(2, RoundingMode.HALF_UP).doubleValue();
double executionTime = new BigDecimal(ocrAndNluTimeSum+(dataStructuredTime/1000)).setScale(2, RoundingMode.HALF_UP).doubleValue();
responseBody.put("dataStructuredTime",dataStructuredTime);
responseBody.put("allExecutionTime",executionTime);
//=========排序
if (CollectionUtils.isNotEmpty(ocrResultDTOList)) {
ocrResultDTOList.sort((h1, h2) -> h1.getTag().compareTo(h2.getTag()));
}
//============
if (CollectionUtils.isEmpty(ocrResultDTOList)) {
//没有匹配结果
responseBody.put("taskResult",1);
}else{
long count = fieldRightMap.values().stream().filter(o->!o).count();
//long count = ocrResultDTOList.stream().filter(o -> !o.getRuleValidation()).count();
responseBody.put("taskResult",count>0?0:1);//匹配成功或失败
Set<String> haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getTextRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toSet());
List<OcrResultDTO> newResultDTOList=new ArrayList<>();
//过滤掉0的值
for (OcrResultDTO o : ocrResultDTOList) {
if (haveRateTagList.contains(o.getTag())) {
if (o.getTextRate()>0) {
newResultDTOList.add(o);
}
}else{
newResultDTOList.add(o);
}
//脱敏处理
String tagName = o.getTagName();
String ocrText = o.getOcrText();
StringBuilder sb = new StringBuilder();
if ("患者姓名".equals(tagName)) {
// 保留第一个字,其余用 "*" 替代
int length = Math.max(0, ocrText.length() - 1);
for (int i = 0; i < length; i++) {
sb.append("*");
}
String desensitizedText = ocrText.substring(0, 1) + sb.toString();
o.setOcrText(desensitizedText);
}
if ("联系方式".equals(tagName) || "身份证号".equals(tagName)){
String desensitizedText = desensitizeText(ocrText); // 自定义的脱敏方法
// 更新脱敏后的值
o.setOcrText(desensitizedText);
}
if ("家庭住址".equals(tagName) || "工作地址".equals(tagName) || "病情陈述人".equals(tagName)
|| "户籍地".equals(tagName)){
sb.append(ocrText.charAt(0));
for (int i = 1; i < ocrText.length() - 1; i++) {
sb.append("*");
}
sb.append(ocrText.charAt(ocrText.length() - 1));
String desensitizedText= sb.toString();
o.setOcrText(desensitizedText);
}
}
ocrResultDTOList = newResultDTOList;
}
//获取最小
double min = 0d;
//获取最大
double max = 0d;
if (CollectionUtils.isNotEmpty(ocrResultDTOList)) {
min = ocrResultDTOList.stream().mapToDouble(OcrResultDTO::getTextRate).min().getAsDouble();
max = ocrResultDTOList.stream().mapToDouble(OcrResultDTO::getTextRate).max().getAsDouble();
}
responseBody.put("min",min);
responseBody.put("max",max);
responseBody.put("detailList", ocrResultDTOList);
return responseBody;
}
private Map<String, CheckSemanticModel> getCheckSemanticModelMapV0(String configRule, Map<String, String> fieldMap, List<JSONObject> sourceJson) {
if (configRule!=null) {
String[] split = configRule.split("&");
//将 configRuleMap的 key 创建一个Set
// Set<String> keySet = new HashSet<>(configRuleMap.keySet());
// //循环keySet判断字段是否是缩写如果是缩写就把缩写的全称put一下
// for (String s : keySet) {
// String value = configRuleMap.get(s);
// if ("hn".equals(s)) {
// configRuleMap.put("hospitalName",value);
// }else if("dn".equals(s)) {
// configRuleMap.put("doctorName", value);
// }else if("dmn".equals(s)) {
// configRuleMap.put("departmentName", value);
// }else if("tm".equals(s) || ("time".equals(s))) {
// configRuleMap.put("time", value);
// }else{
// configRuleMap.put(s,value);
// }
// }
}
Map<String, CheckSemanticModel> checkSemanticModelMap = new LinkedHashMap<>();
//校验正确的值
Map<String, String> inputMap = new LinkedHashMap<>();
if (sourceJson != null && sourceJson.size() > 0) {
String tag, inputText;
for (JSONObject sourceJsonObject : sourceJson) {
tag = sourceJsonObject.getString("tag");
if (StringUtils.isBlank(tag)) {
continue;
}
inputText = sourceJsonObject.getString("inputText");
inputMap.put(tag, inputText);
}
}
CheckSemanticModel copyEntity = null;
String fieldName = null, inputText;
//判断 规则检查配置 是不是 isrule=1
if (configRule.contains("isrule==1")) {
//isrule=1
for (String field : inputMap.keySet()) {
fieldName = fieldMap.get(field);
copyEntity = new CheckSemanticModel();
inputText = inputMap.get(field);
copyEntity.setField(field);
copyEntity.setInputText(inputText);
copyEntity.setRuleInfo("1");
copyEntity.setFieldName(fieldName);
checkSemanticModelMap.put(field, copyEntity);
}
} else {
if (fieldMap != null) {
for (String field : fieldMap.keySet()) {
copyEntity = new CheckSemanticModel();
copyEntity.setField(field);
//1/0
// if (configRuleMap != null && configRuleMap.containsKey(field)) {
// configRule = configRuleMap.get(field);
// copyEntity.setRuleInfo(configRule);
// //端字段含义
// fieldName = fieldMap.get(field);
// //检查数据
// inputText = inputMap.get(field);
//
// copyEntity.setFieldName(fieldName);
//
// copyEntity.setInputText(inputText);
//
// checkSemanticModelMap.put(field, copyEntity);
// }
}
}
}
return checkSemanticModelMap;
}
// 自定义的脱敏方法,对字段进行半脱敏
private String desensitizeText(String text) {
StringBuilder sb = new StringBuilder(text);
if (text == null) {
return text;
}else if (text.length() == 11){ //手机号脱敏
for (int i = 3; i < sb.length() - 4; i++) {
sb.setCharAt(i, '*');
}
return sb.toString();
}else if(text.length() == 14){ //身份证号码脱敏
for (int i = 3; i < sb.length() - 4; i++) {
sb.setCharAt(i, '*');
}
}else{
sb.append(text.charAt(0));
for (int i = 1; i < text.length() - 1; i++) {
sb.append("*");
}
sb.append(text.charAt(text.length() - 1));
return sb.toString();
}
return text;
}
@Transactional(rollbackFor = Exception.class)
public void executeTask() {
//获取任务
@ -1115,4 +1629,28 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
return taskList;
}
@Override
public long calculateTimeDifferenceByRequestId(String requestId) {
LambdaQueryWrapper<OcrIdentify> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(OcrIdentify::getRequestId, requestId).orderByDesc(OcrIdentify::getCreateTime).last("LIMIT 1");
OcrIdentify lastIdentify = this.getOne(queryWrapper);
if (lastIdentify != null) {
Date lastCreateTime = lastIdentify.getCreateTime();
Date currentTime = new Date();
return (currentTime.getTime() - lastCreateTime.getTime()) / 1000;
}
return 11; // 如果没有找到数据,返回默认值
}
@Override
public long calculateTimeDifferenceByTaskName(String taskName) {
LambdaQueryWrapper<OcrIdentify> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(OcrIdentify::getTaskName,taskName).orderByDesc(OcrIdentify::getCreateTime).last("LIMIT 1");
OcrIdentify lastIdentify = this.getOne(queryWrapper);
if (lastIdentify != null) {
Date lastCreateTime = lastIdentify.getCreateTime();
Date currentTime = new Date();
return (currentTime.getTime() - lastCreateTime.getTime()) / 1000;
}
return 11; // 如果没有找到数据,返回默认值
}
}

@ -1,5 +1,6 @@
package org.jeecg.modules.ocr.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -18,13 +19,16 @@ import org.jeecg.modules.ocr.mapper.OcrRuleCheckMapper;
import org.jeecg.modules.ocr.service.IOcrRuleCheckDetailService;
import org.jeecg.modules.ocr.service.IOcrRuleCheckService;
import org.jeecg.modules.ocr.vo.SaveOcrRuleCheckVO;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@ -96,6 +100,88 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, Ocr
}
return true;
}
public static void configRuleAdapter(@NotNull StringBuffer configRule, String split, StringBuffer rest){
String[] configRuleList=configRule.toString().split(split);
List<StringBuffer> list=new ArrayList<>();
for(int i=0;i<configRuleList.length;i++){
list.add(new StringBuffer(configRuleList[i]));
}
String splitAdapter="";
String nextSplit="";
if(split.equals("&")){
splitAdapter="&&";
nextSplit="\\|";
}else if(split.equals("\\|")){
splitAdapter="||";
nextSplit="&";
}
for(StringBuffer sb:list){
if(isExpression(sb.toString())){
configRuleAdapter(sb,nextSplit,rest);
}else{
if (sb.toString().contains("hn")) {
String str=sb.toString().replaceAll("hn","hospitalName");
sb.setLength(0);
sb.append(str);
}else if(sb.toString().contains("dn")) {
String str=sb.toString().replaceAll("dn","doctorName");
sb.setLength(0);
sb.append(str);
}else if(sb.toString().contains("dmn")) {
String str=sb.toString().replaceAll("dmn","departmentName");
sb.setLength(0);
sb.append(str);
}else if(sb.toString().contains("tm")) {
String str=sb.toString().replaceAll("tm","time");
sb.setLength(0);
sb.append(str);
}
}
}
rest.append(String.join(splitAdapter, configRuleList));
}
@Override
public OcrRuleCheckDTO findByIdV01(String ruleCheckId) {
OcrRuleCheckDTO ocrRuleCheckVo = baseMapper.findById(ruleCheckId);
AssertUtils.notNull(ocrRuleCheckVo,ruleCheckId+"-规则检查配置不存在");
if (StringUtils.isNotBlank(ocrRuleCheckVo.getConfigRule())) {
String configRule = ocrRuleCheckVo.getConfigRule();
if (configRule!=null) {
// if(isExpression(configRule)){
// String[] split = configRule.split("&");
// for()
// }
//将 configRuleMap的 key 创建一个Set
// Set<String> keySet = new HashSet<>(configRuleMap.keySet());
// //循环keySet判断字段是否是缩写如果是缩写就把缩写的全称put一下
// for (String s : keySet) {
// String value = configRuleMap.get(s);
// if ("hn".equals(s)) {
// configRuleMap.put("hospitalName",value);
// }else if("dn".equals(s)) {
// configRuleMap.put("doctorName", value);
// }else if("dmn".equals(s)) {
// configRuleMap.put("departmentName", value);
// }else if("tm".equals(s) || ("time".equals(s))) {
// configRuleMap.put("time", value);
// }else{
// configRuleMap.put(s,value);
// }
// }
}
//hn=40&&(dmn=0||dn=0)
}
if (StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) {
String metadataConfigId = ocrRuleCheckVo.getMetadataConfigId();
List<OcrMetadataConfigDetail> ocrMetadataConfigDetails = ocrMetadataConfigDetailMapper.selectList(new LambdaQueryWrapper<OcrMetadataConfigDetail>().eq(OcrMetadataConfigDetail::getMetadataConfigId, metadataConfigId));
Map<String,String> fieldMap=new LinkedHashMap<>();
for (OcrMetadataConfigDetail ocrMetadataConfigDetail : ocrMetadataConfigDetails) {
fieldMap.put(ocrMetadataConfigDetail.getFieldName(),ocrMetadataConfigDetail.getGetField());
}
ocrRuleCheckVo.setFieldMap(fieldMap);
}
return ocrRuleCheckVo;
}
@Override
public OcrRuleCheck updateModel(SaveOcrRuleCheckVO saveOcrRuleCheckVO) {
@ -148,6 +234,99 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, Ocr
params.put("configRule",ocrRuleCheck.getConfigRule());
return baseMapper.pageVo(page,params);
}
public static String excludeSymbols(String str){
return str.replaceAll("\\(","").replaceAll("\\)","")
.replaceAll("!","")
.replaceAll("<=","")
.replaceAll(">=","")
.replaceAll(">","")
.replaceAll("<","")
.replaceAll("=","");
}
public static boolean compare(char cur, char peek) {// 如果是peek优先级高于cur返回true默认都是peek优先级要低
int[] operatPriority = new int[] { 0, 3, 2, 1, -1, 1, 0, 2 };
boolean result = false;
System.out.println(peek+cur);
if (operatPriority[(peek) - 40] >= operatPriority[(cur) - 40]) {
result = true;
}
return result;
}
public static void main(String[] args) throws ScriptException {
String str="((hn=40)&((dmn=0&tm=2)|dn=0))";
StringBuffer sb=new StringBuffer();
System.out.println(str);
configRuleAdapter(new StringBuffer(str),"&",sb);
System.out.println(sb);
}
static boolean isMatch(String s){
//定义左右括号的对应关系
Map<Character,Character> bracket = new HashMap<>();
bracket.put(')','(');
bracket.put(']','[');
bracket.put('}','{');
Stack stack = new Stack();
for(int i = 0; i < s.length(); i++){
Character temp = s.charAt(i);//先转换成字符
//是否为左括号
if(bracket.containsValue(temp)){
stack.push(temp);
//是否为右括号
}else if(bracket.containsKey(temp)){
if(stack.isEmpty()){
return false;
}
//若左右括号匹配
if(stack.peek() == bracket.get(temp)){
stack.pop();
}
else{
return false;
}
}
}
return stack.isEmpty()? true: false;
}
public static String replaceFunctionStr(String text){
return text.replaceAll("hn","H").replaceAll("dmn","D").replaceAll("dn","N").replaceAll("&","K").replaceAll("\\|","L");
}
public static String zkh="(",ykh=")",hz="||",bq="&",dy="=",th="!";
public static int strNumber(String zf,String str){
int oldCount=str.length();
int newCount=str.replace(zf,"").length();
return oldCount-newCount/zf.length();
}
public static boolean isOperator(char c){
return c == '(' || c == ')';
}
public static boolean isExpression(String op){
return op.contains("&")||op.contains("|");
}
public static boolean isFlagOp(String op){
return op.contains(">")||op.contains("<")||op.contains("!=");
}
public static boolean isExpressOp(String op){
return op.equals("H")||op.equals("D")||op.equals("N")||op.equals("O");
}
public static boolean isOtherOp(String op){
return op.equals(",");
}
public static boolean isNumber(String op){
return op.matches("\\d+(\\.\\d+)?");
}
public static boolean isString(String op){
return op.matches("[\\u4e00-\\u9fa50-9a-zA-Z-]{1,}$");
}
public static int priority(String op){
if(op.equals("*")||op.equals("/")||isFlagOp(op)||isExpressOp(op)){
return 1;
}else if(op.equals("+")||op.equals("-")){
return 0;
}
return -1;
}
@Override
public OcrRuleCheckDTO findById(String id) {
@ -200,14 +379,4 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, Ocr
return ocrRuleCheckVo;
}
public static void main(String[] args) {
String text="hospitalName=1||doctorName=0";
String[] split = text.split("||");
for (String s : split) {
s=s.replace("(","");
}
}
}

@ -27,34 +27,52 @@ import java.util.List;
@Slf4j
public class CallBackWlyUtils {
public static boolean callbackWly(OcrIdentify ocrIdentify, List<OcrIdentifyDetail> identifyDetails) {
public static boolean callbackWly(String url,OcrIdentify ocrIdentify, List<OcrIdentifyDetail> identifyDetails) {
String requestId = ocrIdentify.getRequestId();
log.info("数据准备:{}",requestId);
//请求对象
CallBackWlyResult result = new CallBackWlyResult();
List<JSONObject> jsonObjects = new ArrayList<>();
//成功率
BigDecimal textRateBigd = new BigDecimal(0);
List<JSONObject> jsonObjects=new ArrayList<>();
//总明细数量
int detail_detailCount = 0;
int detailValidationCount=0;
BigDecimal imageTagRetrievePercentage = new BigDecimal("0");//成功率
String taskResultInfo = ocrIdentify.getTaskResultInfo();
if (StringUtils.isNotBlank(taskResultInfo)) {
//循环获取哪些字段通过了
List<JSONObject> taskResultInfoList = JSONArray.parseArray(taskResultInfo).toJavaList(JSONObject.class);
// detail_detailCount=taskResultInfoList.size();
// for (JSONObject jsonObject : taskResultInfoList) {
// Boolean ruleValidation = (Boolean) jsonObject.getOrDefault("ruleValidation", false);
// if (ruleValidation) {
// //通过了,
// detailValidationCount++;
// }
// }
for (JSONObject jsonObject : taskResultInfoList) {
Double ruleValidation = jsonObject.getDouble("textRate");
if (ruleValidation!=null) {
imageTagRetrievePercentage=imageTagRetrievePercentage.add(new BigDecimal(ruleValidation));
detailValidationCount++;
}
}
}
for (OcrIdentifyDetail identifyDetail : identifyDetails) {
if (StringUtils.isNotBlank(identifyDetail.getDataStructured())) {
List<JSONObject> jsonObjects1 = JSONArray.parseArray(identifyDetail.getDataStructured()).toJavaList(JSONObject.class);
if (CollectionUtils.isNotEmpty(jsonObjects1)) {
double textRate = jsonObjects.stream().mapToDouble(o->o.getDouble("textRate")).sum();
textRateBigd = textRateBigd.add(new BigDecimal(textRate));
detail_detailCount += jsonObjects1.size();
jsonObjects.addAll(jsonObjects1);
}
}
}
//组装回调参数
double imageTagRetrievePercentage = 0.0d;
if (detail_detailCount > 0) {
BigDecimal divide = textRateBigd.divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP);
imageTagRetrievePercentage = divide.doubleValue();
}
imageTagRetrievePercentage = imageTagRetrievePercentage.divide(new BigDecimal(detailValidationCount), 2, RoundingMode.HALF_UP);
if (StringUtils.isNotBlank(ocrIdentify.getTaskResult()) && "1".equals(ocrIdentify.getTaskResult())) {
result.setRuleValidation(true);
}else{
@ -64,6 +82,7 @@ public class CallBackWlyUtils {
result.setRetrieveReviewCompliance(imageTagRetrievePercentage+"");
result.setFailureReason(ocrIdentify.getErrorMsg());
if (CollectionUtils.isEmpty(jsonObjects)) {
log.info("结果为空不给无量云推送:{}",jsonObjects);
return false;
}
result.setOcrResult(jsonObjects);
@ -77,7 +96,7 @@ public class CallBackWlyUtils {
System.out.println("=============================================");
System.out.println(JSONObject.toJSONString(callBackWlyRequestBody));
System.out.println("=============================================");
semanticResponseJson = RestUtil.post("https://192.168.1.100:8894/api/task/image/ocr/callback", JSONObject.parseObject(JSONObject.toJSONString(callBackWlyRequestBody, SerializerFeature.WriteNullStringAsEmpty)));
semanticResponseJson = RestUtil.post(url, JSONObject.parseObject(JSONObject.toJSONString(callBackWlyRequestBody, SerializerFeature.WriteNullStringAsEmpty)));
} catch (org.springframework.web.client.ResourceAccessException e) {
log.error("请求无量云回调接口失败-拒绝连接 (Connection refused)");
log.error(e.getMessage());
@ -95,4 +114,52 @@ public class CallBackWlyUtils {
}
}
}
public static boolean callbackWly2(OcrIdentify ocrIdentify, List<OcrIdentifyDetail> identifyDetails) {
String requestId = ocrIdentify.getRequestId();
//请求对象
CallBackWlyResult result = new CallBackWlyResult();
List<JSONObject> jsonObjects = new ArrayList<>();
//成功率
BigDecimal textRateBigd = new BigDecimal(0);
//总明细数量
int detail_detailCount = 0;
for (OcrIdentifyDetail identifyDetail : identifyDetails) {
if (StringUtils.isNotBlank(identifyDetail.getDataStructured())) {
List<JSONObject> jsonObjects1 = JSONArray.parseArray(identifyDetail.getDataStructured()).toJavaList(JSONObject.class);
if (CollectionUtils.isNotEmpty(jsonObjects1)) {
double textRate = jsonObjects.stream().mapToDouble(o->o.getDouble("textRate")).sum();
textRateBigd = textRateBigd.add(new BigDecimal(textRate));
detail_detailCount += jsonObjects1.size();
jsonObjects.addAll(jsonObjects1);
}
}
}
//组装回调参数
double imageTagRetrievePercentage = 0.0d;
if (detail_detailCount > 0) {
BigDecimal divide = textRateBigd.divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP);
imageTagRetrievePercentage = divide.doubleValue();
}
if (StringUtils.isNotBlank(ocrIdentify.getTaskResult()) && "1".equals(ocrIdentify.getTaskResult())) {
result.setRuleValidation(true);
}else{
result.setRuleValidation(false);
}
result.setImageTagRetrievePercentage(imageTagRetrievePercentage + "");
result.setRetrieveReviewCompliance(imageTagRetrievePercentage+"");
result.setFailureReason(ocrIdentify.getErrorMsg());
if (CollectionUtils.isEmpty(jsonObjects)) {
return false;
}
result.setOcrResult(jsonObjects);
log.info("请求无量云回调接口");
JSONObject semanticResponseJson = null;
return false;
}
}

@ -51,6 +51,8 @@ public class CommonController {
*/
@Value(value="${jeecg.uploadType}")
private String uploadType;
@Value("${system.project.fileReviewUrlPrefix}")
private String fileReviewUrlPrefix;
/**
* @Author
@ -120,7 +122,7 @@ public class CommonController {
if(oConvertUtils.isNotEmpty(savePath)){
/*result.setMessage(savePath);
result.setSuccess(true);*/
return Result.OK(savePath, OcrConstant.FILE_REVIEW_URL_PREFIX+uploadpath+"/"+savePath);
return Result.OK(savePath, fileReviewUrlPrefix+uploadpath+"/"+savePath);
}else {
result.setMessage("上传失败!");
result.setSuccess(false);

@ -84,10 +84,13 @@ public class RandImageUtil {
}
private static BufferedImage getImageBuffer(String resultCode){
System.out.println("验证码:"+resultCode);
// 在内存中创建图象
final BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
System.out.println("image"+image);
// 获取图形上下文
final Graphics2D graphics = (Graphics2D) image.getGraphics();
System.out.println("image11111111111 "+graphics);
// 设定背景颜色
// ---1
graphics.setColor(Color.WHITE);
@ -119,6 +122,9 @@ public class RandImageUtil {
// 设置字体样式
// graphics.setFont(new Font("Arial Black", Font.ITALIC, 18));
graphics.setFont(new Font("Times New Roman", Font.BOLD, 24));
System.out.println("resultCode"+resultCode);
System.out.println("resultCode i"+i);
System.out.println("resultCode"+String.valueOf(resultCode.charAt(i)));
// 设置字符,字符间距,上边距
graphics.drawString(String.valueOf(resultCode.charAt(i)), (23 * i) + 8, 26);
}

@ -299,4 +299,6 @@ third-app:
system:
project:
env: customer_test
enableHandleTask: false
enableHandleTask: true
fileReviewUrlPrefix: http://47.103.213.109:8072/files
wlyCallback: https://hyycsozs.prevailcloud.com/api/task/image/ocr/callback

@ -1,5 +1,5 @@
server:
port: 8080
port: 8020
tomcat:
max-swallow-size: -1
error:
@ -7,7 +7,7 @@ server:
include-stacktrace: ALWAYS
include-message: ALWAYS
servlet:
context-path: /jeecg-boot
context-path: /ocr
compression:
enabled: true
min-response-size: 1024
@ -26,7 +26,7 @@ spring:
max-request-size: 10MB
mail:
host: smtp.163.com
username: ??
username: jeecgos@163.com
password: ??
properties:
mail:
@ -111,14 +111,14 @@ spring:
# 初始化大小,最小,最大
initial-size: 5
min-idle: 5
maxActive: 1000
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
validationQuery: SELECT 1
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
@ -131,10 +131,14 @@ spring:
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
master:
url: jdbc:mysql://127.0.0.1:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
url: jdbc:mysql://127.0.0.1:3306/ocr?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
password: root
password: stqpvqk/.6:H
driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://127.0.0.1:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
# username: root
# password: root
# driver-class-name: com.mysql.cj.jdbc.Driver
# 多数据源配置
#multi-datasource1:
#url: jdbc:mysql://localhost:3306/jeecg-boot2?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
@ -143,8 +147,9 @@ spring:
#driver-class-name: com.mysql.cj.jdbc.Driver
#redis 配置
redis:
database: 0
database: 3
host: 127.0.0.1
# host: 47.103.213.109
port: 6379
password: ''
#mybatis plus 设置
@ -173,31 +178,30 @@ jeecg:
signatureSecret: dd05f1c54d63749eda95f9fa6d49v442a
# 签名拦截接口
signUrls: /sys/dict/getDictItems/*,/sys/dict/loadDict/*,/sys/dict/loadDictOrderByValue/*,/sys/dict/loadDictItem/*,/sys/dict/loadTreeData,/sys/api/queryTableDictItemsByCode,/sys/api/queryFilterTableDictInfo,/sys/api/queryTableDictByKeys,/sys/api/translateDictFromTable,/sys/api/translateDictFromTableByKeys
#local\minio\alioss
uploadType: alioss
#local、minio、alioss
uploadType: local
# 前端访问地址
domainUrl:
pc: http://localhost:3100
app: http://localhost:8051
path:
#文件上传根目录 设置
upload: /data/ocr/upload
upload: /data/ocr/upFiles
#webapp文件路径
webapp: /opt/jeecg-boot/webapp
webapp: /opt/webapp
shiro:
excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/api/getUserInfo
excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**
#阿里云oss存储和大鱼短信秘钥配置
oss:
accessKey: ??
secretKey: ??
endpoint: oss-cn-beijing.aliyuncs.com
bucketName: jeecgdev
staticDomain: https://static.jeecg.com
# ElasticSearch 设置
# ElasticSearch 6设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 127.0.0.1:9200
check-enabled: true
check-enabled: false
# 在线预览文件服务器地址配置
file-view-domain: http://fileview.jeecg.com
# minio文件上传
@ -208,17 +212,9 @@ jeecg:
bucketName: otatest
#大屏报表参数设置
jmreport:
mode: prod
mode: dev
#数据字典是否进行saas数据隔离自己看自己的字典
saas: false
#是否开启租户模式 Support By v1.5.5+
openTenant: false
#安全模式(敏感接口校验、saas模式下不允许使用平台数据源)
#safeMode: true
#是否需要校验token
is_verify_token: true
#必须校验方法
verify_methods: remove,delete,save,add,update
#xxl-job配置
xxljob:
enabled: false
@ -250,7 +246,7 @@ knife4j:
#开启生产环境屏蔽
production: false
basic:
enable: true
enable: false
username: jeecg
password: jeecg1314
#第三方登录
@ -303,4 +299,7 @@ third-app:
agent-id: ??
system:
project:
env: customer_prod
env: customer_test
enableHandleTask: true
fileReviewUrlPrefix: http://localhost:8071/files
wlyCallback: https://hyycsozs.prevailcloud.com/api/task/image/ocr/callback

@ -131,7 +131,7 @@ spring:
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
master:
url: jdbc:mysql://47.103.213.109:3306/ocr?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
url: jdbc:mysql://127.0.0.1:3306/ocr?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
password: Wang5322570..
driver-class-name: com.mysql.cj.jdbc.Driver
@ -148,8 +148,8 @@ spring:
#redis 配置
redis:
database: 3
#host: 127.0.0.1
host: 47.103.213.109
host: 127.0.0.1
# host: 47.103.213.109
port: 6379
password: ''
#mybatis plus 设置
@ -300,4 +300,5 @@ third-app:
system:
project:
env: customer_test
enableHandleTask: true
enableHandleTask: true
fileReviewUrlPrefix: http://172.16.0.132:8071/files

@ -3,4 +3,4 @@ spring:
name: jeecg-system
profiles:
# active: '@profile.name@'
active: dev
active: prod
Loading…
Cancel
Save