From 02ec24e0d1a3bd0fe4bcdb8fe37fe0cb55a6f921 Mon Sep 17 00:00:00 2001 From: yjz <3131811435@qq.com> Date: Mon, 3 Jun 2024 14:45:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=9C=AC=E5=9C=B0=E5=B7=A5=E5=85=B7):=20O?= =?UTF-8?q?CR=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- laws-modules/pom.xml | 8 +- .../com/jero/modules/laws/ocr/Base64Util.java | 213 ++++++++++++++ .../com/jero/modules/laws/ocr/MD5Util.java | 77 +++++ .../com/jero/modules/laws/ocr/OkHttpUtil.java | 193 ++++++++++++ .../com/jero/modules/laws/ocr/RsaUtil.java | 132 +++++++++ .../com/jero/modules/laws/ocr/UUIDUtils.java | 40 +++ .../modules/laws/ocr/config/OkHttpConfig.java | 69 +++++ .../ocr/controller/OCRRestfulController.java | 181 ++++++++++++ .../modules/laws/ocr/entity/BaseEntity.java | 6 + .../laws/ocr/entity/OcrCallBackResultEo.java | 76 +++++ .../modules/laws/ocr/entity/OcrRecordEO.java | 278 ++++++++++++++++++ .../modules/laws/ocr/entity/OcrRequestEo.java | 83 ++++++ .../modules/laws/ocr/entity/OcrResultEo.java | 30 ++ .../jero/modules/laws/ocr/http/PageInfo.java | 168 +++++++++++ .../laws/ocr/http/ResponseMessage.java | 62 ++++ .../ocr/http/ResponseMessageCodeEnum.java | 21 ++ .../jero/modules/laws/ocr/http/Result.java | 50 ++++ .../laws/ocr/mapper/OcrRecordEOMapper.java | 32 ++ .../laws/ocr/mapper/xml/OcrRecordEOMapper.xml | 259 ++++++++++++++++ .../jero/modules/laws/ocr/page/BasePage.java | 102 +++++++ .../laws/ocr/page/OcrRecordEOPage.java | 255 ++++++++++++++++ .../laws/ocr/service/OCRRestfulService.java | 15 + .../laws/ocr/service/OcrRecordEOService.java | 18 ++ .../service/impl/OCRRestfulServiceImpl.java | 230 +++++++++++++++ .../service/impl/OcrRecordEOServiceImpl.java | 44 +++ .../modules/laws/ocr/web/BaseController.java | 82 ++++++ .../src/main/resources/application-dev.yml | 16 + 27 files changed, 2739 insertions(+), 1 deletion(-) create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/Base64Util.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/MD5Util.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/OkHttpUtil.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/RsaUtil.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/UUIDUtils.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/config/OkHttpConfig.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/controller/OCRRestfulController.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/BaseEntity.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrCallBackResultEo.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrRecordEO.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrRequestEo.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrResultEo.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/http/PageInfo.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/http/ResponseMessage.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/http/ResponseMessageCodeEnum.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/http/Result.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/mapper/OcrRecordEOMapper.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/mapper/xml/OcrRecordEOMapper.xml create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/page/BasePage.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/page/OcrRecordEOPage.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/service/OCRRestfulService.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/service/OcrRecordEOService.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/service/impl/OCRRestfulServiceImpl.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/service/impl/OcrRecordEOServiceImpl.java create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/ocr/web/BaseController.java diff --git a/laws-modules/pom.xml b/laws-modules/pom.xml index c06c35d0..a4e94544 100644 --- a/laws-modules/pom.xml +++ b/laws-modules/pom.xml @@ -178,5 +178,11 @@ poi-ooxml-schemas 3.17 --> + + org.bouncycastle + bcprov-jdk15on + 1.56 + compile + - \ No newline at end of file + diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/Base64Util.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/Base64Util.java new file mode 100644 index 00000000..e8e982bb --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/Base64Util.java @@ -0,0 +1,213 @@ +package com.jero.modules.laws.ocr; + +import org.bouncycastle.util.encoders.Base64; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; + +/** + * @program: OcrDemo + * @description: 工具类 + * @author: duyunbao + * @create: 2019-03-13 14:58 + */ +public class Base64Util { + private static final Logger logger = LoggerFactory.getLogger(Base64Util.class); + public static String PDFToBase64(MultipartFile file) { + //BASE64Encoder encoder = new BASE64Encoder(); + InputStream fin =null; + BufferedInputStream bin =null; + ByteArrayOutputStream baos = null; + BufferedOutputStream bout =null; + try { + fin = file.getInputStream(); + bin = new BufferedInputStream(fin); + baos = new ByteArrayOutputStream(); + bout = new BufferedOutputStream(baos); + byte[] buffer = new byte[1024]; + int len = bin.read(buffer); + while(len != -1){ + bout.write(buffer, 0, len); + len = bin.read(buffer); + } + //刷新此输出流并强制写出所有缓冲的输出字节 + bout.flush(); + byte[] bytes = baos.toByteArray(); + return Base64.toBase64String(bytes); + + } catch (FileNotFoundException e) { + logger.error(e.getMessage(),e); + } catch (IOException e) { + logger.error(e.getMessage(),e); + }finally{ + try { + fin.close(); + bin.close(); + bout.close(); + } catch (IOException e) { + logger.error(e.getMessage(),e); + } + } + return null; + } + + + /* public static String FindPDFBase(MultipartFile file){ + InputStream fin= null; + BufferedInputStream bin= null; + ByteArrayOutputStream baos= null; + BufferedOutputStream bout= null; + try{ + fin=file.getInputStream(); + bin=new BufferedInputStream(fin); + baos=new ByteArrayOutputStream(); + bout=new BufferedOutputStream(baos); + byte[] buffer=new byte[1024]; + int len=bin.read(buffer); + while(len!=-1){ + bout.write(buffer,0,len); + len=bin.read(buffer); + } + //读取完毕 + bout.flush(); + byte[] bytes=baos.toByteArray(); + String res= Base64.toBase64String(bytes); + return res; + }catch(Exception e){ + e.printStackTrace(); + }finally { + try{ + fin.close(); + bin.close(); + bout.close(); + }catch (IOException e){ + e.printStackTrace(); + } + } + + return null; + }*/ + + /** + *@Description: base64 转成文件 + *@Param: [base64Content, filePath] + *@return: void + *@Author: duyunbao + *@date: 2019/3/13 16:49 + */ + public static String base64StringToFile(String base64Content,String filePath) { + // BASE64Decoder decoder = new BASE64Decoder(); + BufferedInputStream bis = null; + FileOutputStream fos = null; + BufferedOutputStream bos = null; + + try { + // logger.info("获取到的文件base64字符串:"+base64Content); + // byte[] bytes = decoder.decodeBuffer(base64Content,);//base64编码内容转换为字节数组 + byte[] bytes = Base64.decode(base64Content.getBytes("UTF-8")); + ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes); + bis = new BufferedInputStream(byteInputStream); + File file = new File(filePath); + File path = file.getParentFile(); + if(!path.exists()){ + path.mkdirs(); + } + fos = new FileOutputStream(file); + bos = new BufferedOutputStream(fos); + + byte[] buffer = new byte[1024]; + int length = bis.read(buffer); + while(length != -1){ + bos.write(buffer, 0, length); + length = bis.read(buffer); + } + bos.flush(); + } catch (Exception e) { + logger.error(e.getMessage(),e); + return "error"; + }finally{ + try { + bos.close(); + bis.close(); + fos.close(); + } catch (IOException e) { + logger.error(e.getMessage(),e); + return "error"; + } + } + return "success"; + } + + /** + *@Description: base64 转成文件 + *@Param: [base64Content, filePath] + *@return: void + *@Author: duyunbao + *@date: 2019/3/13 16:49 + */ + public static String base64StringToFileOfTxt(String base64Content,String filePath) { +// BASE64Decoder decoder = new BASE64Decoder(); + java.util.Base64.Decoder decoder = java.util.Base64.getDecoder(); + BufferedInputStream bis = null; + FileOutputStream fos = null; + BufferedOutputStream bos = null; + + try { + //logger.info("获取到的文件base64字符串:"+base64Content); + // new String(decoder.decodeBuffer(base64Content),"UTF-8"); +// byte[] bytes = decoder.decodeBuffer(base64Content);//base64编码内容转换为字节数组 + byte[] bytes = Base64.decode(base64Content.getBytes("UTF-8")); +// String result=new String(bytes); +// logger.info("返回的内容为:"+result); + ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes); + bis = new BufferedInputStream(byteInputStream); + File file = new File(filePath); + File path = file.getParentFile(); + if(!path.exists()){ + path.mkdirs(); + } + fos = new FileOutputStream(file); + bos = new BufferedOutputStream(fos); + + byte[] buffer = new byte[1024]; + int length = bis.read(buffer); + while(length != -1){ + bos.write(buffer, 0, length); + length = bis.read(buffer); + } + bos.flush(); +// FileWriter fw; +// fw = new FileWriter(filePath); +// PrintWriter out = new PrintWriter(fw); +// out.write(result); +// out.println(); +// fw.close(); +// out.close(); + } catch (Exception e) { + logger.error(e.getMessage(),e); + return "error"; + }finally{ + try { + bos.close(); + bis.close(); + fos.close(); + } catch (IOException e) { + logger.error(e.getMessage(),e); + return "error"; + } + } + return "success"; + } + + + + public static void main(String[] args) { + String str="UEsDBBQAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAX3JlbHMvUEsDBBQAAAAIAAAAAADjVjz6ugAAAC4BAAALAAAAX3JlbHMvLnJlbHONzzsOwjAMBuAdiTtE3mlaBoRQ0y4IqSsqB4gSN41okygJj56NgSNxBTIwAGJgt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AAICAAALoHAAB3b3JkL2Zvb3Rub3Rlcy54bWxQSwECFAAUAAAACABae3xO2LqOecMCAAApBwAAEQAAAAAAAAAAACAgAAAyCQAAd29yZC9kb2N1bWVudC54bWxQSwECFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAADAAAAAkDAAAd29yZC9fcmVscy9QSwECFAAUAAAACAAAAAAAlHqY/usAAACsAgAAHAAAAAAAAAAAACAAAABNDAAAd29yZC9fcmVscy9kb2N1bWVudC54bWwucmVsc1BLAQIUABQAAAAIAAAAAACGDYnXPQEAACQEAAATAAAAAAAAAAAAIAAAAHINAABbQ29udGVudF9UeXBlc10ueG1sUEsFBgAAAAALAAsAnwIAAOAOAAAAAA=="; + base64StringToFileOfTxt(str,"d://1.json"); + } + + +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/MD5Util.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/MD5Util.java new file mode 100644 index 00000000..dbe22ece --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/MD5Util.java @@ -0,0 +1,77 @@ +package com.jero.modules.laws.ocr; + + +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); + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/OkHttpUtil.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/OkHttpUtil.java new file mode 100644 index 00000000..2a8b80b3 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/OkHttpUtil.java @@ -0,0 +1,193 @@ +package com.jero.modules.laws.ocr; + +import okhttp3.*; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.util.Iterator; +import java.util.Map; + +/** + * + * @author David + */ +@Component +public class OkHttpUtil { + private static final Logger logger = LoggerFactory.getLogger(OkHttpUtil.class); + + @Autowired + private OkHttpClient okHttpClient; + /** + * get + * + * @param url 请求的url + * @param queries 请求的参数,在浏览器?后面的数据,没有可以传null + * @return + */ + public String get(String url, Map queries, Map headerParams) { + String responseBody = ""; + StringBuffer sb = new StringBuffer(url); + if (queries != null && queries.keySet().size() > 0) { + boolean firstFlag = true; + Iterator iterator = queries.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = (Map.Entry) iterator.next(); + if (firstFlag) { + sb.append("?" + entry.getKey() + "=" + entry.getValue()); + firstFlag = false; + } else { + sb.append("&" + entry.getKey() + "=" + entry.getValue()); + } + } + } + + Request.Builder requestBuilder = new Request.Builder().url(url); + + if(headerParams != null){ + for(Map.Entry entry : headerParams.entrySet()) { + requestBuilder.addHeader(entry.getKey(), entry.getValue()); + } + } + + + Request request = requestBuilder.url(sb.toString()) + .build(); + Response response = null; + try { + response = okHttpClient.newCall(request).execute(); + int status = response.code(); + if (status == 200) { + return response.body().string(); + } + } catch (Exception e) { + logger.error("okhttp put error >> ex = {}", ExceptionUtils.getStackTrace(e)); + } finally { + if (response != null) { + response.close(); + } + } + return responseBody; + } + /** + * post + * + * @param url 请求的url + * @param params post form 提交的参数 + * @return + */ + public String post(String url, Map params, Map headerParams) { + String responseBody = ""; + FormBody.Builder builder = new FormBody.Builder(); + //添加参数 + if (params != null && params.keySet().size() > 0) { + for (String key : params.keySet()) { + builder.add(key, params.get(key)); + } + } + + Request.Builder requestBuilder = new Request.Builder().url(url); + + for(Map.Entry entry : headerParams.entrySet()) { + requestBuilder.addHeader(entry.getKey(), entry.getValue()); + } + + Request request = requestBuilder.post(builder.build()).build(); + Response response = null; + try { + response = okHttpClient.newCall(request).execute(); + int status = response.code(); + if (status == 200) { + return response.body().string(); + } + } catch (Exception e) { + logger.error("okhttp post error >> ex = {}", ExceptionUtils.getStackTrace(e)); + } finally { + if (response != null) { + response.close(); + } + } + return responseBody; + } + + /** + * post + * + * @param url 请求的url + * @param params post form 提交的参数 + * @return + */ + public String postForJson(String url, String json, Map headerParams) { + RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), json); + String responseBody = ""; + Request.Builder requestBuilder = new Request.Builder().url(url); + for(Map.Entry entry : headerParams.entrySet()) { + requestBuilder.addHeader(entry.getKey(), entry.getValue()); + } + Request request = requestBuilder.post(requestBody).build(); + Response response = null; + try { + response = okHttpClient.newCall(request).execute(); + int status = response.code(); + if (status == 200) { + return response.body().string(); + } + } catch (Exception e) { + logger.error("okhttp post error >> ex = {}", ExceptionUtils.getStackTrace(e)); + } finally { + if (response != null) { + response.close(); + } + } + return responseBody; + } + + /** + * post 上传文件 + * + * @param url + * @param params + * @param fileType + * @return + */ + public String postFile(String url, Map params, String fileType, Map headerParams) { + String responseBody = ""; + MultipartBody.Builder builder = new MultipartBody.Builder(); + //添加参数 + if (params != null && params.keySet().size() > 0) { + for (String key : params.keySet()) { + if (params.get(key) instanceof File) { + File file = (File) params.get(key); + builder.addFormDataPart(key, file.getName(), RequestBody.create(MediaType.parse(fileType), file)); + continue; + } + builder.addFormDataPart(key, params.get(key).toString()); + } + } + + Request.Builder requestBuilder = new Request.Builder(); + for(Map.Entry entry : headerParams.entrySet()) { + requestBuilder.addHeader(entry.getKey(), entry.getValue()); + } + + Request request = requestBuilder.url(url).post(builder.build()).build(); + Response response = null; + try { + response = okHttpClient.newCall(request).execute(); + int status = response.code(); + if (status == 200) { + return response.body().string(); + } + } catch (Exception e) { + logger.error("okhttp postFile error >> ex = {}", ExceptionUtils.getStackTrace(e)); + } finally { + if (response != null) { + response.close(); + } + } + return responseBody; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/RsaUtil.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/RsaUtil.java new file mode 100644 index 00000000..296c8310 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/RsaUtil.java @@ -0,0 +1,132 @@ +package com.jero.modules.laws.ocr; + + +import com.aliyuncs.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; + } + + +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/UUIDUtils.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/UUIDUtils.java new file mode 100644 index 00000000..f88b3f9f --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/UUIDUtils.java @@ -0,0 +1,40 @@ +package com.jero.modules.laws.ocr; + + +import com.jero.common.util.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(); + } + + +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/config/OkHttpConfig.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/config/OkHttpConfig.java new file mode 100644 index 00000000..ec6c56fb --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/config/OkHttpConfig.java @@ -0,0 +1,69 @@ +package com.jero.modules.laws.ocr.config; + +import okhttp3.ConnectionPool; +import okhttp3.OkHttpClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.concurrent.TimeUnit; + +@Configuration +public class OkHttpConfig { + + @Bean + public X509TrustManager x509TrustManager() { + return new X509TrustManager() { + @Override + public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { + } + @Override + public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { + } + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + }; + } + @Bean + public SSLSocketFactory sslSocketFactory() { + try { + //信任任何链接 + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, new TrustManager[]{x509TrustManager()}, new SecureRandom()); + return sslContext.getSocketFactory(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + return null; + } + /** + * Create a new connection pool with tuning parameters appropriate for a single-user application. + * The tuning parameters in this pool are subject to change in future OkHttp releases. Currently + */ + @Bean + public ConnectionPool pool() { + return new ConnectionPool(200, 5, TimeUnit.MINUTES); + } + @Bean + public OkHttpClient okHttpClient() { + return new OkHttpClient.Builder() + .sslSocketFactory(sslSocketFactory(), x509TrustManager()) + .retryOnConnectionFailure(false)//是否开启缓存 + .connectionPool(pool())//连接池 + .connectTimeout(10L, TimeUnit.SECONDS) + .readTimeout(10L, TimeUnit.SECONDS) + .build(); + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/controller/OCRRestfulController.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/controller/OCRRestfulController.java new file mode 100644 index 00000000..0f7602d4 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/controller/OCRRestfulController.java @@ -0,0 +1,181 @@ +package com.jero.modules.laws.ocr.controller; + +import com.alibaba.fastjson.JSON; +import com.jero.modules.laws.ocr.MD5Util; +import com.jero.modules.laws.ocr.entity.OcrCallBackResultEo; +import com.jero.modules.laws.ocr.entity.OcrRecordEO; +import com.jero.modules.laws.ocr.http.PageInfo; +import com.jero.modules.laws.ocr.http.ResponseMessage; +import com.jero.modules.laws.ocr.http.Result; +import com.jero.modules.laws.ocr.page.OcrRecordEOPage; +import com.jero.modules.laws.ocr.service.OCRRestfulService; +import com.jero.modules.laws.ocr.service.OcrRecordEOService; +import com.jero.modules.laws.ocr.web.BaseController; +import com.jero.modules.onlyoffice.entity.AttFileEO; +import com.jero.modules.onlyoffice.service.IAttFileEOService; +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("/laws/ocr/OCRRestful") +@Api(description = "|OCR识别 |") +public class OCRRestfulController extends BaseController { + 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 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> 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 rows = ocrRecordEOService.queryByPage(page); + Integer integer = ocrRecordEOService.queryByPageCount(page); + DecimalFormat df = new DecimalFormat("0.00");//设置保留位数 + for (OcrRecordEO ocrRecordEO : rows){ + ocrRecordEO.setDocRealFile(ocrDownPath+ocrRecordEO.getDocRealName()); + ocrRecordEO.setJsonRealFile(ocrDownPath+ocrRecordEO.getJsonRealName()); + } + page.getPager().setRowCount(integer); + return Result.success(getPageInfo(page.getPager(), rows)); + } + + @ApiOperation(value = "新增ocr内容") + @PostMapping("/addOcrRecord") + public ResponseMessage 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 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 idList = Arrays.asList(idArr); + int i = ocrRecordEOService.deleteByIds(idList); + return Result.success("0","删除成功",i); + } else { + return Result.error("删除数据不能为空"); + } + + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/BaseEntity.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/BaseEntity.java new file mode 100644 index 00000000..ea90712a --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/BaseEntity.java @@ -0,0 +1,6 @@ +package com.jero.modules.laws.ocr.entity; + +public class BaseEntity { + public BaseEntity() { + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrCallBackResultEo.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrCallBackResultEo.java new file mode 100644 index 00000000..fd39b673 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrCallBackResultEo.java @@ -0,0 +1,76 @@ +package com.jero.modules.laws.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; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrRecordEO.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrRecordEO.java new file mode 100644 index 00000000..68bc404c --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrRecordEO.java @@ -0,0 +1,278 @@ +package com.jero.modules.laws.ocr.entity; + +import java.io.Serializable; +import java.util.Date; + +/** + * 功能:OCR_RECORD OcrRecordEOEntity
+ * 作者:code generator
+ * 日期: 2019-03-25
+ * 版权所有:版权归北京卡达克数据技术中心所有。
+ */ +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字段名转换为原始数据库列名。如果不存在则返回null
+ *

字段列表:

+ *
  • wordFileCode -> word_file_code
  • + *
  • jsonFileCode -> json_file_code
  • + *
  • id -> id
  • + *
  • docRealName -> doc_real_name
  • + *
  • jsonRealName -> json_real_name
  • + *
  • fileName -> file_name
  • + *
  • docName -> doc_name
  • + *
  • jsonName -> json_name
  • + *
  • creationTime -> creation_time
  • + *
  • modifyTime -> modify_time
  • + */ + 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字段名。如果不存在则返回null
    + *

    字段列表:

    + *
  • word_file_code -> wordFileCode
  • + *
  • json_file_code -> jsonFileCode
  • + *
  • id -> id
  • + *
  • doc_real_name -> docRealName
  • + *
  • json_real_name -> jsonRealName
  • + *
  • file_name -> fileName
  • + *
  • doc_name -> docName
  • + *
  • json_name -> jsonName
  • + *
  • creation_time -> creationTime
  • + *
  • modify_time -> modifyTime
  • + */ + 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; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrRequestEo.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrRequestEo.java new file mode 100644 index 00000000..fe8029b5 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrRequestEo.java @@ -0,0 +1,83 @@ +package com.jero.modules.laws.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; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrResultEo.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrResultEo.java new file mode 100644 index 00000000..7f917942 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/entity/OcrResultEo.java @@ -0,0 +1,30 @@ +package com.jero.modules.laws.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; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/PageInfo.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/PageInfo.java new file mode 100644 index 00000000..71379196 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/PageInfo.java @@ -0,0 +1,168 @@ +package com.jero.modules.laws.ocr.http; + +import org.apache.commons.lang3.StringUtils; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PageInfo { + private Integer pageNo; + private Integer pageSize; + private Long count; + private Long pageCount; + private List list; + private List> title; + private Map ext; + private String orderBy; + + public PageInfo() { + this.pageNo = 1; + this.pageSize = 10; + this.list = new ArrayList(); + this.title = new ArrayList(); + this.ext = new HashMap(); + this.orderBy = ""; + this.pageSize = 1; + } + + public PageInfo(HttpServletRequest request) { + this.pageNo = 1; + this.pageSize = 10; + this.list = new ArrayList(); + this.title = new ArrayList(); + this.ext = new HashMap(); + this.orderBy = ""; + String no = request.getParameter("pageNo"); + if (StringUtils.isEmpty(no)) { + this.setPageNo(1); + } else if (StringUtils.isNumeric(no)) { + this.setPageNo(Integer.parseInt(no)); + } + + String size = request.getParameter("pageSize"); + if (StringUtils.isEmpty(size)) { + this.setPageSize(10); + } + + if (StringUtils.isNumeric(size)) { + this.setPageSize(Integer.parseInt(size)); + } + + String orderByParam = request.getParameter("orderBy"); + if (StringUtils.isNotBlank(orderByParam)) { + this.setOrderBy(orderByParam); + } + + } + + public PageInfo(Integer pageNo, Integer pageSize) { + this(pageNo, pageSize, 0L); + } + + public PageInfo(Integer pageNo, Integer pageSize, Long count) { + this(pageNo, pageSize, count, new ArrayList()); + } + + public PageInfo(Integer pageNo, Integer pageSize, Long count, List list) { + this.pageNo = 1; + this.pageSize = 10; + this.list = new ArrayList(); + this.title = new ArrayList(); + this.ext = new HashMap(); + this.orderBy = ""; + if (pageNo == null) { + pageNo = 1; + } + + if (pageSize == null) { + pageSize = 10; + } + + this.setCount(count); + this.setPageNo(Math.abs(pageNo)); + this.setPageSize(Math.abs(pageSize)); + this.setList(list); + } + + public Long getCount() { + return this.count; + } + + public void setCount(Long count) { + this.count = count; + if ((long) this.pageSize >= count) { + this.pageNo = 1; + } + + } + + public Integer getPageNo() { + return this.pageNo; + } + + public void setPageNo(Integer pageNo) { + this.pageNo = pageNo; + } + + public Integer getPageSize() { + return this.pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize <= 0 ? 10 : pageSize; + } + + public List getList() { + return this.list; + } + + public PageInfo setList(List list) { + this.list = list; + return this; + } + + public String getOrderBy() { + return this.orderBy; + } + + public void setOrderBy(String orderBy) { + this.orderBy = orderBy; + } + + public Map getExt() { + return this.ext; + } + + public void setExt(Map ext) { + this.ext = ext; + } + + public Long getPageCount() { + if (this.count % (long) this.pageSize != 0L) { + this.pageCount = this.count / (long) this.pageSize + 1L; + } else { + this.pageCount = this.count / (long) this.pageSize; + } + + if (this.pageCount < 1L) { + this.pageCount = 1L; + } + + return this.pageCount; + } + + public void setPageCount(Long pageCount) { + this.pageCount = pageCount; + } + + public List> getTitle() { + return this.title; + } + + public void setTitle(List> title) { + this.title = title; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/ResponseMessage.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/ResponseMessage.java new file mode 100644 index 00000000..190fbd07 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/ResponseMessage.java @@ -0,0 +1,62 @@ +package com.jero.modules.laws.ocr.http; + +public class ResponseMessage { + private String respCode; + private String respMsg; + private T data; + private boolean ok; + + public ResponseMessage() { + } + + public ResponseMessage(String respCode, String message) { + this.respCode = respCode; + this.respMsg = message; + } + + public ResponseMessage(String respCode, String message, boolean ok) { + this.respCode = respCode; + this.respMsg = message; + this.ok = ok; + } + + public ResponseMessage(String respCode, String message, boolean ok, T data) { + this.respCode = respCode; + this.respMsg = message; + this.ok = ok; + this.data = data; + } + + public ResponseMessage(T data) { + this.data = data; + } + + public String getRespCode() { + return this.respCode; + } + + public void setRespCode(String respCode) { + this.respCode = respCode; + } + + public String getMessage() { + return this.respMsg; + } + + public void setMessage(String message) { + this.respMsg = message; + } + + public T getData() { + return this.data; + } + + public void setData(T data) { + this.data = data; + } + + public boolean isOk() { + return this.ok; + } +} + diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/ResponseMessageCodeEnum.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/ResponseMessageCodeEnum.java new file mode 100644 index 00000000..094d7076 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/ResponseMessageCodeEnum.java @@ -0,0 +1,21 @@ +package com.jero.modules.laws.ocr.http; + +public enum ResponseMessageCodeEnum { + SUCCESS("0"), + ERROR("-1"), + ERROR_TOKEN("LE505"), + VALID_ERROR("1000"), + SAVE_SUCCESS("r0001"), + UPDATE_SUCCESS("r0002"), + REMOVE_SUCCESS("r0003"); + + private String code; + + private ResponseMessageCodeEnum(String code) { + this.code = code; + } + + public String getCode() { + return this.code; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/Result.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/Result.java new file mode 100644 index 00000000..c7c3056e --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/http/Result.java @@ -0,0 +1,50 @@ +package com.jero.modules.laws.ocr.http; + +public class Result { + public Result() { + } + + public static ResponseMessage success() { + return new ResponseMessage(ResponseMessageCodeEnum.SUCCESS.getCode(), "", true); + } + + public static ResponseMessage success(String code, T t) { + return new ResponseMessage(code, "", true, t); + } + + public static ResponseMessage success(String code, String message) { + return new ResponseMessage(code, message); + } + + public static ResponseMessage success(String code, String message, T t) { + return new ResponseMessage(code, message, true, t); + } + + public static ResponseMessage success(String code, String message,Boolean t) { + return new ResponseMessage(code, message, true); + } + + public static ResponseMessage success(T t) { + return new ResponseMessage(ResponseMessageCodeEnum.SUCCESS.getCode(), "", true, t); + } + + public static ResponseMessage error() { + return error(""); + } + + public static ResponseMessage error(String message) { + return error(ResponseMessageCodeEnum.ERROR.getCode(), message); + } + + public static ResponseMessage error(String code, String message) { + return error(code, message, (Object)null); + } + + public static ResponseMessage error(String code, String message, T t) { + return new ResponseMessage(code, message, false, t); + } + + public static ResponseMessage error( T t) { + return new ResponseMessage(t); + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/mapper/OcrRecordEOMapper.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/mapper/OcrRecordEOMapper.java new file mode 100644 index 00000000..00dc1317 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/mapper/OcrRecordEOMapper.java @@ -0,0 +1,32 @@ +package com.jero.modules.laws.ocr.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.jero.modules.laws.ocr.entity.OcrRecordEO; +import com.jero.modules.laws.ocr.page.BasePage; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * + *
    + * 功能:OCR_RECORD OcrRecordEODao
    + * 作者:code generator
    + * 日期: 2019-03-25
    + * 版权所有:版权归北京卡达克数据技术中心所有。
    + */ +public interface OcrRecordEOMapper extends BaseMapper { + +// List getAllOcrResult(); +// +// int deleteByIds(@Param("idList") List idList); + + List queryByPage(BasePage var1); + Integer queryByPageCount(BasePage var1); + + int insertSelective(OcrRecordEO ocrRecordEO); + + int updateByPrimaryKeySelective(OcrRecordEO ocrRecordEO); + + int deleteByIds(@Param("idList") List idList); +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/mapper/xml/OcrRecordEOMapper.xml b/laws-modules/src/main/java/com/jero/modules/laws/ocr/mapper/xml/OcrRecordEOMapper.xml new file mode 100644 index 00000000..d8b9339e --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/mapper/xml/OcrRecordEOMapper.xml @@ -0,0 +1,259 @@ + + + + + + + + + + + + + + + + + + + + + + + + word_file_code, json_file_code, id, doc_real_name, json_real_name, file_name, doc_name, json_name, + creation_time, modify_time,result_content,file_type,stand_number,stand_name + + + + + where 1=1 + + + and word_file_code ${wordFileCodeOperator} #{wordFileCode} + + + and json_file_code ${jsonFileCodeOperator} #{jsonFileCode} + + + and id ${idOperator} #{id} + + + and doc_real_name ${docRealNameOperator} #{docRealName} + + + and json_real_name ${jsonRealNameOperator} #{jsonRealName} + + + and file_name ${fileNameOperator} #{fileName} + + + and doc_name ${docNameOperator} #{docName} + + + and json_name ${jsonNameOperator} #{jsonName} + + + and creation_time ${creationTimeOperator} #{creationTime} + + + and creation_time >= #{creationTime1} + + + and creation_time <= #{creationTime2} + + + and modify_time ${modifyTimeOperator} #{modifyTime} + + + and modify_time >= #{modifyTime1} + + + and modify_time <= #{modifyTime2} + + + + + + + + insert into OCR_RECORD() + values (#{wordFileCode, jdbcType=VARCHAR}, #{jsonFileCode, jdbcType=VARCHAR}, #{id, jdbcType=VARCHAR}, #{docRealName, jdbcType=VARCHAR}, #{jsonRealName, jdbcType=VARCHAR}, #{fileName, jdbcType=VARCHAR}, #{docName, jdbcType=VARCHAR}, #{jsonName, jdbcType=VARCHAR}, #{creationTime, jdbcType=TIMESTAMP}, #{modifyTime, jdbcType=TIMESTAMP}) + + + + + + insert into OCR_RECORD + + word_file_code, + json_file_code, + id, + doc_real_name, + json_real_name, + file_name, + doc_name, + json_name, + creation_time, + modify_time, + result_content, + file_type, + stand_number, + stand_name, + + + #{wordFileCode, jdbcType=VARCHAR}, + #{jsonFileCode, jdbcType=VARCHAR}, + #{id, jdbcType=VARCHAR}, + #{docRealName, jdbcType=VARCHAR}, + #{jsonRealName, jdbcType=VARCHAR}, + #{fileName, jdbcType=VARCHAR}, + #{docName, jdbcType=VARCHAR}, + #{jsonName, jdbcType=VARCHAR}, + #{creationTime, jdbcType=TIMESTAMP}, + #{modifyTime, jdbcType=TIMESTAMP}, + #{resultContent, jdbcType=VARCHAR}, + #{fileType, jdbcType=VARCHAR}, + #{standNumber, jdbcType=VARCHAR}, + #{standName, jdbcType=VARCHAR}, + + + + + + update OCR_RECORD + set word_file_code = #{wordFileCode}, + json_file_code = #{jsonFileCode}, + doc_real_name = #{docRealName}, + json_real_name = #{jsonRealName}, + file_name = #{fileName}, + doc_name = #{docName}, + json_name = #{jsonName}, + creation_time = #{creationTime}, + modify_time = #{modifyTime} + where id = #{id} + + + + + update OCR_RECORD + + + word_file_code = #{wordFileCode}, + + + json_file_code = #{jsonFileCode}, + + + doc_real_name = #{docRealName}, + + + json_real_name = #{jsonRealName}, + + + file_name = #{fileName}, + + + doc_name = #{docName}, + + + json_name = #{jsonName}, + + + creation_time = #{creationTime}, + + + modify_time = #{modifyTime}, + + + result_content = #{resultContent}, + + + file_type = #{fileType}, + + + stand_number = #{standNumber}, + + + stand_name = #{standName}, + + + where id = #{id} + + + + + + + + delete from OCR_RECORD + where id = #{value} + + + + + + + + + + + + + + + + + delete from OCR_RECORD + where id in + + #{item} + + + + diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/page/BasePage.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/page/BasePage.java new file mode 100644 index 00000000..757becb3 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/page/BasePage.java @@ -0,0 +1,102 @@ +package com.jero.modules.laws.ocr.page; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.jero.modules.split.common.Pager; + +public class BasePage { + @TableField(exist = false) + private Integer page = 1; + @TableField(exist = false) + private Integer pageSize = 20; + @TableField(exist = false) + private Integer startIndex; + @TableField(exist = false) + private Integer endIndex; + @TableField(exist = false) + private String orderBy; + @TableField(exist = false) + private String order; + @TableField(exist = false) + private String q; + @TableField(exist = false) + private Pager pager = new Pager(); + + public BasePage() { + } + + public Pager getPager() { + this.pager.setPageId(this.getPage()); + this.pager.setPageSize(this.getPageSize()); + String orderField = ""; + if (this.orderBy != null && this.orderBy.trim().length() > 0) { + orderField = this.orderBy; + } + + if (orderField.trim().length() > 0 && this.order != null && this.order.trim().length() > 0) { + orderField = orderField + " " + this.order; + } + + this.pager.setOrderField(orderField); + return this.pager; + } + + public void setPager(Pager pager) { + this.pager = pager; + } + + public Integer getPage() { + return this.page; + } + + public void setPage(Integer page) { + this.page = page; + } + + public Integer getPageSize() { + return this.pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public String getOrderBy() { + return this.orderBy; + } + + public void setOrderBy(String orderBy) { + this.orderBy = orderBy; + } + + public String getOrder() { + return this.order; + } + + public void setOrder(String order) { + this.order = order; + } + + public String getQ() { + return this.q; + } + + public void setQ(String q) { + this.q = q; + } + + public Integer getStartIndex() { + return this.startIndex; + } + + public void setStartIndex(Integer startIndex) { + this.startIndex = (this.page - 1) * this.pageSize + 1; + } + + public Integer getEndIndex() { + return this.endIndex; + } + + public void setEndIndex(Integer endIndex) { + this.endIndex = this.page * this.pageSize; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/page/OcrRecordEOPage.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/page/OcrRecordEOPage.java new file mode 100644 index 00000000..720fb575 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/page/OcrRecordEOPage.java @@ -0,0 +1,255 @@ +package com.jero.modules.laws.ocr.page; + + +/** + * 功能:OCR_RECORD OcrRecordEOPage
    + * 作者:code generator
    + * 日期: 2019-03-25
    + * 版权所有:版权归北京卡达克数据技术中心所有。
    + */ +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; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/OCRRestfulService.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/OCRRestfulService.java new file mode 100644 index 00000000..dfeace5f --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/OCRRestfulService.java @@ -0,0 +1,15 @@ +package com.jero.modules.laws.ocr.service; + +import com.jero.modules.laws.ocr.entity.OcrRecordEO; +import com.jero.modules.laws.ocr.http.ResponseMessage; +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; + +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/OcrRecordEOService.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/OcrRecordEOService.java new file mode 100644 index 00000000..4e3b3617 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/OcrRecordEOService.java @@ -0,0 +1,18 @@ +package com.jero.modules.laws.ocr.service; + + +import com.jero.modules.laws.ocr.entity.OcrRecordEO; +import com.jero.modules.laws.ocr.page.OcrRecordEOPage; + +import java.util.List; + +public interface OcrRecordEOService { + + List queryByPage(OcrRecordEOPage page); + + Integer queryByPageCount(OcrRecordEOPage page); + + int updateByPrimaryKeySelective(OcrRecordEO ocrRecordEO); + + int deleteByIds(List idList); +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/impl/OCRRestfulServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/impl/OCRRestfulServiceImpl.java new file mode 100644 index 00000000..96e421af --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/impl/OCRRestfulServiceImpl.java @@ -0,0 +1,230 @@ +package com.jero.modules.laws.ocr.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.jero.modules.laws.ocr.Base64Util; +import com.jero.modules.laws.ocr.OkHttpUtil; +import com.jero.modules.laws.ocr.RsaUtil; +import com.jero.modules.laws.ocr.UUIDUtils; +import com.jero.modules.laws.ocr.mapper.OcrRecordEOMapper; +import com.jero.modules.laws.ocr.entity.OcrRecordEO; +import com.jero.modules.laws.ocr.entity.OcrResultEo; +import com.jero.modules.laws.ocr.http.ResponseMessage; +import com.jero.modules.laws.ocr.http.Result; +import com.jero.modules.laws.ocr.service.OCRRestfulService; +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.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@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 OkHttpUtil okHttpUtil; + @Autowired + private OcrRecordEOMapper ocrRecordEOMapper; + //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失败"); + } + SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss"); + try{ + //ResponseEntity responseEntity = restTemplate.postForEntity(RestHandleFileUrl, httpEntity, String.class); + Map map = new HashMap<>(); + map.put("userId",OcrUserId); + map.put("authCode",authCode); + map.put("convertType",convertType); + map.put("fileName",fileName); + map.put("fileContent",fileContent); + map.put("taskId",taskId); + map.put("callBackUrl",RestCallBackUrl); + map.put("callBackMethod",""); + logger.info("处理完文件数据,开始请求OCR接口数据:【"+sdf.format(new Date())+"】"); + String result = okHttpUtil.post(RestHandleFileUrl,map,new HashMap<>()); + logger.info("okHttp结果:"+result); + logger.info("请求OCR接口完毕,返回响应状态:【"+sdf.format(new Date())+"】"); + if(!result.contains("请求成功")){ + logger.error("请求出现异常:"+result); + return Result.error("请求出现异常"); + }else{ + OcrResultEo ocrResultEo = JSONObject.parseObject(result, 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()); + ocrRecordEOMapper.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()); + ocrRecordEOMapper.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); + ocrRecordEOMapper.updateByPrimaryKeySelective(ocrRecordEO); + } + + public String OcrHandleResult(MultipartFile wordFile,MultipartFile jsonFile,String taskId) throws Exception { + //首先将文件保存至本地 + String saveWordFilePath=null; + String saveWordFileName=null; + logger.info("将文件保存至本地"); + if(wordFile!=null && !wordFile.isEmpty()){ + saveWordFileName=UUIDUtils.randomUUID20()+"_"+wordFile.getOriginalFilename().replace("/","_"); + saveWordFilePath=ocrFilePath+saveWordFileName; + logger.info(saveWordFilePath); + //生成保存文件 + File saveWordFile = new File(saveWordFilePath); + System.out.println(saveWordFile); + wordFile.transferTo(saveWordFile); +// FileUtils.copyInputStreamToFile(wordFile.getInputStream(),new File(saveWordFilePath)); +// savePic(wordFile.getInputStream(),saveWordFilePath); + logger.info("word存储完成"); + } + String saveJsonFilePath=null; + String saveJsonFileName=null; + if(jsonFile!=null && !jsonFile.isEmpty()){ + saveJsonFileName=UUIDUtils.randomUUID20()+"_"+jsonFile.getOriginalFilename().replace("/","_"); + saveJsonFilePath=ocrFilePath+saveJsonFileName; + logger.info(saveJsonFilePath); + File saveJsonFile = new File(saveJsonFilePath); + System.out.println(saveJsonFile); + jsonFile.transferTo(saveJsonFile); +// FileUtils.copyInputStreamToFile(jsonFile.getInputStream(),new File(saveJsonFilePath)); +// savePic(jsonFile.getInputStream(),saveJsonFilePath); + logger.info("Json存储完成"); + } + //开始将文件保存至数据库中 + 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("转换成功"); + ocrRecordEOMapper.updateByPrimaryKeySelective(ocrRecordEO); + return "{\"result\":\"success\"}"; + }else{ + updateDb(taskId,"error:File does not exist"); + return "{\"result\":\"error:File does not exist\"}";//文件不存在 + } + } + + private void savePic(InputStream inputStream, String filePath) { + + OutputStream os = null; + try { + // 2、保存到临时文件 + // 1K的数据缓冲 + byte[] bs = new byte[1024]; + // 读取到的数据长度 + int len; + // 输出的文件流保存到本地文件 + + File tempFile = new File(ocrFilePath); + if (!tempFile.exists()) { + tempFile.mkdirs(); + } + os = new FileOutputStream(filePath); + // 开始读取 + while ((len = inputStream.read(bs)) != -1) { + os.write(bs, 0, len); + } + + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 完毕,关闭所有链接 + try { + os.close(); + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/impl/OcrRecordEOServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/impl/OcrRecordEOServiceImpl.java new file mode 100644 index 00000000..233ada96 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/service/impl/OcrRecordEOServiceImpl.java @@ -0,0 +1,44 @@ +package com.jero.modules.laws.ocr.service.impl; + +import com.jero.modules.laws.ocr.mapper.OcrRecordEOMapper; +import com.jero.modules.laws.ocr.entity.OcrRecordEO; +import com.jero.modules.laws.ocr.page.OcrRecordEOPage; +import com.jero.modules.laws.ocr.service.OcrRecordEOService; +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 OcrRecordEOMapper ocrRecordEOMapper; + + @Override + public List queryByPage(OcrRecordEOPage page) { + return ocrRecordEOMapper.queryByPage(page); + } + + @Override + public Integer queryByPageCount(OcrRecordEOPage page) { + return ocrRecordEOMapper.queryByPageCount(page); + } + + @Override + public int updateByPrimaryKeySelective(OcrRecordEO ocrRecordEO) { + return ocrRecordEOMapper.updateByPrimaryKeySelective(ocrRecordEO); + } + + @Override + public int deleteByIds(List idList){ + return ocrRecordEOMapper.deleteByIds(idList); + } + +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/ocr/web/BaseController.java b/laws-modules/src/main/java/com/jero/modules/laws/ocr/web/BaseController.java new file mode 100644 index 00000000..3d617b10 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/ocr/web/BaseController.java @@ -0,0 +1,82 @@ +package com.jero.modules.laws.ocr.web; + + +import com.jero.modules.laws.ocr.http.PageInfo; +import com.jero.modules.split.common.Pager; + +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class BaseController { + private static final String DATA = "data"; + private static final String TOTAL = "total"; + + protected BaseController() { + } + + public PageInfo getPageInfo(Pager pager, List rows) { + PageInfo pageInfo = new PageInfo(); + pageInfo.setList(rows); + pageInfo.setCount((long)pager.getRowCount()); + pageInfo.setPageSize(pager.getPageSize()); + pageInfo.setPageCount((long)pager.getPageCount()); + pageInfo.setPageNo(pager.getPageId()); + return pageInfo; + } + + public static Map getGridData(int total, List rows) { + Map response = new HashMap(); + response.put("total", total); + response.put("data", rows); + return response; + } + + public static Map getData(Object data) { + Map response = new HashMap(); + response.put("data", data); + return response; + } + + public static void download(HttpServletResponse response, File file) throws IOException { + download(response, file, file.getName()); + } + + public static void download(HttpServletResponse response, File file, String fileName) throws IOException { + FileInputStream in = new FileInputStream(file); + Throwable var4 = null; + + try { + download(response, (InputStream)in, fileName); + } catch (Throwable var13) { + var4 = var13; + throw var13; + } finally { + if (in != null) { + if (var4 != null) { + try { + in.close(); + } catch (Throwable var12) { + var4.addSuppressed(var12); + } + } else { + in.close(); + } + } + + } + + } + + public static void download(HttpServletResponse response, InputStream in, String fileName) throws IOException { + response.setContentType("application/x-msdownload;"); + response.addHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); + response.setCharacterEncoding("UTF-8"); + } +} diff --git a/laws-single-startup/src/main/resources/application-dev.yml b/laws-single-startup/src/main/resources/application-dev.yml index a4fa6422..1103685d 100644 --- a/laws-single-startup/src/main/resources/application-dev.yml +++ b/laws-single-startup/src/main/resources/application-dev.yml @@ -522,3 +522,19 @@ bindPart: auth_username: CNHTC_PO_PSRMS #Authorization auth_password: Cnhtcpsrms2024 + +# 云端OCR识别集成配置参数 +OCR: + #OCR请求识别URL地址 + handleFileUrl: http://61.136.1.103:8091/WebService.asmx/FileConversion + # OCR回调接口地址 配置客户本地的IP及端口号 + callBackUrl: https://srms.foton.com.cn/laws/ocr/OCRRestful/OcrHandleResult + userId: dayuzhou1234 + authCode: 123456 + publicKey: EC4KKA6ZDTCPAOCRBC5M + # OCR文件存储路径 + ocrPath: /data/slrs/ocrResultFile/ + # OCR文件请求下载或在线预览时URL + ocrDownPath: /data/slrs/ocrResultFile/ + times: 20 + convertType: BOTH