Browse Source

Merge remote-tracking branch 'origin/master'

sbtjtserver/gw-zhaojq01 10 hours ago
parent
commit
2f2a4b1a91

+ 5 - 0
nckd-fi/src/main/java/nckd/fi/er/common/constant/InttempConfigConstant.java

@@ -91,6 +91,11 @@ public class InttempConfigConstant {
      * 转换表达式
      */
     public static final String NCKD_BUSINESSEXPR = "nckd_businessexpr";
+    /**
+     * nckd_businessexprname
+     * 转换表达式
+     */
+    public static final String NCKD_BUSINESSEXPRNAME = "nckd_businessexprname";
     /**
      * nckd_masktype
      * 脱敏类型

+ 254 - 0
nckd-fi/src/main/java/nckd/fi/er/common/utils/ExpressionPopupUtil.java

@@ -0,0 +1,254 @@
+package nckd.fi.er.common.utils;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.serialization.SerializationUtils;
+import kd.bos.dataentity.utils.StringUtils;
+import kd.bos.form.CloseCallBack;
+import kd.bos.form.FormShowParameter;
+import kd.bos.form.ShowType;
+import kd.bos.form.events.ClosedCallBackEvent;
+import kd.bos.form.plugin.AbstractFormPlugin;
+import kd.bos.entity.datamodel.IDataModel;
+import nckd.base.common.constant.BaseFieldConst;
+import nckd.fi.er.common.constant.InttempConfigConstant;
+
+/**
+ * 通用表达式弹窗工具类
+ * @author: Custom
+ */
+public class ExpressionPopupUtil {
+    
+    /**
+     * 常量定义 - 严格参考凭证定义中的常量
+     */
+    public static class Constants {
+        // 表达式表单ID
+        public static final String FORMULA_FORM_ID = "ai_formula";
+        
+        // 参数名称
+        public static final String IS_EVENT = "isevent";
+        public static final String BILL_ENTITY_NUMBER = "billEntityNumber";
+        public static final String ENTITY_NUMBER = "entitynumber";
+        public static final String SOURCE_BILL = "sourcebill";
+        public static final String BUILD = "build";
+        public static final String SRC_MAIN_ENTITY_TYPE = "srcMainEntityType";
+        public static final String AI_BUTTON_KEY = "ai_button_key";
+        public static final String FORMULA = "formula";
+        public static final String AI_EXPRESSION = "ai_expression";
+        public static final String AI_VCH_TEMPLATE_CACHE_KEY = "ai_vchtemplatecachekey";
+        public static final String EVENT = "event";
+        public static final String BILL = "bill";
+        
+        // 引用字段编辑标识
+        public static final String REFERENCE_FIELD_EDIT = "referencefieldedit";
+    }
+    
+    private AbstractFormPlugin plugin;
+    
+    /**
+     * 构造方法
+     * @param plugin 表单插件实例,用于调用框架API
+     */
+    public ExpressionPopupUtil(AbstractFormPlugin plugin) {
+        this.plugin = plugin;
+    }
+    
+    /**
+     * 打开表达式弹窗 - 严格参考凭证定义中的showFormulaForm方法
+     * @param model 数据模型,用于获取和设置字段值
+     * @param fieldKey 字段标识
+     * @param sourceBill 来源单据对象
+     * @param entryEntityName 单据体名称(如果字段在单据体中,否则为null)
+     * @param currentRow 当前行索引(如果字段在单据体中,否则为-1)
+     */
+    public void showExpressionPopup(IDataModel model, String fieldKey, DynamicObject sourceBill,
+                                  String entryEntityName, int currentRow) {
+        // 校验来源单据是否为空
+        if (sourceBill == null) {
+            plugin.getView().showErrorNotification("请先选择来源单据!");
+            return;
+        }
+        
+        // 获取来源单据编码
+        String bizObjectNumber = sourceBill.getString(BaseFieldConst.NUMBER);
+        
+        // 获取当前字段的表达式值
+        String currentExpression = getCurrentExpression(model, fieldKey, entryEntityName, currentRow);
+        
+        // 创建表单显示参数
+        FormShowParameter showParam = new FormShowParameter();
+        
+        // 设置弹窗基础参数
+        showParam.setFormId(Constants.FORMULA_FORM_ID);
+        showParam.getOpenStyle().setShowType(ShowType.Modal);
+        showParam.setCloseCallBack(new CloseCallBack(plugin, fieldKey));
+        
+        // 严格按照参考代码设置自定义参数
+        showParam.setCustomParam(Constants.IS_EVENT, false);
+        showParam.setCustomParam(Constants.BILL_ENTITY_NUMBER, bizObjectNumber);
+        showParam.setCustomParam(Constants.ENTITY_NUMBER, bizObjectNumber);
+        showParam.setCustomParam(Constants.SOURCE_BILL, bizObjectNumber);
+        showParam.setCustomParam(Constants.BUILD, bizObjectNumber);
+        showParam.setCustomParam(Constants.SRC_MAIN_ENTITY_TYPE, Constants.REFERENCE_FIELD_EDIT);
+        
+        // 设置按钮标识
+        String buttonKey = Constants.AI_EXPRESSION + "-" + fieldKey;
+        showParam.setCustomParam(Constants.AI_BUTTON_KEY, buttonKey);
+        
+        // 按照参考代码构建表达式对象并序列化
+        VchTplExpression exprObj = new VchTplExpression();
+        exprObj.setExprType(ExpressionType.Formula);
+        exprObj.setExpression(currentExpression);
+        String formulaJson = SerializationUtils.toJsonString(exprObj);
+        showParam.getCustomParams().put(Constants.FORMULA, formulaJson);
+        
+        // 获取缓存信息(严格参考代码)
+        String cacheKey = Constants.AI_VCH_TEMPLATE_CACHE_KEY + "-" + currentRow;
+        String isEvent = plugin.getPageCache().get(Constants.EVENT);
+        
+        // 设置缓存参数
+        showParam.setCustomParam(Constants.AI_VCH_TEMPLATE_CACHE_KEY, plugin.getPageCache().get(cacheKey));
+        
+        // 打开弹窗
+        plugin.getView().showForm(showParam);
+    }
+
+    /**
+     * 处理表达式弹窗回调 - 严格参考凭证定义中的closedCallBack方法
+     * @param model 数据模型,用于设置字段值
+     * @param event 关闭回调事件
+     * @param entryEntityName 单据体名称(如果字段在单据体中,否则为null)
+     * @param currentRow 当前行索引(如果字段在单据体中,否则为-1)
+     */
+    public void handleExpressionCallback(IDataModel model, ClosedCallBackEvent event,
+                                         String entryEntityName, int currentRow) {
+        String actionId = event.getActionId();
+        Object returnData = event.getReturnData();
+
+        // 严格按照参考代码处理返回数据
+        if (returnData != null) {
+            String returnStr = returnData.toString();
+            if (StringUtils.isBlank(returnStr)) {
+                setFieldValue(model, InttempConfigConstant.NCKD_BUSINESSEXPR, "", entryEntityName, currentRow);
+                // 同时设置译文字段
+                setFieldValue(model,  InttempConfigConstant.NCKD_BUSINESSEXPRNAME, "", entryEntityName, currentRow);
+            } else {
+                try {
+                    // 使用系统提供的SerializationUtils解析外层数据
+                    VchReturnData retData = kd.bos.dataentity.serialization.SerializationUtils.fromJsonString(returnStr, VchReturnData.class);
+                    String dataStr = retData.getDataStr();
+
+                    if (StringUtils.isBlank(dataStr)) {
+                        setFieldValue(model,  InttempConfigConstant.NCKD_BUSINESSEXPR, "", entryEntityName, currentRow);
+                        setFieldValue(model,  InttempConfigConstant.NCKD_BUSINESSEXPRNAME, "", entryEntityName, currentRow);
+                        return;
+                    }
+
+                    // 解析内层表达式数据 - 现在会包含exprTran等字段
+                    VchTplExpression filterObj = kd.bos.dataentity.serialization.SerializationUtils.fromJsonString(dataStr, VchTplExpression.class);
+
+                    // 设置表达式字段值
+                    setFieldValue(model, InttempConfigConstant.NCKD_BUSINESSEXPR, filterObj.getExpression(), entryEntityName, currentRow);
+                    // 设置表达式译文字段值
+                    setFieldValue(model, InttempConfigConstant.NCKD_BUSINESSEXPRNAME, filterObj.getExprTran(), entryEntityName, currentRow);
+                } catch (Exception e) {
+                    plugin.getView().showErrorNotification("解析表达式返回数据失败:" + e.getMessage());
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+    
+    /**
+     * 获取当前字段的表达式值
+     * @param model 数据模型
+     * @param fieldKey 字段标识
+     * @param entryEntityName 单据体名称
+     * @param currentRow 当前行索引
+     * @return 当前表达式值
+     */
+    private String getCurrentExpression(IDataModel model, String fieldKey,
+                                      String entryEntityName, int currentRow) {
+        if (StringUtils.isNotBlank(entryEntityName) && currentRow >= 0) {
+            // 单据体字段
+            Object value = model.getValue(fieldKey, currentRow);
+            return value != null ? value.toString() : "";
+        } else {
+            // 表头字段
+            Object value = model.getValue(fieldKey);
+            return value != null ? value.toString() : "";
+        }
+    }
+    
+    /**
+     * 设置字段值
+     * @param model 数据模型
+     * @param fieldKey 字段标识
+     * @param value 字段值
+     * @param entryEntityName 单据体名称
+     * @param currentRow 当前行索引
+     */
+    private void setFieldValue(IDataModel model, String fieldKey, Object value, 
+                             String entryEntityName, int currentRow) {
+        if (StringUtils.isNotBlank(entryEntityName) && currentRow >= 0) {
+            // 单据体字段
+            model.setValue(fieldKey, value, currentRow);
+        } else {
+            // 表头字段
+            model.setValue(fieldKey, value);
+        }
+    }
+    
+    // ==================== 内部类定义 - 严格参考凭证定义中的相关类 ====================
+    
+    /**
+     * 表达式类型枚举 - 严格参考凭证定义
+     */
+    public enum ExpressionType {
+        Formula, Condition
+    }
+
+    /**
+     * VchTplExpression类 - 严格参考凭证定义
+     */
+    public static class VchTplExpression {
+        private ExpressionType exprType;
+        private String expression;
+        private String exprTran;  // 添加表达式译文字段
+        private Object description;  // 描述字段
+        private Object localeExprTran;  // 本地化表达式译文
+        private String exprDesc;  // 表达式描述
+
+        // getter and setter methods
+        public ExpressionType getExprType() { return exprType; }
+        public void setExprType(ExpressionType exprType) { this.exprType = exprType; }
+        public String getExpression() { return expression; }
+        public void setExpression(String expression) { this.expression = expression; }
+        public String getExprTran() { return exprTran; }  // 添加getter
+        public void setExprTran(String exprTran) { this.exprTran = exprTran; }  // 添加setter
+        public Object getDescription() { return description; }
+        public void setDescription(Object description) { this.description = description; }
+        public Object getLocaleExprTran() { return localeExprTran; }
+        public void setLocaleExprTran(Object localeExprTran) { this.localeExprTran = localeExprTran; }
+        public String getExprDesc() { return exprDesc; }
+        public void setExprDesc(String exprDesc) { this.exprDesc = exprDesc; }
+    }
+    
+    /**
+     * VchReturnData类 - 严格参考凭证定义
+     */
+    public static class VchReturnData {
+        private String dataStr;
+        private String formId;
+        private String entryName;
+        
+        // getter and setter methods
+        public String getDataStr() { return dataStr; }
+        public void setDataStr(String dataStr) { this.dataStr = dataStr; }
+        public String getFormId() { return formId; }
+        public void setFormId(String formId) { this.formId = formId; }
+        public String getEntryName() { return entryName; }
+        public void setEntryName(String entryName) { this.entryName = entryName; }
+    }
+
+}

+ 60 - 3
nckd-fi/src/main/java/nckd/fi/er/formplugin/InttempConfigFromPlugin.java

@@ -12,6 +12,7 @@ import kd.bos.form.events.ClosedCallBackEvent;
 import kd.bos.form.plugin.AbstractFormPlugin;
 import nckd.base.common.constant.BaseFieldConst;
 import nckd.fi.er.common.constant.InttempConfigConstant;
+import nckd.fi.er.common.utils.ExpressionPopupUtil;
 
 import java.util.EventObject;
 import java.util.Map;
@@ -21,11 +22,20 @@ import java.util.Map;
  * @author: Yanglp
  */
 public class InttempConfigFromPlugin  extends AbstractFormPlugin {
+    // 表达式弹窗工具类实例
+    private ExpressionPopupUtil expressionPopupUtil;
 
     @Override
     public void registerListener(EventObject e) {
         super.registerListener(e);
-        this.addClickListeners(InttempConfigConstant.NCKD_QFILTER);
+        this.addClickListeners(InttempConfigConstant.NCKD_QFILTER,InttempConfigConstant.NCKD_BUSINESSEXPRNAME);
+    }
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        // 初始化表达式弹窗工具类
+        expressionPopupUtil = new ExpressionPopupUtil(this);
     }
 
     @Override
@@ -34,9 +44,8 @@ public class InttempConfigFromPlugin  extends AbstractFormPlugin {
         Control source = (Control) args.getSource();
         String key = source.getKey();
         // IPageCache pageCache = this.getPageCache();
+        IDataModel model = this.getModel();
         if ("nckd_qfilter".equals(key)) {
-            IDataModel model = this.getModel();
-
             //通用过滤条件
             String qFilter = (String) model.getValue("nckd_qfilter");
             //业务对象编码
@@ -48,6 +57,35 @@ public class InttempConfigFromPlugin  extends AbstractFormPlugin {
             String bizObjectNumber = entity.getString(BaseFieldConst.NUMBER);
             //显示通用过滤动态表单
             showFilterGrid(bizObjectNumber, qFilter);
+        } else if (InttempConfigConstant.NCKD_BUSINESSEXPRNAME.equals(key)) {
+            if(model.getValue(InttempConfigConstant.NCKD_BUSINESSEXPRNAME).toString().isEmpty()){
+                this.getModel().beginInit();
+                model.setValue(InttempConfigConstant.NCKD_BUSINESSEXPR, null);
+                this.getModel().endInit();
+            }
+            //业务对象编码
+            DynamicObject entity = (DynamicObject) model.getValue(InttempConfigConstant.NCKD_ENTITYOBJECT);
+            if (entity == null) {
+                this.getView().showErrorNotification("请选择关联业务对象!");
+                return;
+            }
+
+            // 获取当前行索引(因为表达式字段在单据体中)
+            int currentRow = model.getEntryCurrentRowIndex(InttempConfigConstant.NCKD_ENTRYENTITY);
+
+            // 使用表达式弹窗工具类打开弹窗
+            expressionPopupUtil.showExpressionPopup(
+                    // 数据模型
+                    model,
+                    // 字段标识
+                    InttempConfigConstant.NCKD_BUSINESSEXPR,
+                    // 来源单据
+                    entity,
+                    // 单据体名称
+                    InttempConfigConstant.NCKD_ENTRYENTITY,
+                    // 当前行索引
+                    currentRow
+            );
         }
     }
 
@@ -69,6 +107,7 @@ public class InttempConfigFromPlugin  extends AbstractFormPlugin {
     @Override
     public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
         Object returnData = closedCallBackEvent.getReturnData();
+        String actionId = closedCallBackEvent.getActionId();
         if (StringUtils.equals(closedCallBackEvent.getActionId(),InttempConfigConstant.NCKD_QFILTER )&& null != returnData){
             IDataModel model = this.getModel();
             Map<String, Object> filterMap = (Map<String, Object>) returnData;
@@ -81,6 +120,24 @@ public class InttempConfigFromPlugin  extends AbstractFormPlugin {
                 model.setValue(InttempConfigConstant.NCKD_FILTERCONDITION, filterMap.get(InttempConfigConstant.NCKD_FILTERCONDITION));
                 model.setValue(InttempConfigConstant.NCKD_FIELDNAME, filterMap.get(InttempConfigConstant.NCKD_FIELDNAME));
             }
+        } else if ((StringUtils.equals(actionId, InttempConfigConstant.NCKD_BUSINESSEXPR)
+                || StringUtils.equals(actionId, InttempConfigConstant.NCKD_BUSINESSEXPRNAME))) {
+            // 处理表达式弹窗回调
+            IDataModel model = this.getModel();
+            // 获取当前行索引
+            int currentRow = model.getEntryCurrentRowIndex(InttempConfigConstant.NCKD_ENTRYENTITY);
+
+            // 使用表达式弹窗工具类处理回调
+            expressionPopupUtil.handleExpressionCallback(
+                    // 数据模型
+                    model,
+                    // 回调事件
+                    closedCallBackEvent,
+                    // 单据体名称
+                    InttempConfigConstant.NCKD_ENTRYENTITY,
+                    // 当前行索引
+                    currentRow
+            );
         }
     }
 }