فهرست منبع

feat(swc): 新增社保核定单批量编辑和校验功能

Tyx 1 هفته پیش
والد
کامیت
296898898d

+ 16 - 0
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/sit/hcsi/business/coordination/api/SinsurCoordBizExtRegister.java

@@ -0,0 +1,16 @@
+package nckd.jxccl.sit.hcsi.business.coordination.api;
+
+import kd.hr.hbp.business.coordination.api.ext.CoordBizExtRegister;
+import kd.hr.hbp.business.coordination.model.CoordBizContext;
+
+/**
+ * Tyx 2025-10-28
+ * 社保档案注册器,注册在 薪资数据集成 -> 员工变动协作配置 -> 协作字段配置 -> 社保档案的bizextregister字段中
+ */
+public class SinsurCoordBizExtRegister implements CoordBizExtRegister {
+    @Override
+    public void registerHandler(CoordBizContext context) {
+        CoordBizExtRegister.super.registerHandler(context);
+        context.registerHandlers(CoordBizContext.CoordBizStage.AFTER_OPERATE, new SinsurCoordBizSaveHandler());
+    }
+}

+ 104 - 0
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/sit/hcsi/business/coordination/api/SinsurCoordBizSaveHandler.java

@@ -0,0 +1,104 @@
+package nckd.jxccl.sit.hcsi.business.coordination.api;
+
+import com.kingdee.util.Uuid;
+import kd.bos.dataentity.OperateOption;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.dataentity.utils.ObjectUtils;
+import kd.bos.entity.operate.result.OperationResult;
+import kd.bos.exception.KDBizException;
+import kd.bos.logging.Log;
+import kd.bos.logging.LogFactory;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import kd.hr.hbp.business.coordination.api.ext.CoordBizSaveHandler;
+import kd.hr.hbp.business.coordination.model.CoordBizContext;
+import kd.hr.hbp.business.servicehelper.HRBaseServiceHelper;
+import nckd.jxccl.sit.hcsi.business.importtaskguide.ImportTaskGuideImportService;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Tyx 2025-10-28
+ * 社保档案处理器,生成社保档案头之后,保存核定单分录的险种基数设置信息。
+ */
+public class SinsurCoordBizSaveHandler implements CoordBizSaveHandler {
+
+    private static final Log log = LogFactory.getLog(SinsurCoordBizSaveHandler.class);
+    private static HRBaseServiceHelper SIBASE_HELPER = new HRBaseServiceHelper("hcsi_sibase");
+    private static String SIBASE_ENTITY = "hcsi_sibase";
+    //字段对应的Map, k = 核定单分录字段标识, v = 社保档案险种基数设置字段标识
+    private static Map<String, String> fieldMap = new HashMap<String, String>();
+    static {
+        fieldMap.put("nckd_welfaretype","welfaretype");
+        fieldMap.put("nckd_insured","insured");
+        fieldMap.put("nckd_paybaseofemployee","paybaseofemployee");
+        fieldMap.put("nckd_paybaseofcompany","paybaseofcompany");
+        fieldMap.put("nckd_startdate","startdate");
+        fieldMap.put("nckd_enddate","enddate");
+        fieldMap.put("nckd_description","description");
+        fieldMap.put("nckd_sinsurdimension","nckd_sinsurdimension");
+    }
+
+    /**
+     * 实际处理方法
+     * @param map key = hcsi_sinsurfile, value = 社保档案Dyn
+     * @param map1 unknown
+     * @param dynamicObject 核定单Dyn
+     * @param coordBizContext 协作业务上下文
+     * @return
+     */
+    @Override
+    public Map<String, Object> handle(Map<String, DynamicObject> map, Map<String, Map<String, Object>> map1, DynamicObject dynamicObject, CoordBizContext coordBizContext) {
+        log.info(" -------- begin SinsurCoordBizSaveHandler handle --------");
+        // 返回的Map
+        Map<String, Object> returnMap = new HashMap<String, Object>();
+        DynamicObject sinsurFile = map.get("hcsi_sinsurfile");
+        if(!ObjectUtils.isEmpty(sinsurFile)) {
+            log.info("-------- 当前处理社保档案编号 = " + sinsurFile.getString("number"));
+            DynamicObjectCollection sibaseCols = new DynamicObjectCollection();
+            // 获取档案Id
+            Long fileId = sinsurFile.getLong("id");
+            // 获取核定单分录数据
+            DynamicObjectCollection entryCols = dynamicObject.getDynamicObjectCollection("nckd_entryentity");
+            for (DynamicObject entry : entryCols) {
+                // 新建数据包
+                DynamicObject dyn = BusinessDataServiceHelper.newDynamicObject(SIBASE_ENTITY);
+                // 设置字段,单独处理下档案,计薪人员,参保单位,其余字段从fieldMap从处理;
+                dyn.set("sinsurfile", sinsurFile);
+                dyn.set("employee", sinsurFile.getDynamicObject("employee"));
+                dyn.set("welfarepayer", sinsurFile.getDynamicObject("welfarepayer"));
+                dyn.set("id", Uuid.create());
+                Iterator it = fieldMap.keySet().iterator();
+                while(it.hasNext()) {
+                    String key = it.next().toString();
+                    dyn.set(fieldMap.get(key), entry.get(key));
+                }
+                sibaseCols.add(dyn);
+            }
+            OperationResult result = SaveServiceHelper.saveOperate(SIBASE_ENTITY, sibaseCols.stream().toArray(DynamicObject[]::new), OperateOption.create());
+            // 标品SinSurFileCoordServiceHelper.saveBizObject方法中,判断success写反了,这里暂时反着写,后续等标品调整
+            // TODO
+            if(result.isSuccess()) {
+                returnMap.put("success",false);
+            }
+            else {
+                throw new KDBizException("-------- 险种基数保存失败:" + result.getMessage());
+                //returnMap.put("success",true);
+                //returnMap.put("msg", result.getMessage());
+            }
+//            if(result.isSuccess()) {
+//                returnMap.put("success",true);
+//            }
+//            else {
+//                returnMap.put("success",false);
+//                returnMap.put("msg", result.getMessage());
+//            }
+            log.info("-------- bizSaveHandler result = " + result + " --------");
+        }
+        return returnMap;
+    }
+}

