From b2da4c75dfaf283bb97c141df1de2b29d0b6c355 Mon Sep 17 00:00:00 2001 From: chenhao <852066789@qq.com> Date: Fri, 21 Mar 2025 17:52:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(demand):=20=E6=96=B0=E5=A2=9E=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=8A=B6=E6=80=81=E6=9E=9A=E4=B8=BE=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=9C=80=E6=B1=82=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= =?UTF-8?q?-=20=E5=9C=A8=20Project=20=E7=B1=BB=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20ProjectStateEnum=20=E6=9E=9A=E4=B8=BE=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E8=A1=A8=E7=A4=BA=E9=A1=B9=E7=9B=AE=E7=8A=B6=E6=80=81?= =?UTF-8?q?=20-=20=E4=BF=AE=E6=94=B9=20ProjectDemand=20=E7=B1=BB=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=9E=9A=E4=B8=BE=E5=90=8D=E7=A7=B0=EF=BC=8C=E4=BB=8E?= =?UTF-8?q?=20DemandStatus=E6=94=B9=E4=B8=BA=20DemandStatusEnum=20-=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ProjectDemandMapper.xml=EF=BC=8C=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=86=97=E4=BD=99=E7=9A=84=20SQL=20=E8=AF=AD=E5=8F=A5?= =?UTF-8?q?=20-=20=E4=BC=98=E5=8C=96=20ProjectDemandServiceImpl=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=8F=92=E5=85=A5=E3=80=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=92=8C=E5=88=A0=E9=99=A4=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=A1=B9=E7=9B=AE=E7=8A=B6=E6=80=81=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/demand/domain/ProjectDemand.java | 10 ++--- .../impl/ProjectDemandServiceImpl.java | 30 ++++++++++--- .../pms/business/project/domain/Project.java | 42 +++++++++++++++++++ .../ProjectDemand/ProjectDemandMapper.xml | 2 +- 4 files changed, 72 insertions(+), 12 deletions(-) diff --git a/pms-business/src/main/java/tech/unissense/pms/business/demand/domain/ProjectDemand.java b/pms-business/src/main/java/tech/unissense/pms/business/demand/domain/ProjectDemand.java index d28ce44..df3f074 100644 --- a/pms-business/src/main/java/tech/unissense/pms/business/demand/domain/ProjectDemand.java +++ b/pms-business/src/main/java/tech/unissense/pms/business/demand/domain/ProjectDemand.java @@ -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 ""; diff --git a/pms-business/src/main/java/tech/unissense/pms/business/demand/service/impl/ProjectDemandServiceImpl.java b/pms-business/src/main/java/tech/unissense/pms/business/demand/service/impl/ProjectDemandServiceImpl.java index fcecb48..e0b8a39 100644 --- a/pms-business/src/main/java/tech/unissense/pms/business/demand/service/impl/ProjectDemandServiceImpl.java +++ b/pms-business/src/main/java/tech/unissense/pms/business/demand/service/impl/ProjectDemandServiceImpl.java @@ -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); } diff --git a/pms-business/src/main/java/tech/unissense/pms/business/project/domain/Project.java b/pms-business/src/main/java/tech/unissense/pms/business/project/domain/Project.java index e2faaac..6624aa0 100644 --- a/pms-business/src/main/java/tech/unissense/pms/business/project/domain/Project.java +++ b/pms-business/src/main/java/tech/unissense/pms/business/project/domain/Project.java @@ -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 ""; + } + } } diff --git a/pms-business/src/main/resources/mapper/business/ProjectDemand/ProjectDemandMapper.xml b/pms-business/src/main/resources/mapper/business/ProjectDemand/ProjectDemandMapper.xml index 3fe14d0..6f8cb6b 100644 --- a/pms-business/src/main/resources/mapper/business/ProjectDemand/ProjectDemandMapper.xml +++ b/pms-business/src/main/resources/mapper/business/ProjectDemand/ProjectDemandMapper.xml @@ -108,7 +108,7 @@ INSERT INTO pms_project_demand - title,/projectVersion/tree + title, version_id,