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

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 @SneakyThrows
@PostMapping("/subtask/exist") @GetMapping("/subtask/exist")
public ResponseMap createTask( public ResponseMap existSubTask(
@RequestHeader("Token") String token, @RequestHeader("Token") String token,
@PathVariable("projectId") Integer projectId, @PathVariable("projectId") Integer projectId,
@RequestParam("taskId") Long taskId @RequestParam("taskId") Long taskId
@ -54,4 +54,27 @@ public class TaskController {
.put("existSubTask" ,taskService.existSubTask(token, projectId, taskId)); .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 lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Objects;
/** /**
* @author * @author
@ -20,6 +21,7 @@ public class Task {
private Integer taskProjectId; private Integer taskProjectId;
private Integer taskHolderId; private Integer taskHolderId;
private String taskStatus; private String taskStatus;
private String taskType;
private Long taskFatherId; private Long taskFatherId;
private LocalDateTime taskCreatedTime; private LocalDateTime taskCreatedTime;
private LocalDateTime taskStartTime; private LocalDateTime taskStartTime;
@ -27,7 +29,7 @@ public class Task {
private LocalDateTime taskClosedTime; private LocalDateTime taskClosedTime;
private Integer taskPriority; private Integer taskPriority;
private String taskDescription; private String taskDescription;
private String attachedInfo; //TODO: 验证 private String attachedInfo;
@TableField("is_deleted") @TableField("is_deleted")
@TableLogic @TableLogic
private Boolean deleted; private Boolean deleted;
@ -38,4 +40,39 @@ public class Task {
return false; return false;
return !this.getTaskEndTime().isBefore(this.getTaskStartTime()); 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; List<Task> getMyTaskList(String token,Integer projectId) throws BadRequestException;
Boolean canBeDone(Long taskId); Boolean canBeDone(Long taskId);
Task insertTask(String token,Task task) throws BadRequestException; 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 @Override
public Boolean existSubTask(String token, Integer projectId, Long taskId) throws BadRequestException { 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("请求参数错误"); throw new BadRequestException("请求参数错误");
} }
return baseMapper.exists(Wrappers.<Task>lambdaQuery().eq(Task::getTaskFatherId, taskId)); 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) { while (true) {
List<Task> list = baseMapper.selectList( List<Task> list = baseMapper.selectList(
Wrappers.<Task>lambdaQuery() Wrappers.<Task>lambdaQuery()
.in(Task::getTaskFatherId, res) .in(Task::getTaskFatherId, res));
.ne(Task::getTaskStatus, "已完成"));
baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, res)); baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, res));
if (list == null || list.isEmpty()) break; if (list == null || list.isEmpty()) break;
res = list.stream().map(Task::getTaskId).collect(Collectors.toList()); 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() Wrappers.<Task>lambdaQuery()
.in(Task::getTaskFatherId, res) .in(Task::getTaskFatherId, res)
.ne(Task::getTaskStatus, "已完成") .ne(Task::getTaskStatus, "已完成")
.ne(Task::getTaskStatus, "关闭")
); );
baseMapper.update( baseMapper.update(
null, null,
Wrappers.<Task>lambdaUpdate() Wrappers.<Task>lambdaUpdate()
.in(Task::getTaskId, res) .in(Task::getTaskId, res)
.set(Task::getTaskStatus, "关闭") .set(Task::getTaskStatus, "关闭")
.set(Task::getTaskClosedTime,LocalDateTime.now())
); );
if (list == null || list.isEmpty()) break; if (list == null || list.isEmpty()) break;
res = list.stream().map(Task::getTaskId).collect(Collectors.toList()); 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 * @return 1:all rights 2:father holder 3:current holder 0:no right
*/ */
@Override @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)); Task task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, taskId));
if (task == null || staffId <= 0) if (task == null || staffId <= 0)
return 0; return 0;
int count=0; int count = 0;
if(task.getTaskHolderId().equals(staffId)) if (task.getTaskHolderId().equals(staffId))
count++; count++;
task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskFatherId())); task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskFatherId()));
while (task.getTaskId() != 0) { 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 * @return 1:all rights 2:father holder 3:current holder 0:no right
*/ */
@Override @Override
@ -168,13 +167,13 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
public Boolean canBeDone(Long taskId) { public Boolean canBeDone(Long taskId) {
try { try {
Task task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, taskId)); 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; return false;
List<Task> childTask = baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskFatherId, task.getTaskId())); List<Task> childTask = baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskFatherId, task.getTaskId()));
if (childTask == null || childTask.isEmpty()) if (childTask == null || childTask.isEmpty())
return true; return true;
for (Task cTask : childTask) { for (Task cTask : childTask) {
if (cTask.getTaskStatus().equals("打开") || cTask.getTaskStatus().equals("进行中")) if (cTask.getTaskStatus().equals("待进行") || cTask.getTaskStatus().equals("进行中"))
return false; return false;
} }
return true; return true;
@ -187,25 +186,63 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
public Task insertTask(String token, Task task) throws BadRequestException { public Task insertTask(String token, Task task) throws BadRequestException {
task.setTaskId(null); task.setTaskId(null);
Integer userLevel = projectGroupService.getUserLevelInGroup(token, task.getTaskProjectId()); Integer userLevel = projectGroupService.getUserLevelInGroup(token, task.getTaskProjectId());
if (userLevel == 0 || (userLevel == 1 && task.getTaskFatherId() == 0)) { if (userLevel == 0) {
System.out.println(userLevel); System.out.println(userLevel);
throw new BadRequestException("错误的操作"); throw new BadRequestException("错误的操作");
} }
if (!task.checkInsert()) { if (!task.checkInsert()) {
throw new BadRequestException("工作项参数错误"); throw new BadRequestException("工作项参数错误");
} }
if (checkHolder(token, task.getTaskFatherId()) == 0) {
throw new BadRequestException("非法的父级参数");
}
try { 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.setTaskCreatedTime(LocalDateTime.now());
task.setTaskStatus("打开"); task.setTaskStatus("待进行");
task.setTaskClosedTime(null); task.setTaskClosedTime(null);
System.out.println("-------------------------\n");
if (baseMapper.insert(task) == 0) { if (baseMapper.insert(task) == 0) {
throw new BadRequestException("新建失败"); throw new BadRequestException("新建失败");
} }
} catch (Exception e) { } 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; return task;
} }