瀏覽代碼

refactor(hr): 重构离职申请和岗位分配相关服务调用

- 移除 DispatchServiceHelper 依赖,改用 HRMServiceHelper 进行业务服务调用
- 更新离职申请表单插件中的考勤档案查询逻辑
- 在岗位账单服务助手类中添加获取岗位所有字段的方法
- 优化岗位分配表单插件中的数据复制和变更检测逻辑
- 添加操作结果错误处理和编码回收机制
- 移除无效的 billIds 初始化代码
jtd 5 天之前
父節點
當前提交
52892659e8

+ 7 - 6
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/htm/plugin/form/quitapply/QuitApplyFormPlugin.java

@@ -7,11 +7,10 @@ import kd.bos.entity.datamodel.events.PropertyChangedArgs;
 import kd.bos.form.plugin.AbstractFormPlugin;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
-import kd.bos.servicehelper.DispatchServiceHelper;
 import kd.bos.servicehelper.QueryServiceHelper;
+import kd.hr.hbp.business.servicehelper.HRMServiceHelper;
 import nckd.jxccl.hr.htm.common.quitapply.QuitApplyConstant;
 
-import java.time.ZoneId;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -80,14 +79,16 @@ public class QuitApplyFormPlugin extends AbstractFormPlugin {
      */
     private void setUnUsedAnnualLeave(Long employeeId, Date contractEndDate) {
         // 获取人员考勤档案
-        String attFileSerializedString = DispatchServiceHelper.invokeService("nckd.jxccl.wtc.wtp.servicehelper", QuitApplyConstant.WTP_APP, "IWTPCustomerService", "getAttFile", new Object[]{contractEndDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), employeeId});
-        if (attFileSerializedString == null) {
+        //String attFileSerializedString = DispatchServiceHelper.invokeService("nckd.jxccl.wtc.wtp.servicehelper", QuitApplyConstant.WTP_APP, "IWTPCustomerService", "getAttFile", new Object[]{contractEndDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), employeeId});
+        Object attFileObj = HRMServiceHelper.invokeBizService(QuitApplyConstant.WTC_CLOUD, QuitApplyConstant.WTBS_APP, "IAttFileQueryService", "attFileQuery", new Object[]{contractEndDate, employeeId});
+        if (attFileObj == null) {
             getView().showTipNotification("未获取到应休未休剩余年假,请检查离职人员是否存在离职时间内有效的考勤档案");
             return;
         }
-        Map<String, Object> attFile = SerializationUtils.fromJsonString(attFileSerializedString, HashMap.class);
+        Map<String, Object> attFile = SerializationUtils.fromJsonString(SerializationUtils.toJsonString(attFileObj), HashMap.class);
 
-        List<DynamicObject> quotaList = DispatchServiceHelper.invokeService("nckd.jxccl.wtc.wtp.servicehelper", QuitApplyConstant.WTP_APP, "IWTPCustomerService", "queryQuota", new Object[]{attFile.get("boId"), Collections.singletonList(1666695290893207552L), 0, contractEndDate, contractEndDate});
+        List<DynamicObject> quotaList = HRMServiceHelper.invokeBizService(QuitApplyConstant.WTC_CLOUD, QuitApplyConstant.WTP_APP, "IQTService", "queryQuota", new Object[]{attFile.get("boId"), Collections.singletonList(1666695290893207552L), 0, contractEndDate, contractEndDate});
+        //List<DynamicObject> quotaList = DispatchServiceHelper.invokeService("nckd.jxccl.wtc.wtp.servicehelper", QuitApplyConstant.WTP_APP, "IWTPCustomerService", "queryQuota", new Object[]{attFile.get("boId"), Collections.singletonList(1666695290893207552L), 0, contractEndDate, contractEndDate});
         if (quotaList != null && !quotaList.isEmpty()) {
             DynamicObject quotaDy = quotaList.get(0);
             getModel().setValue(QuitApplyConstant.NCKD_UNUSEDANNUALLEAVE_KEY, quotaDy.getBigDecimal(QuitApplyConstant.USABLEVALUE_KEY));

+ 5 - 0
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/business/hr/service/impl/PositionBillServiceHelper.java

@@ -53,6 +53,7 @@ import org.apache.commons.lang3.time.DateUtils;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -199,6 +200,10 @@ public class PositionBillServiceHelper {
         return EntityMetadataCache.getDataEntityType(PositionBillConstant.HBPM_POSITIONHR).getProperties().stream().map(IDataEntityProperty::getName).collect(Collectors.toSet());
     }
 
+    public static Set<String> getPositionAllFields() {
+        return new HashSet<String>(EntityMetadataCache.getDataEntityType(PositionBillConstant.HBPM_POSITIONHR).getAllFields().keySet());
+    }
+
     /**
      * 获取分录序号
      * @param iDataModel

+ 59 - 12
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/plugin/form/hr/PositionAssignFormPlugin.java

@@ -3,6 +3,7 @@ package nckd.jxccl.hrmp.hbpm.plugin.form.hr;
 import kd.bos.dataentity.OperateOption;
 import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.dataentity.entity.DynamicObjectCollection;
+import kd.bos.entity.EntityType;
 import kd.bos.entity.operate.OperateOptionConst;
 import kd.bos.entity.operate.result.IOperateInfo;
 import kd.bos.entity.operate.result.OperationResult;
@@ -15,8 +16,10 @@ import kd.bos.servicehelper.operation.OperationServiceHelper;
 import kd.hr.hbp.business.servicehelper.HRBaseServiceHelper;
 import kd.hr.hbp.common.util.HRDateTimeUtils;
 import kd.hr.hbp.common.util.HRDynamicObjectUtils;
+import kd.hr.hbp.common.util.HRObjectUtils;
 import kd.hr.hbp.common.util.HRStringUtils;
 import nckd.jxccl.base.common.utils.QueryFieldBuilder;
+import nckd.jxccl.hrmp.hbpm.business.hr.service.impl.PositionBillServiceHelper;
 import nckd.jxccl.hrmp.hbpm.common.hr.PositionBillConstant;
 import nckd.jxccl.hrmp.hbpm.common.hr.PositionHRConstant;
 
@@ -26,6 +29,7 @@ import java.util.EventObject;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -133,25 +137,49 @@ public class PositionAssignFormPlugin extends AbstractFormPlugin {
 
     private void confirm(Map<Long, DynamicObject> positionDyMap) {
         DynamicObjectCollection entryEntityDyoColl = getModel().getDataEntity(true).getDynamicObjectCollection(PositionHRConstant.NCKD_ENTRYENTITY);
+        // 获取所有单据体 属性
+        Set<String> entryFields = ((EntityType) entryEntityDyoColl.getDynamicObjectType()).getFields().keySet();
+        // 获取所有岗位属性
+        Set<String> positionFields = PositionBillServiceHelper.getPositionAllFields();
+        // 获取岗位要转换的键值,页面字段: 岗位字段
+        Map<String, String> posAssignReverseTransKeyMap = getPosAssignTransKeyMap().entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey, (oldValue, newValue) -> newValue));
         List<DynamicObject> dataEntities = new ArrayList<DynamicObject>();
         HRBaseServiceHelper positionServiceHelper = HRBaseServiceHelper.create(PositionHRConstant.HBPM_POSITIONHR);
         String orgId = "";
         for (DynamicObject entryEntityDy : entryEntityDyoColl) {
             DynamicObject newDyo = positionServiceHelper.generateEmptyDynamicObject();
-            HRDynamicObjectUtils.copy(positionDyMap.get(entryEntityDy.getLong(PositionHRConstant.ID_KEY)), newDyo);
+            DynamicObject dbPositionDy = positionDyMap.get(entryEntityDy.getLong(PositionHRConstant.ID_KEY));
+            HRDynamicObjectUtils.copy(dbPositionDy, newDyo);
+
+            // 设置 变更值到要新增的岗位数据中
+            for (String entryField : entryFields) {
+                String positionField = posAssignReverseTransKeyMap.getOrDefault(entryField, entryField);
+                // 如果岗位中不存在该属性则忽略
+                if (!positionFields.contains(positionField)) {
+                    continue;
+                }
+
+                Object oldValue = dbPositionDy.get(positionField);
+                Object newValue = entryEntityDy.get(entryField);
+                boolean isChange;
+                if (HRObjectUtils.isEmpty(oldValue) && HRObjectUtils.isEmpty(newValue)) {
+                    isChange = false;
+                } else if ((!HRObjectUtils.isEmpty(oldValue) && HRObjectUtils.isEmpty(newValue)) || (HRObjectUtils.isEmpty(oldValue) && !HRObjectUtils.isEmpty(newValue))) {
+                    isChange = true;
+                } else {
+                    isChange = !HRDynamicObjectUtils.compareValues(newValue, oldValue);
+                }
+
+                if (isChange) {
+                    newDyo.set(positionField, newValue);
+                }
+            }
+
             // 重置ID
             newDyo.set(PositionHRConstant.ID_KEY, null);
             newDyo.set(PositionHRConstant.BOID_KEY, null);
-            // 设置 行政组织
-            newDyo.set(PositionHRConstant.ADMINORG, entryEntityDy.get(PositionHRConstant.NCKD_ADMINORG));
-            // 设置 上级岗位
-            newDyo.set(PositionHRConstant.PARENT_KEY, entryEntityDy.get(PositionHRConstant.NCKD_PARENT_KEY));
-            // 设置 岗级
-            newDyo.set(PositionHRConstant.NCKD_POSTGRADE_KEY, entryEntityDy.get(PositionHRConstant.NCKD_POSTGRADE_KEY));
-            // 设置 管理层级细项
-            newDyo.set(PositionHRConstant.NCKD_MGTLVLDTL_KEY, entryEntityDy.get(PositionHRConstant.NCKD_MGTLVLDTL_KEY));
-            // 设置 法人岗位层级
-            newDyo.set(PositionHRConstant.NCKD_LEGPOSTLV_KEY, entryEntityDy.get(PositionHRConstant.NCKD_LEGPOSTLV_KEY));
+            // 设置 生效日期为设立日期
+            newDyo.set(PositionHRConstant.BSED_KEY, newDyo.get(PositionHRConstant.NCKD_ESTABLISHMENTDATE_KEY));
             // 设置编码
             orgId = newDyo.getString(String.join(".", PositionHRConstant.ORG_KEY, PositionHRConstant.ID_KEY));
             String positionNumber = CodeRuleServiceHelper.getNumber(PositionHRConstant.HBPM_POSITIONHR, newDyo, orgId);
@@ -184,7 +212,26 @@ public class PositionAssignFormPlugin extends AbstractFormPlugin {
             return;
         }
 
-        OperationServiceHelper.executeOperate(PositionHRConstant.SAVE_OP, PositionBillConstant.HBPM_POSITIONHR, dataEntities.toArray(new DynamicObject[0]));
+        operationResult = OperationServiceHelper.executeOperate(PositionHRConstant.SAVE_OP, PositionBillConstant.HBPM_POSITIONHR, dataEntities.toArray(new DynamicObject[0]));
+        if (!operationResult.isSuccess()) {
+            for(IOperateInfo operateInfo : operationResult.getAllErrorOrValidateInfo()) {
+                errorMsgList.add(operateInfo.getMessage());
+            }
+
+            if (HRStringUtils.isNotBlank(operationResult.getMessage())) {
+                errorMsgList.add(operationResult.getMessage());
+            }
+
+            // 回收编码
+            String[] numbers = dataEntities.stream().map(data -> data.getString(PositionHRConstant.NUMBER_KEY)).toArray(String[]::new);
+            CodeRuleServiceHelper.recycleBatchNumber(PositionHRConstant.HBPM_POSITIONHR, dataEntities.toArray(new DynamicObject[0]), orgId, numbers);
+        }
+
+        if (!errorMsgList.isEmpty()) {
+            getView().showMessage(null ,String.join(System.lineSeparator(), errorMsgList), MessageTypes.Default);
+            return;
+        }
+
         getView().returnDataToParent("true");
         getView().close();
     }

+ 0 - 1
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/plugin/operate/hr/PositionBillEffectOpPlugin.java

@@ -66,7 +66,6 @@ public class PositionBillEffectOpPlugin extends AbstractOperationServicePlugIn {
 
         DynamicObject[] bills = e.getDataEntities();
         Set<Long> billIds = Sets.newHashSetWithExpectedSize(bills.length);
-        billIds = null;
 
         for(DynamicObject bill : bills) {
             billIds.add(bill.getLong(PositionBillConstant.ID_KEY));