From c05f9ae08236d34fd0c05eed070652ca94d9327a Mon Sep 17 00:00:00 2001 From: hanbo <2608504783@qq.com> Date: Thu, 9 Dec 2021 18:03:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E6=9C=88=E7=BB=9F=E8=AE=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=85=B3=E8=81=94=E9=A1=B9=E7=9B=AE=E5=8F=AF=E8=A7=81?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectSettleCashFlowRepository.java | 3 ++ .../ProjectSettleCostManageRepository.java | 3 ++ .../model/ProjectSettleCostRepository.java | 3 ++ .../model/ProjectSettleIncomeRepository.java | 3 ++ .../ProjectSettleProfitMarginRepository.java | 3 ++ .../work/model/ProjectVisibleRepository.java | 5 ++++ .../work/service/StatisticsService.java | 30 ++++++++++++------- 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/main/java/cn/palmte/work/model/ProjectSettleCashFlowRepository.java b/src/main/java/cn/palmte/work/model/ProjectSettleCashFlowRepository.java index 60e8706..cf2a1f5 100644 --- a/src/main/java/cn/palmte/work/model/ProjectSettleCashFlowRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectSettleCashFlowRepository.java @@ -32,4 +32,7 @@ public interface ProjectSettleCashFlowRepository extends JpaRepository getProjectTime(); + + @Query(value = "select * from project_settle_cash_flow where project_id in ?1", nativeQuery = true) + List findAllByProjectIds(List projectIds); } diff --git a/src/main/java/cn/palmte/work/model/ProjectSettleCostManageRepository.java b/src/main/java/cn/palmte/work/model/ProjectSettleCostManageRepository.java index 68c2554..164a49b 100644 --- a/src/main/java/cn/palmte/work/model/ProjectSettleCostManageRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectSettleCostManageRepository.java @@ -35,4 +35,7 @@ public interface ProjectSettleCostManageRepository extends JpaRepository findAllByProjectIds(List projectIds); } diff --git a/src/main/java/cn/palmte/work/model/ProjectSettleCostRepository.java b/src/main/java/cn/palmte/work/model/ProjectSettleCostRepository.java index b5bdc2f..98d4264 100644 --- a/src/main/java/cn/palmte/work/model/ProjectSettleCostRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectSettleCostRepository.java @@ -35,4 +35,7 @@ public interface ProjectSettleCostRepository extends JpaRepository findAllByProjectIds(List projectIds); } diff --git a/src/main/java/cn/palmte/work/model/ProjectSettleIncomeRepository.java b/src/main/java/cn/palmte/work/model/ProjectSettleIncomeRepository.java index 0aa8d5f..b9b5ab9 100644 --- a/src/main/java/cn/palmte/work/model/ProjectSettleIncomeRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectSettleIncomeRepository.java @@ -41,4 +41,7 @@ public interface ProjectSettleIncomeRepository extends JpaRepository findAllByProjectIds(List projectInt); } diff --git a/src/main/java/cn/palmte/work/model/ProjectSettleProfitMarginRepository.java b/src/main/java/cn/palmte/work/model/ProjectSettleProfitMarginRepository.java index 9dae9ee..13f8a55 100644 --- a/src/main/java/cn/palmte/work/model/ProjectSettleProfitMarginRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectSettleProfitMarginRepository.java @@ -25,4 +25,7 @@ public interface ProjectSettleProfitMarginRepository extends JpaRepository findAllByProjectsAndTime(List ids, String time); + + @Query(value = "select * from project_settle_profit_margin where project_id in ?1", nativeQuery = true) + List findAllByProjectIds(List projectIds); } diff --git a/src/main/java/cn/palmte/work/model/ProjectVisibleRepository.java b/src/main/java/cn/palmte/work/model/ProjectVisibleRepository.java index b7d0406..25c4d15 100644 --- a/src/main/java/cn/palmte/work/model/ProjectVisibleRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectVisibleRepository.java @@ -2,10 +2,15 @@ package cn.palmte.work.model; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; public interface ProjectVisibleRepository extends JpaRepository { List findAllByProjectIdEqualsAndTypeEquals(int projectId, int type); List findAllByProjectIdEquals(int projectId); + + @Query(value = "SELECT project_id FROM project_visible WHERE type = ?1 and tid = ?2", nativeQuery = true) + List findProjectIdByTypeAndTid(int type,int tid); + } diff --git a/src/main/java/cn/palmte/work/service/StatisticsService.java b/src/main/java/cn/palmte/work/service/StatisticsService.java index ed68ae0..31471fd 100644 --- a/src/main/java/cn/palmte/work/service/StatisticsService.java +++ b/src/main/java/cn/palmte/work/service/StatisticsService.java @@ -5,6 +5,7 @@ import cn.palmte.work.bean.PrimaryIndicatorBean; import cn.palmte.work.bean.ProfitAndLossBean; import cn.palmte.work.bean.StatisticsBean; import cn.palmte.work.model.*; +import cn.palmte.work.utils.InterfaceUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import top.jfunc.common.utils.CollectionUtil; @@ -43,6 +44,9 @@ public class StatisticsService { @Autowired private ProjectSettleProfitMarginRepository projectSettleProfitMarginRepository; + @Autowired + private ProjectVisibleRepository projectVisibleRepository; + /** * 分月项目统计 获取主要指标数据、损益表 * @@ -62,8 +66,12 @@ public class StatisticsService { profitAndLossBeanExclude.setTitle("预算金额(不含税)"); include.setTitle("预算金额(含税)"); exclude.setTitle("预算金额(不含税)"); + + int adminId = InterfaceUtil.getAdminId(); + List projectIds = projectVisibleRepository.findProjectIdByTypeAndTid(ProjectVisible.TYPE_USER, adminId); + //收入数据 - List allIncome = projectBudgetIncomeRepository.findAll(); + List allIncome = projectBudgetIncomeRepository.findAllByProjectIds(projectIds); if (CollectionUtil.isNotEmpty(allIncome)) { BigDecimal deviceIncomeTaxIncludeSum = allIncome.stream().filter(d -> d.getType() == ProjectBudgetIncome.TYPE_DEVICE).map(ProjectBudgetIncome::getIncomeTaxInclude).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal engineerIncomeTaxIncludeSum = allIncome.stream().filter(d -> d.getType() == ProjectBudgetIncome.TYPE_ENGINEER).map(ProjectBudgetIncome::getIncomeTaxInclude).reduce(BigDecimal.ZERO, BigDecimal::add); @@ -88,7 +96,7 @@ public class StatisticsService { } //成本数据 - List allCost = projectBudgetCostRepository.findAll(); + List allCost = projectBudgetCostRepository.findAllByProjectIds(projectIds); if (CollectionUtil.isNotEmpty(allCost)) { BigDecimal deviceCostTaxIncludeSum = allCost.stream().filter(d -> d.getType() == ProjectBudgetCost.TYPE_DEVICE).map(ProjectBudgetCost::getCostTaxInclude).reduce(BigDecimal.ZERO, BigDecimal::add); @@ -133,7 +141,7 @@ public class StatisticsService { } //管理成本数据 - List allCostManage = projectBudgetCostManageRepository.findAll(); + List allCostManage = projectBudgetCostManageRepository.findAllByProjectIds(projectIds); if (CollectionUtil.isNotEmpty(allCostManage)) { BigDecimal expropriationSum = allCostManage.stream().filter(d -> d.getType() == ProjectBudgetCostManage.TYPE_EXPROPRIATION).map(ProjectBudgetCostManage::getCostTaxExclude).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal companyManageSum = allCostManage.stream().filter(d -> d.getType() == ProjectBudgetCostManage.TYPE_COMPANY_MANAGE).map(ProjectBudgetCostManage::getCostTaxExclude).reduce(BigDecimal.ZERO, BigDecimal::add); @@ -155,7 +163,7 @@ public class StatisticsService { allSettle.setTitle("实际累计(不含税)"); allProfitAndLoss.setTitle("实际累计(不含税)"); - List allSettleIncome = projectSettleIncomeRepository.findAll(); + List allSettleIncome = projectSettleIncomeRepository.findAllByProjectIds(projectIds); if (CollectionUtil.isNotEmpty(allSettleIncome)) { BigDecimal incomeDeviceAll = allSettleIncome.stream().filter(d -> d.getType() == ProjectSettleIncome.TYPE_DEVICE).map(ProjectSettleIncome::getIncomeTaxExclude).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal incomeEngineerAll = allSettleIncome.stream().filter(d -> d.getType() == ProjectSettleIncome.TYPE_ENGINEER).map(ProjectSettleIncome::getIncomeTaxExclude).reduce(BigDecimal.ZERO, BigDecimal::add); @@ -169,7 +177,7 @@ public class StatisticsService { allProfitAndLoss.setIncome(incomeExclude); } - List allSettleCost = projectSettleCostRepository.findAll(); + List allSettleCost = projectSettleCostRepository.findAllByProjectIds(projectIds); if (CollectionUtil.isNotEmpty(allSettleCost)) { BigDecimal costDeviceAll = allSettleCost.stream().filter(d -> d.getType() == ProjectSettleCost.TYPE_DEVICE).map(ProjectSettleCost::getCostTaxExclude).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal costBuildingAll = allSettleCost.stream().filter(d -> d.getType() == ProjectSettleCost.TYPE_BUILDING).map(ProjectSettleCost::getCostTaxExclude).reduce(BigDecimal.ZERO, BigDecimal::add); @@ -192,7 +200,7 @@ public class StatisticsService { } - List allSettleCostManage = projectSettleCostManageRepository.findAll(); + List allSettleCostManage = projectSettleCostManageRepository.findAllByProjectIds(projectIds); if (CollectionUtil.isNotEmpty(allSettleCostManage)) { BigDecimal expropriationAll = allSettleCostManage.stream().filter(d -> d.getType() == ProjectSettleCostManage.TYPE_EXPROPRIATION).map(ProjectSettleCostManage::getCostTaxExclude).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal companyManageAll = allSettleCostManage.stream().filter(d -> d.getType() == ProjectSettleCostManage.TYPE_COMPANY_MANAGE).map(ProjectSettleCostManage::getCostTaxExclude).reduce(BigDecimal.ZERO, BigDecimal::add); @@ -204,7 +212,7 @@ public class StatisticsService { allProfitAndLoss.setCompanyManage(companyManageAll); } - List profitMargins = projectSettleProfitMarginRepository.findAll(); + List profitMargins = projectSettleProfitMarginRepository.findAllByProjectIds(projectIds); if(CollectionUtil.isNotEmpty(profitMargins)){ BigDecimal typeGrossProfit = profitMargins.stream().filter(d -> d.getType() == ProjectSettleProfitMargin.TYPE_GROSS_PROFIT).map(ProjectSettleProfitMargin::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal typeContributionProfit = profitMargins.stream().filter(d -> d.getType() == ProjectSettleProfitMargin.TYPE_CONTRIBUTION_PROFIT).map(ProjectSettleProfitMargin::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); @@ -279,7 +287,7 @@ public class StatisticsService { } } - List cashFlow = getCashFlow(); + List cashFlow = getCashFlow(projectIds); statisticsBean.setPrimaryIndicatorBeanList(list); statisticsBean.setProfitAndLossBeanList(profitAndLossList); @@ -292,12 +300,12 @@ public class StatisticsService { * * @return */ - public List getCashFlow() { + public List getCashFlow(List projectIds) { List list = new ArrayList<>(); CashFlowStatisticsBean cashFlowStatisticsBean = new CashFlowStatisticsBean(); cashFlowStatisticsBean.setTitle("预算金额"); - List cashFlows = projectBudgetPlanDetailRepository.findAll(); + List cashFlows = projectBudgetPlanDetailRepository.findAllByProjectIds(projectIds); BigDecimal saleIncome = cashFlows.stream().map(ProjectBudgetPlanDetail::getSaleIncome).reduce(BigDecimal.ZERO, BigDecimal::add); cashFlowStatisticsBean.setSaleIncomeCash(saleIncome); @@ -327,7 +335,7 @@ public class StatisticsService { list.add(cashFlowStatisticsBean); List projectTime = projectSettleCashFlowRepository.getProjectTime(); - List all = projectSettleCashFlowRepository.findAll(); + List all = projectSettleCashFlowRepository.findAllByProjectIds(projectIds); CashFlowStatisticsBean cashFlowStatisticsAll = new CashFlowStatisticsBean(); cashFlowStatisticsAll.setTitle("实际累计");