FpzsMainEXPlugin.java 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package fi.rim.fromPlugin;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import kd.bos.dataentity.entity.DynamicObject;
  5. import kd.bos.form.control.Button;
  6. import kd.bos.form.control.Control;
  7. import kd.bos.form.control.EntryGrid;
  8. import kd.bos.form.control.events.RowClickEventListener;
  9. import kd.bos.form.control.events.TabSelectEvent;
  10. import kd.bos.form.control.events.TabSelectListener;
  11. import kd.bos.form.control.events.UploadListener;
  12. import kd.bos.msgjet.MsgSendFactory;
  13. import kd.bos.orm.util.CollectionUtils;
  14. import kd.imc.rim.common.constant.InputInvoiceTypeEnum;
  15. import kd.imc.rim.common.helper.ExcelHelper;
  16. import kd.imc.rim.common.invoice.fpzs.FpzsMainService;
  17. import kd.imc.rim.common.invoice.query.AttachQueryService;
  18. import kd.imc.rim.common.invoice.verify.VerifyStatisticsService;
  19. import kd.imc.rim.common.invoice.verify.VerifyUtil;
  20. import kd.imc.rim.common.license.LicenseFormPlugin;
  21. import kd.imc.rim.common.service.InvoiceAutoFillBillService;
  22. import kd.imc.rim.common.service.InvoiceLog;
  23. import kd.imc.rim.common.utils.BigDecimalUtil;
  24. import kd.imc.rim.common.utils.CacheHelper;
  25. import java.util.EventObject;
  26. import java.util.Iterator;
  27. import java.util.Map;
  28. public class FpzsMainEXPlugin extends LicenseFormPlugin implements RowClickEventListener, UploadListener, TabSelectListener {
  29. private static final String BTN_IMPORT = "btn_import";
  30. @Override
  31. public void tabSelected(TabSelectEvent tabSelectEvent) {}
  32. public void initialize() {
  33. EntryGrid entryGrid = (EntryGrid)this.getView().getControl("operate_entry");
  34. entryGrid.addRowClickListener(this);
  35. EntryGrid entryGridAttach = (EntryGrid)this.getView().getControl("operate_entry_attach");
  36. entryGridAttach.addRowClickListener(this);
  37. Button excelDownload = (Button)this.getView().getControl("excel_download");
  38. excelDownload.addClickListener(this);
  39. Button importButton = (Button)this.getView().getControl("btn_import");
  40. importButton.addClickListener(this);
  41. Button uploadFile = (Button)this.getView().getControl("upload_file");
  42. uploadFile.addUploadListener(this);
  43. Button uploadInvoiceAttach = (Button)this.getView().getControl("upload_invoice_attach");
  44. uploadInvoiceAttach.addUploadListener(this);
  45. Button uploadInvoiceAttachUnimport = (Button)this.getView().getControl("upload_invoice_attach2");
  46. uploadInvoiceAttachUnimport.addUploadListener(this);
  47. }
  48. public void click(EventObject evt) {
  49. Control properties = (Control)evt.getSource();
  50. String clickKey = properties.getKey();
  51. if ("excel_download".equals(clickKey)) {
  52. ExcelHelper.downloadTemplate(this, "templates", "发票查验模板.xlsx");
  53. } else if ("btn_import".equals(clickKey)) {
  54. Map<String, Object> param = FpzsMainService.getCustomParam(this);
  55. Object linkKey = param.get("linkKey");
  56. int attachTotal = this.getModel().getEntryRowCount("attach_grid_entry");
  57. JSONObject returnData = new JSONObject();
  58. JSONArray attachData = new JSONArray();
  59. String billId = "billId";
  60. if (!CollectionUtils.isEmpty(param)) {
  61. billId = (String)param.get("billId");
  62. }
  63. AttachQueryService attachQueryService = new AttachQueryService();
  64. String entityId = (String)param.get("entityId");
  65. String resource = (String)param.get("resource");
  66. JSONArray attachCacheArray = new JSONArray();
  67. String key;
  68. for(int i = 0; i < attachTotal; ++i) {
  69. String serialNo = (String)this.getModel().getValue("serial_no3", i);
  70. String attachId = (String)this.getModel().getValue("attachid", i);
  71. JSONObject attach = new JSONObject(true);
  72. attach.put("serialNo", serialNo);
  73. attach.put("attachId", attachId);
  74. attach.put("attachType", (String)this.getModel().getValue("attach_type", i));
  75. key = (String)this.getModel().getValue("attach_name", i);
  76. attach.put("attachName", key);
  77. String fileExtension = (String)this.getModel().getValue("file_extension", i);
  78. attach.put("fileExtension", fileExtension);
  79. attach.put("originalFileName", key + '.' + fileExtension);
  80. attach.put("attachNo", (String)this.getModel().getValue("attach_no", i));
  81. attach.put("attachUrl", (String)this.getModel().getValue("attach_path", i));
  82. attach.put("remark", (String)this.getModel().getValue("attach_remark", i));
  83. attach.put("attachIcon", (String)this.getModel().getValue("attach_icon", i));
  84. attach.put("uploadDate", this.getModel().getValue("upload_date", i));
  85. Object pkValue = this.getModel().getValue("attach_category_grid");
  86. Object pkValue2 = this.getModel().getValue("attach_categoryid");
  87. attach.put("expenseId", billId);
  88. DynamicObject attachCategory = (DynamicObject)this.getModel().getValue("attach_category_grid", i);
  89. if (attachCategory != null) {
  90. attach.put("attachCategory", attachCategory.getLong("id"));
  91. }
  92. attachCacheArray.add(attach);
  93. JSONObject dataJson = new JSONObject();
  94. dataJson.put("serialNo", serialNo);
  95. dataJson.put("attachId", attachId);
  96. dataJson.put("attachUrl", (String)this.getModel().getValue("attach_path", i));
  97. dataJson.put("attachType", (String)this.getModel().getValue("attach_type", i));
  98. dataJson.put("attachNo", (String)this.getModel().getValue("attach_no", i));
  99. dataJson.put("attachName", (String)this.getModel().getValue("attach_name", i));
  100. dataJson.put("remark", (String)this.getModel().getValue("attach_remark", i));
  101. dataJson.put("attachSize", this.getModel().getValue("attach_size", i));
  102. dataJson.put("attachIcon", this.getModel().getValue("attach_icon", i));
  103. dataJson.put("uploadDate", this.getModel().getValue("upload_date", i));
  104. attachData.add(dataJson);
  105. }
  106. attachQueryService.addFpzsAttach(billId, entityId, resource, attachCacheArray);
  107. returnData.put("attachData", attachData);
  108. JSONObject dataJson = FpzsMainService.getInvoiceDataCache(this.getView().getPageId());
  109. JSONArray invoiceData = new JSONArray();
  110. JSONArray invoiceVerifyData = new JSONArray();
  111. Iterator<String> iterator = dataJson.keySet().iterator();
  112. while(iterator.hasNext()) {
  113. key = (String)iterator.next();
  114. JSONObject invoice = dataJson.getJSONObject(key);
  115. invoiceVerifyData.add(invoice);
  116. String errorLevel = invoice.getString("errorLevel");
  117. String invoiceType = invoice.getString("invoiceType");
  118. String serialNo = invoice.getString("serialNo");
  119. VerifyUtil.updateDataStatus(errorLevel, serialNo, InputInvoiceTypeEnum.getInvoiceTypeByAwsType(invoiceType), Boolean.TRUE);
  120. if (!FpzsMainService.isFilter(invoice) && !invoice.isEmpty()) {
  121. if (!"expense_pc".equals(param.get("resource"))) {
  122. invoice.remove("validateMessage_html");
  123. }
  124. invoiceData.add(invoice);
  125. }
  126. }
  127. this.saveVerifyResult(invoiceVerifyData);
  128. if (attachTotal < 1 && invoiceData.isEmpty()) {
  129. this.getView().showTipNotification("不存在符合导入单据的发票,请检查是否已采集发票或采集的发票是否合规", 3000);
  130. return;
  131. }
  132. returnData.put("invoiceData", invoiceData);//发票助手导入单据的数据
  133. Object pushType = param.get("pushType");
  134. InvoiceLog.insertExpenseLog("发票助手导入单据", String.valueOf(param.get("billId")), String.valueOf(param.get("billNo")), returnData.toJSONString());
  135. if (pushType != null) {
  136. if ("socket".equals(pushType.toString())) {
  137. MsgSendFactory.getSender().send(linkKey.toString(), returnData.toJSONString());
  138. } else if ("poll".equals(pushType.toString())) {
  139. CacheHelper.put("rim_push:" + linkKey, returnData.toJSONString(), 120);
  140. }
  141. } else {
  142. InvoiceAutoFillBillService iafbs = new InvoiceAutoFillBillService();
  143. iafbs.autoFill(this.getView(), returnData);
  144. this.getView().returnDataToParent(returnData);
  145. this.getView().close();
  146. }
  147. }
  148. }
  149. private void saveVerifyResult(JSONArray invoices) {
  150. if (!CollectionUtils.isEmpty(invoices)) {
  151. Map<String, Object> param = FpzsMainService.getCustomParam(this);
  152. VerifyStatisticsService.asyncSaveVerifyStatistics(invoices, BigDecimalUtil.transDecimal(param.get("orgId")).longValue(), (String)param.get("userId"));
  153. }
  154. }
  155. }