Переглянути джерело

refactor(hrmp): 重构岗位申请单相关服务类

- 新增 PositionBillAfterBindDataService 类处理绑定数据后置服务
- 优化 PositionBillClosedCallBackService 中的属性名处理逻辑
- 使用 PositionBillServiceHelper.getNoLineSuffixProp 替代字符串截取
- 修复 PositionBillSaveHelper 中字段名拼接逻辑错误
- 添加 HRDyObjectPropUtil 工具类用于动态对象属性处理
- 优化分录字段后缀处理机制,统一使用辅助方法
- 移除硬编码的字符串截取操作,提高代码可维护性
jtd 2 тижнів тому
батько
коміт
59ab780642

+ 31 - 0
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/business/hr/PositionBillAfterBindDataService.java

@@ -0,0 +1,31 @@
+package nckd.jxccl.hrmp.hbpm.business.hr;
+
+import kd.bos.form.IFormView;
+import kd.bos.orm.ORM;
+import nckd.jxccl.hrmp.hbpm.common.hr.PositionBillConstant;
+
+/**
+ * 岗位申请单后置绑定数据服务
+ * @from: kd.hr.homs.business.domain.batchbill.service.impl.AdminOrgBatchBillAfterBindDataService
+ * @author: jtd
+ * @date: 2025/12/27 21:48
+ */
+public class PositionBillAfterBindDataService extends PositionBillBaseService {
+    public PositionBillAfterBindDataService(IFormView view) {
+        super(view);
+    }
+
+    public void afterBindData() {
+        genBillIdIfNotExist();
+        getModel().setDataChanged(false);
+    }
+
+    private void genBillIdIfNotExist() {
+        long billId = getModel().getDataEntity().getLong(PositionBillConstant.ID_KEY);
+        if (billId == 0L) {
+            billId = ORM.create().genLongId(getView().getEntityId());
+            getModel().setValue(PositionBillConstant.ID_KEY, billId);
+        }
+    }
+
+}

+ 6 - 6
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/business/hr/PositionBillClosedCallBackService.java

@@ -14,6 +14,7 @@ import kd.bos.form.events.ClosedCallBackEvent;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import kd.hr.hbp.business.servicehelper.HRBaseServiceHelper;
+import kd.hr.hbp.common.util.HRDyObjectPropUtil;
 import nckd.jxccl.hrmp.hbpm.common.hr.PositionBillConstant;
 import nckd.jxccl.hrmp.hbpm.common.hr.PositionChangeTypeEnum;
 
