|
@@ -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));
|