完成了Task的一部分功能

master
白封羽 2022-07-04 20:24:11 +08:00
parent f7a420ca73
commit 43c1e5fa91
5 changed files with 114 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task;
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -22,14 +23,28 @@ public class TaskController {
@SneakyThrows
@GetMapping("/{projectId}")
public ResponseList getTaskList(@RequestHeader("Token") String token,@PathVariable Integer projectId){
List<Task> result = taskService.getTaskList(token,projectId,0);
List<Task> result = taskService.getTaskList(token,projectId,0L);
return ResponseList.ofSuccess("查询成功",result);
}
@SneakyThrows
@GetMapping("/getSubTask")
public ResponseList getSubTaskList(@RequestHeader("Token") String token,@RequestParam("projectId") Integer projectId,@RequestParam("fatherId") Integer fatherId){
public ResponseList getSubTaskList(@RequestHeader("Token") String token,@RequestParam("projectId") Integer projectId,@RequestParam("fatherId") Long fatherId){
List<Task> result = taskService.getTaskList(token,projectId,fatherId);
return ResponseList.ofSuccess("查询成功",result);
}
@SneakyThrows
@GetMapping("/getMyTasks")
public ResponseList getMyTasks(@RequestHeader("Token") String token,@RequestParam("projectId") Integer projectId){
List<Task> result = taskService.getMyTaskList(token,projectId);
return ResponseList.ofSuccess("查询成功",result);
}
@SneakyThrows
@PostMapping("/createTask")
public ResponseMap createTask(@RequestHeader("Token") String token, @RequestBody Task task){
task=taskService.insertTask(token,task);
return ResponseMap.ofSuccess("新建成功",task);
}
}

View File

@ -30,4 +30,12 @@ public class Task {
@TableField("is_deleted")
@TableLogic
private Boolean deleted;
public Boolean checkInsert(){
if(this.getTaskName()==null||this.getTaskName().length()<=0||this.getTaskName().length()>=100)
return false;
if(this.getTaskEndTime().isBefore(this.getTaskStartTime()))
return false;
return true;
}
}

View File

@ -12,6 +12,10 @@ import java.util.List;
* created at 2022/7/4 14:49
*/
public interface ITaskService extends IService<Task> {
List<Task> getTaskList(String token,Integer projectId,Integer fatherId) throws BadRequestException;
Boolean checkHolder(Integer staffId,Integer taskId);
List<Task> getTaskList(String token,Integer projectId,Long fatherId) throws BadRequestException;
Boolean checkHolder(Integer staffId,Long taskId);
Boolean checkHolder(String token,Long taskId);
List<Task> getMyTaskList(String token,Integer projectId) throws BadRequestException;
Boolean canBeDone(Long taskId);
Task insertTask(String token,Task task) throws BadRequestException;
}

View File

@ -35,6 +35,8 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
ProjectGroup projectGroup=baseMapper.selectOne(Wrappers.<ProjectGroup>lambdaQuery().eq(ProjectGroup::getStaffId, staffId).eq(ProjectGroup::getProjectId, projectId));
if(projectGroup == null)
return 0;
else if(projectGroup.getProjectStaffPosition().equals("负责人"))
return 3;
else if(projectGroup.getProjectStaffPosition().length()>0)
return 1;
else

View File

@ -4,15 +4,18 @@ import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.StaffMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.TaskMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -24,17 +27,17 @@ import java.util.Objects;
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {
@Autowired
private ProjectGroupServiceImpl projectGroupServiceImpl;
private ProjectGroupServiceImpl projectGroupService;
@Override
public List<Task> getTaskList(String token,Integer projectId,Integer fatherId) throws BadRequestException {
if(projectGroupServiceImpl.getUserLevelInGroup(token,projectId)==0||fatherId==null){
public List<Task> getTaskList(String token,Integer projectId,Long fatherId) throws BadRequestException {
if(projectGroupService.getUserLevelInGroup(token,projectId)==0||fatherId==null){
throw new BadRequestException("错误的访问参数");
}
return baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskProjectId,projectId).eq(Task::getTaskFatherId,fatherId).eq(Task::getDeleted,false));
return baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskProjectId,projectId).eq(Task::getTaskFatherId,fatherId));
}
@Override
public Boolean checkHolder(Integer staffId,Integer taskId){
public Boolean checkHolder(Integer staffId,Long taskId){
try{
Task task=baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId,taskId));
if(task==null||staffId<=0)
@ -49,4 +52,77 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
return false;
}
}
@Override
public Boolean checkHolder(String token,Long taskId){
try{
Integer staffId=TokenUtils.getStaffId(token);
Task task=baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId,taskId));
if(task==null||staffId==null||staffId<=0)
return false;
while(task.getTaskFatherId()!=0){
if(Objects.equals(task.getTaskHolderId(), staffId))
return true;
task=baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId,task.getTaskFatherId()));
}
return false;
}catch(Exception e){
return false;
}
}
@Override
public List<Task> getMyTaskList(String token,Integer projectId) throws BadRequestException{
if(projectGroupService.getUserLevelInGroup(token,projectId)==0){
throw new BadRequestException("错误的访问参数");
}
Integer staffId = 0;
try{
staffId= TokenUtils.getStaffId(token);
}catch(TokenException e){
//impossible
}
return baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskHolderId,staffId).eq(Task::getTaskProjectId,projectId));
}
@Override
public Boolean canBeDone(Long taskId){
try{
Task task=baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId,taskId));
if(task==null||!"打开".equals(task.getTaskType())||!"进行中".equals(task.getTaskType()))
return false;
List<Task> childTask=baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskFatherId,task.getTaskId()));
if(childTask==null||childTask.isEmpty())
return true;
for(Task cTask:childTask){
if(cTask.getTaskType().equals("打开")||cTask.getTaskType().equals("进行中"))
return false;
}
return true;
}catch(Exception e){//需要调整
return false;
}
}
@Override
public Task insertTask(String token,Task task) throws BadRequestException{
task.setTaskId(null);
Integer userLevel=projectGroupService.getUserLevelInGroup(token,task.getTaskProjectId());
if(userLevel==0||(userLevel==1&&task.getTaskFatherId()==0)){
throw new BadRequestException("错误的操作");
}
if(task.checkInsert()){
throw new BadRequestException("工作项参数错误");
}
if(checkHolder(token,task.getTaskFatherId())){
throw new BadRequestException("非法的父级参数");
}
try{
task.setTaskBuiltTime(LocalDateTime.now());
task.setTaskType("打开");
task.setTaskCloseTime(null);
if(baseMapper.insert(task)==0){
throw new BadRequestException("新建失败");
}
}catch(Exception e){
throw new BadRequestException("新建失败");
}
return task;
}
}