Explorar el Código

ljx:新增同比增速分析获取接口

ljx hace 1 mes
padre
commit
f4224ad813

+ 2 - 0
enteprise-admin/src/main/java/com/enteprise/base_data_month/mapper/EnterpriseBaseDataMonthMapper.java

@@ -2,6 +2,7 @@ package com.enteprise.base_data_month.mapper;
 
 import java.util.List;
 import com.enteprise.base_data_month.domain.EnterpriseBaseDataMonth;
+import org.apache.ibatis.annotations.Mapper;
 
 /**
  * base_data_monthMapper接口
@@ -9,6 +10,7 @@ import com.enteprise.base_data_month.domain.EnterpriseBaseDataMonth;
  * @author ruoyi
  * @date 2024-08-30
  */
+@Mapper
 public interface EnterpriseBaseDataMonthMapper 
 {
     /**

+ 2 - 0
enteprise-admin/src/main/java/com/enteprise/base_data_year/mapper/EnterpriseBaseDataYearMapper.java

@@ -2,6 +2,7 @@ package com.enteprise.base_data_year.mapper;
 
 import java.util.List;
 import com.enteprise.base_data_year.domain.EnterpriseBaseDataYear;
+import org.apache.ibatis.annotations.Mapper;
 
 /**
  * base_data_yearMapper接口
@@ -9,6 +10,7 @@ import com.enteprise.base_data_year.domain.EnterpriseBaseDataYear;
  * @author ruoyi
  * @date 2024-08-30
  */
+@Mapper
 public interface EnterpriseBaseDataYearMapper 
 {
     /**

+ 2 - 0
enteprise-admin/src/main/java/com/enteprise/enterprise/mapper/EnterpriseMapper.java

@@ -3,6 +3,7 @@ package com.enteprise.enterprise.mapper;
 import java.util.List;
 import com.enteprise.enterprise.domain.Enterprise;
 import com.enteprise.enterprise.dto.EnterpriseDto;
+import org.apache.ibatis.annotations.Mapper;
 
 /**
  * enterpriseMapper接口
@@ -10,6 +11,7 @@ import com.enteprise.enterprise.dto.EnterpriseDto;
  * @author ruoyi
  * @date 2024-08-30
  */
+@Mapper
 public interface EnterpriseMapper 
 {
     /**

+ 30 - 1
enteprise-admin/src/main/java/com/enteprise/growthRate/controller/GrowthRateController.java

@@ -1,4 +1,33 @@
 package com.enteprise.growthRate.controller;
 
-public class GrowthRateController {
+import com.enteprise.common.core.controller.BaseController;
+import com.enteprise.common.core.page.TableDataInfo;
+import com.enteprise.growthRate.domain.GrowthRate;
+import com.enteprise.growthRate.domain.dto.GrowthRateDto;
+import com.enteprise.growthRate.service.IGrowthRateService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/growthRate/growthRate")
+public class GrowthRateController extends BaseController {
+    @Autowired
+    private IGrowthRateService growthRateService;
+
+    /**
+     * 查询enterprise列表
+     */
+    @PreAuthorize("@ss.hasPermi('growthRate:growthRate:list')")
+    @GetMapping("/analysis")
+    public TableDataInfo analysisGrowthRate(GrowthRate growthRate)
+    {
+        startPage();
+        List<GrowthRateDto> list = growthRateService.analysisGrowthRate(growthRate);
+        return getDataTable(list);
+    }
 }

+ 84 - 12
enteprise-admin/src/main/java/com/enteprise/growthRate/service/impl/GrowthRateServiceImpl.java

@@ -2,38 +2,49 @@ package com.enteprise.growthRate.service.impl;
 
 import com.enteprise.base_data_month.domain.EnterpriseBaseDataMonth;
 import com.enteprise.base_data_month.mapper.EnterpriseBaseDataMonthMapper;
+import com.enteprise.base_data_year.domain.EnterpriseBaseDataYear;
+import com.enteprise.base_data_year.mapper.EnterpriseBaseDataYearMapper;
 import com.enteprise.enterprise.domain.Enterprise;
 import com.enteprise.enterprise.dto.EnterpriseDto;
 import com.enteprise.enterprise.mapper.EnterpriseMapper;
 import com.enteprise.growthRate.domain.GrowthRate;
 import com.enteprise.growthRate.domain.dto.GrowthRateDto;
 import com.enteprise.growthRate.service.IGrowthRateService;
+import com.enteprise.season.domain.EnterpriseBaseDataSeason;
+import com.enteprise.season.mapper.EnterpriseBaseDataSeasonMapper;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
 
+@Service
 public class GrowthRateServiceImpl implements IGrowthRateService {
     @Autowired
     private EnterpriseMapper enterpriseMapper;
     @Autowired
     private EnterpriseBaseDataMonthMapper enterpriseBaseDataMonthMapper;
+    @Autowired
+    private EnterpriseBaseDataSeasonMapper enterpriseBaseDataSeasonMapper;
+    @Autowired
+    private EnterpriseBaseDataYearMapper enterpriseBaseDataYearMapper;
     @Override
     public List<GrowthRateDto> analysisGrowthRate(GrowthRate growthRate) {
         String analysisType = growthRate.getAnalysisType();
         int startMonth = growthRate.getStartMonth();
         int endMonth = growthRate.getEndMonth();
         int year = growthRate.getYear();
+        int season = growthRate.getSeason();
+        //通过分类、行业代码过滤企业列表
+        Enterprise enterprise = new Enterprise();
+        enterprise.setCode(growthRate.getCode());
+        enterprise.setTypeNum(growthRate.getTypeNum());
+        List<EnterpriseDto> enterpriseDtos = enterpriseMapper.selectAllWithType(enterprise);
         if (analysisType.isEmpty() || year == 0) {
             return null;
         } else {
             ArrayList<GrowthRateDto> list = new ArrayList<>();
             if (startMonth != 0 && endMonth != 0) {
-                //通过分类、行业代码过滤企业列表
-                Enterprise enterprise = new Enterprise();
-                enterprise.setCode(growthRate.getCode());
-                enterprise.setTypeNum(growthRate.getTypeNum());
-                List<EnterpriseDto> enterpriseDtos = enterpriseMapper.selectAllWithType(enterprise);
                 //每个企业从开始月份循环相加到结束月份
                 List<Integer> monthRange = getMonthRange(startMonth, endMonth);
                 for (EnterpriseDto enterpriseDto : enterpriseDtos){
@@ -46,17 +57,15 @@ public class GrowthRateServiceImpl implements IGrowthRateService {
                         dataMonth.setMonth(String.valueOf(nowMonth));
                         dataMonth.setYear(String.valueOf(year));
                         List<EnterpriseBaseDataMonth> dataMonths = enterpriseBaseDataMonthMapper.selectEnterpriseBaseDataMonthList(dataMonth);
-                        //重复操作获取去年对应的月份数据
+                        //月度指标获取
                         dataMonth.setYear(String.valueOf(year-1));
                         List<EnterpriseBaseDataMonth> oldDataMonths = enterpriseBaseDataMonthMapper.selectEnterpriseBaseDataMonthList(dataMonth);
-                        if (analysisType.equals("totalIndustrialValue")) {
+                        if (analysisType.equals("totalIndustrialValue")&&  !dataMonths.isEmpty() &&!oldDataMonths.isEmpty()) {
                             sum += dataMonths.get(0).getTotalIndustrialValue();
                             oldSum += oldDataMonths.get(0).getTotalIndustrialValue();
-                        }else if (analysisType.equals("powerConsume")){
+                        }else if (analysisType.equals("powerConsume")&&  !dataMonths.isEmpty() &&!oldDataMonths.isEmpty()){
                             sum += dataMonths.get(0).getPowerConsume();
                             oldSum += oldDataMonths.get(0).getPowerConsume();
-                        }else {
-
                         }
                     }
                     //计算同比增速:(今年-去年)/去年
@@ -68,14 +77,77 @@ public class GrowthRateServiceImpl implements IGrowthRateService {
                     growthRateDto.setLocation(enterpriseDto.getLocation());
                     list.add(growthRateDto);
                 }
-
-
+                return list;
+            }
+            if (season != 0){
+                //循环企业列表计算季度指标
+                for (EnterpriseDto dto : enterpriseDtos){
+                    EnterpriseBaseDataSeason dataSeason = new EnterpriseBaseDataSeason();
+                    Long sum = 0L;
+                    Long oldSum = 0L;
+                    dataSeason.setEnterpriseName(dto.getEnterpriseName());
+                    dataSeason.setSeason(String.valueOf(season));
+                    dataSeason.setYear(String.valueOf(year));
+                    //季度指标获取
+                    List<EnterpriseBaseDataSeason> dataSeasons = enterpriseBaseDataSeasonMapper.selectEnterpriseBaseDataSeasonList(dataSeason);
+                    dataSeason.setYear(String.valueOf(year - 1));
+                    List<EnterpriseBaseDataSeason> oldDataSeasons = enterpriseBaseDataSeasonMapper.selectEnterpriseBaseDataSeasonList(dataSeason);
+                    if (analysisType.equals("taxableIncome") &&  !dataSeasons.isEmpty() &&!oldDataSeasons.isEmpty()) {
+                        sum = dataSeasons.get(0).getTaxableIncome();
+                        oldSum = oldDataSeasons.get(0).getTaxableIncome();
+                    }else if (analysisType.equals("paidTax") &&  !dataSeasons.isEmpty() &&!oldDataSeasons.isEmpty()){
+                        sum = dataSeasons.get(0).getPaidTax();
+                        oldSum = oldDataSeasons.get(0).getPaidTax();
+                    }
+                    //计算同比增速:(今年-去年)/去年
+                    double rate = (double) (sum - oldSum) / oldSum;
+                    //初始化企业并把该企业的同比增速和其他数据放入list中
+                    GrowthRateDto growthRateDto = new GrowthRateDto();
+                    growthRateDto.setRate(rate);
+                    growthRateDto.setEnterpriseName(dto.getEnterpriseName());
+                    growthRateDto.setLocation(dto.getLocation());
+                    list.add(growthRateDto);
+                }
+                return list;
+            }
+            //循环企业列表计算年度指标
+            for (EnterpriseDto dto : enterpriseDtos){
+                EnterpriseBaseDataYear dataYear = new EnterpriseBaseDataYear();
+                Long sum = 0L;
+                Long oldSum = 0L;
+                dataYear.setEnterpriseName(dto.getEnterpriseName());
+                dataYear.setYear(String.valueOf(year));
+                //季度指标获取
+                List<EnterpriseBaseDataYear> dataYears = enterpriseBaseDataYearMapper.selectEnterpriseBaseDataYearList(dataYear);
+                dataYear.setYear(String.valueOf(year - 1));
+                List<EnterpriseBaseDataYear> oldDataYears = enterpriseBaseDataYearMapper.selectEnterpriseBaseDataYearList(dataYear);
+                if (analysisType.equals("energyConsume") &&  !dataYears.isEmpty() &&!oldDataYears.isEmpty()) {
+                    sum = dataYears.get(0).getEnergyConsume();
+                    oldSum = oldDataYears.get(0).getEnergyConsume();
+                }else if (analysisType.equals("funding") &&  !dataYears.isEmpty() &&!oldDataYears.isEmpty()){
+                    sum = dataYears.get(0).getFunding();
+                    oldSum = oldDataYears.get(0).getFunding();
+                }
+                //计算同比增速:(今年-去年)/去年
+                double rate = (double) (sum - oldSum) / oldSum;
+                //初始化企业并把该企业的同比增速和其他数据放入list中
+                GrowthRateDto growthRateDto = new GrowthRateDto();
+                growthRateDto.setRate(rate);
+                growthRateDto.setEnterpriseName(dto.getEnterpriseName());
+                growthRateDto.setLocation(dto.getLocation());
+                list.add(growthRateDto);
             }
             return list;
         }
     }
 
 
+    /**
+     * 获取两个月份之间的所有月份
+     * @param start
+     * @param end
+     * @return
+     */
     public static List<Integer> getMonthRange(int start, int end) {
         // 创建一个列表以存储结果
         List<Integer> months = new ArrayList<>();

+ 2 - 0
enteprise-admin/src/main/java/com/enteprise/season/mapper/EnterpriseBaseDataSeasonMapper.java

@@ -2,6 +2,7 @@ package com.enteprise.season.mapper;
 
 import java.util.List;
 import com.enteprise.season.domain.EnterpriseBaseDataSeason;
+import org.apache.ibatis.annotations.Mapper;
 
 /**
  * seasonMapper接口
@@ -9,6 +10,7 @@ import com.enteprise.season.domain.EnterpriseBaseDataSeason;
  * @author ruoyi
  * @date 2024-09-26
  */
+@Mapper
 public interface EnterpriseBaseDataSeasonMapper 
 {
     /**