更改了添加组员接口的参数

master
ArgonarioD 2022-07-08 16:08:53 +08:00
parent 4c5ee5efb3
commit c7f448ef81
7 changed files with 28 additions and 9 deletions

View File

@ -78,9 +78,9 @@ public class ProjectGroupController {
public ResponseMap addGroupMember(
@RequestHeader("Token") String token,
@PathVariable Integer projectId,
@RequestBody GroupPositionVO groupPosition
@Parameter(description = "只传staffUsername和projectStaffPosition") @RequestBody GroupPositionVO groupPosition
) {
if (projectGroupService.insertNewMember(token, projectId, groupPosition.getStaffId(), groupPosition.getPositions())) {
if (projectGroupService.insertNewMember(token, projectId, groupPosition.getStaffUsername(), groupPosition.getProjectStaffPosition())) {
return ResponseMap.ofSuccess();
}
throw new BadRequestException(BadRequestException.OPERATE_FAILED);
@ -93,9 +93,9 @@ public class ProjectGroupController {
@RequestHeader("Token") String token,
@PathVariable Integer projectId,
@PathVariable Integer staffId,
@Parameter(description = "不需要在body中传递staffId用path传递") @RequestBody GroupPositionVO groupPosition
@Parameter(description = "在body中只传projectStaffPosition") @RequestBody GroupPositionVO groupPosition
) {
if (projectGroupService.updateStaffPositions(token, staffId, projectId, groupPosition.getPositions())) {
if (projectGroupService.updateStaffPositions(token, staffId, projectId, groupPosition.getProjectStaffPosition())) {
return ResponseMap.ofSuccess();
}
throw new BadRequestException(BadRequestException.OPERATE_FAILED);

View File

@ -9,5 +9,6 @@ import lombok.Data;
@Data
public class GroupPositionVO {
private Integer staffId;
private String positions;
private String staffUsername;
private String projectStaffPosition;
}

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.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;
@ -23,7 +24,7 @@ public interface IProjectGroupService extends IService<ProjectGroup> {
Boolean addCreator(Integer projectId, Integer staffId);
Boolean insertNewMember(String token, Integer projectId, Integer staffId, String positions) throws ForbiddenException;
Boolean insertNewMember(String token, Integer projectId, String staffUsername, String positions) throws ForbiddenException, BadRequestException;
Boolean updateStaffPositions(String token, Integer projectId, Integer targetId, String positions) throws ForbiddenException;

View File

@ -14,6 +14,9 @@ import java.util.Map;
* @since 2022/6/28 17:28
*/
public interface IStaffService extends IService<Staff> {
String STAFF_DOES_NOT_EXIST = "用户不存在";
Map<String, Object> login(String username, String password) throws BadRequestException, TokenException;
Boolean logout(String token) throws TokenException;

View File

@ -1,15 +1,19 @@
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
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.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.RequestPage;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@ -22,6 +26,10 @@ import java.util.Map;
*/
@Service
public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, ProjectGroup> implements IProjectGroupService {
@Autowired
private IStaffService staffService;
@Override
public Boolean addCreator(Integer projectId, Integer staffId) {
if (projectId == null || staffId == null)
@ -35,10 +43,15 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
}
@Override
public Boolean insertNewMember(String token, Integer projectId, Integer targetId, String positions) throws ForbiddenException {
public Boolean insertNewMember(String token, Integer projectId, String targetUsername, String positions) throws ForbiddenException, BadRequestException {
int accessLevel = getProjectAccessLevel(token, projectId);
int targetLevel = 3;
Staff targetStaff = staffService.getOne(Wrappers.<Staff>lambdaQuery().eq(Staff::getStaffUsername, targetUsername));
if (targetStaff == null) {
throw new BadRequestException(IStaffService.STAFF_DOES_NOT_EXIST);
}
if (accessLevel == 0) {
throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
}
@ -58,7 +71,7 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
}
}
return baseMapper.insert(new ProjectGroup(targetId, projectId, positions, targetLevel)) == 1;
return baseMapper.insert(new ProjectGroup(targetStaff.getStaffId(), projectId, positions, targetLevel)) == 1;
}
@Override

View File

@ -50,7 +50,7 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
Staff staff = getOne(Wrappers.<Staff>lambdaQuery().eq(Staff::getStaffUsername, staffUsername));
if (staff == null)
throw new BadRequestException("用户不存在");
throw new BadRequestException(STAFF_DOES_NOT_EXIST);
password = DigestUtils.md5DigestAsHex((password + staff.getStaffSalt()).getBytes());
if (!staff.getStaffPassword().equals(password))
throw new BadRequestException("密码错误");

View File

@ -29,6 +29,7 @@ public class RequestPage {
@Schema(description = "传true或空时为顺序排序否则倒序排序")
Boolean asc;
@Schema(hidden = true)
public <T> IPage<T> getPage() {
Page<T> page = new Page<>(pageCurrent, pageSize);
if (StringUtils.isNotBlank(sortBy)) {