InvoiceCollectPluginEx.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package kd.imc.rim;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import kd.bos.context.RequestContext;
  5. import kd.bos.dataentity.serialization.SerializationUtils;
  6. import kd.bos.ext.form.control.CustomControl;
  7. import kd.bos.form.IPageCache;
  8. import kd.bos.form.control.events.UploadEvent;
  9. import kd.bos.logging.Log;
  10. import kd.bos.logging.LogFactory;
  11. import kd.bos.orm.util.CollectionUtils;
  12. import kd.bos.threads.ThreadPools;
  13. import kd.bos.util.StringUtils;
  14. import kd.imc.rim.common.constant.CollectTypeEnum;
  15. import kd.imc.rim.common.invoice.collector.InvoiceCollectTaskNew;
  16. import kd.imc.rim.common.service.DialogService;
  17. import kd.imc.rim.common.utils.BigDecimalUtil;
  18. import kd.imc.rim.common.utils.PermissionUtils;
  19. import kd.imc.rim.common.utils.RimConfigUtils;
  20. import kd.imc.rim.formplugin.collector.InvoiceCollectPlugin;
  21. import java.util.*;
  22. public class InvoiceCollectPluginEx extends InvoiceCollectPlugin {
  23. private static Log logger = LogFactory.getLog(InvoiceCollectPluginEx.class);
  24. @Override
  25. public void afterUpload(UploadEvent evt) {
  26. {
  27. String itemKey = evt.getCallbackKey();
  28. Object[] urls = evt.getUrls();
  29. logger.info("上传文件:{}-{}", itemKey, urls);
  30. if (urls.length > 0) {
  31. StringJoiner taskUrls = new StringJoiner(",");
  32. List<Map<String, String>> fileUrls = new ArrayList(urls.length);
  33. String mapSeqStr = this.getPageCache().get("upload_seq");
  34. Map<String, Object> nameSeq = new HashMap(urls.length);
  35. if (StringUtils.isNotEmpty(mapSeqStr)) {
  36. nameSeq = (Map) SerializationUtils.fromJsonString(mapSeqStr, nameSeq.getClass());
  37. }
  38. int i = 0;
  39. for(int size = urls.length; i < size; ++i) {
  40. String url = urls[i].toString();
  41. String fileName = url.substring(url.lastIndexOf(47) + 1);
  42. Map<String, String> map = new HashMap(2);
  43. map.put("url", url);
  44. map.put("name", fileName);
  45. if (!CollectionUtils.isEmpty((Map)nameSeq)) {
  46. String seq = String.valueOf(((Map)nameSeq).get(fileName));
  47. if (StringUtils.isNotEmpty(seq)) {
  48. map.put("seq", seq);
  49. }
  50. }
  51. fileUrls.add(map);
  52. }
  53. Collections.sort(fileUrls, (o1, o2) -> {
  54. Long uploadSeq1 = BigDecimalUtil.transDecimal(o1.get("seq")).longValue();
  55. Long uploadSeq2 = BigDecimalUtil.transDecimal(o2.get("seq")).longValue();
  56. return uploadSeq1.compareTo(uploadSeq2);
  57. });
  58. Iterator var14 = fileUrls.iterator();
  59. while(var14.hasNext()) {
  60. Map<String, String> fileUrl = (Map)var14.next();
  61. taskUrls.add((CharSequence)fileUrl.get("url"));
  62. }
  63. this.getPageCache().put("upload_itemKey", itemKey);
  64. this.getPageCache().remove("upload_seq");
  65. this.getPageCache().put("taskUrls", taskUrls.toString());
  66. this.progressBarVisible(Boolean.TRUE, new String[]{"进行中..."});
  67. this.getPageCache().put("startprogress", "true");
  68. JSONObject businessParam = this.getBusinessParam(CollectTypeEnum.PC_UPLOAD.getCode());
  69. businessParam.put("itemKey", itemKey);
  70. InvoiceCollectTaskNew collectTask = new InvoiceCollectTaskNew(RequestContext.get(), this.getView().getPageId(), fileUrls, businessParam);
  71. ThreadPools.executeOnce("CollectorProgressPool", collectTask);
  72. }
  73. }
  74. }
  75. private JSONObject getBusinessParam(String collectType) {
  76. JSONObject businessParam = new JSONObject();
  77. IPageCache pageCache = this.getView().getPageCache();
  78. String businessParamCache = pageCache.get("businessParam");
  79. if (businessParamCache != null) {
  80. businessParam = JSON.parseObject(businessParamCache);
  81. } else {
  82. RequestContext request = RequestContext.get();
  83. businessParam.put("collect_type", collectType);
  84. businessParam.put("resource", "收票管理");
  85. businessParam.put("isAdmin", PermissionUtils.checkPermission(request.getUserId(), request.getOrgId(), this.getView(), "1PAFGP5MO1NU"));
  86. String state = RimConfigUtils.getConfig("original_state");
  87. if ("1".equals(state)) {
  88. businessParam.put("originalState", "1");
  89. }
  90. Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
  91. if (!CollectionUtils.isEmpty(customParams)) {
  92. businessParam.putAll(customParams);
  93. }
  94. businessParam.put("billType", "fpqs");
  95. pageCache.put("businessParam", businessParam.toJSONString());
  96. }
  97. logger.info("发票签收采集参数:" + businessParam);
  98. return businessParam;
  99. }
  100. private void progressBarVisible(Boolean visibleFlag, String[] descriptionArray) {
  101. CustomControl customcontrol = (CustomControl)this.getControl("progressBar_customcontrol");
  102. DialogService service = new DialogService(customcontrol);
  103. if (visibleFlag) {
  104. if (null != descriptionArray) {
  105. service.show("1", descriptionArray, 500);
  106. } else {
  107. service.show("1", new String[]{"进行中..."}, 500);
  108. }
  109. } else {
  110. service.hide();
  111. }
  112. }
  113. }