实现了项目更新功能
parent
5bcf064ae9
commit
a257d53021
|
@ -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("操作成功");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -47,14 +47,39 @@ public class Project {
|
||||||
private LocalDateTime projectCreatedTime;
|
private LocalDateTime projectCreatedTime;
|
||||||
private LocalDate projectClosedDate;
|
private LocalDate projectClosedDate;
|
||||||
|
|
||||||
Boolean checkProjectDate() {
|
public Boolean checkProjectDate() {
|
||||||
if(!TimeUtils.validateTimeLine(projectStartDate, projectFirstTestDate, projectClosedDate, projectEndDate)) {
|
if (!TimeUtils.validateTimeLine(projectStartDate, projectFirstTestDate, projectClosedDate, 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,4 +24,6 @@ public interface IProjectService extends IService<Project> {
|
||||||
Boolean createProject(String token, Project project) throws BadRequestException;
|
Boolean createProject(String token, Project project) throws BadRequestException;
|
||||||
|
|
||||||
Boolean checkOpenStatus(Integer projectId);
|
Boolean checkOpenStatus(Integer projectId);
|
||||||
|
|
||||||
|
Boolean updateProject(String token, Project project) throws BadRequestException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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("参数错误");
|
||||||
}
|
}
|
||||||
|
@ -100,4 +100,22 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
||||||
Project project = baseMapper.selectOne(Wrappers.<Project>lambdaQuery().eq(Project::getProjectId, projectId));
|
Project project = baseMapper.selectOne(Wrappers.<Project>lambdaQuery().eq(Project::getProjectId, projectId));
|
||||||
return project != null && !project.getCompleted();
|
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("修改失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue