Parcourir la source

feat(hr): 添加个人最高积分配置及校验逻辑

- 在ContributionConstant中新增NCKD_PERSONMAXSCORE常量
- 修改ContributionHelper支持按个人最高积分获取配置
- 更新ContribBillFormPlugin积分计算逻辑
- 调整ContribBillOpPlugin校验规则,支持总积分超限检查
- 优化PerfRankMgmtSaveOpPlugin导入依赖及代码结构
wyc il y a 23 heures
Parent
commit
caa18ae34a

+ 2 - 0
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/common/ContributionConstant.java

@@ -49,5 +49,7 @@ public class ContributionConstant extends FormConstant {
     public static final String SCOREITEMCONF_ENTITYID = "nckd_scoreitemconf";
     /** 最高分数 */
     public static final String NCKD_MAXSCORE = "nckd_maxscore";
+    /** 个人最高分数 */
+    public static final String NCKD_PERSONMAXSCORE = "nckd_personmaxscore";
     /*-------------------------------------- 积分项目分数配置 begin --------------------------------------*/
 }

+ 16 - 3
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/helper/ContributionHelper.java

@@ -605,6 +605,13 @@ public class ContributionHelper {
         return getScoreConf(null);
     }
 
+    public static Map<String, BigDecimal> getScoreConfByPersonMaxScore(QFilter otherFilter) {
+        return getScoreConf(otherFilter,2);
+    }
+    public static Map<String, BigDecimal> getScoreConf(QFilter otherFilter) {
+        return getScoreConf(otherFilter,1);
+    }
+
     /**
      * 获取积分配置
      * @return: java.util.Map<java.lang.String, java.math.BigDecimal>;key:根据配置的完整程度生成不同格式的字符串,
@@ -615,13 +622,13 @@ public class ContributionHelper {
      * @author W.Y.C
      * @date: 2025/10/26 13:38
      */
-    public static Map<String, BigDecimal> getScoreConf(QFilter otherFilter) {
+    public static Map<String, BigDecimal> getScoreConf(QFilter otherFilter,Integer type) {
         //查询积分项目分数配置
         QueryFieldBuilder scoreItemConfFieldBuilder = QueryFieldBuilder.create()
                 .addIdNumberName(FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEM)
                 .addIdNumberName(FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMSUB)
                 .addIdNumberName(FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMRANK)
-                .addGroup(new String[]{FormConstant.NCKD_ENTRYENTITY}, ContributionConstant.NCKD_MAXSCORE);
+                .addGroup(new String[]{FormConstant.NCKD_ENTRYENTITY}, ContributionConstant.NCKD_MAXSCORE,ContributionConstant.NCKD_PERSONMAXSCORE);
         QFilter filter = QFilterCommonHelper.getEnableFilter()
                 .and(QFilterCommonHelper.getValidDateFilter(FormConstant.NCKD_STARTDATE,FormConstant.NCKD_ENDDATE));
         if(otherFilter != null){
@@ -652,7 +659,13 @@ public class ContributionHelper {
                         return scoreItemId+"";
                     }
                 },
-                item -> item.getBigDecimal(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_MAXSCORE)),
+                item -> {
+                    if(type == 1){
+                        return item.getBigDecimal(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_MAXSCORE));
+                    }else{
+                        return item.getBigDecimal(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_PERSONMAXSCORE));
+                    }
+                },
                 //处理重复key的情况,取最大值
                 (existing, replacement) -> existing.max(replacement)
         ));

+ 45 - 50
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/plugin/form/contribution/ContribBillFormPlugin.java

@@ -156,30 +156,27 @@ public class ContribBillFormPlugin extends AbstractFormPlugin implements Plugin,
         DynamicObject scoreItemRank = ConvertUtil.toDynamicObjectOrNull(this.getModel().getValue(ContributionConstant.NCKD_SCOREITEMRANK));
         DynamicObject person = ConvertUtil.toDynamicObjectOrNull(this.getModel().getValue(ContributionConstant.NCKD_PERSON, rowIndex));
         BigDecimal oriScore = ConvertUtil.toBigDecimal(this.getModel().getValue(ContributionConstant.NCKD_ORISCORE, rowIndex));
