|
@@ -1,30 +1,44 @@
|
|
|
package nckd.jxccl.hr.hstu.business;
|
|
|
|
|
|
+import kd.bos.common.enums.EnableEnum;
|
|
|
+import kd.bos.context.RequestContext;
|
|
|
+import kd.bos.dataentity.OperateOption;
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
+import kd.bos.entity.EntityMetadataCache;
|
|
|
+import kd.bos.entity.MainEntityType;
|
|
|
+import kd.bos.entity.constant.StatusEnum;
|
|
|
+import kd.bos.entity.operate.OperateOptionConst;
|
|
|
+import kd.bos.entity.operate.result.IOperateInfo;
|
|
|
+import kd.bos.entity.operate.result.OperationResult;
|
|
|
+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.servicehelper.BusinessDataServiceHelper;
|
|
|
import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
+import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
+import kd.bos.servicehelper.user.UserServiceHelper;
|
|
|
import kd.hr.hbp.business.openservicehelper.hrpi.HRPIDepempServiceHelper;
|
|
|
-import nckd.jxccl.base.common.constant.FromConstant;
|
|
|
+import nckd.jxccl.base.common.constant.FormConstant;
|
|
|
+import nckd.jxccl.base.common.schedule.ProgressCallback;
|
|
|
import nckd.jxccl.base.common.utils.ConvertUtil;
|
|
|
import nckd.jxccl.base.common.utils.DateUtil;
|
|
|
+import nckd.jxccl.base.common.utils.StrFormatter;
|
|
|
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.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.StringJoiner;
|
|
|
-
|
|
|
/**
|
|
|
- * 【优秀生】-生成评价问卷
|
|
|
+ * 【优秀生】-生成评价问卷服务类
|
|
|
* @author W.Y.C
|
|
|
* @date 2025/7/2 16:41
|
|
|
* @version 1.0
|
|
@@ -33,7 +47,6 @@ public class CreateEvalQuestService {
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(CreateEvalQuestService.class);
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 批量生成评价问卷
|
|
|
* @param evalQuestTplId 评价问卷模板Id
|
|
@@ -43,80 +56,212 @@ public class CreateEvalQuestService {
|
|
|
* @author W.Y.C
|
|
|
* @date: 2025/07/02 17:24
|
|
|
*/
|
|
|
- public static void createEvalQuest(Long evalQuestTplId, DynamicObject selectedEvalRule, DynamicObjectCollection selectedPerson) {
|
|
|
+ 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("【职位体系】-生成综合评测问卷-开始");
|
|
|
-
|
|
|
-
|
|
|
- StringJoiner ruleColum = new StringJoiner(",");
|
|
|
- //其他同级评分人比例
|
|
|
- ruleColum.add(HonorStudentConstant.NCKD_PROPORTION);
|
|
|
- //同级评分人上限人数
|
|
|
- ruleColum.add(HonorStudentConstant.NCKD_UPPER);
|
|
|
- //同级评分人下限人数
|
|
|
- ruleColum.add(HonorStudentConstant.NCKD_LOWER);
|
|
|
- selectedEvalRule = QueryServiceHelper.queryOne(HonorStudentConstant.EVALUATIONRULE_ENTITYID, ruleColum.toString(), new QFilter[]{QFilterCommonHelper.getIdEqFilter(selectedEvalRule.getPkValue())});
|
|
|
- int proportion = selectedEvalRule.getInt(HonorStudentConstant.NCKD_PROPORTION);
|
|
|
- int upper = selectedEvalRule.getInt(HonorStudentConstant.NCKD_UPPER);
|
|
|
- int lower = selectedEvalRule.getInt(HonorStudentConstant.NCKD_LOWER);
|
|
|
- int otherLower = lower * proportion / 100;
|
|
|
- try{
|
|
|
- // 用工关系状态:正式员工、试用员工、见习期员工
|
|
|
- for (DynamicObject row : selectedPerson) {
|
|
|
- DynamicObject depEmpRow = (DynamicObject)row.getDynamicObject(FromConstant.BASEDATAID_KEY);
|
|
|
-
|
|
|
- Map<String, Object> depEmp = HRPIDepempServiceHelper.getDepemp(ConvertUtil.toLong(depEmpRow.getPkValue()));
|
|
|
- Long id = ConvertUtil.toLong(depEmp.get("id"));
|
|
|
- //获取当前人员的组织
|
|
|
- Long adminOrgId = ConvertUtil.toLong(depEmp.get("adminorg_id"));
|
|
|
- //获取当前人员的岗位
|
|
|
- Long positionId = ConvertUtil.toLong(depEmp.get("position_id"));
|
|
|
-
|
|
|
- //获取领导(获取上上级岗位中的人员作为领导)
|
|
|
- DynamicObject parentParentPosition = QueryServiceHelper.queryOne("hbpm_positionhr","parent.parent.id as parentId",new QFilter[]{QFilterCommonHelper.getIdEqFilter(positionId)});
|
|
|
- QFilter positionFilter = new QFilter("position.id", QCP.equals, parentParentPosition.getLong("parentId"));
|
|
|
- DynamicObjectCollection leadColl = PersonHelper.getDepEmpEffectivePerson("id,person.name",positionFilter);
|
|
|
+ logger.info("【优秀生考评】-生成综合评测问卷-开始");
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取当前用户ID和主组织ID(创建组织)
|
|
|
+ Long currUserId = userId;
|
|
|
+ if(currUserId == null) {
|
|
|
+ currUserId = RequestContext.get().getCurrUserId();
|
|
|
+ }
|
|
|
+ Long currOrgId = orgId;
|
|
|
+ if(currOrgId == null) {
|
|
|
+ currOrgId = RequestContext.get().getOrgId();
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicObject currUser = UserServiceHelper.getUserInfoByID(currUserId, HonorStudentConstant.ID_KEY);
|
|
|
+
|
|
|
+ // 获取实体元数据
|
|
|
+ MainEntityType bosOrgEntityType = EntityMetadataCache.getDataEntityType(AdminOrgHelper.BOS_ORG);
|
|
|
+ // 基于元数据创建 DynamicObject
|
|
|
+ DynamicObject org = new DynamicObject(bosOrgEntityType);
|
|
|
+ org.set(FormConstant.ID_KEY,currOrgId);
|
|
|
+
|
|
|
+ // 配置操作选项(忽略警告)
|
|
|
+ OperateOption option = OperateOption.create();
|
|
|
+ // 忽略警告
|
|
|
+ option.setVariableValue(OperateOptionConst.IGNOREWARN, Boolean.TRUE.toString());
|
|
|
+ // 忽略交互提示
|
|
|
+ option.setVariableValue(OperateOptionConst.IGNOREINTERACTION, Boolean.TRUE.toString());
|
|
|
+ //单据页面操作
|
|
|
+ //option.setVariableValue(OperateOptionConst.ISFORMVIEWOPERATION, Boolean.TRUE.toString());
|
|
|
+
|
|
|
+ DynamicObject evalQuestTpl = QueryServiceHelper.queryOne(HonorStudentConstant.NCKD_EVALQUESTTPL, "id",new QFilter[]{QFilterCommonHelper.getIdEqFilter(evalQuestTplId)});
|
|
|
+ if (evalQuestTpl == null) {
|
|
|
+ throw new KDBizException("评价问卷模板未找到");
|
|
|
+ }
|
|
|
+
|
|
|
+ StringJoiner ruleColum = new StringJoiner(",");
|
|
|
+ ruleColum.add(FormConstant.ID_KEY);
|
|
|
+ //其他同级评分人比例
|
|
|
+ ruleColum.add(HonorStudentConstant.NCKD_PROPORTION);
|
|
|
+ //同级评分人上限人数
|
|
|
+ ruleColum.add(HonorStudentConstant.NCKD_UPPER);
|
|
|
+ //同级评分人下限人数
|
|
|
+ ruleColum.add(HonorStudentConstant.NCKD_LOWER);
|
|
|
+ selectedEvalRule = QueryServiceHelper.queryOne(HonorStudentConstant.EVALUATIONRULE_ENTITYID, ruleColum.toString(), new QFilter[]{QFilterCommonHelper.getIdEqFilter(selectedEvalRule.getLong(HonorStudentConstant.ID_KEY))});
|
|
|
+ if (selectedEvalRule == null) {
|
|
|
+ throw new KDBizException("评价规则未找到");
|
|
|
+ }
|
|
|
+
|
|
|
+ int proportion = selectedEvalRule.getInt(HonorStudentConstant.NCKD_PROPORTION);
|
|
|
+ int upper = selectedEvalRule.getInt(HonorStudentConstant.NCKD_UPPER);
|
|
|
+ int lower = selectedEvalRule.getInt(HonorStudentConstant.NCKD_LOWER);
|
|
|
+
|
|
|
+ // 参数验证
|
|
|
+ if (proportion < 0 || proportion > 100) {
|
|
|
+ throw new KDBizException("其他同级评分人比例必须在0-100之间");
|
|
|
+ }
|
|
|
+ if (lower < 0 || upper < lower) {
|
|
|
+ throw new KDBizException("同级评分人上限人数必须大于等于下限人数且都大于等于0");
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据比例计算出的其他部门同级评分人的最小人数(同级评分人下限人数*其他同级评分人比例/100=其他同级评分人下限人数)
|
|
|
+ int otherLower = (lower * proportion) / 100;
|
|
|
+
|
|
|
+ for (int i = 0; i < selectedPerson.size(); i++) {
|
|
|
+ DynamicObject row = selectedPerson.get(i);
|
|
|
+ Long personId = null;
|
|
|
+ String personName = null;
|
|
|
+ if(row.containsProperty(FormConstant.BASEDATAID_KEY)){
|
|
|
+ //获取页面选择的多选基础数据可能会被存放在fbasedataid中
|
|
|
+ DynamicObject depEmpRow = (DynamicObject)row.getDynamicObject(FormConstant.BASEDATAID_KEY);
|
|
|
+ if (depEmpRow == null) {
|
|
|
+ logger.warn("跳过无效的人员数据,索引:{}", i);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ personId = ConvertUtil.toLong(depEmpRow.getPkValue());
|
|
|
+ personName = depEmpRow.getString("person.name");
|
|
|
+ }else{
|
|
|
+ personId = row.getLong(HonorStudentConstant.ID_KEY);
|
|
|
+ personName = row.getString("person.name");
|
|
|
+ }
|
|
|
|
|
|
- //获取上级(获取上级岗位中的人员作为上级)
|
|
|
- DynamicObject parentPosition = QueryServiceHelper.queryOne("hbpm_positionhr","parent.id as parentId",new QFilter[]{QFilterCommonHelper.getIdEqFilter(positionId)});
|
|
|
- positionFilter = new QFilter("position.id", QCP.equals, parentPosition.getLong("parentId"));
|
|
|
- DynamicObjectCollection superiorColl = PersonHelper.getDepEmpEffectivePerson("id,person.name",positionFilter);
|
|
|
+ if (personId == null) {
|
|
|
+ logger.warn("跳过人员ID为空的数据,索引:{}", i);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- //获取同级人员
|
|
|
- Set<Long> excludePersons = new HashSet<>(leadColl.size()+superiorColl.size());
|
|
|
- excludePersons.add(id);
|
|
|
- leadColl.forEach(dynamicObject -> excludePersons.add(dynamicObject.getLong(HonorStudentConstant.ID_KEY)));
|
|
|
- superiorColl.forEach(dynamicObject -> excludePersons.add(dynamicObject.getLong(HonorStudentConstant.ID_KEY)));
|
|
|
- DynamicObjectCollection peers = getPeers(adminOrgId,excludePersons, proportion,upper, lower, otherLower);
|
|
|
+ MainEntityType depempEntityType = EntityMetadataCache.getDataEntityType(PersonHelper.DEP_EMP_ENTITY_ID);
|
|
|
+ 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());
|
|
|
|
|
|
- System.out.println();
|
|
|
+
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+ if(callback != null) {
|
|
|
+ callback.onProgress(i);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- }catch (Exception e){
|
|
|
- logger.error("【职位体系】-生成综合评测问卷-异常",e);
|
|
|
+ }catch (KDBizException e){
|
|
|
+ logger.error("【优秀生考评】-生成综合评测问卷-业务异常",e);
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e){
|
|
|
+ logger.error("【优秀生考评】-生成综合评测问卷-系统异常",e);
|
|
|
+ throw e;
|
|
|
}
|
|
|
- logger.info("【职位体系】-生成综合评测问卷-结束");
|
|
|
+ logger.info("【优秀生考评】-生成综合评测问卷-结束");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取同级人员
|
|
|
- * 1.最新一条党政职务履历为副处级及以上人员不作为同级取数
|
|
|
- * 2.工作性质大类过滤掉编码为H01(居休)、H02(退养)、H03(随任)、H04(女工长假)、H05(长期工伤病休)、H06(长期病休)、H07(其他不在岗)、J(外派)的员工,不做为同级
|
|
|
- * 3.除去领导和上级
|
|
|
- * 4.入职超半年、职位非协理员
|
|
|
- * @param adminOrgId 当前组织ID
|
|
|
- * @param excludePersons 排除的ID
|
|
|
- * @return: kd.bos.dataentity.entity.DynamicObjectCollection
|
|
|
+ * 获取预计参与问卷打分的用户列表
|
|
|
+ * @param person 评分人员
|
|
|
+ * @param proportion 其他同级评分人比例
|
|
|
+ * @param upper 同级评分人上限人数
|
|
|
+ * @param lower 同级评分人下限人数
|
|
|
+ * @param otherLower 根据比例计算出的其他部门同级评分人的最小人数(同级评分人下限人数*其他同级评分人比例/100=其他同级评分人下限人数)
|
|
|
+ * @param isLeadAndSuperior 是否获取上级和领导
|
|
|
+ * @return: void
|
|
|
* @author W.Y.C
|
|
|
- * @date: 2025/07/08 17:48
|
|
|
+ * @date: 2025/07/10 17:38
|
|
|
*/
|
|
|
- private static DynamicObjectCollection getPeers(Long adminOrgId,Set<Long> excludePersons,int proportion,int upper,int lower,int otherLower){
|
|
|
+ public static DynamicObjectCollection fetchExpectedScorers(DynamicObject person,int proportion,int upper,int lower,int otherLower,boolean isLeadAndSuperior) {
|
|
|
+ Long personId = null;
|
|
|
+ if(person.containsProperty(FormConstant.BASEDATAID_KEY)){
|
|
|
+ //获取页面选择的数据可能会被存放在fbasedataid中
|
|
|
+ DynamicObject depEmpRow = (DynamicObject)person.getDynamicObject(FormConstant.BASEDATAID_KEY);
|
|
|
+ if (depEmpRow == null) {
|
|
|
+ logger.warn("获取人员信息失败,BASEDATAID_KEY为空");
|
|
|
+ return new DynamicObjectCollection();
|
|
|
+ }
|
|
|
+ personId = ConvertUtil.toLong(depEmpRow.getPkValue());
|
|
|
+ }else{
|
|
|
+ personId = person.getLong(HonorStudentConstant.ID_KEY);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (personId == null) {
|
|
|
+ logger.warn("人员ID为空");
|
|
|
+ return new DynamicObjectCollection();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> depEmp = HRPIDepempServiceHelper.getDepemp(personId);
|
|
|
+ if (depEmp == null) {
|
|
|
+ logger.warn("获取人员信息失败,人员ID:{}", personId);
|
|
|
+ return new DynamicObjectCollection();
|
|
|
+ }
|
|
|
+
|
|
|
+ Long id = ConvertUtil.toLong(depEmp.get(FormConstant.ID_KEY));
|
|
|
+ //获取当前人员的组织
|
|
|
+ Long adminOrgId = ConvertUtil.toLong(depEmp.get("adminorg_id"));
|
|
|
+ //获取当前人员的岗位
|
|
|
+ Long positionId = ConvertUtil.toLong(depEmp.get("position_id"));
|
|
|
+
|
|
|
+ DynamicObjectCollection leadColl = new DynamicObjectCollection();
|
|
|
+ DynamicObjectCollection superiorColl = new DynamicObjectCollection();
|
|
|
+ if(isLeadAndSuperior) {
|
|
|
+ //1:获取领导(获取上上级岗位中的人员作为领导)
|
|
|
+ DynamicObject parentParentPosition = QueryServiceHelper.queryOne("hbpm_positionhr", "parent.parent.id as parentId", new QFilter[]{QFilterCommonHelper.getIdEqFilter(positionId)});
|
|
|
+ if (parentParentPosition != null && parentParentPosition.getLong("parentId") != 0) {
|
|
|
+ QFilter positionFilter = new QFilter("position.id", QCP.equals, parentParentPosition.getLong("parentId"));
|
|
|
+ leadColl = PersonHelper.getDepEmpEffectivePerson("id,person.name", positionFilter);
|
|
|
+ }
|
|
|
+
|
|
|
+ //2:获取上级(获取上级岗位中的人员作为上级)
|
|
|
+ DynamicObject parentPosition = QueryServiceHelper.queryOne("hbpm_positionhr", "parent.id as parentId", new QFilter[]{QFilterCommonHelper.getIdEqFilter(positionId)});
|
|
|
+ if (parentPosition != null && parentPosition.getLong("parentId") != 0) {
|
|
|
+ QFilter positionFilter = new QFilter("position.id", QCP.equals, parentPosition.getLong("parentId"));
|
|
|
+ superiorColl = PersonHelper.getDepEmpEffectivePerson("id,person.name", positionFilter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
同级人数取数逻辑
|
|
|
│
|
|
@@ -124,38 +269,115 @@ public class CreateEvalQuestService {
|
|
|
│
|
|
|
├─ 1:查询当前组织内的同级员工(排除上级、自己)
|
|
|
│ ├─ 1.1:若人数 >= lower → 只取前 upper 个
|
|
|
- │ └─ 1.2:否则 继续向上级组织查找(最多 10 层)
|
|
|
+ │ └─ 1.2:否则 继续向上级组织查找【上级组织的人员】(最多 10 层)
|
|
|
│
|
|
|
├─ 2:查询同级其他部门在职人员
|
|
|
+ │ ├─ 2.1:若人数 >= otherLower → 只取前 otherLower 个
|
|
|
+ │ └─ 2.2:否则 继续向上级组织查找【上级组织下所有组织的人员】(最多 10 层)
|
|
|
│
|
|
|
└─ 返回最终的同级评分人列表
|
|
|
*/
|
|
|
+ //3:查询当前组织内的同级员工
|
|
|
+ Set<Long> excludePersons = new HashSet<>();
|
|
|
+ excludePersons.add(id);
|
|
|
+ if(isLeadAndSuperior) {
|
|
|
+ leadColl.forEach(dynamicObject -> excludePersons.add(dynamicObject.getLong(HonorStudentConstant.ID_KEY)));
|
|
|
+ superiorColl.forEach(dynamicObject -> excludePersons.add(dynamicObject.getLong(HonorStudentConstant.ID_KEY)));
|
|
|
+ }
|
|
|
+ DynamicObjectCollection peers = getPeers(adminOrgId,excludePersons, proportion,upper, lower, otherLower);
|
|
|
+ peers.forEach(dynamicObject -> excludePersons.add(dynamicObject.getLong(HonorStudentConstant.ID_KEY)));
|
|
|
+
|
|
|
+ //4:同级其他部门在职人员
|
|
|
+ DynamicObjectCollection otherPeers = new DynamicObjectCollection();
|
|
|
+ if(otherLower > 0) {
|
|
|
+ otherPeers = getOtherPeers(adminOrgId, excludePersons, otherLower);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 主单据创建
|
|
|
+ DynamicObject mainObj = BusinessDataServiceHelper.newDynamicObject(HonorStudentConstant.NCKD_EVALQUEST);
|
|
|
+ //分录创建
|
|
|
+ DynamicObjectCollection entryEntity = mainObj.getDynamicObjectCollection(HonorStudentConstant.NCKD_EVALQUESTENTRY);
|
|
|
+ ////1:领导、2:上级、3:同级
|
|
|
+ if(isLeadAndSuperior) {
|
|
|
+ builderEvalQuestEntry(leadColl, "1", entryEntity);
|
|
|
+ builderEvalQuestEntry(superiorColl, "2", entryEntity);
|
|
|
+ }
|
|
|
+ builderEvalQuestEntry(peers, "3", entryEntity);
|
|
|
+ builderEvalQuestEntry(otherPeers, "3", entryEntity);
|
|
|
+
|
|
|
+
|
|
|
+ return entryEntity;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final int MAX_RECURSION_DEPTH = 10;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取同级人员
|
|
|
+ * 1.最新一条党政职务履历为副处级及以上人员不作为同级取数
|
|
|
+ * 2.工作性质大类过滤掉编码为H01(居休)、H02(退养)、H03(随任)、H04(女工长假)、H05(长期工伤病休)、H06(长期病休)、H07(其他不在岗)、J(外派)的员工,不做为同级
|
|
|
+ * 3.除去领导和上级
|
|
|
+ * 4.入职超半年、职位非协理员
|
|
|
+ * @param adminOrgId 当前组织ID
|
|
|
+ * @param excludePersons 排除的ID
|
|
|
+ * @return: kd.bos.dataentity.entity.DynamicObjectCollection
|
|
|
+ * @author W.Y.C
|
|
|
+ * @date: 2025/07/08 17:48
|
|
|
+ */
|
|
|
+ private static DynamicObjectCollection getPeers(Long adminOrgId,Set<Long> excludePersons,int proportion,int upper,int lower,int otherLower){
|
|
|
//最终的结果
|
|
|
DynamicObjectCollection finalResult = new DynamicObjectCollection();
|
|
|
|
|
|
//------ 基本条件 begin------
|
|
|
- QFilter baseFilter = new QFilter(HonorStudentConstant.ID_KEY, QCP.not_in, excludePersons);
|
|
|
- //入职超半年
|
|
|
- baseFilter.and(new QFilter("startdate",QCP.less_equals, DateUtil.minusMonths(DateUtil.now(),6)));
|
|
|
- //职位非协理员
|
|
|
- baseFilter.and(new QFilter("position.name", QCP.not_like, "%协理员%"));
|
|
|
+ QFilter baseFilter = getBaseFilter(excludePersons);
|
|
|
//------ 基本条件 end------
|
|
|
|
|
|
//1.查询当前组织内的同级员工
|
|
|
QFilter adminOrgFilter = new QFilter("adminorg.id", QCP.equals, adminOrgId);
|
|
|
DynamicObjectCollection depEmpEffectivePerson = PersonHelper.getDepEmpEffectivePerson("id,person.name", baseFilter, adminOrgFilter);
|
|
|
|
|
|
- //当前组织人数小于下限人数,继续向上级组织查找直到 >= lower
|
|
|
+ //2.当前组织人数小于下限人数,继续向上级组织查找直到 >= lower
|
|
|
if(depEmpEffectivePerson.size() < lower){
|
|
|
- recursionGetParentPeers(adminOrgId, depEmpEffectivePerson, baseFilter, lower, 1);
|
|
|
+ Integer count = recursionGetPeers(adminOrgId, depEmpEffectivePerson, baseFilter, lower, 1);
|
|
|
+ logger.info("【优秀生考评】-向上级组织查找次数:{}",count);
|
|
|
}
|
|
|
- //截取前 upper 个同级人员
|
|
|
+ //打乱顺序随机抽取前 upper 个
|
|
|
Collections.shuffle(depEmpEffectivePerson);
|
|
|
- List<DynamicObject> dynamicObjects = depEmpEffectivePerson.subList(0, depEmpEffectivePerson.size() > upper ? upper-1 : depEmpEffectivePerson.size() -1);
|
|
|
+ int endIndex = Math.min(depEmpEffectivePerson.size(), upper);
|
|
|
+ List<DynamicObject> dynamicObjects = depEmpEffectivePerson.subList(0, endIndex);
|
|
|
finalResult.addAll(dynamicObjects);
|
|
|
|
|
|
- //2.查询同级其他部门在职人员
|
|
|
+ return finalResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询同级行政组织下的人员(排除同级确认的人员)
|
|
|
+ * @param adminOrgId 当前人员的行政组织id
|
|
|
+ * @param excludePersons 需要排除的人员
|
|
|
+ * @param otherLower
|
|
|
+ * @return: kd.bos.dataentity.entity.DynamicObjectCollection
|
|
|
+ * @author W.Y.C
|
|
|
+ * @date: 2025/07/10 15:14
|
|
|
+ */
|
|
|
+ private static DynamicObjectCollection getOtherPeers(Long adminOrgId,Set<Long> excludePersons,int otherLower){
|
|
|
+ //最终的结果
|
|
|
+ DynamicObjectCollection finalResult = new DynamicObjectCollection();
|
|
|
|
|
|
+ //------ 基本条件 begin------
|
|
|
+ QFilter baseFilter = getBaseFilter(excludePersons);
|
|
|
+ //------ 基本条件 end------
|
|
|
+ Long parentOrg = AdminOrgHelper.getParentOrg(adminOrgId);
|
|
|
+ QFilter adminOrgFilter = new QFilter("adminorg.parent.id", QCP.equals, parentOrg);
|
|
|
+ adminOrgFilter.and(new QFilter("adminorg.id", QCP.not_equals, adminOrgId));
|
|
|
+ DynamicObjectCollection depEmpEffectivePerson = PersonHelper.getDepEmpEffectivePerson("id,person.name,adminorg.name", baseFilter, adminOrgFilter);
|
|
|
+ if(depEmpEffectivePerson.size() < otherLower){
|
|
|
+ Integer count = recursionGetParentPeers(parentOrg, depEmpEffectivePerson, baseFilter, otherLower, 1);
|
|
|
+ logger.info("【优秀生考评】-向上级组织查找次数:{}",count);
|
|
|
+ }
|
|
|
+ Collections.shuffle(depEmpEffectivePerson);
|
|
|
+ int endIndex = Math.min(depEmpEffectivePerson.size(), otherLower);
|
|
|
+ List<DynamicObject> dynamicObjects = depEmpEffectivePerson.subList(0, endIndex);
|
|
|
+ finalResult.addAll(dynamicObjects);
|
|
|
return finalResult;
|
|
|
}
|
|
|
|
|
@@ -170,19 +392,108 @@ public class CreateEvalQuestService {
|
|
|
* @author W.Y.C
|
|
|
* @date: 2025/07/09 16:03
|
|
|
*/
|
|
|
- private static void recursionGetParentPeers(Long adminOrgId,DynamicObjectCollection persons,QFilter baseFilter,int lower,Integer count){
|
|
|
+ private static Integer recursionGetPeers(Long adminOrgId,DynamicObjectCollection persons,QFilter baseFilter,int lower,Integer count){
|
|
|
+ if(count > MAX_RECURSION_DEPTH) {
|
|
|
+ logger.warn("达到最大递归深度{}, 组织ID: {}", MAX_RECURSION_DEPTH, adminOrgId);
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
Long parentOrg = AdminOrgHelper.getParentOrg(adminOrgId);
|
|
|
if(parentOrg == null){
|
|
|
- return;
|
|
|
+ return count;
|
|
|
}
|
|
|
+ // 创建一个查询条件,用于筛选属于上级组织的人员
|
|
|
QFilter adminOrgFilter = new QFilter("adminorg.id", QCP.equals, parentOrg);
|
|
|
- DynamicObjectCollection depEmpEffectivePerson = PersonHelper.getDepEmpEffectivePerson("id,person.name", baseFilter, adminOrgFilter);
|
|
|
+ DynamicObjectCollection depEmpEffectivePerson = PersonHelper.getDepEmpEffectivePerson("id,person.name,adminorg.name", baseFilter, adminOrgFilter);
|
|
|
persons.addAll(depEmpEffectivePerson);
|
|
|
- if(persons.size() >= lower || count > 10){
|
|
|
- return;
|
|
|
+ if(persons.size() >= lower || count > MAX_RECURSION_DEPTH){
|
|
|
+ return count;
|
|
|
}else{
|
|
|
count++;
|
|
|
- recursionGetParentPeers(parentOrg,persons,baseFilter,lower,count);
|
|
|
+ if(count == MAX_RECURSION_DEPTH) {
|
|
|
+ logger.warn("即将达到最大递归深度, 组织ID: {}", adminOrgId);
|
|
|
+ }
|
|
|
+ return recursionGetPeers(parentOrg,persons,baseFilter,lower,count);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归获取指定管理组织及其所有上级管理组织下的有效人员
|
|
|
+ *
|
|
|
+ * 该方法从指定的管理组织开始,向上遍历其所有上级管理组织,并收集每个管理组织下的有效人员
|
|
|
+ * 直到达到指定的人员数量下限或超过最大递归深度时停止
|
|
|
+ *
|
|
|
+ * @param adminOrgId 当前管理组织的ID,用于启动递归
|
|
|
+ * @param persons 用于存储收集到的所有有效人员的集合
|
|
|
+ * @param baseFilter 基础过滤条件,用于筛选有效人员
|
|
|
+ * @param lower 人员数量下限,当收集到的人员数量达到或超过这个值时停止递归
|
|
|
+ * @param count 当前递归计数,用于防止无限递归,最大为10
|
|
|
+ * @return: java.lang.Integer
|
|
|
+ * @author W.Y.C
|
|
|
+ * @date: 2025/07/10 16:02
|
|
|
+ */
|
|
|
+ private static Integer recursionGetParentPeers(Long adminOrgId,DynamicObjectCollection persons,QFilter baseFilter,int lower,Integer count){
|
|
|
+ if(count > MAX_RECURSION_DEPTH) {
|
|
|
+ logger.warn("达到最大递归深度{}, 组织ID: {}", MAX_RECURSION_DEPTH, adminOrgId);
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long parentOrg = AdminOrgHelper.getParentOrg(adminOrgId);
|
|
|
+ if(parentOrg == null){
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+ // 构建用于筛选上级管理组织下有效人员的过滤条件
|
|
|
+ QFilter adminOrgFilter = new QFilter("adminorg.parent.id", QCP.equals, parentOrg);
|
|
|
+ DynamicObjectCollection depEmpEffectivePerson = PersonHelper.getDepEmpEffectivePerson("id,person.name,adminorg.name", baseFilter, adminOrgFilter);
|
|
|
+ persons.addAll(depEmpEffectivePerson);
|
|
|
+ if(persons.size() >= lower || count > MAX_RECURSION_DEPTH){
|
|
|
+ return count;
|
|
|
+ }else{
|
|
|
+ count++;
|
|
|
+ if(count == MAX_RECURSION_DEPTH) {
|
|
|
+ logger.warn("即将达到最大递归深度, 组织ID: {}", adminOrgId);
|
|
|
+ }
|
|
|
+ return recursionGetParentPeers(parentOrg,persons,baseFilter,lower,count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建问卷分录
|
|
|
+ * @param persons 评分人
|
|
|
+ * @param perfPlanRole 评分角色
|
|
|
+ * @param entryEntity 分录集合
|
|
|
+ * @return: void
|
|
|
+ * @author W.Y.C
|
|
|
+ * @date: 2025/07/13 18:52
|
|
|
+ */
|
|
|
+ private static void builderEvalQuestEntry(DynamicObjectCollection persons,String perfPlanRole,DynamicObjectCollection entryEntity){
|
|
|
+ persons.forEach(dynamicObject -> {
|
|
|
+ DynamicObject evalQuest = entryEntity.addNew();
|
|
|
+ long depEmpId = dynamicObject.getLong(HonorStudentConstant.ID_KEY);
|
|
|
+ evalQuest.set(HonorStudentConstant.NCKD_PERSON, depEmpId);
|
|
|
+ evalQuest.set(HonorStudentConstant.NCKD_PERFPLANROLE, perfPlanRole);
|
|
|
+ //获取任职经历
|
|
|
+ Map<String, Object> empOrgRel = HRPIDepempServiceHelper.getDataEmpOrgrel(depEmpId);
|
|
|
+ Long companyId = ConvertUtil.toLong(empOrgRel.get("company_id"));
|
|
|
+ Long jobId = ConvertUtil.toLong(empOrgRel.get("job_id"));
|
|
|
+ evalQuest.set(HonorStudentConstant.NCKD_COMPANY, companyId);
|
|
|
+ evalQuest.set(HonorStudentConstant.NCKD_JOB, jobId);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询人员基本条件
|
|
|
+ * @param excludePersons
|
|
|
+ * @return: kd.bos.orm.query.QFilter
|
|
|
+ * @author W.Y.C
|
|
|
+ * @date: 2025/07/10 11:34
|
|
|
+ */
|
|
|
+ private static QFilter getBaseFilter(Set<Long> excludePersons){
|
|
|
+ QFilter baseFilter = new QFilter(HonorStudentConstant.ID_KEY, QCP.not_in, excludePersons);
|
|
|
+ //入职超半年
|
|
|
+ baseFilter.and(new QFilter("startdate",QCP.less_equals, DateUtil.minusMonths(DateUtil.now(),6)));
|
|
|
+ //职位非协理员
|
|
|
+ baseFilter.and(new QFilter("position.name", QCP.not_like, "%协理员%"));
|
|
|
+ return baseFilter;
|
|
|
+ }
|
|
|
}
|