+ 218 - 0
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/sit/hcsi/formplugin/web/coordination/SinSurEmpChgCoordBatchEditPluginEx.java

@@ -0,0 +1,218 @@
+package nckd.jxccl.sit.hcsi.formplugin.web.coordination;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.dataentity.serialization.SerializationUtils;
+import kd.bos.db.DB;
+import kd.bos.entity.EntityMetadataCache;
+import kd.bos.entity.datamodel.IDataModel;
+import kd.bos.form.MessageBoxOptions;
+import kd.bos.form.control.EntryGrid;
+import kd.bos.form.events.AfterDoOperationEventArgs;
+import kd.bos.form.events.BeforeDoOperationEventArgs;
+import kd.bos.form.field.FieldEdit;
+import kd.bos.form.operate.AbstractOperate;
+import kd.bos.form.plugin.AbstractFormPlugin;
+import kd.bos.org.utils.DynamicObjectUtils;
+import kd.bos.orm.query.QFilter;
+import kd.hr.hbp.business.servicehelper.HRBaseServiceHelper;
+import kd.hr.hbp.common.util.HRStringUtils;
+import kd.sdk.plugin.Plugin;
+
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Tyx 2025-10-27
+ * 变动核定单表单插件扩展【nckd_hpdi_empcoordbat_ext】
+ */
+public class SinSurEmpChgCoordBatchEditPluginEx extends AbstractFormPlugin implements Plugin {
+
+    private static final HRBaseServiceHelper COORDBILL_HELPER = new HRBaseServiceHelper("hpdi_empcoordverifbill3");
+    private static final List<String> defaultQueryFields = (List) Stream.of("id", "employeev", "assignment", "coordruleparam").collect(Collectors.toList());
+    /**
+     * 在标品加载完数据之后,再获取一下核定单分录的数据展示出来
+     * @param e
+     */
+    @Override
+    public void afterBindData(EventObject e) {
+        super.afterBindData(e);
+        List<String> queryFields = this.getQueryFields();
+        HRBaseServiceHelper helper = new HRBaseServiceHelper(this.getEntityNumber());
+        DynamicObject[] billCols = helper.load(String.join(",", queryFields), new QFilter[]{new QFilter("id", "in", this.getSelectIds())});
+        showEntryData(billCols);
+    }
+
+    private void showEntryData(DynamicObject[] billCols) {
+        Set<String> entryFields = this.getEntryFields();
+        // 根据ID提取出来
+        Map<Long, DynamicObject> billMap = (Map) Arrays.stream(billCols).collect(Collectors.toMap((dyx) -> {
+            return dyx.getLong("id");
+        }, (dyx) -> {
+            return dyx;
+        }, (key1, key2) -> {
+            return key2;
+        }));
+        DynamicObjectCollection entryCols = this.getModel().getEntryEntity("entryentity");
+        for(DynamicObject entry : entryCols) {
+            Long billId = entry.getLong("id");
+            DynamicObject bill = billMap.get(billId);
+            DynamicObjectCollection billEntryCols = bill.getDynamicObjectCollection("nckd_entryentity");
+            DynamicObjectCollection subEntryCols = entry.getDynamicObjectCollection("nckd_subentryentity");
+            subEntryCols.clear();
+            for(DynamicObject billEntry : billEntryCols) {
+                DynamicObject subEntry = subEntryCols.addNew();
+                for(String field : entryFields) {
+                    subEntry.set(field, billEntry.get(field));
+                }
+            }
+        }
+        this.getView().updateView("nckd_subentryentity");
+    }
+
+
+
+
+    @Override
+    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
+        super.beforeDoOperation(args);
+        IDataModel model = this.getModel();
+        AbstractOperate op = (AbstractOperate)args.getSource();
+        String operateKey = op.getOperateKey();
+        // 批量设置前校验,查询当前选中的单据体的子单据体是否有数据
+        if(HRStringUtils.equals(operateKey, "batchsetting")){
+            int row = model.getEntryCurrentRowIndex("entryentity");
+            model.setEntryCurrentRowIndex("entryentity", row);
+            int rowCount = model.getEntryRowCount("nckd_subentryentity");
+            if(rowCount == 0) {
+                args.setCancel(true);
+                this.getView().showTipNotification("请先维护险种基数!");
+            }
+        }
+
+    }
+
+    @Override
+    public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
+        super.afterDoOperation(afterDoOperationEventArgs);
+        AbstractOperate op = (AbstractOperate)afterDoOperationEventArgs.getSource();
+        String operateKey = op.getOperateKey();
+        if (afterDoOperationEventArgs.getOperationResult().isSuccess() && (HRStringUtils.equals(operateKey, "save") || HRStringUtils.equals(operateKey, "confirmeffect"))) {
+            doSaveSubEntry();
+        }
+        else if(HRStringUtils.equals(operateKey, "batchsetting")){
+            doBatchSetting();
+        }
+    }
+
+    /**
+     * 批量设置其余子分录的险种信息
+     */
+    public void doBatchSetting() {
+        IDataModel model = this.getModel();
+        DynamicObject bill = model.getDataEntity(true);
+        DynamicObjectCollection entryCols = bill.getDynamicObjectCollection("entryentity");
+        // 当前选中行
+        int row = model.getEntryCurrentRowIndex("entryentity");
+        // 当前选中行的子单据体数据
+        DynamicObjectCollection subCols = entryCols.get(row).getDynamicObjectCollection("nckd_subentryentity");
+
+        for(int i = 0; i < entryCols.size(); i++) {
+            if(i == row)
+                continue;
+            // 获取本次要执行覆盖的子单据体
+            DynamicObjectCollection otherSubCols = entryCols.get(i).getDynamicObjectCollection("nckd_subentryentity");
+            // 清除数据
+            otherSubCols.clear();
+            // 从subCols copy 过来
+            for(DynamicObject subEntry : subCols) {
+                DynamicObject otherSubEntry = otherSubCols.addNew();
+                DynamicObjectUtils.copy(subEntry, otherSubEntry);
+            }
+        }
+        this.getView().updateView("nckd_subentryentity");
+    }
+
+    public void checkSubEntryData() {
+        IDataModel model = this.getModel();
+        DynamicObject dyn = model.getDataEntity(true);
+        DynamicObjectCollection entryCols = dyn.getDynamicObjectCollection("entryentity");
+    }
+
+    /**
+     * 执行保存,把当前页面的子单据体保存到核定单上;
+     */
+    public void doSaveSubEntry () {
+        DynamicObject bill = this.getModel().getDataEntity(true);
+        DynamicObjectCollection entryCols = bill.getDynamicObjectCollection("entryentity");
+        DynamicObjectCollection saveCols = new DynamicObjectCollection();
+        Set<String> subEntryFields = getEntryFields();
+        for (DynamicObject entry : entryCols) {
+            // 获取到核定单ID
+            Long coordBillId = entry.getLong("id");
+            // 获取到核定单Dyn
+            DynamicObject coordBill = COORDBILL_HELPER.loadOne(coordBillId);
+            // 获取当前页面子单据体的信息
+            DynamicObjectCollection subEntryCols = entry.getDynamicObjectCollection("nckd_subentryentity");
+            // 保存核定单的分录
+            DynamicObjectCollection coordBillEntryCols = coordBill.getDynamicObjectCollection("nckd_entryentity");
+            // 清空核定单的分录
+            coordBillEntryCols.clear();
+            // 根据当前页面子单据体信息->核定单分录数据
+            for (DynamicObject subEntry : subEntryCols) {
+                DynamicObject billEntry = coordBillEntryCols.addNew();
+                for(String field : subEntryFields) {
+                    billEntry.set(field, subEntry.get(field));
+                }
+            }
+            saveCols.add(coordBill);
+        }
+        if(saveCols.size() > 0) {
+            COORDBILL_HELPER.save(saveCols);
+        }
+    }
+
+    /**
+     * 获取子单据体字段
+     * @return
+     */
+    public Set<String> getEntryFields() {
+        Set<String> subEntryFields = EntityMetadataCache.getDataEntityType("hpdi_empcoordbatchedit3").getAllEntities().get("nckd_subentryentity").getFields().keySet();
+        return subEntryFields;
+    }
+
+    /**
+     * 获取核定单ID
+     * @return
+     */
+    protected List<Long> getSelectIds() {
+        String selectIdStr = (String)this.getView().getFormShowParameter().getCustomParam("selectIds");
+        return (List<Long>) SerializationUtils.fromJsonStringToList(selectIdStr, Long.class);
+    }
+
+    /**
+     * 获取实体标识
+     * @return
+     */
+    protected String getEntityNumber() {
+        return (String)this.getView().getFormShowParameter().getCustomParam("entityNumber");
+    }
+
+    /**
+     * 构建查询字段
+     * @return
+     */
+    protected List<String> getQueryFields() {
+        EntryGrid entryGrid = (EntryGrid)this.getView().getControl("entryentity");
+        List<FieldEdit> entryFields = entryGrid.getFieldEdits();
+        Set<String> queryFields = (Set)entryFields.stream().map(FieldEdit::getFieldKey).collect(Collectors.toSet());
+        queryFields.remove("adminorg");
+        queryFields.remove("position");
+        queryFields.addAll(defaultQueryFields);
+        Set<String> fields = this.getEntryFields();
+        queryFields.addAll(fields.stream().map(field -> "nckd_entryentity." + field).collect(Collectors.toList()));
+        return new ArrayList(queryFields);
+    }
+
+}

