Compare commits

..

No commits in common. "3b35115cb6eae948c465aca2a95b1c5e3e01b41c" and "2cf9f1af635c50017816cd5f70b8e14f759b20c2" have entirely different histories.

12 changed files with 238 additions and 271 deletions

View File

@ -2,14 +2,17 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.annotation.ProjectAuthorize; 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.ProjectGroup;
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;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.ForbiddenException; import cn.edu.hfut.rmdjzz.projectmanagement.exception.ForbiddenException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IAnnouncementService; import cn.edu.hfut.rmdjzz.projectmanagement.service.IAnnouncementService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService; import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils; import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -28,23 +31,37 @@ public class AnnouncementController {
private IProjectGroupService projectGroupService; private IProjectGroupService projectGroupService;
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0")
@GetMapping @GetMapping
public ResponseList<AnnouncementDTO> getAnnouncementList( public ResponseList<AnnouncementDTO> getAnnouncementList(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@PathVariable Integer projectId @PathVariable Integer projectId,
@PathVariable Integer staffId
) { ) {
// if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// }
ProjectGroup designatedStaff = projectGroupService.getOne(
Wrappers.<ProjectGroup>lambdaQuery()
.eq(ProjectGroup::getStaffId, staffId)
.eq(ProjectGroup::getProjectId, projectId));
if (designatedStaff == null) { //说明是超级管理员
designatedStaff = new ProjectGroup(staffId, projectId, IStaffService.LEVEL_1, 1);
}
return ResponseList.ofSuccess(announcementService.getAnnouncementList(projectId)); return ResponseList.ofSuccess(announcementService.getAnnouncementList(projectId));
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0") @ProjectAuthorize("a==0")
@GetMapping("/{announcementId}") @GetMapping("/{announcementId}")
public ResponseMap getAnnouncementById( public ResponseMap getAnnouncementById(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Integer accessLevel,
@PathVariable Integer projectId, @PathVariable Integer projectId,
@PathVariable Long announcementId @PathVariable Long announcementId
) { ) {
// if (accessLevel == 0) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// }
return ResponseMap.ofSuccess(announcementService.getAnnouncementById(projectId, announcementId)); return ResponseMap.ofSuccess(announcementService.getAnnouncementById(projectId, announcementId));
} }
@ -88,16 +105,16 @@ public class AnnouncementController {
}*/ }*/
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a>0 && a<=2")
@DeleteMapping("/{announcementId}") @DeleteMapping("/{announcementId}")
public ResponseMap deleteAnnouncement( public ResponseMap deleteAnnouncement(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Integer staffId,
@RequestAttribute Integer globalAccessLevel,
@PathVariable Integer projectId, @PathVariable Integer projectId,
@PathVariable Long announcementId @PathVariable Long announcementId,
@RequestBody Announcement announcement
) { ) {
if (announcementService.deleteAnnouncement(projectId, staffId, globalAccessLevel, announcementId)) { announcement.setProjectId(projectId);
announcement.setAnnouncementId(announcementId);
if (announcementService.removeById(announcement)) {
return ResponseMap.ofSuccess(); return ResponseMap.ofSuccess();
} }
throw new BadRequestException(BadRequestException.OPERATE_FAILED); throw new BadRequestException(BadRequestException.OPERATE_FAILED);

View File

@ -1,11 +1,9 @@
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.annotation.RateLimit; import cn.edu.hfut.rmdjzz.projectmanagement.annotation.RateLimit;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project; import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectDTO; import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectDTO;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException; import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.ForbiddenException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService; import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService; import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils; import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
@ -21,9 +19,6 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import static cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService.PROJECT_COMPLETED;
/** /**
* @author * @author
@ -44,72 +39,65 @@ public class ProjectController {
@GetMapping @GetMapping
public ResponseList<ProjectDTO> getProjectListOfStaff( public ResponseList<ProjectDTO> getProjectListOfStaff(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Integer globalAccessLevel, @PathVariable Integer staffId,
@RequestAttribute Integer staffId,
@Valid RequestPage page, @Valid RequestPage page,
@Parameter(description = "参数列表见Project实体类时间可以用xxxxStart与xxxxEnd来确定区间" @Parameter(description = "参数列表见Project实体类时间可以用xxxxStart与xxxxEnd来确定区间"
, required = true) @RequestParam("paramMap") Map<String, Object> paramMap , required = true) @RequestParam("paramMap") Map<String, Object> paramMap
) { ) {
if(globalAccessLevel == 1) staffId = null;
Page<ProjectDTO> result = projectService.pageMyProjects(staffId, page, paramMap); Page<ProjectDTO> result = projectService.pageMyProjects(staffId, page, paramMap);
return ResponseList.ofSuccess(result); return ResponseList.ofSuccess(result);
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0")
@GetMapping("/{projectId}") @GetMapping("/{projectId}")
public ResponseMap getOneProjectBasicInfo( public ResponseMap getOneProjectBasicInfo(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@PathVariable Integer staffId,
@PathVariable("projectId") Integer projectId @PathVariable("projectId") Integer projectId
) { ) {
if (projectGroupService.getProjectAccessLevel(staffId, projectId) == 0) {
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
}
return ResponseMap.ofSuccess(projectService.getById(projectId)); return ResponseMap.ofSuccess(projectService.getById(projectId));
} }
@Operation(description = "根据Token获取该员工的Project数") @Operation(description = "根据Token获取该员工的Project数")
@SneakyThrows @SneakyThrows
@GetMapping("/count") @GetMapping("/count")
public ResponseMap getProjectNumOfStaff( public ResponseMap getProjectNumOfStaff(@RequestHeader(TokenUtils.HEADER_TOKEN) String token) {
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token
@RequestAttribute Integer staffId
) {
return ResponseMap.ofSuccess() return ResponseMap.ofSuccess()
.put("totalNum", projectService.countMyProjects(staffId)); .put("totalNum", projectService.countMyProjects(token));
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a == 1 || g == 1") @PostMapping("/complete")
@PostMapping("/complete/{projectId}")
public ResponseMap completeProject( public ResponseMap completeProject(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Project targetProject, @PathVariable Integer staffId,
@Parameter(description = "只需要传projectId即可{\"projectId\": 1}") @Parameter(description = "只需要传projectId即可{\"projectId\": 1}")
@PathVariable Integer projectId @RequestBody Map<String, Object> map
) { ) {
if (targetProject.getCompleted()) Integer targetProjectId = (Integer) map.get("projectId");
throw new BadRequestException(PROJECT_COMPLETED); projectService.setProjectCompleted(staffId, targetProjectId);
projectService.setProjectCompleted(targetProject);
return ResponseMap.ofSuccess(); return ResponseMap.ofSuccess();
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("g != 0 && g <= 2")
@PostMapping @PostMapping
public ResponseMap createProject( public ResponseMap createProject(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Integer staffId, @PathVariable Integer staffId,
@RequestBody Project project @RequestBody Project project) {
) {
projectService.createProject(staffId, project); projectService.createProject(staffId, project);
return ResponseMap.ofSuccess(); return ResponseMap.ofSuccess();
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a == 1 || g == 1")
@PutMapping("/{projectId}") @PutMapping("/{projectId}")
public ResponseMap updateProject( public ResponseMap updateProject(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Integer staffId,
@PathVariable Integer projectId, @PathVariable Integer projectId,
@PathVariable Integer staffId,
@RequestBody Project project @RequestBody Project project
) { ) {
project.setProjectId(projectId); project.setProjectId(projectId);
@ -120,17 +108,12 @@ public class ProjectController {
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0")
@GetMapping("/{projectId}/stats") @GetMapping("/{projectId}/stats")
public ResponseMap getProjectProcess( public ResponseMap getProjectProcess(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, // @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Integer staffId, @PathVariable Integer projectId,
@RequestAttribute Integer globalAccessLevel, @PathVariable Integer staffId
@PathVariable Integer projectId
) { ) {
if (Objects.equals(projectId, 0)) { return ResponseMap.ofSuccess(projectService.getProjectProcess(staffId, projectId));
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
}
return ResponseMap.ofSuccess(projectService.getProjectProcess(staffId, globalAccessLevel, projectId));
} }
} }

View File

@ -1,16 +1,12 @@
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.annotation.RateLimit; 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;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException; import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.ForbiddenException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService; import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService; import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.impl.TaskServiceImpl;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils; import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
@ -33,68 +29,54 @@ public class TaskController {
private IProjectService projectService; private IProjectService projectService;
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0")
@GetMapping("/{fatherId}/subtask") @GetMapping("/{fatherId}/subtask")
public ResponseList<TaskDTO> getSubTaskList( public ResponseList<TaskDTO> getSubTaskList(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@PathVariable("projectId") Integer projectId, @PathVariable("projectId") Integer projectId,
@PathVariable("fatherId") Long fatherId @PathVariable("fatherId") Long fatherId
) { ) {
List<TaskDTO> result = taskService.listSubtasks(projectId, fatherId); List<TaskDTO> result = taskService.listSubtasks(token, projectId, fatherId);
return ResponseList.ofSuccess(result); return ResponseList.ofSuccess(result);
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0")
@RateLimit(key = "TaskMine", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200) @RateLimit(key = "TaskMine", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200)
@GetMapping("/mine") @GetMapping("/mine")
public ResponseList<TaskDTO> getMyTasks( public ResponseList<TaskDTO> getMyTasks(@RequestHeader(TokenUtils.HEADER_TOKEN) String token, @PathVariable("projectId") Integer projectId) {
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, List<TaskDTO> result = taskService.listMyTasks(token, projectId);
@RequestAttribute Integer staffId,
@PathVariable("projectId") Integer projectId
) {
List<TaskDTO> result = taskService.listMyTasks(staffId, projectId);
return ResponseList.ofSuccess(result); return ResponseList.ofSuccess(result);
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0")
@GetMapping("/subtask/exist") @GetMapping("/subtask/exist")
public ResponseMap existSubTask( public ResponseMap existSubTask(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@PathVariable("projectId") Integer projectId, @PathVariable("projectId") Integer projectId,
@RequestParam("taskId") Long taskId @RequestParam("taskId") Long taskId
) { ) {
return ResponseMap.ofSuccess() return ResponseMap.ofSuccess()
.put("existSubTask", taskService.existSubTask(projectId, taskId)); .put("existSubTask", taskService.existSubTask(token, projectId, taskId));
} }
@SneakyThrows @SneakyThrows
@PostMapping @PostMapping
public ResponseMap createTask( public ResponseMap createTask(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Integer staffId,
@RequestAttribute Integer globalAccessLevel,
@RequestAttribute Integer accessLevel,
@PathVariable("projectId") Integer projectId, @PathVariable("projectId") Integer projectId,
@RequestBody Task task @RequestBody Task task
) { ) {
if (!projectService.checkOpenStatus(projectId)) if (!projectService.checkOpenStatus(projectId))
throw new BadRequestException(IProjectService.PROJECT_UNOPENED); throw new BadRequestException(IProjectService.PROJECT_UNOPENED);
task.setTaskProjectId(projectId); task.setTaskProjectId(projectId);
taskService.insertTask(staffId, globalAccessLevel, accessLevel, task); taskService.insertTask(token, task);
return ResponseMap.ofSuccess(); return ResponseMap.ofSuccess();
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0")
@RateLimit(key = "TaskModify", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200) @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,
@RequestAttribute Integer staffId,
@RequestAttribute Integer globalAccessLevel,
@RequestAttribute Integer accessLevel,
@PathVariable("projectId") Integer projectId, @PathVariable("projectId") Integer projectId,
@PathVariable("taskId") Long taskId, @PathVariable("taskId") Long taskId,
@RequestBody Task task @RequestBody Task task
@ -104,7 +86,7 @@ public class TaskController {
task.setTaskProjectId(projectId); task.setTaskProjectId(projectId);
task.setTaskId(taskId); task.setTaskId(taskId);
task.setDeleted(false); task.setDeleted(false);
taskService.modifyTask(staffId, globalAccessLevel, accessLevel, task); taskService.modifyTask(token, task);
return ResponseMap.ofSuccess(); return ResponseMap.ofSuccess();
} }
@ -112,59 +94,46 @@ public class TaskController {
@RateLimit(key = "TaskModify", permitsPerSecond = 40, maxBurstSeconds = 15, timeout = 1200) @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,
@RequestAttribute Integer staffId,
@RequestAttribute Integer globalAccessLevel,
@PathVariable("projectId") Integer projectId, @PathVariable("projectId") Integer projectId,
@PathVariable("taskId") Long taskId @PathVariable("taskId") Long taskId
) { ) {
if (!projectService.checkOpenStatus(projectId)) if (!projectService.checkOpenStatus(projectId))
throw new BadRequestException(IProjectService.PROJECT_UNOPENED); throw new BadRequestException(IProjectService.PROJECT_UNOPENED);
Integer level = taskService.getHolderLevel(staffId, globalAccessLevel, taskId); taskService.deleteTaskAndSubTask(token, projectId, taskId);
if (level == 0 || level == 3) {
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
}
taskService.deleteTaskAndSubTask(staffId, globalAccessLevel, taskId);
return ResponseMap.ofSuccess(); return ResponseMap.ofSuccess();
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0")
@RateLimit(key = "TaskTrend", permitsPerSecond = 50, maxBurstSeconds = 15, timeout = 1200) @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,
@PathVariable Integer projectId @PathVariable Integer projectId
) { ) {
if (!projectService.checkOpenStatus(projectId)) { if (!projectService.checkOpenStatus(projectId)) {
throw new BadRequestException(IProjectService.PROJECT_UNOPENED); throw new BadRequestException(IProjectService.PROJECT_UNOPENED);
} }
return ResponseMap.ofSuccess("查询成功", taskService.getProjectTaskTrend(projectId)); return ResponseMap.ofSuccess("查询成功", taskService.getProjectTaskTrend(token, projectId));
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0")
@GetMapping("/stats/group") @GetMapping("/stats/group")
public ResponseMap getTaskNumOfEveryone( public ResponseMap getTaskNumOfEveryone(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@PathVariable Integer projectId @PathVariable Integer projectId
) { ) {
return ResponseMap.ofSuccess("查询成功", taskService.getProjectProcessOfEveryone(projectId)); return ResponseMap.ofSuccess("查询成功", taskService.getProjectProcessOfEveryone(token, projectId));
} }
@SneakyThrows @SneakyThrows
@ProjectAuthorize("a != 0") @GetMapping({"/stats", "/stats/{staffId}"})
@GetMapping({"/stats", "/stats/{targetStaffId}"})
public ResponseList<StaffProcessDTO> getProjectStatistics( public ResponseList<StaffProcessDTO> getProjectStatistics(
// @RequestHeader(TokenUtils.HEADER_TOKEN) String token, @RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@RequestAttribute Integer staffId,
@PathVariable Integer projectId, @PathVariable Integer projectId,
@PathVariable(required = false) Integer targetStaffId @PathVariable(required = false) Integer staffId
) { ) {
if (staffId != null && staffId.equals(targetStaffId)) { return ResponseList.ofSuccess("查询成功", taskService.getProjectStatistics(token, projectId, staffId));
throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
}
return ResponseList.ofSuccess("查询成功", taskService.getProjectStatistics(projectId, targetStaffId));
} }
} }

View File

@ -18,8 +18,8 @@ public interface IAnnouncementService extends IService<Announcement> {
AnnouncementDTO getAnnouncementById(Integer projectId, Long announcementId); AnnouncementDTO getAnnouncementById(Integer projectId, Long announcementId);
// Boolean updateAnnouncement(Integer projectId, Announcement announcement) throws ForbiddenException, BadRequestException; Boolean updateAnnouncement(String token, Integer projectId, Announcement announcement) throws ForbiddenException, BadRequestException;
Boolean deleteAnnouncement(Integer projectId, Integer staffId, Integer globalAccessLevel, Long announcementId) throws ForbiddenException, BadRequestException; Boolean deleteAnnouncement(String token, Integer projectId, Long announcementId) throws ForbiddenException, BadRequestException;
} }

View File

@ -33,6 +33,7 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
/** /**
* @return 0AccessLevel11 * @return 0AccessLevel11
*/ */
Integer getProjectAccessLevel(Integer staffId, Integer projectId);
Integer getProjectAccessLevel(Integer staffId, Integer staffGlobalLevel, Integer projectId); Integer getProjectAccessLevel(Integer staffId, Integer staffGlobalLevel, Integer projectId);
@ -48,7 +49,7 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
* <p> * <p>
* {@link Integer#compare(int, int)}使compareProjectAccessLevel(...)>()0<token * {@link Integer#compare(int, int)}使compareProjectAccessLevel(...)>()0<token
*/ */
Integer compareProjectAccessLevel(Integer projectId, Integer staffId, Integer globalAccessLevel, Integer targetId); Integer compareProjectAccessLevel(Integer projectId, String token, Integer targetId);
Page<ProjectGroupDTO> pageProjectMembers(RequestPage page, Integer projectId); Page<ProjectGroupDTO> pageProjectMembers(RequestPage page, Integer projectId);
@ -61,4 +62,4 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
*/ */
Map<String, Integer> collectStatsForGroupPositions(Integer accessLevel, Integer projectId) throws ForbiddenException; Map<String, Integer> collectStatsForGroupPositions(Integer accessLevel, Integer projectId) throws ForbiddenException;
} }

View File

@ -20,16 +20,28 @@ public interface IProjectService extends IService<Project> {
String PROJECT_UNOPENED = "该项目未开放"; String PROJECT_UNOPENED = "该项目未开放";
String PROJECT_COMPLETED = "该项目已结项"; String PROJECT_COMPLETED = "该项目已结项";
Long countMyProjects(Integer staffId); Long countMyProjects(String token);
ProjectProcessDTO getProjectProcess(Integer staff, Integer globalAccessLevel, Integer projectId) throws ForbiddenException, BadRequestException; ProjectProcessDTO getProjectProcess(Integer staffId, Integer projectId) throws ForbiddenException, BadRequestException;
Page<ProjectDTO> pageMyProjects(Integer staffId, RequestPage page, Map<String, Object> params); Page<ProjectDTO> pageMyProjects(Integer staffId, RequestPage page, Map<String, Object> params);
Boolean setProjectCompleted(Project targetProject) throws BadRequestException, ForbiddenException; Boolean setProjectCompleted(Integer staffId, Integer projectId) throws BadRequestException, ForbiddenException;
ProjectProcessDTO getProjectProcess(String token, Integer projectId) throws ForbiddenException, BadRequestException;
Page<ProjectDTO> pageMyProjects(
String token,
RequestPage page,
Map<String, Object> params
);
Boolean setProjectCompleted(String token, Integer projectId) throws BadRequestException, ForbiddenException;
Boolean createProject(Integer staffId, Project project) throws BadRequestException, ForbiddenException; Boolean createProject(Integer staffId, Project project) throws BadRequestException, ForbiddenException;
Boolean createProject(String token, Project project) throws BadRequestException, ForbiddenException;
Boolean checkOpenStatus(Integer projectId); Boolean checkOpenStatus(Integer projectId);
Boolean updateProject(Integer staffId, Project project) throws BadRequestException, ForbiddenException; Boolean updateProject(Integer staffId, Project project) throws BadRequestException, ForbiddenException;

View File

@ -16,15 +16,15 @@ import java.util.Map;
* created at 2022/7/4 14:49 * created at 2022/7/4 14:49
*/ */
public interface ITaskService extends IService<Task> { public interface ITaskService extends IService<Task> {
List<TaskDTO> listSubtasks(Integer projectId, Long fatherId) throws BadRequestException, ForbiddenException; List<TaskDTO> listSubtasks(String token, Integer projectId, Long fatherId) throws BadRequestException, ForbiddenException;
Boolean existSubTask(Integer projectId, Long taskId) throws BadRequestException, ForbiddenException; Boolean existSubTask(String token, Integer projectId, Long taskId) throws BadRequestException, ForbiddenException;
Boolean deleteTaskAndSubTask(Integer staffId, Integer globalAccessLevel, Long taskId) throws BadRequestException, ForbiddenException; Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException, ForbiddenException;
// Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException; Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException;
List<StaffProcessDTO> getProjectStatistics(Integer projectId, Integer staffId) throws BadRequestException, ForbiddenException; List<StaffProcessDTO> getProjectStatistics(String token, Integer projectId, Integer staffId) throws BadRequestException, ForbiddenException;
/** /**
* @return 1:all rights 2:father holder 3:current holder 0:no right * @return 1:all rights 2:father holder 3:current holder 0:no right
@ -36,21 +36,21 @@ public interface ITaskService extends IService<Task> {
* *
* @return 1:all rights 2:father holder 3:current holder 0:no right * @return 1:all rights 2:father holder 3:current holder 0:no right
*/ */
// Integer getHolderLevel(String token, Long taskId); Integer getHolderLevel(String token, Long taskId);
List<TaskDTO> listMyTasks(Integer staffId, Integer projectId) throws BadRequestException, ForbiddenException; List<TaskDTO> listMyTasks(String token, Integer projectId) throws BadRequestException, ForbiddenException;
Boolean canBeDone(Long taskId); Boolean canBeDone(Long taskId);
Task insertTask(Integer staffId, Integer globalAccessLevel, Integer accessLevel, Task task) throws BadRequestException, ForbiddenException; Task insertTask(String token, Task task) throws BadRequestException, ForbiddenException;
Task modifyTask(Integer staffId, Integer globalAccessLevel, Integer accessLevel, Task task) throws BadRequestException, ForbiddenException; Task modifyTask(String token, Task task) throws BadRequestException, ForbiddenException;
Map<String, List<TaskTrendDTO>> getProjectTaskTrend(Integer projectId) throws ForbiddenException; Map<String, List<TaskTrendDTO>> getProjectTaskTrend(String token, Integer projectId) throws ForbiddenException;
Boolean transferStaffTasks(String token, Integer projectId, Integer transferredStaffId, Map<Long, Integer> transferMap) throws ForbiddenException, BadRequestException; Boolean transferStaffTasks(String token, Integer projectId, Integer transferredStaffId, Map<Long, Integer> transferMap) throws ForbiddenException, BadRequestException;
Boolean transferTasksToSingleStaff(String token, Integer projectId, Integer transferredStaffId, Integer targetStaffId) throws ForbiddenException, BadRequestException; Boolean transferTasksToSingleStaff(String token, Integer projectId, Integer transferredStaffId, Integer targetStaffId) throws ForbiddenException, BadRequestException;
Map<String, Long> getProjectProcessOfEveryone(Integer projectId) throws ForbiddenException; Map<String, Long> getProjectProcessOfEveryone(String token, Integer projectId) throws ForbiddenException;
} }

View File

@ -35,39 +35,34 @@ public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Ann
return baseMapper.selectAnnouncementById(projectId, announcementId); return baseMapper.selectAnnouncementById(projectId, announcementId);
} }
// @Override @Override
// public Boolean updateAnnouncement(Integer projectId, Announcement announcement) throws ForbiddenException, BadRequestException { public Boolean updateAnnouncement(String token, Integer projectId, Announcement announcement) throws ForbiddenException, BadRequestException {
// Integer accessLevel = projectGroupService.getProjectAccessLevel(token, projectId); Integer accessLevel = projectGroupService.getProjectAccessLevel(token, projectId);
// if (accessLevel == 0) { if (accessLevel == 0) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// } }
// if (accessLevel > 2) { if (accessLevel > 2) {
// throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
// } }
// Announcement rawAnnouncement = baseMapper.selectById(announcement.getAnnouncementId()); Announcement rawAnnouncement = baseMapper.selectById(announcement.getAnnouncementId());
// if (projectGroupService.compareProjectAccessLevel(projectId, token, rawAnnouncement.getAnnouncementPublisherId()) <= 0) { if (projectGroupService.compareProjectAccessLevel(projectId, token, rawAnnouncement.getAnnouncementPublisherId()) <= 0) {
// if (!announcement.checkModification(rawAnnouncement)) { if (!announcement.checkModification(rawAnnouncement)) {
// throw new BadRequestException(BadRequestException.WRONG_PARAMETERS); throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
// } }
// return updateById(announcement); return updateById(announcement);
// } }
// throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
// } }
@Override @Override
public Boolean deleteAnnouncement( public Boolean deleteAnnouncement(String token, Integer projectId, Long announcementId) throws ForbiddenException, BadRequestException {
Integer staffId, Integer accessLevel = projectGroupService.getProjectAccessLevel(token, projectId);
Integer globalAccessLevel, if (accessLevel == 0) {
Integer projectId, throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
Long announcementId }
) throws ForbiddenException, BadRequestException { if (accessLevel > 2) {
// Integer accessLevel = projectGroupService.getProjectAccessLevel(token, projectId); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
// if (accessLevel == 0) { }
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// }
// if (accessLevel > 2) {
// throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
// }
Announcement rawAnnouncement = baseMapper.selectOne(Wrappers.<Announcement>lambdaQuery() Announcement rawAnnouncement = baseMapper.selectOne(Wrappers.<Announcement>lambdaQuery()
.select(Announcement::getProjectId, Announcement::getAnnouncementPublisherId) .select(Announcement::getProjectId, Announcement::getAnnouncementPublisherId)
.eq(Announcement::getAnnouncementId, announcementId) .eq(Announcement::getAnnouncementId, announcementId)
@ -75,7 +70,7 @@ public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Ann
if (!Objects.equals(projectId, rawAnnouncement.getProjectId())) { if (!Objects.equals(projectId, rawAnnouncement.getProjectId())) {
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS); throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
} }
if (projectGroupService.compareProjectAccessLevel(projectId, staffId, globalAccessLevel, rawAnnouncement.getAnnouncementPublisherId()) > 0) { if (projectGroupService.compareProjectAccessLevel(projectId, token, rawAnnouncement.getAnnouncementPublisherId()) > 0) {
throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
} }
return removeById(announcementId); return removeById(announcementId);

View File

@ -145,6 +145,13 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
) == 1; ) == 1;
} }
@Override
public Integer getProjectAccessLevel(String token, Integer projectId) {
Integer staffId = TokenUtils.getStaffId(token);
Integer staffGlobalLevel = TokenUtils.getStaffGlobalLevel(token);
return getProjectAccessLevel(staffId, staffGlobalLevel, projectId);
}
@Override @Override
public Integer getProjectAccessLevel(Integer staffId, Integer staffGlobalLevel, Integer projectId) { public Integer getProjectAccessLevel(Integer staffId, Integer staffGlobalLevel, Integer projectId) {
//对全局权限做特判 //对全局权限做特判
@ -177,8 +184,8 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
} }
@Override @Override
public Integer compareProjectAccessLevel(Integer projectId, Integer staffId, Integer globalAccessLevel, Integer targetId) { public Integer compareProjectAccessLevel(Integer projectId, String token, Integer targetId) {
return Integer.compare(getProjectAccessLevel(staffId, globalAccessLevel, projectId), getProjectAccessLevelIgnoreGlobalLevel(targetId, projectId)); return Integer.compare(getProjectAccessLevel(token, projectId), getProjectAccessLevelIgnoreGlobalLevel(targetId, projectId));
} }
@Override @Override

View File

@ -33,44 +33,45 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
private IProjectGroupService projectGroupService; private IProjectGroupService projectGroupService;
@Override @Override
public Long countMyProjects(Integer staffId) { public Long countMyProjects(String token) {
Integer staffId = TokenUtils.getStaffId(token);
return baseMapper.selectMyProjectCount(staffId); return baseMapper.selectMyProjectCount(staffId);
} }
@Override @Override
public ProjectProcessDTO getProjectProcess(Integer staffId, Integer globalAccessLevel, Integer projectId) throws ForbiddenException, BadRequestException { public ProjectProcessDTO getProjectProcess(String token, Integer projectId) throws ForbiddenException, BadRequestException {
// if (projectGroupService.getProjectAccessLevel(staffId, globalAccessLevel, projectId) == 0) { if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// } }
// if (Objects.equals(projectId, 0)) { if (Objects.equals(projectId, 0)) {
// throw new BadRequestException(BadRequestException.WRONG_PARAMETERS); throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
// } }
return baseMapper.selectProjectProcess(projectId); return baseMapper.selectProjectProcess(projectId);
} }
@Override @Override
public Page<ProjectDTO> pageMyProjects( public Page<ProjectDTO> pageMyProjects(
// String token, String token,
Integer staffId,
RequestPage page, RequestPage page,
Map<String, Object> params Map<String, Object> params
) { ) {
// Integer staffId = TokenUtils.getStaffGlobalLevel(token) == 1 ? null : TokenUtils.getStaffId(token); Integer staffId = TokenUtils.getStaffGlobalLevel(token) == 1 ? null : TokenUtils.getStaffId(token);
IPage<ProjectDTO> userPage = baseMapper.selectMyProject(page.getPage(), staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params)); IPage<ProjectDTO> userPage = baseMapper.selectMyProject(page.getPage(), staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params));
return (Page<ProjectDTO>) userPage; return (Page<ProjectDTO>) userPage;
} }
@Override @Override
public Boolean setProjectCompleted( public Boolean setProjectCompleted(String token, Integer projectId) throws BadRequestException, ForbiddenException {
Project targetProject Project project = new Project();
) throws BadRequestException, ForbiddenException project.setProjectId(projectId);
{ Project targetProject = baseMapper.selectById(project.getProjectId());
// Project targetProject = baseMapper.selectById(project.getProjectId()); if (targetProject == null)
// if (targetProject == null) throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
// throw new BadRequestException(BadRequestException.WRONG_PARAMETERS); if (!Objects.equals(TokenUtils.getStaffId(token), targetProject.getProjectCreator())
/*if (!Objects.equals(staffId, targetProject.getProjectCreator()) && !Objects.equals(TokenUtils.getStaffGlobalLevel(token), 1))
&& !Objects.equals(globalAccessLevel, 1)) throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);*/ if (targetProject.getCompleted())
throw new BadRequestException(PROJECT_COMPLETED);
targetProject.setCompleted(true); targetProject.setCompleted(true);
targetProject.setProjectClosedDate(LocalDate.now()); targetProject.setProjectClosedDate(LocalDate.now());
if (baseMapper.updateById(targetProject) == 1) if (baseMapper.updateById(targetProject) == 1)
@ -79,15 +80,15 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
} }
@Override @Override
public Boolean createProject(Integer staffId, Project project) throws BadRequestException, ForbiddenException { public Boolean createProject(String token, Project project) throws BadRequestException, ForbiddenException {
// Integer staffGlobalLevel = TokenUtils.getStaffGlobalLevel(token); Integer staffGlobalLevel = TokenUtils.getStaffGlobalLevel(token);
// if (staffGlobalLevel == 0 || staffGlobalLevel > 2) { if (staffGlobalLevel == 0 || staffGlobalLevel > 2) {
// throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
// } }
project.setProjectId(null); project.setProjectId(null);
project.setCompleted(false); project.setCompleted(false);
project.setProjectCreatedTime(null); project.setProjectCreatedTime(null);
project.setProjectCreator(staffId); project.setProjectCreator(TokenUtils.getStaffId(token));
project.setProjectClosedDate(null); project.setProjectClosedDate(null);
if (project.getExpectedCompletion() == null) { if (project.getExpectedCompletion() == null) {
project.setExpectedCompletion((short) 100); project.setExpectedCompletion((short) 100);
@ -99,7 +100,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
try { try {
if (baseMapper.insert(project) == 1) { if (baseMapper.insert(project) == 1) {
return projectGroupService.addCreator(project.getProjectId(), staffId); return projectGroupService.addCreator(project.getProjectId(), TokenUtils.getStaffId(token));
} }
} catch (Exception e) { } catch (Exception e) {
// log.error(e.getMessage(), e); // log.error(e.getMessage(), e);
@ -115,11 +116,11 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
return project != null && !project.getCompleted(); return project != null && !project.getCompleted();
} }
public Boolean updateProject(Integer staffId, Project project) throws BadRequestException, ForbiddenException { public Boolean updateProject(String token, Project project) throws BadRequestException, ForbiddenException {
// Integer staffId = TokenUtils.getStaffId(token); Integer staffId = TokenUtils.getStaffId(token);
// if (!staffId.equals(project.getProjectCreator()) && TokenUtils.getStaffGlobalLevel(token) != 1) { if (!staffId.equals(project.getProjectCreator()) && TokenUtils.getStaffGlobalLevel(token) != 1) {
// throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
// } }
Project rawProject = baseMapper.selectById(project.getProjectId()); Project rawProject = baseMapper.selectById(project.getProjectId());
if (Objects.equals(project, rawProject)) { if (Objects.equals(project, rawProject)) {
return true; return true;

View File

@ -38,10 +38,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
private IProjectGroupService projectGroupService; private IProjectGroupService projectGroupService;
@Override @Override
public List<TaskDTO> listSubtasks(Integer projectId, Long fatherId) throws ForbiddenException, BadRequestException { public List<TaskDTO> listSubtasks(String token, Integer projectId, Long fatherId) throws ForbiddenException, BadRequestException {
// if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) { if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// } }
if (fatherId == null) { if (fatherId == null) {
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS); throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
} }
@ -52,27 +52,23 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
@Override @Override
public Boolean existSubTask(Integer projectId, Long taskId) throws ForbiddenException { public Boolean existSubTask(String token, Integer projectId, Long taskId) throws ForbiddenException {
// if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) { if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// } }
return baseMapper.exists(Wrappers.<Task>lambdaQuery().eq(Task::getTaskFatherId, taskId)); return baseMapper.exists(Wrappers.<Task>lambdaQuery().eq(Task::getTaskFatherId, taskId));
} }
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class) @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@Override @Override
public Boolean deleteTaskAndSubTask( public Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException, ForbiddenException {
Integer staffId, Integer level = getHolderLevel(token, taskId);
Integer globalAccessLevel, if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
Long taskId throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
) throws BadRequestException, ForbiddenException { }
// Integer level = getHolderLevel(staffId, globalAccessLevel, taskId); if (level == 0 || level == 3) {
// if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) { throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); }
// }
// if (level == 0 || level == 3) {
// throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
// }
try { try {
List<Long> res = new ArrayList<>(); List<Long> res = new ArrayList<>();
// 添加根任务点Id获得子节点数目 // 添加根任务点Id获得子节点数目
@ -85,7 +81,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
throw new BadRequestException("删除失败"); throw new BadRequestException("删除失败");
} }
// 每次按照广度优先搜索的方式,按照树形的任务结构向下层寻找 // 每次按照广度优先搜索的方式,按照树形的任务结构向下层寻找
for (int depth = 1; depth <= 20; depth++) { for(int depth = 1; depth <= 20; depth++) {
// 寻找下一层的所有任务 // 寻找下一层的所有任务
List<Task> list = baseMapper.selectList( List<Task> list = baseMapper.selectList(
Wrappers.<Task>lambdaQuery() Wrappers.<Task>lambdaQuery()
@ -106,11 +102,12 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class) @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
public Boolean closeTaskAndSubTask(Integer staffId, Integer globalAccessLevel, Integer projectId, Long taskId) throws BadRequestException { @Override
Integer level = getHolderLevel(staffId, globalAccessLevel, taskId); public Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException {
// if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) { Integer level = getHolderLevel(token, taskId);
// throw new BadRequestException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
// } throw new BadRequestException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
}
if (level == 0) { if (level == 0) {
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS); throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
} }
@ -118,7 +115,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
List<Long> res = new ArrayList<>(); List<Long> res = new ArrayList<>();
// 获得初始的任务Id // 获得初始的任务Id
res.add(taskId); res.add(taskId);
for (int depth = 1; depth <= 20; depth++) { for(int depth = 1; depth <= 20; depth++) {
// 获得下一层所有任务 // 获得下一层所有任务
List<Task> list = baseMapper.selectList( List<Task> list = baseMapper.selectList(
Wrappers.<Task>lambdaQuery() Wrappers.<Task>lambdaQuery()
@ -146,13 +143,13 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
@Override @Override
public List<StaffProcessDTO> getProjectStatistics(Integer projectId, Integer staffId) throws ForbiddenException { public List<StaffProcessDTO> getProjectStatistics(String token, Integer projectId, Integer staffId) throws ForbiddenException {
// if (staffId != null && !TokenUtils.getStaffId(token).equals(staffId)) { if (staffId != null && !TokenUtils.getStaffId(token).equals(staffId)) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// } }
// if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) { if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// } }
List<StaffProcessDTO> resList = baseMapper.selectProjectProcess(projectId, staffId); List<StaffProcessDTO> resList = baseMapper.selectProjectProcess(projectId, staffId);
addResultProjectProcess(resList, Task.TYPE_ASSIGNMENT); addResultProjectProcess(resList, Task.TYPE_ASSIGNMENT);
addResultProjectProcess(resList, Task.TYPE_DEFECT); addResultProjectProcess(resList, Task.TYPE_DEFECT);
@ -207,12 +204,12 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
} }
// @Override @Override
// public Integer getHolderLevel(String token, Long taskId) { public Integer getHolderLevel(String token, Long taskId) {
// Integer staffId = TokenUtils.getStaffId(token); Integer staffId = TokenUtils.getStaffId(token);
// Integer staffGlobalLevel = TokenUtils.getStaffGlobalLevel(token); Integer staffGlobalLevel = TokenUtils.getStaffGlobalLevel(token);
// return getHolderLevel(staffId, staffGlobalLevel, taskId); return getHolderLevel(staffId, staffGlobalLevel, taskId);
// } }
private int lowerBound(List<Task> data, long x) { private int lowerBound(List<Task> data, long x) {
int l = 0, r = data.size() - 1; int l = 0, r = data.size() - 1;
@ -238,11 +235,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
@Override @Override
public List<TaskDTO> listMyTasks(Integer staffId, Integer projectId) throws ForbiddenException { public List<TaskDTO> listMyTasks(String token, Integer projectId) throws ForbiddenException {
// Integer staffId = TokenUtils.getStaffId(token); Integer staffId = TokenUtils.getStaffId(token);
// if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) { if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
// throw new ForbiddenException("不可操作的项目"); throw new ForbiddenException("不可操作的项目");
// } }
List<Task> resList = baseMapper.selectList(Wrappers.<Task>lambdaQuery() List<Task> resList = baseMapper.selectList(Wrappers.<Task>lambdaQuery()
.select(Task::getTaskId, Task::getTaskFatherId, Task::getTaskHolderId) .select(Task::getTaskId, Task::getTaskFatherId, Task::getTaskHolderId)
.eq(Task::getTaskProjectId, projectId) .eq(Task::getTaskProjectId, projectId)
@ -296,24 +293,18 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
@Override @Override
public Task insertTask( public Task insertTask(String token, Task task) throws BadRequestException, ForbiddenException {
Integer staffId,
Integer globalAccessLevel,
Integer accessLevel,
Task task
) throws BadRequestException, ForbiddenException {
task.setTaskId(null); task.setTaskId(null);
// Integer userLevel = projectGroupService.getProjectAccessLevel(token, task.getTaskProjectId()); Integer userLevel = projectGroupService.getProjectAccessLevel(token, task.getTaskProjectId());
// if (userLevel == 0) { if (userLevel == 0) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// } }
if (!task.checkInsert()) { if (!task.checkInsert()) {
throw new BadRequestException(BadRequestException.WRONG_PARAMETERS); throw new BadRequestException(BadRequestException.WRONG_PARAMETERS);
} }
try { try {
Task father = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskFatherId())); Task father = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskFatherId()));
if (!task.checkLegalFather(father) if (!task.checkLegalFather(father) || (getHolderLevel(token, task.getTaskFatherId()) == 0 && userLevel == 3)) {
|| (getHolderLevel(staffId, globalAccessLevel, task.getTaskFatherId()) == 0 && accessLevel == 3)) {
throw new BadRequestException("无法指定该父级"); throw new BadRequestException("无法指定该父级");
} }
task.setTaskCreatedTime(null); task.setTaskCreatedTime(null);
@ -336,15 +327,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
@Override @Override
public Task modifyTask( public Task modifyTask(String token, Task task) throws BadRequestException, ForbiddenException {
Integer staffId, Integer userLevel = projectGroupService.getProjectAccessLevel(token, task.getTaskProjectId());
Integer globalAccessLevel,
Integer accessLevel,
Task task
) throws BadRequestException, ForbiddenException {
// Integer userLevel = projectGroupService.getProjectAccessLevel(token, task.getTaskProjectId());
Task rawTask = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskId())); Task rawTask = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskId()));
if (accessLevel == 0 || (accessLevel == 3 && getHolderLevel(staffId, globalAccessLevel, task.getTaskId()) == 0)) { if (userLevel == 0 || (userLevel == 3 && getHolderLevel(token, task.getTaskId()) == 0)) {
throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
} }
int typeChangeValue = 0; int typeChangeValue = 0;
@ -367,7 +353,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
task.setTaskClosedTime(LocalDateTime.now()); task.setTaskClosedTime(LocalDateTime.now());
} }
if (typeChangeValue == 2) { if (typeChangeValue == 2) {
closed = closeTaskAndSubTask(staffId, globalAccessLevel, task.getTaskProjectId(), task.getTaskId()); closed = closeTaskAndSubTask(token, task.getTaskProjectId(), task.getTaskId());
} }
if (Objects.equals(rawTask, task)) { if (Objects.equals(rawTask, task)) {
return task; return task;
@ -384,10 +370,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
// 完成任务数目概况统计 // 完成任务数目概况统计
@Override @Override
public Map<String, List<TaskTrendDTO>> getProjectTaskTrend(Integer projectId) throws ForbiddenException { public Map<String, List<TaskTrendDTO>> getProjectTaskTrend(String token, Integer projectId) throws ForbiddenException {
// if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) { if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
// throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
// } }
// 起止日期 // 起止日期
LocalDate endDate = LocalDate.now(); LocalDate endDate = LocalDate.now();
LocalDate startDate = endDate.plusDays(-14); LocalDate startDate = endDate.plusDays(-14);
@ -483,18 +469,16 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
return taskTrendDTO; return taskTrendDTO;
} }
// FIXME
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class) @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@Override @Override
public Boolean transferStaffTasks(String token, Integer projectId, Integer transferredStaffId, Map<Long, Integer> transferMap) throws ForbiddenException, BadRequestException { public Boolean transferStaffTasks(String token, Integer projectId, Integer transferredStaffId, Map<Long, Integer> transferMap) throws ForbiddenException, BadRequestException {
if ( if (projectGroupService.getProjectAccessLevel(token, projectId) == 0
// projectGroupService.getProjectAccessLevel(token, projectId) == 0 || || projectGroupService.getProjectAccessLevelIgnoreGlobalLevel(transferredStaffId, projectId) == 0) {
projectGroupService.getProjectAccessLevelIgnoreGlobalLevel(transferredStaffId, projectId) == 0) {
throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
} }
// if (projectGroupService.compareProjectAccessLevel(projectId, token, transferredStaffId) > 0) { if (projectGroupService.compareProjectAccessLevel(projectId, token, transferredStaffId) > 0) {
// throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
// } }
Map<Long, Task> originTransferTaskMap = SimpleQuery.keyMap( Map<Long, Task> originTransferTaskMap = SimpleQuery.keyMap(
Wrappers.<Task>lambdaQuery() Wrappers.<Task>lambdaQuery()
@ -539,19 +523,17 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
// FIXME
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class) @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@Override @Override
public Boolean transferTasksToSingleStaff(String token, Integer projectId, Integer transferredStaffId, Integer targetStaffId) throws ForbiddenException, BadRequestException { public Boolean transferTasksToSingleStaff(String token, Integer projectId, Integer transferredStaffId, Integer targetStaffId) throws ForbiddenException, BadRequestException {
if ( if (projectGroupService.getProjectAccessLevel(token, projectId) == 0
// projectGroupService.getProjectAccessLevel(token, projectId) == 0 || || projectGroupService.getProjectAccessLevelIgnoreGlobalLevel(transferredStaffId, projectId) == 0
projectGroupService.getProjectAccessLevelIgnoreGlobalLevel(transferredStaffId, projectId) == 0
|| projectGroupService.getProjectAccessLevelIgnoreGlobalLevel(targetStaffId, projectId) == 0) { || projectGroupService.getProjectAccessLevelIgnoreGlobalLevel(targetStaffId, projectId) == 0) {
throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
} }
// if (projectGroupService.compareProjectAccessLevel(projectId, token, transferredStaffId) > 0) { if (projectGroupService.compareProjectAccessLevel(projectId, token, transferredStaffId) > 0) {
// throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE); throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
// } }
Long transferredTaskCount = baseMapper.selectCount(Wrappers.<Task>lambdaQuery() Long transferredTaskCount = baseMapper.selectCount(Wrappers.<Task>lambdaQuery()
.eq(Task::getTaskHolderId, transferredStaffId) .eq(Task::getTaskHolderId, transferredStaffId)
.and(wrapper -> wrapper .and(wrapper -> wrapper
@ -574,10 +556,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
@Override @Override
public Map<String, Long> getProjectProcessOfEveryone(Integer projectId) throws ForbiddenException { public Map<String, Long> getProjectProcessOfEveryone(String token, Integer projectId) throws ForbiddenException {
// if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) { if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
// throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
// } }
Map<String, Long> resMap = new HashMap<>(); Map<String, Long> resMap = new HashMap<>();
List<TaskNumOfEveryoneDTO> resList = baseMapper.selectProjectProcessOfEveryone(projectId); List<TaskNumOfEveryoneDTO> resList = baseMapper.selectProjectProcessOfEveryone(projectId);
for (TaskNumOfEveryoneDTO taskNumOfEveryoneDTO : resList) { for (TaskNumOfEveryoneDTO taskNumOfEveryoneDTO : resList) {

View File

@ -87,9 +87,9 @@ public class MybatisPlusTests {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("completed", true); map.put("completed", true);
// System.out.println(objectMapper.writeValueAsString(projectService System.out.println(objectMapper.writeValueAsString(projectService
// .pageMyProjects("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkdXJhdGlvbiI6MTgwMDAsInN0YWZmVXNlcm5hbWUiOiJtaWtlIiwiZXhwIjoxNjU3MDkzNTU1LCJpYXQiOjE2NTcwNzU1NTUsInN0YWZmSWQiOjF9.g8l01dnHglt223469Z03i9gqZL8P13Fo7KoaA1pf310", .pageMyProjects("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkdXJhdGlvbiI6MTgwMDAsInN0YWZmVXNlcm5hbWUiOiJtaWtlIiwiZXhwIjoxNjU3MDkzNTU1LCJpYXQiOjE2NTcwNzU1NTUsInN0YWZmSWQiOjF9.g8l01dnHglt223469Z03i9gqZL8P13Fo7KoaA1pf310",
// page, map))); page, map)));
} }
@SneakyThrows @SneakyThrows