添加了需求,优化了接口

master
ArgonarioD 2022-07-05 17:51:45 +08:00
parent 9dab2d8e10
commit b42b6b0b77
5 changed files with 121 additions and 102 deletions

View File

@ -1,11 +1,25 @@
# 项目管理模块-后端部分 # 项目管理模块-后端部分
---- ----
任务列表 task /project/{projectId}/task
- [ ] 用户管理-权限部分
- [ ] 完成服务器部署 - [ ] 新建工作项 POST /
- [ ] 完成初步接口文档 - [x] 拉取指定father的子工作项 GET /subtask/{fatherId}
- [ ] 任务管理 - [x] 筛选“我的”工作项 GET /mine
- [ ] 需求管理 - [ ] 修改工作项信息/状态 PUT /
- [ ] 团队管理
- [ ] 个人信息 name holder starttime endtime priority attachedinfo description status
- [ ] 删除工作项 DELETE /
- [ ] 是否存在孩子 GET /subtask/exist
----
group /project/{projectId}/group
- [ ] 拉取当前项目所有组员 GET /
- [ ] 岗位统计 GET
- [ ] 加人
- [ ] 改岗位
---
项目日志 项目统计
---
导入账户 大权限

View File

@ -15,35 +15,37 @@ import java.util.List;
* created at 2022/7/4 15:02 * created at 2022/7/4 15:02
*/ */
@RestController @RestController
@RequestMapping("/task") @RequestMapping("/project/{projectId}/task")
public class TaskController { public class TaskController {
@Autowired @Autowired
private ITaskService taskService; private ITaskService taskService;
@SneakyThrows @SneakyThrows
@GetMapping("/{projectId}") @GetMapping("/subtask/{fatherId}")
public ResponseList getTaskList(@RequestHeader("Token") String token,@PathVariable Integer projectId){ public ResponseList<Task> getSubTaskList(
List<Task> result = taskService.getTaskList(token,projectId,0L); @RequestHeader("Token") String token,
return ResponseList.ofSuccess("查询成功",result); @PathVariable("projectId") Integer projectId,
} @PathVariable("fatherId") Long fatherId
) {
@SneakyThrows
@GetMapping("/getSubTask")
public ResponseList getSubTaskList(@RequestHeader("Token") String token,@RequestParam("projectId") Integer projectId,@RequestParam("fatherId") Long fatherId){
List<Task> result = taskService.getTaskList(token, projectId, fatherId); List<Task> result = taskService.getTaskList(token, projectId, fatherId);
return ResponseList.ofSuccess("查询成功", result); return ResponseList.ofSuccess("查询成功", result);
} }
@SneakyThrows @SneakyThrows
@GetMapping("/getMyTasks") @GetMapping("/mine")
public ResponseList getMyTasks(@RequestHeader("Token") String token,@RequestParam("projectId") Integer projectId){ public ResponseList<Task> getMyTasks(@RequestHeader("Token") String token, @PathVariable("projectId") Integer projectId) {
List<Task> result = taskService.getMyTaskList(token, projectId); List<Task> result = taskService.getMyTaskList(token, projectId);
return ResponseList.ofSuccess("查询成功", result); return ResponseList.ofSuccess("查询成功", result);
} }
@SneakyThrows @SneakyThrows
@PostMapping("/createTask") @PostMapping
public ResponseMap createTask(@RequestHeader("Token") String token, @RequestBody Task task){ public ResponseMap createTask(
@RequestHeader("Token") String token,
@PathVariable("projectId") Integer projectId,
@RequestBody Task task
) {
task.setTaskProjectId(projectId);
task = taskService.insertTask(token, task); task = taskService.insertTask(token, task);
return ResponseMap.ofSuccess("新建成功", task); return ResponseMap.ofSuccess("新建成功", task);
} }

View File

@ -19,14 +19,15 @@ public class Task {
private String taskName; private String taskName;
private Integer taskProjectId; private Integer taskProjectId;
private Integer taskHolderId; private Integer taskHolderId;
private String taskType; private String taskStatus;
private Long taskFatherId; private Long taskFatherId;
private LocalDateTime taskBuiltTime; private LocalDateTime taskCreatedTime;
private LocalDateTime taskStartTime; private LocalDateTime taskStartTime;
private LocalDateTime taskEndTime; private LocalDateTime taskEndTime;
private LocalDateTime taskCloseTime; private LocalDateTime taskClosedTime;
private Integer taskPriority; private Integer taskPriority;
private String taskDescription; private String taskDescription;
private String attachedInfo; //TODO: 验证
@TableField("is_deleted") @TableField("is_deleted")
@TableLogic @TableLogic
private Boolean deleted; private Boolean deleted;
@ -34,8 +35,6 @@ public class Task {
public Boolean checkInsert() { public Boolean checkInsert() {
if (this.getTaskName() == null || this.getTaskName().length() <= 0 || this.getTaskName().length() >= 100) if (this.getTaskName() == null || this.getTaskName().length() <= 0 || this.getTaskName().length() >= 100)
return false; return false;
if(this.getTaskEndTime().isBefore(this.getTaskStartTime())) return !this.getTaskEndTime().isBefore(this.getTaskStartTime());
return false;
return true;
} }
} }

View File

@ -27,7 +27,8 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
projectGroup.setProjectStaffPosition("负责人"); projectGroup.setProjectStaffPosition("负责人");
return baseMapper.insert(projectGroup) == 1; return baseMapper.insert(projectGroup) == 1;
} }
//TODO:权限分级
//TODO:
@Override @Override
public Integer getUserLevelInGroup(String token,Integer projectId){ public Integer getUserLevelInGroup(String token,Integer projectId){
try{ try{

View File

@ -1,19 +1,17 @@
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl; package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
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.entity.Task;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException; import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException; 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.mapper.TaskMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService; import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils; import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
@ -25,10 +23,12 @@ import java.util.stream.Collectors;
* @author * @author
* created at 2022/7/4 14:51 * created at 2022/7/4 14:51
*/ */
//FIXME: 修改delete/close函数
@Service @Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService { public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {
@Autowired @Autowired
private ProjectGroupServiceImpl projectGroupService; private ProjectGroupServiceImpl projectGroupService;
@Override @Override
public List<Task> getTaskList(String token, Integer projectId, Long fatherId) throws BadRequestException { public List<Task> getTaskList(String token, Integer projectId, Long fatherId) throws BadRequestException {
if (projectGroupService.getUserLevelInGroup(token, projectId) == 0 || fatherId == null) { if (projectGroupService.getUserLevelInGroup(token, projectId) == 0 || fatherId == null) {
@ -37,6 +37,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
return baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskProjectId, projectId).eq(Task::getTaskFatherId, fatherId)); return baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskProjectId, projectId).eq(Task::getTaskFatherId, fatherId));
} }
//FIXME:
@Override @Override
public List<List<Long>> getTaskAndSubTask(Long taskId) { public List<List<Long>> getTaskAndSubTask(Long taskId) {
List<List<Long>> resList = new ArrayList<>(); List<List<Long>> resList = new ArrayList<>();
@ -52,6 +53,8 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
return resList; return resList;
} }
//FIXME:
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@Override @Override
public Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException { public Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException {
if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) { if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) {
@ -71,6 +74,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
} }
//FIXME:
@Override @Override
public Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException { public Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException {
if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) { if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) {
@ -82,7 +86,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
List<List<Long>> resList = getTaskAndSubTask(taskId); List<List<Long>> resList = getTaskAndSubTask(taskId);
try { try {
for (List<Long> list : resList) { for (List<Long> list : resList) {
baseMapper.update(null, Wrappers.<Task>lambdaUpdate().in(Task::getTaskId, list).set(Task::getTaskType, "关闭")); baseMapper.update(null, Wrappers.<Task>lambdaUpdate().in(Task::getTaskId, list).set(Task::getTaskStatus, "关闭"));
} }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
@ -106,23 +110,17 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
return false; return false;
} }
} }
@Override @Override
public Boolean checkHolder(String token, Long taskId) { public Boolean checkHolder(String token, Long taskId) {
try { try {
Integer staffId = TokenUtils.getStaffId(token); Integer staffId = TokenUtils.getStaffId(token);
Task task=baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId,taskId)); return checkHolder(staffId, 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) { } catch (Exception e) {
return false; return false;
} }
} }
@Override @Override
public List<Task> getMyTaskList(String token, Integer projectId) throws BadRequestException { public List<Task> getMyTaskList(String token, Integer projectId) throws BadRequestException {
if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) { if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) {
@ -134,19 +132,23 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} catch (TokenException e) { } catch (TokenException e) {
//impossible //impossible
} }
return baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskHolderId,staffId).eq(Task::getTaskProjectId,projectId)); return baseMapper.selectList(Wrappers.<Task>lambdaQuery()
.eq(Task::getTaskHolderId, staffId)
.eq(Task::getTaskProjectId, projectId)
);
} }
@Override @Override
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.getTaskType())||!"进行中".equals(task.getTaskType())) 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.getTaskType().equals("打开")||cTask.getTaskType().equals("进行中")) if (cTask.getTaskStatus().equals("打开") || cTask.getTaskStatus().equals("进行中"))
return false; return false;
} }
return true; return true;
@ -154,6 +156,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
return false; return false;
} }
} }
@Override @Override
public Task insertTask(String token, Task task) throws BadRequestException { public Task insertTask(String token, Task task) throws BadRequestException {
task.setTaskId(null); task.setTaskId(null);
@ -169,9 +172,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
throw new BadRequestException("非法的父级参数"); throw new BadRequestException("非法的父级参数");
} }
try { try {
task.setTaskBuiltTime(LocalDateTime.now()); task.setTaskCreatedTime(LocalDateTime.now());
task.setTaskType("打开"); task.setTaskStatus("打开");
task.setTaskCloseTime(null); task.setTaskClosedTime(null);
if (baseMapper.insert(task) == 0) { if (baseMapper.insert(task) == 0) {
throw new BadRequestException("新建失败"); throw new BadRequestException("新建失败");
} }