Parcourir la source

refactor(hr): 重构生成综合评测问卷功能

- 优化代码结构,提取公共方法
- 改进变量命名,提高可读性
- 移除冗余代码,简化逻辑
- 统一错误处理方式
wyc il y a 6 jours
Parent
commit
58e84fcc9b

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

@@ -106,7 +106,7 @@ public class FormConstant {
     /** 多选基础资料*/
     public static final String BASEDATAID_KEY = "fbasedataid";
     /** 当前user id*/
-    public static final String CURR_USER_ID = "CURRUSER_ID";
+    public static final String KEY_CURR_USER_ID = "KEY_CURR_USER_ID";
     /** 当前org id*/
     public static final String CURR_ORG_ID = "ORG_ID";
     /** 当前org id*/

+ 47 - 34
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/hstu/business/CreateEvalQuestService.java

@@ -30,6 +30,8 @@ import nckd.jxccl.base.org.helper.AdminOrgHelper;
 import nckd.jxccl.base.org.helper.PersonHelper;
 import nckd.jxccl.base.orm.helper.QFilterCommonHelper;
 import nckd.jxccl.hr.hstu.common.HonorStudentConstant;
+
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
@@ -57,14 +59,7 @@ public class CreateEvalQuestService {
      * @date: 2025/07/02 17:24
      */
     public static void batchGenerateEvalQuest(Long evalQuestTplId, DynamicObject selectedEvalRule, DynamicObjectCollection selectedPerson, ProgressCallback callback, Long userId,Long orgId) {
-
-        //同级人员取数条件:
-        //1.最新一条党政职务履历为副处级及以上人员不作为同级取数
-        //2.工作性质大类过滤掉编码为H01(居休)、H02(退养)、H03(随任)、H04(女工长假)、H05(长期工伤病休)、H06(长期病休)、H07(其他不在岗)、J(外派)的员工,不做为同级
-        //3.除去领导和上级
-        //4.入职超半年、职位非协理员
         logger.info("【优秀生考评】-生成综合评测问卷-开始");
-
         try {
             // 获取当前用户ID和主组织ID(创建组织)
             Long currUserId = userId;
@@ -126,6 +121,7 @@ public class CreateEvalQuestService {
             //根据比例计算出的其他部门同级评分人的最小人数(同级评分人下限人数*其他同级评分人比例/100=其他同级评分人下限人数)
             int otherLower = (lower * proportion) / 100;
 
+            List<DynamicObject> evalQuestList = new ArrayList<>();
             for (int i = 0; i < selectedPerson.size(); i++) {
                 DynamicObject row = selectedPerson.get(i);
                 Long personId = null;
@@ -153,40 +149,19 @@ public class CreateEvalQuestService {
                 DynamicObject person = new DynamicObject(depempEntityType);
                 person.set(FormConstant.ID_KEY,personId);
 
-                // 主单据创建
-                DynamicObject mainObj = BusinessDataServiceHelper.newDynamicObject(HonorStudentConstant.NCKD_EVALQUEST);
-                //当表单是必填时必须要传结构对象,非必填的只传id就行
-                mainObj.set(HonorStudentConstant.NCKD_EVALPERSON, person);
-                mainObj.set(HonorStudentConstant.NCKD_PERIODSTATE, 0);
-                mainObj.set(HonorStudentConstant.NCKD_EVALUATIONRULE, selectedEvalRule.getLong(HonorStudentConstant.ID_KEY));
-                mainObj.set(HonorStudentConstant.NCKD_EVALQUESTTPL, evalQuestTplId);
-                mainObj.set(HonorStudentConstant.CREATEORG_KEY, org);
-                mainObj.set(HonorStudentConstant.USEORG_KEY, org);
-                mainObj.set(HonorStudentConstant.CREATE_TIME_KEY, new Date());
-                mainObj.set(HonorStudentConstant.CREATOR_KEY, currUser);
-                //默认为已审核
-                mainObj.set(HonorStudentConstant.STATUS, StatusEnum.C.toString());
-                //默认为可用
-                mainObj.set(HonorStudentConstant.ENABLE, EnableEnum.YES.getCode());
-
-
+                //表头构建
+                DynamicObject mainObj = prepareMainObject(person, org, currUser, selectedEvalRule, evalQuestTplId);
+                //分录构建
                 DynamicObjectCollection entryEntity = fetchExpectedScorers(row, proportion, upper, lower, otherLower, Boolean.TRUE);
                 if (entryEntity == null || entryEntity.isEmpty()) {
                     logger.warn("未能获取到有效的评分人列表,人员ID:{}", personId);
                     continue;
                 }
-                
                 mainObj.set(HonorStudentConstant.NCKD_EVALQUESTENTRY,entryEntity);
-                OperationResult operationResult = SaveServiceHelper.saveOperate(FormConstant.SAVE_KEY,HonorStudentConstant.NCKD_EVALQUEST, new DynamicObject[]{mainObj}, option);
-                if (!operationResult.isSuccess()) {
-                    StringJoiner errorMsg = new StringJoiner(";");
-                    for (IOperateInfo error : operationResult.getAllErrorOrValidateInfo()) {
-                        errorMsg.add(error.getMessage());
-                        logger.error("【优秀生考评】-评价对象【{}】生成综合评测问卷-异常,异常信息:{}",personName,error.getMessage());
-                    }
-                    throw new KDBizException(StrFormatter.format("评价对象【{}】生成综合评测问卷失败,原因:{}",personName,errorMsg.toString()));
-                }
+                //保存
+                saveQuest(mainObj, option, personName);
                 if(callback != null) {
+                    //回调进度控件
                     callback.onProgress(i);
                 }
             }
@@ -201,6 +176,44 @@ public class CreateEvalQuestService {
         logger.info("【优秀生考评】-生成综合评测问卷-结束");
     }
 
+    private static void saveQuest(DynamicObject mainObj, OperateOption option, String personName) {
+        OperationResult operationResult = SaveServiceHelper.saveOperate(FormConstant.SAVE_KEY,HonorStudentConstant.NCKD_EVALQUEST, new DynamicObject[]{mainObj}, option);
+        if (!operationResult.isSuccess()) {
+            StringJoiner errorMsg = new StringJoiner(";");
+            for (IOperateInfo error : operationResult.getAllErrorOrValidateInfo()) {
+                errorMsg.add(error.getMessage());
+                logger.error("【优秀生考评】-评价对象【{}】生成综合评测问卷-异常,异常信息:{}", personName,error.getMessage());
+            }
+            throw new KDBizException(StrFormatter.format("评价对象【{}】生成综合评测问卷失败,原因:{}", personName,errorMsg.toString()));
+        }
+    }
+
+    /**
+     * 构建表头
+     * @param person
+     * @param org
+     * @param currUser
+     * @param selectedEvalRule
+     * @param evalQuestTplId
+     * @return: kd.bos.dataentity.entity.DynamicObject
+     * @author W.Y.C
+     * @date: 2025/07/14 09:44
+     */
+    private static DynamicObject prepareMainObject(DynamicObject person, DynamicObject org, DynamicObject currUser, DynamicObject selectedEvalRule, Long evalQuestTplId) {
+        DynamicObject mainObj = BusinessDataServiceHelper.newDynamicObject(HonorStudentConstant.NCKD_EVALQUEST);
+        mainObj.set(HonorStudentConstant.NCKD_EVALPERSON, person);
+        mainObj.set(HonorStudentConstant.NCKD_PERIODSTATE, 0);
+        mainObj.set(HonorStudentConstant.NCKD_EVALUATIONRULE, selectedEvalRule.getLong(HonorStudentConstant.ID_KEY));
+        mainObj.set(HonorStudentConstant.NCKD_EVALQUESTTPL, evalQuestTplId);
+        mainObj.set(HonorStudentConstant.CREATEORG_KEY, org);
+        mainObj.set(HonorStudentConstant.USEORG_KEY, org);
+        mainObj.set(HonorStudentConstant.CREATE_TIME_KEY, new Date());
+        mainObj.set(HonorStudentConstant.CREATOR_KEY, currUser);
+        mainObj.set(HonorStudentConstant.STATUS, StatusEnum.C.toString());
+        mainObj.set(HonorStudentConstant.ENABLE, EnableEnum.YES.getCode());
+        return mainObj;
+    }
+
     /**
      * 获取预计参与问卷打分的用户列表
      * @param person 评分人员

+ 1 - 1
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/hstu/plugin/form/CreateEvalQuestFormPlugin.java

@@ -116,7 +116,7 @@ public class CreateEvalQuestFormPlugin extends AbstractFormPlugin implements Plu
                 //调度任务中获取不到当前用户信息
                 long currUserId = RequestContext.get().getCurrUserId();
                 long orgId = RequestContext.get().getOrgId();
-                params.put(HonorStudentConstant.CURR_USER_ID, currUserId);
+                params.put(HonorStudentConstant.KEY_CURR_USER_ID, currUserId);
                 params.put(HonorStudentConstant.CURR_ORG_ID, orgId);
                 jobInfo.setParams(params);
                 jobInfo.setJobType(JobType.REALTIME);

+ 1 - 5
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/hstu/task/CreateEvalQuestTask.java

@@ -6,12 +6,9 @@ import kd.bos.dataentity.entity.DynamicObjectCollection;
 import kd.bos.exception.KDBizException;
 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.schedule.executor.AbstractTask;
-import kd.bos.servicehelper.BusinessDataServiceHelper;
 import kd.bos.servicehelper.QueryServiceHelper;
-import kd.bos.servicehelper.operation.SaveServiceHelper;
 import nckd.jxccl.base.common.schedule.ProgressCallback;
 import nckd.jxccl.base.common.utils.ConvertUtil;
 import nckd.jxccl.base.org.helper.PersonHelper;
@@ -20,7 +17,6 @@ import nckd.jxccl.hr.hstu.business.CreateEvalQuestService;
 import nckd.jxccl.hr.hstu.common.HonorStudentConstant;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.StringJoiner;
@@ -43,7 +39,7 @@ public class CreateEvalQuestTask extends AbstractTask implements ProgressCallbac
             Long evalQuestTplId = ConvertUtil.toLong(params.get(HonorStudentConstant.NCKD_EVALQUESTTPLID));
             Map<String, Object> selectedEvalRuleMap = (Map<String, Object>) params.get(HonorStudentConstant.NCKD_SELECTEDEVALRULE);
             List<Map<String,Object>> selectedPersonList = (List<Map<String, Object>>) params.get(HonorStudentConstant.NCKD_SELECTEDPERSON);
-            Long crrUserId = ConvertUtil.toLong(params.get(HonorStudentConstant.CURR_USER_ID));
+            Long crrUserId = ConvertUtil.toLong(params.get(HonorStudentConstant.KEY_CURR_USER_ID));
             Long currOrgId = ConvertUtil.toLong(params.get(HonorStudentConstant.CURR_ORG_ID));
             totalItems = selectedPersonList.size();