ReimbursementFormPlugin.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package fi.em.formPlugin;
  2. import com.aliyun.odps.security.User;
  3. import kd.bos.exception.KDBizException;
  4. import kd.bos.form.plugin.AbstractFormPlugin;
  5. import kd.sdk.plugin.Plugin;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import kd.bos.dataentity.entity.DynamicObject;
  9. import kd.bos.dataentity.serialization.SerializationUtils;
  10. import kd.bos.form.control.Control;
  11. import kd.bos.form.control.EntryGrid;
  12. import kd.bos.orm.query.QCP;
  13. import kd.bos.orm.query.QFilter;
  14. import kd.bos.servicehelper.BusinessDataServiceHelper;
  15. import org.apache.commons.lang3.StringUtils;
  16. import java.math.BigDecimal;
  17. import java.util.*;
  18. /**
  19. * @author cjz
  20. * @date 2024/7/25 15:13
  21. * @description:报销单初始化表单
  22. */
  23. public class ReimbursementFormPlugin extends AbstractFormPlugin implements Plugin {
  24. private final static String KEY_OK = "btnok";//确定按钮标识
  25. private final static String KEY_CANCEL = "btncancel";//页面取消按钮标识
  26. private final static String KEY_SEARCH = "search";//动态表单查询按钮操作
  27. private final static String FORMID_ENTRY = "nckd_entryentity";//动态表单单据体标识
  28. private static String er_prepaybill = "er_prepaybill";//预付单标识
  29. /**
  30. * 页面点击事件
  31. *
  32. * @param evt
  33. */
  34. @Override
  35. public void click(EventObject evt) {
  36. super.click(evt);
  37. //获取被点击的控件对象
  38. Control source = (Control) evt.getSource();
  39. String pageId = this.getView().getPageId();
  40. //点击确定后
  41. if (StringUtils.equals(source.getKey(), KEY_OK)) {
  42. String listStr = this.getPageCache().get(pageId);
  43. if (StringUtils.isNotBlank(listStr)) {
  44. JSONArray reJa = new JSONArray();
  45. //获取单据控件模型
  46. EntryGrid entryGrid = this.getView().getControl(FORMID_ENTRY);
  47. //获取选择的行号
  48. int[] selectRows = entryGrid.getSelectRows();
  49. //判断数据是否存在
  50. if (selectRows.length <= 0) {
  51. this.getView().showMessage("请先选择一条数据!");
  52. return;
  53. }
  54. JSONArray infoJa = SerializationUtils.fromJsonString(listStr, JSONArray.class);
  55. for (int i = 0; i < selectRows.length; i++) {
  56. JSONObject reJo = infoJa.getJSONObject(selectRows[i]);
  57. reJa.add(reJo);
  58. }
  59. HashMap<String, String> map = new HashMap<>();
  60. map.put("reJaStr", reJa.toJSONString());
  61. //将获取的json数据返回到界面view中
  62. this.getView().returnDataToParent(map);
  63. }
  64. this.getView().close();
  65. } else if (StringUtils.equals(source.getKey(), KEY_CANCEL)) {
  66. //被点击控件为取消则设置返回值为空并关闭页面(在页面关闭回调方法中必须验证返回值不为空,否则会报空指针)
  67. this.getView().returnDataToParent(null);
  68. this.getView().close();
  69. } else {
  70. this.getView().returnDataToParent(null);
  71. this.getView().close();
  72. }
  73. }
  74. //监听接口
  75. @Override
  76. public void registerListener(EventObject e) {
  77. super.registerListener(e);
  78. //页面确认按钮和取消按钮添加监听
  79. this.addClickListeners(KEY_OK, KEY_CANCEL);
  80. }
  81. @Override
  82. public void afterCreateNewData(EventObject e) {
  83. super.afterBindData(e);
  84. //获取父页面传入数据
  85. Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
  86. String orgnumber = (String) customParams.get("orgnumber");
  87. String orgid = (String) customParams.get("orgid");
  88. String creatorNumber=(String) customParams.get("creatorNumber");//获取人员编码
  89. String costdeptNumber=(String) customParams.get("costdeptNumber");//获取费用承担部门编码
  90. if (orgnumber == null) {
  91. throw new KDBizException("付费承担公司为空!");
  92. }
  93. List<JSONObject> resdate = new ArrayList<>();
  94. //历史数据清除
  95. this.getModel().deleteEntryData(FORMID_ENTRY);
  96. //根据当前用户和费用承担部门过滤
  97. QFilter nckd_orgamountFilter = new QFilter("costdept.number", QCP.equals, costdeptNumber);
  98. nckd_orgamountFilter.and("billstatus", QCP.equals, "E");
  99. nckd_orgamountFilter.and("creator.number",QCP.equals,creatorNumber);
  100. DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.
  101. load(er_prepaybill, "id,number", new QFilter[]{nckd_orgamountFilter});
  102. for (int c=0;c<nckd_orgamountaccount.length;c++){
  103. //当前循环动因基础资料单头
  104. DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(nckd_orgamountaccount[c].getPkValue(), nckd_orgamountaccount[c].getDynamicObjectType().getName());
  105. String billno= dynamicObject.getString("billno");
  106. //循环分录
  107. for (DynamicObject entryentity : dynamicObject.getDynamicObjectCollection("expenseentryentity")) {
  108. //获取费用承担部门
  109. DynamicObject entrycostdept = entryentity.getDynamicObject("entrycostdept");
  110. //获取费用项目
  111. DynamicObject expenseitem=entryentity.getDynamicObject("expenseitem");
  112. //申请金额
  113. BigDecimal expenseamount=entryentity.getBigDecimal("expenseamount");
  114. //结算金额
  115. BigDecimal exporiusedamount=entryentity.getBigDecimal("exporiusedamount");
  116. //未结算金额
  117. BigDecimal orgiexpebalanceamount=entryentity.getBigDecimal("orgiexpebalanceamount");
  118. //备注
  119. String remark=entryentity.getString("remark");
  120. //新增动态单据分录
  121. int rowIndex = this.getModel().createNewEntryRow(FORMID_ENTRY);
  122. //赋值给新增分录
  123. this.getModel().setValue("nckd_billno",billno,rowIndex);
  124. this.getModel().setValue("nckd_entrycostdept",entrycostdept,rowIndex);
  125. this.getModel().setValue("nckd_expenseitem",expenseitem,rowIndex);
  126. this.getModel().setValue("nckd_expenseamount",expenseamount,rowIndex);
  127. this.getModel().setValue("nckd_exporiusedamount",exporiusedamount,rowIndex);
  128. this.getModel().setValue("nckd_unexporiusedamount",orgiexpebalanceamount,rowIndex);
  129. this.getModel().setValue("nckd_remarke",remark,rowIndex);
  130. //将选中的数据放到缓存中
  131. JSONObject obj = new JSONObject();
  132. //放入缓存
  133. obj.put("nckd_billno",billno);
  134. obj.put("nckd_entrycostdept",entrycostdept.getString("number"));
  135. obj.put("nckd_expenseitem",expenseitem.getString("number"));
  136. obj.put("nckd_expenseamount",expenseamount);
  137. obj.put("nckd_exporiusedamount",exporiusedamount);
  138. obj.put("nckd_unexporiusedamount",orgiexpebalanceamount);
  139. obj.put("nckd_remark",remark);
  140. resdate.add(obj);
  141. }
  142. }
  143. String pageId = this.getView().getPageId();
  144. String listStr = SerializationUtils.toJsonString(resdate);
  145. this.getPageCache().put(pageId, listStr);
  146. }
  147. }