-        if (date != null && scoreItem != null && scoreItemSub != null) {
-            String scoreItemNumber = scoreItem.getString(FormConstant.NUMBER_KEY);
-            if (ScoreItemEnum.RESEARCH_SCORE.getCode().equalsIgnoreCase(scoreItemNumber)) {
-                if (person != null  && oriScore != null && oriScore.compareTo(BigDecimal.ZERO) > 0) {
-                    //科研与创新需要需要匹配积分规则
-                    QFilter filter = new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEM), QCP.equals, scoreItem.getLong(FormConstant.ID_KEY))
-                            .and(new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMSUB), QCP.equals, scoreItemSub.getLong(FormConstant.ID_KEY)))
-                            .and(new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMRANK), QCP.equals, scoreItemRank.getLong(FormConstant.ID_KEY)));
-                    Map<String, BigDecimal> scoreConf = ContributionHelper.getScoreConf(filter);
-                    String key = scoreItem.getLong(FormConstant.ID_KEY) + "-" + scoreItemSub.getLong(FormConstant.ID_KEY) + "-" + scoreItemRank.getLong(FormConstant.ID_KEY);
-                    BigDecimal validScore = oriScore;
-                    if (!scoreConf.isEmpty() && scoreConf.containsKey(key)) {
-                        BigDecimal maxScore = scoreConf.get(key);
-                        if (maxScore != null) {
-                            validScore = oriScore.compareTo(maxScore) > 0 ? maxScore : oriScore;
-                        }
+        if (date != null && scoreItem != null && scoreItemSub != null && scoreItemRank != null) {
+            if (person != null  && oriScore != null && oriScore.compareTo(BigDecimal.ZERO) > 0) {
+                //科研与创新需要需要匹配积分规则
+                QFilter filter = new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEM), QCP.equals, scoreItem.getLong(FormConstant.ID_KEY))
+                        .and(new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMSUB), QCP.equals, scoreItemSub.getLong(FormConstant.ID_KEY)))
+                        .and(new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMRANK), QCP.equals, scoreItemRank.getLong(FormConstant.ID_KEY)));
+                Map<String, BigDecimal> scoreConf = ContributionHelper.getScoreConfByPersonMaxScore(filter);
+                String key = scoreItem.getLong(FormConstant.ID_KEY) + "-" + scoreItemSub.getLong(FormConstant.ID_KEY) + "-" + scoreItemRank.getLong(FormConstant.ID_KEY);
+                BigDecimal validScore = oriScore;
+                if (!scoreConf.isEmpty() && scoreConf.containsKey(key) &&  scoreConf.get(key) != null && scoreConf.get(key).compareTo(BigDecimal.ZERO) > 0) {
+                    BigDecimal maxScore = scoreConf.get(key);
+                    if (maxScore != null) {
+                        validScore = oriScore.compareTo(maxScore) > 0 ? maxScore : oriScore;
                     }
-                    this.getModel().setValue(ContributionConstant.NCKD_SCORE, validScore, rowIndex);
-                    this.getView().updateView(ContributionConstant.NCKD_SCORE, rowIndex);
                 }
-            } else {
-                this.getModel().setValue(ContributionConstant.NCKD_SCORE, oriScore, rowIndex);
+                this.getModel().setValue(ContributionConstant.NCKD_SCORE, validScore, rowIndex);
                 this.getView().updateView(ContributionConstant.NCKD_SCORE, rowIndex);
             }
+        }else{
+            this.getModel().setValue(ContributionConstant.NCKD_SCORE, oriScore, rowIndex);
+            this.getView().updateView(ContributionConstant.NCKD_SCORE, rowIndex);
         }
     }
 
@@ -231,40 +228,38 @@ public class ContribBillFormPlugin extends AbstractFormPlugin implements Plugin,
         DynamicObject scoreItemRank = ConvertUtil.toDynamicObjectOrNull(this.getModel().getValue(ContributionConstant.NCKD_SCOREITEMRANK));
 
 
