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 836ae0f..fecd1f1 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,6 +24,10 @@ public class DecimalUtil { private DecimalUtil() { } + public static boolean notNullAndGtZero(BigDecimal num) { + return num != null && num.compareTo(BigDecimal.ZERO) > 0; + } + @SafeVarargs public static BigDecimal sum(Collection objs, Function... functions) { if (CollUtil.isEmpty(objs) || ArrayUtil.isEmpty(functions)) { 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 4256902..c711c14 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 @@ -2,12 +2,12 @@ package com.hz.pm.api.projectlib.manage; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.NumberUtil; 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.helper.UserInfoHelper; +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.projectlib.helper.ProjectManageUtil; @@ -16,8 +16,6 @@ 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.AnnualPlanListItemVO; -import com.hz.pm.api.projectlib.model.vo.AnnualPlanProgressStatisticsVO; import com.hz.pm.api.projectlib.model.vo.ProjectLibListItemVO; import com.hz.pm.api.projectlib.service.IProjectService; import com.hz.pm.api.user.helper.MhUnitCache; @@ -29,7 +27,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.math.BigDecimal; import java.util.List; import java.util.Optional; @@ -98,15 +95,7 @@ public class AmountApprovalManage { ProjectManageUtil.projectBaseQuery(query); query.eq(Project::getNewest, Boolean.TRUE) .ne(Project::getStage, ProjectStatus.STOPPED.getCode()); - if (req.getIsAmountApproval() != null) { - if (Boolean.TRUE.equals(req.getIsAmountApproval())) { - query.gt(Project::getApprovalAmount, 0) - .isNotNull(Project::getApprovalAmount); - } else { - query.and(q -> q.isNull(Project::getApprovalAmount) - .or(q1 -> q1.le(Project::getApprovalAmount, 0))); - } - } + buildAmountApprovalFilter(req.getIsAmountApproval(), query); Page page = projectService.page(req.page(), query); long total = page.getTotal(); if (total == 0) { @@ -131,6 +120,18 @@ public class AmountApprovalManage { return PageVo.of(records, total); } + private static void buildAmountApprovalFilter(Boolean isAmountApproval, LambdaQueryWrapper query) { + if (isAmountApproval != null) { + if (Boolean.TRUE.equals(isAmountApproval)) { + query.gt(Project::getApprovalAmount, 0) + .isNotNull(Project::getApprovalAmount); + } else { + query.and(q -> q.isNull(Project::getApprovalAmount) + .or(q1 -> q1.le(Project::getApprovalAmount, 0))); + } + } + } + public AmountApprovalProgressStatisticsVO progressStatistics(ProjectListReq req) { LambdaQueryWrapper query = ProjectManageUtil.initQuery(); UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); @@ -141,20 +142,11 @@ public class AmountApprovalManage { ProjectManageUtil.projectBaseQuery(query); query.eq(Project::getNewest, Boolean.TRUE) .ne(Project::getStage, ProjectStatus.STOPPED.getCode()); - if (req.getIsAmountApproval() != null) { - if (Boolean.TRUE.equals(req.getIsAmountApproval())) { - query.gt(Project::getApprovalAmount, 0) - .isNotNull(Project::getApprovalAmount); - } else { - query.and(q -> q.isNull(Project::getApprovalAmount) - .or(q1 -> q1.le(Project::getApprovalAmount, 0))); - } - } + buildAmountApprovalFilter(req.getIsAmountApproval(), query); List page = projectService.list(query); AmountApprovalProgressStatisticsVO stat = new AmountApprovalProgressStatisticsVO(); stat.setTotalCount(page.size()); - stat.setApprovalCount(CollUtil.count(page, w -> w.getApprovalAmount() != null - && NumberUtil.isGreater(w.getApprovalAmount(), BigDecimal.ZERO))); + stat.setApprovalCount(CollUtil.count(page, w -> DecimalUtil.notNullAndGtZero(w.getApprovalAmount()))); stat.setUnApprovalCount(stat.getTotalCount() - stat.getApprovalCount()); return stat; }