Compare commits

...

2 Commits

Author SHA1 Message Date
ShiPengHui f0ca1ce6d9 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/controller/ProjectGroupController.java
2022-07-06 17:28:16 +08:00
ShiPengHui 93a0d7ba28 带权限的项目成员id查询 2022-07-06 17:26:13 +08:00
5 changed files with 24 additions and 33 deletions

10
pom.xml
View File

@ -15,6 +15,8 @@
<description>ProjectManagementBackend</description> <description>ProjectManagementBackend</description>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
@ -154,6 +156,14 @@
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@ -1,13 +1,7 @@
package cn.edu.hfut.rmdjzz.projectmanagement.controller; package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.UnauthorizedException;
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.http.ResponseList; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
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.*;
@ -27,28 +21,8 @@ public class ProjectGroupController {
@SneakyThrows @SneakyThrows
@GetMapping @GetMapping
public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId) { public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId, @RequestHeader("Token") String token) {
List<Integer> res = projectGroupService.findAllProjectNumber(projectId); List<Integer> res = projectGroupService.findAllProjectNumber(token, projectId);
return ResponseList.ofSuccess("查询成功", res); return ResponseList.ofSuccess("查询成功", res);
} }
@SneakyThrows
@GetMapping("/{staffId}")
public ResponseMap getStaffPostion(
@RequestHeader("Token") String token,
@PathVariable Integer staffId,
@PathVariable Integer projectId
) {
if (TokenUtils.getStaffId(token) != staffId) {
throw new BadRequestException("用户访问错误");
}
if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) {
throw new UnauthorizedException("无该项目访问权限");
}
return ResponseMap.ofSuccess("查询成功", projectGroupService.getOne(
Wrappers.<ProjectGroup>lambdaQuery()
.eq(ProjectGroup::getStaffId, staffId)
.eq(ProjectGroup::getProjectId, projectId)
));
}
} }

View File

@ -2,6 +2,7 @@ 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.exception.BadRequestException; import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List; import java.util.List;
@ -18,5 +19,5 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
*/ */
Integer getUserLevelInGroup(String token, Integer projectId); Integer getUserLevelInGroup(String token, Integer projectId);
List<Integer> findAllProjectNumber(Integer projectId) throws BadRequestException; List<Integer> findAllProjectNumber(String token, Integer projectId) throws TokenException, BadRequestException;
} }

View File

@ -2,6 +2,7 @@ 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.exception.BadRequestException; import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectGroupMapper; import cn.edu.hfut.rmdjzz.projectmanagement.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;
@ -48,14 +49,19 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
} }
@Override @Override
public List<Integer> findAllProjectNumber(Integer projectId) throws BadRequestException { public List<Integer> findAllProjectNumber(String token, Integer projectId) throws TokenException, BadRequestException {
List<Integer> res = new ArrayList<>(); List<Integer> res = new ArrayList<>();
Integer staffId = TokenUtils.getStaffId(token);
List<ProjectGroup> targetProject = baseMapper.selectList(Wrappers.<ProjectGroup>lambdaQuery().eq(ProjectGroup::getProjectId, projectId)); List<ProjectGroup> targetProject = baseMapper.selectList(Wrappers.<ProjectGroup>lambdaQuery().eq(ProjectGroup::getProjectId, projectId));
if (targetProject.size() == 0) if (targetProject.size() == 0)
throw new BadRequestException("项目不存在"); throw new BadRequestException("项目不存在");
for (int i = 0; i < targetProject.size(); i++) { for (ProjectGroup projectGroup : targetProject) {
res.add(targetProject.get(i).getStaffId()); res.add(projectGroup.getStaffId());
} }
if(!res.contains(staffId))
throw new BadRequestException("用户请求非法");
return res; return res;
} }
} }