提交本地工具模块相关代码
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
package com.adc.da.ocr.controller;
|
||||
|
||||
import com.adc.da.att.entity.AttFileEO;
|
||||
import com.adc.da.att.service.IAttFileEOService;
|
||||
import com.adc.da.base.web.BaseController;
|
||||
import com.adc.da.http.PageInfo;
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.Result;
|
||||
import com.adc.da.ocr.entity.OcrCallBackResultEo;
|
||||
import com.adc.da.ocr.entity.OcrRecordEO;
|
||||
import com.adc.da.ocr.page.OcrRecordEOPage;
|
||||
import com.adc.da.ocr.service.OCRRestfulService;
|
||||
import com.adc.da.ocr.service.OcrRecordEOService;
|
||||
import com.adc.da.ocr.util.MD5Util;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.Value;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: OcrDemo
|
||||
* @description: ocr接口对接类
|
||||
* @author: duyunbao
|
||||
* @create: 2019-03-13 18:21
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${restPath}/ocr/OCRRestful")
|
||||
@Api(description = "|OCR识别 |")
|
||||
public class OCRRestfulController extends BaseController<OcrRecordEO> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OCRRestfulController.class);
|
||||
|
||||
@Autowired
|
||||
private OCRRestfulService ocrRestfulService;
|
||||
@Autowired
|
||||
private OcrRecordEOService ocrRecordEOService;
|
||||
@Autowired
|
||||
private IAttFileEOService attFileEOService;
|
||||
//接口回调公钥
|
||||
@Value("${OCR.publicKey}")
|
||||
private String OcrPublicKey;
|
||||
@Value("${OCR.ocrDownPath}")
|
||||
private String ocrDownPath;
|
||||
@Value("${file.path}")
|
||||
private String filePath;//文件存储路径
|
||||
|
||||
@ApiOperation(value = "请求ocr")
|
||||
@PostMapping(value="/upload",consumes="multipart/*",headers="content-type=multipart/form-data" )
|
||||
public ResponseMessage<String> handleFile(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
||||
logger.info("收到文件上传请求,开始处理文件:【"+sdf.format(new Date())+"】");
|
||||
return ocrRestfulService.handleFile(file,file.getOriginalFilename(),null,"add");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "ocr回调")
|
||||
@PostMapping("/OcrHandleResult")
|
||||
public String OcrHandleResult(@RequestParam("wordFile") MultipartFile wordFile,@RequestParam("jsonFile") MultipartFile jsonFile, OcrCallBackResultEo ocrCallBackResultEo) {
|
||||
try{
|
||||
logger.info("调取到我了");
|
||||
logger.info("接口回调结果:"+ JSON.toJSONString(ocrCallBackResultEo));
|
||||
logger.info("接口回调时所传文件---wordFile:"+ wordFile.toString() +"; jsonFile:"+jsonFile.toString());
|
||||
if("error".equals(ocrCallBackResultEo.getResult())){
|
||||
logger.info("客户接口处理文件失败");
|
||||
ocrRestfulService.updateDb(ocrCallBackResultEo.getTaskID(),"客户接口处理文件失败");
|
||||
return "{\"result\":\"error\"}";
|
||||
}
|
||||
//1.验证 key 是否符合,不符合打回,符合继续
|
||||
//2.向后传递文件
|
||||
String key = ocrCallBackResultEo.getKey();
|
||||
String sign = ocrCallBackResultEo.getTaskID() + OcrPublicKey;
|
||||
String signMD5 = MD5Util.string2MD5(sign);
|
||||
if(!signMD5.equals(key)){
|
||||
//不同,则认证失败
|
||||
logger.info("认证失败");
|
||||
ocrRestfulService.updateDb(ocrCallBackResultEo.getTaskID(),"回调接口认证失败");
|
||||
return "{\"result\":\"Authentication failed\"}";
|
||||
}
|
||||
return ocrRestfulService.OcrHandleResult(wordFile,jsonFile,ocrCallBackResultEo.getTaskID());
|
||||
}catch (Exception e){
|
||||
logger.error(e.getMessage(),e);
|
||||
return "{\"result\":\"runTimeException\"}";
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取所有ocr结果")
|
||||
@PostMapping("/getAllOcrResult")
|
||||
public ResponseMessage<PageInfo<OcrRecordEO>> page(OcrRecordEOPage page) throws Exception {
|
||||
if(org.apache.commons.lang3.StringUtils.isNotBlank(page.getPaixu()) && org.apache.commons.lang3.StringUtils.isNotBlank(page.getShunxu())){
|
||||
String sql = page.getPaixu()+" "+page.getShunxu();
|
||||
page.setSql(sql);
|
||||
}else{
|
||||
page.setOrderBy("creation_time");
|
||||
page.setOrder("desc");
|
||||
}
|
||||
List<OcrRecordEO> rows = ocrRecordEOService.queryByPage(page);
|
||||
DecimalFormat df = new DecimalFormat("0.00");//设置保留位数
|
||||
for (OcrRecordEO ocrRecordEO : rows){
|
||||
ocrRecordEO.setDocRealFile(ocrDownPath+ocrRecordEO.getDocRealName());
|
||||
ocrRecordEO.setJsonRealFile(ocrDownPath+ocrRecordEO.getJsonRealName());
|
||||
}
|
||||
return Result.success(getPageInfo(page.getPager(), rows));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增ocr内容")
|
||||
@PostMapping("/addOcrRecord")
|
||||
public ResponseMessage<OcrRecordEO> addOcrRecord(OcrRecordEO ocrRecordEO) throws Exception {
|
||||
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
||||
logger.info("收到文件上传请求,开始处理文件:【"+sdf.format(new Date())+"】");
|
||||
// 根据attID查找文件
|
||||
String fileId = ocrRecordEO.getAttId();
|
||||
AttFileEO attFileEO = attFileEOService.getFileInfo(fileId);
|
||||
if (attFileEO != null) {
|
||||
String fileOriPath = filePath + attFileEO.getFilePath();
|
||||
String oriName = attFileEO.getOldFileName();
|
||||
File pdfFile = new File(fileOriPath+attFileEO.getFileName());
|
||||
FileInputStream fileInputStream = new FileInputStream(pdfFile);
|
||||
MultipartFile multipartFile = new MockMultipartFile(oriName, oriName,
|
||||
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
||||
return ocrRestfulService.handleFile(multipartFile,multipartFile.getOriginalFilename(),ocrRecordEO,"add");
|
||||
} else {
|
||||
return Result.error("0","无法找到该文件",null);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改ocr内容")
|
||||
@PutMapping("/updateOcrRecord")
|
||||
public ResponseMessage<OcrRecordEO> updateOcrRecord(@RequestBody OcrRecordEO ocrRecordEO) throws Exception {
|
||||
if (StringUtils.isEmpty(ocrRecordEO.getAttId())) {
|
||||
ocrRecordEOService.updateByPrimaryKeySelective(ocrRecordEO);
|
||||
return Result.success("0","保存成功",ocrRecordEO);
|
||||
} else {
|
||||
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
||||
logger.info("收到文件上传请求,开始处理文件:【"+sdf.format(new Date())+"】");
|
||||
// 根据attID查找文件
|
||||
String fileId = ocrRecordEO.getAttId();
|
||||
AttFileEO attFileEO = attFileEOService.getFileInfo(fileId);
|
||||
if (attFileEO != null) {
|
||||
String fileOriPath = filePath + attFileEO.getFilePath();
|
||||
String oriName = attFileEO.getOldFileName();
|
||||
File pdfFile = new File(fileOriPath+attFileEO.getFileName());
|
||||
FileInputStream fileInputStream = new FileInputStream(pdfFile);
|
||||
MultipartFile multipartFile = new MockMultipartFile(oriName, oriName,
|
||||
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
||||
return ocrRestfulService.handleFile(multipartFile,multipartFile.getOriginalFilename(),ocrRecordEO,"update");
|
||||
} else {
|
||||
return Result.error("0","无法找到该文件",null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除ocr内容")
|
||||
@DeleteMapping("/deleteOcrRecord")
|
||||
public ResponseMessage deleteOcrRecord(String ids) throws Exception {
|
||||
if (StringUtils.isNotEmpty(ids)) {
|
||||
String[] idArr = ids.split(",");
|
||||
List<String> idList = Arrays.asList(idArr);
|
||||
int i = ocrRecordEOService.deleteByIds(idList);
|
||||
return Result.success("0","删除成功",i);
|
||||
} else {
|
||||
return Result.error("删除数据不能为空");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.adc.da.ocr.dao;
|
||||
|
||||
import com.adc.da.base.page.BasePage;
|
||||
import com.adc.da.ocr.entity.OcrRecordEO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* <br>
|
||||
* <b>功能:</b>OCR_RECORD OcrRecordEODao<br>
|
||||
* <b>作者:</b>code generator<br>
|
||||
* <b>日期:</b> 2019-03-25 <br>
|
||||
* <b>版权所有:<b>版权归北京卡达克数据技术中心所有。<br>
|
||||
*/
|
||||
@Mapper
|
||||
public interface OcrRecordEODao extends BaseMapper<OcrRecordEO> {
|
||||
|
||||
// List<OcrRecordEO> getAllOcrResult();
|
||||
//
|
||||
// int deleteByIds(@Param("idList") List<String> idList);
|
||||
|
||||
List<OcrRecordEO> queryByPage(BasePage var1);
|
||||
|
||||
int insertSelective(OcrRecordEO ocrRecordEO);
|
||||
|
||||
int updateByPrimaryKeySelective(OcrRecordEO ocrRecordEO);
|
||||
|
||||
int deleteByIds(@Param("idList") List<String> idList);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.adc.da.ocr.entity;
|
||||
|
||||
/**
|
||||
* @program: OcrDemo
|
||||
* @description: orc调取回调函数的参数
|
||||
* @author: duyunbao
|
||||
* @create: 2019-03-13 16:14
|
||||
*/
|
||||
public class OcrCallBackResultEo {
|
||||
|
||||
private String result ;
|
||||
private String taskID ;
|
||||
// private String wordFileName;
|
||||
// private String wordFileContent;
|
||||
// private String jsonFileName;
|
||||
// private String jsonFileContent;
|
||||
|
||||
private String key;
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getTaskID() {
|
||||
return taskID;
|
||||
}
|
||||
|
||||
public void setTaskID(String taskID) {
|
||||
this.taskID = taskID;
|
||||
}
|
||||
//
|
||||
// public String getWordFileName() {
|
||||
// return wordFileName;
|
||||
// }
|
||||
//
|
||||
// public void setWordFileName(String wordFileName) {
|
||||
// this.wordFileName = wordFileName;
|
||||
// }
|
||||
//
|
||||
// public String getWordFileContent() {
|
||||
// return wordFileContent;
|
||||
// }
|
||||
//
|
||||
// public void setWordFileContent(String wordFileContent) {
|
||||
// this.wordFileContent = wordFileContent;
|
||||
// }
|
||||
//
|
||||
// public String getJsonFileName() {
|
||||
// return jsonFileName;
|
||||
// }
|
||||
//
|
||||
// public void setJsonFileName(String jsonFileName) {
|
||||
// this.jsonFileName = jsonFileName;
|
||||
// }
|
||||
|
||||
// public String getJsonFileContent() {
|
||||
// return jsonFileContent;
|
||||
// }
|
||||
//
|
||||
// public void setJsonFileContent(String jsonFileContent) {
|
||||
// this.jsonFileContent = jsonFileContent;
|
||||
// }
|
||||
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package com.adc.da.ocr.entity;
|
||||
|
||||
import com.adc.da.base.entity.BaseEntity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <b>功能:</b>OCR_RECORD OcrRecordEOEntity<br>
|
||||
* <b>作者:</b>code generator<br>
|
||||
* <b>日期:</b> 2019-03-25 <br>
|
||||
* <b>版权所有:<b>版权归北京卡达克数据技术中心所有。<br>
|
||||
*/
|
||||
public class OcrRecordEO extends BaseEntity implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = -5464438392516276473L;
|
||||
private Object wordFileCode;
|
||||
private Object jsonFileCode;
|
||||
private String id;
|
||||
private String docRealName;
|
||||
private String jsonRealName;
|
||||
private String fileName;
|
||||
private String docName;
|
||||
private String jsonName;
|
||||
@org.springframework.format.annotation.DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date creationTime;
|
||||
@org.springframework.format.annotation.DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date modifyTime;
|
||||
|
||||
private String docRealFile;
|
||||
private String jsonRealFile;
|
||||
|
||||
//计算文件转换耗费时间
|
||||
private String spendTime;
|
||||
//转换结果
|
||||
private String resultContent;
|
||||
//新增字段
|
||||
private String fileType;
|
||||
private String standNumber;
|
||||
private String standName;
|
||||
private String creationUser;
|
||||
private String attId;
|
||||
/**
|
||||
* java字段名转换为原始数据库列名。<b>如果不存在则返回null</b><br>
|
||||
* <p>字段列表:</p>
|
||||
* <li>wordFileCode -> word_file_code</li>
|
||||
* <li>jsonFileCode -> json_file_code</li>
|
||||
* <li>id -> id</li>
|
||||
* <li>docRealName -> doc_real_name</li>
|
||||
* <li>jsonRealName -> json_real_name</li>
|
||||
* <li>fileName -> file_name</li>
|
||||
* <li>docName -> doc_name</li>
|
||||
* <li>jsonName -> json_name</li>
|
||||
* <li>creationTime -> creation_time</li>
|
||||
* <li>modifyTime -> modify_time</li>
|
||||
*/
|
||||
public static String fieldToColumn(String fieldName) {
|
||||
if (fieldName == null) return null;
|
||||
switch (fieldName) {
|
||||
case "wordFileCode": return "word_file_code";
|
||||
case "jsonFileCode": return "json_file_code";
|
||||
case "id": return "id";
|
||||
case "docRealName": return "doc_real_name";
|
||||
case "jsonRealName": return "json_real_name";
|
||||
case "fileName": return "file_name";
|
||||
case "docName": return "doc_name";
|
||||
case "jsonName": return "json_name";
|
||||
case "creationTime": return "creation_time";
|
||||
case "modifyTime": return "modify_time";
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 原始数据库列名转换为java字段名。<b>如果不存在则返回null</b><br>
|
||||
* <p>字段列表:</p>
|
||||
* <li>word_file_code -> wordFileCode</li>
|
||||
* <li>json_file_code -> jsonFileCode</li>
|
||||
* <li>id -> id</li>
|
||||
* <li>doc_real_name -> docRealName</li>
|
||||
* <li>json_real_name -> jsonRealName</li>
|
||||
* <li>file_name -> fileName</li>
|
||||
* <li>doc_name -> docName</li>
|
||||
* <li>json_name -> jsonName</li>
|
||||
* <li>creation_time -> creationTime</li>
|
||||
* <li>modify_time -> modifyTime</li>
|
||||
*/
|
||||
public static String columnToField(String columnName) {
|
||||
if (columnName == null) return null;
|
||||
switch (columnName) {
|
||||
case "word_file_code": return "wordFileCode";
|
||||
case "json_file_code": return "jsonFileCode";
|
||||
case "id": return "id";
|
||||
case "doc_real_name": return "docRealName";
|
||||
case "json_real_name": return "jsonRealName";
|
||||
case "file_name": return "fileName";
|
||||
case "doc_name": return "docName";
|
||||
case "json_name": return "jsonName";
|
||||
case "creation_time": return "creationTime";
|
||||
case "modify_time": return "modifyTime";
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** **/
|
||||
public Object getWordFileCode() {
|
||||
return this.wordFileCode;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setWordFileCode(Object wordFileCode) {
|
||||
this.wordFileCode = wordFileCode;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public Object getJsonFileCode() {
|
||||
return this.jsonFileCode;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setJsonFileCode(Object jsonFileCode) {
|
||||
this.jsonFileCode = jsonFileCode;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public String getDocRealName() {
|
||||
return this.docRealName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setDocRealName(String docRealName) {
|
||||
this.docRealName = docRealName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public String getJsonRealName() {
|
||||
return this.jsonRealName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setJsonRealName(String jsonRealName) {
|
||||
this.jsonRealName = jsonRealName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public String getDocName() {
|
||||
return this.docName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setDocName(String docName) {
|
||||
this.docName = docName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public String getJsonName() {
|
||||
return this.jsonName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setJsonName(String jsonName) {
|
||||
this.jsonName = jsonName;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public Date getCreationTime() {
|
||||
return this.creationTime;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setCreationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public Date getModifyTime() {
|
||||
return this.modifyTime;
|
||||
}
|
||||
|
||||
/** **/
|
||||
public void setModifyTime(Date modifyTime) {
|
||||
this.modifyTime = modifyTime;
|
||||
}
|
||||
|
||||
public String getDocRealFile() {
|
||||
return docRealFile;
|
||||
}
|
||||
|
||||
public void setDocRealFile(String docRealFile) {
|
||||
this.docRealFile = docRealFile;
|
||||
}
|
||||
|
||||
public String getJsonRealFile() {
|
||||
return jsonRealFile;
|
||||
}
|
||||
|
||||
public void setJsonRealFile(String jsonRealFile) {
|
||||
this.jsonRealFile = jsonRealFile;
|
||||
}
|
||||
|
||||
public String getSpendTime() {
|
||||
return spendTime;
|
||||
}
|
||||
|
||||
public void setSpendTime(String spendTime) {
|
||||
this.spendTime = spendTime;
|
||||
}
|
||||
|
||||
public String getResultContent() {
|
||||
return resultContent;
|
||||
}
|
||||
|
||||
public void setResultContent(String resultContent) {
|
||||
this.resultContent = resultContent;
|
||||
}
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public String getFileType() {
|
||||
return fileType;
|
||||
}
|
||||
|
||||
public void setFileType(String fileType) {
|
||||
this.fileType = fileType;
|
||||
}
|
||||
|
||||
public String getStandNumber() {
|
||||
return standNumber;
|
||||
}
|
||||
|
||||
public void setStandNumber(String standNumber) {
|
||||
this.standNumber = standNumber;
|
||||
}
|
||||
|
||||
public String getStandName() {
|
||||
return standName;
|
||||
}
|
||||
|
||||
public void setStandName(String standName) {
|
||||
this.standName = standName;
|
||||
}
|
||||
|
||||
public String getCreationUser() {
|
||||
return creationUser;
|
||||
}
|
||||
|
||||
public void setCreationUser(String creationUser) {
|
||||
this.creationUser = creationUser;
|
||||
}
|
||||
|
||||
public String getAttId() {
|
||||
return attId;
|
||||
}
|
||||
|
||||
public void setAttId(String attId) {
|
||||
this.attId = attId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.adc.da.ocr.entity;
|
||||
|
||||
/**
|
||||
* @program: OcrDemo
|
||||
* @description: ocr接口请求实体类
|
||||
* @author: duyunbao
|
||||
* @create: 2019-03-13 20:46
|
||||
*/
|
||||
public class OcrRequestEo {
|
||||
|
||||
private String userId;
|
||||
private String authCode;
|
||||
private String convertType;
|
||||
private String Filename;
|
||||
private String taskId;
|
||||
private String callBackUrl;
|
||||
private String callBackMethod;
|
||||
private String fileContent;
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getAuthCode() {
|
||||
return authCode;
|
||||
}
|
||||
|
||||
public void setAuthCode(String authCode) {
|
||||
this.authCode = authCode;
|
||||
}
|
||||
|
||||
public String getConvertType() {
|
||||
return convertType;
|
||||
}
|
||||
|
||||
public void setConvertType(String convertType) {
|
||||
this.convertType = convertType;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return Filename;
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
Filename = filename;
|
||||
}
|
||||
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public String getCallBackUrl() {
|
||||
return callBackUrl;
|
||||
}
|
||||
|
||||
public void setCallBackUrl(String callBackUrl) {
|
||||
this.callBackUrl = callBackUrl;
|
||||
}
|
||||
|
||||
public String getCallBackMethod() {
|
||||
return callBackMethod;
|
||||
}
|
||||
|
||||
public void setCallBackMethod(String callBackMethod) {
|
||||
this.callBackMethod = callBackMethod;
|
||||
}
|
||||
|
||||
public String getFileContent() {
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
public void setFileContent(String fileContent) {
|
||||
this.fileContent = fileContent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.adc.da.ocr.entity;
|
||||
|
||||
/**
|
||||
* @program: OcrDemo
|
||||
* @description: ocr返回结果
|
||||
* @author: duyunbao
|
||||
* @create: 2019-03-13 15:35
|
||||
*/
|
||||
public class OcrResultEo {
|
||||
|
||||
private String resultCode;
|
||||
|
||||
private String returnMessage;
|
||||
|
||||
public String getResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
public void setResultCode(String resultCode) {
|
||||
this.resultCode = resultCode;
|
||||
}
|
||||
|
||||
public String getReturnMessage() {
|
||||
return returnMessage;
|
||||
}
|
||||
|
||||
public void setReturnMessage(String returnMessage) {
|
||||
this.returnMessage = returnMessage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package com.adc.da.ocr.page;
|
||||
|
||||
import com.adc.da.base.page.BasePage;
|
||||
|
||||
/**
|
||||
* <b>功能:</b>OCR_RECORD OcrRecordEOPage<br>
|
||||
* <b>作者:</b>code generator<br>
|
||||
* <b>日期:</b> 2019-03-25 <br>
|
||||
* <b>版权所有:<b>版权归北京卡达克数据技术中心所有。<br>
|
||||
*/
|
||||
public class OcrRecordEOPage extends BasePage {
|
||||
|
||||
private String wordFileCode;
|
||||
private String wordFileCodeOperator = "=";
|
||||
private String jsonFileCode;
|
||||
private String jsonFileCodeOperator = "=";
|
||||
private String id;
|
||||
private String idOperator = "=";
|
||||
private String docRealName;
|
||||
private String docRealNameOperator = "=";
|
||||
private String jsonRealName;
|
||||
private String jsonRealNameOperator = "=";
|
||||
private String fileName;
|
||||
private String fileNameOperator = "=";
|
||||
private String docName;
|
||||
private String docNameOperator = "=";
|
||||
private String jsonName;
|
||||
private String jsonNameOperator = "=";
|
||||
private String creationTime;
|
||||
private String creationTime1;
|
||||
private String creationTime2;
|
||||
private String creationTimeOperator = "=";
|
||||
private String modifyTime;
|
||||
private String modifyTime1;
|
||||
private String modifyTime2;
|
||||
private String modifyTimeOperator = "=";
|
||||
private String paixu;
|
||||
private String shunxu;
|
||||
private String sql;
|
||||
|
||||
public String getWordFileCode() {
|
||||
return this.wordFileCode;
|
||||
}
|
||||
|
||||
public void setWordFileCode(String wordFileCode) {
|
||||
this.wordFileCode = wordFileCode;
|
||||
}
|
||||
|
||||
public String getWordFileCodeOperator() {
|
||||
return this.wordFileCodeOperator;
|
||||
}
|
||||
|
||||
public void setWordFileCodeOperator(String wordFileCodeOperator) {
|
||||
this.wordFileCodeOperator = wordFileCodeOperator;
|
||||
}
|
||||
|
||||
public String getJsonFileCode() {
|
||||
return this.jsonFileCode;
|
||||
}
|
||||
|
||||
public void setJsonFileCode(String jsonFileCode) {
|
||||
this.jsonFileCode = jsonFileCode;
|
||||
}
|
||||
|
||||
public String getJsonFileCodeOperator() {
|
||||
return this.jsonFileCodeOperator;
|
||||
}
|
||||
|
||||
public void setJsonFileCodeOperator(String jsonFileCodeOperator) {
|
||||
this.jsonFileCodeOperator = jsonFileCodeOperator;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getIdOperator() {
|
||||
return this.idOperator;
|
||||
}
|
||||
|
||||
public void setIdOperator(String idOperator) {
|
||||
this.idOperator = idOperator;
|
||||
}
|
||||
|
||||
public String getDocRealName() {
|
||||
return this.docRealName;
|
||||
}
|
||||
|
||||
public void setDocRealName(String docRealName) {
|
||||
this.docRealName = docRealName;
|
||||
}
|
||||
|
||||
public String getDocRealNameOperator() {
|
||||
return this.docRealNameOperator;
|
||||
}
|
||||
|
||||
public void setDocRealNameOperator(String docRealNameOperator) {
|
||||
this.docRealNameOperator = docRealNameOperator;
|
||||
}
|
||||
|
||||
public String getJsonRealName() {
|
||||
return this.jsonRealName;
|
||||
}
|
||||
|
||||
public void setJsonRealName(String jsonRealName) {
|
||||
this.jsonRealName = jsonRealName;
|
||||
}
|
||||
|
||||
public String getJsonRealNameOperator() {
|
||||
return this.jsonRealNameOperator;
|
||||
}
|
||||
|
||||
public void setJsonRealNameOperator(String jsonRealNameOperator) {
|
||||
this.jsonRealNameOperator = jsonRealNameOperator;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFileNameOperator() {
|
||||
return this.fileNameOperator;
|
||||
}
|
||||
|
||||
public void setFileNameOperator(String fileNameOperator) {
|
||||
this.fileNameOperator = fileNameOperator;
|
||||
}
|
||||
|
||||
public String getDocName() {
|
||||
return this.docName;
|
||||
}
|
||||
|
||||
public void setDocName(String docName) {
|
||||
this.docName = docName;
|
||||
}
|
||||
|
||||
public String getDocNameOperator() {
|
||||
return this.docNameOperator;
|
||||
}
|
||||
|
||||
public void setDocNameOperator(String docNameOperator) {
|
||||
this.docNameOperator = docNameOperator;
|
||||
}
|
||||
|
||||
public String getJsonName() {
|
||||
return this.jsonName;
|
||||
}
|
||||
|
||||
public void setJsonName(String jsonName) {
|
||||
this.jsonName = jsonName;
|
||||
}
|
||||
|
||||
public String getJsonNameOperator() {
|
||||
return this.jsonNameOperator;
|
||||
}
|
||||
|
||||
public void setJsonNameOperator(String jsonNameOperator) {
|
||||
this.jsonNameOperator = jsonNameOperator;
|
||||
}
|
||||
|
||||
public String getCreationTime() {
|
||||
return this.creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(String creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
public String getCreationTime1() {
|
||||
return this.creationTime1;
|
||||
}
|
||||
|
||||
public void setCreationTime1(String creationTime1) {
|
||||
this.creationTime1 = creationTime1;
|
||||
}
|
||||
|
||||
public String getCreationTime2() {
|
||||
return this.creationTime2;
|
||||
}
|
||||
|
||||
public void setCreationTime2(String creationTime2) {
|
||||
this.creationTime2 = creationTime2;
|
||||
}
|
||||
|
||||
public String getCreationTimeOperator() {
|
||||
return this.creationTimeOperator;
|
||||
}
|
||||
|
||||
public void setCreationTimeOperator(String creationTimeOperator) {
|
||||
this.creationTimeOperator = creationTimeOperator;
|
||||
}
|
||||
|
||||
public String getModifyTime() {
|
||||
return this.modifyTime;
|
||||
}
|
||||
|
||||
public void setModifyTime(String modifyTime) {
|
||||
this.modifyTime = modifyTime;
|
||||
}
|
||||
|
||||
public String getModifyTime1() {
|
||||
return this.modifyTime1;
|
||||
}
|
||||
|
||||
public void setModifyTime1(String modifyTime1) {
|
||||
this.modifyTime1 = modifyTime1;
|
||||
}
|
||||
|
||||
public String getModifyTime2() {
|
||||
return this.modifyTime2;
|
||||
}
|
||||
|
||||
public void setModifyTime2(String modifyTime2) {
|
||||
this.modifyTime2 = modifyTime2;
|
||||
}
|
||||
|
||||
public String getModifyTimeOperator() {
|
||||
return this.modifyTimeOperator;
|
||||
}
|
||||
|
||||
public void setModifyTimeOperator(String modifyTimeOperator) {
|
||||
this.modifyTimeOperator = modifyTimeOperator;
|
||||
}
|
||||
|
||||
public String getPaixu() {
|
||||
return paixu;
|
||||
}
|
||||
|
||||
public void setPaixu(String paixu) {
|
||||
this.paixu = paixu;
|
||||
}
|
||||
|
||||
public String getShunxu() {
|
||||
return shunxu;
|
||||
}
|
||||
|
||||
public void setShunxu(String shunxu) {
|
||||
this.shunxu = shunxu;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public void setSql(String sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.adc.da.ocr.service;
|
||||
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.ocr.entity.OcrRecordEO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface OCRRestfulService{
|
||||
|
||||
ResponseMessage handleFile(MultipartFile file, String fileName, OcrRecordEO getOcrEO, String type) throws Exception;
|
||||
|
||||
void updateDb(String taskId,String result) throws Exception;
|
||||
|
||||
String OcrHandleResult(MultipartFile wordFile,MultipartFile jsonFile,String taskId) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.adc.da.ocr.service;
|
||||
|
||||
import com.adc.da.ocr.entity.OcrRecordEO;
|
||||
import com.adc.da.ocr.page.OcrRecordEOPage;
|
||||
import java.util.List;
|
||||
|
||||
public interface OcrRecordEOService {
|
||||
|
||||
List<OcrRecordEO> queryByPage(OcrRecordEOPage page);
|
||||
|
||||
int updateByPrimaryKeySelective(OcrRecordEO ocrRecordEO);
|
||||
|
||||
int deleteByIds(List<String> idList);
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package com.adc.da.ocr.service.impl;
|
||||
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.Result;
|
||||
import com.adc.da.ocr.dao.OcrRecordEODao;
|
||||
import com.adc.da.ocr.entity.OcrRecordEO;
|
||||
import com.adc.da.ocr.entity.OcrResultEo;
|
||||
import com.adc.da.ocr.service.OCRRestfulService;
|
||||
import com.adc.da.ocr.util.Base64Util;
|
||||
import com.adc.da.ocr.util.RsaUtil;
|
||||
import com.adc.da.ocr.util.UUIDUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.adc.da.sys.util.LoginUserUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
@Transactional(value = "transactionManager", readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
||||
public class OCRRestfulServiceImpl implements OCRRestfulService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OCRRestfulServiceImpl.class);
|
||||
|
||||
//请求处理客户认证码
|
||||
@Value("${OCR.authCode}")
|
||||
private String OcrAuthCode;
|
||||
//请求处理文件url
|
||||
@Value("${OCR.handleFileUrl}")
|
||||
private String RestHandleFileUrl;
|
||||
//接口回调url
|
||||
@Value("${OCR.callBackUrl}")
|
||||
private String RestCallBackUrl;
|
||||
//请求处理usrid
|
||||
@Value("${OCR.userId}")
|
||||
private String OcrUserId;
|
||||
@Value("${OCR.convertType}")
|
||||
private String convertType;
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
private OcrRecordEODao ocrRecordEODao;
|
||||
//ocr处理文件后存放url
|
||||
@Value("${OCR.ocrPath}")
|
||||
private String ocrFilePath;
|
||||
@Value("${OCR.ocrDownPath}")
|
||||
private String ocrDownPath;
|
||||
|
||||
public ResponseMessage handleFile(MultipartFile file, String fileName, OcrRecordEO getOcrEO, String type)
|
||||
throws Exception {
|
||||
String taskId = "";
|
||||
if ("add".equals(type)) {
|
||||
taskId = UUIDUtils.randomUUID20();
|
||||
} else {
|
||||
taskId = getOcrEO.getId();
|
||||
}
|
||||
|
||||
String authCode = RsaUtil.publicEncrypt(OcrAuthCode);
|
||||
if(authCode == null){
|
||||
logger.error("客户认证RSA加密失败");
|
||||
return Result.error("客户认证RSA加密失败");
|
||||
}
|
||||
String fileContent = Base64Util.PDFToBase64(file);
|
||||
if(fileContent == null || "".equals(fileContent)){
|
||||
logger.error("PDF转Base64失败");
|
||||
return Result.error("PDF转Base64失败");
|
||||
}
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
|
||||
paramMap.add("userId",OcrUserId);
|
||||
paramMap.add("authCode",authCode);
|
||||
paramMap.add("convertType",convertType);
|
||||
paramMap.add("fileName",fileName);
|
||||
paramMap.add("fileContent",fileContent);
|
||||
paramMap.add("taskId",taskId);
|
||||
paramMap.add("callBackUrl",RestCallBackUrl);
|
||||
paramMap.add("callBackMethod","");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap,headers);
|
||||
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
|
||||
logger.info("处理完文件数据,开始请求OCR接口数据:【"+sdf.format(new Date())+"】");
|
||||
try{
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(RestHandleFileUrl, httpEntity, String.class);
|
||||
logger.info("请求OCR接口完毕,返回响应状态:【"+sdf.format(new Date())+"】");
|
||||
HttpStatus statusCode = responseEntity.getStatusCode();
|
||||
if(statusCode != HttpStatus.OK){
|
||||
logger.error("请求出现异常:"+statusCode.value());
|
||||
return Result.error("请求出现异常");
|
||||
}else{
|
||||
OcrResultEo ocrResultEo = JSONObject.parseObject(responseEntity.getBody(), OcrResultEo.class);
|
||||
if(ocrResultEo.getResultCode().equals("0")){
|
||||
if ("add".equals(type)) {
|
||||
OcrRecordEO ocrRecordEO = new OcrRecordEO();
|
||||
ocrRecordEO.setId(taskId);
|
||||
ocrRecordEO.setCreationUser(LoginUserUtil.getUserId());
|
||||
ocrRecordEO.setFileName(fileName);
|
||||
ocrRecordEO.setCreationTime(new Date());
|
||||
ocrRecordEO.setResultContent("转换中");
|
||||
ocrRecordEO.setStandNumber(getOcrEO.getStandNumber());
|
||||
ocrRecordEO.setStandName(getOcrEO.getStandName());
|
||||
ocrRecordEO.setFileType(getOcrEO.getFileType());
|
||||
ocrRecordEODao.insertSelective(ocrRecordEO);
|
||||
return Result.success(ocrResultEo.getResultCode(), "加入转换成功", taskId);
|
||||
} else {
|
||||
OcrRecordEO ocrRecordEO = new OcrRecordEO();
|
||||
ocrRecordEO.setId(taskId);
|
||||
ocrRecordEO.setFileName(fileName);
|
||||
ocrRecordEO.setResultContent("转换中");
|
||||
ocrRecordEO.setStandNumber(getOcrEO.getStandNumber());
|
||||
ocrRecordEO.setStandName(getOcrEO.getStandName());
|
||||
ocrRecordEO.setFileType(getOcrEO.getFileType());
|
||||
ocrRecordEO.setCreationTime(new Date());
|
||||
ocrRecordEODao.updateByPrimaryKeySelective(ocrRecordEO);
|
||||
return Result.success(ocrResultEo.getResultCode(), "加入转换成功", taskId);
|
||||
}
|
||||
}else{
|
||||
return Result.error(ocrResultEo.getReturnMessage());
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
logger.error(e.getMessage(),e);
|
||||
return Result.error("OCR接口请求出现异常,无法将文件传输到OCR引擎!");
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDb(String taskId,String result) throws Exception {
|
||||
OcrRecordEO ocrRecordEO = new OcrRecordEO();
|
||||
ocrRecordEO.setId(taskId);
|
||||
ocrRecordEO.setModifyTime(new Date());
|
||||
ocrRecordEO.setResultContent(result);
|
||||
ocrRecordEODao.updateByPrimaryKeySelective(ocrRecordEO);
|
||||
}
|
||||
|
||||
public String OcrHandleResult(MultipartFile wordFile,MultipartFile jsonFile,String taskId) throws Exception {
|
||||
//首先将文件保存至本地
|
||||
String saveWordFilePath=null;
|
||||
String saveWordFileName=null;
|
||||
if(wordFile!=null && !wordFile.isEmpty()){
|
||||
saveWordFileName=UUIDUtils.randomUUID20()+"_"+wordFile.getOriginalFilename();
|
||||
saveWordFilePath=ocrFilePath+saveWordFileName;
|
||||
FileUtils.copyInputStreamToFile(wordFile.getInputStream(),new File(saveWordFilePath));
|
||||
}
|
||||
String saveJsonFilePath=null;
|
||||
String saveJsonFileName=null;
|
||||
if(jsonFile!=null && !jsonFile.isEmpty()){
|
||||
saveJsonFileName=UUIDUtils.randomUUID20()+"_"+jsonFile.getOriginalFilename();
|
||||
saveJsonFilePath=ocrFilePath+saveJsonFileName;
|
||||
FileUtils.copyInputStreamToFile(jsonFile.getInputStream(),new File(saveJsonFilePath));
|
||||
}
|
||||
//开始将文件保存至数据库中
|
||||
if(StringUtils.isNotEmpty(saveWordFilePath) && StringUtils.isNotEmpty(saveJsonFilePath)){
|
||||
OcrRecordEO ocrRecordEO = new OcrRecordEO();
|
||||
ocrRecordEO.setId(taskId);
|
||||
ocrRecordEO.setDocName(saveWordFilePath);
|
||||
ocrRecordEO.setJsonName(saveJsonFilePath);
|
||||
ocrRecordEO.setDocRealName(saveWordFileName);
|
||||
ocrRecordEO.setWordFileCode(null);
|
||||
ocrRecordEO.setJsonRealName(saveJsonFileName);
|
||||
ocrRecordEO.setJsonFileCode(null);
|
||||
ocrRecordEO.setModifyTime(new Date());
|
||||
ocrRecordEO.setResultContent("转换成功");
|
||||
ocrRecordEODao.updateByPrimaryKeySelective(ocrRecordEO);
|
||||
return "{\"result\":\"success\"}";
|
||||
}else{
|
||||
updateDb(taskId,"error:File does not exist");
|
||||
return "{\"result\":\"error:File does not exist\"}";//文件不存在
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.adc.da.ocr.service.impl;
|
||||
|
||||
import com.adc.da.ocr.dao.OcrRecordEODao;
|
||||
import com.adc.da.ocr.entity.OcrRecordEO;
|
||||
import com.adc.da.ocr.page.OcrRecordEOPage;
|
||||
import com.adc.da.ocr.service.OcrRecordEOService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional(value = "transactionManager", readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
||||
public class OcrRecordEOServiceImpl implements OcrRecordEOService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OcrRecordEOServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private OcrRecordEODao ocrRecordEODao;
|
||||
|
||||
@Override
|
||||
public List<OcrRecordEO> queryByPage(OcrRecordEOPage page) {
|
||||
return ocrRecordEODao.queryByPage(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKeySelective(OcrRecordEO ocrRecordEO) {
|
||||
return ocrRecordEODao.updateByPrimaryKeySelective(ocrRecordEO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByIds(List<String> idList){
|
||||
return ocrRecordEODao.deleteByIds(idList);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,77 @@
|
||||
package com.adc.da.ocr.util;
|
||||
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* 采用MD5加密解密
|
||||
* @author tfq
|
||||
* @datetime 2011-10-13
|
||||
*/
|
||||
public class MD5Util {
|
||||
|
||||
/***
|
||||
* MD5加码 生成32位md5码
|
||||
*/
|
||||
public static String string2MD5(String inStr){
|
||||
MessageDigest md5 = null;
|
||||
try{
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
}catch (Exception e){
|
||||
System.out.println(e.toString());
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
char[] charArray = inStr.toCharArray();
|
||||
byte[] byteArray = new byte[charArray.length];
|
||||
|
||||
for (int i = 0; i < charArray.length; i++)
|
||||
byteArray[i] = (byte) charArray[i];
|
||||
byte[] md5Bytes = md5.digest(byteArray);
|
||||
StringBuffer hexValue = new StringBuffer();
|
||||
for (int i = 0; i < md5Bytes.length; i++){
|
||||
int val = ((int) md5Bytes[i]) & 0xff;
|
||||
if (val < 16)
|
||||
hexValue.append("0");
|
||||
hexValue.append(Integer.toHexString(val));
|
||||
}
|
||||
return hexValue.toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密解密算法 执行一次加密,两次解密
|
||||
*/
|
||||
public static String convertMD5(String inStr){
|
||||
|
||||
char[] a = inStr.toCharArray();
|
||||
for (int i = 0; i < a.length; i++){
|
||||
a[i] = (char) (a[i] ^ 't');
|
||||
}
|
||||
String s = new String(a);
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
// 测试主函数
|
||||
public static void main(String args[]) {
|
||||
/* String s = new String("tangfuqiang");
|
||||
System.out.println("原始:" + s);
|
||||
System.out.println("MD5后:" + string2MD5(s));
|
||||
|
||||
System.out.println("加密的:" + convertMD5(s));
|
||||
|
||||
System.out.println("解密的:" + convertMD5(convertMD5(s)));*/
|
||||
// String fileId = "ATT_FILE_07_JLBUTUSFXDRUKTVX5BT5";
|
||||
// String key = "dufy20170329java";
|
||||
// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH");
|
||||
// String time = df.format(new Date());
|
||||
// String sign = fileId + time + key;
|
||||
String str="GVJ3EZKW6NTK6Z5U92QE"+"EC4KKA6ZDTCPAOCRBC5M";
|
||||
String key="ecd2c0791b398882310c4edcc1eee42b";
|
||||
String entoryStr = string2MD5(str);
|
||||
|
||||
System.out.println(entoryStr);
|
||||
System.out.println(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.adc.da.ocr.util;
|
||||
|
||||
|
||||
import com.adc.da.util.utils.IOUtils;
|
||||
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
|
||||
import org.bouncycastle.crypto.params.RSAKeyParameters;
|
||||
import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory;
|
||||
import org.bouncycastle.util.encoders.Base64;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
|
||||
/**
|
||||
* @program: OcrDemo
|
||||
* @description: rsa加密解密
|
||||
* @author: duyunbao
|
||||
* @create: 2019-03-14 19:54
|
||||
*/
|
||||
public class RsaUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RsaUtil.class);
|
||||
|
||||
public static final String CHARSET = "UTF-8";
|
||||
public static final String RSA_ALGORITHM = "RSA";
|
||||
|
||||
/// RSA公钥格式转换,.net->java
|
||||
|
||||
public static String RSAPublicKeyDotNet2Java() throws IOException, DocumentException {
|
||||
/* SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(new File("../../../resources/rsa/publicRSAXML.xml"));
|
||||
Element root = document.getRootElement();
|
||||
Element ModulusElem = root.element("Modulus");
|
||||
Element ExponentElem = root.element("Exponent");
|
||||
BigInteger m = new BigInteger(1, Base64.decode(ModulusElem.elements().get(0).getData().toString()));
|
||||
BigInteger p = new BigInteger(1, Base64.decode(ExponentElem.elements().get(0).getData().toString()));*/
|
||||
BigInteger m = new BigInteger(1, Base64.decode("ncJeLmq4CT6t07x1Ct8LJn8/h6vPaSoySEcirRxAfFS7uoxxaWTyQE3khA4idvwky2ZrLtZjqVCFWRlHADKB5OCbRsVxvQv7kAR3VASJnCUtXH1lm+5zF9vxcw20ISfqEYUwikMDDogbVyLzNjwU/7ZfzzNY5lG+KsZxV8tuOE8="));
|
||||
BigInteger p = new BigInteger(1, Base64.decode("AQAB"));
|
||||
|
||||
RSAKeyParameters pub = new RSAKeyParameters(false, m, p);
|
||||
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(pub);
|
||||
byte[] serializedPublicBytes = publicKeyInfo.toASN1Primitive().getEncoded();
|
||||
return Base64.toBase64String(serializedPublicBytes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
}
|
||||
|
||||
* 得到公钥
|
||||
* @param publicKey 密钥字符串(经过base64编码)
|
||||
* @throws Exception
|
||||
*/
|
||||
public static RSAPublicKey getPublicKey(String publicKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
// 通过X509编码的Key指令获得公钥对象
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
|
||||
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(Base64.decode(publicKey));
|
||||
RSAPublicKey key = (RSAPublicKey) keyFactory.generatePublic(x509KeySpec);
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 公钥加密
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static String publicEncrypt(String data) {
|
||||
RSAPublicKey publicKey = null;
|
||||
try {
|
||||
publicKey = getPublicKey(RSAPublicKeyDotNet2Java());
|
||||
}catch (Exception e){
|
||||
logger.error(e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
return Base64.toBase64String(rsaSplitCodec(cipher, Cipher.ENCRYPT_MODE, data.getBytes(CHARSET),
|
||||
publicKey.getModulus().bitLength()));
|
||||
} catch (Exception e) {
|
||||
logger.error("加密字符串[" + data + "]时遇到异常",e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static byte[] rsaSplitCodec(Cipher cipher, int opmode, byte[] datas, int keySize) {
|
||||
int maxBlock = 0;
|
||||
if (opmode == Cipher.DECRYPT_MODE) {
|
||||
maxBlock = keySize / 8;
|
||||
} else {
|
||||
maxBlock = keySize / 8 - 11;
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offSet = 0;
|
||||
byte[] buff;
|
||||
int i = 0;
|
||||
try {
|
||||
while (datas.length > offSet) {
|
||||
if (datas.length - offSet > maxBlock) {
|
||||
buff = cipher.doFinal(datas, offSet, maxBlock);
|
||||
} else {
|
||||
buff = cipher.doFinal(datas, offSet, datas.length - offSet);
|
||||
}
|
||||
out.write(buff, 0, buff.length);
|
||||
i++;
|
||||
offSet = i * maxBlock;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("加解密阀值为[" + maxBlock + "]的数据时发生异常",e);
|
||||
}
|
||||
byte[] resultDatas = out.toByteArray();
|
||||
IOUtils.closeQuietly(out);
|
||||
return resultDatas;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.adc.da.ocr.util;
|
||||
|
||||
|
||||
import com.adc.da.util.utils.RandomUtils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class UUIDUtils {
|
||||
|
||||
public static String randomUUID10() {
|
||||
return RandomUtils.randomString(10);
|
||||
}
|
||||
|
||||
public static String randomUUID20() {
|
||||
return RandomUtils.randomString(20);
|
||||
}
|
||||
|
||||
public static String randomUUID(int length) {
|
||||
return RandomUtils.randomString(length);
|
||||
}
|
||||
|
||||
public static String getUUIDPath(String uuid){
|
||||
StringBuilder builder=new StringBuilder();
|
||||
builder.append("/");
|
||||
builder.append((uuid.substring(0, 3).hashCode())%100+"").append("/");
|
||||
builder.append((uuid.substring(7,10).hashCode())%100+"").append("/");
|
||||
builder.append((uuid.substring(11,14).hashCode())%100+"").append("/");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String getAttTable(){
|
||||
Random rand = new Random();
|
||||
int nextInt = rand.nextInt(10)+1;
|
||||
StringBuilder builder=new StringBuilder();
|
||||
builder.append("ATT_FILE_").append(String.format("%02d", nextInt));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user