Browse Source

feat(hr): 优化绩效排名管理表单插件逻辑

- 新增从数据库加载现有数据的功能
- 改进条目移除与恢复的判断条件
- 避免重复添加已存在的条目到集合中
- 设置非排名条目的数据状态为来自数据库
wyc 2 hours ago
parent
commit
83c1f6a818

+ 28 - 2
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/plugin/form/performance/PerfRankMgmtFormPlugin.java

@@ -599,6 +599,13 @@ public class PerfRankMgmtFormPlugin extends AbstractFormPlugin implements Wizard
             this.getView().setEnable(Boolean.FALSE, i, FormConstant.NCKD_PERSON);
             this.getView().setEnable(Boolean.FALSE, i, PerfRankMgmtConstant.NCKD_ISRANKING);
         }
+        DynamicObjectCollection dbEntryEntity = null;
+        Long id = ConvertUtil.toLong(this.getModel().getValue(FormConstant.ID_KEY));
+        if (id != null && id > 0) {
+            MainEntityType perfRankMgmtEntityType = EntityMetadataCache.getDataEntityType(PerfRankMgmtConstant.NCKD_PERFRANKMGMT_ENTITYID);
+            DynamicObject dbPerfRankMgmt = BusinessDataServiceHelper.loadSingle(id, perfRankMgmtEntityType);
+            dbEntryEntity = dbPerfRankMgmt.getDynamicObjectCollection(PerfRankMgmtConstant.NCKD_PERFRANKMGMTENTRY);
+        }
 
         DynamicObjectCollection entryEntityCols = this.getModel().getDataEntity(true).getDynamicObjectCollection(PerfRankMgmtConstant.NCKD_PERFRANKMGMTENTRY);
         // 暂存被过滤掉的条目而不是直接删除
@@ -606,7 +613,7 @@ public class PerfRankMgmtFormPlugin extends AbstractFormPlugin implements Wizard
                 .filter(obj -> !obj.getBoolean(PerfRankMgmtConstant.NCKD_ISRANKING))
                 .collect(Collectors.toList());
         entryEntityCols.removeIf(obj -> !obj.getBoolean(PerfRankMgmtConstant.NCKD_ISRANKING));
-        if(!removedEntries.isEmpty()){
+        if((dbEntryEntity != null && dbEntryEntity.size() != entryEntityCols.size()) || !removedEntries.isEmpty()){
             this.getView().getPageCache().put("removedEntries","true");
         }else{
             this.getView().getPageCache().put("removedEntries","false");
@@ -628,7 +635,22 @@ public class PerfRankMgmtFormPlugin extends AbstractFormPlugin implements Wizard
                         .filter(obj -> !obj.getBoolean(PerfRankMgmtConstant.NCKD_ISRANKING))
                         .collect(Collectors.toList());
                 DynamicObjectCollection entryEntityCols = this.getModel().getDataEntity(true).getDynamicObjectCollection(PerfRankMgmtConstant.NCKD_PERFRANKMGMTENTRY);
-                entryEntityCols.addAll(removedEntries);
+
+                // 创建一个Set来存储entryEntityCols中已有的ID
+                Set<Object> existingIds = entryEntityCols.stream()
+                        .map(obj -> obj.get(FormConstant.ID_KEY))
+                        .filter(Objects::nonNull)
+                        .collect(Collectors.toSet());
+
+                // 只添加不存在的项
+                List<DynamicObject> entriesToAdd = removedEntries.stream()
+                        .filter(obj -> {
+                            Object idObj = obj.get(FormConstant.ID_KEY);
+                            return idObj == null || !existingIds.contains(idObj);
+                        })
+                        .collect(Collectors.toList());
+
+                entryEntityCols.addAll(entriesToAdd);
                 this.getView().updateView(PerfRankMgmtConstant.NCKD_PERFRANKMGMTENTRY);
                 this.getView().getPageCache().put("removedEntries", "false");
             }
@@ -640,6 +662,10 @@ public class PerfRankMgmtFormPlugin extends AbstractFormPlugin implements Wizard
         for (int i = 0; i < entryEntity.size(); i++) {
             this.getView().setEnable(Boolean.TRUE, i, FormConstant.NCKD_PERSON);
             this.getView().setEnable(Boolean.TRUE, i, PerfRankMgmtConstant.NCKD_ISRANKING);
+            DynamicObject dynamicObject = entryEntity.get(i);
+            if(!entryEntity.get( i).getBoolean(PerfRankMgmtConstant.NCKD_ISRANKING)){
+                dynamicObject.getDataEntityState().setFromDatabase( true);
+            }
         }
 
     }