分页查询项目成员id,用户名,全名,职位,权限等级

master
ShiPengHui 2022-07-07 15:59:06 +08:00
parent ad9544111c
commit 0db64e3fad
5 changed files with 40 additions and 17 deletions

View File

@ -1,20 +1,24 @@
package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.ProjectGroupDto;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.vo.GroupPositionVo;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.ForbiddenException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
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.ResponseList;
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 io.swagger.v3.oas.annotations.Parameter;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
@ -33,8 +37,15 @@ 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<ProjectGroupDto> getGroupNumber(
@PathVariable Integer projectId,
@RequestHeader("Token") String token,
@Valid RequestPage page
) {
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
throw new ForbiddenException("无该项目访问权限");
}
Page<ProjectGroupDto> res = projectGroupService.getOnePageProjectNumber(page, projectId);
return ResponseList.ofSuccess("查询成功", res);
}

View File

@ -10,8 +10,8 @@ import lombok.Data;
@Data
public class ProjectGroupDto {
Integer staffId;
String staffUsername;
String staffFullname;
Integer projectId;
String projectStaffPosition;
Integer projectAccessLevel;
}

View File

@ -1,11 +1,25 @@
package cn.edu.hfut.rmdjzz.projectmanagement.mapper;
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 com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @author
* created at 2022/6/30 21:34
*/
public interface ProjectGroupMapper extends BaseMapper<ProjectGroup> {
@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}
""")
Page<ProjectGroupDto> findNumber(IPage<ProjectDto> pg, @Param("projectId") Integer projectId);
}

View File

@ -1,8 +1,11 @@
package cn.edu.hfut.rmdjzz.projectmanagement.service;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
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.utils.http.RequestPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@ -28,7 +31,7 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
Integer compareProjectAccessLevel(Integer projectId, Integer staffId1, Integer staffId2);
List<Integer> findAllProjectNumber(String token, Integer projectId) throws BadRequestException;
Page<ProjectGroupDto> getOnePageProjectNumber(RequestPage page, Integer projectId);
/**
*

View File

@ -1,12 +1,17 @@
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
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.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.ForbiddenException;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectGroupMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
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.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@ -117,19 +122,9 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
}
@Override
public List<Integer> findAllProjectNumber(String token, 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());
}
if (!res.contains(staffId))
throw new BadRequestException("用户请求非法");
return res;
public Page<ProjectGroupDto> getOnePageProjectNumber(RequestPage page, Integer projectId){
IPage<ProjectGroupDto> numberPage = baseMapper.findNumber(page.getPage(), projectId);
return (Page<ProjectGroupDto>) numberPage;
}
@Override