带权限的项目成员id查询

master
ShiPengHui 2022-07-06 17:26:13 +08:00
parent 5e26599858
commit 93a0d7ba28
5 changed files with 25 additions and 12 deletions

10
pom.xml
View File

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

View File

@ -1,14 +1,10 @@
package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -25,8 +21,8 @@ public class ProjectGroupController {
@SneakyThrows
@GetMapping
public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId) {
List<Integer> res = projectGroupService.findAllProjectNumber(projectId);
public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId, @RequestHeader("Token") String token) {
List<Integer> res = projectGroupService.findAllProjectNumber(token, projectId);
return ResponseList.ofSuccess("查询成功", res);
}
}

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.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@ -18,5 +19,5 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
*/
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.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectGroupMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
@ -48,14 +49,19 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
}
@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<>();
Integer staffId = TokenUtils.getStaffId(token);
List<ProjectGroup> targetProject = baseMapper.selectList(Wrappers.<ProjectGroup>lambdaQuery().eq(ProjectGroup::getProjectId, projectId));
if (targetProject.size() == 0)
throw new BadRequestException("项目不存在");
for (int i = 0; i < targetProject.size(); i++) {
res.add(targetProject.get(i).getStaffId());
for (ProjectGroup projectGroup : targetProject) {
res.add(projectGroup.getStaffId());
}
if(!res.contains(staffId))
throw new BadRequestException("用户请求非法");
return res;
}
}