Compare commits
2 Commits
e714f2e3d4
...
f0ca1ce6d9
Author | SHA1 | Date |
---|---|---|
ShiPengHui | f0ca1ce6d9 | |
ShiPengHui | 93a0d7ba28 |
10
pom.xml
10
pom.xml
|
@ -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>
|
||||||
|
|
||||||
|
|
|
@ -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)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.apache.ibatis.annotations.Select;
|
||||||
public interface ProjectMapper extends BaseMapper<Project> {
|
public interface ProjectMapper extends BaseMapper<Project> {
|
||||||
|
|
||||||
@Select("""
|
@Select("""
|
||||||
SELECT COUNT(*) FROM project WHERE project_id IN
|
SELECT COUNT(*) FROM project WHERE project_id IN
|
||||||
(SELECT DISTINCT project_id FROM project_group WHERE staff_id = #{id})
|
(SELECT DISTINCT project_id FROM project_group WHERE staff_id = #{id})
|
||||||
""")
|
""")
|
||||||
Long findProjectCount(@Param("id") Integer staffId);
|
Long findProjectCount(@Param("id") Integer staffId);
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue