Quellcode durchsuchen

1、ocr拆分;2、link拆分;3、back拆分。

jessie vor 5 Jahren
Ursprung
Commit
597a02bb7a

+ 23 - 3
src/main/java/com/pavis/ai/app/fjsocrasy/common/config/AsyncConfig.java

@@ -11,14 +11,17 @@ import java.util.concurrent.Executor;
 @EnableAsync
 public class AsyncConfig {
 
-    // 声明一个线程池(并指定线程池的名字)
+    /**
+     * 声明一个线程池(并指定线程池的名字)
+     * @return
+     */
     @Bean("ocrFjsExecutor")
-    public Executor recAndSaveExecutor() {
+    public Executor ocrExecutor() {
         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
         //核心线程数2:线程池创建时候初始化的线程数
         executor.setCorePoolSize(3);
         //最大线程数5:线程池最大的线程数,只有在缓冲队列满了之后才会申请超过核心线程数的线程
-        executor.setMaxPoolSize(3);
+        executor.setMaxPoolSize(5);
         //缓冲队列180:用来缓冲执行任务的队列
         executor.setQueueCapacity(10);
         //允许线程的空闲时间60秒:当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
@@ -28,4 +31,21 @@ public class AsyncConfig {
         executor.initialize();
         return executor;
     }
+
+    @Bean("linkFjsExecutor")
+    public Executor linkExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        //核心线程数2:线程池创建时候初始化的线程数
+        executor.setCorePoolSize(5);
+        //最大线程数5:线程池最大的线程数,只有在缓冲队列满了之后才会申请超过核心线程数的线程
+        executor.setMaxPoolSize(10);
+        //缓冲队列180:用来缓冲执行任务的队列
+        executor.setQueueCapacity(10);
+        //允许线程的空闲时间60秒:当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
+        executor.setKeepAliveSeconds(60);
+        //线程池名的前缀:设置好了之后可以方便我们定位处理任务所在的线程池
+        executor.setThreadNamePrefix("Async-LinkFjs-");
+        executor.initialize();
+        return executor;
+    }
 }

+ 65 - 58
src/main/java/com/pavis/ai/app/fjsocrasy/controller/BackController.java

@@ -56,19 +56,18 @@ public class BackController {
     private static final String TYPE_FOURTEEN = "14";
     private static final String TYPE_FIFTEEN = "15";
     private static final String TYPE_SIXTEEN = "16";
-    @Autowired
-    private InternalSendService internalSendService;
 
     @Autowired
-    private CommonProperties commonProperties;
-
+    private OcrService ocrService;
 
     @Autowired
     private UploadService uploadService;
 
     @Autowired
-    private OcrService ocrService;
+    private CommonProperties commonProperties;
 
+    @Autowired
+    private InternalSendService internalSendService;
 
     @Autowired
     private RecommendInfoService recommendInfoService;
@@ -147,12 +146,21 @@ public class BackController {
         return reqId.equals("null") ? boId : reqId;
     }
 
-    @ApiOperation("获取midOcr结果接口")
-    @ApiOperationSupport(order = 4)
-    @PostMapping("/api/mid")
-    public ResultBody send(String reqId, String fileType) {
-        List list = uploadService.findMidOcr(reqId, fileType);
-        return ResultBody.ok().data(list);
+    @ApiOperation("排查问题接口")
+    @ApiOperationSupport(order = 1)
+    @PostMapping("/tes")
+    public ResultBody tes() {
+        String sourceDate = DateUtils.createFilesByDate();
+        log.info("test date:{}", sourceDate);
+        String date = uploadService.tes();
+        log.info("res date:{}", date);
+
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
+        Date dat = new Date(System.currentTimeMillis());
+        String dataStr = formatter.format(dat);
+        log.info("other method dataStr:{}", dataStr);
+        String finalDate = "sourceDate: " + sourceDate + ",date: " + date + ",other date: " + dataStr;
+        return ResultBody.ok().msg("获取成功").data(finalDate);
     }
 
     @ApiOperation("富士通图片识别同步接口 内部测试用")
@@ -190,27 +198,7 @@ public class BackController {
         }
     }
 
-    @ApiOperation("印章检测本地测试接口")
-    @ApiOperationSupport(order = 7)
-    @PostMapping("/api/sign")
-    public ResultBody testSign(@RequestParam("files") MultipartFile[] files) throws Exception {
-        // String url = "http://192.168.1.73:18000/down/fjs/3/20200622/3_11a238f7-eba8-4dbd-a04d-05500a62a2c8.jpg";
-        // Map<String, Object> urlMap = new HashMap<>();
-        // urlMap.put("url",url);
-        // return ResultBody.ok().data(internalSendService.testSign(url));
-        long startTime = System.currentTimeMillis();
-        uploadService.upload("tes20200622","3","{}",files,startTime);
-        return ResultBody.ok().data(internalSendService.testSign("1"));
-    }
-
 
-    @ApiOperation("本地回传接口")
-    @ApiOperationSupport(order = 5)
-    @PostMapping(value = "/api/receive", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = "application/json")
-    public ResultBody send(@RequestBody SendData data) {
-        System.err.println("回传data>>>" + JSON.toJSONString(data));
-        return ResultBody.ok().data(System.currentTimeMillis());
-    }
 
     @ApiOperation("富士通图片识别异步接口")
     @ApiOperationSupport(order = 3)
@@ -231,6 +219,50 @@ public class BackController {
         return ResultBody.failed().path("/api/fjs/ocr").data(null).msg("参数不能为空,请仔细检查参数后重试。");
     }
 
+    @ApiOperation("获取midOcr结果接口")
+    @ApiOperationSupport(order = 4)
+    @PostMapping("/api/mid")
+    public ResultBody send(String reqId, String fileType) {
+        List list = uploadService.findMidOcr(reqId, fileType);
+        return ResultBody.ok().data(list);
+    }
+
+
+
+    @ApiOperation("本地回传接口")
+    @ApiOperationSupport(order = 5)
+    @PostMapping(value = "/api/receive", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = "application/json")
+    public ResultBody send(@RequestBody SendData data) {
+        System.err.println("回传data>>>" + JSON.toJSONString(data));
+        return ResultBody.ok().data(System.currentTimeMillis());
+    }
+
+    @ApiOperation("推荐人联系方式维护接口")
+    @ApiOperationSupport(order = 6)
+    @PostMapping("/importRecommendInfo")
+    public ResultBody importRecommendInfo(@RequestParam("files") MultipartFile[] files) {
+        int savedId = recommendInfoService.recommdInfoImport(files);
+        if (savedId > 0 && savedId != 3) {
+            return ResultBody.ok().msg("数据导入成功").data(savedId);
+        } else {
+            return ResultBody.failed().msg(savedId == 3 ? "该数据已存在请勿重复录入" : "数据导入失败").data(savedId);
+        }
+    }
+
+    @ApiOperation("印章检测本地测试接口")
+    @ApiOperationSupport(order = 7)
+    @PostMapping("/api/sign")
+    public ResultBody testSign(@RequestParam("files") MultipartFile[] files) throws Exception {
+        // String url = "http://192.168.1.73:18000/down/fjs/3/20200622/3_11a238f7-eba8-4dbd-a04d-05500a62a2c8.jpg";
+        // Map<String, Object> urlMap = new HashMap<>();
+        // urlMap.put("url",url);
+        // return ResultBody.ok().data(internalSendService.testSign(url));
+        long startTime = System.currentTimeMillis();
+        uploadService.upload("tes20200622","3","{}",files,startTime);
+        return ResultBody.ok().data(internalSendService.testSign("1"));
+    }
+
+
     // @ApiOperation("Api接口每分钟访问次数限制")
     // @AuthIgnore
     // @PostMapping("getImpose")
@@ -252,37 +284,12 @@ public class BackController {
     //     return data;
     // }
 
-    @ApiOperation("排查问题接口")
-    @ApiOperationSupport(order = 1)
-    @PostMapping("/tes")
-    public ResultBody tes() {
-        String sourceDate = DateUtils.createFilesByDate();
-        log.info("test date:{}", sourceDate);
-        String date = uploadService.tes();
-        log.info("res date:{}", date);
 
-        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
-        Date dat = new Date(System.currentTimeMillis());
-        String dataStr = formatter.format(dat);
-        log.info("other method dataStr:{}", dataStr);
-        String finalDate = "sourceDate: " + sourceDate + ",date: " + date + ",other date: " + dataStr;
-        return ResultBody.ok().msg("获取成功").data(finalDate);
-    }
 
-    @ApiOperation("推荐人联系方式维护接口")
-    @ApiOperationSupport(order = 6)
-    @PostMapping("/importRecommendInfo")
-    public ResultBody importRecommendInfo(@RequestParam("files") MultipartFile[] files) {
-        int savedId = recommendInfoService.recommdInfoImport(files);
-        if (savedId > 0 && savedId != 3) {
-            return ResultBody.ok().msg("数据导入成功").data(savedId);
-        } else {
-            return ResultBody.failed().msg(savedId == 3 ? "该数据已存在请勿重复录入" : "数据导入失败").data(savedId);
-        }
-    }
+
 
     @ApiOperation("历史版本获取接口")
-    @ApiOperationSupport(order = 1)
+    @ApiOperationSupport(order = 10)
     @GetMapping("/version")
     public ResultBody version() {
         List<ProVersion> vers = getVersions();

+ 5 - 3
src/main/java/com/pavis/ai/app/fjsocrasy/controller/OcrController.java

@@ -33,12 +33,14 @@ import java.util.Map;
 @RequestMapping("/api")
 public class OcrController {
 
-    @Autowired
-    private UploadService uploadService;
 
     @Autowired
     private OcrService ocrService;
 
+    @Autowired
+    private UploadService uploadService;
+
+
     /**
      * 异步请求。
      * @param reqId
@@ -56,7 +58,7 @@ public class OcrController {
                 List<FileDetails> paths = uploadService.upload(reqId,fileType,data,files,startTime);
                 // uploadService.upload(reqId,fileType,data,files,startTime);
                 long endTime = System.currentTimeMillis();
-                log.info("upload excTime:{}", DateUtils.getExcTime(startTime,endTime));
+                log.info("step1 upload excTime:{}", DateUtils.getExcTime(startTime,endTime));
                 if (paths.size() > 0){
                     return ResultBody.ok().path("/api/fjs/ocr").data(reqId).msg("上传成功");
                 }else {

+ 49 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/BackService.java

@@ -0,0 +1,49 @@
+package com.pavis.ai.app.fjsocrasy.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.pavis.ai.app.fjsocrasy.form.res.ResData;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.Map;
+
+/**
+ * @author guanhuijuan
+ * @create 2020-07-08 15:19
+ * @desc BackService
+ **/
+public interface BackService {
+
+    /**
+     * 返回函数。
+     * @param fileType
+     * @param reqId
+     * @param startTime
+     * @param ocr
+     */
+    void back(String fileType, String reqId, Long startTime, JSONObject ocr);
+
+    /**
+     * 返回数据至富士通。
+     * @param resData
+     * @param reqId
+     * @param excTime
+     * @param code
+     */
+    void backToFjs(ResData resData, String reqId, Long startTime, String code);
+
+    /**
+     * 返回提示信息构造。
+     * @param code
+     * @param resData
+     * @return
+     */
+    Map<String, Object> res(String code, ResData resData);
+    /**
+     * 构造空返回数据。和富士通想要数据结构保持一致。
+     * @param reqId
+     * @param templateType
+     * @return
+     */
+    ResData getNullBackResData(String reqId, String templateType);
+}

+ 2 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/DealService.java

@@ -2,12 +2,14 @@ package com.pavis.ai.app.fjsocrasy.service;
 
 import org.springframework.amqp.rabbit.connection.CorrelationData;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.stereotype.Service;
 
 /**
  * @Author: guanhuijuan
  * @Description: 消息发送
  * @Date: 2020/4/17_12:31
  */
+
 public interface DealService extends RabbitTemplate.ConfirmCallback  {
 
     /**

+ 30 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/LinkService.java

@@ -0,0 +1,30 @@
+package com.pavis.ai.app.fjsocrasy.service;
+
+import com.pavis.ai.app.fjsocrasy.form.FileDetails;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author guanhuijuan
+ * @create 2020-07-08 15:18
+ * @desc LinkService
+ **/
+public interface LinkService {
+
+    /**
+     * 调用相似匹配算法。
+     * @param reqId
+     * @param type
+     * @param startTime
+     * @param sourceData
+     * @param ocrData
+     * @param accJson
+     * @param recommends
+     */
+    void match(String reqId,String type,Long startTime,String sourceData, String ocrData,String mideOcr, String accJson, String recommends);
+
+
+}

+ 4 - 31
src/main/java/com/pavis/ai/app/fjsocrasy/service/OcrService.java

@@ -2,6 +2,7 @@ package com.pavis.ai.app.fjsocrasy.service;
 
 import com.pavis.ai.app.fjsocrasy.form.FileDetails;
 import com.pavis.ai.app.fjsocrasy.form.res.ResData;
+import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
@@ -15,17 +16,6 @@ import java.util.Map;
  **/
 public interface OcrService {
 
-    /**
-     * 调用ocr。
-     * @param reqId
-     * @param fileType
-     * @param data
-     * @param files
-     * @param startTime
-     * @param parsedFilePaths
-     * @throws IOException
-     */
-    void uploading(String reqId, String fileType, String data, MultipartFile[] files, Long startTime, List<FileDetails> parsedFilePaths) throws IOException;
 
 
     /**
@@ -39,19 +29,8 @@ public interface OcrService {
      * @return
      * @throws IOException
      */
-    Map<String,Object> toOcr(String reqId, String fileType, String url, String fileName, String data, Long startTime) throws IOException;
+    void toOcr(String reqId, String fileType, String url, String fileName, String data, Long startTime) throws IOException;
 
-    /**
-     * 调用相似匹配算法。
-     * @param reqId
-     * @param type
-     * @param startTime
-     * @param sourceData
-     * @param ocrData
-     * @param accJson
-     * @param recommends
-     */
-    void matching(String reqId,String type,String startTime,String sourceData, String ocrData,String mideOcr, String accJson, String recommends);
 
     /**
      * 识别处理。
@@ -64,13 +43,7 @@ public interface OcrService {
      */
     void ocr(String reqId, String fileType, String url, String fileName, String data, Long startTime) throws IOException;
 
-    /**
-     * 返回提示信息构造。
-     * @param code
-     * @param resData
-     * @return
-     */
-    Map<String, Object> res(String code, ResData resData);
+
 
     /**
      * 构造空返回数据。和富士通想要数据结构保持一致。
@@ -78,7 +51,7 @@ public interface OcrService {
      * @param templateType
      * @return
      */
-    ResData getNullBackResData(String reqId, String templateType);
+    // ResData getNullBackResData(String reqId, String templateType);
 
     /**
      * 同步

+ 2 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/OpService.java

@@ -1,5 +1,7 @@
 package com.pavis.ai.app.fjsocrasy.service;
 
+import org.springframework.stereotype.Service;
+
 import java.io.IOException;
 
 /**

+ 28 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/OtherService.java

@@ -0,0 +1,28 @@
+package com.pavis.ai.app.fjsocrasy.service;
+
+import com.pavis.ai.app.fjsocrasy.form.FileDetails;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author guanhuijuan
+ * @create 2020-07-08 19:26
+ * @desc OtherService
+ **/
+public interface OtherService {
+    /**
+     * 调用ocr。
+     * @param reqId
+     * @param fileType
+     * @param data
+     * @param files
+     * @param startTime
+     * @param parsedFilePaths
+     * @throws IOException
+     */
+    void uploading(String reqId, String fileType, String data, MultipartFile[] files, Long startTime, List<FileDetails> parsedFilePaths) throws IOException;
+
+
+}

+ 1 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/RecommendInfoService.java

@@ -2,6 +2,7 @@ package com.pavis.ai.app.fjsocrasy.service;
 
 import com.pavis.ai.app.fjsocrasy.common.utils.excel.Recommends;
 import com.pavis.ai.app.fjsocrasy.model.RecommendInfo;
+import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;

+ 1 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/UploadService.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.pavis.ai.app.fjsocrasy.form.FileDetails;
 import com.pavis.ai.app.fjsocrasy.form.res.ResData;
 import com.pavis.ai.app.fjsocrasy.model.Upload;
+import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;

+ 366 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/impl/BackServiceImpl.java

@@ -0,0 +1,366 @@
+package com.pavis.ai.app.fjsocrasy.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.pavis.ai.app.fjsocrasy.common.utils.DateUtils;
+import com.pavis.ai.app.fjsocrasy.common.utils.ocr.ParseUtils;
+import com.pavis.ai.app.fjsocrasy.form.eight.EnjoyLoansToClient;
+import com.pavis.ai.app.fjsocrasy.form.eleven.IdCardReverse;
+import com.pavis.ai.app.fjsocrasy.form.fifteen.LetterOfCreditCommitment;
+import com.pavis.ai.app.fjsocrasy.form.five.CreditLoanUseContract;
+import com.pavis.ai.app.fjsocrasy.form.four.CreditConfirmationLetter;
+import com.pavis.ai.app.fjsocrasy.form.fourteen.EnjoyLoanApplicationForm;
+import com.pavis.ai.app.fjsocrasy.form.nine.EnjoyLoansConfirm;
+import com.pavis.ai.app.fjsocrasy.form.one.PciiAuth;
+import com.pavis.ai.app.fjsocrasy.form.res.BackData;
+import com.pavis.ai.app.fjsocrasy.form.res.ResData;
+import com.pavis.ai.app.fjsocrasy.form.seven.LoanPurposeCommitment;
+import com.pavis.ai.app.fjsocrasy.form.seventeen.LoanApplicationFormEnjoyELoan;
+import com.pavis.ai.app.fjsocrasy.form.six.ConsumerFinanceHandlingInstructions;
+import com.pavis.ai.app.fjsocrasy.form.sixteen.LeEnjoyLoanCommitmentLetter;
+import com.pavis.ai.app.fjsocrasy.form.ten.IdCardFront;
+import com.pavis.ai.app.fjsocrasy.form.thirteen.PayAndEnjoyLoanApplicationForm;
+import com.pavis.ai.app.fjsocrasy.form.three.RecommendationLetter;
+import com.pavis.ai.app.fjsocrasy.form.twelve.PersonalInfoUseAuthorization;
+import com.pavis.ai.app.fjsocrasy.form.two.LoanApplicationForm;
+import com.pavis.ai.app.fjsocrasy.service.BackService;
+import com.pavis.ai.app.fjsocrasy.service.EternalSendService;
+import com.pavis.ai.app.fjsocrasy.service.OcrService;
+import com.pavis.ai.app.fjsocrasy.service.UploadService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author guanhuijuan
+ * @create 2020-07-08 15:19
+ * @desc
+ **/
+@Slf4j
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class BackServiceImpl implements BackService {
+
+
+    @Autowired
+    private UploadService uploadService;
+
+
+    @Autowired
+    private EternalSendService eternalSendService;
+
+    @Override
+    public void back(String fileType,String reqId,Long startTime,JSONObject ocr) {
+        // log.info("step ***4: back***");
+        if (fileType.equals("10") || fileType.equals("11")){
+            // 类型10、11意常情况返回。
+            JSONObject midOcr = fileType.equals("10") ? ParseUtils.midOcrFront(false,"-1",fileType,"")
+                    : ParseUtils.midOcrReverse(false,"-1",fileType,"");
+            // todo 直接返回,不用在调用match函数。
+            uploadService.saveBack(getNullBackResData(reqId, fileType), JSON.toJSONString(midOcr),startTime);
+            boolean flag = null != ocr ? ocr.get("image_status").equals("non_idcard") ? true : false : false;
+            backToFjs(getNullBackResData(reqId, fileType), reqId, startTime, flag ? "-1" : "0");
+            long endTime = System.currentTimeMillis();
+            log.info("ocr-ex back excTime:{}", DateUtils.getExcTime(startTime,endTime));
+
+        }else {
+            if (null != ocr && ocr.get("code").toString().equals("-1")) {
+                // 图片不符情况返回。
+                // todo 直接返回,不用在调用match函数。
+                uploadService.saveBack(getNullBackResData(reqId, fileType), JSON.toJSONString(ocr), startTime);
+                backToFjs(getNullBackResData(reqId, fileType), reqId, startTime, ocr.get("code").toString());
+                long endTime = System.currentTimeMillis();
+                log.info("ocr-ex back excTime:{}", DateUtils.getExcTime(startTime, endTime));
+            }else {
+                // 算法异常情况返回。
+                uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
+                backToFjs(getNullBackResData(reqId, fileType), reqId, startTime, ocr.get("code").toString());
+                long endTime = System.currentTimeMillis();
+                log.info("ocr-ex back excTime:{}", DateUtils.getExcTime(startTime,endTime));
+            }
+        }
+    }
+
+    /**
+     * todo 回传函数。
+     *
+     * @param resData
+     * @param reqId
+     * @param startTime
+     * @param code
+     */
+    @Override
+    public void backToFjs(ResData resData, String reqId, Long startTime, String code) {
+        log.info("step ***4: back***");
+        log.info("开始回传:{}", reqId);
+        // todo 记得清除。
+        String result = "";
+        if (code.equals("1")) {
+            result = JSON.toJSONString(res(code, resData));
+        } else {
+            result = JSON.toJSONString(res(code, resData));
+        }
+        // todo ghj-online 上线时放开。
+        String backRes = eternalSendService.send(result);
+        long endTime = System.currentTimeMillis();
+        String excTime = DateUtils.getExcTime(startTime, endTime);
+        log.info("fjs back time:{}",excTime);
+        // todo ghj-online 上线时注释掉,本地自己接收。
+        // SendData sendData = JSONObject.parseObject(result, SendData.class);
+        // sendData.setData(resData);
+        // String backRes = sendService.send(JSON.toJSONString(sendData));
+        log.info("回传响应backRes:{}", backRes);
+        log.info("回传结束!回传信息详情:{}", result);
+    }
+
+    @Override
+    public Map<String, Object> res(String code, ResData resData) {
+        log.info("res code:{}", code);
+        Map<String, Object> map = new HashMap<>();
+        map.put("code", code.equals("1") ? "0" : "1");
+        map.put("message", code.equals("1") ? "识别成功" : code.equals("-1") ? "文件内容不符,请上传正确的文件后重试。" :
+                code.equals("-3") ? "请确保文件大小不超出4M,且最长边不超过4096像素" : "未识别出数据,请确保上传为正确文件后重试");
+        map.put("reqId", resData.getReqId());
+        map.put("fileType", resData.getType());
+        map.put("data", resData.getRes());
+        // 20200507 新增回传参数:
+        map.put("overallConfidence",code.equals("-1") ? "0" : resData.getOverallConfidence());
+        map.put("midConfidence",code.equals("-1") ? "0" : resData.getMidConfidence());
+        return map;
+    }
+
+    @Override
+    public ResData getNullBackResData(String reqId, String templateType) {
+        ResData resData = new ResData();
+        try {
+            resData = new ResData();
+            switch (templateType) {
+                case "1":
+                    PciiAuth pciiAuth = new PciiAuth(new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(pciiAuth);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "2":
+                    // 待开发
+                    LoanApplicationForm loanApplicationForm = new LoanApplicationForm(new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(loanApplicationForm);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "3":
+                    // 待开发
+                    RecommendationLetter recommendationLetter = new RecommendationLetter(new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(recommendationLetter);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "4":
+                    // 待开发
+                    CreditConfirmationLetter creditConfirmationLetter = new CreditConfirmationLetter(new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(creditConfirmationLetter);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "5":
+                    // 待开发
+                    CreditLoanUseContract creditLoanUseContract = new CreditLoanUseContract(new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(creditLoanUseContract);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "6":
+                    // 待开发
+                    ConsumerFinanceHandlingInstructions consumerFinanceHandlingInstructions = new ConsumerFinanceHandlingInstructions(new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(consumerFinanceHandlingInstructions);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "7":
+                    // 待开发
+                    LoanPurposeCommitment loanPurposeCommitment = new LoanPurposeCommitment(new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(loanPurposeCommitment);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "8":
+                    // 待开发
+                    EnjoyLoansToClient enjoyLoansToClient = new EnjoyLoansToClient(new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(enjoyLoansToClient);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "9":
+                    // 待开发
+                    EnjoyLoansConfirm enjoyLoansConfirm = new EnjoyLoansConfirm(new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(enjoyLoansConfirm);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "10":
+                    // 待开发
+                    IdCardFront idCardFront = new IdCardFront(new BackData("", "", "","0"),
+                            new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(idCardFront);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "11":
+                    // 待开发
+                    IdCardReverse idCardReverse = new IdCardReverse(new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(idCardReverse);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "12":
+                    // 待开发
+                    PersonalInfoUseAuthorization personalInfoUseAuthorization = new PersonalInfoUseAuthorization(new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(personalInfoUseAuthorization);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "13":
+                    // 待开发
+                    PayAndEnjoyLoanApplicationForm payAndEnjoyLoanApplicationForm = new PayAndEnjoyLoanApplicationForm(new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(payAndEnjoyLoanApplicationForm);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "14":
+                    // 待开发
+                    EnjoyLoanApplicationForm enjoyLoanApplicationForm = new EnjoyLoanApplicationForm(new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0")
+                            // ,new BackData("", "", "","0")
+                    );
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(enjoyLoanApplicationForm);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "15":
+                    // 待开发
+                    LetterOfCreditCommitment letterOfCreditCommitment = new LetterOfCreditCommitment(new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(letterOfCreditCommitment);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "16":
+                    // 待开发
+                    LeEnjoyLoanCommitmentLetter leEnjoyLoanCommitmentLetter = new LeEnjoyLoanCommitmentLetter(new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(leEnjoyLoanCommitmentLetter);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                case "17":
+                    // 待开发
+                    LoanApplicationFormEnjoyELoan loanApplicationFormEnjoyELoan = new LoanApplicationFormEnjoyELoan(new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
+                            new BackData("", "", "","0"));
+                    resData.setReqId(reqId);
+                    resData.setType(templateType);
+                    resData.setRes(loanApplicationFormEnjoyELoan);
+                    resData.setOverallConfidence("2");
+                    resData.setMidConfidence("2");
+                    break;
+                default:
+                    // 待开发
+            }
+            return resData;
+        } catch (Exception e) {
+            log.info("getNullBackResData:{}", e);
+        }
+        resData.setReqId(reqId);
+        resData.setType(templateType);
+        resData.setRes("null");
+        resData.setOverallConfidence("2");
+        resData.setMidConfidence("2");
+        return resData;
+    }
+}

+ 116 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/impl/LinkServiceImpl.java

@@ -0,0 +1,116 @@
+package com.pavis.ai.app.fjsocrasy.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.pavis.ai.app.fjsocrasy.common.config.constants.Constants;
+import com.pavis.ai.app.fjsocrasy.common.utils.DateUtils;
+import com.pavis.ai.app.fjsocrasy.common.utils.ocr.ParseUtils;
+import com.pavis.ai.app.fjsocrasy.form.FileDetails;
+import com.pavis.ai.app.fjsocrasy.form.res.ResData;
+import com.pavis.ai.app.fjsocrasy.service.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.amqp.rabbit.connection.CorrelationData;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * @author guanhuijuan
+ * @create 2020-07-08 15:18
+ * @desc LinkServiceImpl
+ **/
+@Slf4j
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class LinkServiceImpl implements LinkService {
+    @Autowired
+    private InternalSendService internalSendService;
+
+    @Autowired
+    private RecommendInfoService recommendInfoService;
+
+    @Autowired
+    private UploadService uploadService;
+
+    @Autowired
+    private BackService backService;
+
+    @Async("linkFjsExecutor")
+    @Override
+    public void match(String reqId,String type,Long startTime,String sourceData, String ocrData,String mideOcr, String accJson, String recommends) {
+        log.info("step ***3: test&link***");
+        Map<String, Object> matchMap = new HashMap<>();
+        if (type.equals("10") || type.equals("11")){
+            try {
+                JSONObject midOcr = new JSONObject();
+                if (type.equals("10")) {
+                    midOcr = ParseUtils.midOcrFront(true,"1",type,ocrData);
+                } else {
+                    midOcr = ParseUtils.midOcrReverse(true,"1",type,ocrData);
+                }
+                matchMap.put("source_data", sourceData);
+                matchMap.put("ocr_data", ocrData);
+                matchMap.put("acc_json",accJson);
+                matchMap.put("type",type);
+                matchMap.put("recommends",type.equals("3") ? JSON.toJSONString(recommendInfoService.findRecomInfo()) : "[]");
+                // todo 放入队列中处理。
+                String matchRes = internalSendService.match(matchMap);
+                log.info("ocr-matching send back res:{}", matchRes);
+                ResData resData = ParseUtils.parseRes(reqId, type, JSON.parseObject(sourceData),
+                        JSON.parseObject(ocrData), JSON.parseObject(matchRes));
+                uploadService.saveBack(resData,JSON.toJSONString(midOcr),Long.valueOf(startTime));
+                long endTime = System.currentTimeMillis();
+                log.info("step3 link excTime:{}",DateUtils.getExcTime(startTime,endTime));
+                // 4、将结果数据返回至富士通接口。
+                backService.backToFjs(resData, reqId, startTime, "1");
+                // backService.back(type,reqId,Long.valueOf(startTime),JSON.parseObject(mideOcr), reqId, type, "1");
+                endTime = System.currentTimeMillis();
+                log.info("step4 back excTime:{}", DateUtils.getExcTime(startTime,endTime));
+            }catch (Exception ex){
+                log.info("matching:{}", ex);
+            }
+        }else {
+            // 处理类型1、2、3、4、5、6、7、8、9、12、13、14、15、16
+            // 4,8,15,后期可能不要。
+            matchMap.put("source_data", sourceData);
+            matchMap.put("ocr_data", ocrData);
+            matchMap.put("acc_json",accJson);
+            // todo 根据类型3判断该字段是否有值。类型为3时,有值,类型不为3时,已补充。
+            matchMap.put("recommends",type.equals("3") ? JSON.toJSONString(recommendInfoService.findRecomInfo()) : "[]");
+            ResData resData;
+            String bo = StringUtils.substringBeforeLast(reqId,"-");
+            if (uploadService.findLinkByBo(bo).size() > 1){
+                log.info("关联数据START...");
+                // todo ghj link数据部分也要新增类型三的findRecomInfo()数据。已补充。
+                log.info("link param:{}", JSON.toJSONString(matchMap));
+                String matchRes = internalSendService.link(matchMap);
+                resData = ParseUtils.parseRes(reqId, type, JSON.parseObject(sourceData),
+                        JSON.parseObject(ocrData), JSON.parseObject(matchRes));
+            }else {
+                matchMap.put("type",type);
+                log.info("match param:{}", JSON.toJSONString(matchMap));
+                String matchRes = internalSendService.match(matchMap);
+                resData = ParseUtils.parseRes(reqId, type, JSON.parseObject(sourceData),
+                        JSON.parseObject(ocrData), JSON.parseObject(matchRes));
+            }
+            uploadService.saveBack(resData,JSON.toJSONString(JSON.parseObject(mideOcr)),Long.valueOf(startTime));
+            long endTime = System.currentTimeMillis();
+            log.info("step3 link excTime:{}",DateUtils.getExcTime(startTime,endTime));
+            // 4、将结果数据返回至富士通接口。
+            backService.backToFjs(resData, reqId, startTime, JSON.parseObject(mideOcr).get("code").toString());
+            endTime = System.currentTimeMillis();
+            log.info("step4 back excTime:{}", DateUtils.getExcTime(Long.valueOf(startTime),endTime));
+        }
+    }
+
+
+}

+ 63 - 363
src/main/java/com/pavis/ai/app/fjsocrasy/service/impl/OcrServiceImpl.java

@@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.amqp.rabbit.connection.CorrelationData;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -66,27 +67,43 @@ public class OcrServiceImpl implements OcrService {
     private RecommendInfoService recommendInfoService;
 
     @Autowired
-    private DealService dealService;
+    private LinkService linkService;
+
+    @Autowired
+    private BackService backService;
+
+
 
     @Async("ocrFjsExecutor")
     @Override
-    public void uploading(String reqId, String fileType, String data, MultipartFile[] files, Long startTime, List<FileDetails> parsedFilePaths) throws IOException {
-        log.info("step 2");
-        // 2、调用OCR接口,并将返回的ocr数据保存至数据库表。
-        String suffix = files[0].getOriginalFilename().substring(files[0].getOriginalFilename().lastIndexOf("."));
-        String fileName = UUID.randomUUID().toString() + suffix;
-        Map<String,Object> ocrMap = toOcr(reqId, fileType,JSON.toJSONString(parsedFilePaths),fileName,data,startTime);
-        log.info("step 3");
-        // 3、将ocr数据放入队列中。
-        if(null != ocrMap && ocrMap.containsKey("type")){
-            // 放入队列。
-            CorrelationData correlationData = new CorrelationData(reqId);
-            dealService.sendMessage(Constants.ROUTING_OP_KEY, JSON.toJSONString(ocrMap).getBytes(), correlationData);
+    public void toOcr(String reqId, String fileType, String url, String fileName, String data, Long startTime) throws IOException {
+        // 2.2 获取ocr返回值。
+        log.info("step ***2: ocr***");
+        Map<String,Object> ocrMap = toOcrMap(reqId,fileType,url,fileName,data,startTime);
+        System.err.println("***"+JSON.toJSONString(ocrMap));
+        if (null != ocrMap && ocrMap.containsKey("req_id")){
+            // 3、用户画像相似匹配。
+            linkService.match(ocrMap.get("req_id").toString(),ocrMap.get("type").toString(),startTime,
+                    ocrMap.get("source_data").toString(), ocrMap.get("ocr_data").toString(),ocrMap.get("mid_ocr").toString(),ocrMap.get("acc_json").toString(),
+                    ocrMap.get("recommends").toString());
+            long endTime = System.currentTimeMillis();
+            String excTime = DateUtils.getExcTime(startTime, endTime);
+            log.info("match exctime:{}",excTime);
         }
+
     }
 
-    @Override
-    public Map<String, Object> toOcr(String reqId, String fileType, String url, String fileName, String data, Long startTime) throws IOException {
+    /**
+     * ocr识别函数1。
+     * @param reqId
+     * @param fileType
+     * @param url
+     * @param fileName
+     * @param data
+     * @param startTime
+     * @return
+     */
+    public Map<String,Object> toOcrMap(String reqId, String fileType, String url, String fileName, String data, Long startTime){
         Map<String,Object> ocrMap = new HashMap<>();
         try {
             // 解析已处理过的有效的图片url
@@ -109,14 +126,14 @@ public class OcrServiceImpl implements OcrService {
                     // 单文件上传。
                     ocrMap = toSingleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, data,startTime);
                     long endTime = System.currentTimeMillis();
-                    log.info("ocrMap excTime:{}", DateUtils.getExcTime(startTime,endTime));
+                    log.info("step2 ocrMap excTime:{}", DateUtils.getExcTime(startTime,endTime));
                     return ocrMap;
                 }
             } else if (effectiveImgpaths.size() > 1) {
                 // 多文件上传,pdf转图片&两张图片,第8、15、16种。
                 ocrMap = toSingleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, data,startTime);
                 long endTime = System.currentTimeMillis();
-                log.info("ocrMap res excTime:{}", DateUtils.getExcTime(startTime,endTime));
+                log.info("step2 ocrMap excTime:{}", DateUtils.getExcTime(startTime,endTime));
                 return ocrMap;
             } else {
                 // todo 没有图片,不合法等,待开发。
@@ -126,7 +143,7 @@ public class OcrServiceImpl implements OcrService {
                 resData.setRes(null);
                 long endTime = System.currentTimeMillis();
                 back(resData, reqId, DateUtils.getExcTime(startTime,endTime), "0");
-                log.info("ocrMap excTime:{}", DateUtils.getExcTime(startTime,endTime));
+                log.info("step2 ocrMap excTime:{}", DateUtils.getExcTime(startTime,endTime));
             }
         } catch (Exception e) {
             log.info("ocr:{}", e);
@@ -134,67 +151,8 @@ public class OcrServiceImpl implements OcrService {
         return ocrMap;
     }
 
-    @Override
-    public void matching(String reqId,String type,String startTime,String sourceData, String ocrData,String mideOcr, String accJson, String recommends) {
-        Map<String, Object> matchMap = new HashMap<>();
-        if (type.equals("10") || type.equals("11")){
-            try {
-                JSONObject midOcr = new JSONObject();
-                if (type.equals("10")) {
-                    midOcr = ParseUtils.midOcrFront(true,"1",type,ocrData);
-                } else {
-                    midOcr = ParseUtils.midOcrReverse(true,"1",type,ocrData);
-                }
-                matchMap.put("source_data", sourceData);
-                matchMap.put("ocr_data", ocrData);
-                matchMap.put("acc_json",accJson);
-                matchMap.put("type",type);
-                matchMap.put("recommends",type.equals("3") ? JSON.toJSONString(recommendInfoService.findRecomInfo()) : "[]");
-                // todo 放入队列中处理。
-                String matchRes = internalSendService.match(matchMap);
-                log.info("ocr-matching send back res:{}", matchRes);
-                ResData resData = ParseUtils.parseRes(reqId, type, JSON.parseObject(sourceData),
-                        JSON.parseObject(ocrData), JSON.parseObject(matchRes));
-                uploadService.saveBack(resData,JSON.toJSONString(midOcr),Long.valueOf(startTime));
-                back(resData, reqId, type, "1");
-                long endTime = System.currentTimeMillis();
-                log.info("finish excTime:{}", DateUtils.getExcTime(Long.valueOf(startTime),endTime));
-            }catch (Exception ex){
-                log.info("matching:{}", ex);
-            }
-        }else {
-            // 处理类型1、2、3、4、5、6、7、8、9、12、13、14、15、16
-            // 4,8,15,后期可能不要。
-            matchMap.put("source_data", sourceData);
-            matchMap.put("ocr_data", ocrData);
-            matchMap.put("acc_json",accJson);
-            // todo 根据类型3判断该字段是否有值。类型为3时,有值,类型不为3时,已补充。
-            matchMap.put("recommends",type.equals("3") ? JSON.toJSONString(recommendInfoService.findRecomInfo()) : "[]");
-            ResData resData;
-            String bo = StringUtils.substringBeforeLast(reqId,"-");
-            if (uploadService.findLinkByBo(bo).size() > 1){
-                log.info("关联数据START...");
-                // todo ghj link数据部分也要新增类型三的findRecomInfo()数据。已补充。
-                log.info("link param:{}", JSON.toJSONString(matchMap));
-                String matchRes = internalSendService.link(matchMap);
-                resData = ParseUtils.parseRes(reqId, type, JSON.parseObject(sourceData),
-                        JSON.parseObject(ocrData), JSON.parseObject(matchRes));
-            }else {
-                matchMap.put("type",type);
-                log.info("match param:{}", JSON.toJSONString(matchMap));
-                String matchRes = internalSendService.match(matchMap);
-                resData = ParseUtils.parseRes(reqId, type, JSON.parseObject(sourceData),
-                        JSON.parseObject(ocrData), JSON.parseObject(matchRes));
-            }
-            uploadService.saveBack(resData,JSON.toJSONString(JSON.parseObject(mideOcr)),Long.valueOf(startTime));
-            back(resData, reqId, type, JSON.parseObject(mideOcr).get("code").toString());
-            long endTime = System.currentTimeMillis();
-            log.info("finish excTime:{}", DateUtils.getExcTime(Long.valueOf(startTime),endTime));
-        }
-    }
-
     /**
-     * ocr识别函数。
+     * ocr识别函数2。
      * @param reqId
      * @param fileType
      * @param parsedFilePath
@@ -211,7 +169,7 @@ public class OcrServiceImpl implements OcrService {
             try {
                 ocr = JSON.parseObject(AipOcrUtils.sample(parsedFilePath.getUrls(), fileType));
                 long endTime = System.currentTimeMillis();
-                log.info("ocr excTime:{}", DateUtils.getExcTime(startTime,endTime));
+                log.info("step2 ocr excTime:{}", DateUtils.getExcTime(startTime,endTime));
                 log.info("ocr-mid res:{}", JSON.toJSONString(ocr));
                 if (null != ocr && ocr.get("image_status").toString().equals("normal")) {
                     // 解析ocr数据。
@@ -236,18 +194,10 @@ public class OcrServiceImpl implements OcrService {
                     // 将ocr结果信息及其他信息封装后写入source表中。
                     // uploadService.updateByReqIdAndType(reqId,fileType,"time",JSON.toJSONString(matchMap));
                     // 返回map.
-                    endTime = System.currentTimeMillis();
-                    log.info("finish excTime:{}", DateUtils.getExcTime(startTime,endTime));
                     return matchMap;
                 } else {
-                    JSONObject midOcr = fileType.equals("10") ? ParseUtils.midOcrFront(false,"-1",fileType,"")
-                            : ParseUtils.midOcrReverse(false,"-1",fileType,"");
-                    // todo 直接返回,不用在调用match函数。
-                    uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(midOcr),startTime);
-                    boolean flag = null != ocr ? ocr.get("image_status").equals("non_idcard") ? true : false : false;
-                    back(getNullBackResData(reqId, fileType), reqId, fileType, flag ? "-1" : "0");
-                    endTime = System.currentTimeMillis();
-                    log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
+                    // 返回至富士通。
+                    backService.back(fileType,reqId,startTime,ocr);
                 }
             } catch (Exception e) {
                 log.info("singleFileOcr:{}", e);
@@ -259,7 +209,7 @@ public class OcrServiceImpl implements OcrService {
             ocrMap = getOcrMap(reqId, fileType, paths);
             ocr = internalSendService.ocr(ocrMap);
             long endTime = System.currentTimeMillis();
-            log.info("ocr sf excTime:{}", DateUtils.getExcTime(startTime,endTime));
+            log.info("step2 ocr excTime:{}", DateUtils.getExcTime(startTime,endTime));
             log.info("ocr-mid result:{}", JSON.toJSONString(ocr));
             if (null != ocr && ocr.get("code").toString().equals("1")) {
                 matchMap = matchMap(matchMap,fileType,reqId,ocr,sourceData);
@@ -268,22 +218,17 @@ public class OcrServiceImpl implements OcrService {
                 // uploadService.updateByReqIdAndType(reqId,fileType,"time",JSON.toJSONString(matchMap));
                 return matchMap;
             } else if (null != ocr && ocr.get("code").toString().equals("-1")) {
-                // todo 直接返回,不用在调用match函数。
-                uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
-                back(getNullBackResData(reqId, fileType), reqId, fileType, ocr.get("code").toString());
-                endTime = System.currentTimeMillis();
-                log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
+                // 返回至富士通。
+                backService.back(fileType,reqId,startTime,ocr);
             } else {
-                // 调用match函数。
-                uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
-                back(getNullBackResData(reqId, fileType), reqId, fileType, ocr.get("code").toString());
-                endTime = System.currentTimeMillis();
-                log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
+                // 返回至富士通。
+                backService.back(fileType,reqId,startTime,ocr);
             }
         }
         return matchMap;
     }
 
+
     @Override
     public void ocr(String reqId, String fileType, String url, String fileName, String sourceData,Long startTime) {
         try {
@@ -328,251 +273,6 @@ public class OcrServiceImpl implements OcrService {
         }
     }
 
-    @Override
-    public Map<String, Object> res(String code, ResData resData) {
-        log.info("res code:{}", code);
-        Map<String, Object> map = new HashMap<>();
-        map.put("code", code.equals("1") ? "0" : "1");
-        map.put("message", code.equals("1") ? "识别成功" : code.equals("-1") ? "文件内容不符,请上传正确的文件后重试。" :
-                code.equals("-3") ? "请确保文件大小不超出4M,且最长边不超过4096像素" : "未识别出数据,请确保上传为正确文件后重试");
-        map.put("reqId", resData.getReqId());
-        map.put("fileType", resData.getType());
-        map.put("data", resData.getRes());
-        // 20200507 新增回传参数:
-        map.put("overallConfidence",code.equals("-1") ? "0" : resData.getOverallConfidence());
-        map.put("midConfidence",code.equals("-1") ? "0" : resData.getMidConfidence());
-        return map;
-    }
-
-    @Override
-    public ResData getNullBackResData(String reqId, String templateType) {
-        ResData resData = new ResData();
-        try {
-            resData = new ResData();
-            switch (templateType) {
-                case "1":
-                    PciiAuth pciiAuth = new PciiAuth(new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(pciiAuth);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "2":
-                    // 待开发
-                    LoanApplicationForm loanApplicationForm = new LoanApplicationForm(new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(loanApplicationForm);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "3":
-                    // 待开发
-                    RecommendationLetter recommendationLetter = new RecommendationLetter(new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(recommendationLetter);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "4":
-                    // 待开发
-                    CreditConfirmationLetter creditConfirmationLetter = new CreditConfirmationLetter(new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(creditConfirmationLetter);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "5":
-                    // 待开发
-                    CreditLoanUseContract creditLoanUseContract = new CreditLoanUseContract(new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(creditLoanUseContract);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "6":
-                    // 待开发
-                    ConsumerFinanceHandlingInstructions consumerFinanceHandlingInstructions = new ConsumerFinanceHandlingInstructions(new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(consumerFinanceHandlingInstructions);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "7":
-                    // 待开发
-                    LoanPurposeCommitment loanPurposeCommitment = new LoanPurposeCommitment(new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(loanPurposeCommitment);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "8":
-                    // 待开发
-                    EnjoyLoansToClient enjoyLoansToClient = new EnjoyLoansToClient(new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(enjoyLoansToClient);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "9":
-                    // 待开发
-                    EnjoyLoansConfirm enjoyLoansConfirm = new EnjoyLoansConfirm(new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(enjoyLoansConfirm);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "10":
-                    // 待开发
-                    IdCardFront idCardFront = new IdCardFront(new BackData("", "", "","0"),
-                            new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(idCardFront);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "11":
-                    // 待开发
-                    IdCardReverse idCardReverse = new IdCardReverse(new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(idCardReverse);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "12":
-                    // 待开发
-                    PersonalInfoUseAuthorization personalInfoUseAuthorization = new PersonalInfoUseAuthorization(new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(personalInfoUseAuthorization);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "13":
-                    // 待开发
-                    PayAndEnjoyLoanApplicationForm payAndEnjoyLoanApplicationForm = new PayAndEnjoyLoanApplicationForm(new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(payAndEnjoyLoanApplicationForm);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "14":
-                    // 待开发
-                    EnjoyLoanApplicationForm enjoyLoanApplicationForm = new EnjoyLoanApplicationForm(new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0")
-                            // ,new BackData("", "", "","0")
-                    );
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(enjoyLoanApplicationForm);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "15":
-                    // 待开发
-                    LetterOfCreditCommitment letterOfCreditCommitment = new LetterOfCreditCommitment(new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(letterOfCreditCommitment);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "16":
-                    // 待开发
-                    LeEnjoyLoanCommitmentLetter leEnjoyLoanCommitmentLetter = new LeEnjoyLoanCommitmentLetter(new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(leEnjoyLoanCommitmentLetter);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                case "17":
-                    // 待开发
-                    LoanApplicationFormEnjoyELoan loanApplicationFormEnjoyELoan = new LoanApplicationFormEnjoyELoan(new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"), new BackData("", "", "","0"),
-                            new BackData("", "", "","0"));
-                    resData.setReqId(reqId);
-                    resData.setType(templateType);
-                    resData.setRes(loanApplicationFormEnjoyELoan);
-                    resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-                    break;
-                default:
-                    // 待开发
-            }
-            return resData;
-        } catch (Exception e) {
-            log.info("getNullBackResData:{}", e);
-        }
-        resData.setReqId(reqId);
-        resData.setType(templateType);
-        resData.setRes("null");
-        resData.setOverallConfidence("2");
-                    resData.setMidConfidence("2");
-        return resData;
-    }
 
     @Override
     public Map<String, Object> res(String reqId, String fileType, MultipartFile[] files, String data, Long startTime) throws Exception {
@@ -630,9 +330,9 @@ public class OcrServiceImpl implements OcrService {
                 } else {
                     JSONObject midOcr = fileType.equals("10") ? ParseUtils.midOcrFront(false,"-1",fileType,"")
                             : ParseUtils.midOcrReverse(false,"-1",fileType,"");
-                    uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(midOcr),startTime);
+                    uploadService.saveBack(backService.getNullBackResData(reqId, fileType),JSON.toJSONString(midOcr),startTime);
                     boolean flag = null != ocr ? ocr.get("image_status").equals("non_idcard") ? true : false : false;
-                    back(getNullBackResData(reqId, fileType), reqId, fileType, flag ? "-1" : "0");
+                    back(backService.getNullBackResData(reqId, fileType), reqId, fileType, flag ? "-1" : "0");
                     endTime = System.currentTimeMillis();
                     log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
                 }
@@ -656,14 +356,14 @@ public class OcrServiceImpl implements OcrService {
                 endTime = System.currentTimeMillis();
                 log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
             } else if (null != ocr && ocr.get("code").toString().equals("-1")) {
-                uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
-                back(getNullBackResData(reqId, fileType), reqId, fileType, ocr.get("code").toString());
+                uploadService.saveBack(backService.getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
+                back(backService.getNullBackResData(reqId, fileType), reqId, fileType, ocr.get("code").toString());
                 endTime = System.currentTimeMillis();
                 log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
             } else {
                 // todo 待处理。
-                uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
-                back(getNullBackResData(reqId, fileType), reqId, fileType, ocr.get("code").toString());
+                uploadService.saveBack(backService.getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
+                back(backService.getNullBackResData(reqId, fileType), reqId, fileType, ocr.get("code").toString());
                 endTime = System.currentTimeMillis();
                 log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
             }
@@ -679,7 +379,7 @@ public class OcrServiceImpl implements OcrService {
                 resData.setReqId(reqId);
                 resData.setType(fileType);
                 resData.setRes(null);
-                return res("-3", getNullBackResData(reqId, fileType));
+                return backService.res("-3", backService.getNullBackResData(reqId, fileType));
             } else {
                 // 单文件上传。
                 return singleFileOcrSyn(reqId, fileType, parsedFilePaths.get(0), parsedFilePaths, sourceData,startTime);
@@ -779,7 +479,7 @@ public class OcrServiceImpl implements OcrService {
                     uploadService.saveBack(resData,JSON.toJSONString(midOcr),startTime);
                     endTime = System.currentTimeMillis();
                     log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
-                    return res("1", resData);
+                    return backService.res("1", resData);
                 }else {
                     // todo 待处理。
                     ResData resData = new ResData();
@@ -790,11 +490,11 @@ public class OcrServiceImpl implements OcrService {
                     resData.setMidConfidence("2");
                     JSONObject midOcr = fileType.equals("10") ? ParseUtils.midOcrFront(false,"-1",fileType,"")
                             : ParseUtils.midOcrReverse(false,"-1",fileType,"");
-                    uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(midOcr),startTime);
+                    uploadService.saveBack(backService.getNullBackResData(reqId, fileType),JSON.toJSONString(midOcr),startTime);
                     endTime = System.currentTimeMillis();
                     log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
                     boolean flag = null != ocr ? ocr.get("image_status").equals("non_idcard") ? true : false : false;
-                    return res(flag ? "-1" : "0", getNullBackResData(reqId, fileType));
+                    return backService.res(flag ? "-1" : "0", backService.getNullBackResData(reqId, fileType));
                 }
             } catch (Exception e) {
                 log.info("singleFileOcrSyn:{}",  e);
@@ -814,12 +514,12 @@ public class OcrServiceImpl implements OcrService {
                 uploadService.saveBack(resData,JSON.toJSONString(ocr),startTime);
                 endTime = System.currentTimeMillis();
                 log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
-                return res(ocr.get("code").toString(), resData);
+                return backService.res(ocr.get("code").toString(), resData);
             } else if (null != ocr && ocr.get("code").toString().equals("-1")) {
-                uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
+                uploadService.saveBack(backService.getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
                 endTime = System.currentTimeMillis();
                 log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
-                return res(ocr.get("code").toString(), getNullBackResData(reqId, fileType));
+                return backService.res(ocr.get("code").toString(), backService.getNullBackResData(reqId, fileType));
             } else {
                 // todo 待处理。
                 ResData resData = new ResData();
@@ -828,13 +528,13 @@ public class OcrServiceImpl implements OcrService {
                 resData.setRes(null);
                 resData.setOverallConfidence("2");
                     resData.setMidConfidence("2");
-                uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
+                uploadService.saveBack(backService.getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
                 endTime = System.currentTimeMillis();
                 log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
-                return res(ocr.get("code").toString(), getNullBackResData(reqId, fileType));
+                return backService.res(ocr.get("code").toString(), backService.getNullBackResData(reqId, fileType));
             }
         }
-        uploadService.saveBack(getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
+        uploadService.saveBack(backService.getNullBackResData(reqId, fileType),JSON.toJSONString(ocr),startTime);
         long endTime = System.currentTimeMillis();
         log.info("ocr back excTime:{}", DateUtils.getExcTime(startTime,endTime));
         return resFailed(ocr.containsKey("code") ? ocr.get("code").toString() : "", "操作失败", reqId, fileType);
@@ -939,9 +639,9 @@ public class OcrServiceImpl implements OcrService {
         // todo 记得清除。
         String result = "";
         if (code.equals("1")) {
-            result = JSON.toJSONString(res(code, resData));
+            result = JSON.toJSONString(backService.res(code, resData));
         } else {
-            result = JSON.toJSONString(res(code, resData));
+            result = JSON.toJSONString(backService.res(code, resData));
         }
         // todo ghj-online 上线时放开。
         String backRes = eternalSendService.send(result);

+ 11 - 6
src/main/java/com/pavis/ai/app/fjsocrasy/service/impl/OpServiceImpl.java

@@ -36,15 +36,20 @@ public class OpServiceImpl implements OpService {
             String message = new String(bytes);
             JSONObject json = JSON.parseObject(message);
             // 调用算法,做识别。
-            ocrService.matching(json.get("req_id").toString(),json.get("type").toString(),json.get("start_time").toString(),
-                    json.get("source_data").toString(), json.get("ocr_data").toString(),json.get("mid_ocr").toString(),json.get("acc_json").toString(),
-                    json.get("recommends").toString());
-            long endTime = System.currentTimeMillis();
-            log.info("ocr excTime:{}", DateUtils.getExcTime(startTime,endTime));
+            // 调用算法,做识别。
+            // rbmqMap.put("reqId", reqId);
+            // rbmqMap.put("fileType", fileType);
+            // rbmqMap.put("url", parsedFilePaths);
+            // rbmqMap.put("fileName", fileName);
+            // rbmqMap.put("data", data);
+            // rbmqMap.put("startTime", startTime);
+            // toOcr(reqId, fileType,JSON.toJSONString(parsedFilePaths),fileName,data,startTime);
+            ocrService.toOcr(json.get("reqId").toString(),json.get("fileType").toString(),json.get("url").toString(),
+                    json.get("fileName").toString(), json.get("data").toString(),Long.valueOf(json.get("startTime").toString()));
         } catch (Exception e) {
             log.info("接收消息异常...:{}", e.getMessage(), e);
         }
-        log.info(",消息处理完毕时间:{}", DateUtils.getCurrentTime());
+        log.info("消息处理完毕时间:{}", DateUtils.getCurrentTime());
     }
 
 }

+ 52 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/service/impl/OtherServiceImpl.java

@@ -0,0 +1,52 @@
+package com.pavis.ai.app.fjsocrasy.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.pavis.ai.app.fjsocrasy.common.config.constants.Constants;
+import com.pavis.ai.app.fjsocrasy.form.FileDetails;
+import com.pavis.ai.app.fjsocrasy.service.DealService;
+import com.pavis.ai.app.fjsocrasy.service.OtherService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.connection.CorrelationData;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * @author guanhuijuan
+ * @create 2020-07-08 19:27
+ * @desc OtherServiceImpl
+ **/
+
+@Slf4j
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class OtherServiceImpl implements OtherService {
+    @Autowired
+    private DealService dealService;
+
+    @Override
+    public void uploading(String reqId, String fileType, String data, MultipartFile[] files, Long startTime, List<FileDetails> parsedFilePaths) throws IOException {
+        String suffix = files[0].getOriginalFilename().substring(files[0].getOriginalFilename().lastIndexOf("."));
+        String fileName = UUID.randomUUID().toString() + suffix;
+        // 2、参数封装供ocr使用。
+        Map<String, Object> rbmqMap = new HashMap<>();
+        rbmqMap.put("reqId", reqId);
+        rbmqMap.put("fileType", fileType);
+        rbmqMap.put("url", parsedFilePaths);
+        rbmqMap.put("fileName", fileName);
+        rbmqMap.put("data", data);
+        rbmqMap.put("startTime", startTime);
+
+        // 2.1、将ocr数据放入队列中。
+        CorrelationData correlationData = new CorrelationData(reqId);
+        dealService.sendMessage(Constants.ROUTING_OP_KEY, JSON.toJSONString(rbmqMap).getBytes(), correlationData);
+
+    }
+}

+ 9 - 13
src/main/java/com/pavis/ai/app/fjsocrasy/service/impl/UploadServiceImpl.java

@@ -56,15 +56,13 @@ import com.pavis.ai.app.fjsocrasy.form.two.LoanApplicationForm;
 import com.pavis.ai.app.fjsocrasy.form.two.MidTwo;
 import com.pavis.ai.app.fjsocrasy.mapper.*;
 import com.pavis.ai.app.fjsocrasy.model.*;
-import com.pavis.ai.app.fjsocrasy.service.DealService;
-import com.pavis.ai.app.fjsocrasy.service.OcrService;
-import com.pavis.ai.app.fjsocrasy.service.RecommendInfoService;
-import com.pavis.ai.app.fjsocrasy.service.UploadService;
+import com.pavis.ai.app.fjsocrasy.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.amqp.rabbit.connection.CorrelationData;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -113,9 +111,6 @@ public class UploadServiceImpl implements UploadService {
     @Autowired
     private UploadMapper uploadMapper;
 
-    @Autowired
-    private DealService dealService;
-
     @Autowired
     private ContractOneMapper contractOneMapper;
 
@@ -222,16 +217,15 @@ public class UploadServiceImpl implements UploadService {
     private RecommendInfoService recommendInfoService;
 
     @Autowired
-    private OcrService ocrService;
+    private OtherService otherService;
+
 
     @Override
     public List<FileDetails> upload(String reqId, String fileType, String data, MultipartFile[] files, Long startTime) throws Exception {
         // 1、将上传信息数据写入库,并将文件数据写入磁盘,同时返回待处理的图片路径。
-        log.info("step 1");
+        log.info("step ****1: save***");
         List<FileDetails> parsedFilePaths = writeToDisk(files, reqId, fileType, data, startTime);
-
-        ocrService.uploading(reqId,fileType,data,files,startTime,parsedFilePaths);
-
+        otherService.uploading(reqId,fileType,data,files,startTime,parsedFilePaths);
         // todo 待处理。
         // return "1";
         return parsedFilePaths;
@@ -258,7 +252,9 @@ public class UploadServiceImpl implements UploadService {
         if (savedId > 0) {
             JSONObject dataJson = JSON.parseObject(data);
             // 原始数据入库。
-            return savedSourceData(reqId, type, dataJson,excTime);
+            int insertId = savedSourceData(reqId, type, dataJson,excTime);
+            log.info("insert result:{}",insertId);
+            return insertId;
         } else {
             return 0;
         }