添加了UnauthorizedException,修改了Task以适配attachedInfo,添加了FIXME,格式化了代码
parent
e3462d0ed7
commit
5e26599858
|
@ -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());
|
||||
|
|
|
@ -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.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;
|
||||
|
@ -22,14 +23,10 @@ public class ProjectGroupController {
|
|||
@Autowired
|
||||
private IProjectGroupService projectGroupService;
|
||||
|
||||
@SneakyThrows
|
||||
@GetMapping
|
||||
public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId) {
|
||||
List<Integer> res = null;
|
||||
try {
|
||||
res = projectGroupService.findAllProjectNumber(projectId);
|
||||
} catch (BadRequestException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
List<Integer> res = projectGroupService.findAllProjectNumber(projectId);
|
||||
return ResponseList.ofSuccess("查询成功", res);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
|
@ -15,6 +19,12 @@ import java.util.Objects;
|
|||
*/
|
||||
@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;
|
||||
|
@ -29,17 +39,53 @@ public class Task {
|
|||
private LocalDateTime taskClosedTime;
|
||||
private Integer taskPriority;
|
||||
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")
|
||||
@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;
|
||||
|
@ -47,15 +93,14 @@ public class Task {
|
|||
return true;
|
||||
if (this.getTaskType().equals("缺陷")) {
|
||||
return false;
|
||||
}
|
||||
else if(this.getTaskType().equals("需求")){
|
||||
} else if (this.getTaskType().equals("需求")) {
|
||||
return father.getTaskType().equals("需求");
|
||||
}
|
||||
else if(this.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;
|
||||
|
@ -71,8 +116,6 @@ public class Task {
|
|||
return false;
|
||||
if (!Objects.equals(rawTask.getTaskCreatedTime(), this.getTaskCreatedTime()))
|
||||
return false;
|
||||
if(!Objects.equals(rawTask.getTaskClosedTime(),this.getTaskClosedTime()))
|
||||
return false;
|
||||
return true;
|
||||
return Objects.equals(rawTask.getTaskClosedTime(), this.getTaskClosedTime());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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.exception.BadRequestException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectGroupMapper;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
||||
|
@ -31,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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
|||
|
||||
/**
|
||||
* 检查是否objects全都非null
|
||||
*
|
||||
* @return 都非null则true,否则false
|
||||
*/
|
||||
public static boolean checkAllNotNull(Object... objects) {
|
||||
|
@ -70,6 +72,7 @@ public class BeanUtils {
|
|||
|
||||
/**
|
||||
* 检查是否objects含有非null
|
||||
*
|
||||
* @return 有则true,否则false
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue