完成了项目公告相关接口(未测试),新增了手动validate的方法,格式化了部分代码
parent
5b7f552530
commit
2ed153ca93
|
@ -0,0 +1,20 @@
|
||||||
|
package cn.edu.hfut.rmdjzz.projectmanagement.config;
|
||||||
|
|
||||||
|
import org.hibernate.validator.HibernateValidator;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.validation.Validation;
|
||||||
|
import javax.validation.Validator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 佘语殊
|
||||||
|
* @since 2022/7/7 17:38
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class ValidationConfig {
|
||||||
|
@Bean
|
||||||
|
public Validator validator() {
|
||||||
|
return Validation.byProvider(HibernateValidator.class).configure().failFast(true).buildValidatorFactory().getValidator();
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ 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 {
|
||||||
|
@ -41,11 +42,11 @@ public class AnnouncementController {
|
||||||
@RequestHeader("Token") String token,
|
@RequestHeader("Token") String token,
|
||||||
@PathVariable Integer projectId,
|
@PathVariable Integer projectId,
|
||||||
@PathVariable Long announcementId
|
@PathVariable Long announcementId
|
||||||
){
|
) {
|
||||||
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
||||||
throw new ForbiddenException("无该项目访问权限");
|
throw new ForbiddenException("无该项目访问权限");
|
||||||
}
|
}
|
||||||
return ResponseMap.ofSuccess("查询成功");
|
return ResponseMap.ofSuccess("查询成功", announcementService.getAnnouncementById(announcementId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
|
@ -55,7 +56,8 @@ public class AnnouncementController {
|
||||||
@PathVariable Integer projectId,
|
@PathVariable Integer projectId,
|
||||||
@RequestBody Announcement announcement
|
@RequestBody Announcement announcement
|
||||||
) {
|
) {
|
||||||
if (projectGroupService.getProjectAccessLevel(token, projectId) > 2) {
|
Integer accessLevel = projectGroupService.getProjectAccessLevel(token, projectId);
|
||||||
|
if (accessLevel == 0 || accessLevel > 2) {
|
||||||
throw new ForbiddenException("无该操作权限");
|
throw new ForbiddenException("无该操作权限");
|
||||||
}
|
}
|
||||||
announcement.setProjectId(projectId);
|
announcement.setProjectId(projectId);
|
||||||
|
@ -67,17 +69,33 @@ public class AnnouncementController {
|
||||||
throw new BadRequestException("创建失败");
|
throw new BadRequestException("创建失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: 查询权限高低
|
// 取消功能
|
||||||
|
/*@SneakyThrows
|
||||||
@PutMapping("/{announcementId}")
|
@PutMapping("/{announcementId}")
|
||||||
public ResponseMap modifyAnnouncement(
|
public ResponseMap modifyAnnouncement(
|
||||||
@RequestHeader("Token") String token,
|
@RequestHeader("Token") String token,
|
||||||
@PathVariable Integer projectId,
|
@PathVariable Integer projectId,
|
||||||
@PathVariable Long announcementId,
|
@PathVariable Long announcementId,
|
||||||
@RequestBody Announcement announcement
|
@RequestBody Announcement announcement
|
||||||
){
|
) {
|
||||||
|
announcement.setAnnouncementId(announcementId);
|
||||||
|
if (announcementService.updateAnnouncement(token, projectId, announcement)) {
|
||||||
return ResponseMap.ofSuccess("更新成功");
|
return ResponseMap.ofSuccess("更新成功");
|
||||||
}
|
}
|
||||||
|
throw new BadRequestException("更新失败");
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@DeleteMapping("/{announcementId}")
|
||||||
|
public ResponseMap deleteAnnouncement(
|
||||||
|
@RequestHeader("Token") String token,
|
||||||
|
@PathVariable Integer projectId,
|
||||||
|
@PathVariable Long announcementId
|
||||||
|
) {
|
||||||
|
if (announcementService.deleteAnnouncement(token, projectId, announcementId)) {
|
||||||
|
return ResponseMap.ofSuccess("删除成功");
|
||||||
|
}
|
||||||
|
throw new BadRequestException("删除失败");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,24 +2,25 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectGroupDto;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectGroupDto;
|
||||||
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.StaffProcessDto;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.vo.GroupPositionVo;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.vo.GroupPositionVo;
|
||||||
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.IProjectGroupService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
||||||
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.ValidateUtils;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
|
||||||
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.extension.plugins.pagination.Page;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
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.*;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import java.util.Objects;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 史鹏辉
|
* @author 史鹏辉
|
||||||
|
@ -31,23 +32,28 @@ import java.util.List;
|
||||||
public class ProjectGroupController {
|
public class ProjectGroupController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IProjectGroupService projectGroupService;
|
private IProjectGroupService projectGroupService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ITaskService taskService;
|
private ITaskService taskService;
|
||||||
|
@Autowired
|
||||||
|
private ValidateUtils validateUtils;
|
||||||
|
|
||||||
|
@Operation(description = "传入合法page参数时分页查询,否则拉取整个列表")
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseList<ProjectGroupDto> getGroupNumber(
|
public ResponseList<ProjectGroupDto> getGroupMembers(
|
||||||
@PathVariable Integer projectId,
|
@PathVariable Integer projectId,
|
||||||
@RequestHeader("Token") String token,
|
@RequestHeader("Token") String token,
|
||||||
@Valid RequestPage page
|
RequestPage page
|
||||||
) {
|
) {
|
||||||
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
||||||
throw new ForbiddenException("无该项目访问权限");
|
throw new ForbiddenException("无该项目访问权限");
|
||||||
}
|
}
|
||||||
Page<ProjectGroupDto> res = projectGroupService.getOnePageProjectNumber(page, projectId);
|
if (validateUtils.validate(page).isEmpty()) {
|
||||||
return ResponseList.ofSuccess("查询成功", res);
|
return ResponseList.ofSuccess("查询成功", projectGroupService.pageProjectMembers(page, projectId));
|
||||||
}
|
}
|
||||||
|
return ResponseList.ofSuccess("查询成功", projectGroupService.listProjectMembers(projectId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@GetMapping("/{staffId}")
|
@GetMapping("/{staffId}")
|
||||||
|
@ -102,12 +108,12 @@ public class ProjectGroupController {
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@GetMapping("/{staffId}/stats")
|
@GetMapping("/{staffId}/stats")
|
||||||
public ResponseList getProjectProcessOfStaff(
|
public ResponseList<StaffProcessDto> getProjectProcessOfStaff(
|
||||||
@RequestHeader("Token") String token,
|
@RequestHeader("Token") String token,
|
||||||
@PathVariable Integer projectId,
|
@PathVariable Integer projectId,
|
||||||
@PathVariable Integer staffId
|
@PathVariable Integer staffId
|
||||||
) {
|
) {
|
||||||
if(TokenUtils.getStaffId(token) != staffId) {
|
if (!Objects.equals(TokenUtils.getStaffId(token), staffId)) {
|
||||||
throw new BadRequestException("错误请求");
|
throw new BadRequestException("错误请求");
|
||||||
}
|
}
|
||||||
return ResponseList.ofSuccess("查询成功", taskService.getProjectProcessOfStaff(token, projectId));
|
return ResponseList.ofSuccess("查询成功", taskService.getProjectProcessOfStaff(token, projectId));
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 佘语殊
|
* @author 佘语殊
|
||||||
|
@ -24,4 +25,14 @@ public class Announcement {
|
||||||
@TableField("is_deleted")
|
@TableField("is_deleted")
|
||||||
@TableLogic
|
@TableLogic
|
||||||
private Boolean deleted;
|
private Boolean deleted;
|
||||||
|
|
||||||
|
public boolean checkModification(Announcement rawAnnouncement) {
|
||||||
|
if (!Objects.equals(projectId, rawAnnouncement.projectId))
|
||||||
|
return false;
|
||||||
|
if (!Objects.equals(announcementPublisherId, rawAnnouncement.announcementPublisherId))
|
||||||
|
return false;
|
||||||
|
if (!Objects.equals(announcementPublishTime, rawAnnouncement.announcementPublishTime))
|
||||||
|
return false;
|
||||||
|
return deleted == rawAnnouncement.deleted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,6 @@ public class Project {
|
||||||
public Boolean checkModification(Project rawProject) {
|
public Boolean checkModification(Project rawProject) {
|
||||||
if (!this.checkProjectDate())
|
if (!this.checkProjectDate())
|
||||||
return false;
|
return false;
|
||||||
if (!Objects.equals(this.getProjectId(), rawProject.getProjectId()))
|
|
||||||
return false;
|
|
||||||
if (!Objects.equals(this.getProjectCreator(), rawProject.getProjectCreator()))
|
if (!Objects.equals(this.getProjectCreator(), rawProject.getProjectCreator()))
|
||||||
return false;
|
return false;
|
||||||
if (!Objects.equals(this.getProjectCreatedTime(), rawProject.getProjectCreatedTime()))
|
if (!Objects.equals(this.getProjectCreatedTime(), rawProject.getProjectCreatedTime()))
|
||||||
|
|
|
@ -21,5 +21,12 @@ public interface ProjectGroupMapper extends BaseMapper<ProjectGroup> {
|
||||||
FROM project_group inner join staff
|
FROM project_group inner join staff
|
||||||
ON project_group.staff_id = staff.staff_id AND project_group.project_id = #{projectId}
|
ON project_group.staff_id = staff.staff_id AND project_group.project_id = #{projectId}
|
||||||
""")
|
""")
|
||||||
Page<ProjectGroupDto> findNumber(IPage<ProjectDto> pg, @Param("projectId") Integer projectId);
|
Page<ProjectGroupDto> selectMembersByPage(IPage<ProjectDto> pg, @Param("projectId") Integer projectId);
|
||||||
|
|
||||||
|
@Select("""
|
||||||
|
SELECT staff.staff_id, staff_username, staff_fullname, project_staff_position, project_access_level
|
||||||
|
FROM project_group inner join staff
|
||||||
|
ON project_group.staff_id = staff.staff_id AND project_group.project_id = #{projectId}
|
||||||
|
""")
|
||||||
|
List<ProjectGroupDto> selectMembersByList(@Param("projectId") Integer projectId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package cn.edu.hfut.rmdjzz.projectmanagement.service;
|
||||||
|
|
||||||
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.ForbiddenException;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -11,7 +13,13 @@ import java.util.List;
|
||||||
* @since 2022/7/7 11:27
|
* @since 2022/7/7 11:27
|
||||||
*/
|
*/
|
||||||
public interface IAnnouncementService extends IService<Announcement> {
|
public interface IAnnouncementService extends IService<Announcement> {
|
||||||
|
|
||||||
List<AnnouncementDto> getAnnouncementList(Integer projectId);
|
List<AnnouncementDto> getAnnouncementList(Integer projectId);
|
||||||
|
|
||||||
AnnouncementDto getAnnouncementById(Long announcementId);
|
AnnouncementDto getAnnouncementById(Long announcementId);
|
||||||
|
|
||||||
|
Boolean updateAnnouncement(String token, Integer projectId, Announcement announcement) throws ForbiddenException, BadRequestException;
|
||||||
|
|
||||||
|
Boolean deleteAnnouncement(String token, Integer projectId, Long announcementId) throws ForbiddenException, BadRequestException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package cn.edu.hfut.rmdjzz.projectmanagement.service;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectGroupDto;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectGroupDto;
|
||||||
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.utils.http.RequestPage;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
@ -29,9 +28,18 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
|
||||||
|
|
||||||
Integer getProjectAccessLevel(Integer staffId, Integer projectId);
|
Integer getProjectAccessLevel(Integer staffId, Integer projectId);
|
||||||
|
|
||||||
Integer compareProjectAccessLevel(Integer projectId, Integer staffId1, Integer staffId2);
|
/**
|
||||||
|
* 比较token持有者与目标id在项目中的权限等级大小关系,一般用于当token持有者对目标id的某条目做危险操作时判断用
|
||||||
|
* <p>
|
||||||
|
* token持有者的判断受全局权限影响,目标id不会
|
||||||
|
* <p>
|
||||||
|
* 返回类似于{@link Integer#compare(int, int)}
|
||||||
|
*/
|
||||||
|
Integer compareProjectAccessLevel(Integer projectId, String token, Integer targetId);
|
||||||
|
|
||||||
Page<ProjectGroupDto> getOnePageProjectNumber(RequestPage page, Integer projectId);
|
Page<ProjectGroupDto> pageProjectMembers(RequestPage page, Integer projectId);
|
||||||
|
|
||||||
|
List<ProjectGroupDto> listProjectMembers(Integer projectId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计小组中各岗位数量
|
* 统计小组中各岗位数量
|
||||||
|
|
|
@ -2,12 +2,19 @@ package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
|
||||||
|
|
||||||
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.ForbiddenException;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.AnnouncementMapper;
|
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.AnnouncementMapper;
|
||||||
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.utils.TokenUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 佘语殊
|
* @author 佘语殊
|
||||||
|
@ -16,6 +23,9 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements IAnnouncementService {
|
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements IAnnouncementService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IProjectGroupService projectGroupService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AnnouncementDto> getAnnouncementList(Integer projectId) {
|
public List<AnnouncementDto> getAnnouncementList(Integer projectId) {
|
||||||
return baseMapper.selectAnnouncementList(projectId);
|
return baseMapper.selectAnnouncementList(projectId);
|
||||||
|
@ -23,6 +33,52 @@ public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Ann
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AnnouncementDto getAnnouncementById(Long announcementId) {
|
public AnnouncementDto getAnnouncementById(Long announcementId) {
|
||||||
return null;
|
return baseMapper.selectAnnouncementById(announcementId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateAnnouncement(String token, Integer projectId, Announcement announcement) throws ForbiddenException, BadRequestException {
|
||||||
|
Integer staffId = TokenUtils.getStaffId(token);
|
||||||
|
Integer accessLevel = projectGroupService.getProjectAccessLevel(staffId, projectId);
|
||||||
|
if (accessLevel == 0) {
|
||||||
|
throw new ForbiddenException("无该项目访问权限");
|
||||||
|
}
|
||||||
|
if (accessLevel > 2) {
|
||||||
|
throw new ForbiddenException("无权修改该公告");
|
||||||
|
}
|
||||||
|
Announcement rawAnnouncement = baseMapper.selectById(announcement.getAnnouncementId());
|
||||||
|
if (projectGroupService.compareProjectAccessLevel(projectId, token, rawAnnouncement.getAnnouncementPublisherId()) >= 0) {
|
||||||
|
if (!announcement.checkModification(rawAnnouncement)) {
|
||||||
|
throw new BadRequestException("请求参数错误");
|
||||||
|
}
|
||||||
|
return updateById(announcement);
|
||||||
|
}
|
||||||
|
throw new ForbiddenException("无权修改该公告");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean deleteAnnouncement(String token, Integer projectId, Long announcementId) throws ForbiddenException, BadRequestException {
|
||||||
|
Integer staffId = TokenUtils.getStaffId(token);
|
||||||
|
Integer accessLevel = projectGroupService.getProjectAccessLevel(staffId, projectId);
|
||||||
|
if (accessLevel == 0) {
|
||||||
|
throw new ForbiddenException("无该项目访问权限");
|
||||||
|
}
|
||||||
|
if (accessLevel > 2) {
|
||||||
|
throw new ForbiddenException("无权修改该公告");
|
||||||
|
}
|
||||||
|
Announcement rawAnnouncement = baseMapper.selectOne(Wrappers.<Announcement>lambdaQuery()
|
||||||
|
.select(Announcement::getProjectId)
|
||||||
|
.select(Announcement::getAnnouncementPublisherId)
|
||||||
|
.eq(Announcement::getAnnouncementId, announcementId)
|
||||||
|
);
|
||||||
|
if (!Objects.equals(projectId, rawAnnouncement.getProjectId())) {
|
||||||
|
throw new BadRequestException("请求参数错误");
|
||||||
|
}
|
||||||
|
if (projectGroupService.compareProjectAccessLevel(projectId, token, rawAnnouncement.getAnnouncementPublisherId()) < 0) {
|
||||||
|
throw new ForbiddenException("无权修改该公告");
|
||||||
|
}
|
||||||
|
return removeById(announcementId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
|
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectDto;
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectGroupDto;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectGroupDto;
|
||||||
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.mapper.ProjectGroupMapper;
|
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectGroupMapper;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -117,14 +113,27 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer compareProjectAccessLevel(Integer projectId, Integer staffId1, Integer staffId2) {
|
public Integer compareProjectAccessLevel(Integer projectId, String token, Integer targetId) {
|
||||||
return Integer.compare(getProjectAccessLevel(staffId1, projectId), getProjectAccessLevel(staffId2, projectId));
|
Integer targetLevel = baseMapper.selectOne(Wrappers.<ProjectGroup>lambdaQuery()
|
||||||
|
.select(ProjectGroup::getProjectAccessLevel)
|
||||||
|
.eq(ProjectGroup::getStaffId, targetId)
|
||||||
|
.eq(ProjectGroup::getProjectId, projectId)
|
||||||
|
).getProjectAccessLevel();
|
||||||
|
|
||||||
|
if (targetLevel == null) {
|
||||||
|
targetLevel = 0;
|
||||||
|
}
|
||||||
|
return Integer.compare(getProjectAccessLevel(token, projectId), targetLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<ProjectGroupDto> getOnePageProjectNumber(RequestPage page, Integer projectId){
|
public Page<ProjectGroupDto> pageProjectMembers(RequestPage page, Integer projectId) {
|
||||||
IPage<ProjectGroupDto> numberPage = baseMapper.findNumber(page.getPage(), projectId);
|
return baseMapper.selectMembersByPage(page.getPage(), projectId);
|
||||||
return (Page<ProjectGroupDto>) numberPage;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProjectGroupDto> listProjectMembers(Integer projectId) {
|
||||||
|
return baseMapper.selectMembersByList(projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProjectProcessDto getProjectProcess(String token, Integer projectId) throws ForbiddenException {
|
public ProjectProcessDto getProjectProcess(String token, Integer projectId) throws ForbiddenException {
|
||||||
if(projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
||||||
throw new ForbiddenException("无查看权限");
|
throw new ForbiddenException("无查看权限");
|
||||||
}
|
}
|
||||||
return baseMapper.findProjectProcess(projectId);
|
return baseMapper.findProjectProcess(projectId);
|
||||||
|
@ -62,7 +62,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
||||||
Integer staffId = TokenUtils.getStaffId(token);
|
Integer staffId = TokenUtils.getStaffId(token);
|
||||||
Project project = new Project();
|
Project project = new Project();
|
||||||
project.setProjectId(projectId);
|
project.setProjectId(projectId);
|
||||||
Project targetProject = baseMapper.selectOne(Wrappers.<Project>lambdaQuery().eq(Project::getProjectId, project.getProjectId()));
|
Project targetProject = baseMapper.selectById(project.getProjectId());
|
||||||
if (targetProject == null)
|
if (targetProject == null)
|
||||||
throw new BadRequestException("项目不存在");
|
throw new BadRequestException("项目不存在");
|
||||||
if (!Objects.equals(staffId, targetProject.getProjectCreator()))
|
if (!Objects.equals(staffId, targetProject.getProjectCreator()))
|
||||||
|
@ -87,7 +87,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
||||||
if (project.getExpectedCompletion() == null) {
|
if (project.getExpectedCompletion() == null) {
|
||||||
project.setExpectedCompletion((short) 100);
|
project.setExpectedCompletion((short) 100);
|
||||||
} else if (project.getExpectedCompletion() < 0 || project.getExpectedCompletion() > 100 ||
|
} else if (project.getExpectedCompletion() < 0 || project.getExpectedCompletion() > 100 ||
|
||||||
!project.checkProjectDate() || project.getProjectManMonth().compareTo(new BigDecimal("0")) == -1
|
!project.checkProjectDate() || project.getProjectManMonth().compareTo(new BigDecimal("0")) < 0
|
||||||
) {
|
) {
|
||||||
throw new BadRequestException("参数错误");
|
throw new BadRequestException("参数错误");
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
||||||
public Boolean checkOpenStatus(Integer projectId) {
|
public Boolean checkOpenStatus(Integer projectId) {
|
||||||
if (projectId == null || projectId < 1)
|
if (projectId == null || projectId < 1)
|
||||||
return false;
|
return false;
|
||||||
Project project = baseMapper.selectOne(Wrappers.<Project>lambdaQuery().eq(Project::getProjectId, projectId));
|
Project project = baseMapper.selectById(projectId);
|
||||||
return project != null && !project.getCompleted();
|
return project != null && !project.getCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
||||||
if (!staffId.equals(project.getProjectCreator())) {
|
if (!staffId.equals(project.getProjectCreator())) {
|
||||||
throw new BadRequestException("无权操作");
|
throw new BadRequestException("无权操作");
|
||||||
}
|
}
|
||||||
Project rawProject = baseMapper.selectOne(Wrappers.<Project>lambdaQuery().eq(Project::getProjectId, project.getProjectId()));
|
Project rawProject = baseMapper.selectById(project.getProjectId());
|
||||||
if (!project.checkModification(rawProject)) {
|
if (!project.checkModification(rawProject)) {
|
||||||
throw new BadRequestException("参数错误");
|
throw new BadRequestException("参数错误");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.Date;
|
||||||
public final class TokenUtils {
|
public final class TokenUtils {
|
||||||
public final static String pvKey = "SignedByRMDJZZ";
|
public final static String pvKey = "SignedByRMDJZZ";
|
||||||
|
|
||||||
|
//TODO: 加个大权限
|
||||||
public static String getToken(String staffUsername, Integer staffId, Long duration) {
|
public static String getToken(String staffUsername, Integer staffId, Long duration) {
|
||||||
return JWT.create()
|
return JWT.create()
|
||||||
.withClaim("staffUsername", staffUsername)
|
.withClaim("staffUsername", staffUsername)
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package cn.edu.hfut.rmdjzz.projectmanagement.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.Validator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 佘语殊
|
||||||
|
* @since 2022/7/7 17:41
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ValidateUtils {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Validator validator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 利用hibernate validator对对象进行手动校验
|
||||||
|
*
|
||||||
|
* @return 返回校验失败的信息,若校验成功则返回空值
|
||||||
|
*/
|
||||||
|
public <T> List<String> validate(T t) {
|
||||||
|
if (t == null) {
|
||||||
|
return List.of("null");
|
||||||
|
}
|
||||||
|
Set<ConstraintViolation<T>> validate = validator.validate(t);
|
||||||
|
return validate.stream().map(ConstraintViolation::getMessage).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement;
|
package cn.edu.hfut.rmdjzz.projectmanagement;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
||||||
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
|
||||||
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.impl.ProjectServiceImpl;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.impl.ProjectServiceImpl;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
|
||||||
|
@ -27,10 +29,12 @@ import java.util.Map;
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class MybatisPlusTests {
|
public class MybatisPlusTests {
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private IStaffService staffService;
|
private IStaffService staffService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IProjectService projectService;
|
private IProjectService projectService;
|
||||||
|
@Autowired
|
||||||
|
private ITaskService taskService;
|
||||||
@Resource
|
@Resource
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@ -87,4 +91,27 @@ public class MybatisPlusTests {
|
||||||
.getOnePageProject("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkdXJhdGlvbiI6MTgwMDAsInN0YWZmVXNlcm5hbWUiOiJtaWtlIiwiZXhwIjoxNjU3MDkzNTU1LCJpYXQiOjE2NTcwNzU1NTUsInN0YWZmSWQiOjF9.g8l01dnHglt223469Z03i9gqZL8P13Fo7KoaA1pf310",
|
.getOnePageProject("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkdXJhdGlvbiI6MTgwMDAsInN0YWZmVXNlcm5hbWUiOiJtaWtlIiwiZXhwIjoxNjU3MDkzNTU1LCJpYXQiOjE2NTcwNzU1NTUsInN0YWZmSWQiOjF9.g8l01dnHglt223469Z03i9gqZL8P13Fo7KoaA1pf310",
|
||||||
page, map)));
|
page, map)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Test
|
||||||
|
public void updateTest() {
|
||||||
|
Task task = objectMapper.readValue("""
|
||||||
|
{
|
||||||
|
"taskType": "需求",
|
||||||
|
"taskFatherId": 16,
|
||||||
|
"taskName": "1-2",
|
||||||
|
"taskHolderId": 3,
|
||||||
|
"taskPriority": 2,
|
||||||
|
"taskStartTime": 1657137600,
|
||||||
|
"taskEndTime": 1657144800,
|
||||||
|
"taskDescription": "dasdasdsadasdasd",
|
||||||
|
"attachedInfo": {
|
||||||
|
"demandSource": "内部需求"
|
||||||
|
},
|
||||||
|
"taskId": 23,
|
||||||
|
"taskStatus": "待进行"
|
||||||
|
}
|
||||||
|
""", Task.class);
|
||||||
|
taskService.updateById(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package cn.edu.hfut.rmdjzz.projectmanagement;
|
||||||
|
|
||||||
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.ValidateUtils;
|
||||||
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.Validator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 佘语殊
|
||||||
|
* @since 2022/7/7 17:13
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
public class ValidateTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
@Autowired
|
||||||
|
private Validator validator;
|
||||||
|
@Autowired
|
||||||
|
private ValidateUtils validateUtils;
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Test
|
||||||
|
public void manuallyValidateTest() {
|
||||||
|
RequestPage page = new RequestPage();
|
||||||
|
page.setPageCurrent(0);
|
||||||
|
page.setPageSize(0);
|
||||||
|
|
||||||
|
Set<ConstraintViolation<RequestPage>> validate = validator.validate(page);
|
||||||
|
//System.out.println(objectMapper.writeValueAsString(validate));
|
||||||
|
for (ConstraintViolation<RequestPage> violation : validate) {
|
||||||
|
System.out.println(violation.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Test
|
||||||
|
public void utilTest() {
|
||||||
|
RequestPage page = new RequestPage();
|
||||||
|
page.setPageCurrent(0);
|
||||||
|
page.setPageSize(0);
|
||||||
|
|
||||||
|
System.out.println(objectMapper.writeValueAsString(validateUtils.validate(page)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue