修改ocr日志
This commit is contained in:
+11
-12
@@ -19,10 +19,9 @@ import com.jero.modules.oss.entity.OSSFile;
|
|||||||
import com.jero.modules.oss.service.IOSSFileService;
|
import com.jero.modules.oss.service.IOSSFileService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
@@ -51,8 +50,8 @@ import java.util.Objects;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/laws/ocr/OCRRestful")
|
@RequestMapping("/laws/ocr/OCRRestful")
|
||||||
@Api(tags = "OCR识别")
|
@Api(tags = "OCR识别")
|
||||||
|
@Slf4j
|
||||||
public class OCRRestfulController extends BaseController<OcrRecordEO> {
|
public class OCRRestfulController extends BaseController<OcrRecordEO> {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(OCRRestfulController.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OCRRestfulService ocrRestfulService;
|
private OCRRestfulService ocrRestfulService;
|
||||||
@@ -74,7 +73,7 @@ public class OCRRestfulController extends BaseController<OcrRecordEO> {
|
|||||||
@PostMapping(value="/upload",consumes="multipart/*",headers="content-type=multipart/form-data" )
|
@PostMapping(value="/upload",consumes="multipart/*",headers="content-type=multipart/form-data" )
|
||||||
public ResponseMessage<String> handleFile(@RequestParam("file") MultipartFile file) throws Exception {
|
public ResponseMessage<String> handleFile(@RequestParam("file") MultipartFile file) throws Exception {
|
||||||
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
||||||
logger.info("收到文件上传请求,开始处理文件:【"+sdf.format(new Date())+"】");
|
log.info("收到文件上传请求,开始处理文件:【"+sdf.format(new Date())+"】");
|
||||||
return ocrRestfulService.handleFile(file,file.getOriginalFilename(),null,"add");
|
return ocrRestfulService.handleFile(file,file.getOriginalFilename(),null,"add");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,11 +81,11 @@ public class OCRRestfulController extends BaseController<OcrRecordEO> {
|
|||||||
@PostMapping("/OcrHandleResult")
|
@PostMapping("/OcrHandleResult")
|
||||||
public String OcrHandleResult(@RequestParam("wordFile") MultipartFile wordFile,@RequestParam("jsonFile") MultipartFile jsonFile, OcrCallBackResultEo ocrCallBackResultEo) {
|
public String OcrHandleResult(@RequestParam("wordFile") MultipartFile wordFile,@RequestParam("jsonFile") MultipartFile jsonFile, OcrCallBackResultEo ocrCallBackResultEo) {
|
||||||
try{
|
try{
|
||||||
logger.info("调取到我了");
|
log.info("调取到我了");
|
||||||
logger.info("接口回调结果:"+ JSON.toJSONString(ocrCallBackResultEo));
|
log.info("接口回调结果:"+ JSON.toJSONString(ocrCallBackResultEo));
|
||||||
logger.info("接口回调时所传文件---wordFile:"+ wordFile.toString() +"; jsonFile:"+jsonFile.toString());
|
log.info("接口回调时所传文件---wordFile:"+ wordFile.toString() +"; jsonFile:"+jsonFile.toString());
|
||||||
if("error".equals(ocrCallBackResultEo.getResult())){
|
if("error".equals(ocrCallBackResultEo.getResult())){
|
||||||
logger.info("客户接口处理文件失败");
|
log.info("客户接口处理文件失败");
|
||||||
ocrRestfulService.updateDb(ocrCallBackResultEo.getTaskID(),"客户接口处理文件失败");
|
ocrRestfulService.updateDb(ocrCallBackResultEo.getTaskID(),"客户接口处理文件失败");
|
||||||
return "{\"result\":\"error\"}";
|
return "{\"result\":\"error\"}";
|
||||||
}
|
}
|
||||||
@@ -97,13 +96,13 @@ public class OCRRestfulController extends BaseController<OcrRecordEO> {
|
|||||||
String signMD5 = MD5Util.string2MD5(sign);
|
String signMD5 = MD5Util.string2MD5(sign);
|
||||||
if(!signMD5.equals(key)){
|
if(!signMD5.equals(key)){
|
||||||
//不同,则认证失败
|
//不同,则认证失败
|
||||||
logger.info("认证失败");
|
log.info("认证失败");
|
||||||
ocrRestfulService.updateDb(ocrCallBackResultEo.getTaskID(),"回调接口认证失败");
|
ocrRestfulService.updateDb(ocrCallBackResultEo.getTaskID(),"回调接口认证失败");
|
||||||
return "{\"result\":\"Authentication failed\"}";
|
return "{\"result\":\"Authentication failed\"}";
|
||||||
}
|
}
|
||||||
return ocrRestfulService.OcrHandleResult(wordFile,jsonFile,ocrCallBackResultEo.getTaskID());
|
return ocrRestfulService.OcrHandleResult(wordFile,jsonFile,ocrCallBackResultEo.getTaskID());
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
logger.error(e.getMessage(),e);
|
log.error(e.getMessage(),e);
|
||||||
return "{\"result\":\"runTimeException\"}";
|
return "{\"result\":\"runTimeException\"}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +132,7 @@ public class OCRRestfulController extends BaseController<OcrRecordEO> {
|
|||||||
@PostMapping("/addOcrRecord")
|
@PostMapping("/addOcrRecord")
|
||||||
public ResponseMessage<OcrRecordEO> addOcrRecord(@RequestBody OcrRecordEO ocrRecordEO) throws Exception {
|
public ResponseMessage<OcrRecordEO> addOcrRecord(@RequestBody OcrRecordEO ocrRecordEO) throws Exception {
|
||||||
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
||||||
logger.info("收到文件上传请求,开始处理文件:【"+sdf.format(new Date())+"】");
|
log.info("收到文件上传请求,开始处理文件:【"+sdf.format(new Date())+"】");
|
||||||
// 根据attID查找文件
|
// 根据attID查找文件
|
||||||
String fileId = ocrRecordEO.getAttId();
|
String fileId = ocrRecordEO.getAttId();
|
||||||
OSSFile ossFile = ossFileService.getById(fileId);
|
OSSFile ossFile = ossFileService.getById(fileId);
|
||||||
@@ -156,7 +155,7 @@ public class OCRRestfulController extends BaseController<OcrRecordEO> {
|
|||||||
return Result.success("0","保存成功",ocrRecordEO);
|
return Result.success("0","保存成功",ocrRecordEO);
|
||||||
} else {
|
} else {
|
||||||
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
||||||
logger.info("收到文件上传请求,开始处理文件:【"+sdf.format(new Date())+"】");
|
log.info("收到文件上传请求,开始处理文件:【"+sdf.format(new Date())+"】");
|
||||||
// 根据attID查找文件
|
// 根据attID查找文件
|
||||||
String fileId = ocrRecordEO.getAttId();
|
String fileId = ocrRecordEO.getAttId();
|
||||||
OSSFile ossFile = ossFileService.getById(fileId);
|
OSSFile ossFile = ossFileService.getById(fileId);
|
||||||
|
|||||||
+14
-13
@@ -1,5 +1,6 @@
|
|||||||
package com.jero.modules.laws.ocr.service.impl;
|
package com.jero.modules.laws.ocr.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.jero.common.system.vo.LoginUser;
|
import com.jero.common.system.vo.LoginUser;
|
||||||
import com.jero.common.util.SnowflakeUtils;
|
import com.jero.common.util.SnowflakeUtils;
|
||||||
@@ -16,10 +17,9 @@ import com.jero.modules.laws.ocr.mapper.OcrRecordEOMapper;
|
|||||||
import com.jero.modules.laws.ocr.service.OCRRestfulService;
|
import com.jero.modules.laws.ocr.service.OCRRestfulService;
|
||||||
import com.jero.modules.oss.entity.OSSFile;
|
import com.jero.modules.oss.entity.OSSFile;
|
||||||
import com.jero.modules.oss.service.IOSSFileService;
|
import com.jero.modules.oss.service.IOSSFileService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -35,9 +35,9 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
@Transactional(value = "transactionManager", readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
@Transactional(value = "transactionManager", readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
||||||
public class OCRRestfulServiceImpl implements OCRRestfulService {
|
public class OCRRestfulServiceImpl implements OCRRestfulService {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(OCRRestfulServiceImpl.class);
|
|
||||||
|
|
||||||
//请求处理客户认证码
|
//请求处理客户认证码
|
||||||
@Value("${OCR.authCode}")
|
@Value("${OCR.authCode}")
|
||||||
@@ -78,12 +78,12 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
|||||||
|
|
||||||
String authCode = RsaUtil.publicEncrypt(OcrAuthCode);
|
String authCode = RsaUtil.publicEncrypt(OcrAuthCode);
|
||||||
if(authCode == null){
|
if(authCode == null){
|
||||||
logger.error("客户认证RSA加密失败");
|
log.error("客户认证RSA加密失败");
|
||||||
return Result.error("客户认证RSA加密失败");
|
return Result.error("客户认证RSA加密失败");
|
||||||
}
|
}
|
||||||
String fileContent = Base64Util.PDFToBase64(file);
|
String fileContent = Base64Util.PDFToBase64(file);
|
||||||
if(fileContent == null || "".equals(fileContent)){
|
if(fileContent == null || "".equals(fileContent)){
|
||||||
logger.error("PDF转Base64失败");
|
log.error("PDF转Base64失败");
|
||||||
return Result.error("PDF转Base64失败");
|
return Result.error("PDF转Base64失败");
|
||||||
}
|
}
|
||||||
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
||||||
@@ -98,12 +98,13 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
|||||||
map.put("taskId",taskId);
|
map.put("taskId",taskId);
|
||||||
map.put("callBackUrl",RestCallBackUrl);
|
map.put("callBackUrl",RestCallBackUrl);
|
||||||
map.put("callBackMethod","");
|
map.put("callBackMethod","");
|
||||||
logger.info("处理完文件数据,开始请求OCR接口数据:【"+sdf.format(new Date())+"】");
|
log.info("处理完文件数据,开始请求OCR接口数据:【"+sdf.format(new Date())+"】");
|
||||||
|
log.info("提交参数:" + JSON.toJSONString(map));
|
||||||
String result = okHttpUtil.post(RestHandleFileUrl,map,new HashMap<>());
|
String result = okHttpUtil.post(RestHandleFileUrl,map,new HashMap<>());
|
||||||
logger.info("okHttp结果:"+result);
|
log.info("okHttp结果:"+result);
|
||||||
logger.info("请求OCR接口完毕,返回响应状态:【"+sdf.format(new Date())+"】");
|
log.info("请求OCR接口完毕,返回响应状态:【"+sdf.format(new Date())+"】");
|
||||||
if(!result.contains("请求成功")){
|
if(!result.contains("请求成功")){
|
||||||
logger.error("请求出现异常:"+result);
|
log.error("请求出现异常:"+result);
|
||||||
return Result.error("请求出现异常");
|
return Result.error("请求出现异常");
|
||||||
}else{
|
}else{
|
||||||
OcrResultEo ocrResultEo = JSONObject.parseObject(result, OcrResultEo.class);
|
OcrResultEo ocrResultEo = JSONObject.parseObject(result, OcrResultEo.class);
|
||||||
@@ -142,7 +143,7 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
logger.error(e.getMessage(),e);
|
log.error(e.getMessage(),e);
|
||||||
return Result.error("OCR接口请求出现异常,无法将文件传输到OCR引擎!");
|
return Result.error("OCR接口请求出现异常,无法将文件传输到OCR引擎!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,7 +160,7 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
|||||||
//首先将文件保存至本地
|
//首先将文件保存至本地
|
||||||
String wordId=null;
|
String wordId=null;
|
||||||
String jsonId=null;
|
String jsonId=null;
|
||||||
logger.info("保存文件");
|
log.info("保存文件");
|
||||||
if(wordFile!=null && !wordFile.isEmpty()){
|
if(wordFile!=null && !wordFile.isEmpty()){
|
||||||
// String wordUrl = MinioUtil.upload(wordFile, "/temp");
|
// String wordUrl = MinioUtil.upload(wordFile, "/temp");
|
||||||
String wordUrl = ObsBootUtil.upload(wordFile, "temp");
|
String wordUrl = ObsBootUtil.upload(wordFile, "temp");
|
||||||
@@ -169,7 +170,7 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
|||||||
ossFile.setUrl(wordUrl);
|
ossFile.setUrl(wordUrl);
|
||||||
ossFileService.save(ossFile);
|
ossFileService.save(ossFile);
|
||||||
wordId = ossFile.getId();
|
wordId = ossFile.getId();
|
||||||
logger.info("word存储完成");
|
log.info("word存储完成");
|
||||||
}
|
}
|
||||||
if(jsonFile!=null && !jsonFile.isEmpty()){
|
if(jsonFile!=null && !jsonFile.isEmpty()){
|
||||||
// String jsonUrl = MinioUtil.upload(jsonFile, "/temp");
|
// String jsonUrl = MinioUtil.upload(jsonFile, "/temp");
|
||||||
@@ -180,7 +181,7 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
|||||||
ossFile.setUrl(jsonUrl);
|
ossFile.setUrl(jsonUrl);
|
||||||
ossFileService.save(ossFile);
|
ossFileService.save(ossFile);
|
||||||
jsonId = ossFile.getId();
|
jsonId = ossFile.getId();
|
||||||
logger.info("Json存储完成");
|
log.info("Json存储完成");
|
||||||
}
|
}
|
||||||
//开始将文件保存至数据库中
|
//开始将文件保存至数据库中
|
||||||
if(StringUtils.isNotBlank(wordId) && StringUtils.isNotBlank(jsonId)){
|
if(StringUtils.isNotBlank(wordId) && StringUtils.isNotBlank(jsonId)){
|
||||||
|
|||||||
Reference in New Issue
Block a user