|
@@ -0,0 +1,1059 @@
|
|
|
+//
|
|
|
+// Source code recreated from a .class file by IntelliJ IDEA
|
|
|
+// (powered by FernFlower decompiler)
|
|
|
+//
|
|
|
+
|
|
|
+package kd.imc.rim.common.helper;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+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.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+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.utils.StringUtils;
|
|
|
+import kd.bos.fileservice.FileServiceFactory;
|
|
|
+import kd.bos.logging.Log;
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
+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.rim.common.constant.AttachConstant;
|
|
|
+import kd.imc.rim.common.constant.FpzsConstant;
|
|
|
+import kd.imc.rim.common.constant.InputInvoiceTypeEnum;
|
|
|
+import kd.imc.rim.common.invoice.checknew.model.CheckParam;
|
|
|
+import kd.imc.rim.common.invoice.checknew.model.CheckResult;
|
|
|
+import kd.imc.rim.common.invoice.collector.InvoiceCollectService;
|
|
|
+import kd.imc.rim.common.invoice.model.ConvertFieldUtil;
|
|
|
+import kd.imc.rim.common.invoice.model.type.OtherInvoice;
|
|
|
+import kd.imc.rim.common.invoice.recognitionnew.RecognitionFactory;
|
|
|
+import kd.imc.rim.common.invoice.recognitionnew.model.RecognitionParam;
|
|
|
+import kd.imc.rim.common.invoice.recognitionnew.model.RecognitionResult;
|
|
|
+import kd.imc.rim.common.message.exception.MsgException;
|
|
|
+import kd.imc.rim.common.service.SimplyCheckService;
|
|
|
+import kd.imc.rim.common.utils.BigDecimalUtil;
|
|
|
+import kd.imc.rim.common.utils.CacheHelper;
|
|
|
+import kd.imc.rim.common.utils.DateUtils;
|
|
|
+import kd.imc.rim.common.utils.DynamicObjectUtil;
|
|
|
+import kd.imc.rim.common.utils.FileUtils;
|
|
|
+import kd.imc.rim.common.utils.FormFileEntity;
|
|
|
+import kd.imc.rim.common.utils.ImcConfigUtil;
|
|
|
+import kd.imc.rim.common.utils.InvoiceConvertUtils;
|
|
|
+import kd.imc.rim.common.utils.MD5;
|
|
|
+import kd.imc.rim.common.utils.MetadataUtil;
|
|
|
+import kd.imc.rim.common.utils.RimConfigUtils;
|
|
|
+import kd.imc.rim.common.utils.TenantUtils;
|
|
|
+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 final String HANGXINCHECKSERIVCESTR = "kd.imc.rim.common.invoice.checknew.impl.HangxinCheckService";
|
|
|
+ private InvoiceCollectService invoiceCollectService = new InvoiceCollectService();
|
|
|
+
|
|
|
+ public RecognitionCheckHelperEx() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<JSONObject> recognitionInvoiceFile(FormFileEntity fileEntity, Map<String, Object> extMap) throws Exception {
|
|
|
+ List<JSONObject> resultList = Lists.newArrayList();
|
|
|
+ List<FormFileEntity> fileEntityList = fileEntity.getSubFileList();
|
|
|
+ if (fileEntityList == null || ((List)fileEntityList).isEmpty()) {
|
|
|
+ fileEntityList = new ArrayList(1);
|
|
|
+ ((List)fileEntityList).add(fileEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ String cachhour = (String)configMap.get("cache_hour");
|
|
|
+ int cacheHour = 24;
|
|
|
+ if (!StringUtils.isEmpty(cachhour)) {
|
|
|
+ cacheHour = BigDecimalUtil.transDecimal(configMap.get("cache_hour")).intValue();
|
|
|
+ if (cacheHour < 0) {
|
|
|
+ cacheHour = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String overseaAppCode = this.getOverseaAppCode(configMap);
|
|
|
+ Iterator var12 = ((List)fileEntityList).iterator();
|
|
|
+
|
|
|
+ while(var12.hasNext()) {
|
|
|
+ FormFileEntity entity = (FormFileEntity)var12.next();
|
|
|
+ ++pageNo;
|
|
|
+ String fileName = entity.getFileName();
|
|
|
+ InputStream fileInputStream = UrlServiceUtils.getAttachmentDecodedStream(FileServiceFactory.getAttachmentFileService().getInputStream(entity.getFileUrl()));
|
|
|
+ Throwable var16 = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (fileEntityList == null || ((List)fileEntityList).isEmpty()) {
|
|
|
+ fileEntity.setFileSize(fileInputStream.available());
|
|
|
+ }
|
|
|
+
|
|
|
+ byte[] streamByte = FileUtils.getByte(fileInputStream);
|
|
|
+ String fileHash = FileConvertUtils.getSHA256(streamByte);
|
|
|
+ long threadCount = 0L;
|
|
|
+ boolean exceptionDecr = false;
|
|
|
+ int countTimeOut = 60;
|
|
|
+
|
|
|
+ try {
|
|
|
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(streamByte);
|
|
|
+ Throwable var24 = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ RecognitionParam recognitionParam = new RecognitionParam(byteArrayInputStream, extMap);
|
|
|
+ recognitionParam.setFileName(fileName);
|
|
|
+ recognitionParam.setLocalUrl(fileEntity.getFileUrl());
|
|
|
+ recognitionParam.setLocalHash(fileEntity.getFileHash());
|
|
|
+ recognitionParam.setRecogConfigMap(configMap);
|
|
|
+ if (StringUtils.isEmpty(recognitionParam.getLocalHash())) {
|
|
|
+ recognitionParam.setLocalHash(fileHash);
|
|
|
+ }
|
|
|
+
|
|
|
+ recognitionParam.setFileUrl(entity.getFileUrl());
|
|
|
+ recognitionParam.setPageNo(pageNo);
|
|
|
+ recognitionParam.setCacheHour(cacheHour);
|
|
|
+ if (extMap.get("recogType") != null) {
|
|
|
+ recognitionParam.setRecogType(extMap.get("recogType").toString());
|
|
|
+ recognitionParam.setAppCode(overseaAppCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ RecognitionResult recognitionResult = new RecognitionResult();
|
|
|
+ JSONObject analysisInvoiceInfo = entity.getInvoiceInfo();
|
|
|
+ boolean flag = !ObjectUtils.isEmpty(analysisInvoiceInfo) && analysisInvoiceInfo.getLong("invoiceType") != 0L;
|
|
|
+ if (analysisInvoiceInfo != null && flag) {
|
|
|
+ List entityList = Lists.newArrayList();
|
|
|
+ JSONArray invoiceArray = new JSONArray();
|
|
|
+ invoiceArray.add(analysisInvoiceInfo);
|
|
|
+ String itemsKey = "items";
|
|
|
+ ConvertFieldUtil.convertRecognitionEntity(entityList, invoiceArray, new String[]{itemsKey, "item"});
|
|
|
+ recognitionResult.setErrcode("0000");
|
|
|
+ recognitionResult.setData(entityList);
|
|
|
+ logger.info("全电票转识别结果:{}", recognitionResult);
|
|
|
+ } else {
|
|
|
+ exceptionDecr = true;
|
|
|
+ threadCount = CacheHelper.inc("recogThread", countTimeOut);
|
|
|
+ logger.info("识别线程数量{}", threadCount);
|
|
|
+ recognitionResult = RecognitionFactory.getRecognitionService(recognitionImplStr).recognitionInvoice(recognitionParam);
|
|
|
+ threadCount = CacheHelper.decr("recogThread", countTimeOut);
|
|
|
+ exceptionDecr = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (recognitionResult != null) {
|
|
|
+ if (!"0000".equals(recognitionResult.getErrcode())) {
|
|
|
+ StringBuilder sb = this.getMsgExceptionInfo(recognitionResult);
|
|
|
+ throw new MsgException(sb.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Object> recognitionDataList = recognitionResult.getData();
|
|
|
+ String salelistposturl = (String)configMap.get("salelistposturl");
|
|
|
+ if (!StringUtils.isEmpty(salelistposturl)) {
|
|
|
+ ByteArrayInputStream saleListByteArrayStream = new ByteArrayInputStream(streamByte);
|
|
|
+ Throwable var32 = 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;
|
|
|
+ } finally {
|
|
|
+ if (saleListByteArrayStream != null) {
|
|
|
+ if (var32 != null) {
|
|
|
+ try {
|
|
|
+ saleListByteArrayStream.close();
|
|
|
+ } catch (Throwable var78) {
|
|
|
+ var32.addSuppressed(var78);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ saleListByteArrayStream.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.supRecognitionInfo(recognitionDataList, isAwsRecognition, fileHash, fileName, pageNo, resultList, configMap);
|
|
|
+ }
|
|
|
+ } catch (Throwable var81) {
|
|
|
+ var24 = var81;
|
|
|
+ throw var81;
|
|
|
+ } finally {
|
|
|
+ if (byteArrayInputStream != null) {
|
|
|
+ if (var24 != null) {
|
|
|
+ try {
|
|
|
+ byteArrayInputStream.close();
|
|
|
+ } catch (Throwable var77) {
|
|
|
+ var24.addSuppressed(var77);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ byteArrayInputStream.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Throwable var83) {
|
|
|
+ if (exceptionDecr && threadCount > 0L) {
|
|
|
+ threadCount = CacheHelper.decr("recogThread", countTimeOut);
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.error("ByteArrayInputStream error:", var83);
|
|
|
+ throw var83;
|
|
|
+ }
|
|
|
+ } catch (Throwable var84) {
|
|
|
+ var16 = var84;
|
|
|
+ throw var84;
|
|
|
+ } finally {
|
|
|
+ if (fileInputStream != null) {
|
|
|
+ if (var16 != null) {
|
|
|
+ try {
|
|
|
+ fileInputStream.close();
|
|
|
+ } catch (Throwable var76) {
|
|
|
+ var16.addSuppressed(var76);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fileInputStream.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getOverseaAppCode(Map<String, String> configMap) {
|
|
|
+ if (configMap == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ String appCode = (String)configMap.get("overappkey");
|
|
|
+ String appSect = (String)configMap.get("overappsecret");
|
|
|
+ if (!StringUtils.isEmpty(appCode) && !StringUtils.isEmpty(appSect)) {
|
|
|
+ String code = appCode + "@@@" + appSect;
|
|
|
+ String retStr = Base64.encodeBase64String(code.getBytes());
|
|
|
+ return retStr;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saleListRecognition(List<Object> recognitionDataList, RecognitionParam recognitionParam) {
|
|
|
+ List<Object> resultList = Lists.newArrayList();
|
|
|
+ recognitionDataList.stream().forEach((f) -> {
|
|
|
+ if (f instanceof OtherInvoice) {
|
|
|
+ OtherInvoice otherInvoice = (OtherInvoice)f;
|
|
|
+ String invoiceCode = otherInvoice.getInvoiceCode();
|
|
|
+ String invoiceNo = otherInvoice.getInvoiceNo();
|
|
|
+ boolean emptyCheck = StringUtils.isNotEmpty(invoiceCode) && StringUtils.isNotEmpty(invoiceNo);
|
|
|
+ boolean titleCheck = StringUtils.isNotEmpty(otherInvoice.getTitle()) && otherInvoice.getTitle().contains("清单");
|
|
|
+ if (emptyCheck && titleCheck) {
|
|
|
+ try {
|
|
|
+ List<JSONObject> saleListRecognitionList = this.saleListPost(recognitionParam);
|
|
|
+ Iterator var10 = saleListRecognitionList.iterator();
|
|
|
+
|
|
|
+ while(var10.hasNext()) {
|
|
|
+ JSONObject saleList = (JSONObject)var10.next();
|
|
|
+ String saleListCode = saleList.getString("invoiceCode");
|
|
|
+ String saleListNo = saleList.getString("invoiceNo");
|
|
|
+ String saleListPageNum = saleList.getString("pageNum");
|
|
|
+ if (invoiceCode.equals(saleListCode) && invoiceNo.equals(saleListNo)) {
|
|
|
+ otherInvoice.setPageNum(saleListPageNum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception var15) {
|
|
|
+ logger.info("销货清单识别出错:", var15);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resultList.add(f);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<JSONObject> saleListPost(RecognitionParam recognitionParam) throws Exception {
|
|
|
+ RecognitionResult recognitionResult = RecognitionFactory.getSaleListRecognitionService().recognitionInvoice(recognitionParam);
|
|
|
+ if (recognitionResult != null && "0000".equals(recognitionResult.getErrcode())) {
|
|
|
+ List<JSONObject> data = recognitionResult.getData();
|
|
|
+ return (List)data.stream().filter((f) -> {
|
|
|
+ String invoiceCode = f.getString("invoiceCode");
|
|
|
+ String invoiceNo = f.getString("invoiceNo");
|
|
|
+ String pageNum = f.getString("pageNum");
|
|
|
+ return StringUtils.isNotEmpty(invoiceCode) && StringUtils.isNotEmpty(invoiceNo) && StringUtils.isNotEmpty(pageNum);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ return Lists.newArrayList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private StringBuilder getMsgExceptionInfo(RecognitionResult recognitionResult) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append("识别失败,识别接口返回:【");
|
|
|
+ sb.append(recognitionResult.getErrcode());
|
|
|
+ sb.append('】');
|
|
|
+ sb.append(recognitionResult.getDescription());
|
|
|
+ return sb;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void supRecognitionInfo(List<Object> recognitionDataList, boolean isAwsRecognition, String fileHash, String fileName, int pageNo, List<JSONObject> resultList, Map<String, String> configMap) throws ParseException {
|
|
|
+ if (recognitionDataList != null && recognitionDataList.size() != 0) {
|
|
|
+ String otherMust = ImcConfigUtil.getValue(configMap, "other_must", "0");
|
|
|
+ Iterator var9 = recognitionDataList.iterator();
|
|
|
+
|
|
|
+ while(true) {
|
|
|
+ Object object;
|
|
|
+ JSONObject recognitionInfo;
|
|
|
+ do {
|
|
|
+ do {
|
|
|
+ if (!var9.hasNext()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ object = var9.next();
|
|
|
+ } while(object == null);
|
|
|
+
|
|
|
+ String invoiceStr = JSONObject.toJSONString(object);
|
|
|
+ recognitionInfo = JSON.parseObject(invoiceStr);
|
|
|
+ } while(recognitionInfo == null);
|
|
|
+
|
|
|
+ this.setMaxAmount(recognitionInfo);
|
|
|
+ this.dealElectric(recognitionInfo);
|
|
|
+ this.dealBlockChain(recognitionInfo);
|
|
|
+ boolean isPass = false;
|
|
|
+ Long invoiceType;
|
|
|
+ String invoiceCode;
|
|
|
+ if (object.getClass() != null) {
|
|
|
+ invoiceType = recognitionInfo.getLong("invoiceType");
|
|
|
+ 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);
|
|
|
+ if (StringUtils.isEmpty(invoiceCode) || "OPEN".equalsIgnoreCase(invoiceCode)) {
|
|
|
+ recognitionInfo.put("invoiceDate", DateUtils.format(date, "yyyy-MM-dd"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ isPass = ConvertFieldUtil.checkNullValidate(recognitionInfo, object.getClass());
|
|
|
+ if (isPass && InputInvoiceTypeEnum.ROAD_BRIDGE.getCode().equals(invoiceType)) {
|
|
|
+ invoiceCode = recognitionInfo.getString("invoiceCode");
|
|
|
+ String exit = recognitionInfo.getString("exit");
|
|
|
+ if (StringUtils.isEmpty(invoiceCode) && StringUtils.isEmpty(exit)) {
|
|
|
+ isPass = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isPass && InputInvoiceTypeEnum.OTHER_INVOICE.getCode().equals(invoiceType)) {
|
|
|
+ if ("1".equals(otherMust) && StringUtils.isEmpty(recognitionInfo.getString("invoiceNo"))) {
|
|
|
+ isPass = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("2".equals(otherMust) && (StringUtils.isEmpty(recognitionInfo.getString("invoiceNo")) || StringUtils.isEmpty(recognitionInfo.getString("invoiceCode")))) {
|
|
|
+ isPass = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isPass) {
|
|
|
+ recognitionInfo.remove("serialNo");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isPass && StringUtils.isEmpty(recognitionInfo.getString("serialNo"))) {
|
|
|
+ recognitionInfo.put("serialNo", UUID.randomUUID());
|
|
|
+ }
|
|
|
+
|
|
|
+ invoiceType = recognitionInfo.getLong("invoiceType");
|
|
|
+ invoiceCode = recognitionInfo.getString("currency_code");
|
|
|
+ recognitionInfo.put("currency", InvoiceConvertUtils.changeCurrency(invoiceCode));
|
|
|
+ if (!isAwsRecognition) {
|
|
|
+ this.setOtherInfoByType(invoiceType, recognitionInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!InvoiceConvertUtils.isVatInvoiceType(invoiceType)) {
|
|
|
+ recognitionInfo.put("checkStatus", "1");
|
|
|
+ this.recognitionInvoiceMix(recognitionInfo, invoiceType);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (InvoiceConvertUtils.isSaleListInvoiceType(invoiceType)) {
|
|
|
+ this.markSaleListInvoice(recognitionInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ recognitionInfo.put("fileHash", fileHash);
|
|
|
+ recognitionInfo.put("pageNo", pageNo);
|
|
|
+ recognitionInfo.put("fileName", fileName);
|
|
|
+ resultList.add(recognitionInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setMaxAmount(JSONObject recognitionInfo) {
|
|
|
+ Set<Map.Entry<String, Object>> entries = recognitionInfo.entrySet();
|
|
|
+ Iterator var3 = entries.iterator();
|
|
|
+
|
|
|
+ while(var3.hasNext()) {
|
|
|
+ Map.Entry<String, Object> object = (Map.Entry)var3.next();
|
|
|
+ Object valueObj = object.getValue();
|
|
|
+ if (valueObj instanceof BigDecimal) {
|
|
|
+ String valueObjStr = valueObj.toString().replace("-", "");
|
|
|
+ if (BigDecimalUtil.transDecimal(valueObjStr).compareTo(FpzsConstant.sysMaxAmount) > 0) {
|
|
|
+ valueObj = BigDecimal.ZERO;
|
|
|
+ logger.info("发票{} 超过系统金额最大值:{} 置为0", object.getKey(), FpzsConstant.sysMaxAmount);
|
|
|
+ recognitionInfo.put((String)object.getKey(), valueObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dealBlockChain(JSONObject recognitionInfo) {
|
|
|
+ String checkImplStr = RimConfigUtils.getConfig("rim_recog_check", "cimpl");
|
|
|
+ boolean isHangxinCheck = "kd.imc.rim.common.invoice.checknew.impl.HangxinCheckService".equals(checkImplStr);
|
|
|
+ boolean isBlockChainType = InvoiceConvertUtils.isBlockChainType(recognitionInfo.getString("invoiceCode"), recognitionInfo.getString("invoiceNo"));
|
|
|
+ boolean isYunnanChainType = InvoiceConvertUtils.isYunNanBlockchain(recognitionInfo.getString("invoiceCode"), recognitionInfo.getString("invoiceNo"));
|
|
|
+ if (isHangxinCheck && (isBlockChainType || isYunnanChainType)) {
|
|
|
+ recognitionInfo.put("invoiceType", InputInvoiceTypeEnum.GENERAL_ELECTRON.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void markSaleListInvoice(JSONObject recognitionInfo) {
|
|
|
+ JSONArray items = recognitionInfo.getJSONArray("items");
|
|
|
+ recognitionInfo.put("isSaleListInvoice", "0");
|
|
|
+ if (items != null && items.size() == 1) {
|
|
|
+ String goodsName = items.getJSONObject(0).getString("goodsName");
|
|
|
+ if (StringUtils.isNotEmpty(goodsName) && goodsName.contains("详见") && goodsName.contains("清单")) {
|
|
|
+ recognitionInfo.put("isSaleListInvoice", "1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dealElectric(JSONObject recognitionInfo) {
|
|
|
+ String invoiceNo = recognitionInfo.getString("invoiceNo");
|
|
|
+ String invoiceCode = recognitionInfo.getString("invoiceCode");
|
|
|
+ Long invoiceType = recognitionInfo.getLong("invoiceType");
|
|
|
+ if (StringUtils.isNotEmpty(invoiceNo) && invoiceNo.length() == 20 && InputInvoiceTypeEnum.ORDINARY_ROLL.getCode().equals(invoiceType) && StringUtils.isEmpty(invoiceCode)) {
|
|
|
+ recognitionInfo.put("invoiceType", InputInvoiceTypeEnum.ELECTRIC_SPECIAL.getCode());
|
|
|
+ String serialNo = recognitionInfo.getString("serialNo");
|
|
|
+ if (StringUtils.isEmpty(serialNo)) {
|
|
|
+ recognitionInfo.put("serialNo", UUID.randomUUID());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public FormFileEntity getFormFileEntity(String url, String fileName) throws IOException {
|
|
|
+ FormFileEntity fileEntity = new FormFileEntity(url, fileName);
|
|
|
+ if (FileUtils.checkFileType(fileName, new String[]{"pdf"})) {
|
|
|
+ return ItextPdfUtils.extractpdf(url, fileName);
|
|
|
+ } else {
|
|
|
+ if (FileUtils.checkFileType(fileName, new String[]{"ofd"})) {
|
|
|
+ JSONObject result = this.ofdAnalysis(url);
|
|
|
+ if (result != null) {
|
|
|
+ fileEntity.setFileSize(BigDecimalUtil.transDecimal(result.getString("fileSize")).intValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ fileEntity.setInvoiceInfo(result);
|
|
|
+ fileEntity.setFileType("ofd");
|
|
|
+ fileEntity.setSignatureFlag(Boolean.TRUE);
|
|
|
+ } else {
|
|
|
+ fileEntity.setFileType(FileUtils.getFileType(fileName));
|
|
|
+ }
|
|
|
+
|
|
|
+ return fileEntity;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject ofdAnalysis(String fileUrl) {
|
|
|
+ try {
|
|
|
+ InputStream fileInputStream = UrlServiceUtils.getAttachmentDecodedStream(FileServiceFactory.getAttachmentFileService().getInputStream(fileUrl));
|
|
|
+ Throwable var3 = null;
|
|
|
+
|
|
|
+ JSONObject var20;
|
|
|
+ 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")));
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("fileSize", streamByte.length);
|
|
|
+ }
|
|
|
+
|
|
|
+ var20 = result;
|
|
|
+ } catch (Throwable var17) {
|
|
|
+ var3 = var17;
|
|
|
+ throw var17;
|
|
|
+ } finally {
|
|
|
+ if (fileInputStream != null) {
|
|
|
+ if (var3 != null) {
|
|
|
+ try {
|
|
|
+ fileInputStream.close();
|
|
|
+ } catch (Throwable var16) {
|
|
|
+ var3.addSuppressed(var16);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fileInputStream.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return var20;
|
|
|
+ } catch (Exception var19) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Object> getRecognitionCheckExtMap(JSONObject businessParam) {
|
|
|
+ Map<String, Object> extMap = Maps.newHashMap();
|
|
|
+ Long orgId = RequestContext.get().getOrgId();
|
|
|
+ if (businessParam != null) {
|
|
|
+ if (businessParam.getLong("org_id") != null) {
|
|
|
+ orgId = businessParam.getLong("org_id");
|
|
|
+ }
|
|
|
+
|
|
|
+ extMap.put("recogType", businessParam.getString("recogType"));
|
|
|
+ }
|
|
|
+
|
|
|
+ String taxNo = TenantUtils.getTaxNoByOrgId(orgId);
|
|
|
+ extMap.put("eid", RequestContext.get().getUserId());
|
|
|
+ extMap.put("orgId", orgId);
|
|
|
+ extMap.put("taxNo", taxNo);
|
|
|
+ return extMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<JSONObject> checkInvoiceByRecognitionInfo(List<JSONObject> recognitionResultList, Map<String, Object> extMap) {
|
|
|
+ if (recognitionResultList != null && recognitionResultList.size() != 0) {
|
|
|
+ List<JSONObject> checkResultList = Lists.newArrayList();
|
|
|
+ Iterator var5 = recognitionResultList.iterator();
|
|
|
+
|
|
|
+ while(true) {
|
|
|
+ while(var5.hasNext()) {
|
|
|
+ JSONObject invoiceInfo = (JSONObject)var5.next();
|
|
|
+ JSONObject result = invoiceInfo;
|
|
|
+ Long invoiceType = invoiceInfo.getLong("invoiceType");
|
|
|
+ if (!InvoiceConvertUtils.isVatInvoiceType(invoiceType)) {
|
|
|
+ checkResultList.add(invoiceInfo);
|
|
|
+ } else {
|
|
|
+ CheckParam checkParam = ConvertFieldUtil.getInvoiceCheckPart(invoiceInfo);
|
|
|
+ if (checkParam != null) {
|
|
|
+ try {
|
|
|
+ Long orgId = (Long)extMap.get("orgId");
|
|
|
+ String taxNo = (String)extMap.get("taxNo");
|
|
|
+ CheckResult checkResult = SimplyCheckService.checkInvoice(checkParam, orgId, taxNo);
|
|
|
+ if ("0000".equals(checkResult.getErrcode()) && checkResult.getData() != null) {
|
|
|
+ Object invoiceEntity = checkResult.getData();
|
|
|
+ String invoiceCheckStr = JSONObject.toJSONString(invoiceEntity);
|
|
|
+ JSONObject invoiceCheckInfo = JSON.parseObject(invoiceCheckStr);
|
|
|
+ this.putRecognitionInfo(invoiceCheckInfo, 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);
|
|
|
+ if ("1".equals(originalStateDefault) && typeFlag) {
|
|
|
+ invoiceCheckInfo.put("originalState", "1");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result = invoiceInfo;
|
|
|
+ invoiceInfo.put("checkStatus", "2");
|
|
|
+ invoiceInfo.put("errcode", checkResult.getErrcode());
|
|
|
+ invoiceInfo.put("description", checkResult.getDescription());
|
|
|
+ }
|
|
|
+ } catch (Exception var17) {
|
|
|
+ logger.info("查验步骤报错:", var17);
|
|
|
+ invoiceInfo.put("checkStatus", "2");
|
|
|
+ }
|
|
|
+
|
|
|
+ checkResultList.add(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return checkResultList;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void markSaleListByCheckResult(JSONObject invoiceCheckInfo) {
|
|
|
+ invoiceCheckInfo.put("isSaleListInvoice", "0");
|
|
|
+ JSONArray items = invoiceCheckInfo.getJSONArray("items");
|
|
|
+ if (items != null && items.size() > 8) {
|
|
|
+ invoiceCheckInfo.put("isSaleListInvoice", "1");
|
|
|
+ putSaleListSum(invoiceCheckInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject putRecognitionInfo(JSONObject invoiceCheckInfo, JSONObject recognitionInfo) {
|
|
|
+ invoiceCheckInfo.put("continuousNo", recognitionInfo.get("continuousNo"));
|
|
|
+ invoiceCheckInfo.put("currency", recognitionInfo.get("currency"));
|
|
|
+ invoiceCheckInfo.put("barcode", recognitionInfo.get("barcode"));
|
|
|
+ invoiceCheckInfo.put("qrcode", recognitionInfo.get("qrcode"));
|
|
|
+ invoiceCheckInfo.put("companySeal", recognitionInfo.get("companySeal"));
|
|
|
+ invoiceCheckInfo.put("region", recognitionInfo.get("region"));
|
|
|
+ invoiceCheckInfo.put("rotationAngle", recognitionInfo.get("rotationAngle"));
|
|
|
+ invoiceCheckInfo.put("pixel", recognitionInfo.get("pixel"));
|
|
|
+ invoiceCheckInfo.put("pageNo", recognitionInfo.get("pageNo"));
|
|
|
+ invoiceCheckInfo.put("fileName", recognitionInfo.get("fileName"));
|
|
|
+ String checkStatus = invoiceCheckInfo.getString("checkStatus");
|
|
|
+ String recognitionSaleList = recognitionInfo.getString("isSaleListInvoice");
|
|
|
+ String checkSaleList = invoiceCheckInfo.getString("isSaleListInvoice");
|
|
|
+ if ("1".equals(recognitionSaleList) || "1".equals(checkSaleList)) {
|
|
|
+ invoiceCheckInfo.put("isSaleListInvoice", "1");
|
|
|
+ if (!"1".equals(checkSaleList)) {
|
|
|
+ putSaleListSum(invoiceCheckInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(checkStatus)) {
|
|
|
+ invoiceCheckInfo.put("checkStatus", "1");
|
|
|
+ checkStatus = "1";
|
|
|
+ }
|
|
|
+
|
|
|
+ Long invoiceType = recognitionInfo.getLong("invoiceType");
|
|
|
+ if ((InputInvoiceTypeEnum.ORDINARY_PAPER.getCode().equals(invoiceType) || InputInvoiceTypeEnum.SPECIAL_PAPER.getCode().equals(invoiceType)) && "1".equals(checkStatus) && "1".equals(invoiceCheckInfo.getString("proxyMark"))) {
|
|
|
+ invoiceCheckInfo.put("companySeal", "1");
|
|
|
+ }
|
|
|
+
|
|
|
+ return invoiceCheckInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void putSaleListSum(JSONObject invoiceInfo) {
|
|
|
+ int pageSum = 0;
|
|
|
+ String attachNo = invoiceInfo.getString("invoiceCode") + "_" + invoiceInfo.getString("invoiceNo");
|
|
|
+ QFilter qFilter = new QFilter("attach_no", "=", attachNo);
|
|
|
+ String attachFields = MetadataUtil.getFields("rim_attach");
|
|
|
+ DynamicObject[] attachCollect = BusinessDataServiceHelper.load("rim_attach", attachFields, new QFilter[]{qFilter});
|
|
|
+ if (attachCollect != null && attachCollect.length > 0) {
|
|
|
+ DynamicObject[] var6 = attachCollect;
|
|
|
+ int var7 = attachCollect.length;
|
|
|
+
|
|
|
+ for(int var8 = 0; var8 < var7; ++var8) {
|
|
|
+ DynamicObject attachInfo = var6[var8];
|
|
|
+ if (attachInfo.getInt("page_sum") != 0) {
|
|
|
+ pageSum = attachInfo.getInt("page_sum");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray items = invoiceInfo.getJSONArray("items");
|
|
|
+ if (pageSum == 0) {
|
|
|
+ double itemsNum = (double)items.size();
|
|
|
+ double sum = Math.ceil(itemsNum / 25.0);
|
|
|
+ invoiceInfo.put("salelistSum", (int)sum == 0 ? 1 : (int)sum);
|
|
|
+ } else {
|
|
|
+ invoiceInfo.put("salelistSum", pageSum);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setOtherInfoByType(Long invoiceType, JSONObject recognitionInfo) {
|
|
|
+ String continuousNo = recognitionInfo.getString("continuousNo");
|
|
|
+ String numberConfirm = recognitionInfo.getString("numberConfirm");
|
|
|
+ String codeConfirm = recognitionInfo.getString("codeConfirm");
|
|
|
+ boolean isEquals;
|
|
|
+ if (StringUtils.isEmpty(continuousNo) && StringUtils.isNotEmpty(numberConfirm) && StringUtils.isNotEmpty(codeConfirm)) {
|
|
|
+ String invoiceCode = recognitionInfo.getString("invoiceCode");
|
|
|
+ String invoiceNo = recognitionInfo.getString("invoiceNo");
|
|
|
+ boolean isCodeEquals = invoiceCode.equals(codeConfirm);
|
|
|
+ isEquals = invoiceNo.equals(numberConfirm);
|
|
|
+ recognitionInfo.put("continuousNo", "0");
|
|
|
+ if (!isCodeEquals || !isEquals) {
|
|
|
+ recognitionInfo.put("continuousNo", "1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (InputInvoiceTypeEnum.TAXI_INVOICE.getCode().equals(invoiceType)) {
|
|
|
+ BigDecimal surcharge = recognitionInfo.getBigDecimal("surcharge");
|
|
|
+ BigDecimal totalAmount = recognitionInfo.getBigDecimal("totalAmount") == null ? BigDecimal.ZERO : recognitionInfo.getBigDecimal("totalAmount");
|
|
|
+ BigDecimal fare = recognitionInfo.getBigDecimal("fare") == null ? BigDecimal.ZERO : recognitionInfo.getBigDecimal("fare");
|
|
|
+ isEquals = totalAmount.compareTo(fare) == 0;
|
|
|
+ if (isEquals && surcharge != null) {
|
|
|
+ recognitionInfo.put("totalAmount", totalAmount.add(surcharge));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void recognitionInvoiceMix(JSONObject recognitionInfo, Long invoiceType) {
|
|
|
+ String serialNo = recognitionInfo.getString("serialNo");
|
|
|
+ if (StringUtils.isNotEmpty(serialNo)) {
|
|
|
+ this.invoiceCollectService.convertUnVatInvoice(recognitionInfo, false);
|
|
|
+ } else {
|
|
|
+ this.convertFalseField(invoiceType, recognitionInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convertFalseField(Long invoiceType, JSONObject recognitionInfo) {
|
|
|
+ if (InputInvoiceTypeEnum.TRAIN_INVOICE.getCode().equals(invoiceType)) {
|
|
|
+ recognitionInfo.put("printingSequenceNo", recognitionInfo.getString("sequenceNo"));
|
|
|
+ recognitionInfo.put("seat", recognitionInfo.getString("seatGrade"));
|
|
|
+ recognitionInfo.put("customerIdentityNum", recognitionInfo.getString("customerIdNo"));
|
|
|
+ } else if (InputInvoiceTypeEnum.AIR_INVOICE.getCode().equals(invoiceType)) {
|
|
|
+ recognitionInfo.put("electronicTicketNum", recognitionInfo.getString("eticketNo"));
|
|
|
+ recognitionInfo.put("customerIdentityNum", recognitionInfo.getString("customerIdNo"));
|
|
|
+ recognitionInfo.put("otherTotalTaxAmount", recognitionInfo.getString("otherAmount"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONArray bindAttachInvoice(JSONArray targetArray, JSONObject businessParam) {
|
|
|
+ JSONArray attachArray = new JSONArray();
|
|
|
+ if (targetArray.size() == 0) {
|
|
|
+ return attachArray;
|
|
|
+ } else {
|
|
|
+ targetArray.stream().forEach((i) -> {
|
|
|
+ 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");
|
|
|
+ DynamicObject attachObject = this.getAttachDynamicObject(invoiceInfo, businessParam);
|
|
|
+ DynamicObject attachSaveObject = (DynamicObject)SaveServiceHelper.save(new DynamicObject[]{attachObject})[0];
|
|
|
+ JSONObject attachInfo = new JSONObject(DynamicObjectUtil.dynamicObject2Map(attachSaveObject));
|
|
|
+ attachInfo.put("invoiceCode", invoiceCode);
|
|
|
+ attachInfo.put("invoiceNo", invoiceNo);
|
|
|
+ DynamicObject attachTypeObj = BusinessDataServiceHelper.loadSingle(1503642129396971520L, "bdm_attach_type");
|
|
|
+ attachInfo.put("simplify_name", attachTypeObj.getString("simplify_name"));
|
|
|
+ attachInfo.put("attach_category_grid", attachTypeObj.getString("name"));
|
|
|
+ attachInfo.put("serialNo", MD5.md5Hex(attachObject.get("id").toString()));
|
|
|
+ attachInfo.put("pageNo", pageNo);
|
|
|
+ long attachId = (Long)attachSaveObject.getPkValue();
|
|
|
+ QFilter codeFilter = new QFilter("invoice_code", "=", invoiceCode);
|
|
|
+ QFilter noFilter = new QFilter("invoice_no", "=", invoiceNo);
|
|
|
+ Long[] vatTypes = InputInvoiceTypeEnum.getVatTypes();
|
|
|
+ QFilter typeFilter = new QFilter("invoice_type", "in", vatTypes);
|
|
|
+ String mainFields = MetadataUtil.getFields("rim_invoice");
|
|
|
+ DynamicObject invoiceObject = BusinessDataServiceHelper.loadSingle("rim_invoice", mainFields, new QFilter[]{codeFilter, noFilter, typeFilter});
|
|
|
+ if (invoiceObject != null) {
|
|
|
+ attachInfo.put("isVat", "1");
|
|
|
+ DynamicObject attachRelationObject = this.getAttachRelationDynamicObject(attachId, invoiceObject.getString("serial_no"));
|
|
|
+ if (attachRelationObject != null) {
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{attachRelationObject});
|
|
|
+ }
|
|
|
+
|
|
|
+ int page_sum = attachInfo.getInteger("page_sum");
|
|
|
+ if (page_sum != 0) {
|
|
|
+ invoiceObject.set("salelist_sum", page_sum);
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{invoiceObject});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ attachArray.add(attachInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ return attachArray;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private DynamicObject getAttachRelationDynamicObject(long attachId, String serialNo) {
|
|
|
+ DynamicObjectCollection collect = QueryServiceHelper.query("rim_attach_relation", "id", new QFilter[]{new QFilter("attach_id", "=", String.valueOf(attachId))});
|
|
|
+ if (collect.size() > 0) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ DynamicObject relationObject = BusinessDataServiceHelper.newDynamicObject("rim_attach_relation");
|
|
|
+ relationObject.set("attach_id", attachId);
|
|
|
+ relationObject.set("relation_type", 3);
|
|
|
+ relationObject.set("relation_id", serialNo);
|
|
|
+ DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("rim_attach_relation", "expense_id", new QFilter[]{new QFilter("relation_id", "=", serialNo)});
|
|
|
+ if (dynamicObject != null) {
|
|
|
+ relationObject.set("expense_id", dynamicObject.getString("expense_id"));
|
|
|
+ }
|
|
|
+
|
|
|
+ return relationObject;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private DynamicObject getAttachDynamicObject(JSONObject invoiceInfo, JSONObject businessParam) {
|
|
|
+ Long userId = Long.valueOf(RequestContext.get().getUserId());
|
|
|
+ StringBuilder attachNoSb = new StringBuilder();
|
|
|
+ attachNoSb.append(invoiceInfo.getString("invoiceCode")).append('_');
|
|
|
+ attachNoSb.append(invoiceInfo.getString("invoiceNo"));
|
|
|
+ String attachNo = attachNoSb.toString();
|
|
|
+ QFilter filter1 = new QFilter("attach_no", "=", attachNo);
|
|
|
+ QFilter filter2 = new QFilter("attach_category", "=", AttachConstant.ATTACH_LIST_CATEGORY_ID);
|
|
|
+ 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) {
|
|
|
+ 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());
|
|
|
+ attachObject.set("user", userId);
|
|
|
+ if (businessParam != null) {
|
|
|
+ attachObject.set("rim_user", businessParam.get("rim_user"));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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"));
|
|
|
+ } else {
|
|
|
+ attachObject.set("attach_url", invoiceInfo.getString("snapshotUrl"));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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");
|
|
|
+ if (StringUtils.isNotEmpty(pageNum)) {
|
|
|
+ try {
|
|
|
+ String target = pageNum.replaceAll(" ", "");
|
|
|
+ String subStr = target.substring(0, target.length() - 1);
|
|
|
+ int index = subStr.indexOf(20849);
|
|
|
+ int index2 = subStr.indexOf(39029);
|
|
|
+ int index3 = subStr.indexOf(31532);
|
|
|
+ String pageSum = target.substring(index, index2).substring(1);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return attachObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }).collect(Collectors.toCollection(JSONArray::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void dealInvoiceAttachRelation(JSONObject invoiceInfo) {
|
|
|
+ if (invoiceInfo != null) {
|
|
|
+ logger.info("处理发票绑定附件关系....");
|
|
|
+ String invoiceCode = invoiceInfo.getString("invoiceCode");
|
|
|
+ String invoiceNo = invoiceInfo.getString("invoiceNo");
|
|
|
+ invoiceCode = StringUtils.isNotEmpty(invoiceCode) ? invoiceCode : invoiceInfo.getString("invoice_code");
|
|
|
+ invoiceNo = StringUtils.isNotEmpty(invoiceNo) ? invoiceNo : invoiceInfo.getString("invoice_no");
|
|
|
+ StringBuilder attachNo = new StringBuilder();
|
|
|
+ attachNo.append(invoiceCode).append('_').append(invoiceNo);
|
|
|
+ DynamicObjectCollection attachCollect = this.getAttachDynamicByAttachNo(attachNo.toString());
|
|
|
+ Iterator var6 = attachCollect.iterator();
|
|
|
+
|
|
|
+ while(var6.hasNext()) {
|
|
|
+ DynamicObject attachInfo = (DynamicObject)var6.next();
|
|
|
+ String targetCode = attachInfo.getString("attach_no");
|
|
|
+ if (StringUtils.isNotEmpty(targetCode)) {
|
|
|
+ String[] codeNo = targetCode.split("_");
|
|
|
+ if (codeNo.length == 2 && invoiceCode.equals(codeNo[0]) && invoiceNo.equals(codeNo[1])) {
|
|
|
+ DynamicObject attachRelationObject = this.getAttachRelationDynamicObject(attachInfo.getLong("id"), invoiceInfo.getString("serialNo"));
|
|
|
+ if (attachRelationObject != null) {
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{attachRelationObject});
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("发票绑定附件关系保存成功....");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject numObject = this.calcSaleListComplete(invoiceCode, invoiceNo, attachNo.toString());
|
|
|
+ invoiceInfo.put("salelistSum", numObject.getString("salelistSum"));
|
|
|
+ invoiceInfo.put("bindNum", numObject.getString("bindNum"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject calcSaleListComplete(String invoiceCode, String invoiceNo, String attachNo) {
|
|
|
+ logger.info("计算清单完整性,{},{}", invoiceCode, invoiceNo);
|
|
|
+ JSONObject numObject = new JSONObject();
|
|
|
+ int saleListSum = 0;
|
|
|
+ QFilter attachNoFilter = new QFilter("attach_no", "=", attachNo);
|
|
|
+ String attachFields = MetadataUtil.getFields("rim_attach");
|
|
|
+ DynamicObject[] attachCollect = BusinessDataServiceHelper.load("rim_attach", attachFields, new QFilter[]{attachNoFilter});
|
|
|
+ int bindNum = 0;
|
|
|
+ DynamicObject attachObject;
|
|
|
+ if (attachCollect != null && attachCollect.length > 0) {
|
|
|
+ String url = RimConfigUtils.getConfig("rim_recog_check", "salelistposturl");
|
|
|
+ if (StringUtils.isNotEmpty(url)) {
|
|
|
+ Set<Integer> numSet = (Set)Arrays.stream(attachCollect).filter((f) -> {
|
|
|
+ if (f.getInt("page_no") == 0) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ Long attachId = f.getLong("id");
|
|
|
+ boolean isBind = this.checkBind(attachId);
|
|
|
+ return isBind;
|
|
|
+ }
|
|
|
+ }).map((m) -> {
|
|
|
+ return m.getInt("page_no");
|
|
|
+ }).collect(Collectors.toSet());
|
|
|
+ bindNum = numSet.size();
|
|
|
+ } else {
|
|
|
+ DynamicObject[] var18 = attachCollect;
|
|
|
+ int var12 = attachCollect.length;
|
|
|
+
|
|
|
+ for(int var13 = 0; var13 < var12; ++var13) {
|
|
|
+ attachObject = var18[var13];
|
|
|
+ Long attachId = attachObject.getLong("id");
|
|
|
+ boolean isBind = this.checkBind(attachId);
|
|
|
+ if (isBind) {
|
|
|
+ ++bindNum;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ QFilter invoiceNoFilter = new QFilter("invoice_no", "=", invoiceNo);
|
|
|
+ QFilter invoiceCodeFilter = new QFilter("invoice_code", "=", invoiceCode);
|
|
|
+ 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");
|
|
|
+ if (pageSum != 0 && pageSum != saleListSum) {
|
|
|
+ mainObject.set("salelist_sum", pageSum);
|
|
|
+ saleListSum = pageSum;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bindNum == 0) {
|
|
|
+ mainObject.set("salelist_complete", "3");
|
|
|
+ } else if (bindNum < saleListSum) {
|
|
|
+ mainObject.set("salelist_complete", "2");
|
|
|
+ } else {
|
|
|
+ mainObject.set("salelist_complete", "0");
|
|
|
+ }
|
|
|
+
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{mainObject});
|
|
|
+ logger.info("计算清单完整性完毕,{},{}", invoiceCode, invoiceNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ numObject.put("salelistSum", saleListSum);
|
|
|
+ numObject.put("bindNum", bindNum);
|
|
|
+ return numObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ private DynamicObjectCollection getAttachDynamicByAttachNo(String attachNo) {
|
|
|
+ DynamicObjectCollection result = new DynamicObjectCollection();
|
|
|
+ QFilter attachNoFilter = new QFilter("attach_no", "=", attachNo);
|
|
|
+ String attachFields = MetadataUtil.getFields("rim_attach");
|
|
|
+ DynamicObject[] attachCollect = BusinessDataServiceHelper.load("rim_attach", attachFields, new QFilter[]{attachNoFilter});
|
|
|
+ if (attachCollect != null && attachCollect.length > 0) {
|
|
|
+ DynamicObject[] var6 = attachCollect;
|
|
|
+ int var7 = attachCollect.length;
|
|
|
+
|
|
|
+ for(int var8 = 0; var8 < var7; ++var8) {
|
|
|
+ DynamicObject attachObject = var6[var8];
|
|
|
+ Long attachId = attachObject.getLong("id");
|
|
|
+ boolean isBind = this.checkBind(attachId);
|
|
|
+ if (!isBind) {
|
|
|
+ result.add(attachObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean checkBind(Long attachId) {
|
|
|
+ QFilter attachIdFilter = new QFilter("attach_id", "=", attachId.toString());
|
|
|
+ QFilter relationIdFilter = new QFilter("relation_id", "!=", " ");
|
|
|
+ String attachFields = MetadataUtil.getFields("rim_attach_relation");
|
|
|
+ DynamicObject[] attachCollect = BusinessDataServiceHelper.load("rim_attach_relation", attachFields, new QFilter[]{attachIdFilter, relationIdFilter});
|
|
|
+ return attachCollect != null && attachCollect.length > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Integer> filterBindAttach(List<String> attachIds) {
|
|
|
+ QFilter attachIdFilter = new QFilter("attach_id", "in", attachIds);
|
|
|
+ QFilter relationIdFilter = new QFilter("relation_id", "!=", " ");
|
|
|
+ String attachFields = MetadataUtil.getFields("rim_attach_relation");
|
|
|
+ DynamicObject[] attachCollect = BusinessDataServiceHelper.load("rim_attach_relation", attachFields, new QFilter[]{attachIdFilter, relationIdFilter});
|
|
|
+ if (attachCollect.length == 0) {
|
|
|
+ return Maps.newHashMap();
|
|
|
+ } else {
|
|
|
+ Map<String, List<DynamicObject>> relationGroup = (Map)Arrays.stream(attachCollect).collect(Collectors.groupingBy((attach) -> {
|
|
|
+ return attach.getString("relation_id");
|
|
|
+ }));
|
|
|
+ Map<String, Integer> map = Maps.newHashMapWithExpectedSize(relationGroup.size());
|
|
|
+ List<String> serialList = Lists.newArrayList();
|
|
|
+ Iterator var9 = relationGroup.entrySet().iterator();
|
|
|
+
|
|
|
+ while(var9.hasNext()) {
|
|
|
+ Map.Entry<String, List<DynamicObject>> entry = (Map.Entry)var9.next();
|
|
|
+ map.put(entry.getKey(), ((List)entry.getValue()).size());
|
|
|
+ serialList.add(entry.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ QFilter serialFilter = new QFilter("serial_no", "in", serialList);
|
|
|
+ DynamicObject[] invoiceCollect = BusinessDataServiceHelper.load("rim_invoice", "serial_no, invoice_code, invoice_no", new QFilter[]{serialFilter});
|
|
|
+ Map<String, String> invoiceMap = Maps.newHashMapWithExpectedSize(invoiceCollect.length);
|
|
|
+ DynamicObject[] var12 = invoiceCollect;
|
|
|
+ int var13 = invoiceCollect.length;
|
|
|
+
|
|
|
+ for(int var14 = 0; var14 < var13; ++var14) {
|
|
|
+ DynamicObject invoice = var12[var14];
|
|
|
+ invoiceMap.put(invoice.getString("serial_no"), invoice.getString("invoice_code") + "_" + invoice.getString("invoice_no"));
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Integer> result = Maps.newHashMapWithExpectedSize(map.size());
|
|
|
+ Iterator var19 = map.entrySet().iterator();
|
|
|
+
|
|
|
+ while(var19.hasNext()) {
|
|
|
+ Map.Entry<String, Integer> entry = (Map.Entry)var19.next();
|
|
|
+ result.put(invoiceMap.get(entry.getKey()), entry.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|