Browse Source

修改首页总和接口(/industry_oveview/industry_oveview/list)计算错误问题以及添加年份列表数据

ljx 1 month ago
parent
commit
fb788bce66

+ 16 - 0
enteprise-admin/src/main/java/com/enteprise/industry_oveview/domain/IndustryOverview.java

@@ -64,6 +64,11 @@ public class IndustryOverview extends BaseEntity
     @Excel(name = "实缴税金")
     private Long paidTaxSum;
 
+    /**
+     * 年份列表
+     * @param id
+     */
+    private List<Integer> years;
 
     public void setId(Long id) 
     {
@@ -174,6 +179,17 @@ public class IndustryOverview extends BaseEntity
         return paidTaxSum;
     }
 
+    public void setYear(int year) {
+        this.year = year;
+    }
+
+    public List<Integer> getYears() {
+        return years;
+    }
+
+    public void setYears(List<Integer> years) {
+        this.years = years;
+    }
 
     @Override
     public String toString() {

+ 41 - 3
enteprise-admin/src/main/java/com/enteprise/industry_oveview/service/impl/IndustryOverviewServiceImpl.java

@@ -1,5 +1,7 @@
 package com.enteprise.industry_oveview.service.impl;
 
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -48,10 +50,43 @@ public class IndustryOverviewServiceImpl implements IIndustryOverviewService
     @Override
     public List<IndustryOverview> selectIndustryOverviewList(IndustryOverview industryOverview)
     {
-        List<IndustryOverview> list;
+        List<IndustryOverview> list = new ArrayList<>();;
         if (industryOverview.getYear() == 0){
             //求总和
-            list = industryOverviewMapper.countAllIndustryOverview().stream().limit(1).collect(Collectors.toList());
+            IndustryOverview latestData = null;
+            List<Integer> years = new ArrayList<>();;
+            long sumPowerConsume = 0L;
+            long sumEnergyConsume = 0L;
+            long sumFunding = 0L;
+            long sumTotalIndustrialValue = 0L;
+            long sumTaxableIncome = 0L;
+            long sumPaidTax = 0L;
+            List<IndustryOverview> industryOverviews = industryOverviewMapper.selectIndustryOverviewList(industryOverview);
+            for (IndustryOverview item : industryOverviews){
+                //获取最新年份实体
+                if (latestData  == null || item.getYear() > latestData .getYear()){
+                    latestData  = item;
+                }
+                //统计数据
+                sumPowerConsume += item.getPowerConsumeSum();
+                sumEnergyConsume += item.getEnergyConsumeSum();
+                sumFunding += item.getFundingSum();
+                sumTotalIndustrialValue += item.getTotalIndustrialValueSum();
+                sumTaxableIncome += item.getTaxableIncomeSum();
+                sumPaidTax += item.getPaidTaxSum();
+                years.add(item.getYear());
+                // 替换最新数据
+                if (latestData != null) {
+                    latestData.setYears(years);
+                    latestData.setPowerConsumeSum(sumPowerConsume);
+                    latestData.setEnergyConsumeSum(sumEnergyConsume);
+                    latestData.setFundingSum(sumFunding);
+                    latestData.setTotalIndustrialValueSum(sumTotalIndustrialValue);
+                    latestData.setTaxableIncomeSum(sumTaxableIncome);
+                    latestData.setPaidTaxSum(sumPaidTax);
+                }
+            }
+            list.add(latestData);
         }else {
             //求某年
             list  = industryOverviewMapper.selectIndustryOverviewList(industryOverview);
@@ -77,7 +112,10 @@ public class IndustryOverviewServiceImpl implements IIndustryOverviewService
 
     @Override
     public List<IndustryCount> countAllIndustries() {
-        return industryOverviewMapper.selectIndustryCount();
+        List<IndustryCount> industryCounts = industryOverviewMapper.selectIndustryCount();
+        //数量从小到大排
+        return industryCounts.stream().sorted(Comparator.comparingInt(IndustryCount::getNumber))
+                .collect(Collectors.toList());
     }
 
     /**

+ 1 - 0
enteprise-admin/src/main/resources/mapper/industry_oveview/IndustryOverviewMapper.xml

@@ -38,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="taxableIncomeSum != null "> and taxable_income_sum = #{taxableIncomeSum}</if>
             <if test="paidTaxSum != null "> and paid_tax_sum = #{paidTaxSum}</if>
         </where>
+        order by year
     </select>
     
     <select id="selectIndustryOverviewById" parameterType="Long" resultMap="IndustryOverviewResult">