|
@@ -3,7 +3,7 @@
|
|
|
// (powered by FernFlower decompiler)
|
|
|
//
|
|
|
|
|
|
-package kd.imc.rim.common.helper;
|
|
|
+package kd.imc.rim;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
@@ -12,12 +12,14 @@ import com.google.common.collect.Maps;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.io.Serializable;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -26,7 +28,7 @@ import java.util.stream.Collectors;
|
|
|
import kd.bos.context.RequestContext;
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
-import kd.bos.dataentity.utils.ObjectUtils;
|
|
|
+import kd.bos.dataentity.resource.ResManager;
|
|
|
import kd.bos.dataentity.utils.StringUtils;
|
|
|
import kd.bos.fileservice.FileServiceFactory;
|
|
|
import kd.bos.logging.Log;
|
|
@@ -35,6 +37,8 @@ import kd.bos.orm.query.QFilter;
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
+import kd.imc.aws.ofd.util.analysis.OfdReadUtils;
|
|
|
+import kd.imc.aws.ofd.util.model.VatInvoice;
|
|
|
import kd.imc.rim.common.constant.AttachConstant;
|
|
|
import kd.imc.rim.common.constant.FpzsConstant;
|
|
|
import kd.imc.rim.common.constant.InputInvoiceTypeEnum;
|
|
@@ -64,13 +68,12 @@ import kd.imc.rim.common.utils.UUID;
|
|
|
import kd.imc.rim.common.utils.itextpdf.ItextPdfUtils;
|
|
|
import kd.imc.rim.common.utils.itextpdf.UrlServiceUtils;
|
|
|
import kd.imc.rim.file.utils.FileConvertUtils;
|
|
|
-import kd.imc.rim.file.utils.ofd.OfdUtil;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
|
|
|
|
public class RecognitionCheckHelperEx {
|
|
|
- private static Log logger = LogFactory.getLog(RecognitionCheckHelper.class);
|
|
|
- private static final String awsRecognitionImpl = "kd.imc.rim.common.invoice.recognitionnew.impl.AwsRecognitionServiceEx";
|
|
|
+ private static Log logger = LogFactory.getLog(RecognitionCheckHelperEx.class);
|
|
|
+ private static final String awsRecognitionImpl = "kd.imc.rim.AwsRecognitionServiceEx";
|
|
|
private static final String HANGXINCHECKSERIVCESTR = "kd.imc.rim.common.invoice.checknew.impl.HangxinCheckService";
|
|
|
private InvoiceCollectService invoiceCollectService = new InvoiceCollectService();
|
|
|
|
|
@@ -88,7 +91,7 @@ public class RecognitionCheckHelperEx {
|
|
|
int pageNo = 0;
|
|
|
Map<String, String> configMap = ImcConfigUtil.getValue("rim_recog_check");
|
|
|
String recognitionImplStr = (String)configMap.get("rimpl");
|
|
|
- boolean isAwsRecognition = StringUtils.isEmpty(recognitionImplStr) || "kd.imc.rim.common.invoice.recognitionnew.impl.AwsRecognitionServiceEx".equals(recognitionImplStr);
|
|
|
+ boolean isAwsRecognition = StringUtils.isEmpty(recognitionImplStr) || "kd.imc.rim.AwsRecognitionServiceEx".equals(recognitionImplStr);
|
|
|
String cachhour = (String)configMap.get("cache_hour");
|
|
|
int cacheHour = 24;
|
|
|
if (!StringUtils.isEmpty(cachhour)) {
|
|
@@ -109,7 +112,7 @@ public class RecognitionCheckHelperEx {
|
|
|
Throwable var16 = null;
|
|
|
|
|
|
try {
|
|
|
- if (fileEntityList == null || ((List)fileEntityList).isEmpty()) {
|
|
|
+ if (((List)fileEntityList).isEmpty()) {
|
|
|
fileEntity.setFileSize(fileInputStream.available());
|
|
|
}
|
|
|
|
|
@@ -143,23 +146,38 @@ public class RecognitionCheckHelperEx {
|
|
|
|
|
|
RecognitionResult recognitionResult = new RecognitionResult();
|
|
|
JSONObject analysisInvoiceInfo = entity.getInvoiceInfo();
|
|
|
- boolean flag = !ObjectUtils.isEmpty(analysisInvoiceInfo) && analysisInvoiceInfo.getLong("invoiceType") != 0L;
|
|
|
- if (analysisInvoiceInfo != null && flag) {
|
|
|
+ boolean resultFlag = false;
|
|
|
+ boolean isMore = false;
|
|
|
+ if (analysisInvoiceInfo != null) {
|
|
|
+ Object invoice = analysisInvoiceInfo.get("invoice");
|
|
|
+ if (invoice == null) {
|
|
|
+ invoice = analysisInvoiceInfo;
|
|
|
+ } else {
|
|
|
+ isMore = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ resultFlag = this.getValidateFlag(invoice);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (resultFlag) {
|
|
|
List entityList = Lists.newArrayList();
|
|
|
JSONArray invoiceArray = new JSONArray();
|
|
|
- invoiceArray.add(analysisInvoiceInfo);
|
|
|
+ if (isMore) {
|
|
|
+ invoiceArray.addAll(analysisInvoiceInfo.getJSONArray("invoice"));
|
|
|
+ } else {
|
|
|
+ invoiceArray.add(analysisInvoiceInfo);
|
|
|
+ }
|
|
|
+
|
|
|
String itemsKey = "items";
|
|
|
ConvertFieldUtil.convertRecognitionEntity(entityList, invoiceArray, new String[]{itemsKey, "item"});
|
|
|
recognitionResult.setErrcode("0000");
|
|
|
recognitionResult.setData(entityList);
|
|
|
- logger.info("全电票转识别结果:{}", recognitionResult);
|
|
|
+ logger.info("识别结果取pdf解析..");
|
|
|
} else {
|
|
|
exceptionDecr = true;
|
|
|
threadCount = CacheHelper.inc("recogThread", countTimeOut);
|
|
|
logger.info("识别线程数量{}", threadCount);
|
|
|
- //调用接口
|
|
|
- recognitionResult = RecognitionFactory.getRecognitionService(awsRecognitionImpl).recognitionInvoice(recognitionParam);
|
|
|
-
|
|
|
+ recognitionResult = RecognitionFactory.getRecognitionService("kd.imc.rim.AwsRecognitionServiceEx").recognitionInvoice(recognitionParam);
|
|
|
threadCount = CacheHelper.decr("recogThread", countTimeOut);
|
|
|
exceptionDecr = false;
|
|
|
}
|
|
@@ -174,23 +192,23 @@ public class RecognitionCheckHelperEx {
|
|
|
String salelistposturl = (String)configMap.get("salelistposturl");
|
|
|
if (!StringUtils.isEmpty(salelistposturl)) {
|
|
|
ByteArrayInputStream saleListByteArrayStream = new ByteArrayInputStream(streamByte);
|
|
|
- Throwable var32 = null;
|
|
|
+ Throwable var33 = null;
|
|
|
|
|
|
try {
|
|
|
RecognitionParam saleListParam = new RecognitionParam(saleListByteArrayStream, extMap);
|
|
|
saleListParam.setFileName(fileName);
|
|
|
saleListParam.setRecogConfigMap(configMap);
|
|
|
this.saleListRecognition(recognitionDataList, saleListParam);
|
|
|
- } catch (Throwable var79) {
|
|
|
- var32 = var79;
|
|
|
- throw var79;
|
|
|
+ } catch (Throwable var80) {
|
|
|
+ var33 = var80;
|
|
|
+ throw var80;
|
|
|
} finally {
|
|
|
if (saleListByteArrayStream != null) {
|
|
|
- if (var32 != null) {
|
|
|
+ if (var33 != null) {
|
|
|
try {
|
|
|
saleListByteArrayStream.close();
|
|
|
- } catch (Throwable var78) {
|
|
|
- var32.addSuppressed(var78);
|
|
|
+ } catch (Throwable var79) {
|
|
|
+ var33.addSuppressed(var79);
|
|
|
}
|
|
|
} else {
|
|
|
saleListByteArrayStream.close();
|
|
@@ -202,16 +220,16 @@ public class RecognitionCheckHelperEx {
|
|
|
|
|
|
this.supRecognitionInfo(recognitionDataList, isAwsRecognition, fileHash, fileName, pageNo, resultList, configMap);
|
|
|
}
|
|
|
- } catch (Throwable var81) {
|
|
|
- var24 = var81;
|
|
|
- throw var81;
|
|
|
+ } catch (Throwable var82) {
|
|
|
+ var24 = var82;
|
|
|
+ throw var82;
|
|
|
} finally {
|
|
|
if (byteArrayInputStream != null) {
|
|
|
if (var24 != null) {
|
|
|
try {
|
|
|
byteArrayInputStream.close();
|
|
|
- } catch (Throwable var77) {
|
|
|
- var24.addSuppressed(var77);
|
|
|
+ } catch (Throwable var78) {
|
|
|
+ var24.addSuppressed(var78);
|
|
|
}
|
|
|
} else {
|
|
|
byteArrayInputStream.close();
|
|
@@ -219,24 +237,24 @@ public class RecognitionCheckHelperEx {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- } catch (Throwable var83) {
|
|
|
+ } catch (Throwable var84) {
|
|
|
if (exceptionDecr && threadCount > 0L) {
|
|
|
threadCount = CacheHelper.decr("recogThread", countTimeOut);
|
|
|
}
|
|
|
|
|
|
- logger.error("ByteArrayInputStream error:", var83);
|
|
|
- throw var83;
|
|
|
+ logger.error("ByteArrayInputStream error:", var84);
|
|
|
+ throw var84;
|
|
|
}
|
|
|
- } catch (Throwable var84) {
|
|
|
- var16 = var84;
|
|
|
- throw var84;
|
|
|
+ } catch (Throwable var85) {
|
|
|
+ var16 = var85;
|
|
|
+ throw var85;
|
|
|
} finally {
|
|
|
if (fileInputStream != null) {
|
|
|
if (var16 != null) {
|
|
|
try {
|
|
|
fileInputStream.close();
|
|
|
- } catch (Throwable var76) {
|
|
|
- var16.addSuppressed(var76);
|
|
|
+ } catch (Throwable var77) {
|
|
|
+ var16.addSuppressed(var77);
|
|
|
}
|
|
|
} else {
|
|
|
fileInputStream.close();
|
|
@@ -249,6 +267,63 @@ public class RecognitionCheckHelperEx {
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
+ private boolean getValidateFlag(Object analysisInvoiceInfo) {
|
|
|
+ if (analysisInvoiceInfo == null) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ boolean resultFlag = false;
|
|
|
+ if (analysisInvoiceInfo instanceof JSONObject) {
|
|
|
+ resultFlag = InputInvoiceTypeEnum.ELECTRIC_ORDINARY.getCode().equals(((JSONObject)analysisInvoiceInfo).getLong("invoiceType")) || InputInvoiceTypeEnum.ELECTRIC_SPECIAL.getCode().equals(((JSONObject)analysisInvoiceInfo).getLong("invoiceType"));
|
|
|
+ if (!resultFlag) {
|
|
|
+ resultFlag = this.checkParamValidate((JSONObject)analysisInvoiceInfo);
|
|
|
+ }
|
|
|
+ } else if (analysisInvoiceInfo instanceof JSONArray) {
|
|
|
+ JSONArray array = (JSONArray)analysisInvoiceInfo;
|
|
|
+
|
|
|
+ for(int i = 0; i < array.size(); ++i) {
|
|
|
+ resultFlag = InputInvoiceTypeEnum.ELECTRIC_ORDINARY.getCode().equals(array.getJSONObject(i).getLong("invoiceType")) || InputInvoiceTypeEnum.ELECTRIC_SPECIAL.getCode().equals(array.getJSONObject(i).getLong("invoiceType"));
|
|
|
+ if (!resultFlag) {
|
|
|
+ resultFlag = this.checkParamValidate(array.getJSONObject(i));
|
|
|
+ if (!resultFlag) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (analysisInvoiceInfo instanceof ArrayList) {
|
|
|
+ List<Map<String, Object>> list = (List)analysisInvoiceInfo;
|
|
|
+ Iterator var7 = list.iterator();
|
|
|
+
|
|
|
+ while(var7.hasNext()) {
|
|
|
+ Map<String, Object> map = (Map)var7.next();
|
|
|
+ resultFlag = InputInvoiceTypeEnum.ELECTRIC_ORDINARY.getCode().equals(Long.parseLong(map.get("invoiceType") + "")) || InputInvoiceTypeEnum.ELECTRIC_SPECIAL.getCode().equals(Long.parseLong(map.get("invoiceType") + ""));
|
|
|
+ if (!resultFlag) {
|
|
|
+ resultFlag = this.checkParamValidate(new JSONObject(map));
|
|
|
+ if (!resultFlag) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultFlag;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean checkParamValidate(JSONObject invoice) {
|
|
|
+ String invoiceCode = invoice.getString("invoiceCode");
|
|
|
+ String invoiceNo = invoice.getString("invoiceNo");
|
|
|
+ String invoiceAmount = invoice.getString("invoiceAmount");
|
|
|
+ String invoiceDate = invoice.getString("invoiceDate");
|
|
|
+ boolean validate = StringUtils.isNotEmpty(invoiceCode) && StringUtils.isNotEmpty(invoiceNo) && StringUtils.isNotEmpty(invoiceAmount) && StringUtils.isNotEmpty(invoiceDate);
|
|
|
+ Long invoiceType = invoice.getLong("invoiceType");
|
|
|
+ if (!InputInvoiceTypeEnum.ORDINARY_ELECTRON.getCode().equals(invoiceType) && !InputInvoiceTypeEnum.ORDINARY_PAPER.getCode().equals(invoiceType) && !InputInvoiceTypeEnum.ORDINARY_ROLL.getCode().equals(invoiceType) && !InputInvoiceTypeEnum.TOLL_ELECTRON.getCode().equals(invoiceType)) {
|
|
|
+ return validate;
|
|
|
+ } else {
|
|
|
+ String checkCode = invoice.getString("checkCode");
|
|
|
+ return validate && StringUtils.isNotEmpty(checkCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private String getOverseaAppCode(Map<String, String> configMap) {
|
|
|
if (configMap == null) {
|
|
|
return null;
|
|
@@ -315,10 +390,8 @@ public class RecognitionCheckHelperEx {
|
|
|
|
|
|
private StringBuilder getMsgExceptionInfo(RecognitionResult recognitionResult) {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("识别失败,识别接口返回:【");
|
|
|
- sb.append(recognitionResult.getErrcode());
|
|
|
- sb.append('】');
|
|
|
- sb.append(recognitionResult.getDescription());
|
|
|
+ String str = String.format(ResManager.loadKDString("识别失败,识别接口返回:【%1$s】%2$s", "RecognitionCheckHelper_1", "imc-rim-common", new Object[0]), recognitionResult.getErrcode(), recognitionResult.getDescription());
|
|
|
+ sb.append(str);
|
|
|
return sb;
|
|
|
}
|
|
|
|
|
@@ -351,12 +424,12 @@ public class RecognitionCheckHelperEx {
|
|
|
String invoiceCode;
|
|
|
if (object.getClass() != null) {
|
|
|
invoiceType = recognitionInfo.getLong("invoiceType");
|
|
|
+ String exit;
|
|
|
if (InputInvoiceTypeEnum.AIR_INVOICE.getCode().equals(invoiceType)) {
|
|
|
invoiceCode = recognitionInfo.getString("invoiceDate");
|
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
|
|
|
- String issueDate = recognitionInfo.getString("issueDate");
|
|
|
- if (StringUtils.isNotEmpty(issueDate)) {
|
|
|
- Date date = simpleDateFormat.parse(issueDate);
|
|
|
+ exit = recognitionInfo.getString("issueDate");
|
|
|
+ if (StringUtils.isNotBlank(exit)) {
|
|
|
+ Date date = recognitionInfo.getDate("issueDate");
|
|
|
if (StringUtils.isEmpty(invoiceCode) || "OPEN".equalsIgnoreCase(invoiceCode)) {
|
|
|
recognitionInfo.put("invoiceDate", DateUtils.format(date, "yyyy-MM-dd"));
|
|
|
}
|
|
@@ -366,7 +439,7 @@ public class RecognitionCheckHelperEx {
|
|
|
isPass = ConvertFieldUtil.checkNullValidate(recognitionInfo, object.getClass());
|
|
|
if (isPass && InputInvoiceTypeEnum.ROAD_BRIDGE.getCode().equals(invoiceType)) {
|
|
|
invoiceCode = recognitionInfo.getString("invoiceCode");
|
|
|
- String exit = recognitionInfo.getString("exit");
|
|
|
+ exit = recognitionInfo.getString("exit");
|
|
|
if (StringUtils.isEmpty(invoiceCode) && StringUtils.isEmpty(exit)) {
|
|
|
isPass = false;
|
|
|
}
|
|
@@ -404,7 +477,7 @@ public class RecognitionCheckHelperEx {
|
|
|
}
|
|
|
|
|
|
if (InvoiceConvertUtils.isSaleListInvoiceType(invoiceType)) {
|
|
|
- this.markSaleListInvoice(recognitionInfo);
|
|
|
+ markSaleListInvoice(recognitionInfo);
|
|
|
}
|
|
|
|
|
|
recognitionInfo.put("fileHash", fileHash);
|
|
@@ -425,7 +498,7 @@ public class RecognitionCheckHelperEx {
|
|
|
if (valueObj instanceof BigDecimal) {
|
|
|
String valueObjStr = valueObj.toString().replace("-", "");
|
|
|
if (BigDecimalUtil.transDecimal(valueObjStr).compareTo(FpzsConstant.sysMaxAmount) > 0) {
|
|
|
- valueObj = BigDecimal.ZERO;
|
|
|
+ valueObj = BigDecimal.ZERO;
|
|
|
logger.info("发票{} 超过系统金额最大值:{} 置为0", object.getKey(), FpzsConstant.sysMaxAmount);
|
|
|
recognitionInfo.put((String)object.getKey(), valueObj);
|
|
|
}
|
|
@@ -445,7 +518,7 @@ public class RecognitionCheckHelperEx {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void markSaleListInvoice(JSONObject recognitionInfo) {
|
|
|
+ public static void markSaleListInvoice(JSONObject recognitionInfo) {
|
|
|
JSONArray items = recognitionInfo.getJSONArray("items");
|
|
|
recognitionInfo.put("isSaleListInvoice", "0");
|
|
|
if (items != null && items.size() == 1) {
|
|
@@ -477,7 +550,7 @@ public class RecognitionCheckHelperEx {
|
|
|
return ItextPdfUtils.extractpdf(url, fileName);
|
|
|
} else {
|
|
|
if (FileUtils.checkFileType(fileName, new String[]{"ofd"})) {
|
|
|
- JSONObject result = this.ofdAnalysis(url);
|
|
|
+ JSONObject result = (JSONObject) this.ofdAnalysis(url);
|
|
|
if (result != null) {
|
|
|
fileEntity.setFileSize(BigDecimalUtil.transDecimal(result.getString("fileSize")).intValue());
|
|
|
}
|
|
@@ -493,40 +566,43 @@ public class RecognitionCheckHelperEx {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private JSONObject ofdAnalysis(String fileUrl) {
|
|
|
+ private Serializable ofdAnalysis(String fileUrl) {
|
|
|
try {
|
|
|
InputStream fileInputStream = UrlServiceUtils.getAttachmentDecodedStream(FileServiceFactory.getAttachmentFileService().getInputStream(fileUrl));
|
|
|
Throwable var3 = null;
|
|
|
|
|
|
- JSONObject var20;
|
|
|
+ Long invoiceType;
|
|
|
try {
|
|
|
byte[] streamByte = FileUtils.getByte(fileInputStream);
|
|
|
- JSONObject result = OfdUtil.analysis(streamByte);
|
|
|
- if (result != null) {
|
|
|
- if ("1".equals(result.getString("type"))) {
|
|
|
- String invoiceCode = result.getString("invoiceCode");
|
|
|
- String invoiceNo = result.getString("invoiceNo");
|
|
|
- String type = InvoiceConvertUtils.checkInvoiceType(invoiceCode, invoiceNo);
|
|
|
- result.put("invoiceType", InputInvoiceTypeEnum.getInvoiceTypeByAwsType(type));
|
|
|
- result.remove("type");
|
|
|
- } else {
|
|
|
- result.put("invoiceType", InputInvoiceTypeEnum.getInvoiceTypeByAwsType(result.getString("invoiceType")));
|
|
|
- }
|
|
|
+ JSONObject result;
|
|
|
+ if (streamByte == null) {
|
|
|
+ result = null;
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
+ result = OfdReadUtils.readData(streamByte);
|
|
|
+ Object invoice = result.get("invoice");
|
|
|
+ VatInvoice vatInvoice = (VatInvoice)invoice;
|
|
|
+ result = JSON.parseObject(JSON.toJSONString(vatInvoice));
|
|
|
+ if (vatInvoice != null) {
|
|
|
+ invoiceType = InputInvoiceTypeEnum.getInvoiceTypeByAwsType(vatInvoice.getInvoiceType());
|
|
|
+ result.put("invoiceType", invoiceType);
|
|
|
result.put("fileSize", streamByte.length);
|
|
|
+ JSONObject var9 = result;
|
|
|
+ return var9;
|
|
|
}
|
|
|
|
|
|
- var20 = result;
|
|
|
- } catch (Throwable var17) {
|
|
|
- var3 = var17;
|
|
|
- throw var17;
|
|
|
+ invoiceType = null;
|
|
|
+ } catch (Throwable var21) {
|
|
|
+ var3 = var21;
|
|
|
+ throw var21;
|
|
|
} finally {
|
|
|
if (fileInputStream != null) {
|
|
|
if (var3 != null) {
|
|
|
try {
|
|
|
fileInputStream.close();
|
|
|
- } catch (Throwable var16) {
|
|
|
- var3.addSuppressed(var16);
|
|
|
+ } catch (Throwable var20) {
|
|
|
+ var3.addSuppressed(var20);
|
|
|
}
|
|
|
} else {
|
|
|
fileInputStream.close();
|
|
@@ -535,8 +611,9 @@ public class RecognitionCheckHelperEx {
|
|
|
|
|
|
}
|
|
|
|
|
|
- return var20;
|
|
|
- } catch (Exception var19) {
|
|
|
+ return invoiceType;
|
|
|
+ } catch (Exception var23) {
|
|
|
+ logger.info("ofdAnalysis exception :{}", var23);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
@@ -569,7 +646,7 @@ public class RecognitionCheckHelperEx {
|
|
|
JSONObject invoiceInfo = (JSONObject)var5.next();
|
|
|
JSONObject result = invoiceInfo;
|
|
|
Long invoiceType = invoiceInfo.getLong("invoiceType");
|
|
|
- if (!InvoiceConvertUtils.isVatInvoiceType(invoiceType)) {
|
|
|
+ if (!InputInvoiceTypeEnum.needCheck(invoiceType)) {
|
|
|
checkResultList.add(invoiceInfo);
|
|
|
} else {
|
|
|
CheckParam checkParam = ConvertFieldUtil.getInvoiceCheckPart(invoiceInfo);
|
|
@@ -583,6 +660,11 @@ public class RecognitionCheckHelperEx {
|
|
|
String invoiceCheckStr = JSONObject.toJSONString(invoiceEntity);
|
|
|
JSONObject invoiceCheckInfo = JSON.parseObject(invoiceCheckStr);
|
|
|
this.putRecognitionInfo(invoiceCheckInfo, invoiceInfo);
|
|
|
+ if (InputInvoiceTypeEnum.AIR_ELE_INVOICE.getCode().equals(invoiceType)) {
|
|
|
+ invoiceInfo.putAll(invoiceCheckInfo);
|
|
|
+ invoiceCheckInfo = this.mixAirEleData(invoiceInfo);
|
|
|
+ }
|
|
|
+
|
|
|
result = invoiceCheckInfo;
|
|
|
String originalStateDefault = (String)extMap.get("originalStateDefault");
|
|
|
boolean typeFlag = InputInvoiceTypeEnum.ORDINARY_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.TOLL_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.SPECIAL_ELECTRON.getCode().equals(invoiceType);
|
|
@@ -612,6 +694,26 @@ public class RecognitionCheckHelperEx {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private JSONObject mixAirEleData(JSONObject invoiceInfo) {
|
|
|
+ if (invoiceInfo == null) {
|
|
|
+ return new JSONObject();
|
|
|
+ } else {
|
|
|
+ Object issueDate = invoiceInfo.get("issueDate");
|
|
|
+ if (issueDate instanceof Integer) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+
|
|
|
+ try {
|
|
|
+ Date date = sdf.parse(String.valueOf(issueDate));
|
|
|
+ invoiceInfo.put("invoiceDate", date);
|
|
|
+ invoiceInfo.put("issueDate", date);
|
|
|
+ } catch (ParseException var5) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return invoiceInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static void markSaleListByCheckResult(JSONObject invoiceCheckInfo) {
|
|
|
invoiceCheckInfo.put("isSaleListInvoice", "0");
|
|
|
JSONArray items = invoiceCheckInfo.getJSONArray("items");
|
|
@@ -737,6 +839,10 @@ public class RecognitionCheckHelperEx {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public JSONArray bindAttachInvoice(JSONArray targetArray, JSONObject businessParam) {
|
|
|
+ return this.bindAttachInvoice(targetArray, businessParam, new HashMap(0));
|
|
|
+ }
|
|
|
+
|
|
|
public JSONArray bindAttachInvoice(JSONArray targetArray, JSONObject businessParam, Map<String, Long> invoiceTypeMap) {
|
|
|
JSONArray attachArray = new JSONArray();
|
|
|
if (targetArray.size() == 0) {
|
|
@@ -746,9 +852,11 @@ public class RecognitionCheckHelperEx {
|
|
|
JSONObject invoiceInfo = (JSONObject)i;
|
|
|
int pageNo = invoiceInfo.getInteger("pageNo");
|
|
|
boolean originalCheck = "1".equals(invoiceInfo.getString("originalState"));
|
|
|
- if (!originalCheck) {
|
|
|
- String invoiceCode = invoiceInfo.getString("invoiceCode");
|
|
|
- String invoiceNo = invoiceInfo.getString("invoiceNo");
|
|
|
+ String invoiceCode = invoiceInfo.getString("invoiceCode");
|
|
|
+ String invoiceNo = invoiceInfo.getString("invoiceNo");
|
|
|
+ Long invoiceType = (Long)invoiceTypeMap.get(StringUtils.trimToEmpty(invoiceCode) + StringUtils.trimToEmpty(invoiceNo));
|
|
|
+ boolean salerInvoiceType = invoiceType == null || InvoiceConvertUtils.isSaleListInvoiceType(invoiceType);
|
|
|
+ if (!originalCheck && salerInvoiceType) {
|
|
|
DynamicObject attachObject = this.getAttachDynamicObject(invoiceInfo, businessParam);
|
|
|
DynamicObject attachSaveObject = (DynamicObject)SaveServiceHelper.save(new DynamicObject[]{attachObject})[0];
|
|
|
JSONObject attachInfo = new JSONObject(DynamicObjectUtil.dynamicObject2Map(attachSaveObject));
|
|
@@ -817,11 +925,12 @@ public class RecognitionCheckHelperEx {
|
|
|
QFilter filter3 = new QFilter("attach_hash_value", "=", invoiceInfo.getString("fileHash"));
|
|
|
DynamicObject idObject = QueryServiceHelper.queryOne("rim_attach", "id", new QFilter[]{filter1, filter2, filter3});
|
|
|
DynamicObject attachObject = null;
|
|
|
- if (idObject == null) {
|
|
|
+ boolean pdfFlag = "1".equals(invoiceInfo.getString("fileType"));
|
|
|
+ if (idObject != null && !pdfFlag) {
|
|
|
+ attachObject = BusinessDataServiceHelper.loadSingle(idObject.get("id"), "rim_attach");
|
|
|
+ } else {
|
|
|
attachObject = BusinessDataServiceHelper.newDynamicObject("rim_attach");
|
|
|
attachObject.set("create_time", new Date());
|
|
|
- } else {
|
|
|
- attachObject = BusinessDataServiceHelper.loadSingle(idObject.get("id"), "rim_attach");
|
|
|
}
|
|
|
|
|
|
attachObject.set("update_time", new Date());
|
|
@@ -831,24 +940,27 @@ public class RecognitionCheckHelperEx {
|
|
|
}
|
|
|
|
|
|
attachObject.set("attach_no", attachNo);
|
|
|
- if ("1".equals(invoiceInfo.getString("fileType"))) {
|
|
|
- attachObject.set("attach_url", invoiceInfo.getString("pdfUrl"));
|
|
|
- } else if ("4".equals(invoiceInfo.getString("fileType"))) {
|
|
|
- attachObject.set("attach_url", invoiceInfo.getString("ofdUrl"));
|
|
|
+ attachObject.set("attach_url", invoiceInfo.getString("snapshotUrl"));
|
|
|
+ String subFileName = invoiceInfo.getString("subFileName");
|
|
|
+ String pageNum;
|
|
|
+ if (StringUtils.isNotEmpty(subFileName)) {
|
|
|
+ attachObject.set("attach_type", "2");
|
|
|
+ attachObject.set("attach_name", subFileName);
|
|
|
+ pageNum = subFileName.substring(subFileName.lastIndexOf(46) + 1);
|
|
|
+ attachObject.set("file_extension", pageNum);
|
|
|
} else {
|
|
|
- attachObject.set("attach_url", invoiceInfo.getString("snapshotUrl"));
|
|
|
+ attachObject.set("attach_type", invoiceInfo.getString("fileType"));
|
|
|
+ attachObject.set("attach_name", invoiceInfo.getString("fileName"));
|
|
|
+ pageNum = invoiceInfo.getString("fileName").substring(invoiceInfo.getString("fileName").lastIndexOf(46) + 1);
|
|
|
+ attachObject.set("file_extension", pageNum);
|
|
|
}
|
|
|
|
|
|
- attachObject.set("attach_type", invoiceInfo.getString("fileType"));
|
|
|
attachObject.set("attach_category", AttachConstant.ATTACH_LIST_CATEGORY_ID);
|
|
|
- attachObject.set("attach_name", invoiceInfo.getString("fileName"));
|
|
|
attachObject.set("original_name", invoiceInfo.getString("fileName"));
|
|
|
- String fileExtension = invoiceInfo.getString("fileName").substring(invoiceInfo.getString("fileName").lastIndexOf(46) + 1);
|
|
|
- attachObject.set("file_extension", fileExtension);
|
|
|
attachObject.set("snapshot_url", invoiceInfo.getString("snapshotUrl"));
|
|
|
attachObject.set("icon_url", invoiceInfo.getString("snapshotUrl"));
|
|
|
attachObject.set("attach_hash_value", invoiceInfo.getString("fileHash"));
|
|
|
- String pageNum = invoiceInfo.getString("pageNum");
|
|
|
+ pageNum = invoiceInfo.getString("pageNum");
|
|
|
if (StringUtils.isNotEmpty(pageNum)) {
|
|
|
try {
|
|
|
String target = pageNum.replaceAll(" ", "");
|
|
@@ -860,8 +972,8 @@ public class RecognitionCheckHelperEx {
|
|
|
String pageNo = target.substring(index3, subStr.length()).substring(1);
|
|
|
attachObject.set("page_sum", Integer.valueOf(pageSum));
|
|
|
attachObject.set("page_no", Integer.valueOf(pageNo));
|
|
|
- } catch (Exception var20) {
|
|
|
- logger.info("截取总页码失败:", var20);
|
|
|
+ } catch (Exception var21) {
|
|
|
+ logger.info("截取总页码失败:", var21);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -871,15 +983,20 @@ public class RecognitionCheckHelperEx {
|
|
|
public JSONArray getTargetArray(JSONArray finalResult) {
|
|
|
return (JSONArray)finalResult.stream().filter((f) -> {
|
|
|
JSONObject invoiceInfo = (JSONObject)f;
|
|
|
- String invoiceCode = invoiceInfo.getString("invoiceCode");
|
|
|
- String invoiceNo = invoiceInfo.getString("invoiceNo");
|
|
|
- boolean typeCheck = InputInvoiceTypeEnum.OTHER_INVOICE.getCode().equals(invoiceInfo.getLong("invoiceType"));
|
|
|
- boolean emptyCheck = StringUtils.isNotEmpty(invoiceCode) && StringUtils.isNotEmpty(invoiceNo);
|
|
|
- boolean titleCheck = StringUtils.isNotEmpty(invoiceInfo.getString("title")) && invoiceInfo.getString("title").contains("清单");
|
|
|
- return typeCheck && emptyCheck && titleCheck;
|
|
|
+ return isSalePage(invoiceInfo);
|
|
|
}).collect(Collectors.toCollection(JSONArray::new));
|
|
|
}
|
|
|
|
|
|
+ public static boolean isSalePage(JSONObject invoiceInfo) {
|
|
|
+ String invoiceCode = invoiceInfo.getString("invoiceCode");
|
|
|
+ String invoiceNo = invoiceInfo.getString("invoiceNo");
|
|
|
+ boolean typeCheck = InputInvoiceTypeEnum.OTHER_INVOICE.getCode().equals(invoiceInfo.getLong("invoiceType"));
|
|
|
+ boolean emptyCheck = StringUtils.isNotEmpty(invoiceCode) && StringUtils.isNotEmpty(invoiceNo);
|
|
|
+ String title = invoiceInfo.getString("title");
|
|
|
+ boolean titleCheck = StringUtils.isNotEmpty(title) && (title.contains("清单") || title.contains("明细"));
|
|
|
+ return typeCheck && emptyCheck && titleCheck;
|
|
|
+ }
|
|
|
+
|
|
|
public void dealInvoiceAttachRelation(JSONObject invoiceInfo) {
|
|
|
if (invoiceInfo != null) {
|
|
|
logger.info("处理发票绑定附件关系....");
|
|
@@ -922,7 +1039,7 @@ public class RecognitionCheckHelperEx {
|
|
|
String attachFields = MetadataUtil.getFields("rim_attach");
|
|
|
DynamicObject[] attachCollect = BusinessDataServiceHelper.load("rim_attach", attachFields, new QFilter[]{attachNoFilter});
|
|
|
int bindNum = 0;
|
|
|
- DynamicObject attachObject;
|
|
|
+ DynamicObject attachOne;
|
|
|
if (attachCollect != null && attachCollect.length > 0) {
|
|
|
String url = RimConfigUtils.getConfig("rim_recog_check", "salelistposturl");
|
|
|
if (StringUtils.isNotEmpty(url)) {
|
|
@@ -943,8 +1060,8 @@ public class RecognitionCheckHelperEx {
|
|
|
int var12 = attachCollect.length;
|
|
|
|
|
|
for(int var13 = 0; var13 < var12; ++var13) {
|
|
|
- attachObject = var18[var13];
|
|
|
- Long attachId = attachObject.getLong("id");
|
|
|
+ attachOne = var18[var13];
|
|
|
+ Long attachId = attachOne.getLong("id");
|
|
|
boolean isBind = this.checkBind(attachId);
|
|
|
if (isBind) {
|
|
|
++bindNum;
|
|
@@ -955,13 +1072,17 @@ public class RecognitionCheckHelperEx {
|
|
|
|
|
|
QFilter invoiceNoFilter = new QFilter("invoice_no", "=", invoiceNo);
|
|
|
QFilter invoiceCodeFilter = new QFilter("invoice_code", "=", invoiceCode);
|
|
|
+ if (StringUtils.isNotEmpty(invoiceNo) && invoiceNo.length() == 20) {
|
|
|
+ invoiceCodeFilter = null;
|
|
|
+ }
|
|
|
+
|
|
|
String mainFields = MetadataUtil.getFields("rim_invoice");
|
|
|
DynamicObject mainObject = BusinessDataServiceHelper.loadSingle("rim_invoice", mainFields, new QFilter[]{invoiceNoFilter, invoiceCodeFilter});
|
|
|
if (mainObject != null) {
|
|
|
saleListSum = mainObject.getInt("salelist_sum");
|
|
|
if (attachCollect != null && attachCollect.length > 0) {
|
|
|
- attachObject = attachCollect[0];
|
|
|
- int pageSum = attachObject.getInt("page_sum");
|
|
|
+ attachOne = attachCollect[0];
|
|
|
+ int pageSum = attachOne.getInt("page_sum");
|
|
|
if (pageSum != 0 && pageSum != saleListSum) {
|
|
|
mainObject.set("salelist_sum", pageSum);
|
|
|
saleListSum = pageSum;
|