实现了工作项新建和更新的接口

master
白封羽 2022-07-05 22:14:42 +08:00
parent 4e4bd33e1c
commit e3462d0ed7
4 changed files with 116 additions and 18 deletions

View File

@ -44,8 +44,8 @@ public class TaskController {
}
@SneakyThrows
@PostMapping("/subtask/exist")
public ResponseMap createTask(
@GetMapping("/subtask/exist")
public ResponseMap existSubTask(
@RequestHeader("Token") String token,
@PathVariable("projectId") Integer projectId,
@RequestParam("taskId") Long taskId
@ -54,4 +54,27 @@ public class TaskController {
.put("existSubTask" ,taskService.existSubTask(token, projectId, taskId));
}
@SneakyThrows
@PostMapping("/")
public ResponseMap createTask(
@RequestHeader("Token") String token,
@PathVariable("projectId") Integer projectId,
@RequestBody Task task
) {
task.setTaskProjectId(projectId);
taskService.insertTask(token,task);
return ResponseMap.ofSuccess("操作成功");
}
@SneakyThrows
@PutMapping("/")
public ResponseMap modifyTask(
@RequestHeader("Token") String token,
@PathVariable("projectId") Integer projectId,
@RequestBody Task task
) {
task.setTaskProjectId(projectId);
taskService.modifyTask(token,task);
return ResponseMap.ofSuccess("操作成功");
}
}

View File

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* @author
@ -20,6 +21,7 @@ public class Task {
private Integer taskProjectId;
private Integer taskHolderId;
private String taskStatus;
private String taskType;
private Long taskFatherId;
private LocalDateTime taskCreatedTime;
private LocalDateTime taskStartTime;
@ -27,7 +29,7 @@ public class Task {
private LocalDateTime taskClosedTime;
private Integer taskPriority;
private String taskDescription;
private String attachedInfo; //TODO: 验证
private String attachedInfo;
@TableField("is_deleted")
@TableLogic
private Boolean deleted;
@ -38,4 +40,39 @@ public class Task {
return false;
return !this.getTaskEndTime().isBefore(this.getTaskStartTime());
}
public Boolean checkLegalFather(Task father) {
if(father==null||father.getTaskId()==null)
return false;
if(father.getTaskId()==0)
return true;
if(this.getTaskType().equals("缺陷")){
return false;
}
else if(this.getTaskType().equals("需求")){
return father.getTaskType().equals("需求");
}
else if(this.getTaskType().equals("任务")){
return father.getTaskType().equals("需求")||father.getTaskType().equals("任务");
}
return false;
}
public Boolean checkModification(Task rawTask){
if(rawTask.getTaskStatus().equals("已完成")||rawTask.getTaskStatus().equals("关闭"))
return false;
if(!rawTask.getTaskStatus().equals("待进行")&&this.getTaskStatus().equals("待进行"))
return false;
if(!Objects.equals(rawTask.getTaskId(),this.getTaskId()))
return false;
if(!Objects.equals(rawTask.getTaskProjectId(),this.getTaskProjectId()))
return false;
if(!Objects.equals(rawTask.getTaskFatherId(),this.getTaskFatherId()))
return false;
if(!Objects.equals(rawTask.getTaskType(),this.getTaskType()))
return false;
if(!Objects.equals(rawTask.getTaskCreatedTime(),this.getTaskCreatedTime()))
return false;
if(!Objects.equals(rawTask.getTaskClosedTime(),this.getTaskClosedTime()))
return false;
return true;
}
}

View File

@ -21,4 +21,5 @@ public interface ITaskService extends IService<Task> {
List<Task> getMyTaskList(String token,Integer projectId) throws BadRequestException;
Boolean canBeDone(Long taskId);
Task insertTask(String token,Task task) throws BadRequestException;
Task modifyTask(String token,Task task) throws BadRequestException;
}

View File

@ -40,7 +40,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
@Override
public Boolean existSubTask(String token, Integer projectId, Long taskId) throws BadRequestException {
if(projectGroupService.getUserLevelInGroup(token, projectId) == 0) {
if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) {
throw new BadRequestException("请求参数错误");
}
return baseMapper.exists(Wrappers.<Task>lambdaQuery().eq(Task::getTaskFatherId, taskId));
@ -62,8 +62,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
while (true) {
List<Task> list = baseMapper.selectList(
Wrappers.<Task>lambdaQuery()
.in(Task::getTaskFatherId, res)
.ne(Task::getTaskStatus, "已完成"));
.in(Task::getTaskFatherId, res));
baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, res));
if (list == null || list.isEmpty()) break;
res = list.stream().map(Task::getTaskId).collect(Collectors.toList());
@ -92,12 +91,14 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
Wrappers.<Task>lambdaQuery()
.in(Task::getTaskFatherId, res)
.ne(Task::getTaskStatus, "已完成")
.ne(Task::getTaskStatus, "关闭")
);
baseMapper.update(
null,
Wrappers.<Task>lambdaUpdate()
.in(Task::getTaskId, res)
.set(Task::getTaskStatus, "关闭")
.set(Task::getTaskClosedTime,LocalDateTime.now())
);
if (list == null || list.isEmpty()) break;
res = list.stream().map(Task::getTaskId).collect(Collectors.toList());
@ -109,7 +110,6 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
}
/**
*
* @return 1:all rights 2:father holder 3:current holder 0:no right
*/
@Override
@ -118,8 +118,8 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
Task task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, taskId));
if (task == null || staffId <= 0)
return 0;
int count=0;
if(task.getTaskHolderId().equals(staffId))
int count = 0;
if (task.getTaskHolderId().equals(staffId))
count++;
task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskFatherId()));
while (task.getTaskId() != 0) {
@ -134,7 +134,6 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
}
/**
*
* @return 1:all rights 2:father holder 3:current holder 0:no right
*/
@Override
@ -168,13 +167,13 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
public Boolean canBeDone(Long taskId) {
try {
Task task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, taskId));
if (task == null || !"打开".equals(task.getTaskStatus()) || !"进行中".equals(task.getTaskStatus()))
if (task == null || (!"待进行".equals(task.getTaskStatus()) && !"进行中".equals(task.getTaskStatus())))
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.getTaskStatus().equals("打开") || cTask.getTaskStatus().equals("进行中"))
if (cTask.getTaskStatus().equals("待进行") || cTask.getTaskStatus().equals("进行中"))
return false;
}
return true;
@ -187,25 +186,63 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
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)) {
if (userLevel == 0) {
System.out.println(userLevel);
throw new BadRequestException("错误的操作");
}
if (!task.checkInsert()) {
throw new BadRequestException("工作项参数错误");
}
if (checkHolder(token, task.getTaskFatherId()) == 0) {
throw new BadRequestException("非法的父级参数");
}
try {
Task father = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskFatherId()));
if (!task.checkLegalFather(father) || (checkHolder(token, task.getTaskFatherId()) == 0 && userLevel == 3)) {
throw new BadRequestException("无法指定该父级");
}
task.setTaskCreatedTime(LocalDateTime.now());
task.setTaskStatus("打开");
task.setTaskStatus("待进行");
task.setTaskClosedTime(null);
System.out.println("-------------------------\n");
if (baseMapper.insert(task) == 0) {
throw new BadRequestException("新建失败");
}
} catch (Exception e) {
throw new BadRequestException("新建失败");
System.out.println(e);
throw new BadRequestException("111");
}
return task;
}
@Override
public Task modifyTask(String token, Task task) throws BadRequestException {
Integer userLevel = projectGroupService.getUserLevelInGroup(token, task.getTaskProjectId());
Task rawTask = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskId()));
if (userLevel == 0 || (userLevel == 3 && checkHolder(token, task.getTaskId()) == 0)) {
throw new BadRequestException("没有权限");
}
int typeChangeValue = 0;
if (!task.getTaskStatus().equals(rawTask.getTaskStatus())) {
if (task.getTaskStatus().equals("已完成"))
typeChangeValue = 1;
if (task.getTaskStatus().equals("关闭"))
typeChangeValue = 2;
}
System.out.println(!task.checkModification(rawTask));
if (!task.checkModification(rawTask) || !task.checkInsert() || (typeChangeValue == 1 && !canBeDone(task.getTaskId()))) {
throw new BadRequestException("该修改无法应用");
}
try {
if (typeChangeValue != 0) {
task.setTaskClosedTime(LocalDateTime.now());
}
if (typeChangeValue == 2) {
closeTaskAndSubTask(token, task.getTaskProjectId(), task.getTaskId());
}
if (baseMapper.update(task, Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskId())) == 0) {
throw new BadRequestException("修改失败");
}
} catch (Exception e) {
throw new BadRequestException("修改失败");
}
return task;
}