添加了需求,优化了接口

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,36 +15,38 @@ 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
) {
List<Task> result = taskService.getTaskList(token, projectId, fatherId);
return ResponseList.ofSuccess("查询成功", result);
} }
@SneakyThrows @SneakyThrows
@GetMapping("/getSubTask") @GetMapping("/mine")
public ResponseList getSubTaskList(@RequestHeader("Token") String token,@RequestParam("projectId") Integer projectId,@RequestParam("fatherId") Long fatherId){ public ResponseList<Task> getMyTasks(@RequestHeader("Token") String token, @PathVariable("projectId") Integer projectId) {
List<Task> result = taskService.getTaskList(token,projectId,fatherId); List<Task> result = taskService.getMyTaskList(token, projectId);
return ResponseList.ofSuccess("查询成功",result); return ResponseList.ofSuccess("查询成功", result);
} }
@SneakyThrows @SneakyThrows
@GetMapping("/getMyTasks") @PostMapping
public ResponseList getMyTasks(@RequestHeader("Token") String token,@RequestParam("projectId") Integer projectId){ public ResponseMap createTask(
List<Task> result = taskService.getMyTaskList(token,projectId); @RequestHeader("Token") String token,
return ResponseList.ofSuccess("查询成功",result); @PathVariable("projectId") Integer projectId,
} @RequestBody Task task
) {
@SneakyThrows task.setTaskProjectId(projectId);
@PostMapping("/createTask") task = taskService.insertTask(token, task);
public ResponseMap createTask(@RequestHeader("Token") String token, @RequestBody Task task){ return ResponseMap.ofSuccess("新建成功", task);
task=taskService.insertTask(token,task);
return ResponseMap.ofSuccess("新建成功",task);
} }
} }

View File

@ -19,23 +19,22 @@ 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;
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,44 +23,49 @@ 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) {
throw new BadRequestException("错误的访问参数"); throw new BadRequestException("错误的访问参数");
} }
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<>();
List<Long> res = new ArrayList<>(); List<Long> res = new ArrayList<>();
res.add(taskId); res.add(taskId);
resList.add(res); resList.add(res);
while(true) { while (true) {
List<Task> list = baseMapper.selectList(Wrappers.<Task>lambdaQuery().in(Task::getTaskFatherId, res)); List<Task> list = baseMapper.selectList(Wrappers.<Task>lambdaQuery().in(Task::getTaskFatherId, 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());
resList.add(res); resList.add(res);
} }
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) {
throw new BadRequestException("错误参数"); throw new BadRequestException("错误参数");
} }
if(!checkHolder(token, taskId)) { if (!checkHolder(token, taskId)) {
throw new BadRequestException("错误父级参数"); throw new BadRequestException("错误父级参数");
} }
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.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, list)); baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, list));
} }
return true; return true;
@ -71,18 +74,19 @@ 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) {
throw new BadRequestException("错误参数"); throw new BadRequestException("错误参数");
} }
if(!checkHolder(token, taskId)) { if (!checkHolder(token, taskId)) {
throw new BadRequestException("错误父级参数"); throw new BadRequestException("错误父级参数");
} }
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) {
@ -91,91 +95,90 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
@Override @Override
public Boolean checkHolder(Integer staffId,Long taskId){ public Boolean checkHolder(Integer staffId, 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||staffId<=0) if (task == null || staffId <= 0)
return false; return false;
while(task.getTaskFatherId()!=0){ while (task.getTaskFatherId() != 0) {
if(Objects.equals(task.getTaskHolderId(), staffId)) if (Objects.equals(task.getTaskHolderId(), staffId))
return true; return true;
task=baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId,task.getTaskFatherId())); task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskFatherId()));
} }
return false; return false;
}catch(Exception e){ } catch (Exception e) {
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) } catch (Exception e) {
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; 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) {
throw new BadRequestException("错误的访问参数"); throw new BadRequestException("错误的访问参数");
} }
Integer staffId = 0; Integer staffId = 0;
try{ try {
staffId= TokenUtils.getStaffId(token); staffId = TokenUtils.getStaffId(token);
}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;
}catch(Exception e){//需要调整 } catch (Exception e) {//需要调整
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);
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 || (userLevel == 1 && task.getTaskFatherId() == 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())){ if (!checkHolder(token, task.getTaskFatherId())) {
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("新建失败");
} }
}catch(Exception e){ } catch (Exception e) {
throw new BadRequestException("新建失败"); throw new BadRequestException("新建失败");
} }
return task; return task;