修正考核问题查询的sql

master
李一帆 2025-04-10 11:48:57 +08:00
parent 7bc6712180
commit 97632ce613
2 changed files with 56 additions and 40 deletions

View File

@ -56,7 +56,7 @@ public interface AssessTeamRatingMapper extends BaseMapper<AssessTeamRating> {
left join public.assess_task t5 on t1.task_id = t5.id
where t.is_need_rectify = 1 and t5.status = 3
<if test="obj.userId != null">
and t.object_id = #{obj.userId}
and t2.object_user_id = #{obj.userId}
</if>
<if test="obj.taskName != null and obj.taskName != ''">
and t5.task_name like concat('%', #{obj.taskName}::text, '%')

View File

@ -12,8 +12,14 @@ import com.gunshi.project.xyt.entity.vo.AssessRectifyVo;
import com.gunshi.project.xyt.entity.vo.AssessScoreVo;
import com.gunshi.project.xyt.mapper.*;
import com.gunshi.project.xyt.model.*;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -33,8 +39,7 @@ import java.util.stream.Collectors;
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper, AssessTeamRating>
{
public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper, AssessTeamRating> {
@Autowired
private FileAssociationsService fileService;
@ -57,17 +62,17 @@ public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper,
private AssessIndicatorRatingService indicatorRatingService;
public Boolean saveScore(AssessScoreVo vo) {
return commonScore(vo,9);
return commonScore(vo, 9);
}
private Boolean commonScore(AssessScoreVo vo,Integer status){
private Boolean commonScore(AssessScoreVo vo, Integer status) {
List<AssessTeamRating> ratings = vo.getRatings();
Long teamId = ratings.get(0).getTeamId();
this.delData(teamId);
for(AssessTeamRating rating : ratings){
for (AssessTeamRating rating : ratings) {
rating.setId(IdWorker.getId());
rating.setRectifyStatus(0);
fileService.save(rating.getFiles(), rating.getId().toString(), getGroupId(),getScoreType());
fileService.save(rating.getFiles(), rating.getId().toString(), getGroupId(), getScoreType());
}
AssessTask task = taskMapper.selectById(vo.getTaskId());
//更新该考核人员对考核对象的状态为已评分
@ -76,26 +81,26 @@ public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper,
//获取模板信息
AssessTemplate template = templateMapper.selectById(task.getTemplateId());
//根据总得分计算等级
Integer level = calcLevel(template,vo.getScore());
Integer level = calcLevel(template, vo.getScore());
assessTeam.setAssessScore(vo.getScore());
assessTeam.setAssessLevel(level);
teamMapper.updateById(assessTeam);
Boolean res = this.saveBatch(ratings);
if(status == 2){
updateObjectAndTask(assessTeam.getObjectId(),vo.getTaskId(),template,task);
if (status == 2) {
updateObjectAndTask(assessTeam.getObjectId(), vo.getTaskId(), template, task);
}
return res;
}
public Boolean score(AssessScoreVo vo) {
return commonScore(vo,2);
return commonScore(vo, 2);
}
private void delData(Long teamId) {
List<AssessTeamRating> teamRatings = this.list(new QueryWrapper<AssessTeamRating>().eq("team_id", teamId));
if(CollectionUtils.isNotEmpty(teamRatings)){
if (CollectionUtils.isNotEmpty(teamRatings)) {
List<String> ratingIds = teamRatings.stream().map(AssessTeamRating::getId).map(Objects::toString).collect(Collectors.toList());
fileService.remove(new QueryWrapper<FileAssociations>().in("business_id",ratingIds));
fileService.remove(new QueryWrapper<FileAssociations>().in("business_id", ratingIds));
this.remove(new QueryWrapper<AssessTeamRating>().eq("team_id", teamId));
}
}
@ -104,26 +109,26 @@ public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper,
BigDecimal excellentScore = template.getExcellentScore();
BigDecimal goodScore = template.getGoodScore();
BigDecimal passScore = template.getPassScore();
if(score.compareTo(excellentScore) >= 0){
if (score.compareTo(excellentScore) >= 0) {
return 1;
}else if(score.compareTo(goodScore) >=0 && score.compareTo(excellentScore) < 0){
} else if (score.compareTo(goodScore) >= 0 && score.compareTo(excellentScore) < 0) {
return 2;
}else if(score.compareTo(passScore) >=0 && score.compareTo(goodScore) < 0){
} else if (score.compareTo(passScore) >= 0 && score.compareTo(goodScore) < 0) {
return 3;
}else{
} else {
return 4;
}
}
private void updateObjectAndTask(Long objectId, Long taskId,AssessTemplate template,AssessTask task) {
private void updateObjectAndTask(Long objectId, Long taskId, AssessTemplate template, AssessTask task) {
//先判断该次评分是否是该考核对象的最后一次评分
//如果为最后一次评分,就要计算该考核对象的最终得分
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()){
if (teams.size() == finishTeams.size()) {
Integer scoreWay = task.getScoreWay();
List<Long> teamIds = finishTeams.stream().map(AssessTeam::getId).collect(Collectors.toList());
BigDecimal assessScore = calcScore(scoreWay,teamIds,objectId);
BigDecimal assessScore = calcScore(scoreWay, teamIds, objectId);
Integer level = calcLevel(template, assessScore);
AssessObject object = objectMapper.selectById(objectId);
object.setStatus(2);
@ -132,32 +137,32 @@ public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper,
objectMapper.updateById(object);
//判断该考核任务是否存在未打分的对象,不存在则更新考核任务的状态为已完成
Long taskCount = objectMapper.selectCount(new QueryWrapper<AssessObject>().eq("task_id", taskId).eq("status", 1));
if(taskCount == 0){
if (taskCount == 0) {
task.setStatus(2);
taskMapper.updateById(task);
}
}
}
private BigDecimal calcScore(Integer scoreWay, List<Long> teamIds,Long objectId) {
assessObjectRatingService.remove(new QueryWrapper<AssessObjectRating>().eq("object_id",objectId));
private BigDecimal calcScore(Integer scoreWay, List<Long> teamIds, Long objectId) {
assessObjectRatingService.remove(new QueryWrapper<AssessObjectRating>().eq("object_id", objectId));
final BigDecimal[] score = {new BigDecimal(0)};
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())));
Map<Long, List<Integer>> standardMap = ratings.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId,Collectors.mapping(AssessTeamRating::getStandardScore,Collectors.toList())));
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())));
Map<Long, List<Integer>> standardMap = ratings.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId, Collectors.mapping(AssessTeamRating::getStandardScore, Collectors.toList())));
List<AssessObjectRating> list = new ArrayList<>();
map.entrySet().forEach(o->{
map.entrySet().forEach(o -> {
List<BigDecimal> value = o.getValue();
AssessObjectRating objectRating = new AssessObjectRating();
objectRating.setId(IdWorker.getId());
objectRating.setObjectId(objectId);
objectRating.setIndicatorId(o.getKey());
objectRating.setStandardScore(standardMap.get(o.getKey()).get(0));
if (scoreWay == 1){
if (scoreWay == 1) {
BigDecimal val = value.stream().min(BigDecimal::compareTo).get();
objectRating.setAssessScore(val);
score[0] = score[0].add(val);
}else{
} else {
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);
@ -168,7 +173,7 @@ public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper,
return score[0];
}
public void saveObjectRating(List<AssessObjectRating> list){
public void saveObjectRating(List<AssessObjectRating> list) {
assessObjectRatingService.saveBatch(list);
}
@ -191,30 +196,41 @@ public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper,
}
public Map<Long,List<AssessRatingVo>> scoreDetail(Long objectId) {
public Map<Long, List<AssessRatingVo>> scoreDetail(Long objectId) {
List<AssessRatingVo> list = this.baseMapper.scoreByObjectId(objectId);
fillRating(list);
return list.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId));
}
private void fillRating(List<AssessRatingVo> list){
private void fillRating(List<AssessRatingVo> list) {
List<AssessIndicatorRating> relList = indicatorRatingService.queryRatingList(list.stream().map(AssessRatingVo::getIndicatorId).distinct().collect(Collectors.toList()));
Map<Long, List<AssessIndicatorRating>> map = relList.stream().collect(Collectors.groupingBy(AssessIndicatorRating::getIndicatorId));
for (AssessRatingVo vo : list){
for (AssessRatingVo vo : list) {
vo.setIndicatorRatings(map.get(vo.getIndicatorId()));
if(vo.getIsNeedRectify() != null && vo.getIsNeedRectify() == 1){
vo.setFiles(fileService.queryFileList(vo.getId().toString(),getGroupId(),getScoreType()));
if (vo.getIsNeedRectify() != null && vo.getIsNeedRectify() == 1) {
vo.setFiles(fileService.queryFileList(vo.getId().toString(), getGroupId(), getScoreType()));
}
}
}
public Page<AssessRectifyVo> listPage(AssessTaskPageSo page) {
/*
SecurityContext context = SecurityContextHolder.getContext();
Authentication auth = context.getAuthentication();
Object principal = auth.getPrincipal();
log.info("principal is {}", principal);
LoginUser loginUser = (LoginUser) principal;
SysUser user = loginUser.getUser();
boolean admin = SecurityUtils.isAdmin(user.getUserId());
if (!admin) {
page.setUserId(user.getUserId());
}
*/
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()));
record.setFiles(fileService.queryFileList(record.getId().toString(), getGroupId(), getScoreType()));
record.setRectifyFiles(fileService.queryFileList(record.getId().toString(), getGroupId(), getRectifyType()));
}
}
return res;
@ -223,11 +239,11 @@ public class AssessTeamRatingService extends ServiceImpl<AssessTeamRatingMapper,
public String rectify(AssessTeamRating rating) {
rating.setRectifyStatus(1);
this.updateById(rating);
fileService.save(rating.getRectifyFiles(),rating.getId().toString(),getGroupId(),getRectifyType());
fileService.save(rating.getRectifyFiles(), rating.getId().toString(), getGroupId(), getRectifyType());
return "整改成功";
}
public Map<Integer,Long> rectifyStat(MonthRangeSo monthRangeSo) {
public Map<Integer, Long> rectifyStat(MonthRangeSo monthRangeSo) {
List<AssessTeamRating> list = this.baseMapper.rectifyStat(monthRangeSo);
return list.stream().collect(Collectors.groupingBy(AssessTeamRating::getRectifyStatus, Collectors.counting()));
}