256 lines
10 KiB
Java
256 lines
10 KiB
Java
package com.gunshi.project.xyt.service;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.gunshi.db.dto.MonthRangeSo;
|
|
import com.gunshi.project.xyt.entity.so.AssessTaskPageSo;
|
|
import com.gunshi.project.xyt.entity.vo.AssessResultVo;
|
|
import com.gunshi.project.xyt.mapper.AssessObjectRatingMapper;
|
|
import com.gunshi.project.xyt.mapper.AssessTaskMapper;
|
|
import com.gunshi.project.xyt.mapper.AssessTemplateMapper;
|
|
import com.gunshi.project.xyt.model.*;
|
|
import com.gunshi.project.xyt.util.ExcelUtil;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 描述: 考核任务
|
|
* author: xusan
|
|
* date: 2024-09-05 14:19:04
|
|
*/
|
|
@Service
|
|
@Slf4j
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public class AssessTaskService extends ServiceImpl<AssessTaskMapper, AssessTask>
|
|
{
|
|
@Autowired
|
|
private AssessObjectService assessObjectService;
|
|
|
|
@Autowired
|
|
private FileAssociationsService fileService;
|
|
|
|
@Autowired
|
|
private AssessTemplateMapper templateMapper;
|
|
|
|
@Autowired
|
|
private AssessObjectRatingMapper objectRatingMapper;
|
|
|
|
@Autowired
|
|
private AssessTeamRatingService teamRatingService;
|
|
|
|
@Autowired
|
|
private MessageCenterService messageCenterService;
|
|
|
|
public AssessTask saveData(AssessTask dto) {
|
|
dto.setId(IdWorker.getId());
|
|
dto.setStatus(0);
|
|
dto.setCreateTime(new Date());
|
|
assessObjectService.saveObject(dto.getAssessObjects(),dto.getAssessTeams(),dto.getId());
|
|
this.save(dto);
|
|
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
|
return dto;
|
|
}
|
|
|
|
public String getGroupId() {
|
|
return "assessTask";
|
|
}
|
|
|
|
public Boolean delData(Long id) {
|
|
AssessTask task = this.getById(id);
|
|
if (Objects.isNull(task)) {
|
|
throw new IllegalArgumentException("当前数据不存在");
|
|
}
|
|
if(task.getStatus() != 0){
|
|
throw new IllegalArgumentException("只能删除未启动的考核任务");
|
|
}
|
|
fileService.deleteFile(getGroupId(),id.toString());
|
|
assessObjectService.delObject(id);
|
|
return this.removeById(id);
|
|
}
|
|
|
|
public AssessTask updateData(AssessTask dto) {
|
|
if (Objects.isNull(this.getById(dto.getId()))) {
|
|
throw new IllegalArgumentException("当前数据不存在");
|
|
}
|
|
boolean result = this.updateById(dto);
|
|
if (result) {
|
|
fileService.saveFile(dto.getFiles(), getGroupId(), String.valueOf(dto.getId()));
|
|
assessObjectService.updateObject(dto.getAssessObjects(),dto.getAssessTeams(),dto.getId());
|
|
}
|
|
return dto;
|
|
}
|
|
|
|
public AssessTask detail(Long id) {
|
|
AssessTask task = this.getById(id);
|
|
AssessTemplate template = templateMapper.selectById(task.getTemplateId());
|
|
task.setTemplateName(template.getTemplateName());
|
|
task.setFiles(fileService.getFiles(getGroupId(),id.toString()));
|
|
List<AssessTeam> team = assessObjectService.getTeam(id);
|
|
task.setAssessTeams(team.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<>(Comparator.comparing(AssessTeam::getTeamUserId))),ArrayList::new)));
|
|
task.setAssessObjects(assessObjectService.getObject(id));
|
|
return task;
|
|
}
|
|
|
|
public Page<AssessTask> listPage(AssessTaskPageSo page) {
|
|
Page<AssessTask> res = this.baseMapper.listPage(page.getPageSo().toPage(), page);
|
|
if (res.getRecords() != null && res.getRecords().size() > 0) {
|
|
for (AssessTask record : res.getRecords()) {
|
|
record.setAssessObjects(assessObjectService.getObject(record.getId()));
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public String start(Long id) {
|
|
AssessTask task = this.getById(id);
|
|
task.setStatus(1);
|
|
this.updateById(task);
|
|
//任务中的考核对象
|
|
List<AssessObject> objects = assessObjectService.getObject(id);
|
|
objects.stream().forEach(o->o.setStatus(1));
|
|
assessObjectService.updateBatchById(objects);
|
|
//任务中的考核成员
|
|
List<AssessTeam> teams = assessObjectService.getTeam(id);
|
|
teams.stream().forEach(o->o.setStatus(1));
|
|
assessObjectService.updateTeams(teams);
|
|
//考核指标
|
|
List<AssessTeamRating> ratings = new ArrayList<>();
|
|
List<Long> teamUserIds = teams.stream().map(AssessTeam::getTeamUserId).distinct().collect(Collectors.toList());
|
|
List<MessageCenter> messages = teamUserIds.stream().map(o->{
|
|
MessageCenter center = new MessageCenter();
|
|
center.setPublishUserId(task.getCreateUserId());
|
|
center.setPublishUserName(task.getCreateUserName());
|
|
center.setReceiveUserId(o);
|
|
center.setTitle("评分任务");
|
|
center.setContent("您收到一条考核评分任务的提醒:"+task.getTaskName()+",请及时处理。");
|
|
return center;
|
|
}).collect(Collectors.toList());
|
|
List<AssessIndicator> indicatorIds = this.baseMapper.queryIndicators(task.getTemplateId());
|
|
for(AssessTeam team : teams){
|
|
for(AssessIndicator indicator : indicatorIds){
|
|
AssessTeamRating rating = new AssessTeamRating();
|
|
rating.setId(IdWorker.getId());
|
|
rating.setTeamId(team.getId());
|
|
rating.setIndicatorId(indicator.getId());
|
|
rating.setStandardScore(indicator.getStandardScore());
|
|
ratings.add(rating);
|
|
}
|
|
}
|
|
teamRatingService.saveBatch(ratings);
|
|
messageCenterService.insertMessage(messages);
|
|
List<AssessObjectRating> list = new ArrayList<>();
|
|
for(AssessObject object : objects){
|
|
for(AssessIndicator indicator : indicatorIds){
|
|
AssessObjectRating objectRating = new AssessObjectRating();
|
|
objectRating.setId(IdWorker.getId());
|
|
objectRating.setObjectId(object.getId());
|
|
objectRating.setIndicatorId(indicator.getId());
|
|
objectRating.setStandardScore(indicator.getStandardScore());
|
|
list.add(objectRating);
|
|
}
|
|
}
|
|
teamRatingService.saveObjectRating(list);
|
|
return "启动成功";
|
|
}
|
|
|
|
public Page<AssessTask> myTodo(AssessTaskPageSo page) {
|
|
Page<AssessTask> res = this.baseMapper.myTodo(page.getPageSo().toPage(),page);
|
|
if (res.getRecords() != null && res.getRecords().size() > 0) {
|
|
fillObject(res.getRecords(),page.getUserId());
|
|
}
|
|
return res;
|
|
}
|
|
|
|
private void fillObject(List<AssessTask> records,Long userId) {
|
|
for (AssessTask record : records) {
|
|
List<AssessObject> list = this.baseMapper.selectObject(record.getId(),userId);
|
|
record.setAssessObjects(list);
|
|
}
|
|
}
|
|
|
|
public Page<AssessTask> myDone(AssessTaskPageSo page) {
|
|
List<Long> taskIds = this.baseMapper.myDoneTask(page.getUserId());
|
|
if (CollectionUtils.isEmpty(taskIds)) {
|
|
return null;
|
|
}
|
|
Page<AssessTask> res = this.baseMapper.myDone(page.getPageSo().toPage(), page,taskIds);
|
|
if (res.getRecords() != null && res.getRecords().size() > 0) {
|
|
fillObject(res.getRecords(),page.getUserId());
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public String pass(Long id) {
|
|
AssessTask task = this.getById(id);
|
|
task.setStatus(3);
|
|
this.updateById(task);
|
|
return "审核通过";
|
|
}
|
|
|
|
public String cancel(Long id) {
|
|
AssessTask task = this.getById(id);
|
|
task.setStatus(4);
|
|
this.updateById(task);
|
|
return "作废成功";
|
|
}
|
|
|
|
public String reject(Long id) {
|
|
AssessTask task = this.getById(id);
|
|
task.setStatus(1);
|
|
this.updateById(task);
|
|
//任务中的考核对象
|
|
List<AssessObject> objects = assessObjectService.getObject(id);
|
|
objects.stream().forEach(o->o.setStatus(9));
|
|
assessObjectService.updateBatchById(objects);
|
|
List<Long> objectIds = objects.stream().map(AssessObject::getId).collect(Collectors.toList());
|
|
objectRatingMapper.delete(new QueryWrapper<AssessObjectRating>().in("object_id",objectIds));
|
|
//任务中的考核成员
|
|
List<AssessTeam> teams = assessObjectService.getTeam(id);
|
|
teams.stream().forEach(o->o.setStatus(1));
|
|
assessObjectService.updateTeams(teams);
|
|
return "驳回评分成功";
|
|
}
|
|
|
|
public List<AssessResultVo> result(Long id) {
|
|
List<AssessResultVo> list = this.baseMapper.result(id);
|
|
list.stream().forEach(o->o.setDeductScore(new BigDecimal(o.getStandardScore()).subtract(o.getAssessScore())));
|
|
return list.stream().filter(o->o.getDeductScore().compareTo(new BigDecimal(0)) > 0).collect(Collectors.toList());
|
|
}
|
|
|
|
public void resultExport(Long id, HttpServletResponse response) {
|
|
List<AssessResultVo> list = this.result(id);
|
|
ExcelUtil.exportExcel(list,"考核结果",AssessResultVo.class,1,new int[]{0,4},response,"考核结果");
|
|
}
|
|
|
|
public List<AssessTask> resultStat(MonthRangeSo monthRangeSo) {
|
|
List<AssessTask> list = this.baseMapper.resultStat(monthRangeSo);
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
for (AssessTask record : list) {
|
|
record.setAssessObjects(assessObjectService.getObject(record.getId()));
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public Map<Integer, Long> levelStat(MonthRangeSo monthRangeSo) {
|
|
List<AssessTask> list = this.resultStat(monthRangeSo);
|
|
if(CollectionUtils.isEmpty(list)){
|
|
return new HashMap<>();
|
|
}
|
|
List<AssessObject> objectList = list.stream().map(AssessTask::getAssessObjects).flatMap(List::stream).collect(Collectors.toList());
|
|
return objectList.stream().collect(Collectors.groupingBy(AssessObject::getAssessLevel,Collectors.counting()));
|
|
}
|
|
}
|
|
|
|
|