Browse Source

1、分流接口完成。

guanzi 4 năm trước cách đây
mục cha
commit
10ffff484e

+ 6 - 2
src/main/java/com/pavis/ai/app/fjsocrasy/common/utils/ocr/AipOcrUtils.java

@@ -134,10 +134,14 @@ public class AipOcrUtils {
         String arrStr = StringUtils.remove(StringUtils.remove(shunts.get(0).getCheckArr(),"["),"]");
         List<Integer> checkLists = Pattern.compile(",").splitAsStream(arrStr).map((x) -> Integer.parseInt(x))
                 .collect(Collectors.toList());
+        System.err.println("countFlag:" + countFlag);
         System.err.println("checkLists:" + JSON.toJSONString(checkLists));
         Boolean isHad = checkLists.stream().filter(m -> m.equals(countFlag)).findAny().isPresent();
-//        return isHad == true ? "0" : "1";
-        return isHad == true ? "local" : "ali";
+        String res = isHad == true ? "0" : "1";
+        log.info("res:{}",res.equals("0") ? "local" : "aliyun");
+        System.out.println(res.equals("0") ? "local" : "aliyun");
+        return res;
+//        return isHad == true ? "local" : "ali";
     }
 //    @Test
 //    public void testArr(int randNum) {

+ 16 - 3
src/main/java/com/pavis/ai/app/fjsocrasy/controller/BackController.java

@@ -7,10 +7,12 @@ import com.pavis.ai.app.fjsocrasy.common.config.constants.Constants;
 import com.pavis.ai.app.fjsocrasy.common.config.properties.CommonProperties;
 import com.pavis.ai.app.fjsocrasy.common.http.ResultBody;
 import com.pavis.ai.app.fjsocrasy.common.utils.DateUtils;
+import com.pavis.ai.app.fjsocrasy.common.utils.ocr.AipOcrUtils;
 import com.pavis.ai.app.fjsocrasy.common.utils.test.TestAsync;
 import com.pavis.ai.app.fjsocrasy.form.AutoParam;
 import com.pavis.ai.app.fjsocrasy.form.ProVersion;
 import com.pavis.ai.app.fjsocrasy.form.SendData;
+import com.pavis.ai.app.fjsocrasy.model.Shunt;
 import com.pavis.ai.app.fjsocrasy.service.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -293,6 +295,7 @@ public class BackController {
         return ResultBody.ok().data(map);
     }
 
+    int countFlag = 1;
     @ApiOperation("富士通图片识别自动测试接口 内部测试结合autotest使用")
     @ApiOperationSupport(order = 6)
     @PostMapping("/fjs/auto")
@@ -304,10 +307,20 @@ public class BackController {
         log.info("paths:{}",JSON.toJSONString(autoParam.getPaths()));
         log.info("sourceData:{}",autoParam.getSourceData());
         log.info("startTime:{}",autoParam.getStartTime());
-
-        // Map<String,Object> map = ocrService.singleFileOcrSyn(reqId,fileType,parsedFilePath,paths,sourceData,startTime);
+        // todo 分流:
+        List<Shunt> shunts = ocrService.toSelShuntByType(autoParam.getFileType());
+        String shuntType = AipOcrUtils.checkLocalOrAli(shunts,countFlag);
+        log.info("shuntType调取结果为:{}",shuntType);
         Map<String,Object> map = ocrService.singleFileOcrSyn(autoParam.getReqId(),autoParam.getFileType(),autoParam.getParsedFilePath(),
-                autoParam.getPaths(),autoParam.getSourceData(),autoParam.getStartTime());
+                autoParam.getPaths(),autoParam.getSourceData(),autoParam.getStartTime(),shuntType);
+        // todo 等于数据库存取的proportion如:100时,置为0;可从数据库获取,按照比例来。
+        countFlag = countFlag + 1;
+        int proportion = Integer.valueOf(shunts.get(0).getProportion());
+        if(countFlag == proportion){
+            countFlag = 0;
+        }
+        // Map<String,Object> map = ocrService.singleFileOcrSyn(reqId,fileType,parsedFilePath,paths,sourceData,startTime);
+
         log.info("ocrRes:{}",JSON.toJSONString(map));
         long endTime = System.currentTimeMillis();
         log.info("ocr back excTime:{}", DateUtils.getExcTime(autoParam.getStartTime(),endTime));

