Pārlūkot izejas kodu

提货户头、价格系数,新增表单插件,处理分录条件公式

wanghaiwu 1 mēnesi atpakaļ
vecāks
revīzija
efc29a0099

+ 245 - 0
code/wnq/nckd-wnq01-wnq-scm/src/main/java/nckd/wnq01/wnq/scm/plugin/form/DeliverAccountEditPlugin.java

@@ -0,0 +1,245 @@
+package nckd.wnq01.wnq.scm.plugin.form;
+
+import kd.bos.dataentity.metadata.IDataEntityProperty;
+import kd.bos.dataentity.metadata.IDataEntityType;
+import kd.bos.dataentity.serialization.SerializationUtils;
+import kd.bos.dataentity.utils.StringUtils;
+import kd.bos.designer.botp.BillTreeBuildParameter;
+import kd.bos.designer.botp.EntityParseHelper;
+import kd.bos.entity.BillEntityType;
+import kd.bos.entity.EntityMetadataCache;
+import kd.bos.entity.botp.CRCondition;
+import kd.bos.entity.botp.WriteBackType;
+import kd.bos.entity.datamodel.IDataModel;
+import kd.bos.entity.datamodel.events.ChangeData;
+import kd.bos.entity.datamodel.events.PropertyChangedArgs;
+import kd.bos.entity.property.AttachmentProp;
+import kd.bos.entity.property.DecimalProp;
+import kd.bos.entity.property.MulBasedataProp;
+import kd.bos.entity.property.PictureProp;
+import kd.bos.entity.tree.TreeNode;
+import kd.bos.form.CloseCallBack;
+import kd.bos.form.FormShowParameter;
+import kd.bos.form.ShowType;
+import kd.bos.form.control.Control;
+import kd.bos.form.events.ClosedCallBackEvent;
+
+import java.util.EventObject;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * 单据实体:提货户头(nckd_thht)
+ * @author wanghaiwu_kd
+ * @date 2025/03/14
+ */
+public class DeliverAccountEditPlugin extends CommonHandleExpFormPlugin{
+    public void initialize() {
+        super.initialize();
+        addClickListeners(new String[]{"nckd_condition"});
+    }
+
+    /**
+     * 文本按钮点击事件
+     * @param evt
+     */
+    public void click(EventObject evt) {
+        Control ctl = (Control) evt.getSource();
+        // 表达式
+        if (ctl.getKey().equalsIgnoreCase("nckd_condition")) {
+            this.doClickWBItemCondition(ctl.getKey(),"nckd_entryentity", "nckd_ebillentity");
+        }
+    }
+
+    /**
+     * 构造打开页面参数
+     * 单据上配置需满足 :
+     * 文本按钮字段:nckd_xxx;
+     * 返回Json接收大文本字段 : nckd_xxxjson和nckd_xxxjson_tag
+     * @param key  文本按钮字段
+     * @param entryentity  分录实体名
+     * @param billFieldKey 单据实体下拉字段
+     */
+    private void doClickWBItemCondition(String key, String entryentity, String billFieldKey) {
+        BillEntityType mainType = this.getTargetMainType(entryentity, billFieldKey);
+        int row = this.getModel().getEntryCurrentRowIndex(entryentity);
+        String conditionJson = (String) this.getModel().getValue(key+"json_tag", row);
+        BillTreeBuildParameter parameter = new BillTreeBuildParameter(mainType);
+        parameter.getForbidRefPropFieldTypes().add(MulBasedataProp.class);
+        TreeNode billTreeNode = EntityParseHelper.buildBillTreeNodes(parameter);
+        String fldNodes = SerializationUtils.toJsonString(billTreeNode);
+        this.showConditionForm(conditionJson, mainType.getName(), fldNodes, key);
+
+    }
+
+    /**
+     * 获取单据元数据type
+     * @param entryentity
+     * @param billFieldKey
+     * @return
+     */
+    private BillEntityType getTargetMainType(String entryentity, String billFieldKey) {
+        int row = this.getModel().getEntryCurrentRowIndex(entryentity);
+        String entityNumber = this.getModel().getValue(billFieldKey, row).toString();
+        BillEntityType tgtMainType = (BillEntityType) EntityMetadataCache.getDataEntityType(entityNumber);
+        return tgtMainType;
+    }
+
+    /**
+     * 打开页面
+     * @param conditionJson
+     * @param entityNumber
+     * @param fieldNodes
+     * @param sourceCtrlKey
+     */
+    private void showConditionForm(String conditionJson, String entityNumber, String fieldNodes, String sourceCtrlKey) {
+        FormShowParameter showParameter = new FormShowParameter();
+        showParameter.setFormId("botp_condition");
+        showParameter.getCustomParams().put("formula", conditionJson);
+        showParameter.getCustomParams().put("entitynumber", entityNumber);
+        showParameter.getCustomParams().put("treenodes", fieldNodes);
+        showParameter.setCloseCallBack(new CloseCallBack(this, sourceCtrlKey));
+        showParameter.getOpenStyle().setShowType(ShowType.Modal);
+        this.getView().showForm(showParameter);
+    }
+
+    /**
+     * callback
+     * @param e
+     */
+    public void closedCallBack(ClosedCallBackEvent e) {
+        if (e.getActionId().equalsIgnoreCase("nckd_condition")) {
+            this.receiveCondition((String) e.getReturnData(), "nckd_entryentity", "nckd_conditionjson", "nckd_condition");
+        }
+    }
+
+    /**
+     * 处理子页面返回的信息,组装成json放在nckd_xxxjson_tag字段里面
+     * @param conditionJson
+     * @param entryEntityKey
+     * @param conditionFldKey
+     * @param descFldKey
+     */
+    private void receiveCondition(String conditionJson, String entryEntityKey, String conditionFldKey, String descFldKey) {
+        if (StringUtils.isNotBlank(conditionJson)) {
+            CRCondition condition = (CRCondition)SerializationUtils.fromJsonString(conditionJson, CRCondition.class);
+            String exprTran = condition.getExprDesc();
+            if (StringUtils.isBlank(entryEntityKey)) {
+                this.getModel().setValue(conditionFldKey, conditionJson);
+                this.getModel().setValue(descFldKey, exprTran);
+            } else {
+                int row = this.getModel().getEntryCurrentRowIndex(entryEntityKey);
+                this.getModel().setValue(conditionFldKey, "exists", row);
+                this.getModel().setValue(conditionFldKey+"_tag", conditionJson, row);
+                this.getModel().setValue(descFldKey, exprTran, row);
+            }
+        }
+    }
+
+    /**
+     * 值改变事件,单据实体下拉字段改变时候需清空条件字段
+     * @param e
+     */
+    @Override
+    public void propertyChanged(PropertyChangedArgs e) {
+        super.propertyChanged(e);
+        String key = e.getProperty().getName();
+        if(key.equalsIgnoreCase("nckd_entryentity")) {
+            doClearFieldValue("nckd_condition",  e.getChangeSet());
+        }
+    }
+
+    /**
+     * 清空字段具体实现方法
+     * @param key
+     * @param changeDatas
+     */
+    private void doClearFieldValue(String key, ChangeData[] changeDatas) {
+        for(int i = 0; i < changeDatas.length; ++i) {
+            ChangeData changeData = changeDatas[i];
+            this.getModel().setValue(key, (Object)null, changeData.getRowIndex());
+            this.getModel().setValue(key+"json", (Object)null, changeData.getRowIndex());
+            this.getModel().setValue(key+"json_tag", (Object)null, changeData.getRowIndex());
+        }
+    }
+
+    /**
+     * 单据字段点击入口事件
+     */
+    private void doClickCommitField(String key, String entryentity, String billFieldKey) {
+        BillEntityType sourceMainType = this.getTargetMainType(entryentity,billFieldKey);
+        int rowIndex = this.getModel().getEntryCurrentRowIndex(entryentity);
+        HashSet<String> selectEntitys = getSrcCommitEntity(this.getModel(), sourceMainType, true, rowIndex);
+        //if (WBRuleGetHelper.checkWritebackType(this.getView(), this.getModel())) {
+        //Class<?> fldType = getCommitFieldType(this.getModel());
+        Class<?> fldType = null;
+        BillTreeBuildParameter parameter = new BillTreeBuildParameter(sourceMainType, selectEntitys, fldType);
+        parameter.setForbidClassType(getForbidFieldTypes(this.getModel()));
+        parameter.getForbidRefPropFieldTypes().add(MulBasedataProp.class);
+        TreeNode srcBillNode = EntityParseHelper.buildBillTreeNodes(parameter);
+        this.showSelectFieldForm(srcBillNode, "wb_commitfieldname");
+        //}
+    }
+
+    private void showSelectFieldForm(TreeNode srcBillNode, String sourceCtrlKey) {
+        FormShowParameter showParameter = new FormShowParameter();
+        showParameter.setFormId("botp_selectfield");
+        String nodesJson = SerializationUtils.toJsonString(srcBillNode);
+        showParameter.getCustomParams().put("treenodes", nodesJson);
+        showParameter.setCloseCallBack(new CloseCallBack(this, sourceCtrlKey));
+        showParameter.getOpenStyle().setShowType(ShowType.Modal);
+        this.getView().showForm(showParameter);
+    }
+
+
+    public static HashSet<String> getSrcCommitEntity(IDataModel model, BillEntityType srcMainType, boolean includeParent, int expRowIndex) {
+        HashSet<String> entityKeys = new HashSet();
+        int rowCount = model.getEntryRowCount("entryentity");
+
+        for(int row = 0; row < rowCount; ++row) {
+            if (expRowIndex != row) {
+                String commitFldKey = (String)model.getValue("nckd_fieldkey", row);
+                if (!StringUtils.isBlank(commitFldKey)) {
+                    IDataEntityProperty property = srcMainType.findProperty(commitFldKey);
+                    if (property != null) {
+                        if (!entityKeys.contains(property.getParent().getName())) {
+                            entityKeys.add(property.getParent().getName());
+                        }
+
+                        if (includeParent) {
+                            for(IDataEntityType parent = property.getParent().getParent(); parent != null; parent = parent.getParent()) {
+                                if (!entityKeys.contains(parent.getName())) {
+                                    entityKeys.add(parent.getName());
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        return entityKeys;
+    }
+
+
+    public static Class<?> getCommitFieldType(IDataModel model) {
+        int row = model.getEntryCurrentRowIndex("entryentity");
+        String wbType = (String)model.getValue("wb_writebacktype", row);
+        WriteBackType type = WriteBackType.valueOf(Integer.parseInt(wbType));
+        Class<?> fldType = null;
+        if (type == WriteBackType.Cover) {
+            fldType = null;
+        } else {
+            fldType = DecimalProp.class;
+        }
+
+        return fldType;
+    }
+
+    public static Set<Class<?>> getForbidFieldTypes(IDataModel model) {
+        Set<Class<?>> types = new HashSet();
+        types.add(AttachmentProp.class);
+        types.add(PictureProp.class);
+        return types;
+    }
+}

+ 245 - 0
code/wnq/nckd-wnq01-wnq-scm/src/main/java/nckd/wnq01/wnq/scm/plugin/form/PriceRatioEditPlugin.java

@@ -0,0 +1,245 @@
+package nckd.wnq01.wnq.scm.plugin.form;
+
+import kd.bos.dataentity.metadata.IDataEntityProperty;
+import kd.bos.dataentity.metadata.IDataEntityType;
+import kd.bos.dataentity.serialization.SerializationUtils;
+import kd.bos.dataentity.utils.StringUtils;
+import kd.bos.designer.botp.BillTreeBuildParameter;
+import kd.bos.designer.botp.EntityParseHelper;
+import kd.bos.entity.BillEntityType;
+import kd.bos.entity.EntityMetadataCache;
+import kd.bos.entity.botp.CRCondition;
+import kd.bos.entity.botp.WriteBackType;
+import kd.bos.entity.datamodel.IDataModel;
+import kd.bos.entity.datamodel.events.ChangeData;
+import kd.bos.entity.datamodel.events.PropertyChangedArgs;
+import kd.bos.entity.property.AttachmentProp;
+import kd.bos.entity.property.DecimalProp;
+import kd.bos.entity.property.MulBasedataProp;
+import kd.bos.entity.property.PictureProp;
+import kd.bos.entity.tree.TreeNode;
+import kd.bos.form.CloseCallBack;
+import kd.bos.form.FormShowParameter;
+import kd.bos.form.ShowType;
+import kd.bos.form.control.Control;
+import kd.bos.form.events.ClosedCallBackEvent;
+
+import java.util.EventObject;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * 单据实体:价格系统(nckd_priceratio)
+ * @author wanghaiwu_kd
+ * @date 2025/03/14
+ */
+public class PriceRatioEditPlugin extends CommonHandleExpFormPlugin{
+    public void initialize() {
+        super.initialize();
+        addClickListeners(new String[]{"nckd_condition"});
+    }
+
+    /**
+     * 文本按钮点击事件
+     * @param evt
+     */
+    public void click(EventObject evt) {
+        Control ctl = (Control) evt.getSource();
+        // 表达式
+        if (ctl.getKey().equalsIgnoreCase("nckd_condition")) {
+            this.doClickWBItemCondition(ctl.getKey(),"nckd_entryentity", "nckd_ebillentity");
+        }
+    }
+
+    /**
+     * 构造打开页面参数
+     * 单据上配置需满足 :
+     * 文本按钮字段:nckd_xxx;
+     * 返回Json接收大文本字段 : nckd_xxxjson和nckd_xxxjson_tag
+     * @param key  文本按钮字段
+     * @param entryentity  分录实体名
+     * @param billFieldKey 单据实体下拉字段
+     */
+    private void doClickWBItemCondition(String key, String entryentity, String billFieldKey) {
+        BillEntityType mainType = this.getTargetMainType(entryentity, billFieldKey);
+        int row = this.getModel().getEntryCurrentRowIndex(entryentity);
+        String conditionJson = (String) this.getModel().getValue(key+"json_tag", row);
+        BillTreeBuildParameter parameter = new BillTreeBuildParameter(mainType);
+        parameter.getForbidRefPropFieldTypes().add(MulBasedataProp.class);
+        TreeNode billTreeNode = EntityParseHelper.buildBillTreeNodes(parameter);
+        String fldNodes = SerializationUtils.toJsonString(billTreeNode);
+        this.showConditionForm(conditionJson, mainType.getName(), fldNodes, key);
+
+    }
+
+    /**
+     * 获取单据元数据type
+     * @param entryentity
+     * @param billFieldKey
+     * @return
+     */
+    private BillEntityType getTargetMainType(String entryentity, String billFieldKey) {
+        int row = this.getModel().getEntryCurrentRowIndex(entryentity);
+        String entityNumber = this.getModel().getValue(billFieldKey, row).toString();
+        BillEntityType tgtMainType = (BillEntityType) EntityMetadataCache.getDataEntityType(entityNumber);
+        return tgtMainType;
+    }
+
+    /**
+     * 打开页面
+     * @param conditionJson
+     * @param entityNumber
+     * @param fieldNodes
+     * @param sourceCtrlKey
+     */
+    private void showConditionForm(String conditionJson, String entityNumber, String fieldNodes, String sourceCtrlKey) {
+        FormShowParameter showParameter = new FormShowParameter();
+        showParameter.setFormId("botp_condition");
+        showParameter.getCustomParams().put("formula", conditionJson);
+        showParameter.getCustomParams().put("entitynumber", entityNumber);
+        showParameter.getCustomParams().put("treenodes", fieldNodes);
+        showParameter.setCloseCallBack(new CloseCallBack(this, sourceCtrlKey));
+        showParameter.getOpenStyle().setShowType(ShowType.Modal);
+        this.getView().showForm(showParameter);
+    }
+
+    /**
+     * callback
+     * @param e
+     */
+    public void closedCallBack(ClosedCallBackEvent e) {
+        if (e.getActionId().equalsIgnoreCase("nckd_condition")) {
+            this.receiveCondition((String) e.getReturnData(), "nckd_entryentity", "nckd_conditionjson", "nckd_condition");
+        }
+    }
+
+    /**
+     * 处理子页面返回的信息,组装成json放在nckd_xxxjson_tag字段里面
+     * @param conditionJson
+     * @param entryEntityKey
+     * @param conditionFldKey
+     * @param descFldKey
+     */
+    private void receiveCondition(String conditionJson, String entryEntityKey, String conditionFldKey, String descFldKey) {
+        if (StringUtils.isNotBlank(conditionJson)) {
+            CRCondition condition = (CRCondition)SerializationUtils.fromJsonString(conditionJson, CRCondition.class);
+            String exprTran = condition.getExprDesc();
+            if (StringUtils.isBlank(entryEntityKey)) {
+                this.getModel().setValue(conditionFldKey, conditionJson);
+                this.getModel().setValue(descFldKey, exprTran);
+            } else {
+                int row = this.getModel().getEntryCurrentRowIndex(entryEntityKey);
+                this.getModel().setValue(conditionFldKey, "exists", row);
+                this.getModel().setValue(conditionFldKey+"_tag", conditionJson, row);
+                this.getModel().setValue(descFldKey, exprTran, row);
+            }
+        }
+    }
+
+    /**
+     * 值改变事件,单据实体下拉字段改变时候需清空条件字段
+     * @param e
+     */
+    @Override
+    public void propertyChanged(PropertyChangedArgs e) {
+        super.propertyChanged(e);
+        String key = e.getProperty().getName();
+        if(key.equalsIgnoreCase("nckd_entryentity")) {
+            doClearFieldValue("nckd_condition",  e.getChangeSet());
+        }
+    }
+
+    /**
+     * 清空字段具体实现方法
+     * @param key
+     * @param changeDatas
+     */
+    private void doClearFieldValue(String key, ChangeData[] changeDatas) {
+        for(int i = 0; i < changeDatas.length; ++i) {
+            ChangeData changeData = changeDatas[i];
+            this.getModel().setValue(key, (Object)null, changeData.getRowIndex());
+            this.getModel().setValue(key+"json", (Object)null, changeData.getRowIndex());
+            this.getModel().setValue(key+"json_tag", (Object)null, changeData.getRowIndex());
+        }
+    }
+
+    /**
+     * 单据字段点击入口事件
+     */
+    private void doClickCommitField(String key, String entryentity, String billFieldKey) {
+        BillEntityType sourceMainType = this.getTargetMainType(entryentity,billFieldKey);
+        int rowIndex = this.getModel().getEntryCurrentRowIndex(entryentity);
+        HashSet<String> selectEntitys = getSrcCommitEntity(this.getModel(), sourceMainType, true, rowIndex);
+        //if (WBRuleGetHelper.checkWritebackType(this.getView(), this.getModel())) {
+        //Class<?> fldType = getCommitFieldType(this.getModel());
+        Class<?> fldType = null;
+        BillTreeBuildParameter parameter = new BillTreeBuildParameter(sourceMainType, selectEntitys, fldType);
+        parameter.setForbidClassType(getForbidFieldTypes(this.getModel()));
+        parameter.getForbidRefPropFieldTypes().add(MulBasedataProp.class);
+        TreeNode srcBillNode = EntityParseHelper.buildBillTreeNodes(parameter);
+        this.showSelectFieldForm(srcBillNode, "wb_commitfieldname");
+        //}
+    }
+
+    private void showSelectFieldForm(TreeNode srcBillNode, String sourceCtrlKey) {
+        FormShowParameter showParameter = new FormShowParameter();
+        showParameter.setFormId("botp_selectfield");
+        String nodesJson = SerializationUtils.toJsonString(srcBillNode);
+        showParameter.getCustomParams().put("treenodes", nodesJson);
+        showParameter.setCloseCallBack(new CloseCallBack(this, sourceCtrlKey));
+        showParameter.getOpenStyle().setShowType(ShowType.Modal);
+        this.getView().showForm(showParameter);
+    }
+
+
+    public static HashSet<String> getSrcCommitEntity(IDataModel model, BillEntityType srcMainType, boolean includeParent, int expRowIndex) {
+        HashSet<String> entityKeys = new HashSet();
+        int rowCount = model.getEntryRowCount("entryentity");
+
+        for(int row = 0; row < rowCount; ++row) {
+            if (expRowIndex != row) {
+                String commitFldKey = (String)model.getValue("nckd_fieldkey", row);
+                if (!StringUtils.isBlank(commitFldKey)) {
+                    IDataEntityProperty property = srcMainType.findProperty(commitFldKey);
+                    if (property != null) {
+                        if (!entityKeys.contains(property.getParent().getName())) {
+                            entityKeys.add(property.getParent().getName());
+                        }
+
+                        if (includeParent) {
+                            for(IDataEntityType parent = property.getParent().getParent(); parent != null; parent = parent.getParent()) {
+                                if (!entityKeys.contains(parent.getName())) {
+                                    entityKeys.add(parent.getName());
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        return entityKeys;
+    }
+
+
+    public static Class<?> getCommitFieldType(IDataModel model) {
+        int row = model.getEntryCurrentRowIndex("entryentity");
+        String wbType = (String)model.getValue("wb_writebacktype", row);
+        WriteBackType type = WriteBackType.valueOf(Integer.parseInt(wbType));
+        Class<?> fldType = null;
+        if (type == WriteBackType.Cover) {
+            fldType = null;
+        } else {
+            fldType = DecimalProp.class;
+        }
+
+        return fldType;
+    }
+
+    public static Set<Class<?>> getForbidFieldTypes(IDataModel model) {
+        Set<Class<?>> types = new HashSet();
+        types.add(AttachmentProp.class);
+        types.add(PictureProp.class);
+        return types;
+    }
+}