|
@@ -0,0 +1,95 @@
|
|
|
+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.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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class GrowthRateServiceImpl implements IGrowthRateService {
|
|
|
+ @Autowired
|
|
|
+ private EnterpriseMapper enterpriseMapper;
|
|
|
+ @Autowired
|
|
|
+ private EnterpriseBaseDataMonthMapper enterpriseBaseDataMonthMapper;
|
|
|
+ @Override
|
|
|
+ public List<GrowthRateDto> analysisGrowthRate(GrowthRate growthRate) {
|
|
|
+ String analysisType = growthRate.getAnalysisType();
|
|
|
+ int startMonth = growthRate.getStartMonth();
|
|
|
+ int endMonth = growthRate.getEndMonth();
|
|
|
+ int year = growthRate.getYear();
|
|
|
+ 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){
|
|
|
+ double sum = 0;
|
|
|
+ double oldSum = 0;
|
|
|
+ for (int nowMonth : monthRange){
|
|
|
+ //计算对应月份范围数值
|
|
|
+ EnterpriseBaseDataMonth dataMonth = new EnterpriseBaseDataMonth();
|
|
|
+ dataMonth.setEnterpriseName(enterpriseDto.getEnterpriseName());
|
|
|
+ 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")) {
|
|
|
+ sum += dataMonths.get(0).getTotalIndustrialValue();
|
|
|
+ oldSum += oldDataMonths.get(0).getTotalIndustrialValue();
|
|
|
+ }else if (analysisType.equals("powerConsume")){
|
|
|
+ sum += dataMonths.get(0).getPowerConsume();
|
|
|
+ oldSum += oldDataMonths.get(0).getPowerConsume();
|
|
|
+ }else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算同比增速:(今年-去年)/去年
|
|
|
+ double rate = (sum - oldSum) / oldSum;
|
|
|
+ //初始化企业并把该企业的同比增速和其他数据放入list中
|
|
|
+ GrowthRateDto growthRateDto = new GrowthRateDto();
|
|
|
+ growthRateDto.setRate(rate);
|
|
|
+ growthRateDto.setEnterpriseName(enterpriseDto.getEnterpriseName());
|
|
|
+ growthRateDto.setLocation(enterpriseDto.getLocation());
|
|
|
+ list.add(growthRateDto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|