From 49e9399644b1e1c9746bedf40152cab38a00a74a Mon Sep 17 00:00:00 2001 From: WendyYang Date: Thu, 17 Oct 2024 20:55:08 +0800 Subject: [PATCH] =?UTF-8?q?modify:=201.=20=E8=B5=84=E9=87=91=E4=B8=8B?= =?UTF-8?q?=E8=BE=BE=E5=A2=9E=E5=8A=A0=E7=BB=93=E8=BD=AC=E8=B5=84=E9=87=91?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hz/pm/api/common/util/DecimalUtil.java | 7 +++ .../projectlib/entity/ProjectApprovalAmount.java | 2 +- .../projectlib/manage/AmountApprovalManage.java | 55 +++++++++++++--------- .../pm/api/projectlib/manage/ProjectLibManage.java | 4 +- .../service/IProjectApprovalAmountService.java | 4 +- 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/common/util/DecimalUtil.java b/hz-pm-api/src/main/java/com/hz/pm/api/common/util/DecimalUtil.java index 3343904..118644f 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/common/util/DecimalUtil.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/common/util/DecimalUtil.java @@ -84,4 +84,11 @@ public class DecimalUtil { return objs.stream().min(Comparator.comparing(function)).orElse(null); } + public static BigDecimal sum(BigDecimal... nums) { + if (ArrayUtil.isEmpty(nums)) { + return BigDecimal.ZERO; + } + return Arrays.stream(nums).filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); + } + } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/ProjectApprovalAmount.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/ProjectApprovalAmount.java index a6ed915..7eb6484 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/ProjectApprovalAmount.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/ProjectApprovalAmount.java @@ -30,7 +30,7 @@ public class ProjectApprovalAmount implements Serializable { @ApiModelProperty("下达资金") private BigDecimal approvalAmount; - @ApiModelProperty("上一年度结转资金") + @ApiModelProperty("结转资金") private BigDecimal carryOverAmount; @ApiModelProperty("年度") diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/AmountApprovalManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/AmountApprovalManage.java index 14d213c..aa249cb 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/AmountApprovalManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/AmountApprovalManage.java @@ -181,49 +181,51 @@ public class AmountApprovalManage { if (req.getApprovalAmount() != null && NumberUtil.isGreater(currTotalApprovalAmount, reviewAmount)) { throw ReturnException.wrap("暂不允许下达资金"); } + Integer nextYear = null; if (approved) { if (ObjUtil.isAllEmpty(req.getCarryOverAmount(), req.getApprovalAmount())) { throw ReturnException.wrap("下达资金或结转资金不能为空"); } if (req.getCarryOverAmount() != null) { - ProjectApprovalAmount lastApprovalAmount = projectApprovalAmountService.getByProjectCode(project.getProjectCode()); - if (lastApprovalAmount != null && lastApprovalAmount.getApprovalAmount() == null) { - throw ReturnException.wrap("上一年度未下达资金"); - } - if (lastApprovalAmount != null && NumberUtil.isGreater(req.getCarryOverAmount(), lastApprovalAmount.getApprovalAmount())) { - throw ReturnException.wrap("结转资金不允许超过上一年度下达资金"); + ProjectApprovalAmount last = projectApprovalAmountService.last(project.getProjectCode()); + BigDecimal lastTotalAmount = DecimalUtil.sum(last.getApprovalAmount(), last.getCarryOverAmount()); + if (NumberUtil.isGreater(req.getCarryOverAmount(), lastTotalAmount)) { + throw ReturnException.wrap("结转资金不允许超过上一年度总资金"); } + nextYear = last.getApprovalYear() + 1; } } else if (ObjUtil.hasNull(req.getReviewAmount() == null, req.getApprovalAmount())) { throw ReturnException.wrap("评审总投资和下达资金不能为空"); } - - Wrapper wrapper = Wrappers.lambdaUpdate(Project.class) - .set(StrUtil.isNotBlank(req.getApprovalAmountFile()), Project::getApprovalAmountFile, req.getApprovalAmountFile()) - .set(Project::getApprovalAmount, currTotalApprovalAmount) - .set(req.getReviewAmount() != null, Project::getReviewAmount, req.getReviewAmount()) - .set(Project::getUpdateOn, LocalDateTime.now()) - .set(Project::getUpdateBy, LoginUserUtil.getUserId()) - .eq(Project::getId, project.getId()); - - Integer currProjectYear = getLastApprovalYear(project); + if (nextYear == null) { + nextYear = getLastApprovalYear(project); + } + if (req.getApprovalAmount() != null) { + Wrapper projectWrapper = Wrappers.lambdaUpdate(Project.class) + .set(StrUtil.isNotBlank(req.getApprovalAmountFile()), Project::getApprovalAmountFile, req.getApprovalAmountFile()) + .set(Project::getApprovalAmount, currTotalApprovalAmount) + .set(req.getReviewAmount() != null, Project::getReviewAmount, req.getReviewAmount()) + .set(Project::getUpdateOn, LocalDateTime.now()) + .set(Project::getUpdateBy, LoginUserUtil.getUserId()) + .eq(Project::getId, project.getId()); + projectService.update(projectWrapper); + } ProjectApprovalAmount projectApprovalAmount = new ProjectApprovalAmount(); - projectApprovalAmount.setApprovalYear(currProjectYear); + projectApprovalAmount.setApprovalYear(nextYear); projectApprovalAmount.setApprovalAmount(req.getApprovalAmount()); projectApprovalAmount.setProjectId(project.getId()); projectApprovalAmount.setProjectCode(project.getProjectCode()); projectApprovalAmount.setCarryOverAmount(req.getCarryOverAmount()); projectApprovalAmountService.save(projectApprovalAmount); - projectService.update(wrapper); } private Integer getLastApprovalYear(Project project) { - ProjectApprovalAmount lastApprovalAmount = projectApprovalAmountService.getByProjectCode(project.getProjectCode()); + ProjectApprovalAmount last = projectApprovalAmountService.last(project.getProjectCode()); Integer currProjectYear; - if (lastApprovalAmount == null) { + if (last == null) { currProjectYear = project.getProjectYear(); } else { - currProjectYear = lastApprovalAmount.getApprovalYear() + 1; + currProjectYear = last.getApprovalYear() + 1; } return currProjectYear; } @@ -247,8 +249,15 @@ public class AmountApprovalManage { } public List listApprovalAmounts(String projectCode) { - List approvalAmounts = projectApprovalAmountService.listByProjectCode(projectCode); - return BeanUtil.copyToList(approvalAmounts, ProjectApprovalAmountDTO.class); + List approvalAmounts = projectApprovalAmountService.listAsc(projectCode); + List retData = BeanUtil.copyToList(approvalAmounts, ProjectApprovalAmountDTO.class); + for (int i = 0; i < retData.size() - 1; i++) { + ProjectApprovalAmountDTO curr = retData.get(i); + ProjectApprovalAmountDTO next = retData.get(i + 1); + curr.setCarryOverAmount(next.getCarryOverAmount()); + next.setCarryOverAmount(null); + } + return retData; } } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectLibManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectLibManage.java index 289ee87..e2b9505 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectLibManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/manage/ProjectLibManage.java @@ -150,6 +150,7 @@ public class ProjectLibManage { private final ProjectReviewManage projectReviewManage; private final IMeetingInnerProjectService meetingInnerProjectService; private final IProjectApprovalAmountService projectApprovalAmountService; + private final AmountApprovalManage amountApprovalManage; public PageVo projectLibList(ProjectListReq req) { LambdaQueryWrapper query = ProjectManageUtil.projectQuery(req); @@ -717,8 +718,7 @@ public class ProjectLibManage { retProjectDetail.buildDynamicForm(project.getDynamicForm()); String projectCode = project.getProjectCode(); if (DecimalUtil.noNullAndGtZero(project.getApprovalAmount())) { - List approvalAmounts = projectApprovalAmountService.listByProjectCode(projectCode); - retProjectDetail.setApprovalAmounts(BeanUtil.copyToList(approvalAmounts, ProjectApprovalAmountDTO.class)); + retProjectDetail.setApprovalAmounts(amountApprovalManage.listApprovalAmounts(projectCode)); } // 查询应用 List applications = applicationService.list(projectCode, project.getVersion(), project.getIsConstruct()); diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectApprovalAmountService.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectApprovalAmountService.java index 8e9e53b..6460dd0 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectApprovalAmountService.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectApprovalAmountService.java @@ -18,7 +18,7 @@ import java.util.List; */ public interface IProjectApprovalAmountService extends IService { - default ProjectApprovalAmount getByProjectCode(String projectCode) { + default ProjectApprovalAmount last(String projectCode) { Wrapper query = Wrappers.lambdaQuery(ProjectApprovalAmount.class) .eq(ProjectApprovalAmount::getProjectCode, projectCode) .orderByDesc(ProjectApprovalAmount::getApprovalYear) @@ -26,7 +26,7 @@ public interface IProjectApprovalAmountService extends IService listByProjectCode(String projectCode) { + default List listAsc(String projectCode) { Wrapper query = Wrappers.lambdaQuery(ProjectApprovalAmount.class) .eq(ProjectApprovalAmount::getProjectCode, projectCode) .orderByAsc(ProjectApprovalAmount::getApprovalYear);