-        if (date != null && scoreItem != null && scoreItemSub != null) {
+        if (date != null && scoreItem != null && scoreItemSub != null && scoreItemRank != null) {
 
             DynamicObjectCollection entryEntity = this.getModel().getEntryEntity(FormConstant.NCKD_ENTRYENTITY);
-            String scoreItemNumber = scoreItem.getString(FormConstant.NUMBER_KEY);
-            if(ScoreItemEnum.RESEARCH_SCORE.getCode().equalsIgnoreCase(scoreItemNumber)){
-                if(scoreItemRank != null) {
-                    //科研与创新需要需要匹配积分规则
-                    QFilter filter = new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEM), QCP.equals, scoreItem.getLong(FormConstant.ID_KEY))
-                            .and(new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMSUB), QCP.equals, scoreItemSub.getLong(FormConstant.ID_KEY)))
-                            .and(new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMRANK), QCP.equals, scoreItemRank.getLong(FormConstant.ID_KEY)));
-                    Map<String, BigDecimal> scoreConf = ContributionHelper.getScoreConf(filter);
-                    String key = scoreItem.getLong(FormConstant.ID_KEY)+"-"+scoreItemSub.getLong(FormConstant.ID_KEY)+"-"+scoreItemRank.getLong(FormConstant.ID_KEY);
-                    for (int i = 0; i < entryEntity.size(); i++) {
-                        DynamicObject entry = entryEntity.get(i);
-                        BigDecimal oriScore = entry.getBigDecimal(ContributionConstant.NCKD_ORISCORE);
-                        BigDecimal validScore = oriScore;
-                        if(!scoreConf.isEmpty() && scoreConf.containsKey(key)){
-                            BigDecimal maxScore = scoreConf.get(key);
-                            if (maxScore != null && oriScore != null) {
-                                validScore = oriScore.compareTo(maxScore) > 0 ? maxScore : oriScore;
-                            } else {
-                                // 根据业务需求处理 null 值情况
-                                validScore = oriScore != null ? oriScore : BigDecimal.ZERO;
-                            }
-                        }
-                        this.getModel().setValue(ContributionConstant.NCKD_SCORE, validScore, i);
+
+            //科研与创新需要需要匹配积分规则
+            QFilter filter = new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEM), QCP.equals, scoreItem.getLong(FormConstant.ID_KEY))
+                    .and(new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMSUB), QCP.equals, scoreItemSub.getLong(FormConstant.ID_KEY)))
+                    .and(new QFilter(String.join(".", FormConstant.NCKD_ENTRYENTITY, ContributionConstant.NCKD_SCOREITEMRANK), QCP.equals, scoreItemRank.getLong(FormConstant.ID_KEY)));
+            Map<String, BigDecimal> scoreConf = ContributionHelper.getScoreConfByPersonMaxScore(filter);
+            String key = scoreItem.getLong(FormConstant.ID_KEY)+"-"+scoreItemSub.getLong(FormConstant.ID_KEY)+"-"+scoreItemRank.getLong(FormConstant.ID_KEY);
+            for (int i = 0; i < entryEntity.size(); i++) {
+                DynamicObject entry = entryEntity.get(i);
+                BigDecimal oriScore = entry.getBigDecimal(ContributionConstant.NCKD_ORISCORE);
+                BigDecimal validScore = oriScore;
+                if(!scoreConf.isEmpty() && scoreConf.containsKey(key) &&  scoreConf.get(key) != null && scoreConf.get(key).compareTo(BigDecimal.ZERO) > 0){
+                    BigDecimal maxScore = scoreConf.get(key);
+                    if (maxScore != null && oriScore != null) {
+                        validScore = oriScore.compareTo(maxScore) > 0 ? maxScore : oriScore;
+                    } else {
+                        // 根据业务需求处理 null 值情况
+                        validScore = oriScore != null ? oriScore : BigDecimal.ZERO;
                     }
                 }
-            }else{
-                for (int i = 0; i < entryEntity.size(); i++) {
-                    DynamicObject entry = entryEntity.get(i);
-                    BigDecimal oriScore = entry.getBigDecimal(ContributionConstant.NCKD_ORISCORE);
-                    this.getModel().setValue(ContributionConstant.NCKD_SCORE, oriScore, i);
-                }
+                this.getModel().setValue(ContributionConstant.NCKD_SCORE, validScore, i);
+            }
+
+        }else{
+            DynamicObjectCollection entryEntity = this.getModel().getEntryEntity(FormConstant.NCKD_ENTRYENTITY);
+            for (int i = 0; i < entryEntity.size(); i++) {
+                DynamicObject entry = entryEntity.get(i);
+                BigDecimal oriScore = entry.getBigDecimal(ContributionConstant.NCKD_ORISCORE);
+                this.getModel().setValue(ContributionConstant.NCKD_SCORE, oriScore, i);
             }
         }
     }

