Compare commits
No commits in common. "ee3e03941ca13c720ab5f46cfc9a8d7205e1eb88" and "92a93bce6b7ee6477849ca0cfd171915c2b05c7f" have entirely different histories.
ee3e03941c
...
92a93bce6b
|
@ -1,14 +0,0 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface ProjectAuthorize {
|
||||
/**
|
||||
* 填写逻辑判断式,用p代表项目内权限,g代表全局权限,拥有1级全局权限的人默认拥有所有项目内权限
|
||||
* 如 "p>0 && p<3",指该接口只有在该项目的权限大于3的人才能执行
|
||||
*/
|
||||
String value();
|
||||
}
|
|
@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* @author 佘语殊
|
||||
* @since 2022/7/11 16:57
|
||||
*/
|
||||
//TODO: 加到代码里
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Target({ElementType.METHOD})
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|||
* @author 张韬
|
||||
* created at 2022/6/28 19:44
|
||||
*/
|
||||
//TODO: 整机限流
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
@Bean
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
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.dto.AnnouncementDTO;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
||||
|
@ -18,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
* @author 佘语殊
|
||||
* @since 2022/7/7 11:29
|
||||
*/
|
||||
//TODO: TEST
|
||||
@RestController
|
||||
@RequestMapping("/project/{projectId}/announcement")
|
||||
public class AnnouncementController {
|
||||
|
@ -50,21 +50,18 @@ public class AnnouncementController {
|
|||
}
|
||||
|
||||
@SneakyThrows
|
||||
@ProjectAuthorize("a>0 && a<=2")
|
||||
@PostMapping
|
||||
public ResponseMap createAnnouncement(
|
||||
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
|
||||
@RequestAttribute Integer staffId,
|
||||
@RequestHeader(TokenUtils.HEADER_TOKEN) String token,
|
||||
@PathVariable Integer projectId,
|
||||
@RequestBody Announcement announcement
|
||||
) {
|
||||
/*Integer accessLevel = projectGroupService.getProjectAccessLevel(token, projectId);
|
||||
Integer accessLevel = projectGroupService.getProjectAccessLevel(token, projectId);
|
||||
if (accessLevel == 0 || accessLevel > 2) {
|
||||
throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
|
||||
}*/
|
||||
}
|
||||
announcement.setProjectId(projectId);
|
||||
// announcement.setAnnouncementPublisherId(TokenUtils.getStaffId(token));
|
||||
announcement.setAnnouncementPublisherId(staffId);
|
||||
announcement.setAnnouncementPublisherId(TokenUtils.getStaffId(token));
|
||||
announcement.setAnnouncementPublishTime(null);
|
||||
if (announcementService.save(announcement)) {
|
||||
return ResponseMap.ofSuccess();
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ProjectController {
|
|||
private IProjectGroupService projectGroupService;
|
||||
|
||||
@Operation(summary = "根据Token获取该员工的ProjectList")
|
||||
@RateLimit(key = "ProjectPage", permitsPerSecond = 50, maxBurstSeconds = 15, timeout = 1200)
|
||||
//@RateLimit(permitsPerSecond = 1, maxBurstSeconds = 5)
|
||||
@SneakyThrows
|
||||
@GetMapping
|
||||
public ResponseList<ProjectDTO> getProjectListOfStaff(
|
||||
|
|
|
@ -140,6 +140,7 @@ public class ProjectGroupController {
|
|||
throw new BadRequestException(BadRequestException.OPERATE_FAILED);
|
||||
}
|
||||
|
||||
//TODO: TEST
|
||||
@Operation(description = "将staffId的所有工作项转移至targetStaffId")
|
||||
@SneakyThrows
|
||||
@PutMapping("/{staffId}/transfer/{targetStaffId}")
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
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.dto.StaffProcessDTO;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.TaskDTO;
|
||||
|
@ -40,7 +39,6 @@ public class TaskController {
|
|||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RateLimit(key = "TaskMine", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200)
|
||||
@GetMapping("/mine")
|
||||
public ResponseList<TaskDTO> getMyTasks(@RequestHeader(TokenUtils.HEADER_TOKEN) String token, @PathVariable("projectId") Integer projectId) {
|
||||
List<TaskDTO> result = taskService.listMyTasks(token, projectId);
|
||||
|
@ -73,7 +71,6 @@ public class TaskController {
|
|||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RateLimit(key = "TaskModify", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200)
|
||||
@PutMapping("/{taskId}")
|
||||
public ResponseMap modifyTask(
|
||||
@RequestHeader(TokenUtils.HEADER_TOKEN) String token,
|
||||
|
@ -91,7 +88,6 @@ public class TaskController {
|
|||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RateLimit(key = "TaskModify", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200)
|
||||
@DeleteMapping("/{taskId}")
|
||||
public ResponseMap deleteTaskAndSubTask(
|
||||
@RequestHeader(TokenUtils.HEADER_TOKEN) String token,
|
||||
|
@ -105,7 +101,6 @@ public class TaskController {
|
|||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RateLimit(key = "TaskTrend", permitsPerSecond = 50, maxBurstSeconds = 15, timeout = 1200)
|
||||
@GetMapping("/stats/trend")
|
||||
public ResponseMap getTaskTrend(
|
||||
@RequestHeader(TokenUtils.HEADER_TOKEN) String token,
|
||||
|
|
|
@ -20,5 +20,6 @@ public class Staff {
|
|||
private String staffPassword;
|
||||
@DoNotSerialize
|
||||
private String staffSalt;
|
||||
//TODO: 详细测试
|
||||
private Integer staffGlobalLevel;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,10 @@ public class TokenInterceptor implements HandlerInterceptor {
|
|||
@Autowired
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
|
||||
//FIXME: 最终上线时要把这里的输出删掉
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws TokenException {
|
||||
// log.debug(httpServletRequest.getRequestURL() + " " + httpServletRequest.getMethod());
|
||||
// System.out.println(httpServletRequest.getRequestURL() + " " + httpServletRequest.getMethod());
|
||||
String token = httpServletRequest.getHeader(TokenUtils.HEADER_TOKEN);
|
||||
if (null == token || "".equals(token.trim())) {
|
||||
throw new TokenException("缺少Token");
|
||||
|
@ -36,8 +37,8 @@ public class TokenInterceptor implements HandlerInterceptor {
|
|||
if (TokenUtils.checkTimeOut(token)) {
|
||||
throw new TokenException("Token已过期");
|
||||
}
|
||||
// log.debug(Objects.requireNonNull(TokenUtils.getStaffId(token)));
|
||||
// log.debug(token);
|
||||
// System.out.println(Objects.requireNonNull(TokenUtils.getStaffId(token)));
|
||||
// System.out.println(token);
|
||||
if (!token.equals(redisTemplate.opsForValue().get(Objects.<Integer>requireNonNull(TokenUtils.getStaffId(token))))) {
|
||||
throw new TokenException("请重新登录");
|
||||
}
|
||||
|
@ -49,11 +50,6 @@ public class TokenInterceptor implements HandlerInterceptor {
|
|||
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);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|||
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
|
||||
}
|
||||
|
||||
//FIXME: 改为特定Exception处理
|
||||
try {
|
||||
if (baseMapper.insert(project) == 1) {
|
||||
return projectGroupService.addCreator(project.getProjectId(), TokenUtils.getStaffId(token));
|
||||
|
|
|
@ -146,28 +146,28 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
|||
if (totalCount < 1) {
|
||||
throw new BadRequestException("读取不到条目");
|
||||
}
|
||||
// log.debug(totalCount);
|
||||
// log.debug(staffUsernameC);
|
||||
// System.out.println(totalCount);
|
||||
// System.out.println(staffUsernameC);
|
||||
if (!xlsxColumnGetter("staffPassword", 1, staffPasswordC, sheet) ||
|
||||
staffPasswordC.size() != totalCount) {
|
||||
throw new BadRequestException("读取列staffPassword失败");
|
||||
}
|
||||
// log.debug(staffPasswordC);
|
||||
// System.out.println(staffPasswordC);
|
||||
if (!xlsxColumnGetter("staffFullname", 2, staffFullnameC, sheet) ||
|
||||
staffFullnameC.size() != totalCount) {
|
||||
throw new BadRequestException("读取列staffFullname失败");
|
||||
}
|
||||
// log.debug(staffFullnameC);
|
||||
// System.out.println(staffFullnameC);
|
||||
if (!xlsxColumnGetter("staffGender", 3, staffGenderC, sheet) ||
|
||||
staffGenderC.size() != totalCount) {
|
||||
throw new BadRequestException("读取列staffGender失败");
|
||||
}
|
||||
// log.debug(staffGenderC);
|
||||
// System.out.println(staffGenderC);
|
||||
if (!xlsxColumnGetter("staffGlobalLevel", 4, staffGlobalLevelC, sheet) ||
|
||||
staffGlobalLevelC.size() != totalCount) {
|
||||
throw new BadRequestException("读取列staffGlobalLevel失败");
|
||||
}
|
||||
// log.debug(staffGlobalLevelC);
|
||||
// System.out.println(staffGlobalLevelC);
|
||||
if (staffGlobalLevelC.stream().anyMatch(level -> Integer.parseInt(level) < 2)) {
|
||||
throw new BadRequestException("列staffGlobalLevel无效");
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
|||
staff.setStaffFullname(staffFullnameC.get(i));
|
||||
staff.setStaffGender(staffGenderC.get(i));
|
||||
staff.setStaffGlobalLevel(Integer.parseInt(staffGlobalLevelC.get(i)));
|
||||
// log.debug(staff);
|
||||
// System.out.println(staff);
|
||||
if (baseMapper.insert(staff) != 1) {
|
||||
throw new BadRequestException("第" + (i + 1) + "行数据错误");
|
||||
}
|
||||
|
|
|
@ -159,11 +159,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
|
||||
@NotNull
|
||||
private void addResultProjectProcess(List<StaffProcessDTO> resList, String projectType) {
|
||||
boolean typeExist = false;
|
||||
Boolean typeExist = false;
|
||||
for (StaffProcessDTO staffProcessDTO : resList) {
|
||||
if (Objects.equals(staffProcessDTO.getTaskType(), projectType)) {
|
||||
typeExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!typeExist) {
|
||||
|
@ -286,7 +285,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
} catch (Exception e) { //TODO: 需要调整
|
||||
// log.error(e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
|
@ -340,7 +339,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
if (task.getTaskStatus().equals(Task.STATUS_CLOSED))
|
||||
typeChangeValue = 2;
|
||||
}
|
||||
// log.debug(!task.checkModification(rawTask));
|
||||
// System.out.println(!task.checkModification(rawTask));
|
||||
if (!task.checkModification(rawTask) || !task.checkInsert()) {
|
||||
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
|
||||
}
|
||||
|
@ -428,7 +427,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
taskList.add(taskTrend);
|
||||
iterDate = iterDate.plusDays(1);
|
||||
lastNum = taskTrend.getTaskNum();
|
||||
// log.debug(taskTrend.toString());
|
||||
// System.out.println(taskTrend.toString());
|
||||
}
|
||||
// 各个状态返回
|
||||
res.put(iterTask.getTaskStatus(), taskList);
|
||||
|
|
|
@ -14,14 +14,15 @@ import java.util.Date;
|
|||
* @author 张韬
|
||||
* created at 2022/6/28 18:20
|
||||
*/
|
||||
//TODO: 演示的时候把expireTime改短点儿
|
||||
@Component
|
||||
public final class TokenUtils {
|
||||
private final static String PV_KEY = "SignedByRMDJZZ";
|
||||
|
||||
public final static String HEADER_TOKEN = "Token";
|
||||
public final static String STAFF_USERNAME = "staffUsername";
|
||||
public final static String STAFF_ID = "staffId";
|
||||
public final static String STAFF_GLOBAL_LEVEL = "staffGlobalLevel";
|
||||
private final static String STAFF_USERNAME = "staffUsername";
|
||||
private final static String STAFF_ID = "staffId";
|
||||
private final static String STAFF_GLOBAL_LEVEL = "staffGlobalLevel";
|
||||
private final static String DURATION = "duration";
|
||||
|
||||
public static String getToken(String staffUsername, Integer staffId, Integer staffGlobalLevel, Long duration) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TimeUtils;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
@ -22,11 +21,4 @@ public class UtilTests {
|
|||
LocalTime t = LocalTime.now();
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue