| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 | 
							- //
 
- // Source code recreated from a .class file by IntelliJ IDEA
 
- // (powered by FernFlower decompiler)
 
- //
 
- package kd.imc.rim;
 
- import com.alibaba.fastjson.JSON;
 
- import com.alibaba.fastjson.JSONArray;
 
- import com.alibaba.fastjson.JSONObject;
 
- import java.util.ArrayList;
 
- import java.util.Iterator;
 
- import java.util.List;
 
- import java.util.Map;
 
- import java.util.concurrent.Callable;
 
- import kd.bos.context.RequestContext;
 
- import kd.bos.dataentity.entity.DynamicObject;
 
- import kd.bos.dataentity.entity.DynamicObjectCollection;
 
- import kd.bos.dataentity.resource.ResManager;
 
- import kd.bos.dataentity.utils.StringUtils;
 
- import kd.bos.dlock.DLock;
 
- import kd.bos.logging.Log;
 
- import kd.bos.logging.LogFactory;
 
- import kd.bos.orm.query.QFilter;
 
- import kd.bos.orm.util.CollectionUtils;
 
- import kd.bos.servicehelper.BusinessDataServiceHelper;
 
- import kd.bos.servicehelper.operation.SaveServiceHelper;
 
- import kd.imc.rim.common.constant.InputInvoiceTypeEnum;
 
- import kd.imc.rim.common.constant.ResultContant;
 
- import kd.imc.rim.common.invoice.fpzs.FpzsMainService;
 
- import kd.imc.rim.common.invoice.recognition.listener.IRecognitionListener;
 
- import kd.imc.rim.common.service.EInvoiceZipXmlDealService;
 
- import kd.imc.rim.common.service.ElectAccVoucherService;
 
- import kd.imc.rim.common.service.ExcelInvoiceUploadService;
 
- import kd.imc.rim.common.utils.BigDecimalUtil;
 
- import kd.imc.rim.common.utils.CacheHelper;
 
- import kd.imc.rim.common.utils.FileUtils;
 
- import kd.imc.rim.common.utils.MD5;
 
- import org.apache.commons.lang3.tuple.Pair;
 
- public class RecognitionCheckTaskEx implements Callable<JSONObject> {
 
-     private static Log logger = LogFactory.getLog(RecognitionCheckTaskEx.class);
 
-     private static int cache_time_out = 1800;
 
-     private JSONObject businessParam;
 
-     private Map<String, Object> customParam;
 
-     private String url;
 
-     private String fileName;
 
-     private String pageId;
 
-     private String source;
 
-     private RequestContext ctx;
 
-     public static final String waiting = "waiting";
 
-     public static final String success = "success";
 
-     public static final String fail = "fail";
 
-     protected static final List<String> telGoodNames = new ArrayList<String>(12) {
 
-         private static final long serialVersionUID = 2608083843312492007L;
 
-         {
 
-             this.add("电信服务");
 
-             this.add("基础电信服务");
 
-             this.add("语音通话服务");
 
-             this.add("出租或出售网络元素");
 
-             this.add("增值电信服务");
 
-             this.add("短信和彩信服务");
 
-             this.add("电子数据和信息的传输及应用服务");
 
-             this.add("互联网接入服务");
 
-             this.add("广播电视信号传输服务");
 
-             this.add("卫星电视信号落地转接服务");
 
-             this.add("其他增值电信服务");
 
-         }
 
-     };
 
-     public RecognitionCheckTaskEx(RequestContext ctx, String source, String pageId, JSONObject businessParam, Map<String, Object> customParam, String url, String fileName) {
 
-         saveCacheFile(pageId, url, "waiting");
 
-         this.ctx = ctx;
 
-         this.pageId = pageId;
 
-         this.businessParam = businessParam;
 
-         this.url = url;
 
-         this.source = source;
 
-         this.fileName = fileName;
 
-         this.customParam = customParam;
 
-     }
 
-     public JSONObject call() throws Exception {
 
-         logger.info("begin RecognitionCheckTask :{},{}", this.url, this.fileName);
 
-         try {
 
-             RequestContext.copyAndSet(this.ctx);
 
-             if (StringUtils.isEmpty(this.url)) {
 
-                 return null;
 
-             } else {
 
-                 JSONObject invoiceResult = new JSONObject();
 
-                 Long orgId = RequestContext.get().getOrgId();
 
-                 long rim_user;
 
-                 if (this.customParam != null) {
 
-                     try {
 
-                         rim_user = BigDecimalUtil.transDecimal(this.customParam.get("orgId")).longValue();
 
-                         if (rim_user > 0L) {
 
-                             orgId = rim_user;
 
-                         }
 
-                     } catch (Exception var12) {
 
-                     }
 
-                 }
 
-                 if (this.businessParam != null) {
 
-                     rim_user = BigDecimalUtil.transDecimal(this.businessParam.get("rim_user")).longValue();
 
-                     if (rim_user < 1L) {
 
-                         this.businessParam.put("rim_user", RequestContext.get().getCurrUserId());
 
-                     }
 
-                 }
 
-                 boolean isNeedDeal = FileUtils.checkFileType(this.fileName, new String[]{"zip", "ofd", "pdf"});
 
-                 if (isNeedDeal) {
 
-                     ElectAccVoucherService electAccVoucherService = new ElectAccVoucherService();
 
-                     invoiceResult = electAccVoucherService.dealVoucher(this.url, this.fileName, orgId, this.businessParam, (IRecognitionListener)null);
 
-                 }
 
-                 boolean isZipXmlEI = FileUtils.checkFileType(this.fileName, new String[]{"zip", "xml"});
 
-                 if (isZipXmlEI && !"0000".equals(invoiceResult.getString("errcode"))) {
 
-                     invoiceResult = EInvoiceZipXmlDealService.analysisAndCheckSave(this.url, this.fileName, orgId, this.businessParam, (IRecognitionListener)null);
 
-                 }
 
-                 String xbrlErrCode = invoiceResult.getString("errcode");
 
-                 boolean dealResult = StringUtils.isEmpty(xbrlErrCode) || !xbrlErrCode.equals("0000");
 
-                 boolean isZip = FileUtils.checkFileType(this.fileName, new String[]{"zip"});
 
-                 if (dealResult && !isZip) {
 
-                     if (FileUtils.isExcel(this.fileName)) {
 
-                         invoiceResult = ExcelInvoiceUploadService.getInstance().uploadExcelInvoice(this.url, this.fileName, (IRecognitionListener)null, this.businessParam);
 
-                     } else {
 
-                         logger.info("RecognitionCheckTask识别url:{}{}", this.fileName, this.url);
 
-                         invoiceResult = RecognitionCheckServiceEx.getInstance().recognitionCheckInvoice(this.url, this.fileName, (IRecognitionListener)null, this.businessParam);
 
-                     }
 
-                 }
 
-                 logger.info("发票助手本地上传最终数据返回:{}-{}", this.pageId, invoiceResult);
 
-                 if (ResultContant.isSuccess(invoiceResult)) {
 
-                     JSONArray invoiceArray = invoiceResult.getJSONArray("data");
 
-                     classOfInvoice(invoiceArray);
 
-                     JSONArray failInvoiceArray = invoiceResult.getJSONArray("failData");
 
-                     JSONArray attachArray = invoiceResult.getJSONArray("attach");
 
-                     if (!CollectionUtils.isEmpty(failInvoiceArray)) {
 
-                         CacheHelper.put(this.pageId + "failResult", failInvoiceArray.toJSONString(), cache_time_out);
 
-                     }
 
-                     if (invoiceArray == null && attachArray == null) {
 
-                         saveCacheFile(this.pageId, this.url, "fail");
 
-                     } else {
 
-                         CacheHelper.put(this.pageId + "refresh", "1", cache_time_out);
 
-                         if ("fpzs".equals(this.source)) {
 
-                             Pair<JSONObject, Boolean> cachePair = FpzsMainService.cacheInvoiceList(this.pageId, this.customParam, invoiceArray, attachArray);
 
-                             if ((Boolean)cachePair.getRight()) {
 
-                                 CacheHelper.put(this.pageId + "scannerProcessRepeat", cachePair.getRight() + "", cache_time_out);
 
-                             }
 
-                         } else {
 
-                             saveCacheFileResult(this.url, invoiceArray);
 
-                         }
 
-                         saveCacheFile(this.pageId, this.url, "success");
 
-                     }
 
-                 } else {
 
-                     saveCacheFile(this.pageId, this.url, "fail");
 
-                     saveCacheCause(this.pageId, this.url, "fail", invoiceResult.getString("description"));
 
-                 }
 
-                 return invoiceResult;
 
-             }
 
-         } catch (Throwable var13) {
 
-             logger.info("RecognitionCheckTask throwable:{}", var13);
 
-             saveCacheFile(this.pageId, this.url, "fail");
 
-             saveCacheCause(this.pageId, this.url, "fail", ResManager.loadKDString("程序错误", "RecognitionCheckTask_0", "imc-rim-common", new Object[0]));
 
-             return new JSONObject();
 
-         }
 
-     }
 
-     public static void classOfInvoice(JSONArray invoiceArray) {
 
-         if (invoiceArray != null) {
 
-             for(int i = 0; i < invoiceArray.size(); ++i) {
 
-                 JSONObject invoice = invoiceArray.getJSONObject(i);
 
-                 Long invoiceType = invoice.getLong("invoiceType");
 
-                 if (InputInvoiceTypeEnum.needClassOfInvoice(invoiceType)) {
 
-                     boolean telFlag = telType(invoice);
 
-                     boolean childFlag = childType(invoice);
 
-                     if (telFlag && childFlag) {
 
-                         setInvoiceClass(invoice, "11", "9");
 
-                     } else if (telFlag) {
 
-                         setInvoiceClass(invoice, "9");
 
-                     } else if (childFlag) {
 
-                         setInvoiceClass(invoice, "11");
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-     }
 
-     private static boolean childType(JSONObject invoice) {
 
-         boolean flag = false;
 
-         Long invoiceType = invoice.getLong("invoiceType");
 
-         if (InputInvoiceTypeEnum.FINANCIAL_INVOICE.getCode().equals(invoiceType)) {
 
-             String invoicingPartyName = invoice.getString("invoicingPartyName");
 
-             if (StringUtils.isNotEmpty(invoicingPartyName) && invoicingPartyName.contains("幼儿园")) {
 
-                 flag = true;
 
-             }
 
-         } else if (InputInvoiceTypeEnum.ORDINARY_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ORDINARY_PAPER.getCode().equals(invoiceType) || InputInvoiceTypeEnum.GENERAL_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ELECTRIC_ORDINARY.getCode().equals(invoiceType)) {
 
-             JSONArray items = invoice.getJSONArray("items");
 
-             if (items == null) {
 
-                 return false;
 
-             }
 
-             for(int i = 0; i < items.size(); ++i) {
 
-                 JSONObject item = items.getJSONObject(i);
 
-                 String goodName = item.getString("goodsName");
 
-                 if (StringUtils.isNotEmpty(goodName) && goodName.contains("保教费")) {
 
-                     flag = true;
 
-                     break;
 
-                 }
 
-             }
 
-         }
 
-         return flag;
 
-     }
 
-     private static boolean telType(JSONObject invoice) {
 
-         Long invoiceType = invoice.getLong("invoiceType");
 
-         boolean telFlag = false;
 
-         if (InputInvoiceTypeEnum.ORDINARY_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.SPECIAL_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ORDINARY_PAPER.getCode().equals(invoiceType) || InputInvoiceTypeEnum.SPECIAL_PAPER.getCode().equals(invoiceType) || InputInvoiceTypeEnum.TOLL_ELECTRON.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ELECTRIC_ORDINARY.getCode().equals(invoiceType) || InputInvoiceTypeEnum.ELECTRIC_SPECIAL.getCode().equals(invoiceType) || InputInvoiceTypeEnum.GENERAL_ELECTRON.getCode().equals(invoiceType)) {
 
-             JSONArray items = invoice.getJSONArray("items");
 
-             if (items == null) {
 
-                 return false;
 
-             }
 
-             boolean flag = false;
 
-             for(int i = 0; i < items.size(); ++i) {
 
-                 JSONObject item = items.getJSONObject(i);
 
-                 String goodName = item.getString("goodsName");
 
-                 Iterator var8 = telGoodNames.iterator();
 
-                 while(var8.hasNext()) {
 
-                     String s = (String)var8.next();
 
-                     if (goodName.contains(s)) {
 
-                         telFlag = true;
 
-                         flag = true;
 
-                         break;
 
-                     }
 
-                 }
 
-                 if (flag) {
 
-                     break;
 
-                 }
 
-             }
 
-         }
 
-         return telFlag;
 
-     }
 
-     private static void setInvoiceClass(JSONObject invoice, String... classType) {
 
-         Long mainId = invoice.getLong("mainId");
 
-         DynamicObject invoices = BusinessDataServiceHelper.loadSingle("rim_invoice", "id, mul_class, ext_info", new QFilter[]{new QFilter("id", "=", mainId)});
 
-         if (invoices != null) {
 
-             String mulClassStr = String.join(",", classType);
 
-             String extInfo = invoices.getString("ext_info");
 
-             JSONObject extObject = new JSONObject();
 
-             if (StringUtils.isNotEmpty(extInfo)) {
 
-                 try {
 
-                     extObject = JSONObject.parseObject(extInfo);
 
-                 } catch (Exception var13) {
 
-                     extObject = new JSONObject();
 
-                 }
 
-             }
 
-             extObject.put("sys_mulclass", mulClassStr);
 
-             invoices.set("ext_info", extObject.toString());
 
-             DynamicObjectCollection mul_class = invoices.getDynamicObjectCollection("mul_class");
 
-             if (CollectionUtils.isEmpty(mul_class)) {
 
-                 String[] var8 = classType;
 
-                 int var9 = classType.length;
 
-                 for(int var10 = 0; var10 < var9; ++var10) {
 
-                     String typeStr = var8[var10];
 
-                     DynamicObject classInfo = mul_class.addNew();
 
-                     classInfo.set("fbasedataid_id", typeStr);
 
-                     SaveServiceHelper.save(new DynamicObject[]{invoices});
 
-                 }
 
-             }
 
-         }
 
-     }
 
-     public JSONObject getBusinessParam() {
 
-         return this.businessParam;
 
-     }
 
-     public void setBusinessParam(JSONObject businessParam) {
 
-         this.businessParam = businessParam;
 
-     }
 
-     public String getUrl() {
 
-         return this.url;
 
-     }
 
-     public void setUrl(String url) {
 
-         this.url = url;
 
-     }
 
-     public static void saveCacheFileResult(String url, JSONArray result) {
 
-         if (result != null) {
 
-             CacheHelper.put(MD5.md5Hex(url), result.toJSONString(), cache_time_out);
 
-         } else {
 
-             CacheHelper.remove(MD5.md5Hex(url));
 
-         }
 
-     }
 
-     public static JSONArray queryCacheFileResult(String url) {
 
-         String result = CacheHelper.get(MD5.md5Hex(url));
 
-         return result != null ? JSONArray.parseArray(result) : new JSONArray();
 
-     }
 
-     public static void saveCacheFile(String pageId, String url, String operate) {
 
-         cacheFile(pageId, url, operate);
 
-     }
 
-     public static void saveCacheCause(String pageId, String url, String operate, String cause) {
 
-         cacheCause(pageId, url, operate, cause);
 
-     }
 
-     public static JSONObject queryCacheFile(String pageId) {
 
-         return cacheFile(pageId, (String)null, "query");
 
-     }
 
-     public static JSONObject queryCacheCause(String pageId) {
 
-         return cacheCause(pageId, (String)null, "query", (String)null);
 
-     }
 
-     public static void clearCacheFile(String pageId) {
 
-         cacheFile(pageId, (String)null, "remove");
 
-     }
 
-     private static JSONObject cacheCause(String pageId, String url, String operate, String cause) {
 
-         logger.info(pageId + url + operate + cause);
 
-         if (StringUtils.isEmpty(pageId)) {
 
-             return null;
 
-         } else {
 
-             String cacheKey = "scaner_cause_" + pageId;
 
-             DLock lock = DLock.create("lock_" + cacheKey, ResManager.loadKDString("刷新卡片锁", "RecognitionCheckTask_1", "imc-rim-common", new Object[0]));
 
-             Throwable var6 = null;
 
-             try {
 
-                 int times = 0;
 
-                 while(times < 10) {
 
-                     ++times;
 
-                     if (lock.tryLock(100L)) {
 
-                         try {
 
-                             String cache;
 
-                             if ("remove".equals(operate)) {
 
-                                 CacheHelper.remove(cacheKey);
 
-                                 cache = null;
 
-                                 return null;
 
-                             }
 
-                             cache = CacheHelper.get(cacheKey);
 
-                             JSONObject obj = null;
 
-                             if (StringUtils.isEmpty(cache)) {
 
-                                 obj = new JSONObject();
 
-                             } else {
 
-                                 obj = JSON.parseObject(cache);
 
-                             }
 
-                             JSONObject var10;
 
-                             if ("query".equals(operate)) {
 
-                                 var10 = obj;
 
-                                 return var10;
 
-                             }
 
-                             if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(operate) && StringUtils.isNotEmpty(cause)) {
 
-                                 obj.put(url, cause);
 
-                                 CacheHelper.put(cacheKey, obj.toJSONString(), cache_time_out);
 
-                             }
 
-                             var10 = obj;
 
-                             return var10;
 
-                         } finally {
 
-                             lock.unlock();
 
-                         }
 
-                     }
 
-                 }
 
-             } catch (Throwable var29) {
 
-                 var6 = var29;
 
-                 throw var29;
 
-             } finally {
 
-                 if (lock != null) {
 
-                     if (var6 != null) {
 
-                         try {
 
-                             lock.close();
 
-                         } catch (Throwable var27) {
 
-                             var6.addSuppressed(var27);
 
-                         }
 
-                     } else {
 
-                         lock.close();
 
-                     }
 
-                 }
 
-             }
 
-             return null;
 
-         }
 
-     }
 
-     private static JSONObject cacheFile(String pageId, String url, String operate) {
 
-         logger.info(pageId + url + operate);
 
-         if (StringUtils.isEmpty(pageId)) {
 
-             return null;
 
-         } else {
 
-             String cacheKey = "scaner_" + pageId;
 
-             DLock lock = DLock.create("lock_" + cacheKey, ResManager.loadKDString("刷新卡片锁", "RecognitionCheckTask_1", "imc-rim-common", new Object[0]));
 
-             Throwable var5 = null;
 
-             JSONObject var11;
 
-             try {
 
-                 int times = 0;
 
-                 do {
 
-                     if (times >= 10) {
 
-                         return null;
 
-                     }
 
-                     ++times;
 
-                 } while(!lock.tryLock(100L));
 
-                 long starttime = System.currentTimeMillis();
 
-                 try {
 
-                     String cache;
 
-                     if ("remove".equals(operate)) {
 
-                         CacheHelper.remove(cacheKey);
 
-                         cache = null;
 
-                         return null;
 
-                     }
 
-                     cache = CacheHelper.get(cacheKey);
 
-                     JSONObject obj = null;
 
-                     if (StringUtils.isEmpty(cache)) {
 
-                         obj = new JSONObject();
 
-                     } else {
 
-                         obj = JSON.parseObject(cache);
 
-                     }
 
-                     if ("query".equals(operate)) {
 
-                         var11 = obj;
 
-                         return var11;
 
-                     }
 
-                     if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(operate)) {
 
-                         obj.put(url, operate);
 
-                         CacheHelper.put(cacheKey, obj.toJSONString(), cache_time_out);
 
-                     }
 
-                     var11 = obj;
 
-                 } finally {
 
-                     logger.info("cacheFile总耗时:{}-{}", pageId, System.currentTimeMillis() - starttime);
 
-                     lock.unlock();
 
-                 }
 
-             } catch (Throwable var30) {
 
-                 var5 = var30;
 
-                 throw var30;
 
-             } finally {
 
-                 if (lock != null) {
 
-                     if (var5 != null) {
 
-                         try {
 
-                             lock.close();
 
-                         } catch (Throwable var28) {
 
-                             var5.addSuppressed(var28);
 
-                         }
 
-                     } else {
 
-                         lock.close();
 
-                     }
 
-                 }
 
-             }
 
-             return var11;
 
-         }
 
-     }
 
-     public String getSource() {
 
-         return this.source;
 
-     }
 
-     public void setSource(String source) {
 
-         this.source = source;
 
-     }
 
-     public Map<String, Object> getCustomParam() {
 
-         return this.customParam;
 
-     }
 
-     public void setCustomParam(Map<String, Object> customParam) {
 
-         this.customParam = customParam;
 
-     }
 
- }
 
 
  |