From 97632ce613f0de8f2d9ba179aef57b32baa7f907 Mon Sep 17 00:00:00 2001 From: lyf66 Date: Thu, 10 Apr 2025 11:48:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=80=83=E6=A0=B8=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E6=9F=A5=E8=AF=A2=E7=9A=84sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xyt/mapper/AssessTeamRatingMapper.java | 2 +- .../xyt/service/AssessTeamRatingService.java | 94 +++++++++++-------- 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/gunshi/project/xyt/mapper/AssessTeamRatingMapper.java b/src/main/java/com/gunshi/project/xyt/mapper/AssessTeamRatingMapper.java index 1af2c02..0813f03 100644 --- a/src/main/java/com/gunshi/project/xyt/mapper/AssessTeamRatingMapper.java +++ b/src/main/java/com/gunshi/project/xyt/mapper/AssessTeamRatingMapper.java @@ -56,7 +56,7 @@ public interface AssessTeamRatingMapper extends BaseMapper { left join public.assess_task t5 on t1.task_id = t5.id where t.is_need_rectify = 1 and t5.status = 3 - and t.object_id = #{obj.userId} + and t2.object_user_id = #{obj.userId} and t5.task_name like concat('%', #{obj.taskName}::text, '%') diff --git a/src/main/java/com/gunshi/project/xyt/service/AssessTeamRatingService.java b/src/main/java/com/gunshi/project/xyt/service/AssessTeamRatingService.java index 315413d..fee3eef 100644 --- a/src/main/java/com/gunshi/project/xyt/service/AssessTeamRatingService.java +++ b/src/main/java/com/gunshi/project/xyt/service/AssessTeamRatingService.java @@ -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 -{ +public class AssessTeamRatingService extends ServiceImpl { @Autowired private FileAssociationsService fileService; @@ -57,17 +62,17 @@ public class AssessTeamRatingService extends ServiceImpl 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 teamRatings = this.list(new QueryWrapper().eq("team_id", teamId)); - if(CollectionUtils.isNotEmpty(teamRatings)){ + if (CollectionUtils.isNotEmpty(teamRatings)) { List ratingIds = teamRatings.stream().map(AssessTeamRating::getId).map(Objects::toString).collect(Collectors.toList()); - fileService.remove(new QueryWrapper().in("business_id",ratingIds)); + fileService.remove(new QueryWrapper().in("business_id", ratingIds)); this.remove(new QueryWrapper().eq("team_id", teamId)); } } @@ -104,26 +109,26 @@ public class AssessTeamRatingService extends ServiceImpl= 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 teams = teamMapper.selectList(new QueryWrapper().eq("object_id", objectId).eq("task_id", taskId)); List 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 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().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 teamIds,Long objectId) { - assessObjectRatingService.remove(new QueryWrapper().eq("object_id",objectId)); + private BigDecimal calcScore(Integer scoreWay, List teamIds, Long objectId) { + assessObjectRatingService.remove(new QueryWrapper().eq("object_id", objectId)); final BigDecimal[] score = {new BigDecimal(0)}; - List ratings = this.list(new QueryWrapper().in("team_id",teamIds)); - Map> map = ratings.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId,Collectors.mapping(AssessTeamRating::getAssessScore,Collectors.toList()))); - Map> standardMap = ratings.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId,Collectors.mapping(AssessTeamRating::getStandardScore,Collectors.toList()))); + List ratings = this.list(new QueryWrapper().in("team_id", teamIds)); + Map> map = ratings.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId, Collectors.mapping(AssessTeamRating::getAssessScore, Collectors.toList()))); + Map> standardMap = ratings.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId, Collectors.mapping(AssessTeamRating::getStandardScore, Collectors.toList()))); List list = new ArrayList<>(); - map.entrySet().forEach(o->{ + map.entrySet().forEach(o -> { List 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 list){ + public void saveObjectRating(List list) { assessObjectRatingService.saveBatch(list); } @@ -191,30 +196,41 @@ public class AssessTeamRatingService extends ServiceImpl> scoreDetail(Long objectId) { + public Map> scoreDetail(Long objectId) { List list = this.baseMapper.scoreByObjectId(objectId); fillRating(list); return list.stream().collect(Collectors.groupingBy(AssessTeamRating::getIndicatorId)); } - private void fillRating(List list){ + private void fillRating(List list) { List relList = indicatorRatingService.queryRatingList(list.stream().map(AssessRatingVo::getIndicatorId).distinct().collect(Collectors.toList())); Map> 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 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 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 rectifyStat(MonthRangeSo monthRangeSo) { + public Map rectifyStat(MonthRangeSo monthRangeSo) { List list = this.baseMapper.rectifyStat(monthRangeSo); return list.stream().collect(Collectors.groupingBy(AssessTeamRating::getRectifyStatus, Collectors.counting())); }