2024-09-06 17:37:31 +08:00
|
|
|
package com.gunshi.project.xyt.service;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
2024-09-09 14:14:31 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
2024-09-06 17:37:31 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
2024-09-11 14:03:44 +08:00
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
2024-09-06 17:37:31 +08:00
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
2024-09-11 14:03:44 +08:00
|
|
|
import com.gunshi.project.xyt.entity.so.AssessTaskPageSo;
|
2024-09-09 14:14:31 +08:00
|
|
|
import com.gunshi.project.xyt.entity.vo.AssessRatingVo;
|
2024-09-11 14:03:44 +08:00
|
|
|
import com.gunshi.project.xyt.entity.vo.AssessRectifyVo;
|
2024-09-09 14:14:31 +08:00
|
|
|
import com.gunshi.project.xyt.entity.vo.AssessScoreVo;
|
|
|
|
|
import com.gunshi.project.xyt.mapper.*;
|
|
|
|
|
import com.gunshi.project.xyt.model.*;
|
2024-09-06 17:37:31 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
2024-09-09 14:14:31 +08:00
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.RoundingMode;
|
2024-09-10 15:08:27 +08:00
|
|
|
import java.util.ArrayList;
|
2024-09-06 17:37:31 +08:00
|
|
|
import java.util.List;
|
2024-09-10 09:27:05 +08:00
|
|
|
import java.util.Map;
|
2024-09-10 15:08:27 +08:00
|
|
|
import java.util.Objects;
|
2024-09-09 14:14:31 +08:00
|
|
|
import java.util.stream.Collectors;
|
2024-09-06 17:37:31 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 描述: 考核评分详情
|
|
|
|
|
* author: xusan
|
|
|
|
|
* date: 2024-09-05 14:20:04
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper, AssessTeamRating>
|
|
|
|
|
{
|
|
|
|
|
@Autowired
|
|
|
|
|
private FileAssociationsService fileService;
|
|
|
|
|
|
2024-09-09 14:14:31 +08:00
|
|
|
@Autowired
|
|
|
|
|
private AssessObjectMapper objectMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AssessTaskMapper taskMapper;
|
|
|
|
|
|
2024-09-06 17:37:31 +08:00
|
|
|
@Autowired
|
|
|
|
|
private AssessTeamMapper teamMapper;
|
|
|
|
|
|
2024-09-09 14:14:31 +08:00
|
|
|
@Autowired
|
|
|
|
|
private AssessTemplateMapper templateMapper;
|
|
|
|
|
|
2024-09-10 15:08:27 +08:00
|
|
|
@Autowired
|
|
|
|
|
private AssessObjectRatingService assessObjectRatingService;
|
|
|
|
|
|
2024-09-06 17:37:31 +08:00
|
|
|
|
2024-09-09 14:14:31 +08:00
|
|
|
public Boolean score(AssessScoreVo vo) {
|
|
|
|
|
List<AssessTeamRating> ratings = vo.getRatings();
|
|
|
|
|
Long teamId = ratings.get(0).getTeamId();
|
|
|
|
|
this.delData(teamId);
|
|
|
|
|
for(AssessTeamRating rating : ratings){
|
2024-09-06 17:37:31 +08:00
|
|
|
rating.setId(IdWorker.getId());
|
2024-09-11 14:03:44 +08:00
|
|
|
fileService.save(rating.getFiles(), rating.getId().toString(), getGroupId(),getScoreType());
|
2024-09-06 17:37:31 +08:00
|
|
|
}
|
2024-09-09 14:14:31 +08:00
|
|
|
AssessTask task = taskMapper.selectById(vo.getTaskId());
|
2024-09-06 17:37:31 +08:00
|
|
|
//更新该考核人员对考核对象的状态为已评分
|
|
|
|
|
AssessTeam assessTeam = teamMapper.selectById(teamId);
|
|
|
|
|
assessTeam.setStatus(2);
|
2024-09-09 14:14:31 +08:00
|
|
|
//获取模板信息
|
|
|
|
|
AssessTemplate template = templateMapper.selectById(task.getTemplateId());
|
|
|
|
|
//根据总得分计算等级
|
|
|
|
|
Integer level = calcLevel(template,vo.getScore());
|
|
|
|
|
assessTeam.setAssessScore(vo.getScore());
|
|
|
|
|
assessTeam.setAssessLevel(level);
|
2024-09-06 17:37:31 +08:00
|
|
|
teamMapper.updateById(assessTeam);
|
2024-09-10 15:08:27 +08:00
|
|
|
Boolean res = this.saveBatch(ratings);
|
2024-09-09 14:14:31 +08:00
|
|
|
updateObjectAndTask(assessTeam.getObjectId(),vo.getTaskId(),template,task);
|
2024-09-10 15:08:27 +08:00
|
|
|
return res;
|
2024-09-09 14:14:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void delData(Long teamId) {
|
|
|
|
|
List<AssessTeamRating> teamRatings = this.list(new QueryWrapper<AssessTeamRating>().eq("team_id", teamId));
|
|
|
|
|
if(CollectionUtils.isNotEmpty(teamRatings)){
|
2024-09-10 15:08:27 +08:00
|
|
|
List<String> ratingIds = teamRatings.stream().map(AssessTeamRating::getId).map(Objects::toString).collect(Collectors.toList());
|
2024-09-09 14:14:31 +08:00
|
|
|
fileService.remove(new QueryWrapper<FileAssociations>().in("business_id",ratingIds));
|
|
|
|
|
this.remove(new QueryWrapper<AssessTeamRating>().eq("team_id", teamId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Integer calcLevel(AssessTemplate template, BigDecimal score) {
|
|
|
|
|
BigDecimal excellentScore = template.getExcellentScore();
|
|
|
|
|
BigDecimal goodScore = template.getGoodScore();
|
|
|
|
|
BigDecimal passScore = template.getPassScore();
|
|
|
|
|
if(score.compareTo(excellentScore) >= 0){
|
|
|
|
|
return 1;
|
|
|
|
|
}else if(score.compareTo(goodScore) >=0 && score.compareTo(excellentScore) < 0){
|
|
|
|
|
return 2;
|
|
|
|
|
}else if(score.compareTo(passScore) >=0 && score.compareTo(goodScore) < 0){
|
|
|
|
|
return 3;
|
|
|
|
|
}else{
|
|
|
|
|
return 4;
|
|
|
|
|
}
|
2024-09-06 17:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-09 14:14:31 +08:00
|
|
|
private void updateObjectAndTask(Long objectId, Long taskId,AssessTemplate template,AssessTask task) {
|
2024-09-06 17:37:31 +08:00
|
|
|
//先判断该次评分是否是该考核对象的最后一次评分
|
2024-09-09 14:14:31 +08:00
|
|
|
//如果为最后一次评分,就要计算该考核对象的最终得分
|
|
|
|
|
List<AssessTeam> teams = teamMapper.selectList(new QueryWrapper<AssessTeam>().eq("object_id", objectId).eq("task_id", taskId));
|
|
|
|
|
List<AssessTeam> finishTeams = teams.stream().filter(o -> o.getStatus() == 2).collect(Collectors.toList());
|
|
|
|
|
if(teams.size() == finishTeams.size()){
|
|
|
|
|
Integer scoreWay = task.getScoreWay();
|
2024-09-10 09:27:05 +08:00
|
|
|
List<Long> teamIds = finishTeams.stream().map(AssessTeam::getId).collect(Collectors.toList());
|
2024-09-10 15:08:27 +08:00
|
|
|
BigDecimal assessScore = calcScore(scoreWay,teamIds,objectId);
|
2024-09-09 14:14:31 +08:00
|
|
|
Integer level = calcLevel(template, assessScore);
|
|
|
|
|
AssessObject object = objectMapper.selectById(objectId);
|
|
|
|
|
object.setStatus(2);
|
|
|
|
|
object.setAssessScore(assessScore);
|
|
|
|
|
object.setAssessLevel(level);
|
|
|
|
|
objectMapper.updateById(object);
|
|
|
|
|
//判断该考核任务是否存在未打分的对象,不存在则更新考核任务的状态为已完成
|
|
|
|
|
Long taskCount = objectMapper.selectCount(new QueryWrapper<AssessObject>().eq("task_id", taskId).eq("status", 1));
|
|
|
|
|
if(taskCount == 0){
|
|
|
|
|
task.setStatus(2);
|
|
|
|
|
taskMapper.updateById(task);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-06 17:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-10 15:08:27 +08:00
|
|
|
private BigDecimal calcScore(Integer scoreWay, List<Long> teamIds,Long objectId) {
|
|
|
|
|
final BigDecimal[] score = {new BigDecimal(0)};
|
2024-09-10 09:27:05 +08:00
|
|
|
List<AssessTeamRating> ratings = this.list(new QueryWrapper<AssessTeamRating>().in("team_id",teamIds));
|
|
|
|
|
Map<Long, List<BigDecimal>> map = ratings.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId,Collectors.mapping(AssessTeamRating::getAssessScore,Collectors.toList())));
|
2024-09-10 15:08:27 +08:00
|
|
|
Map<Long, List<Integer>> standardMap = ratings.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId,Collectors.mapping(AssessTeamRating::getStandardScore,Collectors.toList())));
|
|
|
|
|
List<AssessObjectRating> list = new ArrayList<>();
|
2024-09-10 09:27:05 +08:00
|
|
|
map.entrySet().forEach(o->{
|
|
|
|
|
List<BigDecimal> value = o.getValue();
|
2024-09-10 15:08:27 +08:00
|
|
|
AssessObjectRating objectRating = new AssessObjectRating();
|
|
|
|
|
objectRating.setId(IdWorker.getId());
|
|
|
|
|
objectRating.setObjectId(objectId);
|
|
|
|
|
objectRating.setIndicatorId(o.getKey());
|
|
|
|
|
objectRating.setStandardScore(standardMap.get(o.getKey()).get(0));
|
2024-09-10 09:27:05 +08:00
|
|
|
if (scoreWay == 1){
|
2024-09-10 15:08:27 +08:00
|
|
|
BigDecimal val = value.stream().min(BigDecimal::compareTo).get();
|
|
|
|
|
objectRating.setAssessScore(val);
|
|
|
|
|
score[0] = score[0].add(val);
|
2024-09-10 09:27:05 +08:00
|
|
|
}else{
|
2024-09-10 15:08:27 +08:00
|
|
|
BigDecimal vide = value.stream().reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(value.size()), 2, RoundingMode.HALF_UP);
|
|
|
|
|
objectRating.setAssessScore(vide);
|
|
|
|
|
score[0] = score[0].add(vide);
|
2024-09-10 09:27:05 +08:00
|
|
|
}
|
2024-09-10 15:08:27 +08:00
|
|
|
list.add(objectRating);
|
2024-09-10 09:27:05 +08:00
|
|
|
});
|
2024-09-10 15:08:27 +08:00
|
|
|
assessObjectRatingService.saveBatch(list);
|
|
|
|
|
return score[0];
|
2024-09-10 09:27:05 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-06 17:37:31 +08:00
|
|
|
public String getGroupId() {
|
|
|
|
|
return "assessTeamRating";
|
|
|
|
|
}
|
2024-09-09 14:14:31 +08:00
|
|
|
|
2024-09-11 14:03:44 +08:00
|
|
|
public String getScoreType() {
|
|
|
|
|
return "assessScore";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getRectifyType() {
|
|
|
|
|
return "assessRectify";
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-10 09:27:05 +08:00
|
|
|
public List<AssessRatingVo> doDetail(Long teamId) {
|
2024-09-09 14:14:31 +08:00
|
|
|
List<AssessRatingVo> list = this.baseMapper.scoreDetail(teamId);
|
|
|
|
|
for (AssessRatingVo vo : list){
|
|
|
|
|
if(vo.getIsNeedRectify() == 1){
|
2024-09-11 14:03:44 +08:00
|
|
|
vo.setFiles(fileService.queryFileList(vo.getId().toString(),getGroupId(),getScoreType()));
|
2024-09-09 14:14:31 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean saveScore(AssessScoreVo vo) {
|
|
|
|
|
List<AssessTeamRating> ratings = vo.getRatings();
|
|
|
|
|
for(AssessTeamRating rating : ratings){
|
|
|
|
|
rating.setId(IdWorker.getId());
|
2024-09-11 14:03:44 +08:00
|
|
|
fileService.save(rating.getFiles(), rating.getId().toString(), getGroupId(),getScoreType());
|
2024-09-09 14:14:31 +08:00
|
|
|
}
|
|
|
|
|
Long teamId = ratings.get(0).getTeamId();
|
2024-09-10 17:33:31 +08:00
|
|
|
this.delData(teamId);
|
2024-09-09 14:14:31 +08:00
|
|
|
AssessTeam assessTeam = teamMapper.selectById(teamId);
|
2024-09-10 17:33:31 +08:00
|
|
|
assessTeam.setAssessScore(vo.getScore());
|
2024-09-09 14:14:31 +08:00
|
|
|
assessTeam.setStatus(9);
|
|
|
|
|
teamMapper.updateById(assessTeam);
|
2024-09-10 17:33:31 +08:00
|
|
|
return this.saveOrUpdateBatch(ratings);
|
2024-09-09 14:14:31 +08:00
|
|
|
}
|
2024-09-10 09:27:05 +08:00
|
|
|
|
|
|
|
|
public Map<Long,List<AssessRatingVo>> scoreDetail(Long objectId) {
|
|
|
|
|
List<AssessRatingVo> list = this.baseMapper.scoreByObjectId(objectId);
|
|
|
|
|
return list.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId));
|
|
|
|
|
}
|
2024-09-11 14:03:44 +08:00
|
|
|
|
|
|
|
|
public Page<AssessRectifyVo> listPage(AssessTaskPageSo page) {
|
|
|
|
|
Page<AssessRectifyVo> res = this.baseMapper.listPage(page.getPageSo().toPage(), page);
|
|
|
|
|
if (res.getRecords() != null && res.getRecords().size() > 0) {
|
|
|
|
|
for (AssessRectifyVo record : res.getRecords()) {
|
|
|
|
|
record.setFiles(fileService.queryFileList(record.getId().toString(),getGroupId(),getScoreType()));
|
|
|
|
|
record.setRectifyFiles(fileService.queryFileList(record.getId().toString(),getGroupId(),getRectifyType()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String rectify(AssessTeamRating rating) {
|
|
|
|
|
rating.setRectifyStatus(1);
|
|
|
|
|
this.updateById(rating);
|
|
|
|
|
fileService.save(rating.getRectifyFiles(),rating.getId().toString(),getGroupId(),getRectifyType());
|
|
|
|
|
return "整改成功";
|
|
|
|
|
}
|
2024-09-06 17:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|