|
@@ -7,6 +7,7 @@ import com.huaxu.client.UserCenterClient;
|
|
|
import com.huaxu.evaluation.dao.*;
|
|
|
import com.huaxu.evaluation.entity.*;
|
|
|
import com.huaxu.evaluation.enums.EvaluationCycleEnums;
|
|
|
+import com.huaxu.evaluation.enums.EvaluationItemEnums;
|
|
|
import com.huaxu.evaluation.vo.EvaluationItemValueVo;
|
|
|
import com.huaxu.evaluation.vo.EvaluationItemVo;
|
|
|
import com.huaxu.evaluation.vo.EvaluationResultTaskDetailsVo;
|
|
@@ -27,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -65,6 +67,12 @@ public class EvaluationResultJob {
|
|
|
|
|
|
private static boolean lock = false;
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运维类型
|
|
|
+ */
|
|
|
+ private static final String OPERATION_TYPE = "3";
|
|
|
+
|
|
|
/**
|
|
|
* 保存考评项目设置
|
|
|
*/
|
|
@@ -78,7 +86,7 @@ public class EvaluationResultJob {
|
|
|
|
|
|
|
|
|
/***
|
|
|
- * @Scheduled(cron = "0/5 * * * * ?")
|
|
|
+ *@Scheduled(cron = "0/5 * * * * ?")
|
|
|
* 异步启动定时任务
|
|
|
* @Author lihui
|
|
|
* @Date 18:26 2021/5/17
|
|
@@ -102,7 +110,7 @@ public class EvaluationResultJob {
|
|
|
!EvaluationUtil.sameMonth(1)) {
|
|
|
continue;
|
|
|
}
|
|
|
- userTask(evaluationCycleEntity.getTenantId(), evaluationCycleEntity.getCompanyOrgId(), evaluationCycleEntity.getType());
|
|
|
+ userTask(evaluationCycleEntity, queryEntity.getEvaluationDay());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("绩效考评定时任务出错->", e);
|
|
@@ -114,26 +122,33 @@ public class EvaluationResultJob {
|
|
|
log.info("============绩效考评数据生成end=====================");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @Author lihui
|
|
|
- * @Description 用户任务分解
|
|
|
- * @Date 18:19 2021/5/10
|
|
|
- * @Param [tenantId:租户ID, companyOrgId : 公司ID, cycle : 类型(0月度 1季度 2年度)]
|
|
|
- * @return void
|
|
|
- **/
|
|
|
- public void userTask(String tenantId, Integer companyOrgId, Integer cycle){
|
|
|
- // 查询该租户公司下的所有用户
|
|
|
- String startTime = null;
|
|
|
- String endTime = null;
|
|
|
+ /***
|
|
|
+ * 用户任务分解
|
|
|
+ * @author lihui
|
|
|
+ * @date 10:44 2021/5/19
|
|
|
+ * @param evaluationCycleEntity : 考评
|
|
|
+ * @param evaluationDay : 考评周期
|
|
|
+ * @return void
|
|
|
+ **/
|
|
|
+ public void userTask(EvaluationCycleEntity evaluationCycleEntity, Integer evaluationDay){
|
|
|
List<EvaluationItemVo> itemEntityList = null;
|
|
|
- List<Integer> userIds = getUserIds(tenantId, companyOrgId);
|
|
|
+ Integer cycle = evaluationCycleEntity.getType();
|
|
|
+ // 根据类型(0月度 1季度 2年度)得到当前的开始时间和结束时间,如果是按季度,当月必须是1,4,7,10
|
|
|
+ String startTime = EvaluationUtil.getStartTime(cycle, evaluationDay);
|
|
|
+ String endTime = EvaluationUtil.getEndTime(cycle, evaluationDay);
|
|
|
+ if (startTime == null || endTime == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 查询该租户公司下的所有用户
|
|
|
+ List<Integer> userIds = getUserIds(evaluationCycleEntity.getTenantId(), evaluationCycleEntity.getCompanyOrgId());
|
|
|
Map<Long, UserEntity> userEntityMap = toMap(userIds);
|
|
|
if (userEntityMap == null) {
|
|
|
return;
|
|
|
}
|
|
|
for (Integer userId : userIds) {
|
|
|
UserEntity userEntity = userEntityMap.get(Long.parseLong(userId.toString()));
|
|
|
- if (userEntity == null) {
|
|
|
+ // 过滤掉不是运维的用户
|
|
|
+ if (userEntity == null || !OPERATION_TYPE.equals(userEntity.getUserType())) {
|
|
|
continue;
|
|
|
}
|
|
|
itemEntityList = findItem(userEntity);
|
|
@@ -143,12 +158,6 @@ public class EvaluationResultJob {
|
|
|
continue;
|
|
|
}
|
|
|
try {
|
|
|
- // 根据类型(0月度 1季度 2年度)得到当前的开始时间和结束时间,如果是按季度,当月必须是1,4,7,10
|
|
|
- startTime = EvaluationUtil.getStartTime(cycle, null, null);
|
|
|
- endTime = EvaluationUtil.getEndTime(cycle, null,null);
|
|
|
- if (startTime == null || endTime == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
// 保存用户考评结果
|
|
|
saveEvaluationResultInfo(userEntity, itemEntityList , startTime, endTime ,cycle);
|
|
|
} catch (Exception e) {
|
|
@@ -157,6 +166,14 @@ public class EvaluationResultJob {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /***
|
|
|
+ * 获取该租户公司下的用户
|
|
|
+ * @author lihui
|
|
|
+ * @date 10:49 2021/5/19
|
|
|
+ * @param tenantId : 租户ID
|
|
|
+ * @param companyOrgId : 公司id
|
|
|
+ * @return java.util.List<java.lang.Integer>
|
|
|
+ **/
|
|
|
private List<Integer> getUserIds(String tenantId, Integer companyOrgId){
|
|
|
String key = tenantId + "_" + companyOrgId;
|
|
|
List<Integer> result = userIdsMap.get(key);
|
|
@@ -177,11 +194,10 @@ public class EvaluationResultJob {
|
|
|
**/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void saveEvaluationResultInfo(UserEntity userEntity, List<EvaluationItemVo> itemEntityList, String startTime, String endTime, Integer cycle){
|
|
|
- Calendar calendar = EvaluationUtil.getCalendar(endTime);
|
|
|
// 计算用户完成任务情况
|
|
|
EvaluationResultTaskEntity taskDetailsVo = calculationTaskInfo(userEntity.getId().intValue(), userEntity.getTenantId(), startTime, endTime, getValueCondition(itemEntityList));
|
|
|
// 组装考评结果数据
|
|
|
- EvaluationResultEntity resultEntity = packagesEvaluationResultEntity(userEntity, calendar, cycle, startTime, endTime);
|
|
|
+ EvaluationResultEntity resultEntity = packagesEvaluationResultEntity(userEntity, cycle, startTime, endTime);
|
|
|
// 保存考评结果
|
|
|
if (evaluationResultMapper.insertEvaluationResult(resultEntity) != 1) {
|
|
|
throw new ServiceException(500, "保存考评结果出错,退出。");
|
|
@@ -198,11 +214,11 @@ public class EvaluationResultJob {
|
|
|
if (item.getCycle().indexOf(cycle.toString()) == -1 || item.getType() == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- evaluationValue = item.getType() == 1 ? completeCount : completionRate;
|
|
|
+ evaluationValue = item.getType() == EvaluationItemEnums.COMPLETE_COUNT.getType() ? completeCount : completionRate;
|
|
|
EvaluationResultDetailsEntity detailsEntity = new EvaluationResultDetailsEntity();
|
|
|
detailsEntity.setEvaluationResultId(resultId);
|
|
|
detailsEntity.setEvaluationItemId(item.getItemId());
|
|
|
- detailsEntity.setValue(getScore(item.getType(), item.getEvaluationItemValueVoList(), evaluationValue));
|
|
|
+ detailsEntity.setValue(getScore(item, evaluationValue));
|
|
|
detailsEntity.setDateCreate(new Date());
|
|
|
detailsEntity.setDateUpdate(new Date());
|
|
|
detailsEntity.setTenantId(userEntity.getTenantId());
|
|
@@ -285,10 +301,11 @@ public class EvaluationResultJob {
|
|
|
* @Param [userEntity, calendar, cycle, startTime, endTime]
|
|
|
* @return com.huaxu.evaluation.entity.EvaluationResultEntity
|
|
|
**/
|
|
|
- private EvaluationResultEntity packagesEvaluationResultEntity(UserEntity userEntity, Calendar calendar, Integer cycle, String startTime, String endTime){
|
|
|
+ private EvaluationResultEntity packagesEvaluationResultEntity(UserEntity userEntity, Integer cycle, String startTime, String endTime){
|
|
|
+ LocalDate localDate = EvaluationUtil.getLocalDateByCycle(startTime, endTime, cycle);
|
|
|
EvaluationResultEntity resultEntity = new EvaluationResultEntity();
|
|
|
- resultEntity.setYear(calendar.get(Calendar.YEAR));
|
|
|
- resultEntity.setMonth(calendar.get(Calendar.MONTH) + 1);
|
|
|
+ resultEntity.setYear(localDate.getYear());
|
|
|
+ resultEntity.setMonth(localDate.getMonthValue());
|
|
|
resultEntity.setEvaluationBe(userEntity.getUsername());
|
|
|
resultEntity.setEvaluationBeUserId(userEntity.getId());
|
|
|
resultEntity.setCycle(cycle);
|
|
@@ -311,23 +328,24 @@ public class EvaluationResultJob {
|
|
|
return userEntities.stream().collect(Collectors.toMap(UserEntity::getId, a -> a,(k1, k2)->k1));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @Author lihui
|
|
|
- * @Description 获取对应的分数
|
|
|
- * @Date 11:25 2021/5/14
|
|
|
- * @Param [type 0任务完成数 1任务按时完成率 2自定义, list, evaluationValue]
|
|
|
- * @return java.math.BigDecimal
|
|
|
- **/
|
|
|
- private BigDecimal getScore (Integer type, List<EvaluationItemValueVo> list, BigDecimal evaluationValue){
|
|
|
- int ziDingYi = 2;
|
|
|
- if (type != 1 && type != ziDingYi) {
|
|
|
- return null;
|
|
|
+ /***
|
|
|
+ * 获取对应的分数
|
|
|
+ * @Author lihui
|
|
|
+ * @Date 10:32 2021/5/19
|
|
|
+ * @param item : 考评项目设置内容
|
|
|
+ * @param evaluationValue : 统计到的分值
|
|
|
+ * @return java.math.BigDecimal
|
|
|
+ **/
|
|
|
+ private BigDecimal getScore (EvaluationItemVo item, BigDecimal evaluationValue){
|
|
|
+ // 如果是自定义直接返回默认分数
|
|
|
+ if (item.getType() == EvaluationItemEnums.CUSTOM.getType()) {
|
|
|
+ return item.getValue();
|
|
|
}
|
|
|
Integer itemType = null;
|
|
|
BigDecimal itemValue = null;
|
|
|
BigDecimal valueOne = null;
|
|
|
BigDecimal valueTwo = null;
|
|
|
- for (EvaluationItemValueVo evaluationItemValueVo: list) {
|
|
|
+ for (EvaluationItemValueVo evaluationItemValueVo: item.getEvaluationItemValueVoList()) {
|
|
|
itemType = evaluationItemValueVo.getItemType();
|
|
|
itemValue = evaluationItemValueVo.getItemValue();
|
|
|
valueOne = evaluationItemValueVo.getValueOne();
|