|
@@ -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) {
|
|
|
+
|
|
|
+ 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) {
|
|
|
+
|
|
|
+ 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) {
|
|
|
+
|
|
|
+ MatchDto dto = new MatchDto(enterpriseName, trueThreshold, enterpriseDto.getLocation(), enterpriseDto.getCode(), enterpriseDto.getTypeNum(), enterpriseDto.getTypeName());
|
|
|
+ list.add(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+}
|