|
@@ -0,0 +1,185 @@
|
|
|
+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.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 AgentFormPlugin 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 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<selectRows.length;i++){
|
|
|
+ JSONObject reJo = infoJa.getJSONObject(selectRows[i]);
|
|
|
+ reJa.add(reJo);
|
|
|
+ }
|
|
|
+ HashMap<String, String> 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_typeagent");
|
|
|
+ //获取父页面传入数据
|
|
|
+ Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
|
|
|
+ String orgnumber = (String) customParams.get("orgnumber");
|
|
|
+ String orgid = (String) customParams.get("orgid");
|
|
|
+ if (orgnumber == null){
|
|
|
+ throw new KDBizException("付费承担公司为空!");
|
|
|
+ }
|
|
|
+ List<JSONObject> resdate = new ArrayList<>();
|
|
|
+ //历史数据清除
|
|
|
+ this.getModel().deleteEntryData(FORMID_ENTRY);
|
|
|
+ //构建查费用分摊动因参数基础资料参数
|
|
|
+ QFilter nckd_orgamountFilter = new QFilter("nckd_unappliedorg.number", QCP.equals,orgnumber);
|
|
|
+ nckd_orgamountFilter.and("status", QCP.equals,"C");
|
|
|
+ DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.load(nckd_agentparameter,"id,number",new QFilter[] {nckd_orgamountFilter});
|
|
|
+ for (int c=0;c<nckd_orgamountaccount.length;c++){
|
|
|
+ //当前循环动因基础资料单头
|
|
|
+ DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(nckd_orgamountaccount[c].getPkValue(), nckd_orgamountaccount[c].getDynamicObjectType().getName());
|
|
|
+ //获取动因类型
|
|
|
+ DynamicObject nckdTypeagent = dynamicObject.getDynamicObject("nckd_typeagent");
|
|
|
+ //循环分录
|
|
|
+ for (DynamicObject entryentity : dynamicObject.getDynamicObjectCollection("nckd_entryentity")) {
|
|
|
+ //获取分摊组织
|
|
|
+ DynamicObject nckdShareorg = entryentity.getDynamicObject("nckd_shareorg");
|
|
|
+ //获取动因值
|
|
|
+ BigDecimal nckdAgentvalue = entryentity.getBigDecimal("nckd_agentvalue");
|
|
|
+ //新增动态单据分录
|
|
|
+ int rowIndex = this.getModel().createNewEntryRow(FORMID_ENTRY);
|
|
|
+ //赋值给新增分录
|
|
|
+ this.getModel().setValue("nckd_shareorg", nckdShareorg, rowIndex);
|
|
|
+ this.getModel().setValue("nckd_agentvalue", nckdAgentvalue, rowIndex);
|
|
|
+ this.getModel().setValue("nckd_agenttype", nckdTypeagent, rowIndex);
|
|
|
+ //将选中的数据放到缓存中
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("nckd_shareorg",nckdShareorg.getString("number"));
|
|
|
+ obj.put("nckd_agentvalue",nckdAgentvalue);
|
|
|
+ resdate.add(obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String pageId = this.getView().getPageId();
|
|
|
+ String listStr = SerializationUtils.toJsonString(resdate);
|
|
|
+ this.getPageCache().put(pageId, listStr);
|
|
|
+// initTable(isInform,isForce,startDate,endDate,null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterDoOperation(AfterDoOperationEventArgs e) {
|
|
|
+ if (KEY_SEARCH.equals(e.getOperateKey())) {
|
|
|
+ DynamicObject period = (DynamicObject) this.getModel().getValue("nckd_typeagent");
|
|
|
+ //获取父页面传入数据
|
|
|
+ Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
|
|
|
+ String orgnumber = (String) customParams.get("orgnumber");
|
|
|
+ String orgid = (String) customParams.get("orgid");
|
|
|
+ if (orgnumber == null){
|
|
|
+ throw new KDBizException("付费承担公司为空!");
|
|
|
+ }
|
|
|
+ List<JSONObject> resdate = new ArrayList<>();
|
|
|
+ //历史数据清除
|
|
|
+ this.getModel().deleteEntryData(FORMID_ENTRY);
|
|
|
+ //查询动因参数基础资料
|
|
|
+ QFilter nckd_orgamountFilter = new QFilter("nckd_unappliedorg.number", QCP.equals,orgnumber);
|
|
|
+ if(period !=null){
|
|
|
+ period = BusinessDataServiceHelper.loadSingle(period.getPkValue(),period.getDynamicObjectType().getName());
|
|
|
+ String name = period.getString("name");
|
|
|
+ if(name!=null && !name.isEmpty()){
|
|
|
+ nckd_orgamountFilter.and("nckd_typeagent.name", QCP.equals,name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ nckd_orgamountFilter.and("status", QCP.equals,"C");
|
|
|
+ DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.load(nckd_agentparameter,"id,number",new QFilter[] {nckd_orgamountFilter});
|
|
|
+ //循环动因参数基础资料
|
|
|
+ for (int c=0;c<nckd_orgamountaccount.length;c++){
|
|
|
+ //当前行
|
|
|
+ DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(nckd_orgamountaccount[c].getPkValue(), nckd_orgamountaccount[c].getDynamicObjectType().getName());
|
|
|
+ //动因类型
|
|
|
+ DynamicObject nckdTypeagent = dynamicObject.getDynamicObject("nckd_typeagent");
|
|
|
+ //循环分录
|
|
|
+ for (DynamicObject entryentity : dynamicObject.getDynamicObjectCollection("nckd_entryentity")) {
|
|
|
+ //当前分录行分摊组织
|
|
|
+ DynamicObject nckdShareorg = entryentity.getDynamicObject("nckd_shareorg");
|
|
|
+ //当前分录行动因值
|
|
|
+ BigDecimal nckdAgentvalue = entryentity.getBigDecimal("nckd_agentvalue");
|
|
|
+ //新增动态单据分录行
|
|
|
+ int rowIndex = this.getModel().createNewEntryRow(FORMID_ENTRY);
|
|
|
+ //赋值给分录
|
|
|
+ this.getModel().setValue("nckd_shareorg", nckdShareorg, rowIndex);
|
|
|
+ this.getModel().setValue("nckd_agentvalue", nckdAgentvalue, rowIndex);
|
|
|
+ this.getModel().setValue("nckd_agenttype", nckdTypeagent, rowIndex);
|
|
|
+ //存放缓存
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("nckd_shareorg",nckdShareorg.getString("number"));
|
|
|
+ obj.put("nckd_agentvalue",nckdAgentvalue);
|
|
|
+ resdate.add(obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String pageId = this.getView().getPageId();
|
|
|
+ String listStr = SerializationUtils.toJsonString(resdate);
|
|
|
+ this.getPageCache().put(pageId, listStr);
|
|
|
+// initTable(isInform,isForce,startDate,endDate,null);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|