@@ -64,7 +65,7 @@ public class PositionBillClosedCallBackService extends PositionBillBaseService {
         for(IDataEntityProperty iDataEntityProperty : entryEntityInfo) {
             String entryPropName = iDataEntityProperty.getName();
             if (entryPropName.endsWith(lineSuffix)) {
-                String entryPropNameSub = entryPropName.substring(0, entryPropName.lastIndexOf(lineSuffix));
+                String entryPropNameSub = PositionBillServiceHelper.getNoLineSuffixProp(entryPropName, lineSuffix);
                 if (addNamePropMap.containsKey(entryPropNameSub)) {
                     selectPropList.add(entryPropNameSub);
                     toSetValueEntryPropList.add(entryPropName);
@@ -76,7 +77,7 @@ public class PositionBillClosedCallBackService extends PositionBillBaseService {
         Map<String, String> transKeyMap = PositionBillServiceHelper.getPosBillEntryTransKeyMap();
         transKeyMap.forEach((key, value) -> {
             selectPropList.add(value);// 岗位查询字段放入分录页面字段
-            toSetValueEntryPropList.add(key);// 放入单据分录字段
+            toSetValueEntryPropList.add(key+lineSuffix);// 放入单据分录字段(带后缀)
         });
         toSetValueEntryPropList.add(PositionBillConstant.ID_KEY);
 
@@ -95,12 +96,11 @@ public class PositionBillClosedCallBackService extends PositionBillBaseService {
             for(String entryPropName : toSetValueEntryPropList) {
                 if (entryPropName.equals(PositionBillConstant.ID_KEY)) {
                     values.add(addPositionDy.getLong(PositionBillConstant.ID_KEY));
-                } else if (transKeyMap.containsKey(entryPropName)) {
-                    values.add(addPositionDy.get(transKeyMap.get(entryPropName)));
                 } else {
-                    String propName = entryPropName.substring(0, entryPropName.lastIndexOf(lineSuffix));
+                    String propName = PositionBillServiceHelper.getNoLineSuffixProp(entryPropName, lineSuffix);
+                    propName = transKeyMap.getOrDefault(propName, propName);
                     if (addPositionDy.get(propName) instanceof DynamicObject) {
-                        values.add(((DynamicObject) addPositionDy.get(propName)).getLong(PositionBillConstant.ID_KEY));
+                        values.add(HRDyObjectPropUtil.getIdLongObject(addPositionDy.getDynamicObject(propName)));
                     } else {
                         values.add(addPositionDy.get(propName));
                     }

+ 2 - 2
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/business/hr/PositionBillConfirmCallBackService.java

@@ -196,7 +196,7 @@ public class PositionBillConfirmCallBackService extends PositionBillBaseService
             for(IDataEntityProperty iDataEntityProperty : entryEntityInfo) {
                 String propName = iDataEntityProperty.getName();
                 if (PatternUtil.isExProperty(propName) && propName.endsWith(lineSuffix)) {
-                    String selectName = propName.substring(0, propName.lastIndexOf(lineSuffix));
+                    String selectName = PositionBillServiceHelper.getNoLineSuffixProp(propName, lineSuffix);
                     queryFieldBuilder.add(transKeyMap.getOrDefault(selectName, selectName));
                 }
             }
@@ -211,7 +211,7 @@ public class PositionBillConfirmCallBackService extends PositionBillBaseService
             for(IDataEntityProperty iDataEntityProperty : entryEntityInfo) {
                 String propName = iDataEntityProperty.getName();
                 if (nckd.jxccl.hrmp.hbpm.business.hr.PatternUtil.isExProperty(propName) && propName.endsWith(lineSuffix)) {
-                    String selectName = propName.substring(0, propName.lastIndexOf(lineSuffix));
+                    String selectName = PositionBillServiceHelper.getNoLineSuffixProp(propName, lineSuffix);
                     if (positionExcludeKeyList.contains(selectName) || HRStringUtils.equals(selectName, PositionBillConstant.NCKD_POSDUTY_ENTRY_ENTITY_KEY)) {
                         continue;
                     }

+ 2 - 2
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/business/hr/PositionBillPropertyChangedService.java

@@ -91,7 +91,7 @@ public class PositionBillPropertyChangedService extends PositionBillBaseService
         for(IDataEntityProperty iDataEntityProperty : entryEntityInfo) {
             String propName = iDataEntityProperty.getName();
             if (PatternUtil.isExProperty(propName) && propName.endsWith(lineSuffix)) {
-                String selectName = propName.substring(0, propName.lastIndexOf(lineSuffix));
+                String selectName = PositionBillServiceHelper.getNoLineSuffixProp(propName, lineSuffix);
                 selectSqlBuilder.append(",").append(transKeyMap.getOrDefault(selectName, selectName));
             }
         }
@@ -121,7 +121,7 @@ public class PositionBillPropertyChangedService extends PositionBillBaseService
             for(IDataEntityProperty iDataEntityProperty : entryEntityInfo) {
                 String propName = iDataEntityProperty.getName();
                 if (PatternUtil.isExProperty(propName) && propName.endsWith(lineSuffix)) {
-                    String selectName = propName.substring(0, propName.lastIndexOf(lineSuffix));
+                    String selectName = PositionBillServiceHelper.getNoLineSuffixProp(propName, lineSuffix);
                     if (positionExcludeKeyList.contains(selectName) || HRStringUtils.equals(selectName, PositionBillConstant.NCKD_POSDUTY_ENTRY_ENTITY_KEY)) {
                         continue;
                     }

+ 6 - 4
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/business/hr/PositionBillSaveHelper.java

@@ -8,6 +8,7 @@ import nckd.jxccl.hrmp.hbpm.common.hr.PositionChangeTypeEnum;
 
 /**
  * 岗位申请单保存服务
+ * @from: kd.hr.homs.business.domain.orgbatch.service.impl.OrgBatchBillSaveHelper
  * @author: jtd
  * @date: 2025/12/27 15:04
  */
@@ -21,22 +22,23 @@ public class PositionBillSaveHelper {
 
     public Long getPositionId(DynamicObject entryEntityDynFromPage, String suffix) {
         String idFieldName = String.join(".", PositionBillConstant.NCKD_POSITION, PositionBillConstant.ID_KEY);
-        if (entryEntityDynFromPage.getString(spliceTwoStringByUnderLine(String.join(".", PositionBillConstant.NCKD_CHANGETYPE, PositionBillConstant.NUMBER_KEY), suffix)) == PositionChangeTypeEnum.ADD.getNumber()) {
+        if (entryEntityDynFromPage.getString(spliceTwoStringByUnderLine(suffix, String.join(".", PositionBillConstant.NCKD_CHANGETYPE, PositionBillConstant.NUMBER_KEY))) == PositionChangeTypeEnum.ADD.getNumber()) {
             idFieldName = PositionBillConstant.NCKD_POSITION;
         }
 
-        String positionFiledName = spliceTwoStringByUnderLine(idFieldName, suffix);
+        String positionFiledName = spliceTwoStringByUnderLine(suffix, idFieldName);
         return entryEntityDynFromPage.getLong(positionFiledName);
     }
 
     public String getSuffixFromEntryEntityDyn(DynamicObject entryEntityDynFromPage) {
         String entryEntityName = entryEntityDynFromPage.getDynamicObjectType().getName();
-        int lastUnderLineIndex = entryEntityName.indexOf("_");
+        int lastUnderLineIndex = entryEntityName.lastIndexOf("_");
         return entryEntityName.substring(lastUnderLineIndex + 1);
     }
 
     public String spliceTwoStringByUnderLine(String oneString, String otherString) {
-        return oneString + "_" + otherString;
+        String[] str = otherString.split("\\.");
+        return str.length > 1 ? str[0] + "_" + oneString + "." + str[1] : otherString + "_" + oneString;
     }
 
 }

+ 13 - 6
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/business/hr/PositionBillServiceHelper.java

@@ -59,6 +59,13 @@ public class PositionBillServiceHelper {
 
     private static final Log log = LogFactory.getLog(PositionBillServiceHelper.class);
 
+    public static String getNoLineSuffixProp(String prop, String lineSuffix) {
+        if (prop.endsWith(lineSuffix)) {
+            return prop.lastIndexOf(lineSuffix) >= 0 ? prop.substring(0, prop.lastIndexOf(lineSuffix)) : prop;
+        }
+        return prop;
+    }
+
     /**
      * 获取分录序号
      * @param iDataModel
@@ -160,7 +167,7 @@ public class PositionBillServiceHelper {
     }
 
     public static QFilter filterCurrentBillOrg(IFormView iFormView) {
-        List<Long> list = new ArrayList();// 378
+        List<Long> list = new ArrayList();
         DynamicObjectCollection change = new DynamicObjectCollection();
         if (iFormView.getEntityId().equals(PositionBillConstant.NCKD_POSITIONBILL_ENTITY)) {
             change = iFormView.getModel().getDataEntity(true).getDynamicObjectCollection(PositionBillConstant.NCKD_ENTRYENTITY_CHANGE_KEY);
@@ -357,7 +364,7 @@ public class PositionBillServiceHelper {
         if (bill == null) {
             return "";
         } else {
-            DynamicObjectCollection positionEntryDys = new DynamicObjectCollection();// 2238
+            DynamicObjectCollection positionEntryDys = new DynamicObjectCollection();
             positionEntryDys.addAll(bill.getDynamicObjectCollection(PositionBillConstant.NCKD_ENTRYENTITY_ADD_KEY));
             positionEntryDys.addAll(bill.getDynamicObjectCollection(PositionBillConstant.NCKD_ENTRYENTITY_CHANGE_KEY));
             PositionBillSaveHelper helper = PositionBillSaveHelper.getInstance();
@@ -370,7 +377,7 @@ public class PositionBillServiceHelper {
                 if (PositionChangeTypeEnum.ADD.getNumber().equals(changeTypeNumber)) {
                     positionBoId = helper.getPositionId(entryDy, suffix);
                 } else {
-                    DynamicObject positionDyRef = entryDy.getDynamicObject(helper.spliceTwoStringByUnderLine(PositionBillConstant.NCKD_POSITION, suffix));
+                    DynamicObject positionDyRef = entryDy.getDynamicObject(helper.spliceTwoStringByUnderLine(suffix, PositionBillConstant.NCKD_POSITION));
                     if (positionDyRef != null) {
                         positionBoId = positionDyRef.getLong(PositionBillConstant.BOID_KEY);
                     }
@@ -404,11 +411,11 @@ public class PositionBillServiceHelper {
             for(DynamicObject positionEntryDy : positionNumberEntryDys) {
                 String suffix = helper.getSuffixFromEntryEntityDyn(positionEntryDy);
                 long positionId = 0L;
-                String positionNumber = positionEntryDy.getString(helper.spliceTwoStringByUnderLine(PositionBillConstant.NCKD_NUMBER_KEY, suffix));
+                String positionNumber = positionEntryDy.getString(helper.spliceTwoStringByUnderLine(suffix, PositionBillConstant.NCKD_NUMBER_KEY));
                 if (PositionBillConstant.NCKD_ENTRYENTITY_ADD_KEY.equals(positionEntryDy.getDynamicObjectType().getName())) {
-                    positionId = positionEntryDy.getLong(helper.spliceTwoStringByUnderLine(PositionBillConstant.NCKD_POSITION, suffix));
+                    positionId = positionEntryDy.getLong(helper.spliceTwoStringByUnderLine(suffix, PositionBillConstant.NCKD_POSITION));
                 } else {
-                    DynamicObject positionDy = positionEntryDy.getDynamicObject(helper.spliceTwoStringByUnderLine(PositionBillConstant.NCKD_POSITION, suffix));
+                    DynamicObject positionDy = positionEntryDy.getDynamicObject(helper.spliceTwoStringByUnderLine(suffix, PositionBillConstant.NCKD_POSITION));
                     if (positionDy != null) {
                         positionId = positionDy.getLong(PositionBillConstant.BOID_KEY);
                     }

+ 5 - 5
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/plugin/form/hr/PosBillEntryAddFormPlugin.java

@@ -209,7 +209,7 @@ public class PosBillEntryAddFormPlugin extends AbstractFormPlugin {
         if (selectObject != null) {
             String lineSuffix = "_"+PositionBillConstant.ADD_TAG;
             Map<String, Object> map = SerializationUtils.fromJsonString(selectObject.toString(), Map.class);
-            Map<String, Object> noPrefixMap = map.entrySet().stream().collect(HashMap::new, (m, v) -> m.put(v.getKey().substring(0, v.getKey().lastIndexOf(lineSuffix)), v.getValue()), HashMap::putAll);
+            Map<String, Object> noPrefixMap = map.entrySet().stream().collect(HashMap::new, (m, v) -> m.put(PositionBillServiceHelper.getNoLineSuffixProp(v.getKey(), lineSuffix), v.getValue()), HashMap::putAll);
             List<String> props = new ArrayList();
 
             for(String prop : noPrefixMap.keySet()) {
@@ -241,7 +241,7 @@ public class PosBillEntryAddFormPlugin extends AbstractFormPlugin {
             if (value != null) {
                 if (propertyType.equals(DynamicObject.class) && dynamicProperty instanceof BasedataProp) {
                     // 岗位特殊处理
-                    Object id = PositionBillConstant.NCKD_POSITION.equals(key) ? value : ((Map)value).get(PositionBillConstant.ID_KEY);
+                    Object id = PositionBillConstant.NCKD_POSITION.equals(key) ? value : ((Map) value).get(PositionBillConstant.ID_KEY);
                     if (id != null && !HRStringUtils.equals(value.toString(), "0")) {
                         getModel().setValue(key, id);
                     }
@@ -249,11 +249,11 @@ public class PosBillEntryAddFormPlugin extends AbstractFormPlugin {
                     MulBasedataProp property = (MulBasedataProp) getModel().getDataEntityType().getProperty(key);
                     DynamicObjectCollection dynamicObjectCollection = new DynamicObjectCollection();
                         HRBaseServiceHelper serviceHelper = new HRBaseServiceHelper(property.getBaseEntityId());
-                    ((List)value).forEach((map) -> {
+                    ((List) value).forEach((map) -> {
                         DynamicObject dy = new DynamicObject(property.getDynamicCollectionItemPropertyType());
-                        dy.set("fbasedataid_id", ((Map)map).get("fbasedataid_id"));
+                        dy.set("fbasedataid_id", ((Map) map).get("fbasedataid_id"));
                         DynamicObject emptyDynamicObject = serviceHelper.generateEmptyDynamicObject();
-                        emptyDynamicObject.set(PositionBillConstant.ID_KEY, ((Map)map).get("fbasedataid_id"));
+                        emptyDynamicObject.set(PositionBillConstant.ID_KEY, ((Map) map).get("fbasedataid_id"));
                         dy.set("fbasedataid", emptyDynamicObject);
                         dynamicObjectCollection.add(dy);
                     });

+ 7 - 16
code/hrmp/nckd-jxccl-hrmp/src/main/java/nckd/jxccl/hrmp/hbpm/plugin/form/hr/PositionBillFormPlugin.java

@@ -41,7 +41,6 @@ import kd.bos.list.ListShowParameter;
 import kd.bos.logging.Log;
 import kd.bos.logging.LogFactory;
 import kd.bos.mvc.bill.BillView;
-import kd.bos.orm.ORM;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import kd.bos.orm.util.CollectionUtils;
@@ -55,6 +54,7 @@ import kd.hr.hbp.common.util.HRDynamicObjectUtils;
 import kd.hr.hbp.common.util.HRStringUtils;
 import kd.hr.hbp.common.util.concurrent.NullableConcurrentHashMap;
 import kd.sdk.hr.hdm.common.enums.reg.RegBillStatusEnum;
+import nckd.jxccl.hrmp.hbpm.business.hr.PositionBillAfterBindDataService;
 import nckd.jxccl.hrmp.hbpm.business.hr.PositionBillClosedCallBackService;
 import nckd.jxccl.hrmp.hbpm.business.hr.PositionBillConfirmCallBackService;
 import nckd.jxccl.hrmp.hbpm.business.hr.PositionBillPropertyChangedService;
@@ -67,6 +67,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.EventObject;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
 
@@ -84,20 +85,10 @@ public class PositionBillFormPlugin extends AbstractFormPlugin implements Before
     public void afterBindData(EventObject e) {
         super.afterBindData(e);
 
-        // 生成临时单据ID
-        genBillIdIfNotExist();
-        getModel().setDataChanged(false);
-    }
-
-    /**
-     * 生成临时单据ID
-     */
-    private void genBillIdIfNotExist() {
-        long billId = getModel().getDataEntity().getLong(PositionBillConstant.ID_KEY);
-        if (billId == 0L) {
-            billId = ORM.create().genLongId(getView().getEntityId());
-            getModel().setValue(PositionBillConstant.ID_KEY, billId);
-        }
+        long startTime = System.currentTimeMillis();
+        PositionBillAfterBindDataService afterBindDataService = new PositionBillAfterBindDataService(getView());
+        afterBindDataService.afterBindData();
+        LOG.info(String.format(Locale.ROOT, "PositionBillFormPlugin afterBindData() time cost is: %s", System.currentTimeMillis() - startTime));
     }
 
     public void beforeBasedataSetValue(BeforeBasedataSetValueEvent beforeBasedataSetValueEvent) {
@@ -319,7 +310,7 @@ public class PositionBillFormPlugin extends AbstractFormPlugin implements Before
             DynamicObject dynamicObject = dynamicObjectCollection.get(beforeF7SelectEvent.getRow());
             String name = property.getName();
             String lineSuffix = name.substring(name.lastIndexOf("_"));
-            String fieldKey = name.substring(0, name.lastIndexOf(lineSuffix));
+            String fieldKey = PositionBillServiceHelper.getNoLineSuffixProp(name, lineSuffix);
             if (PositionBillConstant.ORG_KEY.equals(fieldKey)) {
                 return false;
             } else if (!dynamicObject.getDataEntityType().getProperties().containsKey(String.join(PositionBillConstant.ORG_KEY +lineSuffix))) {

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

@@ -19,7 +19,7 @@ public class PosBillEntryAddSaveOpPlugin extends PositionBillEntrySaveOpPlugin {
         super.onAddValidators(e);
 
         OperateOption option = getOption();
-        String onlyValidate = option.getVariableValue(OperateOptionConst.ONLY_VALIDATE, Boolean.FALSE.toString());// 22
+        String onlyValidate = option.getVariableValue(OperateOptionConst.ONLY_VALIDATE, Boolean.FALSE.toString());
         if (Boolean.TRUE.toString().equals(onlyValidate)) {
             e.addValidator(new PositionAddSaveValidator());
         }