+ 27 - 0
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/sit/hcsi/opplugin/web/coordination/SinsurEmpConfirmOpEx.java

@@ -0,0 +1,27 @@
+package nckd.jxccl.sit.hcsi.opplugin.web.coordination;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.entity.plugin.AddValidatorsEventArgs;
+import kd.bos.entity.plugin.PreparePropertysEventArgs;
+import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
+import kd.hr.hbp.common.util.HRStringUtils;
+import kd.hr.hbp.opplugin.web.HRDataBaseOp;
+import nckd.jxccl.sit.hcsi.validate.web.SinsurEmpCoordBillValidator;
+
+/**
+ * Tyx 2025-10-28
+ * 社保核定单-确认生效扩展插件【nckd_hpdi_empcoordver_ext】
+ */
+public class SinsurEmpConfirmOpEx extends HRDataBaseOp {
+
+    @Override
+    public void onPreparePropertys(PreparePropertysEventArgs e) {
+        super.onPreparePropertys(e);
+    }
+
+    @Override
+    public void onAddValidators(AddValidatorsEventArgs e) {
+        super.onAddValidators(e);
+        e.addValidator(new SinsurEmpCoordBillValidator());
+    }
+}

+ 27 - 0
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/sit/hcsi/validate/web/SinsurEmpCoordBillValidator.java

@@ -0,0 +1,27 @@
+package nckd.jxccl.sit.hcsi.validate.web;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.entity.ExtendedDataEntity;
+import kd.bos.entity.validate.AbstractValidator;
+
+/**
+ * Tyx 2025-10-29
+ * 社保核定单校验器,弱校验
+ * 当存在单据体未维护子单据体的情况弹窗提示
+ */
+public class SinsurEmpCoordBillValidator extends AbstractValidator {
+
+    @Override
+    public void validate() {
+        String key = this.getOperateKey();
+        for (ExtendedDataEntity dataEntity : dataEntities) {
+            // TODO 个别类型的核定单不校验
+            DynamicObject bill = dataEntity.getDataEntity();
+            DynamicObjectCollection entryCols = bill.getDynamicObjectCollection("nckd_entryentity");
+            if(entryCols.size() == 0) {
+                this.addWarningMessage(dataEntity, "未维护险种基数信息");
+            }
+        }
+    }
+}