feat(demand): 新增项目状态枚举并优化需求相关逻辑- 在 Project 类中添加 ProjectStateEnum 枚举,用于表示项目状态

- 修改 ProjectDemand 类中的枚举名称,从 DemandStatus改为 DemandStatusEnum
- 更新 ProjectDemandMapper.xml,移除冗余的 SQL 语句
- 优化 ProjectDemandServiceImpl 中的插入、更新和删除逻辑,增加项目状态验证
dev_1.2.0
chenhao 2025-03-21 17:52:20 +08:00
parent ce64642460
commit b2da4c75df
4 changed files with 72 additions and 12 deletions

View File

@ -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 "";

View File

@ -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);
}

View File

@ -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 "";
}
}
}

View File

@ -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,