package fi.em.formPlugin; import com.aliyun.odps.security.User; 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.dataentity.entity.DynamicObject; import kd.bos.dataentity.serialization.SerializationUtils; import kd.bos.form.control.Control; import kd.bos.form.control.EntryGrid; 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.*; /** * @author cjz * @date 2024/7/25 15:13 * @description:报销单初始化表单 */ public class ReimbursementFormPlugin 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 = "nckd_entryentity";//动态表单单据体标识 private static String er_prepaybill = "er_prepaybill";//预付单标识 /** * 页面点击事件 * * @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 < selectRows.length; i++) { JSONObject reJo = infoJa.getJSONObject(selectRows[i]); reJa.add(reJo); } HashMap map = new HashMap<>(); map.put("reJaStr", reJa.toJSONString()); //将获取的json数据返回到界面view中 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); //获取父页面传入数据 Map customParams = this.getView().getFormShowParameter().getCustomParams(); String orgnumber = (String) customParams.get("orgnumber"); String orgid = (String) customParams.get("orgid"); String creatorNumber=(String) customParams.get("creatorNumber");//获取人员编码 String costdeptNumber=(String) customParams.get("costdeptNumber");//获取费用承担部门编码 if (orgnumber == null) { throw new KDBizException("付费承担公司为空!"); } List resdate = new ArrayList<>(); //历史数据清除 this.getModel().deleteEntryData(FORMID_ENTRY); //根据当前用户和费用承担部门过滤 QFilter nckd_orgamountFilter = new QFilter("costdept.number", QCP.equals, costdeptNumber); nckd_orgamountFilter.and("billstatus", QCP.equals, "E"); nckd_orgamountFilter.and("creator.number",QCP.equals,creatorNumber); DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper. load(er_prepaybill, "id,number", new QFilter[]{nckd_orgamountFilter}); for (int c=0;c