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 fecd1f1..3343904 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 @@ -24,7 +24,7 @@ public class DecimalUtil { private DecimalUtil() { } - public static boolean notNullAndGtZero(BigDecimal num) { + public static boolean noNullAndGtZero(BigDecimal num) { return num != null && num.compareTo(BigDecimal.ZERO) > 0; } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/AmountApprovalController.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/AmountApprovalController.java index cb91c79..0baf2c1 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/AmountApprovalController.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/controller/AmountApprovalController.java @@ -1,6 +1,7 @@ package com.hz.pm.api.projectlib.controller; import com.hz.pm.api.projectlib.manage.AmountApprovalManage; +import com.hz.pm.api.projectlib.model.dto.ProjectApprovalAmountDTO; import com.hz.pm.api.projectlib.model.req.ProjectListReq; import com.hz.pm.api.projectlib.model.req.SubmitAmountApprovalReq; import com.hz.pm.api.projectlib.model.vo.AmountApprovalProgressStatisticsVO; @@ -10,9 +11,11 @@ import com.ningdatech.log.annotation.WebLog; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.util.List; /** *

@@ -49,4 +52,16 @@ public class AmountApprovalController { amountApprovalManage.submitAmountApproval(req); } + @PostMapping("/initOldApprovalAmount") + @PreAuthorize("hasAuthority('SUPER_ADMIN')") + public void initOldApprovalAmount() { + amountApprovalManage.initOldApprovalAmount(); + } + + @GetMapping("/{projectCode}") + @ApiOperation("查询项目资金下达记录") + public List listApprovalAmounts(@PathVariable String projectCode) { + return amountApprovalManage.listApprovalAmounts(projectCode); + } + } 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 new file mode 100644 index 0000000..d5b2091 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/entity/ProjectApprovalAmount.java @@ -0,0 +1,48 @@ +package com.hz.pm.api.projectlib.entity; + +import com.baomidou.mybatisplus.annotation.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + *

+ * 项目资金下达记录 + *

+ * + * @author WendyYang + * @since 2024-10-09 + */ +@Data +@TableName("ND_PROJECT_APPROVAL_AMOUNT") +@ApiModel(value = "NdProjectApprovalAmount对象") +public class ProjectApprovalAmount implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "ID", type = IdType.AUTO) + private Long id; + + @ApiModelProperty("下达资金") + private BigDecimal approvalAmount; + + @ApiModelProperty("年度") + private Integer approvalYear; + + @ApiModelProperty("项目ID") + private Long projectId; + + @ApiModelProperty("项目编号") + private String projectCode; + + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long createBy; + + @TableField(fill = FieldFill.INSERT_UPDATE) + private LocalDateTime createOn; + +} 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 8384376..9cbdd43 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 @@ -1,23 +1,32 @@ package com.hz.pm.api.projectlib.manage; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.ObjUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.hz.pm.api.common.exception.ReturnException; import com.hz.pm.api.common.helper.UserInfoHelper; +import com.hz.pm.api.common.model.constant.BizConst; import com.hz.pm.api.common.util.DecimalUtil; import com.hz.pm.api.datascope.model.DataScopeDTO; import com.hz.pm.api.datascope.utils.DataScopeUtil; import com.hz.pm.api.external.model.enumeration.MhUnitStripEnum; +import com.hz.pm.api.projectlib.entity.ProjectApprovalAmount; import com.hz.pm.api.projectlib.helper.ProjectManageUtil; +import com.hz.pm.api.projectlib.model.dto.ProjectApprovalAmountDTO; import com.hz.pm.api.projectlib.model.entity.Project; import com.hz.pm.api.projectlib.model.enumeration.status.ProjectStatus; import com.hz.pm.api.projectlib.model.req.ProjectListReq; import com.hz.pm.api.projectlib.model.req.SubmitAmountApprovalReq; import com.hz.pm.api.projectlib.model.vo.AmountApprovalProgressStatisticsVO; import com.hz.pm.api.projectlib.model.vo.ProjectLibListItemVO; +import com.hz.pm.api.projectlib.service.INdProjectApprovalAmountService; import com.hz.pm.api.projectlib.service.IProjectService; import com.hz.pm.api.user.helper.MhUnitCache; import com.hz.pm.api.user.security.model.UserFullInfoDTO; @@ -26,11 +35,15 @@ import com.ningdatech.basic.model.PageVo; import com.ningdatech.basic.util.CollUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.assertj.core.error.ElementsShouldBeExactly; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; /** *

@@ -45,6 +58,7 @@ import java.util.Optional; @RequiredArgsConstructor public class AmountApprovalManage { + private final INdProjectApprovalAmountService projectApprovalAmountService; private final IProjectService projectService; private final UserInfoHelper userInfoHelper; private final MhUnitCache mhUnitCache; @@ -150,25 +164,76 @@ public class AmountApprovalManage { List page = projectService.list(query); AmountApprovalProgressStatisticsVO stat = new AmountApprovalProgressStatisticsVO(); stat.setTotalCount(page.size()); - stat.setApprovalCount(CollUtil.count(page, w -> DecimalUtil.notNullAndGtZero(w.getApprovalAmount()))); + stat.setApprovalCount(CollUtil.count(page, w -> DecimalUtil.noNullAndGtZero(w.getApprovalAmount()))); stat.setUnApprovalCount(stat.getTotalCount() - stat.getApprovalCount()); return stat; } - public void submitAmountApproval(SubmitAmountApprovalReq req) { + public synchronized void submitAmountApproval(SubmitAmountApprovalReq req) { Project project = projectService.getNewestNoNull(req.getProjectId()); if (ProjectStatus.STOPPED.eq(project.getStage()) || ProjectStatus.CHANGE.eq(project.getStage())) { throw ReturnException.wrap("暂不允许下达资金"); } + BigDecimal totalApprovalAmount = ObjUtil.defaultIfNull(project.getApprovalAmount(), BigDecimal.ZERO); + boolean approved = DecimalUtil.noNullAndGtZero(totalApprovalAmount); + if (!approved && req.getReviewAmount() == null) { + throw ReturnException.wrap("评审总投资不能为空"); + } + BigDecimal currTotalApprovalAmount = NumberUtil.add(totalApprovalAmount, req.getApprovalAmount()); + if (approved && NumberUtil.isGreater(currTotalApprovalAmount, project.getReviewAmount())) { + throw ReturnException.wrap("暂不允许下达资金"); + } Wrapper wrapper = Wrappers.lambdaUpdate(Project.class) - .set(Project::getApprovalAmountFile, req.getApprovalAmountFile()) - .set(Project::getApprovalAmount, req.getApprovalAmount()) - .set(Project::getReviewAmount, req.getReviewAmount()) + .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); + ProjectApprovalAmount projectApprovalAmount = new ProjectApprovalAmount(); + projectApprovalAmount.setApprovalYear(currProjectYear); + projectApprovalAmount.setApprovalAmount(req.getApprovalAmount()); + projectApprovalAmount.setProjectId(project.getId()); + projectApprovalAmount.setProjectCode(project.getProjectCode()); + projectApprovalAmountService.save(projectApprovalAmount); projectService.update(wrapper); } + private Integer getLastApprovalYear(Project project) { + ProjectApprovalAmount lastApprovalAmount = projectApprovalAmountService.getByProjectCode(project.getProjectCode()); + Integer currProjectYear; + if (lastApprovalAmount == null) { + currProjectYear = project.getProjectYear(); + } else { + currProjectYear = lastApprovalAmount.getApprovalYear() + 1; + } + return currProjectYear; + } + + @Transactional(rollbackFor = Exception.class) + public synchronized void initOldApprovalAmount(){ + LambdaQueryWrapper query = Wrappers.lambdaQuery(Project.class) + .gt(Project::getApprovalAmount, 0) + .isNotNull(Project::getApprovalAmount) + .eq(Project::getNewest, Boolean.TRUE); + List projects = projectService.list(query); + List approvalAmounts = projects.stream().map(w -> { + ProjectApprovalAmount approvalAmount = new ProjectApprovalAmount(); + approvalAmount.setApprovalYear(w.getProjectYear()); + approvalAmount.setApprovalAmount(w.getApprovalAmount()); + approvalAmount.setProjectId(w.getId()); + approvalAmount.setProjectCode(w.getProjectCode()); + return approvalAmount; + }).collect(Collectors.toList()); + projectApprovalAmountService.saveBatch(approvalAmounts); + } + + public List listApprovalAmounts(String projectCode){ + List approvalAmounts = projectApprovalAmountService.listByProjectCode(projectCode); + return BeanUtil.copyToList(approvalAmounts, ProjectApprovalAmountDTO.class); + } + } 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 7e1edfd..cb82946 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 @@ -24,6 +24,7 @@ import com.hz.pm.api.common.model.constant.ExistsSqlConst; import com.hz.pm.api.common.model.entity.ExcelExportWriter; import com.hz.pm.api.common.statemachine.util.ProjectStateMachineUtil; import com.hz.pm.api.common.util.BizUtils; +import com.hz.pm.api.common.util.DecimalUtil; import com.hz.pm.api.common.util.ExcelDownUtil; import com.hz.pm.api.common.util.StrUtils; import com.hz.pm.api.datascope.model.DataScopeDTO; @@ -56,12 +57,14 @@ import com.hz.pm.api.projectdeclared.service.IPreInsAcceptancePersonService; import com.hz.pm.api.projectdeclared.service.IPurchaseService; import com.hz.pm.api.projectdeclared.utils.ProjectCodeGenUtil; import com.hz.pm.api.projectdeclared.utils.ProjectIdCodeCacheUtil; +import com.hz.pm.api.projectlib.entity.ProjectApprovalAmount; import com.hz.pm.api.projectlib.entity.ProjectGovSystemReplaceInfos; import com.hz.pm.api.projectlib.handle.ProcessProgressHelper; import com.hz.pm.api.projectlib.helper.ProjectManageUtil; import com.hz.pm.api.projectlib.helper.ProjectSaveHelper; import com.hz.pm.api.projectlib.model.constant.ProjectConstant; import com.hz.pm.api.projectlib.model.dto.GovSystemReplaceInfoDTO; +import com.hz.pm.api.projectlib.model.dto.ProjectApprovalAmountDTO; import com.hz.pm.api.projectlib.model.dto.ProjectDTO; import com.hz.pm.api.projectlib.model.dto.ProjectPaymentPlanDTO; import com.hz.pm.api.projectlib.model.entity.*; @@ -147,6 +150,7 @@ public class ProjectLibManage { private final IMhProjectService mhProjectService; private final ProjectReviewManage projectReviewManage; private final IMeetingInnerProjectService meetingInnerProjectService; + private final INdProjectApprovalAmountService projectApprovalAmountService; public PageVo projectLibList(ProjectListReq req) { LambdaQueryWrapper query = ProjectManageUtil.projectQuery(req); @@ -704,6 +708,10 @@ public class ProjectLibManage { BeanUtils.copyProperties(project, retProjectDetail); 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)); + } // 查询应用 List applications = applicationService.list(projectCode, project.getVersion(), project.getIsConstruct()); diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/mapper/NdProjectApprovalAmountMapper.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/mapper/NdProjectApprovalAmountMapper.java new file mode 100644 index 0000000..d55e41f --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/mapper/NdProjectApprovalAmountMapper.java @@ -0,0 +1,16 @@ +package com.hz.pm.api.projectlib.mapper; + +import com.hz.pm.api.projectlib.entity.ProjectApprovalAmount; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author WendyYang + * @since 2024-10-09 + */ +public interface NdProjectApprovalAmountMapper extends BaseMapper { + +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/mapper/NdProjectApprovalAmountMapper.xml b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/mapper/NdProjectApprovalAmountMapper.xml new file mode 100644 index 0000000..99467ba --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/mapper/NdProjectApprovalAmountMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/dto/ProjectApprovalAmountDTO.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/dto/ProjectApprovalAmountDTO.java new file mode 100644 index 0000000..1a4e1d1 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/dto/ProjectApprovalAmountDTO.java @@ -0,0 +1,31 @@ +package com.hz.pm.api.projectlib.model.dto; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + *

+ * 项目资金下达记录 + *

+ * + * @author WendyYang + * @since 2024-10-09 + */ +@Data +public class ProjectApprovalAmountDTO { + + + @ApiModelProperty("下达资金") + private BigDecimal approvalAmount; + + @ApiModelProperty("年度") + private Integer approvalYear; + + private LocalDateTime createOn; + +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/req/SubmitAmountApprovalReq.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/req/SubmitAmountApprovalReq.java index 6f924c7..b6fe421 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/req/SubmitAmountApprovalReq.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/req/SubmitAmountApprovalReq.java @@ -25,8 +25,7 @@ public class SubmitAmountApprovalReq { @NotNull(message = "批复金额不能为空") private BigDecimal approvalAmount; - @ApiModelProperty("评审金额") - @NotNull(message = "评审金额不能为空") + @ApiModelProperty("评审总投资") private BigDecimal reviewAmount; @ApiModelProperty("资金下达附件") diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/ProjectDetailVO.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/ProjectDetailVO.java index 2d18c07..39e95c3 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/ProjectDetailVO.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/model/vo/ProjectDetailVO.java @@ -8,6 +8,7 @@ import com.hz.pm.api.meeting.entity.dto.ProjectReviewResultDTO; import com.hz.pm.api.portrait.model.vo.TagVO; import com.hz.pm.api.projectdeclared.model.vo.PurchaseFullInfoVO; import com.hz.pm.api.projectlib.model.dto.GovSystemReplaceInfoDTO; +import com.hz.pm.api.projectlib.model.dto.ProjectApprovalAmountDTO; import com.hz.pm.api.projectlib.model.dto.ProjectPaymentPlanDTO; import com.hz.pm.api.projectlib.model.enumeration.ProjectTypeNewEnum; import com.hz.pm.api.projectlib.model.enumeration.status.ProjectStatus; @@ -594,4 +595,7 @@ public class ProjectDetailVO { @ApiModelProperty("所属领域") private Integer unitStrip; + @ApiModelProperty("资金下达情况") + private List approvalAmounts; + } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/INdProjectApprovalAmountService.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/INdProjectApprovalAmountService.java new file mode 100644 index 0000000..f7143b0 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/INdProjectApprovalAmountService.java @@ -0,0 +1,36 @@ +package com.hz.pm.api.projectlib.service; + +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.IService; +import com.hz.pm.api.common.model.constant.BizConst; +import com.hz.pm.api.projectlib.entity.ProjectApprovalAmount; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author WendyYang + * @since 2024-10-09 + */ +public interface INdProjectApprovalAmountService extends IService { + + default ProjectApprovalAmount getByProjectCode(String projectCode) { + Wrapper query = Wrappers.lambdaQuery(ProjectApprovalAmount.class) + .eq(ProjectApprovalAmount::getProjectCode, projectCode) + .orderByDesc(ProjectApprovalAmount::getApprovalYear) + .last(BizConst.LIMIT_1); + return getOne(query); + } + + default List listByProjectCode(String projectCode) { + Wrapper query = Wrappers.lambdaQuery(ProjectApprovalAmount.class) + .eq(ProjectApprovalAmount::getProjectCode, projectCode) + .orderByAsc(ProjectApprovalAmount::getApprovalYear); + return list(query); + } + +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/impl/NdProjectApprovalAmountServiceImpl.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/impl/NdProjectApprovalAmountServiceImpl.java new file mode 100644 index 0000000..22af02d --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/impl/NdProjectApprovalAmountServiceImpl.java @@ -0,0 +1,20 @@ +package com.hz.pm.api.projectlib.service.impl; + +import com.hz.pm.api.projectlib.entity.ProjectApprovalAmount; +import com.hz.pm.api.projectlib.mapper.NdProjectApprovalAmountMapper; +import com.hz.pm.api.projectlib.service.INdProjectApprovalAmountService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author WendyYang + * @since 2024-10-09 + */ +@Service +public class NdProjectApprovalAmountServiceImpl extends ServiceImpl implements INdProjectApprovalAmountService { + +}