添加了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;
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

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

View File

@ -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,50 +39,83 @@ 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());
}
public Boolean checkLegalFather(Task father) {
if(father==null||father.getTaskId()==null)
return false;
if(father.getTaskId()==0)
private Boolean checkAttachedInfo() {
if (attachedInfo == null || attachedInfo.isEmpty()) {
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;
}
else if(this.getTaskType().equals("需求")){
return father.getTaskType().equals("需求");
if (attachedInfo.containsKey(ATTACH_ESTIMATED_MAN_HOURS) &&
!(attachedInfo.get(ATTACH_ESTIMATED_MAN_HOURS) instanceof Integer i
&& i > 0
)
) {
return false;
}
else if(this.getTaskType().equals("任务")){
return father.getTaskType().equals("需求")||father.getTaskType().equals("任务");
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("关闭"))
public Boolean checkModification(Task rawTask) {
if (rawTask.getTaskStatus().equals("已完成") || rawTask.getTaskStatus().equals("关闭"))
return false;
if(!rawTask.getTaskStatus().equals("待进行")&&this.getTaskStatus().equals("待进行"))
if (!rawTask.getTaskStatus().equals("待进行") && this.getTaskStatus().equals("待进行"))
return false;
if(!Objects.equals(rawTask.getTaskId(),this.getTaskId()))
if (!Objects.equals(rawTask.getTaskId(), this.getTaskId()))
return false;
if(!Objects.equals(rawTask.getTaskProjectId(),this.getTaskProjectId()))
if (!Objects.equals(rawTask.getTaskProjectId(), this.getTaskProjectId()))
return false;
if(!Objects.equals(rawTask.getTaskFatherId(),this.getTaskFatherId()))
if (!Objects.equals(rawTask.getTaskFatherId(), this.getTaskFatherId()))
return false;
if(!Objects.equals(rawTask.getTaskType(),this.getTaskType()))
if (!Objects.equals(rawTask.getTaskType(), this.getTaskType()))
return false;
if(!Objects.equals(rawTask.getTaskCreatedTime(),this.getTaskCreatedTime()))
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());
}
}

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

@ -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 {
@ -49,9 +49,9 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
@Override
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));
if(targetProject.size() == 0)
if (targetProject.size() == 0)
throw new BadRequestException("项目不存在");
for (int i = 0; i < targetProject.size(); i++) {
res.add(targetProject.get(i).getStaffId());

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

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;
@ -17,7 +18,7 @@ public class BeanUtils {
/**
* beanmap{@link DoNotDeserialize}
*
* @param putNulls nullmap
* @param putNulls nullmap
* @param toUnderline 线
*/
public static Map<String, Object> beanToMap(Object object, boolean toUnderline, boolean putNulls) {
@ -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);
}
}