2024-09-06 17:37:31 +08:00
|
|
|
package com.gunshi.project.xyt.service;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
2024-09-12 10:05:27 +08:00
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
2024-09-11 14:03:44 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
2024-09-06 17:37:31 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
2024-09-12 10:05:27 +08:00
|
|
|
import com.gunshi.db.dto.MonthRangeSo;
|
2024-09-06 17:37:31 +08:00
|
|
|
import com.gunshi.project.xyt.entity.so.AssessTaskPageSo;
|
2024-09-10 15:08:27 +08:00
|
|
|
import com.gunshi.project.xyt.entity.vo.AssessResultVo;
|
2024-09-12 10:05:27 +08:00
|
|
|
import com.gunshi.project.xyt.mapper.AssessObjectRatingMapper;
|
2024-09-06 17:37:31 +08:00
|
|
|
import com.gunshi.project.xyt.mapper.AssessTaskMapper;
|
2024-09-10 15:08:27 +08:00
|
|
|
import com.gunshi.project.xyt.mapper.AssessTemplateMapper;
|
2024-09-12 10:05:27 +08:00
|
|
|
import com.gunshi.project.xyt.model.*;
|
2024-09-10 17:33:31 +08:00
|
|
|
import com.gunshi.project.xyt.util.ExcelUtil;
|
|
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
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-10 15:08:27 +08:00
|
|
|
import java.math.BigDecimal;
|
2024-09-12 10:05:27 +08:00
|
|
|
import java.util.*;
|
2024-09-10 15:08:27 +08:00
|
|
|
import java.util.stream.Collectors;
|
2024-09-06 17:37:31 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 描述: 考核任务
|
|
|
|
|
* 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;
|
|
|
|
|
|
2024-09-10 15:08:27 +08:00
|
|
|
@Autowired
|
|
|
|
|
private AssessTemplateMapper templateMapper;
|
|
|
|
|
|
2024-09-12 10:05:27 +08:00
|
|
|
@Autowired
|
|
|
|
|
private AssessObjectRatingMapper objectRatingMapper;
|
|
|
|
|
|
2024-09-06 17:37:31 +08:00
|
|
|
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);
|
2024-09-10 15:08:27 +08:00
|
|
|
AssessTemplate template = templateMapper.selectById(task.getTemplateId());
|
2024-09-12 10:05:27 +08:00
|
|
|
task.setTemplate(template);
|
2024-09-06 17:37:31 +08:00
|
|
|
task.setFiles(fileService.getFiles(getGroupId(),id.toString()));
|
|
|
|
|
task.setAssessTeams(assessObjectService.getTeam(id));
|
|
|
|
|
task.setAssessObjects(assessObjectService.getObject(id));
|
|
|
|
|
return task;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<AssessTask> listPage(AssessTaskPageSo page) {
|
|
|
|
|
LambdaQueryWrapper<AssessTask> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
if (ObjectUtils.isNotNull(page.getTaskName())) {
|
|
|
|
|
queryWrapper.like(AssessTask::getTaskName, page.getTaskName());
|
|
|
|
|
}
|
|
|
|
|
if (page.getStatus() != null) {
|
|
|
|
|
queryWrapper.eq(AssessTask::getStatus, page.getStatus());
|
|
|
|
|
}
|
|
|
|
|
if(page.getDateRangeSo() != null && page.getDateRangeSo().getStart() != null){
|
|
|
|
|
queryWrapper.ge(AssessTask::getStartDate,page.getDateRangeSo().getStart());
|
|
|
|
|
}
|
|
|
|
|
if(page.getDateRangeSo() != null && page.getDateRangeSo().getEnd() != null){
|
2024-09-10 09:27:05 +08:00
|
|
|
queryWrapper.le(AssessTask::getStartDate,page.getDateRangeSo().getEnd());
|
2024-09-06 17:37:31 +08:00
|
|
|
}
|
2024-09-12 10:05:27 +08:00
|
|
|
queryWrapper.orderByDesc(AssessTask::getCreateTime);
|
2024-09-10 15:08:27 +08:00
|
|
|
Page<AssessTask> res = this.page(page.getPageSo().toPage(), queryWrapper);
|
|
|
|
|
if (res.getRecords() != null && res.getRecords().size() > 0) {
|
|
|
|
|
for (AssessTask record : res.getRecords()) {
|
|
|
|
|
record.setAssessObjects(assessObjectService.getObject(record.getId()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
2024-09-06 17:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
return "启动成功";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<AssessTask> myTodo(AssessTaskPageSo page) {
|
2024-09-11 14:03:44 +08:00
|
|
|
Page<AssessTask> res = this.baseMapper.myTodo(page.getPageSo().toPage(),page);
|
2024-09-09 14:14:31 +08:00
|
|
|
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) {
|
2024-09-11 14:03:44 +08:00
|
|
|
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);
|
2024-09-09 14:14:31 +08:00
|
|
|
if (res.getRecords() != null && res.getRecords().size() > 0) {
|
|
|
|
|
fillObject(res.getRecords(),page.getUserId());
|
|
|
|
|
}
|
|
|
|
|
return res;
|
2024-09-06 17:37:31 +08:00
|
|
|
}
|
2024-09-10 15:08:27 +08:00
|
|
|
|
|
|
|
|
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);
|
2024-09-12 10:05:27 +08:00
|
|
|
objects.stream().forEach(o->o.setStatus(9));
|
2024-09-10 15:08:27 +08:00
|
|
|
assessObjectService.updateBatchById(objects);
|
2024-09-12 10:05:27 +08:00
|
|
|
List<Long> objectIds = objects.stream().map(AssessObject::getId).collect(Collectors.toList());
|
|
|
|
|
objectRatingMapper.delete(new QueryWrapper<AssessObjectRating>().in("object_id",objectIds));
|
2024-09-10 15:08:27 +08:00
|
|
|
//任务中的考核成员
|
|
|
|
|
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());
|
|
|
|
|
}
|
2024-09-10 17:33:31 +08:00
|
|
|
|
|
|
|
|
public void resultExport(Long id, HttpServletResponse response) {
|
|
|
|
|
List<AssessResultVo> list = this.result(id);
|
|
|
|
|
ExcelUtil.exportExcel(list,"考核结果",AssessResultVo.class,1,new int[]{0,4},response,"考核结果");
|
|
|
|
|
}
|
2024-09-12 10:05:27 +08:00
|
|
|
|
|
|
|
|
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()));
|
|
|
|
|
}
|
2024-09-06 17:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|