|  | @@ -0,0 +1,668 @@
 | 
	
		
			
				|  |  | +package kd.imc.rim.common.service;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | +import com.google.common.collect.Maps;
 | 
	
		
			
				|  |  | +import kd.bos.context.RequestContext;
 | 
	
		
			
				|  |  | +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.threads.ThreadPool;
 | 
	
		
			
				|  |  | +import kd.bos.threads.ThreadPools;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.constant.CheckContant;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.constant.InputInvoiceTypeEnum;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.constant.InvoiceUploadErrorType;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.helper.RecognitionCheckHelper;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.invoice.collector.InvoiceCollectService;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.invoice.model.ConvertFieldUtil;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.invoice.recognition.listener.IRecognitionListener;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.invoice.recognition.listener.RecognitionListenerResult;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.invoice.recognitionnew.task.FileUploadAndSignTask;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.invoice.save.InvoiceSaveService;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.message.exception.MsgException;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.utils.*;
 | 
	
		
			
				|  |  | +import kd.imc.rim.common.utils.itextpdf.UrlServiceUtils;
 | 
	
		
			
				|  |  | +import kd.imc.rim.file.model.FileConvertResult;
 | 
	
		
			
				|  |  | +import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  | +import org.apache.commons.compress.utils.Lists;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.io.IOException;
 | 
	
		
			
				|  |  | +import java.io.InputStream;
 | 
	
		
			
				|  |  | +import java.text.DecimalFormat;
 | 
	
		
			
				|  |  | +import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  | +import java.util.concurrent.ExecutionException;
 | 
	
		
			
				|  |  | +import java.util.concurrent.Future;
 | 
	
		
			
				|  |  | +import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  | +import java.util.concurrent.TimeoutException;
 | 
	
		
			
				|  |  | +import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +public class RecognitionCheckServiceEx {
 | 
	
		
			
				|  |  | +    private static RecognitionCheckServiceEx instance = null;
 | 
	
		
			
				|  |  | +    private static Log logger = LogFactory.getLog(RecognitionCheckServiceEx.class);
 | 
	
		
			
				|  |  | +    private RecognitionCheckHelper recognitionCheckHelper = new RecognitionCheckHelper();
 | 
	
		
			
				|  |  | +    private InvoiceCollectService invoiceCollectService = new InvoiceCollectService();
 | 
	
		
			
				|  |  | +    private static Integer recheckorginPage = 999123413;
 | 
	
		
			
				|  |  | +    private static ThreadPool uploadThreadPool = ThreadPools.newFixedThreadPool("recognitionUploadThread_2", Runtime.getRuntime().availableProcessors() + 1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private RecognitionCheckServiceEx() {
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static RecognitionCheckServiceEx getInstance() {
 | 
	
		
			
				|  |  | +        Class var0 = RecognitionCheckServiceEx.class;
 | 
	
		
			
				|  |  | +        synchronized(RecognitionCheckServiceEx.class) {
 | 
	
		
			
				|  |  | +            if (instance == null) {
 | 
	
		
			
				|  |  | +                instance = new RecognitionCheckServiceEx();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return instance;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public JSONObject recognitionCheckInvoice(String fileUrl, String fileName, IRecognitionListener recognitionListener, JSONObject businessParam) {
 | 
	
		
			
				|  |  | +        logger.info("识别查验fileName:{},businessParam:{}", fileName, businessParam);
 | 
	
		
			
				|  |  | +        this.markDeleteByVerifySave(businessParam);
 | 
	
		
			
				|  |  | +        boolean isCheck = this.getCheckFlag(businessParam);
 | 
	
		
			
				|  |  | +        return this.extracted_new(fileUrl, fileName, recognitionListener, businessParam, isCheck);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void markDeleteByVerifySave(JSONObject businessParam) {
 | 
	
		
			
				|  |  | +        if (businessParam != null) {
 | 
	
		
			
				|  |  | +            String verifySaveFlag = RimConfigUtils.getConfig("verify_save");
 | 
	
		
			
				|  |  | +            if ("0".equals(verifySaveFlag)) {
 | 
	
		
			
				|  |  | +                businessParam.put("delete", "2");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private JSONObject extracted_new(String fileUrl, String fileName, IRecognitionListener recognitionListener, JSONObject businessParam, boolean isCheck) {
 | 
	
		
			
				|  |  | +        long startTime = System.currentTimeMillis();
 | 
	
		
			
				|  |  | +        JSONObject result = null;
 | 
	
		
			
				|  |  | +        RecognitionListenerResult listener = new RecognitionListenerResult(fileUrl, fileName, 0, 0, new JSONArray());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        JSONArray finalResult;
 | 
	
		
			
				|  |  | +        JSONArray attachResult;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            long fileStartTime = System.currentTimeMillis();
 | 
	
		
			
				|  |  | +            FormFileEntity fileEntity = this.recognitionCheckHelper.getFormFileEntity(fileUrl, fileName);
 | 
	
		
			
				|  |  | +            if (!fileEntity.getSuccess()) {
 | 
	
		
			
				|  |  | +                this.handle(recognitionListener, listener);
 | 
	
		
			
				|  |  | +                return InvoiceUploadErrorType.getSplitErrorResult();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            int totalPage = CollectionUtils.isEmpty(fileEntity.getSubFileList()) ? 1 : fileEntity.getSubFileList().size();
 | 
	
		
			
				|  |  | +            Map<String, Object> extMap = this.recognitionCheckHelper.getRecognitionCheckExtMap(businessParam);
 | 
	
		
			
				|  |  | +            String originalStateDefault = fileEntity.getOriginalStateDefault();
 | 
	
		
			
				|  |  | +            if ("1".equals(originalStateDefault)) {
 | 
	
		
			
				|  |  | +                extMap.put("originalStateDefault", originalStateDefault);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            String fileType = fileEntity.getFileType();
 | 
	
		
			
				|  |  | +            Map<Integer, Object> subFileFutureMap = this.syncUploadSubFile(fileEntity);
 | 
	
		
			
				|  |  | +            logger.info("RecognitionCheckServiceEx 文件解析耗时:{}", System.currentTimeMillis() - fileStartTime);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List recognitionResultList;
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                long recognitionStartTime = System.currentTimeMillis();
 | 
	
		
			
				|  |  | +                recognitionResultList = this.recognitionCheckHelper.recognitionInvoiceFile(fileEntity, extMap);
 | 
	
		
			
				|  |  | +                logger.info("RecognitionCheckServiceEx 识别总耗时:{}", System.currentTimeMillis() - recognitionStartTime);
 | 
	
		
			
				|  |  | +                this.checkOriginal(fileEntity, subFileFutureMap, recognitionResultList);
 | 
	
		
			
				|  |  | +                finalResult = JSONObject.parseArray(JSONObject.toJSONString(recognitionResultList));
 | 
	
		
			
				|  |  | +            } catch (Throwable var26) {
 | 
	
		
			
				|  |  | +                this.handle(recognitionListener, listener);
 | 
	
		
			
				|  |  | +                if (var26 instanceof MsgException) {
 | 
	
		
			
				|  |  | +                    return JSON.parseObject(var26.toString());
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                logger.info("识别程序错误:", var26);
 | 
	
		
			
				|  |  | +                return InvoiceUploadErrorType.getRecognitionErrorResult();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //改了的地方
 | 
	
		
			
				|  |  | +            isCheck=false;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (isCheck && recognitionResultList.size() > 0) {
 | 
	
		
			
				|  |  | +                try {
 | 
	
		
			
				|  |  | +                    long checkStartTime = System.currentTimeMillis();
 | 
	
		
			
				|  |  | +                    List<JSONObject> checkResultList = this.recognitionCheckHelper.checkInvoiceByRecognitionInfo(recognitionResultList, extMap);
 | 
	
		
			
				|  |  | +                    logger.info("RecognitionCheckServiceEx 查验总耗时:{}", System.currentTimeMillis() - checkStartTime);
 | 
	
		
			
				|  |  | +                    finalResult = JSONObject.parseArray(JSONObject.toJSONString(checkResultList));
 | 
	
		
			
				|  |  | +                } catch (Throwable var25) {
 | 
	
		
			
				|  |  | +                    this.handle(recognitionListener, listener);
 | 
	
		
			
				|  |  | +                    logger.info("查验程序错误:", var25);
 | 
	
		
			
				|  |  | +                    return InvoiceUploadErrorType.getCheckErrorResult();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            Map<String, Object> fileBaseInfo = Maps.newHashMap();
 | 
	
		
			
				|  |  | +            fileBaseInfo.put("fileType", fileType);
 | 
	
		
			
				|  |  | +            fileBaseInfo.put("fileUrl", fileUrl);
 | 
	
		
			
				|  |  | +            fileBaseInfo.put("fileName", fileName);
 | 
	
		
			
				|  |  | +            fileBaseInfo.put("size", fileEntity.getFileSize());
 | 
	
		
			
				|  |  | +            finalResult = this.putFileInfo(fileBaseInfo, finalResult, subFileFutureMap, originalStateDefault);
 | 
	
		
			
				|  |  | +            attachResult = this.dealSaleList(finalResult, businessParam);
 | 
	
		
			
				|  |  | +            boolean isHandleAttach = attachResult.size() > 0 && finalResult.size() == 0;
 | 
	
		
			
				|  |  | +            logger.info("isHandleAttach:{}", isHandleAttach);
 | 
	
		
			
				|  |  | +            if (isHandleAttach) {
 | 
	
		
			
				|  |  | +                this.handleAttach(attachResult, recognitionListener, fileUrl, fileName, totalPage);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                if (fileBaseInfo.get("totalPage") == null) {
 | 
	
		
			
				|  |  | +                    fileBaseInfo.put("totalPage", totalPage);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                this.saveInvoice(finalResult, attachResult, isHandleAttach, fileBaseInfo, businessParam, recognitionListener);
 | 
	
		
			
				|  |  | +                FileUploadUtils.saveBasAttachment(fileUrl, fileName, "rim_invoice", "", fileEntity.getFileSize());
 | 
	
		
			
				|  |  | +            } catch (Throwable var24) {
 | 
	
		
			
				|  |  | +                this.handle(recognitionListener, listener);
 | 
	
		
			
				|  |  | +                logger.info("发票保存错误:", var24);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } catch (IOException var27) {
 | 
	
		
			
				|  |  | +            logger.info("RecognitionCheckServiceEx IOException :{}", var27);
 | 
	
		
			
				|  |  | +            this.handle(recognitionListener, listener);
 | 
	
		
			
				|  |  | +            return InvoiceUploadErrorType.getSplitErrorResult();
 | 
	
		
			
				|  |  | +        } catch (MsgException var28) {
 | 
	
		
			
				|  |  | +            logger.info("RecognitionCheckServiceEx MsgException :{}", var28);
 | 
	
		
			
				|  |  | +            this.handle(recognitionListener, listener);
 | 
	
		
			
				|  |  | +            JSONObject errorInfo = new JSONObject();
 | 
	
		
			
				|  |  | +            errorInfo.put("errcode", var28.getErrorCode());
 | 
	
		
			
				|  |  | +            errorInfo.put("description", var28.getMessage());
 | 
	
		
			
				|  |  | +            return errorInfo;
 | 
	
		
			
				|  |  | +        } catch (Throwable var29) {
 | 
	
		
			
				|  |  | +            logger.info("RecognitionCheckServiceEx BaseErrorResult Throwable:{}", var29);
 | 
	
		
			
				|  |  | +            this.handle(recognitionListener, listener);
 | 
	
		
			
				|  |  | +            return InvoiceUploadErrorType.getBaseErrorResult();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        boolean resultFlag = finalResult.size() != 0 || attachResult.size() != 0;
 | 
	
		
			
				|  |  | +        logger.info("RecognitionCheckServiceEx 识别查验入库总耗时:{}", System.currentTimeMillis() - startTime);
 | 
	
		
			
				|  |  | +        if (resultFlag) {
 | 
	
		
			
				|  |  | +            return InvoiceUploadErrorType.getSuccessResult(finalResult, attachResult);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            this.handle(recognitionListener, listener);
 | 
	
		
			
				|  |  | +            return InvoiceUploadErrorType.getFailResult();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void checkOriginal(FormFileEntity fileEntity, Map<Integer, Object> subFileFutureMap, List<JSONObject> recognitionResultList) {
 | 
	
		
			
				|  |  | +        if (!StringUtils.isBlank(fileEntity.getSecondPageText()) && !CollectionUtils.isEmpty(recognitionResultList)) {
 | 
	
		
			
				|  |  | +            JSONObject firstInvoice = (JSONObject)recognitionResultList.get(0);
 | 
	
		
			
				|  |  | +            Long invoiceType = firstInvoice.getLong("invoiceType");
 | 
	
		
			
				|  |  | +            String invoiceNo = firstInvoice.getString("invoiceNo");
 | 
	
		
			
				|  |  | +            String invoiceCode = firstInvoice.getString("invoiceCode");
 | 
	
		
			
				|  |  | +            int i;
 | 
	
		
			
				|  |  | +            if (InputInvoiceTypeEnum.isCheckOriginalFile(invoiceType) && StringUtils.isNotEmpty(invoiceCode) && StringUtils.isNotEmpty(invoiceNo)) {
 | 
	
		
			
				|  |  | +                i = fileEntity.getSecondPageText().indexOf(invoiceCode);
 | 
	
		
			
				|  |  | +                int noidx = fileEntity.getSecondPageText().indexOf(invoiceNo);
 | 
	
		
			
				|  |  | +                if (i < 0 || noidx < 0) {
 | 
	
		
			
				|  |  | +                    return;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            for(i = 1; i < recognitionResultList.size(); ++i) {
 | 
	
		
			
				|  |  | +                JSONObject invoice = (JSONObject)recognitionResultList.get(i);
 | 
	
		
			
				|  |  | +                Long invoiceType1 = invoice.getLong("invoiceType");
 | 
	
		
			
				|  |  | +                if (InputInvoiceTypeEnum.OTHER_INVOICE.getCode().equals(invoiceType1)) {
 | 
	
		
			
				|  |  | +                    String title = invoice.getString("title");
 | 
	
		
			
				|  |  | +                    boolean saleTitle = !StringUtils.isEmpty(title) && title.indexOf("清单") > 0;
 | 
	
		
			
				|  |  | +                    if (!saleTitle) {
 | 
	
		
			
				|  |  | +                        return;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            FileUploadAndSignTask task = new FileUploadAndSignTask(fileEntity.getFileUrl(), (byte[])null, "pdf", true, RequestContext.get());
 | 
	
		
			
				|  |  | +            task.setSignOnly(true);
 | 
	
		
			
				|  |  | +            Future<JSONObject> subUploadFuture = uploadThreadPool.submit(task);
 | 
	
		
			
				|  |  | +            subFileFutureMap.put(recheckorginPage, subUploadFuture);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void handleAttach(JSONArray attachResult, IRecognitionListener recognitionListener, String fileUrl, String fileName, int totalPage) {
 | 
	
		
			
				|  |  | +        if (attachResult != null && attachResult.size() != 0) {
 | 
	
		
			
				|  |  | +            if (recognitionListener != null) {
 | 
	
		
			
				|  |  | +                Map<Integer, List<Object>> handleMap = (Map)attachResult.stream().collect(Collectors.groupingBy((v) -> {
 | 
	
		
			
				|  |  | +                    return ((JSONObject)v).getInteger("pageNo");
 | 
	
		
			
				|  |  | +                }));
 | 
	
		
			
				|  |  | +                logger.info("handleAttach handleMap:{}", handleMap);
 | 
	
		
			
				|  |  | +                Iterator var7 = handleMap.entrySet().iterator();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                while(var7.hasNext()) {
 | 
	
		
			
				|  |  | +                    Map.Entry<Integer, List<Object>> entry = (Map.Entry)var7.next();
 | 
	
		
			
				|  |  | +                    int pageNo = (Integer)entry.getKey();
 | 
	
		
			
				|  |  | +                    logger.info("附件通知前端pageNo:{}", pageNo);
 | 
	
		
			
				|  |  | +                    JSONArray invoiceArray = JSONArray.parseArray(JSON.toJSONString(entry.getValue()));
 | 
	
		
			
				|  |  | +                    RecognitionListenerResult listener = new RecognitionListenerResult(fileUrl, fileName, pageNo, totalPage, invoiceArray);
 | 
	
		
			
				|  |  | +                    recognitionListener.handle(listener);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private JSONArray dealSaleList(JSONArray finalResult, JSONObject businessParam) {
 | 
	
		
			
				|  |  | +        if (finalResult.size() == 0) {
 | 
	
		
			
				|  |  | +            return new JSONArray();
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            JSONArray targetArray = this.recognitionCheckHelper.getTargetArray(finalResult);
 | 
	
		
			
				|  |  | +            finalResult.removeAll(targetArray);
 | 
	
		
			
				|  |  | +            Map<String, String> configMap = ImcConfigUtil.getValue("rim_recog_check");
 | 
	
		
			
				|  |  | +            String isDealSaleList = (String)configMap.get("is_dealsalelist");
 | 
	
		
			
				|  |  | +            if ("0".equals(isDealSaleList)) {
 | 
	
		
			
				|  |  | +                return new JSONArray();
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                JSONArray attachArray = this.recognitionCheckHelper.bindAttachInvoice(targetArray, businessParam);
 | 
	
		
			
				|  |  | +                List<String> finishList = Lists.newArrayList();
 | 
	
		
			
				|  |  | +                if (attachArray.size() > 0) {
 | 
	
		
			
				|  |  | +                    for(int i = 0; i < attachArray.size(); ++i) {
 | 
	
		
			
				|  |  | +                        JSONObject attachInfo = attachArray.getJSONObject(i);
 | 
	
		
			
				|  |  | +                        String invoiceCode = attachInfo.getString("invoiceCode");
 | 
	
		
			
				|  |  | +                        String invoiceNo = attachInfo.getString("invoiceNo");
 | 
	
		
			
				|  |  | +                        String isVat = attachInfo.getString("isVat");
 | 
	
		
			
				|  |  | +                        if ("1".equals(isVat)) {
 | 
	
		
			
				|  |  | +                            StringBuilder attachNo = new StringBuilder();
 | 
	
		
			
				|  |  | +                            attachNo.append(invoiceCode).append('_').append(invoiceNo);
 | 
	
		
			
				|  |  | +                            if (!finishList.contains(attachNo.toString())) {
 | 
	
		
			
				|  |  | +                                JSONObject numObject = this.recognitionCheckHelper.calcSaleListComplete(invoiceCode, invoiceNo, attachNo.toString());
 | 
	
		
			
				|  |  | +                                int salelistSum = numObject.getInteger("salelistSum");
 | 
	
		
			
				|  |  | +                                if (salelistSum == 0) {
 | 
	
		
			
				|  |  | +                                    salelistSum = attachInfo.getInteger("page_sum");
 | 
	
		
			
				|  |  | +                                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                                attachInfo.put("salelistSum", salelistSum);
 | 
	
		
			
				|  |  | +                                attachInfo.put("bindNum", numObject.getInteger("bindNum"));
 | 
	
		
			
				|  |  | +                                finishList.add(attachNo.toString());
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                return attachArray;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public void handle(IRecognitionListener recognitionListener, RecognitionListenerResult listener) {
 | 
	
		
			
				|  |  | +        if (recognitionListener != null) {
 | 
	
		
			
				|  |  | +            recognitionListener.handle(listener);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static void setInvoiceSeq(JSONObject invoiceInfo, JSONObject businessParam, int pageNo, int invoiceIndex) {
 | 
	
		
			
				|  |  | +        if (invoiceInfo != null) {
 | 
	
		
			
				|  |  | +            String uploadIndex;
 | 
	
		
			
				|  |  | +            if (businessParam == null) {
 | 
	
		
			
				|  |  | +                uploadIndex = String.valueOf(System.currentTimeMillis());
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                uploadIndex = businessParam.getString("uploadIndex");
 | 
	
		
			
				|  |  | +                if (StringUtils.isEmpty(uploadIndex)) {
 | 
	
		
			
				|  |  | +                    uploadIndex = String.valueOf(System.currentTimeMillis());
 | 
	
		
			
				|  |  | +                    businessParam.put("uploadIndex", uploadIndex);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            invoiceInfo.put("uploadSeq", getInvoiceSeq(uploadIndex, pageNo, invoiceIndex));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static Long getInvoiceSeq(String uploadIndex, int pageNo, int invoiceIndex) {
 | 
	
		
			
				|  |  | +        DecimalFormat decimalFormat = new DecimalFormat("000");
 | 
	
		
			
				|  |  | +        return Long.valueOf(uploadIndex + decimalFormat.format((long)pageNo) + decimalFormat.format((long)invoiceIndex));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private JSONArray putFileInfo(Map<String, Object> fileBaseInfo, JSONArray finalResult, Map<Integer, Object> subFileFutureMap, String originalStateDefault) throws ExecutionException, InterruptedException {
 | 
	
		
			
				|  |  | +        String updateFileType = String.valueOf(fileBaseInfo.get("fileType"));
 | 
	
		
			
				|  |  | +        String updateFileUrl = String.valueOf(fileBaseInfo.get("fileUrl"));
 | 
	
		
			
				|  |  | +        int size = finalResult.size();
 | 
	
		
			
				|  |  | +        boolean pdfSplit = false;
 | 
	
		
			
				|  |  | +        if (size > 1 && "pdf".equals(updateFileType)) {
 | 
	
		
			
				|  |  | +            pdfSplit = true;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Object refeature = subFileFutureMap.get(recheckorginPage);
 | 
	
		
			
				|  |  | +        boolean returnFirst = false;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        for(int i = 0; i < finalResult.size(); ++i) {
 | 
	
		
			
				|  |  | +            JSONObject invoiceInfo = (JSONObject)finalResult.get(i);
 | 
	
		
			
				|  |  | +            invoiceInfo.put("fileName", fileBaseInfo.get("fileName"));
 | 
	
		
			
				|  |  | +            int pageNo = (Integer)invoiceInfo.get("pageNo");
 | 
	
		
			
				|  |  | +            Object feature = subFileFutureMap.get(pageNo);
 | 
	
		
			
				|  |  | +            if (feature != null) {
 | 
	
		
			
				|  |  | +                long start = System.currentTimeMillis();
 | 
	
		
			
				|  |  | +                JSONObject fileReuslt = this.getUploadResult(feature);
 | 
	
		
			
				|  |  | +                if (refeature != null && i == 0) {
 | 
	
		
			
				|  |  | +                    JSONObject fileReuslt2 = this.getUploadResult(refeature);
 | 
	
		
			
				|  |  | +                    if (fileReuslt2 != null) {
 | 
	
		
			
				|  |  | +                        returnFirst = "true".equals(fileReuslt2.getString("isOriginal"));
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                String path;
 | 
	
		
			
				|  |  | +                if (fileReuslt != null) {
 | 
	
		
			
				|  |  | +                    path = fileReuslt.getString("isOriginal");
 | 
	
		
			
				|  |  | +                    if (!"1".equals(invoiceInfo.getString("originalState"))) {
 | 
	
		
			
				|  |  | +                        if ("true".equals(path)) {
 | 
	
		
			
				|  |  | +                            invoiceInfo.put("originalState", "1");
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            invoiceInfo.put("originalState", "0");
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("snapshotUrl", fileReuslt.getString("snapshotUrl"));
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("imageUrl", fileReuslt.getString("imageUrl"));
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("ofdUrl", fileReuslt.getString("ofdUrl"));
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("pdfUrl", fileReuslt.getString("pdfUrl"));
 | 
	
		
			
				|  |  | +                    if (pdfSplit) {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("pdfUrl", updateFileUrl);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("localUrl", "");
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("kdcloudUrl", "");
 | 
	
		
			
				|  |  | +                    if ("pdf".equals(FileUtils.getFileType((String)fileBaseInfo.get("fileName")))) {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("fileType", "1");
 | 
	
		
			
				|  |  | +                    } else if ("ofd".equals(FileUtils.getFileType((String)fileBaseInfo.get("fileName")))) {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("fileType", "4");
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("fileType", "2");
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("synConvert", fileReuslt.getString("synConvert"));
 | 
	
		
			
				|  |  | +                } else if (!StringUtils.isEmpty(updateFileUrl)) {
 | 
	
		
			
				|  |  | +                    path = FileUploadUtils.getSnapshotPathByUploadUrl(updateFileUrl);
 | 
	
		
			
				|  |  | +                    String imageUrl = path + ".jpg";
 | 
	
		
			
				|  |  | +                    if ("pdf".equals(updateFileType)) {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("pdfUrl", updateFileUrl);
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("snapshotUrl", imageUrl);
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("imageUrl", imageUrl);
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("synConvert", true);
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("fileType", "1");
 | 
	
		
			
				|  |  | +                        FileUploadAndSignTask.saveFileAws(new FileConvertResult(), updateFileUrl, "1");
 | 
	
		
			
				|  |  | +                    } else if ("ofd".equals(updateFileType)) {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("ofdUrl", updateFileUrl);
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("pdfUrl", path + ".pdf");
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("snapshotUrl", imageUrl);
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("imageUrl", imageUrl);
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("synConvert", true);
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("fileType", "4");
 | 
	
		
			
				|  |  | +                        FileUploadAndSignTask.saveFileAws(new FileConvertResult(), updateFileUrl, "4");
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("snapshotUrl", updateFileUrl);
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("imageUrl", updateFileUrl);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                logger.info("获取文件处理结果等待时长{},{}", System.currentTimeMillis() - start, fileReuslt);
 | 
	
		
			
				|  |  | +                if (returnFirst) {
 | 
	
		
			
				|  |  | +                    JSONArray finalResult2 = new JSONArray();
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("originalState", "1");
 | 
	
		
			
				|  |  | +                    finalResult2.add(invoiceInfo);
 | 
	
		
			
				|  |  | +                    fileBaseInfo.put("totalPage", 1);
 | 
	
		
			
				|  |  | +                    return finalResult2;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                logger.info("获取文件处理结果第{}页结果为空", pageNo);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return finalResult;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private JSONObject getUploadResult(Object feature) {
 | 
	
		
			
				|  |  | +        long timeOut = 10L;
 | 
	
		
			
				|  |  | +        if (feature instanceof Future) {
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                return (JSONObject)((Future)feature).get(timeOut, TimeUnit.SECONDS);
 | 
	
		
			
				|  |  | +            } catch (InterruptedException var5) {
 | 
	
		
			
				|  |  | +                logger.info("获取文件处理结果等待超时-{} InterruptedException", timeOut);
 | 
	
		
			
				|  |  | +            } catch (ExecutionException var6) {
 | 
	
		
			
				|  |  | +                logger.info("获取文件处理结果等待超时-{} ExecutionException", timeOut);
 | 
	
		
			
				|  |  | +            } catch (TimeoutException var7) {
 | 
	
		
			
				|  |  | +                logger.info("获取文件处理结果等待超时-{} TimeoutException", timeOut);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } else if (feature instanceof JSONObject) {
 | 
	
		
			
				|  |  | +            return (JSONObject)feature;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return null;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private Map<Integer, Object> syncUploadSubFile(FormFileEntity fileFile) {
 | 
	
		
			
				|  |  | +        if (fileFile != null && fileFile.getSuccess()) {
 | 
	
		
			
				|  |  | +            Map<Integer, Object> result = Maps.newHashMap();
 | 
	
		
			
				|  |  | +            int pageNo = 0;
 | 
	
		
			
				|  |  | +            if (CollectionUtils.isEmpty(fileFile.getSubFileList())) {
 | 
	
		
			
				|  |  | +                result.put(1, this.syncUploadOneFile(fileFile, 1));
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                int totalPage = fileFile.getSubFileList().size();
 | 
	
		
			
				|  |  | +                Iterator var5 = fileFile.getSubFileList().iterator();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                while(var5.hasNext()) {
 | 
	
		
			
				|  |  | +                    FormFileEntity subFile = (FormFileEntity)var5.next();
 | 
	
		
			
				|  |  | +                    ++pageNo;
 | 
	
		
			
				|  |  | +                    result.put(pageNo, this.syncUploadOneFile(subFile, totalPage));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return result;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            return null;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private Object syncUploadOneFile(FormFileEntity fileFile, int totalPage) {
 | 
	
		
			
				|  |  | +        Future<JSONObject> subUploadFuture = null;
 | 
	
		
			
				|  |  | +        RequestContext context = RequestContext.get();
 | 
	
		
			
				|  |  | +        if (!"ofd".equalsIgnoreCase(fileFile.getFileType()) && !"pdf".equalsIgnoreCase(fileFile.getFileType())) {
 | 
	
		
			
				|  |  | +            JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  | +            result.put("isOriginal", false);
 | 
	
		
			
				|  |  | +            result.put("fileType", "2");
 | 
	
		
			
				|  |  | +            result.put("imageUrl", fileFile.getFileUrl());
 | 
	
		
			
				|  |  | +            result.put("snapshotUrl", fileFile.getFileUrl());
 | 
	
		
			
				|  |  | +            return result;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                InputStream fileInputStream = UrlServiceUtils.getAttachmentDecodedStream(FileServiceFactory.getAttachmentFileService().getInputStream(fileFile.getFileUrl()));
 | 
	
		
			
				|  |  | +                Throwable var6 = null;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                try {
 | 
	
		
			
				|  |  | +                    byte[] streamByte = FileUtils.getByte(fileInputStream);
 | 
	
		
			
				|  |  | +                    subUploadFuture = uploadThreadPool.submit(new FileUploadAndSignTask(fileFile.getFileUrl(), streamByte, fileFile.getFileType(), fileFile.getSignatureFlag(), context));
 | 
	
		
			
				|  |  | +                } catch (Throwable var16) {
 | 
	
		
			
				|  |  | +                    var6 = var16;
 | 
	
		
			
				|  |  | +                    throw var16;
 | 
	
		
			
				|  |  | +                } finally {
 | 
	
		
			
				|  |  | +                    if (fileInputStream != null) {
 | 
	
		
			
				|  |  | +                        if (var6 != null) {
 | 
	
		
			
				|  |  | +                            try {
 | 
	
		
			
				|  |  | +                                fileInputStream.close();
 | 
	
		
			
				|  |  | +                            } catch (Throwable var15) {
 | 
	
		
			
				|  |  | +                                var6.addSuppressed(var15);
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            fileInputStream.close();
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            } catch (IOException var18) {
 | 
	
		
			
				|  |  | +                logger.error("文件处理失败:" + fileFile.getFileUrl(), var18);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return subUploadFuture;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void saveInvoice(JSONArray finalResult, JSONArray attachResult, boolean isHandleAttach, Map<String, Object> fileBaseInfo, JSONObject businessParam, IRecognitionListener recognitionListener) {
 | 
	
		
			
				|  |  | +        String fileUrl = (String)fileBaseInfo.get("fileUrl");
 | 
	
		
			
				|  |  | +        String fileName = (String)fileBaseInfo.get("fileName");
 | 
	
		
			
				|  |  | +        int totalPage = (Integer)fileBaseInfo.get("totalPage");
 | 
	
		
			
				|  |  | +        JSONArray handleResult = new JSONArray();
 | 
	
		
			
				|  |  | +        JSONArray mayErrorResult = new JSONArray();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        for(int i = 0; i < finalResult.size(); ++i) {
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                JSONObject invoiceInfo = finalResult.getJSONObject(i);
 | 
	
		
			
				|  |  | +                int pageNo = (Integer)invoiceInfo.get("pageNo");
 | 
	
		
			
				|  |  | +                setInvoiceSeq(invoiceInfo, businessParam, pageNo, i + 1);
 | 
	
		
			
				|  |  | +                Set<String> serialNosSet = new HashSet(8);
 | 
	
		
			
				|  |  | +                String snapshotUrl = null;
 | 
	
		
			
				|  |  | +                String awsInvoiceType = invoiceInfo.getString("invoiceType");
 | 
	
		
			
				|  |  | +                Long invoiceType = InputInvoiceTypeEnum.getInvoiceTypeByAwsType(awsInvoiceType);
 | 
	
		
			
				|  |  | +                if (InputInvoiceTypeEnum.ELECTRIC_ORDINARY.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ELECTRIC_SPECIAL.getCode().equals(invoiceType)) {
 | 
	
		
			
				|  |  | +                    String originalConfig = RimConfigUtils.getConfig("rim_config", "einvoice_auto_sign");
 | 
	
		
			
				|  |  | +                    if (!StringUtils.isEmpty(originalConfig) && !"0".equals(originalConfig)) {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("originalState", "1");
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("originalState", "0");
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                invoiceInfo.put("invoiceType", invoiceType);
 | 
	
		
			
				|  |  | +                Long tax_org = null;
 | 
	
		
			
				|  |  | +                String resourcePlugin = "";
 | 
	
		
			
				|  |  | +                if (null != businessParam) {
 | 
	
		
			
				|  |  | +                    invoiceInfo.putAll(businessParam);
 | 
	
		
			
				|  |  | +                    tax_org = businessParam.getLong("tax_org");
 | 
	
		
			
				|  |  | +                    resourcePlugin = businessParam.getString("resourcePlugin");
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (!ObjectUtils.isEmpty(tax_org)) {
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("tax_org", tax_org);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (StringUtils.isNotEmpty(invoiceInfo.getString("snapshotUrl"))) {
 | 
	
		
			
				|  |  | +                    snapshotUrl = FileUtils.downLoadAndUpload(invoiceInfo.getString("snapshotUrl"));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (StringUtils.isNotEmpty(snapshotUrl)) {
 | 
	
		
			
				|  |  | +                    invoiceInfo.put("snapshotUrl", snapshotUrl);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                logger.info("发票识别查验返回数据:" + invoiceInfo);
 | 
	
		
			
				|  |  | +                ConvertFieldUtil.getStandardInvoice(invoiceInfo);
 | 
	
		
			
				|  |  | +                if (StringUtils.isEmpty(invoiceInfo.getString("serialNo")) || serialNosSet.add(invoiceInfo.getString("serialNo"))) {
 | 
	
		
			
				|  |  | +                    if ("sign_by_expense".equals(resourcePlugin)) {
 | 
	
		
			
				|  |  | +                        InvoiceSaveService invoiceSaveService = InvoiceSaveService.newInstance(invoiceInfo.getString("invoiceType"));
 | 
	
		
			
				|  |  | +                        if (invoiceSaveService != null) {
 | 
	
		
			
				|  |  | +                            invoiceInfo.put("delete", invoiceSaveService.setInvoiceFiled(invoiceInfo));
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    String fileHash = invoiceInfo.getString("fileHash");
 | 
	
		
			
				|  |  | +                    String resourceSys = invoiceInfo.getString("resourceSys");
 | 
	
		
			
				|  |  | +                    String errcode = invoiceInfo.getString("errcode");
 | 
	
		
			
				|  |  | +                    if ("4999".equals(errcode) && InvoiceConvertUtils.isVatInvoiceType(invoiceInfo.getLong("invoiceType"))) {
 | 
	
		
			
				|  |  | +                        invoiceInfo.put("checkStatus", "3");
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    try {
 | 
	
		
			
				|  |  | +                        Object invoiceDate = invoiceInfo.get("invoiceDate");
 | 
	
		
			
				|  |  | +                        if (invoiceDate instanceof Long) {
 | 
	
		
			
				|  |  | +                            Date date = new Date((Long)invoiceDate);
 | 
	
		
			
				|  |  | +                            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
 | 
	
		
			
				|  |  | +                            String dateString = formatter.format(date);
 | 
	
		
			
				|  |  | +                            invoiceInfo.put("invoiceDate", dateString);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        this.invoiceCollectService.saveInvoice(invoiceInfo, fileUrl, fileHash);
 | 
	
		
			
				|  |  | +                    } catch (Exception var28) {
 | 
	
		
			
				|  |  | +                        mayErrorResult.add(invoiceInfo);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    String isSaleListInvoice = invoiceInfo.getString("isSaleListInvoice");
 | 
	
		
			
				|  |  | +                    Map<String, String> configMap = ImcConfigUtil.getValue("rim_recog_check");
 | 
	
		
			
				|  |  | +                    String isDealSaleList = (String)configMap.get("is_dealsalelist");
 | 
	
		
			
				|  |  | +                    if ("1".equals(isSaleListInvoice) && !"0".equals(isDealSaleList)) {
 | 
	
		
			
				|  |  | +                        this.recognitionCheckHelper.dealInvoiceAttachRelation(invoiceInfo);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    logger.info("发票助手本地上传保存发票后的数据:" + invoiceInfo);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                handleResult.add(invoiceInfo);
 | 
	
		
			
				|  |  | +            } catch (Throwable var29) {
 | 
	
		
			
				|  |  | +                handleResult.add(mayErrorResult);
 | 
	
		
			
				|  |  | +                logger.info("发票入库失败:", var29);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (recognitionListener != null) {
 | 
	
		
			
				|  |  | +            this.finallyHandleResult(handleResult, isHandleAttach, attachResult, fileUrl, fileName, totalPage, recognitionListener);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void finallyHandleResult(JSONArray handleResult, boolean isHandleAttach, JSONArray attachResult, String fileUrl, String fileName, int totalPage, IRecognitionListener recognitionListener) {
 | 
	
		
			
				|  |  | +        Map<Integer, List<Object>> handleMap = (Map)handleResult.stream().collect(Collectors.groupingBy((v) -> {
 | 
	
		
			
				|  |  | +            return ((JSONObject)v).getInteger("pageNo");
 | 
	
		
			
				|  |  | +        }));
 | 
	
		
			
				|  |  | +        Map<Integer, List<Object>> handleAttachMap = Maps.newLinkedHashMap();
 | 
	
		
			
				|  |  | +        if (!isHandleAttach) {
 | 
	
		
			
				|  |  | +            handleAttachMap = (Map)attachResult.stream().collect(Collectors.groupingBy((v) -> {
 | 
	
		
			
				|  |  | +                return ((JSONObject)v).getInteger("pageNo");
 | 
	
		
			
				|  |  | +            }));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        JSONArray handleAttachArray = new JSONArray();
 | 
	
		
			
				|  |  | +        Iterator var11 = handleMap.entrySet().iterator();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        while(var11.hasNext()) {
 | 
	
		
			
				|  |  | +            Map.Entry<Integer, List<Object>> entry = (Map.Entry)var11.next();
 | 
	
		
			
				|  |  | +            int pageNo = (Integer)entry.getKey();
 | 
	
		
			
				|  |  | +            JSONArray invoiceArray = JSONArray.parseArray(JSON.toJSONString(entry.getValue()));
 | 
	
		
			
				|  |  | +            logger.info("handleAttachMap:{}", handleAttachMap);
 | 
	
		
			
				|  |  | +            if (!((Map)handleAttachMap).isEmpty()) {
 | 
	
		
			
				|  |  | +                logger.info("添加清单到发票结果集通知前端:{}", pageNo);
 | 
	
		
			
				|  |  | +                Iterator var15 = ((Map)handleAttachMap).entrySet().iterator();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                while(var15.hasNext()) {
 | 
	
		
			
				|  |  | +                    Map.Entry<Integer, List<Object>> attachEntry = (Map.Entry)var15.next();
 | 
	
		
			
				|  |  | +                    int attachPageNo = (Integer)attachEntry.getKey();
 | 
	
		
			
				|  |  | +                    if (pageNo == attachPageNo) {
 | 
	
		
			
				|  |  | +                        invoiceArray.addAll(JSONArray.parseArray(JSON.toJSONString(attachEntry.getValue())));
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        handleAttachArray.addAll(JSONArray.parseArray(JSON.toJSONString(attachEntry.getValue())));
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            RecognitionListenerResult listener = new RecognitionListenerResult(fileUrl, fileName, pageNo, totalPage, invoiceArray);
 | 
	
		
			
				|  |  | +            recognitionListener.handle(listener);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (!handleAttachArray.isEmpty()) {
 | 
	
		
			
				|  |  | +            Map<Integer, List<Object>> handleAttach = (Map)handleAttachArray.stream().collect(Collectors.groupingBy((v) -> {
 | 
	
		
			
				|  |  | +                return ((JSONObject)v).getInteger("pageNo");
 | 
	
		
			
				|  |  | +            }));
 | 
	
		
			
				|  |  | +            Iterator var19 = handleAttach.entrySet().iterator();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            while(var19.hasNext()) {
 | 
	
		
			
				|  |  | +                Map.Entry<Integer, List<Object>> entry = (Map.Entry)var19.next();
 | 
	
		
			
				|  |  | +                int pageNo = (Integer)entry.getKey();
 | 
	
		
			
				|  |  | +                JSONArray attachArray = JSONArray.parseArray(JSON.toJSONString(entry.getValue()));
 | 
	
		
			
				|  |  | +                RecognitionListenerResult listener = new RecognitionListenerResult(fileUrl, fileName, pageNo, totalPage, attachArray);
 | 
	
		
			
				|  |  | +                recognitionListener.handle(listener);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private boolean getCheckFlag(JSONObject businessParam) {
 | 
	
		
			
				|  |  | +        boolean isCheck = true;
 | 
	
		
			
				|  |  | +        if (businessParam != null) {
 | 
	
		
			
				|  |  | +            isCheck = !"1".equals(businessParam.getString("notCheck"));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (!isCheck) {
 | 
	
		
			
				|  |  | +            businessParam.put("errcode", "4999");
 | 
	
		
			
				|  |  | +            businessParam.put("description", CheckContant.getCheckResultDesc("4999"));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return isCheck;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |