完成了Task的两种查询(待测试)

master
白封羽 2022-07-04 15:22:07 +08:00
parent 6074c8d59f
commit 1df322ecbe
6 changed files with 119 additions and 1 deletions

View File

@ -0,0 +1,35 @@
package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task;
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
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.*;
import java.util.List;
/**
* @author
* created at 2022/7/4 15:02
*/
@RestController
@RequestMapping("/task")
public class TaskController {
@Autowired
private ITaskService taskService;
@SneakyThrows
@GetMapping("/{projectId}")
public ResponseList getTaskList(@RequestHeader("Token") String token,@PathVariable Integer projectId){
List<Task> result = taskService.getTaskList(token,projectId,0);
return ResponseList.ofSuccess("查询成功",result);
}
@SneakyThrows
@GetMapping("/getSubTask")
public ResponseList getSubTaskList(@RequestHeader("Token") String token,@RequestParam("projectId") Integer projectId,@RequestParam("fatherId") Integer fatherId){
List<Task> result = taskService.getTaskList(token,projectId,fatherId);
return ResponseList.ofSuccess("查询成功",result);
}
}

View File

@ -0,0 +1,11 @@
package cn.edu.hfut.rmdjzz.projectmanagement.mapper;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author
* created at 2022/7/4 14:52
*/
public interface TaskMapper extends BaseMapper<Task> {
}

View File

@ -9,5 +9,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IProjectGroupService extends IService<ProjectGroup> {
Boolean addCreator(Integer projectId, Integer staffId);
Integer getUserLevelInGroup(String token,Integer projectId);
}

View File

@ -0,0 +1,16 @@
package cn.edu.hfut.rmdjzz.projectmanagement.service;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @author
* created at 2022/7/4 14:49
*/
public interface ITaskService extends IService<Task> {
List<Task> getTaskList(String token,Integer projectId,Integer fatherId) throws BadRequestException;
}

View File

@ -1,17 +1,23 @@
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.mapper.ProjectGroupMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.io.Serializable;
/**
* @author
* created at 2022/6/30 21:38
*/
@Service
public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, ProjectGroup> implements IProjectGroupService {
@Override
public Boolean addCreator(Integer projectId, Integer staffId) {
if (projectId == null || staffId == null)
return false;
@ -21,4 +27,20 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
projectGroup.setProjectStaffPosition("负责人");
return baseMapper.insert(projectGroup) == 1;
}
//TODO:权限分级
@Override
public Integer getUserLevelInGroup(String token,Integer projectId){
try{
Integer staffId= TokenUtils.getStaffId(token);
ProjectGroup projectGroup=baseMapper.selectOne(Wrappers.<ProjectGroup>lambdaQuery().eq(ProjectGroup::getStaffId, staffId).eq(ProjectGroup::getProjectId, projectId));
if(projectGroup == null)
return 0;
else if(projectGroup.getProjectStaffPosition().length()>0)
return 1;
else
return 0;
}catch(Exception e){//需要调整
return 0;
}
}
}

View File

@ -0,0 +1,34 @@
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.Task;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.StaffMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.TaskMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @author
* created at 2022/7/4 14:51
*/
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {
@Autowired
private ProjectGroupServiceImpl projectGroupServiceImpl;
@Override
public List<Task> getTaskList(String token,Integer projectId,Integer fatherId) throws BadRequestException {
if(projectGroupServiceImpl.getUserLevelInGroup(token,projectId)==0||fatherId==null){
throw new BadRequestException("错误的访问参数");
}
return baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskProjectId,projectId).eq(Task::getTaskFatherId,fatherId));
}
}