Compare commits

..

No commits in common. "f0ca1ce6d9fa4511e6d68e41a34c48bc19a9f98f" and "e714f2e3d41ae67a868be875028f62ac57811ede" have entirely different histories.

5 changed files with 33 additions and 24 deletions

10
pom.xml
View File

@ -15,8 +15,6 @@
<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>
@ -156,14 +154,6 @@
</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,7 +1,13 @@
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.utils.TokenUtils;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -21,8 +27,28 @@ public class ProjectGroupController {
@SneakyThrows
@GetMapping
public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId, @RequestHeader("Token") String token) {
List<Integer> res = projectGroupService.findAllProjectNumber(token, projectId);
public ResponseList<Integer> getGroupNumber(@PathVariable Integer projectId) {
List<Integer> res = projectGroupService.findAllProjectNumber(projectId);
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,7 +2,6 @@ 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;
@ -19,5 +18,5 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
*/
Integer getUserLevelInGroup(String token, Integer projectId);
List<Integer> findAllProjectNumber(String token, Integer projectId) throws TokenException, BadRequestException;
List<Integer> findAllProjectNumber(Integer projectId) throws BadRequestException;
}

View File

@ -2,7 +2,6 @@ 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;
@ -49,19 +48,14 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
}
@Override
public List<Integer> findAllProjectNumber(String token, Integer projectId) throws TokenException, BadRequestException {
public List<Integer> findAllProjectNumber(Integer projectId) throws 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 (ProjectGroup projectGroup : targetProject) {
res.add(projectGroup.getStaffId());
for (int i = 0; i < targetProject.size(); i++) {
res.add(targetProject.get(i).getStaffId());
}
if(!res.contains(staffId))
throw new BadRequestException("用户请求非法");
return res;
}
}