Compare commits

...

3 Commits

14 changed files with 59 additions and 30 deletions

View File

@ -0,0 +1,14 @@
package cn.edu.hfut.rmdjzz.projectmanagement.annotation;
import java.lang.annotation.*;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ProjectAuthorize {
/**
* pg1
* "p>0 && p<3"3
*/
String value();
}

View File

@ -7,7 +7,6 @@ import java.util.concurrent.TimeUnit;
* @author * @author
* @since 2022/7/11 16:57 * @since 2022/7/11 16:57
*/ */
//TODO: 加到代码里
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@Target({ElementType.METHOD}) @Target({ElementType.METHOD})

View File

@ -11,7 +11,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @author * @author
* created at 2022/6/28 19:44 * created at 2022/6/28 19:44
*/ */
//TODO: 整机限流
@Configuration @Configuration
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
@Bean @Bean

View File

@ -1,5 +1,6 @@
package cn.edu.hfut.rmdjzz.projectmanagement.controller; package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.annotation.ProjectAuthorize;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Announcement; import cn.edu.hfut.rmdjzz.projectmanagement.entity.Announcement;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.AnnouncementDTO; import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.AnnouncementDTO;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException; import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
@ -17,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
* @author * @author
* @since 2022/7/7 11:29 * @since 2022/7/7 11:29
*/ */
//TODO: TEST
@RestController @RestController
@RequestMapping("/project/{projectId}/announcement") @RequestMapping("/project/{projectId}/announcement")
public class AnnouncementController { public class AnnouncementController {
@ -50,18 +50,21 @@ public class AnnouncementController {
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a>0 && a<=2")
@PostMapping @PostMapping
public ResponseMap createAnnouncement( public ResponseMap createAnnouncement(
@RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Integer staffId,
@PathVariable Integer projectId, @PathVariable Integer projectId,
@RequestBody Announcement announcement @RequestBody Announcement announcement
) { ) {
Integer accessLevel = projectGroupService.getProjectAccessLevel(token, projectId); /*Integer accessLevel = projectGroupService.getProjectAccessLevel(token, projectId);
if (accessLevel == 0 || accessLevel > 2) { if (accessLevel == 0 || accessLevel > 2) {
throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
} }*/
announcement.setProjectId(projectId); announcement.setProjectId(projectId);
announcement.setAnnouncementPublisherId(TokenUtils.getStaffId(token)); // announcement.setAnnouncementPublisherId(TokenUtils.getStaffId(token));
announcement.setAnnouncementPublisherId(staffId);
announcement.setAnnouncementPublishTime(null); announcement.setAnnouncementPublishTime(null);
if (announcementService.save(announcement)) { if (announcementService.save(announcement)) {
return ResponseMap.ofSuccess(); return ResponseMap.ofSuccess();

View File

@ -34,7 +34,7 @@ public class ProjectController {
private IProjectGroupService projectGroupService; private IProjectGroupService projectGroupService;
@Operation(summary = "根据Token获取该员工的ProjectList") @Operation(summary = "根据Token获取该员工的ProjectList")
//@RateLimit(permitsPerSecond = 1, maxBurstSeconds = 5) @RateLimit(key = "ProjectPage", permitsPerSecond = 50, maxBurstSeconds = 15, timeout = 1200)
@SneakyThrows @SneakyThrows
@GetMapping @GetMapping
public ResponseList<ProjectDTO> getProjectListOfStaff( public ResponseList<ProjectDTO> getProjectListOfStaff(

View File

@ -140,7 +140,6 @@ public class ProjectGroupController {
throw new BadRequestException(BadRequestException.OPERATE_FAILED); throw new BadRequestException(BadRequestException.OPERATE_FAILED);
} }
//TODO: TEST
@Operation(description = "将staffId的所有工作项转移至targetStaffId") @Operation(description = "将staffId的所有工作项转移至targetStaffId")
@SneakyThrows @SneakyThrows
@PutMapping("/{staffId}/transfer/{targetStaffId}") @PutMapping("/{staffId}/transfer/{targetStaffId}")

View File

@ -1,5 +1,6 @@
package cn.edu.hfut.rmdjzz.projectmanagement.controller; package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.annotation.RateLimit;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task; import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.StaffProcessDTO; import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.StaffProcessDTO;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.TaskDTO; import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.TaskDTO;
@ -39,6 +40,7 @@ public class TaskController {
} }
@SneakyThrows @SneakyThrows
@RateLimit(key = "TaskMine", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200)
@GetMapping("/mine") @GetMapping("/mine")
public ResponseList<TaskDTO> getMyTasks(@RequestHeader(TokenUtils.HEADER_TOKEN) String token, @PathVariable("projectId") Integer projectId) { public ResponseList<TaskDTO> getMyTasks(@RequestHeader(TokenUtils.HEADER_TOKEN) String token, @PathVariable("projectId") Integer projectId) {
List<TaskDTO> result = taskService.listMyTasks(token, projectId); List<TaskDTO> result = taskService.listMyTasks(token, projectId);
@ -71,6 +73,7 @@ public class TaskController {
} }
@SneakyThrows @SneakyThrows
@RateLimit(key = "TaskModify", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200)
@PutMapping("/{taskId}") @PutMapping("/{taskId}")
public ResponseMap modifyTask( public ResponseMap modifyTask(
@RequestHeader(TokenUtils.HEADER_TOKEN) String token, @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@ -88,6 +91,7 @@ public class TaskController {
} }
@SneakyThrows @SneakyThrows
@RateLimit(key = "TaskModify", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200)
@DeleteMapping("/{taskId}") @DeleteMapping("/{taskId}")
public ResponseMap deleteTaskAndSubTask( public ResponseMap deleteTaskAndSubTask(
@RequestHeader(TokenUtils.HEADER_TOKEN) String token, @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@ -101,6 +105,7 @@ public class TaskController {
} }
@SneakyThrows @SneakyThrows
@RateLimit(key = "TaskTrend", permitsPerSecond = 50, maxBurstSeconds = 15, timeout = 1200)
@GetMapping("/stats/trend") @GetMapping("/stats/trend")
public ResponseMap getTaskTrend( public ResponseMap getTaskTrend(
@RequestHeader(TokenUtils.HEADER_TOKEN) String token, @RequestHeader(TokenUtils.HEADER_TOKEN) String token,

View File

@ -20,6 +20,5 @@ public class Staff {
private String staffPassword; private String staffPassword;
@DoNotSerialize @DoNotSerialize
private String staffSalt; private String staffSalt;
//TODO: 详细测试
private Integer staffGlobalLevel; private Integer staffGlobalLevel;
} }

View File

@ -23,10 +23,9 @@ public class TokenInterceptor implements HandlerInterceptor {
@Autowired @Autowired
private RedisTemplate<Object, Object> redisTemplate; private RedisTemplate<Object, Object> redisTemplate;
//FIXME: 最终上线时要把这里的输出删掉
@Override @Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws TokenException { public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws TokenException {
// System.out.println(httpServletRequest.getRequestURL() + " " + httpServletRequest.getMethod()); // log.debug(httpServletRequest.getRequestURL() + " " + httpServletRequest.getMethod());
String token = httpServletRequest.getHeader(TokenUtils.HEADER_TOKEN); String token = httpServletRequest.getHeader(TokenUtils.HEADER_TOKEN);
if (null == token || "".equals(token.trim())) { if (null == token || "".equals(token.trim())) {
throw new TokenException("缺少Token"); throw new TokenException("缺少Token");
@ -37,8 +36,8 @@ public class TokenInterceptor implements HandlerInterceptor {
if (TokenUtils.checkTimeOut(token)) { if (TokenUtils.checkTimeOut(token)) {
throw new TokenException("Token已过期"); throw new TokenException("Token已过期");
} }
// System.out.println(Objects.requireNonNull(TokenUtils.getStaffId(token))); // log.debug(Objects.requireNonNull(TokenUtils.getStaffId(token)));
// System.out.println(token); // log.debug(token);
if (!token.equals(redisTemplate.opsForValue().get(Objects.<Integer>requireNonNull(TokenUtils.getStaffId(token))))) { if (!token.equals(redisTemplate.opsForValue().get(Objects.<Integer>requireNonNull(TokenUtils.getStaffId(token))))) {
throw new TokenException("请重新登录"); throw new TokenException("请重新登录");
} }
@ -50,6 +49,11 @@ public class TokenInterceptor implements HandlerInterceptor {
Objects.requireNonNull(TokenUtils.getDuration(token)), TimeUnit.SECONDS Objects.requireNonNull(TokenUtils.getDuration(token)), TimeUnit.SECONDS
); );
} }
httpServletRequest.setAttribute(TokenUtils.STAFF_USERNAME, TokenUtils.getUsername(token));
httpServletRequest.setAttribute(TokenUtils.STAFF_ID, TokenUtils.getStaffId(token));
httpServletRequest.setAttribute(TokenUtils.STAFF_GLOBAL_LEVEL, TokenUtils.getStaffGlobalLevel(token));
httpServletResponse.setHeader(TokenUtils.HEADER_TOKEN, newToken); httpServletResponse.setHeader(TokenUtils.HEADER_TOKEN, newToken);
return true; return true;
} }

View File

@ -98,7 +98,6 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS); throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
} }
//FIXME: 改为特定Exception处理
try { try {
if (baseMapper.insert(project) == 1) { if (baseMapper.insert(project) == 1) {
return projectGroupService.addCreator(project.getProjectId(), TokenUtils.getStaffId(token)); return projectGroupService.addCreator(project.getProjectId(), TokenUtils.getStaffId(token));

View File

@ -146,28 +146,28 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
if (totalCount < 1) { if (totalCount < 1) {
throw new BadRequestException("读取不到条目"); throw new BadRequestException("读取不到条目");
} }
// System.out.println(totalCount); // log.debug(totalCount);
// System.out.println(staffUsernameC); // log.debug(staffUsernameC);
if (!xlsxColumnGetter("staffPassword", 1, staffPasswordC, sheet) || if (!xlsxColumnGetter("staffPassword", 1, staffPasswordC, sheet) ||
staffPasswordC.size() != totalCount) { staffPasswordC.size() != totalCount) {
throw new BadRequestException("读取列staffPassword失败"); throw new BadRequestException("读取列staffPassword失败");
} }
// System.out.println(staffPasswordC); // log.debug(staffPasswordC);
if (!xlsxColumnGetter("staffFullname", 2, staffFullnameC, sheet) || if (!xlsxColumnGetter("staffFullname", 2, staffFullnameC, sheet) ||
staffFullnameC.size() != totalCount) { staffFullnameC.size() != totalCount) {
throw new BadRequestException("读取列staffFullname失败"); throw new BadRequestException("读取列staffFullname失败");
} }
// System.out.println(staffFullnameC); // log.debug(staffFullnameC);
if (!xlsxColumnGetter("staffGender", 3, staffGenderC, sheet) || if (!xlsxColumnGetter("staffGender", 3, staffGenderC, sheet) ||
staffGenderC.size() != totalCount) { staffGenderC.size() != totalCount) {
throw new BadRequestException("读取列staffGender失败"); throw new BadRequestException("读取列staffGender失败");
} }
// System.out.println(staffGenderC); // log.debug(staffGenderC);
if (!xlsxColumnGetter("staffGlobalLevel", 4, staffGlobalLevelC, sheet) || if (!xlsxColumnGetter("staffGlobalLevel", 4, staffGlobalLevelC, sheet) ||
staffGlobalLevelC.size() != totalCount) { staffGlobalLevelC.size() != totalCount) {
throw new BadRequestException("读取列staffGlobalLevel失败"); throw new BadRequestException("读取列staffGlobalLevel失败");
} }
// System.out.println(staffGlobalLevelC); // log.debug(staffGlobalLevelC);
if (staffGlobalLevelC.stream().anyMatch(level -> Integer.parseInt(level) < 2)) { if (staffGlobalLevelC.stream().anyMatch(level -> Integer.parseInt(level) < 2)) {
throw new BadRequestException("列staffGlobalLevel无效"); throw new BadRequestException("列staffGlobalLevel无效");
} }
@ -184,7 +184,7 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
staff.setStaffFullname(staffFullnameC.get(i)); staff.setStaffFullname(staffFullnameC.get(i));
staff.setStaffGender(staffGenderC.get(i)); staff.setStaffGender(staffGenderC.get(i));
staff.setStaffGlobalLevel(Integer.parseInt(staffGlobalLevelC.get(i))); staff.setStaffGlobalLevel(Integer.parseInt(staffGlobalLevelC.get(i)));
// System.out.println(staff); // log.debug(staff);
if (baseMapper.insert(staff) != 1) { if (baseMapper.insert(staff) != 1) {
throw new BadRequestException("第" + (i + 1) + "行数据错误"); throw new BadRequestException("第" + (i + 1) + "行数据错误");
} }

View File

@ -159,10 +159,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
@NotNull @NotNull
private void addResultProjectProcess(List<StaffProcessDTO> resList, String projectType) { private void addResultProjectProcess(List<StaffProcessDTO> resList, String projectType) {
Boolean typeExist = false; boolean typeExist = false;
for (StaffProcessDTO staffProcessDTO : resList) { for (StaffProcessDTO staffProcessDTO : resList) {
if (Objects.equals(staffProcessDTO.getTaskType(), projectType)) { if (Objects.equals(staffProcessDTO.getTaskType(), projectType)) {
typeExist = true; typeExist = true;
break;
} }
} }
if (!typeExist) { if (!typeExist) {
@ -285,7 +286,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
return false; return false;
} }
return true; return true;
} catch (Exception e) { //TODO: 需要调整 } catch (Exception e) {
// log.error(e.getMessage(), e); // log.error(e.getMessage(), e);
return false; return false;
} }
@ -339,7 +340,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
if (task.getTaskStatus().equals(Task.STATUS_CLOSED)) if (task.getTaskStatus().equals(Task.STATUS_CLOSED))
typeChangeValue = 2; typeChangeValue = 2;
} }
// System.out.println(!task.checkModification(rawTask)); // log.debug(!task.checkModification(rawTask));
if (!task.checkModification(rawTask) || !task.checkInsert()) { if (!task.checkModification(rawTask) || !task.checkInsert()) {
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS); throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
} }
@ -427,7 +428,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
taskList.add(taskTrend); taskList.add(taskTrend);
iterDate = iterDate.plusDays(1); iterDate = iterDate.plusDays(1);
lastNum = taskTrend.getTaskNum(); lastNum = taskTrend.getTaskNum();
// System.out.println(taskTrend.toString()); // log.debug(taskTrend.toString());
} }
// 各个状态返回 // 各个状态返回
res.put(iterTask.getTaskStatus(), taskList); res.put(iterTask.getTaskStatus(), taskList);

View File

@ -14,15 +14,14 @@ import java.util.Date;
* @author * @author
* created at 2022/6/28 18:20 * created at 2022/6/28 18:20
*/ */
//TODO: 演示的时候把expireTime改短点儿
@Component @Component
public final class TokenUtils { public final class TokenUtils {
private final static String PV_KEY = "SignedByRMDJZZ"; private final static String PV_KEY = "SignedByRMDJZZ";
public final static String HEADER_TOKEN = "Token"; public final static String HEADER_TOKEN = "Token";
private final static String STAFF_USERNAME = "staffUsername"; public final static String STAFF_USERNAME = "staffUsername";
private final static String STAFF_ID = "staffId"; public final static String STAFF_ID = "staffId";
private final static String STAFF_GLOBAL_LEVEL = "staffGlobalLevel"; public final static String STAFF_GLOBAL_LEVEL = "staffGlobalLevel";
private final static String DURATION = "duration"; private final static String DURATION = "duration";
public static String getToken(String staffUsername, Integer staffId, Integer staffGlobalLevel, Long duration) { public static String getToken(String staffUsername, Integer staffId, Integer staffGlobalLevel, Long duration) {

View File

@ -1,6 +1,7 @@
package cn.edu.hfut.rmdjzz.projectmanagement; package cn.edu.hfut.rmdjzz.projectmanagement;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TimeUtils; import cn.edu.hfut.rmdjzz.projectmanagement.utils.TimeUtils;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.time.LocalDate; import java.time.LocalDate;
@ -21,4 +22,11 @@ public class UtilTests {
LocalTime t = LocalTime.now(); LocalTime t = LocalTime.now();
System.out.println(TimeUtils.validateDateTimeLine(a, b, c)); System.out.println(TimeUtils.validateDateTimeLine(a, b, c));
} }
@SneakyThrows
@Test
public void test() {
Class<?> returnType = this.getClass().getMethod("timeTest").getReturnType();
System.out.println(returnType.equals(void.class));
}
} }