添加了UnauthorizedException,修改了Task以适配attachedInfo,添加了FIXME,格式化了代码
parent
e3462d0ed7
commit
5e26599858
|
@ -1,7 +1,7 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement.advice;
|
package cn.edu.hfut.rmdjzz.projectmanagement.advice;
|
||||||
|
|
||||||
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.UnauthorizedException;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -16,9 +16,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class ExceptionHandlerAdvice {
|
public class ExceptionHandlerAdvice {
|
||||||
@ExceptionHandler(TokenException.class)
|
@ExceptionHandler(UnauthorizedException.class)
|
||||||
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
||||||
public ResponseMap handleTokenException(TokenException e) {
|
public ResponseMap handleUnauthorizedException(Exception e) {
|
||||||
// log.error(ExceptionUtils.getStackTrace(e));
|
// log.error(ExceptionUtils.getStackTrace(e));
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
return ResponseMap.of(HttpStatus.UNAUTHORIZED.value(), e.getMessage());
|
return ResponseMap.of(HttpStatus.UNAUTHORIZED.value(), e.getMessage());
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
@ -22,14 +23,10 @@ public class ProjectGroupController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IProjectGroupService projectGroupService;
|
private IProjectGroupService projectGroupService;
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId) {
|
public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId) {
|
||||||
List<Integer> res = null;
|
List<Integer> res = projectGroupService.findAllProjectNumber(projectId);
|
||||||
try {
|
|
||||||
res = projectGroupService.findAllProjectNumber(projectId);
|
|
||||||
} catch (BadRequestException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return ResponseList.ofSuccess("查询成功", res);
|
return ResponseList.ofSuccess("查询成功", res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement.entity;
|
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.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +19,12 @@ import java.util.Objects;
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Task {
|
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)
|
@TableId(type = IdType.AUTO)
|
||||||
private Long taskId;
|
private Long taskId;
|
||||||
private String taskName;
|
private String taskName;
|
||||||
|
@ -29,50 +39,83 @@ public class Task {
|
||||||
private LocalDateTime taskClosedTime;
|
private LocalDateTime taskClosedTime;
|
||||||
private Integer taskPriority;
|
private Integer taskPriority;
|
||||||
private String taskDescription;
|
private String taskDescription;
|
||||||
private String attachedInfo;
|
@ApiModelProperty(
|
||||||
|
"demandSource:需求来源 (String), estimatedManHours:预估工时 (Integer), severity:严重程度 (String), recurrenceProbability:复现概率 (String)")
|
||||||
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
|
private Map<String, Object> attachedInfo;
|
||||||
@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.getAttachedInfo()!=null&&this.getAttachedInfo().length() > 250))
|
|| this.getTaskName().length() <= 0
|
||||||
|
|| this.getTaskName().length() >= 100
|
||||||
|
|| !this.checkAttachedInfo())
|
||||||
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)
|
private Boolean checkAttachedInfo() {
|
||||||
return false;
|
if (attachedInfo == null || attachedInfo.isEmpty()) {
|
||||||
if(father.getTaskId()==0)
|
|
||||||
return true;
|
return true;
|
||||||
if(this.getTaskType().equals("缺陷")){
|
}
|
||||||
|
if (attachedInfo.containsKey(ATTACH_DEMAND_SOURCE) &&
|
||||||
|
!(attachedInfo.get(ATTACH_DEMAND_SOURCE) instanceof String s
|
||||||
|
&& BeanUtils.checkInSet(s, "产品规划", "用户反馈", "内部需求", "竞品调研", "其他")
|
||||||
|
)
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(this.getTaskType().equals("需求")){
|
if (attachedInfo.containsKey(ATTACH_ESTIMATED_MAN_HOURS) &&
|
||||||
return father.getTaskType().equals("需求");
|
!(attachedInfo.get(ATTACH_ESTIMATED_MAN_HOURS) instanceof Integer i
|
||||||
|
&& i > 0
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else if(this.getTaskType().equals("任务")){
|
if (attachedInfo.containsKey(ATTACH_SEVERITY) || attachedInfo.containsKey(ATTACH_RECURRENCE_PROBABILITY)) {
|
||||||
return father.getTaskType().equals("需求")||father.getTaskType().equals("任务");
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
public Boolean checkModification(Task rawTask){
|
|
||||||
if(rawTask.getTaskStatus().equals("已完成")||rawTask.getTaskStatus().equals("关闭"))
|
public Boolean checkModification(Task rawTask) {
|
||||||
|
if (rawTask.getTaskStatus().equals("已完成") || rawTask.getTaskStatus().equals("关闭"))
|
||||||
return false;
|
return false;
|
||||||
if(!rawTask.getTaskStatus().equals("待进行")&&this.getTaskStatus().equals("待进行"))
|
if (!rawTask.getTaskStatus().equals("待进行") && this.getTaskStatus().equals("待进行"))
|
||||||
return false;
|
return false;
|
||||||
if(!Objects.equals(rawTask.getTaskId(),this.getTaskId()))
|
if (!Objects.equals(rawTask.getTaskId(), this.getTaskId()))
|
||||||
return false;
|
return false;
|
||||||
if(!Objects.equals(rawTask.getTaskProjectId(),this.getTaskProjectId()))
|
if (!Objects.equals(rawTask.getTaskProjectId(), this.getTaskProjectId()))
|
||||||
return false;
|
return false;
|
||||||
if(!Objects.equals(rawTask.getTaskFatherId(),this.getTaskFatherId()))
|
if (!Objects.equals(rawTask.getTaskFatherId(), this.getTaskFatherId()))
|
||||||
return false;
|
return false;
|
||||||
if(!Objects.equals(rawTask.getTaskType(),this.getTaskType()))
|
if (!Objects.equals(rawTask.getTaskType(), this.getTaskType()))
|
||||||
return false;
|
return false;
|
||||||
if(!Objects.equals(rawTask.getTaskCreatedTime(),this.getTaskCreatedTime()))
|
if (!Objects.equals(rawTask.getTaskCreatedTime(), this.getTaskCreatedTime()))
|
||||||
return false;
|
return false;
|
||||||
if(!Objects.equals(rawTask.getTaskClosedTime(),this.getTaskClosedTime()))
|
return Objects.equals(rawTask.getTaskClosedTime(), this.getTaskClosedTime());
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ package cn.edu.hfut.rmdjzz.projectmanagement.exception;
|
||||||
* created at 2022/6/28 23:34
|
* created at 2022/6/28 23:34
|
||||||
*/
|
*/
|
||||||
//FIXME: 是否加入RequestUrl与RequestMethod作为错误信息log到日志
|
//FIXME: 是否加入RequestUrl与RequestMethod作为错误信息log到日志
|
||||||
public class TokenException extends Exception {
|
public class TokenException extends UnauthorizedException {
|
||||||
public TokenException(String message) {
|
public TokenException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,6 @@ package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
||||||
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.mapper.ProjectGroupMapper;
|
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectGroupMapper;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
||||||
|
@ -31,6 +30,7 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
|
||||||
return baseMapper.insert(projectGroup) == 1;
|
return baseMapper.insert(projectGroup) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FIXME: 应该抛错返回信息而不是catch
|
||||||
@Override
|
@Override
|
||||||
public Integer getUserLevelInGroup(String token, Integer projectId) {
|
public Integer getUserLevelInGroup(String token, Integer projectId) {
|
||||||
try {
|
try {
|
||||||
|
@ -49,9 +49,9 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> findAllProjectNumber(Integer projectId) throws BadRequestException {
|
public List<Integer> findAllProjectNumber(Integer projectId) throws BadRequestException {
|
||||||
List<Integer> res= new ArrayList<>();
|
List<Integer> res = new ArrayList<>();
|
||||||
List<ProjectGroup> targetProject = baseMapper.selectList(Wrappers.<ProjectGroup>lambdaQuery().eq(ProjectGroup::getProjectId, projectId));
|
List<ProjectGroup> targetProject = baseMapper.selectList(Wrappers.<ProjectGroup>lambdaQuery().eq(ProjectGroup::getProjectId, projectId));
|
||||||
if(targetProject.size() == 0)
|
if (targetProject.size() == 0)
|
||||||
throw new BadRequestException("项目不存在");
|
throw new BadRequestException("项目不存在");
|
||||||
for (int i = 0; i < targetProject.size(); i++) {
|
for (int i = 0; i < targetProject.size(); i++) {
|
||||||
res.add(targetProject.get(i).getStaffId());
|
res.add(targetProject.get(i).getStaffId());
|
||||||
|
|
|
@ -23,7 +23,6 @@ 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
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ public class BeanUtils {
|
||||||
/**
|
/**
|
||||||
* 将bean转成map,被标注{@link DoNotDeserialize}注释的变量会被跳过
|
* 将bean转成map,被标注{@link DoNotDeserialize}注释的变量会被跳过
|
||||||
*
|
*
|
||||||
* @param putNulls 是否将值为null的变量也放入结果map
|
* @param putNulls 是否将值为null的变量也放入结果map
|
||||||
* @param toUnderline 是否将变量命名转为下划线型
|
* @param toUnderline 是否将变量命名转为下划线型
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> beanToMap(Object object, boolean toUnderline, boolean putNulls) {
|
public static Map<String, Object> beanToMap(Object object, boolean toUnderline, boolean putNulls) {
|
||||||
|
@ -57,6 +58,7 @@ public class BeanUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查是否objects全都非null
|
* 检查是否objects全都非null
|
||||||
|
*
|
||||||
* @return 都非null则true,否则false
|
* @return 都非null则true,否则false
|
||||||
*/
|
*/
|
||||||
public static boolean checkAllNotNull(Object... objects) {
|
public static boolean checkAllNotNull(Object... objects) {
|
||||||
|
@ -70,6 +72,7 @@ public class BeanUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查是否objects含有非null
|
* 检查是否objects含有非null
|
||||||
|
*
|
||||||
* @return 有则true,否则false
|
* @return 有则true,否则false
|
||||||
*/
|
*/
|
||||||
public static boolean checkAnyNotNull(Object... objects) {
|
public static boolean checkAnyNotNull(Object... objects) {
|
||||||
|
@ -80,4 +83,8 @@ public class BeanUtils {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean checkInSet(Object object, Object... set) {
|
||||||
|
return Arrays.asList(set).contains(object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue