Ver Fonte

ljx:新增同比增速匹配接口

ljx há 1 mês atrás
pai
commit
13d87b729b

+ 4 - 6
enteprise-admin/src/main/java/com/enteprise/growthRate/controller/GrowthRateController.java

@@ -7,9 +7,7 @@ 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 org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -20,11 +18,11 @@ public class GrowthRateController extends BaseController {
     private IGrowthRateService growthRateService;
 
     /**
-     * 查询enterprise列表
+     * 分析growthRate列表
      */
     @PreAuthorize("@ss.hasPermi('growthRate:growthRate:list')")
-    @GetMapping("/analysis")
-    public TableDataInfo analysisGrowthRate(GrowthRate growthRate)
+    @PostMapping("/analysis")
+    public TableDataInfo analysisGrowthRate(@RequestBody GrowthRate growthRate)
     {
         startPage();
         List<GrowthRateDto> list = growthRateService.analysisGrowthRate(growthRate);

+ 27 - 42
enteprise-admin/src/main/java/com/enteprise/growthRate/service/impl/GrowthRateServiceImpl.java

@@ -18,6 +18,9 @@ import org.springframework.stereotype.Service;
 import java.util.ArrayList;
 import java.util.List;
 
+import static com.enteprise.util.CommonUtil.getRange;
+
+
 @Service
 public class GrowthRateServiceImpl implements IGrowthRateService {
     @Autowired
@@ -46,7 +49,7 @@ public class GrowthRateServiceImpl implements IGrowthRateService {
             ArrayList<GrowthRateDto> list = new ArrayList<>();
             if (startMonth != 0 && endMonth != 0) {
                 //每个企业从开始月份循环相加到结束月份
-                List<Integer> monthRange = getMonthRange(startMonth, endMonth);
+                List<Integer> monthRange = getRange(startMonth, endMonth);
                 for (EnterpriseDto enterpriseDto : enterpriseDtos){
                     double sum = 0;
                     double oldSum = 0;
@@ -71,11 +74,13 @@ public class GrowthRateServiceImpl implements IGrowthRateService {
                     //计算同比增速:(今年-去年)/去年
                     double rate = (sum - oldSum) / oldSum;
                     //初始化企业并把该企业的同比增速和其他数据放入list中
-                    GrowthRateDto growthRateDto = new GrowthRateDto();
-                    growthRateDto.setRate(rate);
-                    growthRateDto.setEnterpriseName(enterpriseDto.getEnterpriseName());
-                    growthRateDto.setLocation(enterpriseDto.getLocation());
-                    list.add(growthRateDto);
+                    if (rate != 0 ) {
+                        GrowthRateDto growthRateDto = new GrowthRateDto();
+                        growthRateDto.setRate(rate);
+                        growthRateDto.setEnterpriseName(enterpriseDto.getEnterpriseName());
+                        growthRateDto.setLocation(enterpriseDto.getLocation());
+                        list.add(growthRateDto);
+                    }
                 }
                 return list;
             }
@@ -102,11 +107,13 @@ public class GrowthRateServiceImpl implements IGrowthRateService {
                     //计算同比增速:(今年-去年)/去年
                     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);
+                    if (rate != 0) {
+                        GrowthRateDto growthRateDto = new GrowthRateDto();
+                        growthRateDto.setRate(rate);
+                        growthRateDto.setEnterpriseName(dto.getEnterpriseName());
+                        growthRateDto.setLocation(dto.getLocation());
+                        list.add(growthRateDto);
+                    }
                 }
                 return list;
             }
@@ -117,7 +124,7 @@ public class GrowthRateServiceImpl implements IGrowthRateService {
                 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);
@@ -130,38 +137,16 @@ public class GrowthRateServiceImpl implements IGrowthRateService {
                 }
                 //计算同比增速:(今年-去年)/去年
                 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);
+                if (rate != 0 ) {
+                    //初始化企业并把该企业的同比增速和其他数据放入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<>();
-
-        // 确定区间的起始和结束值
-        int min = Math.min(start, end);
-        int max = Math.max(start, end);
-
-        // 使用循环将范围内的所有值添加到列表中
-        for (int i = min; i <= max; i++) {
-            months.add(i);
-        }
-
-        return months;
-    }
-
 }

+ 32 - 0
enteprise-admin/src/main/java/com/enteprise/matchAnalysis/controller/MatchController.java

@@ -0,0 +1,32 @@
+package com.enteprise.matchAnalysis.controller;
+
+import com.enteprise.common.core.controller.BaseController;
+import com.enteprise.common.core.page.TableDataInfo;
+import com.enteprise.matchAnalysis.domain.MatchAna;
+import com.enteprise.matchAnalysis.domain.dto.MatchDto;
+import com.enteprise.matchAnalysis.service.IMatchService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+
+@RestController
+@RequestMapping("/match/match")
+public class MatchController extends BaseController {
+    @Autowired
+    private IMatchService matchService;
+
+    @PreAuthorize("@ss.hasPermi('match:match:list')")
+    @PostMapping("/list")
+    public TableDataInfo analysisGrowthRate(@RequestBody MatchAna matchAna)
+    {
+        startPage();
+        List<MatchDto> list = matchService.matchAnalysisList(matchAna);
+        return getDataTable(list);
+    }
+}

+ 94 - 0
enteprise-admin/src/main/java/com/enteprise/matchAnalysis/domain/MatchAna.java

@@ -0,0 +1,94 @@
+package com.enteprise.matchAnalysis.domain;
+
+public class MatchAna {
+    //评估指标
+    private String dataKey;
+    //行业代码
+    private String code;
+    //企业编码
+    private String typeNum;
+    //阈值
+    private double threshold;
+    private int year;
+    //用电
+    private int elecStartMonth;
+    private int elecEndMonth;
+
+
+    //用人
+    private int manStartSeason;
+    private int manEndSeason;
+
+    public String getDataKey() {
+        return dataKey;
+    }
+
+    public void setDataKey(String dataKey) {
+        this.dataKey = dataKey;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getTypeNum() {
+        return typeNum;
+    }
+
+    public void setTypeNum(String typeNum) {
+        this.typeNum = typeNum;
+    }
+
+    public double getThreshold() {
+        return threshold;
+    }
+
+    public void setThreshold(double threshold) {
+        this.threshold = threshold;
+    }
+
+    public int getYear() {
+        return year;
+    }
+
+    public void setYear(int year) {
+        this.year = year;
+    }
+
+    public int getElecStartMonth() {
+        return elecStartMonth;
+    }
+
+    public void setElecStartMonth(int elecStartMonth) {
+        this.elecStartMonth = elecStartMonth;
+    }
+
+    public int getElecEndMonth() {
+        return elecEndMonth;
+    }
+
+    public void setElecEndMonth(int elecEndMonth) {
+        this.elecEndMonth = elecEndMonth;
+    }
+
+
+    public int getManStartSeason() {
+        return manStartSeason;
+    }
+
+    public void setManStartSeason(int manStartSeason) {
+        this.manStartSeason = manStartSeason;
+    }
+
+    public int getManEndSeason() {
+        return manEndSeason;
+    }
+
+    public void setManEndSeason(int manEndSeason) {
+        this.manEndSeason = manEndSeason;
+    }
+}

+ 74 - 0
enteprise-admin/src/main/java/com/enteprise/matchAnalysis/domain/dto/MatchDto.java

@@ -0,0 +1,74 @@
+package com.enteprise.matchAnalysis.domain.dto;
+
+import com.enteprise.common.annotation.Excel;
+
+public class MatchDto {
+    private String enterpriseName;
+
+    private double trueThreshold;
+
+    private String location;
+
+    /** 行业代码 */
+    private String code;
+
+    private String typeNum;
+    private String typeName;
+
+    public MatchDto(String enterpriseName, double trueThreshold, String location, String code, String typeNum, String typeName) {
+        this.enterpriseName = enterpriseName;
+        this.trueThreshold = trueThreshold;
+        this.location = location;
+        this.code = code;
+        this.typeNum = typeNum;
+        this.typeName = typeName;
+    }
+
+    public String getEnterpriseName() {
+        return enterpriseName;
+    }
+
+    public void setEnterpriseName(String enterpriseName) {
+        this.enterpriseName = enterpriseName;
+    }
+
+    public double getTrueThreshold() {
+        return trueThreshold;
+    }
+
+    public void setTrueThreshold(double trueThreshold) {
+        this.trueThreshold = trueThreshold;
+    }
+
+    public String getLocation() {
+        return location;
+    }
+
+    public void setLocation(String location) {
+        this.location = location;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getTypeNum() {
+        return typeNum;
+    }
+
+    public void setTypeNum(String typeNum) {
+        this.typeNum = typeNum;
+    }
+
+    public String getTypeName() {
+        return typeName;
+    }
+
+    public void setTypeName(String typeName) {
+        this.typeName = typeName;
+    }
+}

+ 10 - 0
enteprise-admin/src/main/java/com/enteprise/matchAnalysis/service/IMatchService.java

@@ -0,0 +1,10 @@
+package com.enteprise.matchAnalysis.service;
+
+import com.enteprise.matchAnalysis.domain.MatchAna;
+import com.enteprise.matchAnalysis.domain.dto.MatchDto;
+
+import java.util.List;
+
+public interface IMatchService {
+    List<MatchDto> matchAnalysisList(MatchAna matchAna);
+}

+ 170 - 0
enteprise-admin/src/main/java/com/enteprise/matchAnalysis/service/impl/MatchServiceImpl.java

@@ -0,0 +1,170 @@
+package com.enteprise.matchAnalysis.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.dto.GrowthRateDto;
+import com.enteprise.matchAnalysis.domain.MatchAna;
+import com.enteprise.matchAnalysis.domain.dto.MatchDto;
+import com.enteprise.matchAnalysis.service.IMatchService;
+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;
+
+import static com.enteprise.util.CommonUtil.getRange;
+
+@Service
+public class MatchServiceImpl implements IMatchService {
+    @Autowired
+    private EnterpriseMapper enterpriseMapper;
+    @Autowired
+    private EnterpriseBaseDataMonthMapper enterpriseBaseDataMonthMapper;
+    @Autowired
+    private EnterpriseBaseDataSeasonMapper enterpriseBaseDataSeasonMapper;
+    @Autowired
+    private EnterpriseBaseDataYearMapper enterpriseBaseDataYearMapper;
+    @Override
+    public List<MatchDto> matchAnalysisList(MatchAna matchAna) {
+        ArrayList<MatchDto> list = new ArrayList<>();
+        //评估类型
+        String dataKey = matchAna.getDataKey();
+        //阈值
+        double threshold = matchAna.getThreshold();
+        //时间纬度
+        int year = matchAna.getYear();
+        int elecStartMonth = matchAna.getElecStartMonth();
+        int elecEndMonth = matchAna.getElecEndMonth();
+        int manStartSeason = matchAna.getManStartSeason();
+        int manEndSeason = matchAna.getManEndSeason();
+        //通过分类、行业代码过滤企业列表
+        Enterprise enterprise = new Enterprise();
+        enterprise.setCode(matchAna.getCode());
+        enterprise.setTypeNum(matchAna.getTypeNum());
+        List<EnterpriseDto> enterpriseDtos = enterpriseMapper.selectAllWithType(enterprise);
+        //对应评估类型业务逻辑
+        if (dataKey.equals("powerConsume")){
+            //用电逻辑,月度指标
+            //每个企业从开始月份循环相加到结束月份
+            List<Integer> monthRange = getRange(elecStartMonth, elecEndMonth);
+            for (EnterpriseDto enterpriseDto : enterpriseDtos) {
+                double powerConsume = 0;
+                double oldPowerConsume = 0;
+                double totalIndustrial = 0;
+                double oldTotalIndustrial = 0;
+                String enterpriseName = enterpriseDto.getEnterpriseName();
+                for (int nowMonth : monthRange) {
+                    //计算对应月份范围数值
+                    EnterpriseBaseDataMonth dataMonth = new EnterpriseBaseDataMonth();
+                    dataMonth.setEnterpriseName(enterpriseName);
+                    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 (!dataMonths.isEmpty() && !oldDataMonths.isEmpty()) {
+                        EnterpriseBaseDataMonth dataMonth1 = dataMonths.get(0);
+                        powerConsume += dataMonth1.getPowerConsume();
+                        totalIndustrial += dataMonth1.getTotalIndustrialValue();
+                        EnterpriseBaseDataMonth dataMonth2 = oldDataMonths.get(0);
+                        oldPowerConsume += dataMonth2.getPowerConsume();
+                        oldTotalIndustrial += dataMonth2.getTotalIndustrialValue();
+                    }
+                }
+                //计算同比增速:(今年-去年)/去年
+                double powerRate = (powerConsume - oldPowerConsume) / oldPowerConsume;
+                double industrialRate = (totalIndustrial - oldTotalIndustrial) / oldTotalIndustrial;
+                double trueThreshold =powerRate - industrialRate;
+                if (trueThreshold !=0 && trueThreshold < threshold) {
+                    //初始化返回实体类并添加到list
+                    MatchDto dto = new MatchDto(enterpriseName, trueThreshold, enterpriseDto.getLocation(), enterpriseDto.getCode(), enterpriseDto.getTypeNum(), enterpriseDto.getTypeName());
+                    list.add(dto);
+                }
+            }
+            return list;
+        }
+        if (dataKey.equals("employeeNumber")){
+            //用人逻辑,季度指标
+            List<Integer> seasonRange = getRange(manStartSeason, manEndSeason);
+            for (EnterpriseDto enterpriseDto : enterpriseDtos){
+                EnterpriseBaseDataSeason dataSeason = new EnterpriseBaseDataSeason();
+                double employeeNumber = 0;
+                double oldEmployeeNumber = 0;
+                double totalIndustrial = 0;
+                double oldTotalIndustrial = 0;
+                String enterpriseName = enterpriseDto.getEnterpriseName();
+                for (int nowSeason : seasonRange) {
+                    dataSeason.setEnterpriseName(enterpriseName);
+                    dataSeason.setSeason(String.valueOf(nowSeason));
+                    dataSeason.setYear(String.valueOf(year));
+                    //季度指标获取
+                    List<EnterpriseBaseDataSeason> dataSeasons = enterpriseBaseDataSeasonMapper.selectEnterpriseBaseDataSeasonList(dataSeason);
+                    dataSeason.setYear(String.valueOf(year - 1));
+                    List<EnterpriseBaseDataSeason> oldDataSeasons = enterpriseBaseDataSeasonMapper.selectEnterpriseBaseDataSeasonList(dataSeason);
+                    if (!dataSeasons.isEmpty() && !oldDataSeasons.isEmpty()) {
+                        EnterpriseBaseDataSeason dataSeason1 = dataSeasons.get(0);
+                        employeeNumber += dataSeason1.getEmployeeNumber();
+                        totalIndustrial += dataSeason1.getTotalIndustrialValue();
+                        EnterpriseBaseDataSeason dataSeason2 = oldDataSeasons.get(0);
+                        oldEmployeeNumber += dataSeason2.getEmployeeNumber();
+                        oldTotalIndustrial += dataSeason2.getTotalIndustrialValue();
+                    }
+                }
+                //计算同比增速:(今年-去年)/去年
+                double employeeRate = (employeeNumber - oldEmployeeNumber) / oldEmployeeNumber;
+                double industrialRate = (totalIndustrial - oldTotalIndustrial) / oldTotalIndustrial;
+                double trueThreshold = employeeRate - industrialRate;
+                if (trueThreshold !=0 && trueThreshold < threshold) {
+                    //初始化返回实体类并添加到list
+                    MatchDto dto = new MatchDto(enterpriseName, trueThreshold, enterpriseDto.getLocation(), enterpriseDto.getCode(), enterpriseDto.getTypeNum(), enterpriseDto.getTypeName());
+                    list.add(dto);
+                }
+            }
+            return list;
+        }
+        if (dataKey.equals("energyConsume")){
+            //用气逻辑,年度指标
+            for (EnterpriseDto enterpriseDto : enterpriseDtos){
+                EnterpriseBaseDataYear dataYear = new EnterpriseBaseDataYear();
+                double energyConsume = 0;
+                double oldEnergyConsume = 0;
+                double totalIndustrial = 0;
+                double oldTotalIndustrial = 0;
+                String enterpriseName = enterpriseDto.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 (!dataYears.isEmpty() && !oldDataYears.isEmpty()) {
+                    EnterpriseBaseDataYear dataYear1 = dataYears.get(0);
+                    energyConsume = dataYear1.getEnergyConsume();
+                    totalIndustrial = dataYear1.getTotalIndustrialValue();
+                    EnterpriseBaseDataYear dataYear2 = oldDataYears.get(0);
+                    oldEnergyConsume = dataYear2.getEnergyConsume();
+                    oldTotalIndustrial = dataYear2.getTotalIndustrialValue();
+                }
+                //计算同比增速:(今年-去年)/去年
+                double employeeRate = (energyConsume - oldEnergyConsume) / oldEnergyConsume;
+                double industrialRate = (totalIndustrial - oldTotalIndustrial) / oldTotalIndustrial;
+                double trueThreshold = employeeRate - industrialRate;
+                if (trueThreshold !=0 && trueThreshold < threshold) {
+                    //初始化返回实体类并添加到list
+                    MatchDto dto = new MatchDto(enterpriseName, trueThreshold, enterpriseDto.getLocation(), enterpriseDto.getCode(), enterpriseDto.getTypeNum(), enterpriseDto.getTypeName());
+                    list.add(dto);
+                }
+            }
+            return list;
+        }
+        return list;
+    }
+}

+ 28 - 0
enteprise-admin/src/main/java/com/enteprise/util/CommonUtil.java

@@ -0,0 +1,28 @@
+package com.enteprise.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CommonUtil {
+    /**
+     * 获取两个值之间的所有整数
+     * @param start
+     * @param end
+     * @return
+     */
+    public static List<Integer> getRange(int start, int end) {
+        // 创建一个列表以存储结果
+        List<Integer> list = new ArrayList<>();
+
+        // 确定区间的起始和结束值
+        int min = Math.min(start, end);
+        int max = Math.max(start, end);
+
+        // 使用循环将范围内的所有值添加到列表中
+        for (int i = min; i <= max; i++) {
+            list.add(i);
+        }
+
+        return list;
+    }
+}