2024-09-06 17:37:31 +08:00
|
|
|
package com.gunshi.project.xyt.service;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
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;
|
|
|
|
|
import com.gunshi.project.xyt.entity.so.AssessTaskPageSo;
|
|
|
|
|
import com.gunshi.project.xyt.mapper.AssessTaskMapper;
|
|
|
|
|
import com.gunshi.project.xyt.model.AssessObject;
|
|
|
|
|
import com.gunshi.project.xyt.model.AssessTask;
|
|
|
|
|
import com.gunshi.project.xyt.model.AssessTeam;
|
|
|
|
|
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.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 描述: 考核任务
|
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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){
|
|
|
|
|
queryWrapper.le(AssessTask::getEndDate,page.getDateRangeSo().getEnd());
|
|
|
|
|
}
|
|
|
|
|
return this.page(page.getPageSo().toPage(),queryWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String start(Long id) {
|
|
|
|
|
AssessTask task = this.getById(id);
|
|
|
|
|
task.setStatus(1);
|
|
|
|
|
this.updateById(task);
|
|
|
|
|
//生成考核评分任务
|
|
|
|
|
Long templateId = task.getTemplateId();
|
|
|
|
|
//任务中的考核对象
|
|
|
|
|
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-09 14:14:31 +08:00
|
|
|
Page<AssessTask> res = this.baseMapper.myTodo(page.getPageSo().toPage(), page,1);
|
|
|
|
|
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) {
|
|
|
|
|
Page<AssessTask> res = this.baseMapper.myTodo(page.getPageSo().toPage(), page,2);
|
|
|
|
|
if (res.getRecords() != null && res.getRecords().size() > 0) {
|
|
|
|
|
fillObject(res.getRecords(),page.getUserId());
|
|
|
|
|
}
|
|
|
|
|
return res;
|
2024-09-06 17:37:31 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|