package fi.em.FormPlugin; import kd.bos.exception.KDBizException; import kd.bos.form.plugin.AbstractFormPlugin; import kd.sdk.plugin.Plugin; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.serialization.SerializationUtils; import kd.bos.form.control.Control; import kd.bos.form.control.EntryGrid; import kd.bos.form.events.AfterDoOperationEventArgs; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import org.apache.commons.lang3.StringUtils; import java.math.BigDecimal; import java.util.*; public class PostModalFormPlugin extends AbstractFormPlugin implements Plugin { private final static String KEY_OK = "btnok"; //页面取消按钮标识 private final static String KEY_CANCEL = "btncancel"; //页面取消按钮标识 private final static String KEY_SEARCH = "search"; private final static String FORMID_ENTRY = "ztjg_entryentity"; private final static String FORMID = "ztjg_postcertifynotice"; private static String FORMID_USER = "bos_user"; private static String nckd_agentparameter = "nckd_agentparameter"; /** * 页面点击事件 * * @param evt */ @Override public void click(EventObject evt) { super.click(evt); //获取被点击的控件对象 Control source = (Control) evt.getSource(); String pageId = this.getView().getPageId(); if (StringUtils.equals(source.getKey(), KEY_OK)) { String listStr = this.getPageCache().get(pageId); if (StringUtils.isNotBlank(listStr)){ JSONArray reJa = new JSONArray(); EntryGrid entryGrid = this.getView().getControl(FORMID_ENTRY); int[] selectRows = entryGrid.getSelectRows(); if (selectRows.length<=0){ this.getView().showMessage("请先选择一条数据!"); return; } JSONArray infoJa = SerializationUtils.fromJsonString(listStr, JSONArray.class); for(int i=0;i map = new HashMap<>(); map.put("reJaStr", reJa.toJSONString()); this.getView().returnDataToParent(map); } this.getView().close(); } else if (StringUtils.equals(source.getKey(), KEY_CANCEL)) { //被点击控件为取消则设置返回值为空并关闭页面(在页面关闭回调方法中必须验证返回值不为空,否则会报空指针) this.getView().returnDataToParent(null); this.getView().close(); } else { this.getView().returnDataToParent(null); this.getView().close(); } } @Override public void registerListener(EventObject e) { super.registerListener(e); //页面确认按钮和取消按钮添加监听 this.addClickListeners(KEY_OK, KEY_CANCEL); } @Override public void afterCreateNewData(EventObject e) { super.afterBindData(e); DynamicObject period = (DynamicObject) this.getModel().getValue("nckd_agentparameter"); //获取父页面传入数据 Map customParams = this.getView().getFormShowParameter().getCustomParams(); String orgnumber = (String) customParams.get("orgnumber"); if (orgnumber == null){ throw new KDBizException("付费承担公司为空!"); } QFilter nckd_orgamountFilter = new QFilter("nckd_unappliedorg.number", QCP.equals,orgnumber); if(period !=null){ String nckd_sole = period.getString("nckd_sole"); if(nckd_sole!=null && !nckd_sole.isEmpty()){ nckd_orgamountFilter.and("nckd_typeagent.nckd_sole", QCP.equals,"A"); } } nckd_orgamountFilter.and("enable", QCP.equals,"1"); DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.load(nckd_agentparameter,"id",new QFilter[] {nckd_orgamountFilter}); for (int c=0;c