Browse Source

Merge remote-tracking branch 'origin/master'

Bohe5 3 weeks ago
parent
commit
d4fa07bebf

+ 148 - 0
base/nckd-base-common/src/main/java/nckd/base/common/utils/AdministrativeDivisionConverter.java

@@ -0,0 +1,148 @@
+package nckd.base.common.utils;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * 行政区划数据转换工具类
+ */
+public class AdministrativeDivisionConverter {
+
+    /**
+     * @param data 原始数据
+     * @return 胜意系统城市列表转树形结构
+     */
+    public static List<Map<String, Object>> convertToHierarchyOptimized(List<Map<String, Object>> data) {
+        if (data == null || data.isEmpty()) {
+            return new ArrayList<>();
+        }
+
+//        List<String> type3List = data.stream()
+//                .filter(it -> it.containsKey("type") && StringUtils.isNotEmpty(it.get("type").toString())
+//                        && it.get("type").toString().equals("3"))
+//                .map(it -> it.get("code").toString())
+//                .collect(Collectors.toList());
+
+        // 1. 创建所有节点索引
+        Map<String, Map<String, Object>> nodeMap = new HashMap<>();
+        List<Map<String, Object>> result = new ArrayList<>();
+
+        // 2. 第一遍:创建所有节点并建立索引
+        for (Map<String, Object> item : data) {
+            String code = (String) item.get("code");
+            String type = (String) item.get("type");
+
+            Map<String, Object> node = new LinkedHashMap<>();
+            node.put("code", code);
+            node.put("name", item.get("name"));
+            node.put("type", convertTypeCode(type));
+            node.put("children", new ArrayList<Map<String, Object>>());
+
+            nodeMap.put(code, node);
+
+            // 如果是省份或直辖市,直接添加到结果中
+            if ("2".equals(type) || "3".equals(type)) {
+                result.add(node);
+            }
+        }
+
+        // 3. 第二遍:建立父子关系
+        for (Map<String, Object> item : data) {
+            String code = (String) item.get("code");
+            String type = (String) item.get("type");
+//            //胜意数据传过来的直辖市层级:省、市、区。而我们直辖市层级:省、市
+//            if(type.equals("3")){
+//                continue;
+//            }
+            Map<String, Object> node = nodeMap.get(code);
+            if (node == null) {
+                continue;
+            }
+//            if (item.get("name").toString().contains("北京") || item.get("name").toString().contains("上海") ||
+//                    item.get("name").toString().contains("重庆") || item.get("name").toString().contains("江西")) {
+//                int i = 0;
+//            }
+            // 确定父节点
+            String parentCode = determineParentCode(item, type);
+            if (parentCode != null) {
+                Map<String, Object> parent = nodeMap.get(parentCode);
+                if (parent != null) {
+                    List<Map<String, Object>> children = (List<Map<String, Object>>) parent.get("children");
+                    children.add(node);
+                }
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 根据类型和关联关系确定父节点code
+     *
+     * @param item 行政区划数据项
+     * @param type 类型代码
+     * @return 父节点code,如果没有父节点返回null
+     */
+    private static String determineParentCode(Map<String, Object> item, String type) {
+        switch (type) {
+            case "1": // 国家,没有父节点
+                return null;
+            case "2": // 省份,父节点为国家
+                return (String) item.get("countryBelongCode");
+            case "3": // 直辖市,父节点为国家
+                return (String) item.get("provinceBelongCode");
+            case "4": // 省会城市
+            case "5": // 地级市
+                return (String) item.get("provinceBelongCode");
+            case "6": // 县级市
+                return (String) item.get("parentCityCode");
+            case "7": // 区
+                String cityBelongCode = (String) item.get("cityBelongCode");
+
+                //当前所属城市如果是直辖市则归属到省份
+//                if(type3List.contains(cityBelongCode)){
+//                    return (String) item.get("provinceBelongCode");
+//                }
+
+                if (cityBelongCode != null && !cityBelongCode.isEmpty()) {
+                    return cityBelongCode;
+                }
+                // 如果没有城市归属,则归属到省份
+                return (String) item.get("provinceBelongCode");
+            default:
+                return null;
+        }
+    }
+
+    /**
+     * 转换类型代码为可读的类型名称
+     *
+     * @param typeCode 类型代码
+     * @return 类型名称
+     */
+    private static String convertTypeCode(String typeCode) {
+        switch (typeCode) {
+            case "1":
+                return "country";
+            case "2":
+                return "province";
+            case "3":
+                return "municipality";
+            case "4":
+                return "capital_city";  // 省会城市
+            case "5":
+                return "prefecture_city";  // 地级市
+            case "6":
+                return "county_city";  // 县级市
+            case "7":
+                return "district";
+            default:
+                return "unknown";
+        }
+    }
+
+
+}

+ 142 - 0
base/nckd-base-common/src/main/java/nckd/base/common/utils/FormUtils.java

@@ -1,5 +1,6 @@
 package nckd.base.common.utils;
 
+import kd.bos.base.BaseShowParameter;
 import kd.bos.bill.BillShowParameter;
 import kd.bos.bill.OperationStatus;
 import kd.bos.dataentity.entity.DynamicObject;
@@ -20,7 +21,9 @@ import kd.bos.form.events.HyperLinkClickListener;
 import kd.bos.form.field.*;
 import kd.bos.form.field.events.BeforeF7SelectListener;
 import kd.bos.form.plugin.AbstractFormPlugin;
+import kd.bos.form.plugin.IFormPlugin;
 import kd.bos.list.BillList;
+import kd.bos.list.ListShowParameter;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import nckd.base.common.constant.BaseFieldConst;
@@ -430,4 +433,143 @@ public final class FormUtils {
         }
     }
 
+
+    /**
+     * 打开动态表单界面
+     *
+     * @param view
+     * @param entityName 动态表单标识
+     * @param value      传入动态表单界面的参数
+     */
+    public static void formShowParameter(IFormView view, String entityName, Map<String, Object> value,
+                                         IFormPlugin plugin, String actionId) {
+        formShowParameter(view, entityName, value, ShowType.Modal,plugin,actionId);
+    }
+
+    /**
+     * 打开动态表单界面
+     *
+     * @param view
+     * @param entityName 动态表单标识
+     * @param value      传入动态表单界面的参数
+     * @param ShowType   打开方式
+     */
+    public static void formShowParameter(IFormView view, String entityName, Map<String, Object> value, ShowType ShowType,
+                                         IFormPlugin plugin,String actionId) {
+        FormShowParameter showParameter = new FormShowParameter();
+        //动态表单标识
+        showParameter.setFormId(entityName);
+        //打开方式
+        showParameter.getOpenStyle().setShowType(ShowType);
+        //设置参数
+        showParameter.setCustomParams(value);
+        //关闭页面回调标识
+        showParameter.setCloseCallBack(new CloseCallBack(plugin,actionId));
+        view.showForm(showParameter);
+    }
+
+    /**
+     * 打开单据界面
+     * @param view
+     * @param entityName      单据标识
+     * @param pkId            单据id
+     * @param value           传入的参数
+     * @param operationStatus 页面状态
+     */
+    public static void billShowParameter(IFormView view, String entityName, Object pkId, Map<String, Object> value, OperationStatus operationStatus) {
+        billShowParameter(view, entityName, pkId, value, ShowType.Modal, operationStatus);
+    }
+
+    /**
+     * 打开单据界面
+     * @param view
+     * @param entityName      单据标识
+     * @param pkId            单据id
+     * @param value           传入的参数
+     * @param ShowType        打开方式
+     * @param operationStatus 页面状态
+     */
+    public static void billShowParameter(IFormView view, String entityName, Object pkId, Map<String, Object> value, ShowType ShowType, OperationStatus operationStatus) {
+        BillShowParameter showParameter = new BillShowParameter();
+        //id为空默认新增
+        showParameter.setStatus(ObjectUtils.isEmpty(pkId) ? OperationStatus.ADDNEW : operationStatus);
+        if(!ObjectUtils.isEmpty(pkId)){
+            //单据id
+            showParameter.setPkId(pkId);
+        }
+        //单据标识
+        showParameter.setFormId(entityName);
+        //打开方式
+        showParameter.getOpenStyle().setShowType(ShowType);
+        //设置参数
+        showParameter.setCustomParams(value);
+        view.showForm(showParameter);
+    }
+
+    /**
+     * 打开列表界面
+     * @param view
+     * @param entityName 单据标识
+     * @param qFilter    列表过滤条件
+     */
+    public static void listShowParameter(IFormView view, String entityName, QFilter qFilter) {
+        listShowParameter(view, entityName, ShowType.Modal, qFilter);
+    }
+
+    /**
+     * 打开列表界面
+     * @param view
+     * @param entityName 单据标识
+     * @param ShowType   打开方式
+     * @param qFilter    列表过滤条件
+     */
+    public static void listShowParameter(IFormView view, String entityName, ShowType ShowType, QFilter qFilter) {
+        ListShowParameter showParameter = new ListShowParameter();
+        //单据标识
+        showParameter.setBillFormId(entityName);
+        //列表的模板标识
+        showParameter.setFormId("bos_list");
+        //打开方式
+        showParameter.getOpenStyle().setShowType(ShowType);
+        //列表界面时过滤条件
+        showParameter.getListFilterParameter().getQFilters().add(qFilter);
+        view.showForm(showParameter);
+    }
+
+    /**
+     * 打开基础资料界面
+     * @param view
+     * @param entityName      单据标识
+     * @param pkId            单据id
+     * @param value           传入的参数
+     * @param operationStatus 页面状态
+     */
+    public static void baseShowParameter(IFormView view, String entityName, Object pkId, Map<String, Object> value, OperationStatus operationStatus) {
+        baseShowParameter(view, entityName, pkId, value, ShowType.Modal, operationStatus);
+    }
+
+    /**
+     * 打开基础资料界面
+     * @param view
+     * @param entityName      单据标识
+     * @param pkId            单据id
+     * @param value           传入的参数
+     * @param ShowType        打开方式
+     * @param operationStatus 页面状态
+     */
+    public static void baseShowParameter(IFormView view, String entityName, Object pkId, Map<String, Object> value, ShowType ShowType, OperationStatus operationStatus){
+        BaseShowParameter showParameter = new BaseShowParameter();
+        //id为空默认新增
+        showParameter.setStatus(ObjectUtils.isEmpty(pkId) ? OperationStatus.ADDNEW : operationStatus);
+        //单据id
+        showParameter.setPkId(ObjectUtils.isEmpty(pkId) ? 0l : pkId);
+        //单据标识
+        showParameter.setFormId(entityName);
+        //打开方式
+        showParameter.getOpenStyle().setShowType(ShowType);
+        //设置参数
+        showParameter.setCustomParams(value);
+        view.showForm(showParameter);
+    }
+
 }

+ 11 - 0
base/nckd-base-common/src/main/java/nckd/base/common/utils/OperationUtils.java

@@ -30,6 +30,17 @@ public class OperationUtils {
     private OperationUtils() {
     }
 
+    public static void operationDoAddNewSave(DynamicObject[] bills, String formBillId) {
+        DynamicObjectType type = EntityMetadataCache.getDataEntityType(formBillId);
+        OperationResult saveResult = OperationServiceHelper.executeOperate(
+                OperationKeyConst.SAVE,
+                formBillId,
+                bills,
+                OperateOption.create()
+        );
+        validateOperationResult(saveResult, String.format("新增【%s】失败:", type.getDisplayName().toString()));
+    }
+
     /**
      * 单据保存到审核
      * @param bills  单据对象

+ 53 - 0
nckd-fi/src/main/java/nckd/fi/er/formplugin/LoanCheckParamFormPlugin.java

@@ -0,0 +1,53 @@
+package nckd.fi.er.formplugin;
+
+import kd.bos.form.control.Control;
+import kd.bos.form.events.ClosedCallBackEvent;
+import kd.bos.form.plugin.AbstractFormPlugin;
+import nckd.base.common.utils.FormUtils;
+
+import java.util.EventObject;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @description:差旅参数平台
+ * @author: dingsixi
+ * @create: 2025/12/22 16:55
+ */
+public class LoanCheckParamFormPlugin extends AbstractFormPlugin {
+
+    /**资源信息*/
+    private static final String CONTROL_KEY_NCKD_RES = "nckd_res";
+
+    /**采集平台资源代号信息*/
+    private static final String FORM_ID_NCKD_EM_RESCODE = "nckd_em_rescode";
+
+
+    @Override
+    public void registerListener(EventObject e) {
+        super.registerListener(e);
+        this.addClickListeners(CONTROL_KEY_NCKD_RES);
+    }
+
+    @Override
+    public void click(EventObject evt) {
+        super.click(evt);
+        Control source = (Control) evt.getSource();
+        // 资源代号信息
+        if (CONTROL_KEY_NCKD_RES.equals(source.getKey())) {
+            // 显示采集平台资源代号信息
+            Map<String, Object> map = new HashMap<>();
+            map.put(CONTROL_KEY_NCKD_RES, this.getModel().getValue(CONTROL_KEY_NCKD_RES));
+            FormUtils.formShowParameter(this.getView(), FORM_ID_NCKD_EM_RESCODE, map, this, CONTROL_KEY_NCKD_RES);
+        }
+    }
+
+    @Override
+    public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
+        super.closedCallBack(closedCallBackEvent);
+        String actionId = closedCallBackEvent.getActionId();
+        if (CONTROL_KEY_NCKD_RES.equals(actionId) && null != closedCallBackEvent.getReturnData()) {
+            this.getModel().setValue(CONTROL_KEY_NCKD_RES, closedCallBackEvent.getReturnData());
+        }
+    }
+}

+ 97 - 0
nckd-fi/src/main/java/nckd/fi/er/formplugin/ResCodeFormPlugin.java

@@ -0,0 +1,97 @@
+package nckd.fi.er.formplugin;
+
+import com.alibaba.fastjson.JSONObject;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.entity.datamodel.IDataModel;
+import kd.bos.form.control.Control;
+import kd.bos.form.plugin.AbstractFormPlugin;
+import org.apache.commons.lang3.ObjectUtils;
+
+import java.util.*;
+
+/**
+ * @description:采集平台资源代号信息
+ * @author: dingsixi
+ * @create: 2025/12/22 16:35
+ */
+public class ResCodeFormPlugin extends AbstractFormPlugin {
+
+    // 确认按钮
+    private static final String CONTROL_KEY_NCKD_CONFIRM = "nckd_confirm";
+
+    // 自定义参数键常量
+    private static final String CUSTOM_PARAM_KEY_NCKD_RES = "nckd_res";
+
+    // 分录实体标识
+    private static final String ENTRY_ENTITY_KEY_NCKD_ENTRYENTITY = "nckd_entryentity";
+
+    // 字段名常量
+    private static final String FIELD_NCKD_TABLE = "nckd_table";
+    private static final String FIELD_NCKD_RESCAPTION = "nckd_rescaption";
+    private static final String FIELD_NCKD_RESCODE = "nckd_rescode";
+
+    @Override
+    public void registerListener(EventObject e) {
+        super.registerListener(e);
+        this.addClickListeners(CONTROL_KEY_NCKD_CONFIRM);
+    }
+
+    @Override
+    public void afterCreateNewData(EventObject e) {
+        super.afterCreateNewData(e);
+        setEntry();
+    }
+
+    @Override
+    public void click(EventObject evt) {
+        super.click(evt);
+        Control source = (Control) evt.getSource();
+        if (CONTROL_KEY_NCKD_CONFIRM.equals(source.getKey())) {
+            callParentEntry();
+        }
+    }
+
+    /**
+     * 将资源信息显示在单据体里面
+     */
+    private void setEntry() {
+        // 获取上级页面传递的资源信息
+        String resCode = this.getView().getFormShowParameter().getCustomParam(CUSTOM_PARAM_KEY_NCKD_RES);
+        if (ObjectUtils.isEmpty(resCode)) {
+            return;
+        }
+        List<Map<String, Object>> resCodeList = JSONObject.parseObject(resCode, List.class);
+        IDataModel model = this.getModel();
+        // 将资源信息显示在分录中
+        DynamicObjectCollection entryEntity = model.getEntryEntity(ENTRY_ENTITY_KEY_NCKD_ENTRYENTITY);
+        for (Map<String, Object> resCodeMap : resCodeList) {
+            DynamicObject entry = entryEntity.addNew();
+            entry.set(FIELD_NCKD_TABLE, resCodeMap.get(FIELD_NCKD_TABLE));
+            entry.set(FIELD_NCKD_RESCAPTION, resCodeMap.get(FIELD_NCKD_RESCAPTION));
+            entry.set(FIELD_NCKD_RESCODE, resCodeMap.get(FIELD_NCKD_RESCODE));
+        }
+    }
+
+    /**
+     * 将分录信息传递至上级页面
+     */
+    private void callParentEntry() {
+        DynamicObjectCollection entryEntity = this.getModel().getEntryEntity(ENTRY_ENTITY_KEY_NCKD_ENTRYENTITY);
+        if (entryEntity.isEmpty()) {
+            this.getView().returnDataToParent("");
+            this.getView().close();
+            return;
+        }
+        List<Map<String, Object>> resCodeList = new ArrayList<>();
+        for (DynamicObject entry : entryEntity) {
+            Map<String, Object> resCode = new HashMap<>();
+            resCode.put(FIELD_NCKD_TABLE, entry.getString(FIELD_NCKD_TABLE));
+            resCode.put(FIELD_NCKD_RESCAPTION, entry.getString(FIELD_NCKD_RESCAPTION));
+            resCode.put(FIELD_NCKD_RESCODE, entry.getString(FIELD_NCKD_RESCODE));
+            resCodeList.add(resCode);
+        }
+        this.getView().returnDataToParent(JSONObject.toJSONString(resCodeList));
+        this.getView().close();
+    }
+}