PostModalFormPlugin.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package fi.em.FormPlugin;
  2. import kd.bos.exception.KDBizException;
  3. import kd.bos.form.plugin.AbstractFormPlugin;
  4. import kd.sdk.plugin.Plugin;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import kd.bos.context.RequestContext;
  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.form.events.AfterDoOperationEventArgs;
  13. import kd.bos.orm.query.QCP;
  14. import kd.bos.orm.query.QFilter;
  15. import kd.bos.servicehelper.BusinessDataServiceHelper;
  16. import org.apache.commons.lang3.StringUtils;
  17. import java.math.BigDecimal;
  18. import java.util.*;
  19. public class PostModalFormPlugin extends AbstractFormPlugin implements Plugin {
  20. private final static String KEY_OK = "btnok";
  21. //页面取消按钮标识
  22. private final static String KEY_CANCEL = "btncancel";
  23. //页面取消按钮标识
  24. private final static String KEY_SEARCH = "search";
  25. private final static String FORMID_ENTRY = "ztjg_entryentity";
  26. private final static String FORMID = "ztjg_postcertifynotice";
  27. private static String FORMID_USER = "bos_user";
  28. private static String nckd_agentparameter = "nckd_agentparameter";
  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. if (StringUtils.equals(source.getKey(), KEY_OK)) {
  41. String listStr = this.getPageCache().get(pageId);
  42. if (StringUtils.isNotBlank(listStr)){
  43. JSONArray reJa = new JSONArray();
  44. EntryGrid entryGrid = this.getView().getControl(FORMID_ENTRY);
  45. int[] selectRows = entryGrid.getSelectRows();
  46. if (selectRows.length<=0){
  47. this.getView().showMessage("请先选择一条数据!");
  48. return;
  49. }
  50. JSONArray infoJa = SerializationUtils.fromJsonString(listStr, JSONArray.class);
  51. for(int i=0;i<selectRows.length;i++){
  52. JSONObject reJo = infoJa.getJSONObject(selectRows[i]);
  53. reJa.add(reJo);
  54. }
  55. HashMap<String, String> map = new HashMap<>();
  56. map.put("reJaStr", reJa.toJSONString());
  57. this.getView().returnDataToParent(map);
  58. }
  59. this.getView().close();
  60. } else if (StringUtils.equals(source.getKey(), KEY_CANCEL)) {
  61. //被点击控件为取消则设置返回值为空并关闭页面(在页面关闭回调方法中必须验证返回值不为空,否则会报空指针)
  62. this.getView().returnDataToParent(null);
  63. this.getView().close();
  64. } else {
  65. this.getView().returnDataToParent(null);
  66. this.getView().close();
  67. }
  68. }
  69. @Override
  70. public void registerListener(EventObject e) {
  71. super.registerListener(e);
  72. //页面确认按钮和取消按钮添加监听
  73. this.addClickListeners(KEY_OK, KEY_CANCEL);
  74. }
  75. @Override
  76. public void afterCreateNewData(EventObject e) {
  77. super.afterBindData(e);
  78. DynamicObject period = (DynamicObject) this.getModel().getValue("nckd_agentparameter");
  79. //获取父页面传入数据
  80. Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
  81. String orgnumber = (String) customParams.get("orgnumber");
  82. if (orgnumber == null){
  83. throw new KDBizException("付费承担公司为空!");
  84. }
  85. QFilter nckd_orgamountFilter = new QFilter("nckd_unappliedorg.number", QCP.equals,orgnumber);
  86. if(period !=null){
  87. String nckd_sole = period.getString("nckd_sole");
  88. if(nckd_sole!=null && !nckd_sole.isEmpty()){
  89. nckd_orgamountFilter.and("nckd_typeagent.nckd_sole", QCP.equals,"A");
  90. }
  91. }
  92. nckd_orgamountFilter.and("enable", QCP.equals,"1");
  93. DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.load(nckd_agentparameter,"id",new QFilter[] {nckd_orgamountFilter});
  94. for (int c=0;c<nckd_orgamountaccount.length;c++){
  95. DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(nckd_orgamountaccount[c].getPkValue(), nckd_orgamountaccount[c].getDynamicObjectType().getName());
  96. for (DynamicObject entryentity : dynamicObject.getDynamicObjectCollection("nckd_sharemessage")) {
  97. DynamicObject nckdShareorg = entryentity.getDynamicObject("nckd_shareorg");
  98. BigDecimal nckdAgentvalue = entryentity.getBigDecimal("nckd_agentvalue");
  99. }
  100. }
  101. //initTable(isInform,isForce,startDate,endDate,null);
  102. }
  103. @Override
  104. public void afterDoOperation(AfterDoOperationEventArgs e) {
  105. if (KEY_SEARCH.equals(e.getOperateKey())) {
  106. Date startDate = (Date) this.getModel().getValue("ztjg_startdate");
  107. Date endDate = (Date) this.getModel().getValue("ztjg_enddate");
  108. Boolean isForce = (Boolean) this.getModel().getValue("ztjg_isforce");
  109. Boolean isInform = (Boolean) this.getModel().getValue("ztjg_isinform");
  110. String likeName = (String) this.getModel().getValue("ztjg_likename");
  111. if (isForce == null){
  112. isForce = false;
  113. }
  114. if (isInform == null){
  115. isInform = false;
  116. }
  117. if (startDate == null){
  118. this.getView().showMessage("请选择开始日期!");
  119. return;
  120. }else if (endDate == null){
  121. this.getView().showMessage("请选择结束日期!");
  122. return;
  123. }
  124. initTable(isInform,isForce,startDate,endDate,likeName);
  125. }
  126. }
  127. public void initTable(Boolean isInform,Boolean isForce,Date startdate,Date etartdate,String likeName){
  128. //历史数据清除
  129. this.getModel().deleteEntryData(FORMID_ENTRY);
  130. JSONArray reJa = getInitData(isInform,isForce,startdate,etartdate,likeName);
  131. for (int i=0;i<reJa.size();i++){
  132. JSONObject processJo = reJa.getJSONObject(i);
  133. int rowIndex = this.getModel().createNewEntryRow(FORMID_ENTRY);
  134. this.getModel().setValue("ztjg_id", processJo.getString("ztjg_id"), rowIndex);
  135. this.getModel().setValue("ztjg_noticeno", processJo.getString("ztjg_noticeno"), rowIndex);
  136. this.getModel().setValue("ztjg_noticedate", processJo.getDate("ztjg_noticedate"), rowIndex);
  137. this.getModel().setValue("ztjg_org", processJo.getObject("ztjg_org", DynamicObject.class), rowIndex);
  138. this.getModel().setValue("ztjg_dept", processJo.getObject("ztjg_dept",DynamicObject.class), rowIndex);
  139. this.getModel().setValue("ztjg_postname", processJo.getString("ztjg_postname"), rowIndex);
  140. this.getModel().setValue("ztjg_postdate", processJo.getDate("ztjg_postdate"), rowIndex);
  141. this.getModel().setValue("ztjg_address", processJo.getString("ztjg_address"), rowIndex);
  142. this.getModel().setValue("ztjg_postcontent", processJo.getString("ztjg_postcontent"), rowIndex);
  143. this.getModel().setValue("ztjg_demand", processJo.getString("ztjg_demand"), rowIndex);
  144. this.getModel().setValue("ztjg_mainnotice", processJo.getString("ztjg_mainnotice"), rowIndex);
  145. this.getModel().setValue("ztjg_integralitem", processJo.getObject("ztjg_integralitem",DynamicObject.class), rowIndex);
  146. this.getModel().setValue("ztjg_retakes", processJo.getBoolean("ztjg_retakes"), rowIndex);
  147. this.getModel().setValue("ztjg_datastr", processJo.getString("ztjg_datastr"), rowIndex);
  148. this.getModel().setValue("ztjg_customize1", processJo.getString("ztjg_customize1"), rowIndex);
  149. this.getModel().setValue("ztjg_customize2", processJo.getString("ztjg_customize2"), rowIndex);
  150. this.getModel().setValue("ztjg_customize3", processJo.getString("ztjg_customize3"), rowIndex);
  151. this.getModel().setValue("ztjg_postnamestr", processJo.getString("ztjg_postnamestr"), rowIndex);
  152. }
  153. String pageId = this.getView().getPageId();
  154. String listStr = SerializationUtils.toJsonString(reJa);
  155. this.getPageCache().put(pageId,listStr);
  156. }
  157. public static JSONArray getInitData(Boolean isInform,Boolean isForce, Date startdate,Date enddate,String likeName){
  158. JSONArray reJa = new JSONArray();
  159. DynamicObject userInfo = BusinessDataServiceHelper.loadSingle(RequestContext.get().getCurrUserId(),FORMID_USER);
  160. QFilter[] filters = null;
  161. QFilter personQFilter = null;
  162. QFilter statusQFilter = null;
  163. if (isForce){
  164. personQFilter = new QFilter("entryentity.ztjg_posteename.id", QCP.equals, userInfo.getPkValue());
  165. statusQFilter = new QFilter("entryentity.ztjg_ispushforce", QCP.equals, false);
  166. }else {
  167. personQFilter = new QFilter("ztjg_entryentity.ztjg_canposteename.id", QCP.equals, userInfo.getPkValue());
  168. statusQFilter = new QFilter("ztjg_entryentity.ztjg_ispushcan", QCP.equals, false);
  169. }
  170. QFilter qFilter1 = new QFilter("billstatus", QCP.equals, "C");
  171. QFilter qFilter2 = new QFilter("ztjg_bizdate", QCP.large_equals, startdate);
  172. QFilter qFilter3 = new QFilter("ztjg_bizdate", QCP.less_equals, enddate);
  173. QFilter qFilter4 = new QFilter("ztjg_postname", QCP.like, "%"+likeName+"%");
  174. if (!isInform){
  175. if (StringUtils.isNotBlank(likeName)){
  176. filters = new QFilter[]{personQFilter,statusQFilter,qFilter1,qFilter2,qFilter3,qFilter4};
  177. }else {
  178. filters = new QFilter[]{personQFilter,statusQFilter,qFilter1,qFilter2,qFilter3};
  179. }
  180. }
  181. DynamicObject[] conObjects = BusinessDataServiceHelper.load(FORMID,"id,billno,ztjg_bizdate,ztjg_org,ztjg_dept,ztjg_postname,ztjg_postdate,ztjg_address,ztjg_postcontent,ztjg_demand,ztjg_mainnotice,ztjg_integralitem,ztjg_retakes,ztjg_postnamestr,ztjg_datastr,ztjg_customize1,ztjg_customize2,ztjg_customize3",filters);
  182. for (DynamicObject obj:conObjects){
  183. JSONObject itemJo = new JSONObject();
  184. itemJo.put("ztjg_id",obj.getPkValue().toString());
  185. itemJo.put("ztjg_noticeno",obj.getString("billno"));
  186. itemJo.put("ztjg_noticedate",obj.getDate("ztjg_bizdate"));
  187. itemJo.put("ztjg_org",obj.getDynamicObject("ztjg_org"));
  188. itemJo.put("ztjg_dept",obj.getDynamicObject("ztjg_dept"));
  189. itemJo.put("ztjg_postname",obj.getString("ztjg_postname"));
  190. itemJo.put("ztjg_postdate",obj.getDate("ztjg_postdate"));
  191. itemJo.put("ztjg_address",obj.getString("ztjg_address"));
  192. itemJo.put("ztjg_postcontent",obj.getString("ztjg_postcontent"));
  193. itemJo.put("ztjg_demand",obj.getString("ztjg_demand"));
  194. itemJo.put("ztjg_mainnotice",obj.getString("ztjg_mainnotice"));
  195. itemJo.put("ztjg_integralitem",obj.getDynamicObject("ztjg_integralitem"));
  196. itemJo.put("ztjg_retakes",obj.getBoolean("ztjg_retakes"));
  197. itemJo.put("ztjg_postnamestr",obj.getString("ztjg_postnamestr"));
  198. itemJo.put("ztjg_datastr",obj.getString("ztjg_datastr"));
  199. itemJo.put("ztjg_customize1",obj.getString("ztjg_customize1"));
  200. itemJo.put("ztjg_customize2",obj.getString("ztjg_customize2"));
  201. itemJo.put("ztjg_customize3",obj.getString("ztjg_customize3"));
  202. reJa.add(itemJo);
  203. }
  204. return reJa;
  205. }
  206. }