Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/controller/TaskController.java
master
yang.yongquan 2022-07-06 09:36:56 +08:00
commit ce02979a98
12 changed files with 240 additions and 25 deletions

View File

@ -1,7 +1,7 @@
package cn.edu.hfut.rmdjzz.projectmanagement.advice;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.UnauthorizedException;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
@ -16,9 +16,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class ExceptionHandlerAdvice {
@ExceptionHandler(TokenException.class)
@ExceptionHandler(UnauthorizedException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public ResponseMap handleTokenException(TokenException e) {
public ResponseMap handleUnauthorizedException(Exception e) {
// log.error(ExceptionUtils.getStackTrace(e));
log.error(e.getMessage());
return ResponseMap.of(HttpStatus.UNAUTHORIZED.value(), e.getMessage());

View File

@ -0,0 +1,32 @@
package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author
* @since 2022/7/5 9:32
*/
@RestController
@RequestMapping("/project/{projectId}/group")
public class ProjectGroupController {
@Autowired
private IProjectGroupService projectGroupService;
@SneakyThrows
@GetMapping
public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId) {
List<Integer> res = projectGroupService.findAllProjectNumber(projectId);
return ResponseList.ofSuccess("查询成功", res);
}
}

View File

@ -54,6 +54,29 @@ 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("操作成功");
}
@SneakyThrows
@DeleteMapping
public ResponseMap deleteTaskAndSubTask(

View File

@ -1,12 +1,17 @@
package cn.edu.hfut.rmdjzz.projectmanagement.entity;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.BeanUtils;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.Objects;
/**
* @author
@ -14,12 +19,19 @@ import java.time.LocalDateTime;
*/
@Data
public class Task {
private static final String ATTACH_DEMAND_SOURCE = "demandSource";
private static final String ATTACH_ESTIMATED_MAN_HOURS = "estimatedManHours";
private static final String ATTACH_SEVERITY = "severity";
private static final String ATTACH_RECURRENCE_PROBABILITY = "recurrenceProbability";
@TableId(type = IdType.AUTO)
private Long taskId;
private String taskName;
private Integer taskProjectId;
private Integer taskHolderId;
private String taskStatus;
private String taskType;
private Long taskFatherId;
private LocalDateTime taskCreatedTime;
private LocalDateTime taskStartTime;
@ -27,15 +39,83 @@ public class Task {
private LocalDateTime taskClosedTime;
private Integer taskPriority;
private String taskDescription;
private String attachedInfo; //TODO: 验证
@ApiModelProperty(
"demandSource:需求来源 (String), estimatedManHours:预估工时 (Integer), severity:严重程度 (String), recurrenceProbability:复现概率 (String)")
@TableField(typeHandler = JacksonTypeHandler.class)
private Map<String, Object> attachedInfo;
@TableField("is_deleted")
@TableLogic
private Boolean deleted;
public Boolean checkInsert() {
if (this.getTaskName() == null || this.getTaskName().length() <= 0 || this.getTaskName().length() >= 100||
(this.getAttachedInfo()!=null&&this.getAttachedInfo().length() > 250))
if (this.getTaskName() == null
|| this.getTaskName().length() <= 0
|| this.getTaskName().length() >= 100
|| !this.checkAttachedInfo())
return false;
return !this.getTaskEndTime().isBefore(this.getTaskStartTime());
}
private Boolean checkAttachedInfo() {
if (attachedInfo == null || attachedInfo.isEmpty()) {
return true;
}
if (attachedInfo.containsKey(ATTACH_DEMAND_SOURCE) &&
!(attachedInfo.get(ATTACH_DEMAND_SOURCE) instanceof String s
&& BeanUtils.checkInSet(s, "产品规划", "用户反馈", "内部需求", "竞品调研", "其他")
)
) {
return false;
}
if (attachedInfo.containsKey(ATTACH_ESTIMATED_MAN_HOURS) &&
!(attachedInfo.get(ATTACH_ESTIMATED_MAN_HOURS) instanceof Integer i
&& i > 0
)
) {
return false;
}
if (attachedInfo.containsKey(ATTACH_SEVERITY) || attachedInfo.containsKey(ATTACH_RECURRENCE_PROBABILITY)) {
return (attachedInfo.containsKey(ATTACH_SEVERITY) && attachedInfo.containsKey(ATTACH_RECURRENCE_PROBABILITY))
&&
(attachedInfo.get(ATTACH_SEVERITY) instanceof String severity
&& BeanUtils.checkInSet(severity, "致命", "严重", "一般", "建议"))
&&
(attachedInfo.get(ATTACH_RECURRENCE_PROBABILITY) instanceof String recurrenceProbability
&& BeanUtils.checkInSet(recurrenceProbability, "必现", "大概率复现", "小概率复现", "仅出现一次"));
}
return true;
}
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;
return Objects.equals(rawTask.getTaskClosedTime(), this.getTaskClosedTime());
}
}

View File

@ -5,7 +5,7 @@ package cn.edu.hfut.rmdjzz.projectmanagement.exception;
* created at 2022/6/28 23:34
*/
//FIXME: 是否加入RequestUrl与RequestMethod作为错误信息log到日志
public class TokenException extends Exception {
public class TokenException extends UnauthorizedException {
public TokenException(String message) {
super(message);
}

View File

@ -0,0 +1,11 @@
package cn.edu.hfut.rmdjzz.projectmanagement.exception;
/**
* @author
* @since 2022/7/5 23:36
*/
public class UnauthorizedException extends Exception {
public UnauthorizedException(String message) {
super(message);
}
}

View File

@ -1,12 +1,15 @@
package cn.edu.hfut.rmdjzz.projectmanagement.mapper;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectType;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
/**
* @author
* created at 2022/6/30 21:34
*/
public interface ProjectGroupMapper extends BaseMapper<ProjectGroup> {
}

View File

@ -1,8 +1,11 @@
package cn.edu.hfut.rmdjzz.projectmanagement.service;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @author
* created at 2022/6/30 21:36
@ -14,4 +17,6 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
* @return 0AccessLevel
*/
Integer getUserLevelInGroup(String token, Integer projectId);
List<Integer> findAllProjectNumber(Integer projectId) throws BadRequestException;
}

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

@ -1,6 +1,7 @@
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectGroupMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
@ -8,6 +9,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @author
* created at 2022/6/30 21:38
@ -26,6 +30,7 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
return baseMapper.insert(projectGroup) == 1;
}
//FIXME: 应该抛错返回信息而不是catch
@Override
public Integer getUserLevelInGroup(String token, Integer projectId) {
try {
@ -41,4 +46,16 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
return 0;
}
}
@Override
public List<Integer> findAllProjectNumber(Integer projectId) throws BadRequestException {
List<Integer> res = new ArrayList<>();
List<ProjectGroup> targetProject = baseMapper.selectList(Wrappers.<ProjectGroup>lambdaQuery().eq(ProjectGroup::getProjectId, projectId));
if (targetProject.size() == 0)
throw new BadRequestException("项目不存在");
for (int i = 0; i < targetProject.size(); i++) {
res.add(targetProject.get(i).getStaffId());
}
return res;
}
}

View File

@ -23,7 +23,6 @@ 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
@ -40,7 +39,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 +61,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 +90,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 +109,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 +117,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 +133,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 +166,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 +185,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;
}

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@ -57,6 +58,7 @@ public class BeanUtils {
/**
* objectsnull
*
* @return nulltruefalse
*/
public static boolean checkAllNotNull(Object... objects) {
@ -70,6 +72,7 @@ public class BeanUtils {
/**
* objectsnull
*
* @return truefalse
*/
public static boolean checkAnyNotNull(Object... objects) {
@ -80,4 +83,8 @@ public class BeanUtils {
}
return false;
}
public static boolean checkInSet(Object object, Object... set) {
return Arrays.asList(set).contains(object);
}
}