Sfoglia il codice sorgente

feat(hr): 新增管理人员任命调动后处理逻辑

- 在FormConstant中新增调动相关字段常量定义
- 修改MgrAppointMgmtListPlugin插件,使用枚举值替换硬编码过滤条件
- 新增MgrAppointMgmtTransferAfterEffectOp操作插件,处理调动生效后的任命逻辑
- 调整NewAppointMentOpPlugin查询条件,增加类型状态过滤
- 优化SubCoHeadServiceListPlugin和TenurePersonListListPlugin中的日期比较字段
wyc 1 settimana fa
parent
commit
e4d39a9cce

+ 8 - 0
code/base/nckd-jxccl-base-common/src/main/java/nckd/jxccl/base/common/constant/FormConstant.java

@@ -330,6 +330,14 @@ public class FormConstant {
     public static final String POST_PERF_WAGE_SYS = "001";
     /**薪酬标准方案*/
     public static final String NCKD_PAYSTDPLAN = "nckd_paystdplan";
+    /**调出岗位*/
+    public static final String BB_PO_POSITION = "bb_po_position";
+    /**调入岗位*/
+    public static final String APOSITION = "aposition";
+    /**待调动人员*/
+    public static final String BB_EM_TID = "bb_em_tid";
+    /**实际调动日期*/
+    public static final String B_EFFECTIVEDATE = "b_effectivedate";
 
 
 

+ 2 - 1
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/plugin/form/other/MgrAppointMgmtListPlugin.java

@@ -12,6 +12,7 @@ import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import kd.sdk.plugin.Plugin;
 import nckd.jxccl.base.common.constant.FormConstant;
+import nckd.jxccl.base.common.enums.psms.TypeStateEnum;
 import nckd.jxccl.hr.psms.common.PositionStructureConstant;
 import org.apache.commons.lang3.StringUtils;
 
@@ -27,7 +28,7 @@ public class MgrAppointMgmtListPlugin extends AbstractListPlugin implements Plug
     @Override
     public void setFilter(SetFilterEvent e) {
         //只查询类型状态
-        QFilter filter = new QFilter(PositionStructureConstant.NCKD_TYPESTATE, QCP.equals, "5");
+        QFilter filter = new QFilter(PositionStructureConstant.NCKD_TYPESTATE, QCP.equals, TypeStateEnum.MANAGEMENT_SEQUENCE_EMPLOYMENT.getCode());
         e.addCustomQFilter(filter);
     }
 

+ 181 - 0
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/plugin/operate/other/MgrAppointMgmtTransferAfterEffectOp.java

@@ -0,0 +1,181 @@
+package nckd.jxccl.hr.psms.plugin.operate.other;
+
+import kd.bos.dataentity.OperateOption;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.entity.EntityMetadataCache;
+import kd.bos.entity.MainEntityType;
+import kd.bos.entity.operate.result.OperationResult;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.PreparePropertysEventArgs;
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
+import kd.bos.logging.Log;
+import kd.bos.logging.LogFactory;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.QueryServiceHelper;
+import kd.bos.servicehelper.operation.OperationServiceHelper;
+import kd.sdk.plugin.Plugin;
+import nckd.jxccl.base.common.constant.FormConstant;
+import nckd.jxccl.base.common.enums.psms.JobSeqEnum;
+import nckd.jxccl.base.common.enums.psms.TypeStateEnum;
+import nckd.jxccl.base.common.utils.DateUtil;
+import nckd.jxccl.base.common.utils.QueryFieldBuilder;
+import nckd.jxccl.base.common.utils.StrFormatter;
+import nckd.jxccl.base.entity.helper.EntityHelper;
+import nckd.jxccl.hr.psms.common.PositionStructureConstant;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+* 事务变动生效后调动事件订阅操作插件-管理人员任命
+* 实体标识:nckd_mgrappointmgmt
+* @author W.Y.C
+* @date 2025/12/5 10:44
+* @version 1.0
+*/
+public class MgrAppointMgmtTransferAfterEffectOp extends AbstractOperationServicePlugIn implements Plugin {
+
+
+    private static final Log log = LogFactory.getLog(MgrAppointMgmtTransferAfterEffectOp.class);
+
+    @Override
+    public void onPreparePropertys(PreparePropertysEventArgs e) {
+        e.getFieldKeys().addAll(this.billEntityType.getAllFields().keySet());
+    }
+
+    @Override
+    public void beginOperationTransaction(BeginOperationTransactionArgs e) {
+        List<Long> personIdList = new ArrayList<>();
+        for (DynamicObject dataEntity : e.getDataEntities()) {
+            DynamicObject employee = dataEntity.getDynamicObject(FormConstant.BB_EM_TID);
+            if(employee != null){
+                personIdList.add(employee.getLong(FormConstant.ID_KEY));
+            }
+        }
+        //查询管理人员任命
+        QueryFieldBuilder queryFieldBuilder = QueryFieldBuilder.create()
+                .add(FormConstant.ID_KEY);
+        QFilter qFilter = new QFilter(PositionStructureConstant.NCKD_PERSON, QCP.in, personIdList);
+        qFilter.and(PositionStructureConstant.NCKD_TYPESTATE, QCP.equals, TypeStateEnum.MANAGEMENT_SEQUENCE_EMPLOYMENT.getCode());
+        DynamicObjectCollection query = QueryServiceHelper.query(PositionStructureConstant.NCKD_PERSONPOSFILE, queryFieldBuilder.buildSelect(), new QFilter[]{});
+        List<Long> ids = query.stream()
+                .map(obj -> obj.getLong(FormConstant.ID_KEY))
+                .collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
+        MainEntityType entityType = EntityMetadataCache.getDataEntityType(PositionStructureConstant.NCKD_PERSONPOSFILE);
+        DynamicObject[] load = BusinessDataServiceHelper.load(ids.toArray(new Long[0]), entityType);
+        // 按人员分组,Map<人员ID, List<职位档案>>
+        Map<Long, List<DynamicObject>> personPosFileMap = query.stream()
+                .collect(Collectors.groupingBy(
+                        obj -> obj.getLong(String.join(".", FormConstant.NCKD_PERSON, FormConstant.ID_KEY))
+                ));
+
+        List<DynamicObject> saveMgrAppointMgmt = new ArrayList<>();
+        for (DynamicObject dataEntity : e.getDataEntities()) {
+            //人员
+            DynamicObject employee = dataEntity.getDynamicObject(FormConstant.BB_EM_TID);
+            long empId = dataEntity.getLong(String.join(".", FormConstant.BB_EM_TID, FormConstant.ID_KEY));
+            //调出岗位
+            DynamicObject beforePosition = dataEntity.getDynamicObject(FormConstant.BB_PO_POSITION);
+            //调出前职位序列
+            DynamicObject beforeJobSeq = beforePosition.getDynamicObject(FormConstant.NCKD_JOBSEQ);
+            //调入岗位
+            DynamicObject afterPosition = dataEntity.getDynamicObject(FormConstant.APOSITION);
+            //调入岗位
+            DynamicObject afterJobSeq = afterPosition.getDynamicObject(FormConstant.NCKD_JOBSEQ);
+            String afterJobSeqNumber = afterJobSeq.getString(FormConstant.NUMBER_KEY);
+            //调动生效日期
+            Date effectiveDate = dataEntity.getDate(FormConstant.B_EFFECTIVEDATE);
+
+            List<DynamicObject> personPosFile = personPosFileMap.get(empId);
+
+            if(JobSeqEnum.MANAGE.getCode().equalsIgnoreCase(afterJobSeqNumber)){
+                //调入后岗位是管理序列
+                //判断有没有在任命的记录,没有则新增。如果有判断状态是不是等于0(已终止),如果是则新增
+                boolean needCreateNew = false;
+                Date latestEndDate = null;
+                if(personPosFile == null || personPosFile.isEmpty()){
+                    // 没有任命记录
+                    needCreateNew = true;
+                }else{
+                    // 检查所有记录的状态是否都为已终止(0)
+                    boolean allTerminated = true;
+
+                    for(DynamicObject record : personPosFile){
+                        String appointStatus = record.getString(PositionStructureConstant.NCKD_APPOINTSTATUS);
+                        if(!"0".equals(appointStatus)){
+                            allTerminated = false;
+                            break;
+                        }
+                        // 获取记录的终止时间,找到最近的一次
+                        Date endDate = record.getDate(PositionStructureConstant.NCKD_ENDDATE);
+                        if (endDate != null) {
+                            if (latestEndDate == null || endDate.after(latestEndDate)) {
+                                latestEndDate = endDate;
+                            }
+                        }
+                    }
+                    // 所有记录都是已终止状态
+                    if(allTerminated){
+                        needCreateNew = true;
+                    }
+                    // 如果需要使用latestEndDate,可以在这里添加相关逻辑
+                    // 例如:可以在新增记录时将此日期作为参考
+                }
+                if(needCreateNew){
+                    DynamicObject newEntity = EntityHelper.newEntity(PositionStructureConstant.NCKD_PERSONPOSFILE);
+                    newEntity.set(FormConstant.NCKD_PERSON, employee);
+                    Date beginDate;
+                    if (latestEndDate != null && latestEndDate.after(effectiveDate)) {
+                        // 如果最后结束日期在生效日期之后,则使用最后结束日期加一天
+                        beginDate = DateUtil.toDate(DateUtil.addDays(DateUtil.toLocalDateTime(latestEndDate), 1));
+                        newEntity.set(FormConstant.DESCRIPTION_KEY, StrFormatter.format("调动单生成任命。(由于最后一次任命结束时间为:【{}】,在调动生效日期:【{}】),系统自动将任命开始日期设置为【{}】",
+                                DateUtil.format(latestEndDate, "yyyy-MM-dd"),
+                                DateUtil.format(effectiveDate, "yyyy-MM-dd"),
+                                DateUtil.format(beginDate, "yyyy-MM-dd")));
+                    } else {
+                        // 否则使用生效日期
+                        beginDate = effectiveDate;
+                        newEntity.set(FormConstant.DESCRIPTION_KEY,"调动单生成任命");
+                    }
+                    newEntity.set(PositionStructureConstant.NCKD_BEGINDATE, beginDate);
+
+                }
+            }else{
+                //调入后岗位不是管理序列
+                //判断有没有在任命的记录,有则终止任命
+                if(personPosFile != null && !personPosFile.isEmpty()){
+                    for(DynamicObject record : personPosFile){
+                        String appointStatus = record.getString(PositionStructureConstant.NCKD_APPOINTSTATUS);
+                        if(!"1".equals(appointStatus)){
+                            // 终止任命
+                            record.set(PositionStructureConstant.NCKD_APPOINTSTATUS, "0");
+                            record.set(PositionStructureConstant.NCKD_ENDDATE, effectiveDate);
+                            record.set(PositionStructureConstant.NCKD_DESCRIPTION, "调动单终止任命");
+                            saveMgrAppointMgmt.add(record);
+                        }
+                    }
+                }
+            }
+        }
+
+        OperateOption operateOption = OperateOption.create();
+        operateOption.setVariableValue(PositionStructureConstant.NCKD_TYPESTATE, TypeStateEnum.MANAGEMENT_SEQUENCE_EMPLOYMENT.getCode());
+        OperationResult operationResult = OperationServiceHelper.executeOperate(
+                "savenewappointment",
+                PositionStructureConstant.PERSONPOSFILE_ENTITYID,
+                saveMgrAppointMgmt.toArray(new DynamicObject[0]),
+                OperateOption.create()
+        );
+
+        if(operationResult != null && !operationResult.isSuccess()){
+
+        }
+    }
+}

+ 3 - 1
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/plugin/operate/other/NewAppointMentOpPlugin.java

@@ -84,7 +84,9 @@ public class NewAppointMentOpPlugin extends AbstractOperationServicePlugIn imple
                         .add(PositionStructureConstant.NCKD_ENDDATE)
                         .add(PositionStructureConstant.NCKD_APPOINTSTATUS)
                         .addIdNumberName(PositionStructureConstant.NCKD_PERSON);
-                DynamicObjectCollection query = QueryServiceHelper.query(PositionStructureConstant.NCKD_PERSONPOSFILE, queryFieldBuilder.buildSelect(), new QFilter[]{new QFilter(PositionStructureConstant.NCKD_PERSON, QCP.in, personIdList)});
+                QFilter qFilter = new QFilter(PositionStructureConstant.NCKD_PERSON, QCP.in, personIdList);
+                qFilter.and(PositionStructureConstant.NCKD_TYPESTATE, QCP.equals, TypeStateEnum.MANAGEMENT_SEQUENCE_EMPLOYMENT.getCode());
+                DynamicObjectCollection query = QueryServiceHelper.query(PositionStructureConstant.NCKD_PERSONPOSFILE, queryFieldBuilder.buildSelect(), new QFilter[]{});
                 // 按用户ID分组
                 mgrAppointMgmtMap = query.stream()
                         .collect(Collectors.groupingBy(

+ 1 - 1
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/swc/mas/plugin/form/empmgt/SubCoHeadServiceListPlugin.java

@@ -199,7 +199,7 @@ public class SubCoHeadServiceListPlugin extends AbstractListPlugin implements Pl
                         // 判断记录是否在当年范围内
                         return changeTime.getYear() == beginYear.getYear();
                     })
-                    .max(Comparator.comparing(record -> record.getDate(MasConstant.STARTDATE),
+                    .max(Comparator.comparing(record -> record.getDate(MasConstant.NCKD_CHANGETIME),
                             Comparator.nullsFirst(Comparator.naturalOrder())));
 
             if (latestRecord.isPresent()) {

+ 1 - 1
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/swc/mas/plugin/form/empmgt/TenurePersonListListPlugin.java

@@ -160,7 +160,7 @@ public class TenurePersonListListPlugin extends AbstractListPlugin implements Pl
                         // 判断记录是否在当年范围内
                         return changeTime.getYear() == beginYear.getYear();
                     })
-                    .max(Comparator.comparing(record -> record.getDate(MasConstant.STARTDATE),
+                    .max(Comparator.comparing(record -> record.getDate(MasConstant.NCKD_CHANGETIME),
                             Comparator.nullsFirst(Comparator.naturalOrder())));
 
             if (latestRecord.isPresent()) {