添加了UnauthorizedException,修改了Task以适配attachedInfo,添加了FIXME,格式化了代码

master
ArgonarioD 2022-07-06 00:07:29 +08:00
parent e3462d0ed7
commit 5e26599858
8 changed files with 95 additions and 38 deletions

View File

@ -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());

View File

@ -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);
} }
} }

View File

@ -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,17 +39,53 @@ 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());
} }
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) { public Boolean checkLegalFather(Task father) {
if (father == null || father.getTaskId() == null) if (father == null || father.getTaskId() == null)
return false; return false;
@ -47,15 +93,14 @@ public class Task {
return true; return true;
if (this.getTaskType().equals("缺陷")) { if (this.getTaskType().equals("缺陷")) {
return false; return false;
} } else if (this.getTaskType().equals("需求")) {
else if(this.getTaskType().equals("需求")){
return father.getTaskType().equals("需求"); return father.getTaskType().equals("需求");
} } else if (this.getTaskType().equals("任务")) {
else if(this.getTaskType().equals("任务")){
return father.getTaskType().equals("需求") || father.getTaskType().equals("任务"); return father.getTaskType().equals("需求") || father.getTaskType().equals("任务");
} }
return false; return false;
} }
public Boolean checkModification(Task rawTask) { public Boolean checkModification(Task rawTask) {
if (rawTask.getTaskStatus().equals("已完成") || rawTask.getTaskStatus().equals("关闭")) if (rawTask.getTaskStatus().equals("已完成") || rawTask.getTaskStatus().equals("关闭"))
return false; return false;
@ -71,8 +116,6 @@ public class Task {
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;
} }
} }

View File

@ -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);
} }

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

@ -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 {

View File

@ -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

View File

@ -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;
@ -57,6 +58,7 @@ public class BeanUtils {
/** /**
* objectsnull * objectsnull
*
* @return nulltruefalse * @return nulltruefalse
*/ */
public static boolean checkAllNotNull(Object... objects) { public static boolean checkAllNotNull(Object... objects) {
@ -70,6 +72,7 @@ public class BeanUtils {
/** /**
* objectsnull * objectsnull
*
* @return truefalse * @return truefalse
*/ */
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);
}
} }