Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/entity/Project.java
master
yang.yongquan 2022-07-07 14:14:06 +08:00
commit 434ad8f57b
7 changed files with 74 additions and 14 deletions

View File

@ -82,7 +82,6 @@ public class ProjectController {
return ResponseMap.ofSuccess("操作成功"); return ResponseMap.ofSuccess("操作成功");
} }
//TODO:该业务尚未实现
@SneakyThrows @SneakyThrows
@PutMapping("/{projectId}") @PutMapping("/{projectId}")
public ResponseMap updateProject( public ResponseMap updateProject(
@ -90,9 +89,10 @@ public class ProjectController {
@PathVariable Integer projectId, @PathVariable Integer projectId,
@RequestBody Project project @RequestBody Project project
) { ) {
//project.setProjectId(projectId); project.setProjectId(projectId);
//projectService.updateById(project); if (!projectService.checkOpenStatus(projectId))
//return ResponseMap.ofSuccess("操作成功"); throw new BadRequestException("项目未开放");
return null; projectService.updateProject(token, project);
return ResponseMap.ofSuccess("操作成功");
} }
} }

View File

@ -8,9 +8,6 @@ import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap; import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.SchemaProperty;
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.*;

View File

@ -2,6 +2,8 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task; import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.TaskDto; import cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.TaskDto;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService; import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
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 cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
@ -20,7 +22,8 @@ import java.util.List;
public class TaskController { public class TaskController {
@Autowired @Autowired
private ITaskService taskService; private ITaskService taskService;
@Autowired
private IProjectService projectService;
@SneakyThrows @SneakyThrows
@GetMapping("/{fatherId}/subtask") @GetMapping("/{fatherId}/subtask")
public ResponseList<TaskDto> getSubTaskList( public ResponseList<TaskDto> getSubTaskList(
@ -57,6 +60,8 @@ public class TaskController {
@PathVariable("projectId") Integer projectId, @PathVariable("projectId") Integer projectId,
@RequestBody Task task @RequestBody Task task
) { ) {
if(!projectService.checkOpenStatus(projectId))
throw new BadRequestException("项目未开放");
task.setTaskProjectId(projectId); task.setTaskProjectId(projectId);
taskService.insertTask(token, task); taskService.insertTask(token, task);
return ResponseMap.ofSuccess("操作成功"); return ResponseMap.ofSuccess("操作成功");
@ -70,6 +75,8 @@ public class TaskController {
@PathVariable("taskId") Long taskId, @PathVariable("taskId") Long taskId,
@RequestBody Task task @RequestBody Task task
) { ) {
if(!projectService.checkOpenStatus(projectId))
throw new BadRequestException("项目未开放");
task.setTaskProjectId(projectId); task.setTaskProjectId(projectId);
task.setTaskId(taskId); task.setTaskId(taskId);
taskService.modifyTask(token, task); taskService.modifyTask(token, task);
@ -83,6 +90,8 @@ public class TaskController {
@PathVariable("projectId") Integer projectId, @PathVariable("projectId") Integer projectId,
@PathVariable("taskId") Long taskId @PathVariable("taskId") Long taskId
) { ) {
if(!projectService.checkOpenStatus(projectId))
throw new BadRequestException("项目未开放");
taskService.deleteTaskAndSubTask(token, projectId, taskId); taskService.deleteTaskAndSubTask(token, projectId, taskId);
return ResponseMap.ofSuccess("删除成功"); return ResponseMap.ofSuccess("删除成功");
} }

View File

@ -10,6 +10,7 @@ import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Objects;
/** /**
* @author * @author
@ -20,7 +21,6 @@ public class Project {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Integer projectId; private Integer projectId;
private String projectName; private String projectName;
//TODO: 时间线顺序判断
private LocalDate projectStartDate; private LocalDate projectStartDate;
private LocalDate projectOnlineDate; private LocalDate projectOnlineDate;
private LocalDate projectFirstTestDate; private LocalDate projectFirstTestDate;
@ -51,10 +51,35 @@ public class Project {
if(!TimeUtils.validateTimeLine(projectStartDate, projectFirstTestDate, projectFinalTestDate, projectEndDate)) { if(!TimeUtils.validateTimeLine(projectStartDate, projectFirstTestDate, projectFinalTestDate, projectEndDate)) {
return false; return false;
} }
if(!TimeUtils.validateTimeLine(projectStartDate, projectOnlineDate)) { if (!TimeUtils.validateTimeLine(projectStartDate, projectOnlineDate)) {
return false; return false;
} }
return true; return true;
} }
public Boolean checkModification(Project rawProject) {
if (!this.checkProjectDate())
return false;
if (!Objects.equals(this.getProjectId(), rawProject.getProjectId()))
return false;
if (!Objects.equals(this.getProjectCreator(), rawProject.getProjectCreator()))
return false;
if (!Objects.equals(this.getProjectCreatedTime(), rawProject.getProjectCreatedTime()))
return false;
if (!Objects.equals(this.getProjectName(), rawProject.getProjectName()))
return false;
if (!Objects.equals(this.getProjectClassId(), rawProject.getProjectClassId()))
return false;
if (!Objects.equals(this.getProjectSubclassId(), rawProject.getProjectSubclassId()))
return false;
if (!Objects.equals(this.getProjectDepartment(), rawProject.getProjectDepartment()))
return false;
if (!Objects.equals(this.getProjectCompany(), rawProject.getProjectCompany()))
return false;
if (!Objects.equals(this.getProjectArea(), rawProject.getProjectArea()))
return false;
this.setDeleted(false);
this.setCompleted(false);
return true;
}
} }

View File

@ -92,7 +92,7 @@ public class Task {
if (father.getTaskId() == 0) if (father.getTaskId() == 0)
return true; return true;
if (this.getTaskType().equals("缺陷")) { if (this.getTaskType().equals("缺陷")) {
return false; return father.getTaskType().equals("需求");
} else if (this.getTaskType().equals("需求")) { } else if (this.getTaskType().equals("需求")) {
return father.getTaskType().equals("需求"); return father.getTaskType().equals("需求");
} else if (this.getTaskType().equals("任务")) { } else if (this.getTaskType().equals("任务")) {

View File

@ -22,4 +22,8 @@ public interface IProjectService extends IService<Project> {
Boolean setProjectCompleted(String token, Integer projectId) throws BadRequestException; Boolean setProjectCompleted(String token, Integer projectId) throws BadRequestException;
Boolean createProject(String token, Project project) throws BadRequestException; Boolean createProject(String token, Project project) throws BadRequestException;
Boolean checkOpenStatus(Integer projectId);
Boolean updateProject(String token, Project project) throws BadRequestException;
} }

View File

@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -76,8 +77,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
if (project.getExpectedCompletion() == null) { if (project.getExpectedCompletion() == null) {
project.setExpectedCompletion((short) 100); project.setExpectedCompletion((short) 100);
} else if (project.getExpectedCompletion() < 0 || project.getExpectedCompletion() > 100 || } else if (project.getExpectedCompletion() < 0 || project.getExpectedCompletion() > 100 ||
project.getProjectStartDate() == null || project.getProjectEndDate() == null || !project.checkProjectDate() || project.getProjectManMonth().compareTo(new BigDecimal("0")) == -1
project.getProjectStartDate().isAfter(project.getProjectEndDate())
) { ) {
throw new BadRequestException("参数错误"); throw new BadRequestException("参数错误");
} }
@ -93,4 +93,29 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
} }
return false; return false;
} }
public Boolean checkOpenStatus(Integer projectId) {
if (projectId == null || projectId < 1)
return false;
Project project = baseMapper.selectOne(Wrappers.<Project>lambdaQuery().eq(Project::getProjectId, projectId));
return project != null && !project.getCompleted();
}
public Boolean updateProject(String token, Project project) throws BadRequestException {
Integer staffId = TokenUtils.getStaffId(token);
if (!staffId.equals(project.getProjectCreator())) {
throw new BadRequestException("无权操作");
}
Project rawProject = baseMapper.selectOne(Wrappers.<Project>lambdaQuery().eq(Project::getProjectId, project.getProjectId()));
if (!project.checkModification(rawProject)) {
throw new BadRequestException("参数错误");
}
try {
if (baseMapper.updateById(project) == 1)
return true;
throw new BadRequestException("修改失败");
} catch (Exception e) {
throw new BadRequestException("修改失败");
}
}
} }