feat(demand): 新增项目状态枚举并优化需求相关逻辑- 在 Project 类中添加 ProjectStateEnum 枚举,用于表示项目状态
- 修改 ProjectDemand 类中的枚举名称,从 DemandStatus改为 DemandStatusEnum - 更新 ProjectDemandMapper.xml,移除冗余的 SQL 语句 - 优化 ProjectDemandServiceImpl 中的插入、更新和删除逻辑,增加项目状态验证dev_1.2.0
parent
ce64642460
commit
b2da4c75df
|
@ -62,7 +62,7 @@ public class ProjectDemand implements Serializable {
|
|||
/**
|
||||
* 需求状态
|
||||
*/
|
||||
public enum DemandStatus
|
||||
public enum DemandStatusEnum
|
||||
{
|
||||
/** 0待排期 */
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class ProjectDemand implements Serializable {
|
|||
private final String value;
|
||||
private final String remark;
|
||||
|
||||
DemandStatus(String value,String remark)
|
||||
DemandStatusEnum(String value, String remark)
|
||||
{
|
||||
this.remark = remark;
|
||||
this.value = value;
|
||||
|
@ -93,9 +93,9 @@ public class ProjectDemand implements Serializable {
|
|||
}
|
||||
public static String getRemark(String value)
|
||||
{
|
||||
for (DemandStatus demandStatus : DemandStatus.values()) {
|
||||
if (demandStatus.value.equals(value)){
|
||||
return demandStatus.remark;
|
||||
for (DemandStatusEnum demandStatusEnum : DemandStatusEnum.values()) {
|
||||
if (demandStatusEnum.value.equals(value)){
|
||||
return demandStatusEnum.remark;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package tech.unissense.pms.business.demand.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.springframework.cglib.core.Local;
|
||||
import tech.unissense.pms.business.demand.domain.ProjectDemand;
|
||||
import tech.unissense.pms.business.demand.mapper.ProjectDemandMapper;
|
||||
import tech.unissense.pms.business.demand.service.IProjectDemandService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tech.unissense.pms.business.project.domain.Project;
|
||||
import tech.unissense.pms.business.project.mapper.ProjectMapper;
|
||||
import tech.unissense.pms.common.exception.ServiceException;
|
||||
import tech.unissense.pms.common.utils.DateUtils;
|
||||
|
||||
|
@ -13,9 +14,7 @@ import javax.annotation.Resource;
|
|||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +28,8 @@ public class ProjectDemandServiceImpl implements IProjectDemandService {
|
|||
|
||||
@Resource
|
||||
private ProjectDemandMapper projectDemandMapper;
|
||||
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
/**
|
||||
* 查询列表数据
|
||||
|
@ -51,6 +51,7 @@ public class ProjectDemandServiceImpl implements IProjectDemandService {
|
|||
|
||||
@Override
|
||||
public int insert(ProjectDemand projectDemand) {
|
||||
verifyProjectState(projectDemand);
|
||||
if (projectDemand.getEndTime() == null) {
|
||||
//根据当前时间向上取整
|
||||
BigDecimal estimatedWorkHours = new BigDecimal(projectDemand.getEstimatedWorkHours());
|
||||
|
@ -58,10 +59,24 @@ public class ProjectDemandServiceImpl implements IProjectDemandService {
|
|||
LocalDate createDate = projectDemand.getCreateTime() == null ? LocalDate.now() :
|
||||
projectDemand.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
projectDemand.setEndTime(DateUtil.date(createDate.plusDays(bigDecimal.intValue())));
|
||||
} else {
|
||||
if (DateUtils.getNowDate().after(projectDemand.getEndTime())) {
|
||||
throw new ServiceException("结束时间不能早于当前时间");
|
||||
}
|
||||
}
|
||||
return projectDemandMapper.insert(projectDemand);
|
||||
}
|
||||
|
||||
private void verifyProjectState(ProjectDemand projectDemand) {
|
||||
Project project = projectMapper.queryById(projectDemand.getProjectId());
|
||||
if (project == null) {
|
||||
throw new ServiceException("项目不存在");
|
||||
}
|
||||
if (Project.ProjectStateEnum.JXZ.value().equals(project.getProjectState())) {
|
||||
throw new ServiceException("项目不处于进行中");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更改逻辑:1:已完成,已关闭状态发生变更必须校验结束时间在当前时间之后 2:定时任务修改状态为已完成
|
||||
|
@ -73,10 +88,11 @@ public class ProjectDemandServiceImpl implements IProjectDemandService {
|
|||
*/
|
||||
@Override
|
||||
public int update(ProjectDemand projectDemand) {
|
||||
verifyProjectState(projectDemand);
|
||||
ProjectDemand existDemand = this.queryById(projectDemand.getId());
|
||||
//已完成或已关闭状态
|
||||
boolean statusFlag = ProjectDemand.DemandStatus.YWC.value().equals(existDemand.getDemandStatus())
|
||||
|| ProjectDemand.DemandStatus.YGB.value().equals(existDemand.getDemandStatus());
|
||||
boolean statusFlag = ProjectDemand.DemandStatusEnum.YWC.value().equals(existDemand.getDemandStatus())
|
||||
|| ProjectDemand.DemandStatusEnum.YGB.value().equals(existDemand.getDemandStatus());
|
||||
// 当前状态发生变化,并且结束时间在当前时间之前
|
||||
boolean timeFlag = !existDemand.getDemandStatus().equals(projectDemand.getDemandStatus()) && DateUtils.getNowDate().before(projectDemand.getEndTime());
|
||||
if (statusFlag && timeFlag) {
|
||||
|
@ -89,6 +105,8 @@ public class ProjectDemandServiceImpl implements IProjectDemandService {
|
|||
|
||||
@Override
|
||||
public int deleteById(Integer id) {
|
||||
ProjectDemand projectDemand = queryById(id);
|
||||
verifyProjectState(projectDemand);
|
||||
return projectDemandMapper.deleteById(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package tech.unissense.pms.business.project.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import tech.unissense.pms.business.demand.domain.ProjectDemand;
|
||||
import tech.unissense.pms.common.core.domain.BaseEntity;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -79,6 +80,47 @@ public class Project extends BaseEntity {
|
|||
private Integer teamNum;
|
||||
|
||||
private Long queryUserId;
|
||||
/**
|
||||
* 需求状态
|
||||
*/
|
||||
public enum ProjectStateEnum
|
||||
{
|
||||
/** 0待排期 */
|
||||
|
||||
DPQ("0","待排期"),
|
||||
/** 已计划 */
|
||||
YJH("1","已计划"),
|
||||
/** 进行中 */
|
||||
JXZ("2","进行中"),
|
||||
/** 已完成 */
|
||||
YWC("3","已完成"),
|
||||
/** 已关闭 */
|
||||
YGB("4","已关闭"),
|
||||
|
||||
;
|
||||
|
||||
private final String value;
|
||||
private final String remark;
|
||||
|
||||
ProjectStateEnum(String value,String remark)
|
||||
{
|
||||
this.remark = remark;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String value()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
public static String getRemark(String value)
|
||||
{
|
||||
for (Project.ProjectStateEnum projectStateEnum : Project.ProjectStateEnum.values()) {
|
||||
if (projectStateEnum.value.equals(value)){
|
||||
return projectStateEnum.remark;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@
|
|||
INSERT INTO pms_project_demand
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="title != null and title != ''">
|
||||
title,/projectVersion/tree
|
||||
title,
|
||||
</if>
|
||||
<if test="versionId != null and versionId != ''">
|
||||
version_id,
|
||||
|
|
Loading…
Reference in New Issue