添加了需求,优化了接口

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
*/
@RestController
@RequestMapping("/task")
@RequestMapping("/project/{projectId}/task")
public class TaskController {
@Autowired
private ITaskService taskService;
@SneakyThrows
@GetMapping("/{projectId}")
public ResponseList getTaskList(@RequestHeader("Token") String token,@PathVariable Integer projectId){
List<Task> result = taskService.getTaskList(token,projectId,0L);
return ResponseList.ofSuccess("查询成功",result);
@GetMapping("/subtask/{fatherId}")
public ResponseList<Task> getSubTaskList(
@RequestHeader("Token") String token,
@PathVariable("projectId") Integer projectId,
@PathVariable("fatherId") Long fatherId
) {
List<Task> result = taskService.getTaskList(token, projectId, fatherId);
return ResponseList.ofSuccess("查询成功", result);
}
@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);
return ResponseList.ofSuccess("查询成功",result);
@GetMapping("/mine")
public ResponseList<Task> getMyTasks(@RequestHeader("Token") String token, @PathVariable("projectId") Integer projectId) {
List<Task> result = taskService.getMyTaskList(token, projectId);
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);
@PostMapping
public ResponseMap createTask(
@RequestHeader("Token") String token,
@PathVariable("projectId") Integer projectId,
@RequestBody Task task
) {
task.setTaskProjectId(projectId);
task = taskService.insertTask(token, task);
return ResponseMap.ofSuccess("新建成功", task);
}
}

View File

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

View File

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

View File

@ -1,19 +1,17 @@
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.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 org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
@ -25,44 +23,49 @@ import java.util.stream.Collectors;
* @author
* created at 2022/7/4 14:51
*/
//FIXME: 修改delete/close函数
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {
@Autowired
private ProjectGroupServiceImpl projectGroupService;
@Override
public List<Task> getTaskList(String token,Integer projectId,Long fatherId) throws BadRequestException {
if(projectGroupService.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));
return baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskProjectId, projectId).eq(Task::getTaskFatherId, fatherId));
}
//FIXME:
@Override
public List<List<Long>> getTaskAndSubTask(Long taskId) {
List<List<Long>> resList = new ArrayList<>();
List<Long> res = new ArrayList<>();
res.add(taskId);
resList.add(res);
while(true) {
while (true) {
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());
resList.add(res);
}
return resList;
}
//FIXME:
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@Override
public Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException{
if(projectGroupService.getUserLevelInGroup(token,projectId)==0) {
public Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException {
if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) {
throw new BadRequestException("错误参数");
}
if(!checkHolder(token, taskId)) {
if (!checkHolder(token, taskId)) {
throw new BadRequestException("错误父级参数");
}
List<List<Long>> resList = getTaskAndSubTask(taskId);
try {
for (List<Long> list: resList) {
for (List<Long> list : resList) {
baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, list));
}
return true;
@ -71,18 +74,19 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
}
}
//FIXME:
@Override
public Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException{
if(projectGroupService.getUserLevelInGroup(token,projectId)==0) {
public Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException {
if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) {
throw new BadRequestException("错误参数");
}
if(!checkHolder(token, taskId)) {
if (!checkHolder(token, taskId)) {
throw new BadRequestException("错误父级参数");
}
List<List<Long>> resList = getTaskAndSubTask(taskId);
try {
for (List<Long> list: resList) {
baseMapper.update(null, Wrappers.<Task>lambdaUpdate().in(Task::getTaskId, list).set(Task::getTaskType, "关闭"));
for (List<Long> list : resList) {
baseMapper.update(null, Wrappers.<Task>lambdaUpdate().in(Task::getTaskId, list).set(Task::getTaskStatus, "关闭"));
}
return true;
} catch (Exception e) {
@ -91,91 +95,90 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
}
@Override
public Boolean checkHolder(Integer staffId,Long taskId){
try{
Task task=baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId,taskId));
if(task==null||staffId<=0)
public Boolean checkHolder(Integer staffId, Long taskId) {
try {
Task task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, taskId));
if (task == null || staffId <= 0)
return false;
while(task.getTaskFatherId()!=0){
if(Objects.equals(task.getTaskHolderId(), staffId))
while (task.getTaskFatherId() != 0) {
if (Objects.equals(task.getTaskHolderId(), staffId))
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;
}catch(Exception e){
} catch (Exception e) {
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){
public Boolean checkHolder(String token, Long taskId) {
try {
Integer staffId = TokenUtils.getStaffId(token);
return checkHolder(staffId, taskId);
} catch (Exception e) {
return false;
}
}
@Override
public List<Task> getMyTaskList(String token,Integer projectId) throws BadRequestException{
if(projectGroupService.getUserLevelInGroup(token,projectId)==0){
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){
try {
staffId = TokenUtils.getStaffId(token);
} catch (TokenException e) {
//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
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()))
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()))
return false;
List<Task> childTask=baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskFatherId,task.getTaskId()));
if(childTask==null||childTask.isEmpty())
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("进行中"))
for (Task cTask : childTask) {
if (cTask.getTaskStatus().equals("打开") || cTask.getTaskStatus().equals("进行中"))
return false;
}
return true;
}catch(Exception e){//需要调整
} catch (Exception e) {//需要调整
return false;
}
}
@Override
public Task insertTask(String token,Task task) throws BadRequestException{
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)){
Integer userLevel = projectGroupService.getUserLevelInGroup(token, task.getTaskProjectId());
if (userLevel == 0 || (userLevel == 1 && task.getTaskFatherId() == 0)) {
System.out.println(userLevel);
throw new BadRequestException("错误的操作");
}
if(!task.checkInsert()){
if (!task.checkInsert()) {
throw new BadRequestException("工作项参数错误");
}
if(!checkHolder(token,task.getTaskFatherId())){
if (!checkHolder(token, task.getTaskFatherId())) {
throw new BadRequestException("非法的父级参数");
}
try{
task.setTaskBuiltTime(LocalDateTime.now());
task.setTaskType("打开");
task.setTaskCloseTime(null);
if(baseMapper.insert(task)==0){
try {
task.setTaskCreatedTime(LocalDateTime.now());
task.setTaskStatus("打开");
task.setTaskClosedTime(null);
if (baseMapper.insert(task) == 0) {
throw new BadRequestException("新建失败");
}
}catch(Exception e){
} catch (Exception e) {
throw new BadRequestException("新建失败");
}
return task;