+ 1 - 0
src/main/java/com/pavis/ai/app/fjsocrasy/controller/OcrController.java

@@ -98,6 +98,7 @@ public class OcrController {
         if (!StringUtils.isEmpty(data) && !data.equals("null")){
             if (data.contains("{") && GeneralUtils.checkJson(data) && !data.equals("{}")){
                 fileType = fileType.equals("5") ? "18" : fileType;
+
                 Map<String,Object> resMap = ocrService.res(reqId,fileType,files,data,startTime);
                 long endTime = System.currentTimeMillis();
                 log.info("upload syn excTime:{}", DateUtils.getExcTime(startTime,endTime));

+ 13 - 2
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.ShuntParam;
+import com.pavis.ai.app.fjsocrasy.model.Shunt;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
@@ -30,6 +31,13 @@ public interface OcrService {
      */
     void toOcr(String reqId, String fileType, String url, String fileName, String data, Long startTime) throws IOException;
 
+    /**
+     * 根据类型获取分流列表。
+     * @param type
+     * @return
+     */
+    List<Shunt> toSelShuntByType(String type);
+
     /**
      * 分流设置。
      * @param shuntParam
@@ -37,6 +45,8 @@ public interface OcrService {
      */
     Map<String,Object> shuntSet(ShuntParam shuntParam);
 
+    void initShuntVal(int countFlag,int proportion,Boolean isReset);
+
 
     /**
      * 识别处理。
@@ -47,7 +57,7 @@ public interface OcrService {
      * @param fileName
      * @throws IOException
      */
-    void ocr(String reqId, String fileType, String url, String fileName, String data, Long startTime) throws IOException;
+    void ocr(String reqId, String fileType, String url, String fileName, String data, Long startTime,String shuntType) throws IOException;
 
 
 
@@ -81,6 +91,7 @@ public interface OcrService {
      * @return
      * @throws Exception
      */
-    Map<String, Object> singleFileOcrSyn(String reqId, String fileType, FileDetails parsedFilePath, List<FileDetails> paths, String sourceData,Long startTime) throws Exception;
+    Map<String, Object> singleFileOcrSyn(String reqId, String fileType, FileDetails parsedFilePath, List<FileDetails> paths,
+                                         String sourceData,Long startTime,String shuntType) throws Exception;
 
 }

+ 90 - 34
src/main/java/com/pavis/ai/app/fjsocrasy/service/impl/OcrServiceImpl.java

@@ -60,7 +60,7 @@ public class OcrServiceImpl implements OcrService {
 
     @Autowired
     private ShuntMapper shuntMapper;
-    int countFlag = 0;
+//    int countFlag = 1;
 
     @Async("ocrFjsExecutor")
     @Override
@@ -71,13 +71,17 @@ public class OcrServiceImpl implements OcrService {
         data = fileType.equals("18") ? ParseUtils.changeSourceDataBy18(data) : data;
         log.info("*******ocr******* pre:{}", System.currentTimeMillis());
         // todo 分流:
+        int countFlag = Integer.valueOf(toSelShuntByType("-1").get(0).getRemarks());
         List<Shunt> shunts = toSelShuntByType(fileType);
-        String shuntType = AipOcrUtils.checkLocalOrAli(shunts,countFlag);
-
-        Map<String, Object> ocrMap = toOcrMap(reqId, fileType, url, fileName, data, startTime);
-
-        // 等于100时,置为0;可从数据库获取,按照比例来。
-
+        String shuntType = AipOcrUtils.checkLocalOrAli(shunts, countFlag);
+        log.info("shuntType调取结果为:{}", shuntType);
+        Map<String, Object> ocrMap = toOcrMap(reqId, fileType, url, fileName, data, startTime, shuntType);
+        // todo 等于数据库存取的proportion如:100时,置为0;可从数据库获取,按照比例来。
+        countFlag = countFlag + 1;
+        int proportion = Integer.valueOf(shunts.get(0).getProportion());
+        // 当countFlag == proportion时,将countFlag置为1;
+        initShuntVal(countFlag,proportion,false);
+        initShuntVal(countFlag,proportion,true);
         log.info("*******ocr******* end:{}", System.currentTimeMillis());
         log.info("match-pre,only ocr:{}", JSON.toJSONString(ocrMap));
         if (null != ocrMap && ocrMap.containsKey("req_id")) {
@@ -96,6 +100,20 @@ public class OcrServiceImpl implements OcrService {
         }
     }
 
+    /**
+     * 根据类型获取分流列表。
+     *
+     * @param type
+     * @return
+     */
+    @Override
+    public List<Shunt> toSelShuntByType(String type) {
+        QueryWrapper<Shunt> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda()
+                .eq(Shunt::getType, type);
+        return shuntMapper.selectList(queryWrapper);
+    }
+
     @Override
     public Map<String, Object> shuntSet(ShuntParam shuntParam) {
         int changedId = 0;
@@ -103,7 +121,7 @@ public class OcrServiceImpl implements OcrService {
             // 获取分流列表。
             List<Shunt> params = toSelShuntByType(s);
             // 更新or插入操作。
-            changedId = toShunt(params,shuntParam);
+            changedId = toShunt(params, shuntParam);
         }
 
         Map<String, Object> resMap = new HashMap<>();
@@ -123,18 +141,28 @@ public class OcrServiceImpl implements OcrService {
         return resMap;
     }
 
-    /**
-     * 根据类型获取分流列表。
-     * @param type
-     * @return
-     */
-    public List<Shunt> toSelShuntByType(String type){
-        QueryWrapper<Shunt> queryWrapper = new QueryWrapper<>();
-        queryWrapper.lambda()
-                .eq(Shunt::getType, type);
-        return shuntMapper.selectList(queryWrapper);
+    @Override
+    public void initShuntVal(int countFlag, int proportion,Boolean isReset) {
+        if (isReset == true){
+//            if (countFlag == (proportion - 1)) {
+            if (countFlag > proportion) {
+                List<Shunt> tmpShunts = toSelShuntByType("-1");
+                for (Shunt tmpShunt : tmpShunts) {
+                    tmpShunt.setRemarks("1");
+                    shuntMapper.updateById(tmpShunt);
+                }
+            }
+        }else {
+            List<Shunt> tmpShunts = toSelShuntByType("-1");
+            for (Shunt tmpShunt : tmpShunts) {
+                tmpShunt.setRemarks(String.valueOf(countFlag));
+                shuntMapper.updateById(tmpShunt);
+            }
+        }
+
     }
 
+
     /**
      * 构建shunt。
      *
@@ -174,7 +202,7 @@ public class OcrServiceImpl implements OcrService {
      * @param startTime
      * @return
      */
-    public Map<String, Object> toOcrMap(String reqId, String fileType, String url, String fileName, String data, Long startTime) {
+    public Map<String, Object> toOcrMap(String reqId, String fileType, String url, String fileName, String data, Long startTime, String shuntType) {
         log.info("to Ocr Map:{}", "开始调用ocr识别....");
         Map<String, Object> ocrMap = new HashMap<>();
         try {
@@ -198,7 +226,7 @@ public class OcrServiceImpl implements OcrService {
                     back(resData, reqId, DateUtils.getExcTime(startTime, endTime), "-3");
                 } else {
                     // 单文件上传。
-                    ocrMap = toSingleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, data, startTime);
+                    ocrMap = toSingleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, data, startTime, shuntType);
                     long endTime = System.currentTimeMillis();
                     log.info("step2 ocrMap excTime:{}", DateUtils.getExcTime(startTime, endTime));
                     log.info("to Ocr single Map:{}", "结束调用ocr识别single....");
@@ -206,7 +234,7 @@ public class OcrServiceImpl implements OcrService {
                 }
             } else if (effectiveImgpaths.size() > 1) {
                 // 多文件上传,pdf转图片&两张图片,第8、15、16种。
-                ocrMap = toSingleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, data, startTime);
+                ocrMap = toSingleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, data, startTime, shuntType);
                 long endTime = System.currentTimeMillis();
                 log.info("step2 ocrMap excTime:{}", DateUtils.getExcTime(startTime, endTime));
                 log.info("to Ocr more Map:{}", "结束调用ocr识别more....");
@@ -239,7 +267,8 @@ public class OcrServiceImpl implements OcrService {
      * @param startTime
      * @return
      */
-    public Map<String, Object> toSingleFileOcr(String reqId, String fileType, FileDetails parsedFilePath, List<FileDetails> paths, String sourceData, Long startTime) {
+    public Map<String, Object> toSingleFileOcr(String reqId, String fileType, FileDetails parsedFilePath,
+                                               List<FileDetails> paths, String sourceData, Long startTime, String shuntType) {
         System.err.println(reqId);
         System.err.println(fileType);
         System.err.println(JSON.toJSONString(parsedFilePath));
@@ -291,7 +320,8 @@ public class OcrServiceImpl implements OcrService {
         } else {
             // 处理类型1、2、3、4、5、6、7、8、9、12、13、14、15、16
             // 4,8,15,后期可能不要。
-            ocrMap = getOcrMap(reqId, fileType, paths);
+            ocrMap = getOcrMap(reqId, fileType, paths, shuntType);
+            log.info("to suanfa ocrMap:{}",JSON.toJSONString(ocrMap));
             ocr = internalSendService.ocr(ocrMap);
             long endTime = System.currentTimeMillis();
             log.info("step2 ocr excTime:{}", DateUtils.getExcTime(startTime, endTime));
@@ -315,7 +345,7 @@ public class OcrServiceImpl implements OcrService {
 
 
     @Override
-    public void ocr(String reqId, String fileType, String url, String fileName, String sourceData, Long startTime) {
+    public void ocr(String reqId, String fileType, String url, String fileName, String sourceData, Long startTime, String shuntType) {
         try {
             // 解析已处理过的有效的图片url
             JSONArray recArr = JSON.parseArray(url);
@@ -335,13 +365,13 @@ public class OcrServiceImpl implements OcrService {
                     back(resData, reqId, DateUtils.getExcTime(startTime, endTime), "-3");
                 } else {
                     // 单文件上传。
-                    singleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, sourceData, startTime);
+                    singleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, sourceData, startTime, shuntType);
                     long endTime = System.currentTimeMillis();
                     log.info("res excTime:{}", DateUtils.getExcTime(startTime, endTime));
                 }
             } else if (effectiveImgpaths.size() > 1) {
                 // 多文件上传,pdf转图片&两张图片,第8、15、16种。
-                singleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, sourceData, startTime);
+                singleFileOcr(reqId, fileType, effectiveImgpaths.get(0), effectiveImgpaths, sourceData, startTime, shuntType);
                 long endTime = System.currentTimeMillis();
                 log.info("res excTime:{}", DateUtils.getExcTime(startTime, endTime));
             } else {
@@ -378,7 +408,7 @@ public class OcrServiceImpl implements OcrService {
      * @param sourceData
      * @throws IOException
      */
-    public void singleFileOcr(String reqId, String fileType, FileDetails parsedFilePath, List<FileDetails> paths, String sourceData, Long startTime) {
+    public void singleFileOcr(String reqId, String fileType, FileDetails parsedFilePath, List<FileDetails> paths, String sourceData, Long startTime, String shuntType) {
         Map<String, Object> matchMap = new HashMap<>();
         Map<String, Object> ocrMap = new HashMap<>();
         sourceData = fileType.equals("18") ? ParseUtils.changeSourceDataBy18(sourceData) : sourceData;
@@ -430,7 +460,7 @@ public class OcrServiceImpl implements OcrService {
         } else {
             // 处理类型1、2、3、4、5、6、7、8、9、12、13、14、15、16
             // 4,8,15,后期可能不要。
-            ocrMap = getOcrMap(reqId, fileType, paths);
+            ocrMap = getOcrMap(reqId, fileType, paths, shuntType);
             ocr = internalSendService.ocr(ocrMap);
             long endTime = System.currentTimeMillis();
             log.info("ocr ali excTime:{}", DateUtils.getExcTime(startTime, endTime));
@@ -468,12 +498,37 @@ public class OcrServiceImpl implements OcrService {
                 resData.setRes(null);
                 return backService.res("-3", backService.getNullBackResData(reqId, fileType));
             } else {
+                // todo 分流:
+                int countFlag = Integer.valueOf(toSelShuntByType("-1").get(0).getRemarks());
+                List<Shunt> shunts = toSelShuntByType(fileType);
+                String shuntType = AipOcrUtils.checkLocalOrAli(shunts, countFlag);
+                log.info("shuntType调取结果为:{}", shuntType);
                 // 单文件上传。
-                return singleFileOcrSyn(reqId, fileType, parsedFilePaths.get(0), parsedFilePaths, sourceData, startTime);
+                Map<String, Object> map = new HashMap<>();
+                map = singleFileOcrSyn(reqId, fileType, parsedFilePaths.get(0), parsedFilePaths, sourceData, startTime, shuntType);
+                // todo 等于数据库存取的proportion如:100时,置为0;可从数据库获取,按照比例来。
+                countFlag = countFlag + 1;
+                int proportion = Integer.valueOf(shunts.get(0).getProportion());
+                initShuntVal(countFlag,proportion,false);
+                initShuntVal(countFlag,proportion,true);
+                return map;
             }
         } else if (parsedFilePaths.size() > 1) {
             // 多文件上传,pdf转图片多个,可能是第八种文件在内。
-            return singleFileOcrSyn(reqId, fileType, parsedFilePaths.get(0), parsedFilePaths, sourceData, startTime);
+            // todo 分流:
+            int countFlag = Integer.valueOf(toSelShuntByType("-1").get(0).getRemarks());
+            List<Shunt> shunts = toSelShuntByType(fileType);
+            String shuntType = AipOcrUtils.checkLocalOrAli(shunts, countFlag);
+            log.info("shuntType调取结果为:{}", shuntType);
+            // 单文件上传。
+            Map<String, Object> map = new HashMap<>();
+            map = singleFileOcrSyn(reqId, fileType, parsedFilePaths.get(0), parsedFilePaths, sourceData, startTime, shuntType);
+            // todo 等于数据库存取的proportion如:100时,置为0;可从数据库获取,按照比例来。
+            countFlag = countFlag + 1;
+            int proportion = Integer.valueOf(shunts.get(0).getProportion());
+            initShuntVal(countFlag,proportion,false);
+            initShuntVal(countFlag,proportion,true);
+            return map;
         } else {
             return resFailed("-2", "文件不能为空,请选择文件后重试。", reqId, fileType);
         }
@@ -500,7 +555,7 @@ public class OcrServiceImpl implements OcrService {
      * @param paths
      * @return
      */
-    public Map<String, Object> getOcrMap(String reqId, String fileType, List<FileDetails> paths) {
+    public Map<String, Object> getOcrMap(String reqId, String fileType, List<FileDetails> paths, String shuntType) {
         // todo 20200421 处理张坤接口的时候,pdf转图片是多张文件,
         // todo 调用张坤的接口。
         Map<String, Object> ocrMap = new HashMap<>();
@@ -512,7 +567,7 @@ public class OcrServiceImpl implements OcrService {
         ocrMap.put("files_list", files);
         ocrMap.put("type", fileType);
         ocrMap.put("reqId", reqId);
-//        ocrMap.put("shuntType","")
+        ocrMap.put("shuntType", shuntType);
 
         // todo 20200421 单文件暂时抛弃,选用多文件上传。
         // File file = new File(parsedFilePath.getUrls());
@@ -534,7 +589,8 @@ public class OcrServiceImpl implements OcrService {
      * @throws IOException
      */
     @Override
-    public Map<String, Object> singleFileOcrSyn(String reqId, String fileType, FileDetails parsedFilePath, List<FileDetails> paths, String sourceData, Long startTime) throws IOException {
+    public Map<String, Object> singleFileOcrSyn(String reqId, String fileType, FileDetails parsedFilePath, List<FileDetails> paths,
+                                                String sourceData, Long startTime, String shuntType) throws IOException {
         Map<String, Object> matchMap = new HashMap<>();
         Map<String, Object> ocrMap = new HashMap<>();
         sourceData = fileType.equals("18") ? ParseUtils.changeSourceDataBy18(sourceData) : sourceData;
@@ -595,7 +651,7 @@ public class OcrServiceImpl implements OcrService {
         } else {
             // 处理类型1、2、3、4、5、6、7、8、9、12、13、14、15、16\17\18
             // 4,8,15,后期可能不要。
-            ocrMap = getOcrMap(reqId, fileType, paths);
+            ocrMap = getOcrMap(reqId, fileType, paths, shuntType);
             ocr = internalSendService.ocr(ocrMap);
             long endTime = System.currentTimeMillis();
             log.info("ocr ali excTime:{}", DateUtils.getExcTime(startTime, endTime));

+ 8 - 1
src/main/java/com/pavis/ai/app/fjsocrasy/service/impl/UploadServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.pavis.ai.app.fjsocrasy.common.config.properties.CommonProperties;
 import com.pavis.ai.app.fjsocrasy.common.utils.DateUtils;
 import com.pavis.ai.app.fjsocrasy.common.utils.IgnoreUtils;
+import com.pavis.ai.app.fjsocrasy.common.utils.ocr.AipOcrUtils;
 import com.pavis.ai.app.fjsocrasy.common.utils.ocr.GeneralUtils;
 import com.pavis.ai.app.fjsocrasy.form.FileDetails;
 import com.pavis.ai.app.fjsocrasy.form.eight.Eight;
@@ -238,6 +239,8 @@ public class UploadServiceImpl implements UploadService {
     @Autowired
     private OcrService ocrService;
 
+    int countFlag = 1;
+
     /**
      * 本地测试接口。
      *
@@ -272,6 +275,10 @@ public class UploadServiceImpl implements UploadService {
 
     @Override
     public int save(String reqId, String type, String fileName, Long fileSize, String data, Long startTime) {
+        List<Shunt> shunts = ocrService.toSelShuntByType("-1");
+        List<Shunt> selShunts = ocrService.toSelShuntByType(type);
+        String shuntType = AipOcrUtils.checkLocalOrAli(selShunts, Integer.valueOf(shunts.get(0).getRemarks()));
+        log.info("upload shuntType:{}", shuntType);
         long endTime = System.currentTimeMillis();
         String excTime = DateUtils.getExcTime(startTime, endTime);
         Upload upload = Upload.builder()
@@ -284,7 +291,7 @@ public class UploadServiceImpl implements UploadService {
                 .operatorId("")
                 .operateIp("")
                 .operateTime(DateUtils.now())
-                .remarks("")
+                .remarks(shuntType)
                 .build();
         int savedId = uploadMapper.insert(upload);
         // if (savedId > 0) {

+ 2 - 1
src/main/resources/application-dev.yml

@@ -50,7 +50,8 @@ logging:
     com.pavis.ai.app.fjsocrasy.mapper: debug
 alg-client:
   # 测试时使用,与测试环境保持一致.
-  internal: http://180.76.146.227:8099
+#  internal: http://180.76.146.227:8099
+  internal: http://180.76.146.227:8089
 #  internal: http://47.104.109.52:8099
   # 使用场景: 生产环境部署时,调试后再上线.
 #  internal: http://47.104.109.52:8089

+ 2 - 2
src/main/resources/application.yml

@@ -1,8 +1,8 @@
 server:
 #  测试环境
-#  port: 8000
+  port: 8000
 #  生产环境
-  port: 18000
+#  port: 18000
 spring:
   application:
     name: fujisu-ocr-server

+ 57 - 2
src/test/java/com/pavis/ai/app/fjsocrasy/FjsOcrAsyApplicationTests.java

@@ -18,6 +18,7 @@ import com.pavis.ai.app.fjsocrasy.model.Upload;
 import com.pavis.ai.app.fjsocrasy.service.BackService;
 import com.pavis.ai.app.fjsocrasy.service.OcrService;
 import com.pavis.ai.app.fjsocrasy.service.UploadService;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -44,6 +45,7 @@ import java.util.Map;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
+@Slf4j
 public class FjsOcrAsyApplicationTests {
 
     @Autowired
@@ -64,7 +66,7 @@ public class FjsOcrAsyApplicationTests {
     @Autowired
     private ShuntMapper shuntMapper;
 
-    int countFlag = 0;
+    int countFlag = 1;
     @Test
     public void testShuntType(){
         List<Integer> uploadLists = new ArrayList<>();
@@ -81,7 +83,7 @@ public class FjsOcrAsyApplicationTests {
             List<Shunt> shunts = shuntMapper.selectList(queryWrapper);
             System.out.println("此"+uploadList+"应该:");
             String shuntType =  AipOcrUtils.checkLocalOrAli(shunts,countFlag);
-            System.err.println("shuntType:"+shuntType);
+            System.out.println("shuntType:"+shuntType);
             countFlag = countFlag + 1;
             int proportion = Integer.valueOf(shunts.get(0).getProportion());
             System.err.println("proportion:" + proportion);
@@ -92,6 +94,59 @@ public class FjsOcrAsyApplicationTests {
 
     }
 
+    @Test
+    public void testFenliu(){
+        String fileType = "1";
+        List<String> lists = new ArrayList<>();
+        for (int i = 0; i < 10; i++) {
+            System.err.println("开始调用:"+i);
+            int countFlag = Integer.valueOf(toSelShuntByType("-1").get(0).getRemarks());
+            System.err.println("sql:" + countFlag);
+            List<Shunt> shunts = toSelShuntByType(fileType);
+            String shuntType = AipOcrUtils.checkLocalOrAli(shunts, countFlag);
+//            log.info("shuntType调取结果为:{}", shuntType);
+            System.err.println("shuntType调取结果为:{}" + shuntType);
+            lists.add(shuntType);
+            System.out.println("to ocr ..........");
+            // todo 等于数据库存取的proportion如:100时,置为0;可从数据库获取,按照比例来。
+            countFlag = countFlag + 1;
+            int proportion = Integer.valueOf(shunts.get(0).getProportion());
+            // 当countFlag == proportion时,将countFlag置为1;
+            initShuntVal(countFlag,proportion,false);
+            initShuntVal(countFlag,proportion,true);
+            System.err.println("sql end:" + Integer.valueOf(toSelShuntByType("-1").get(0).getRemarks()));
+        }
+
+        System.err.println(JSON.toJSONString(lists));
+    }
+
+    public void initShuntVal(int countFlag, int proportion,Boolean isReset) {
+        if (isReset == true){
+//            if (countFlag == (proportion - 1)) {
+            if (countFlag > proportion) {
+                List<Shunt> tmpShunts = toSelShuntByType("-1");
+                for (Shunt tmpShunt : tmpShunts) {
+                    tmpShunt.setRemarks("1");
+                    shuntMapper.updateById(tmpShunt);
+                }
+            }
+        }else {
+            List<Shunt> tmpShunts = toSelShuntByType("-1");
+            for (Shunt tmpShunt : tmpShunts) {
+                tmpShunt.setRemarks(String.valueOf(countFlag));
+                shuntMapper.updateById(tmpShunt);
+            }
+        }
+
+    }
+
+    public List<Shunt> toSelShuntByType(String type) {
+        QueryWrapper<Shunt> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda()
+                .eq(Shunt::getType, type);
+        return shuntMapper.selectList(queryWrapper);
+    }
+
 
     @Test
     public void testPwd() throws Exception {

+ 2 - 1
target/classes/application-dev.yml

@@ -50,7 +50,8 @@ logging:
     com.pavis.ai.app.fjsocrasy.mapper: debug
 alg-client:
   # 测试时使用,与测试环境保持一致.
-  internal: http://180.76.146.227:8099
+#  internal: http://180.76.146.227:8099
+  internal: http://180.76.146.227:8089
 #  internal: http://47.104.109.52:8099
   # 使用场景: 生产环境部署时,调试后再上线.
 #  internal: http://47.104.109.52:8089

+ 2 - 2
target/classes/application.yml

@@ -1,8 +1,8 @@
 server:
 #  测试环境
-#  port: 8000
+  port: 8000
 #  生产环境
-  port: 18000
+#  port: 18000
 spring:
   application:
     name: fujisu-ocr-server

BIN
target/classes/com/pavis/ai/app/fjsocrasy/common/utils/ocr/AipOcrUtils.class


BIN
target/classes/com/pavis/ai/app/fjsocrasy/controller/BackController.class


BIN
target/classes/com/pavis/ai/app/fjsocrasy/controller/OcrController.class


BIN
target/classes/com/pavis/ai/app/fjsocrasy/service/OcrService.class


BIN
target/classes/com/pavis/ai/app/fjsocrasy/service/impl/OcrServiceImpl.class


BIN
target/classes/com/pavis/ai/app/fjsocrasy/service/impl/UploadServiceImpl.class


BIN
target/test-classes/com/pavis/ai/app/fjsocrasy/FjsOcrAsyApplicationTests.class