+ 13 - 11
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/plugin/operate/contribution/ContribBillOpPlugin.java

@@ -68,21 +68,23 @@ public class ContribBillOpPlugin extends AbstractOperationServicePlugIn implemen
                             String scoreItemNumber = scoreItem.getString(FormConstant.NUMBER_KEY);
                             if(ScoreItemEnum.RESEARCH_SCORE.getCode().equalsIgnoreCase(scoreItemNumber)){
                                 String key = scoreItem.getLong(FormConstant.ID_KEY)+"-"+scoreItemSub.getLong(FormConstant.ID_KEY)+"-"+scoreItemRank.getLong(FormConstant.ID_KEY);
-                                if(!scoreConf.isEmpty() && scoreConf.containsKey(key)){
+                                if(!scoreConf.isEmpty() && scoreConf.containsKey(key)) {
                                     BigDecimal maxScore = scoreConf.get(key);
-                                    for (DynamicObject entry : entryEntity) {
-                                        DynamicObject person = entry.getDynamicObject(ContributionConstant.NCKD_PERSON);
-                                        long personId = person.getLong(FormConstant.ID_KEY);
-                                        BigDecimal oriScore = entry.getBigDecimal(ContributionConstant.NCKD_ORISCORE);
-                                        BigDecimal score = entry.getBigDecimal(ContributionConstant.NCKD_SCORE);
-                                        if(oriScore.compareTo(maxScore) > 0) {
-                                            this.addFatalErrorMessage(dataEntity, StrFormatter.format("参与人【{}】的原始分数【{}】超出限制积分【{}】。请重新填写“原始积分”,系统将会自动重算“录入积分”;",
-                                                    person.getString(FormConstant.NAME_KEY),
-                                                    oriScore.setScale(2, RoundingMode.HALF_UP),
+                                    if (maxScore != null && maxScore.compareTo(BigDecimal.ZERO) > 0){
+                                        BigDecimal sumScore = BigDecimal.ZERO;
+                                        for (DynamicObject entry : entryEntity) {
+                                            DynamicObject person = entry.getDynamicObject(ContributionConstant.NCKD_PERSON);
+                                            long personId = person.getLong(FormConstant.ID_KEY);
+                                            BigDecimal oriScore = entry.getBigDecimal(ContributionConstant.NCKD_ORISCORE);
+                                            BigDecimal score = entry.getBigDecimal(ContributionConstant.NCKD_SCORE);
+                                            sumScore = sumScore.add(oriScore);
+                                        }
+                                        if(sumScore.compareTo(maxScore) > 0) {
+                                            this.addFatalErrorMessage(dataEntity, StrFormatter.format("当前单据总积分【{}】超出限制积分【{}】。请重新填写;",
+                                                    sumScore.setScale(2, RoundingMode.HALF_UP),
                                                     maxScore.setScale(2, RoundingMode.HALF_UP)));
                                         }
                                     }
-
                                 }
                             }
 

+ 13 - 4
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/psms/plugin/operate/performance/PerfRankMgmtSaveOpPlugin.java

@@ -4,18 +4,17 @@ import kd.bos.common.enums.EnableEnum;
 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.EntityMetadataCache;
 import kd.bos.entity.MainEntityType;
 import kd.bos.entity.operate.OperateOptionConst;
 import kd.bos.entity.operate.result.IOperateInfo;
-import kd.bos.entity.operate.result.OperateErrorInfo;
 import kd.bos.entity.operate.result.OperationResult;
 import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
 import kd.bos.entity.plugin.AddValidatorsEventArgs;
 import kd.bos.entity.plugin.PreparePropertysEventArgs;
 import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
 import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
-import kd.bos.entity.validate.ErrorLevel;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import kd.bos.servicehelper.BusinessDataServiceHelper;
@@ -38,10 +37,20 @@ import org.apache.commons.lang3.StringUtils;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.StringJoiner;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
-import kd.bos.dataentity.utils.ObjectUtils;
 
 /**
 * 年度绩效排名管理-保存插件