parent
c693aef07e
commit
9585dccc18
@ -0,0 +1,14 @@ |
||||
package com.psdc.service; |
||||
|
||||
import java.util.HashMap; |
||||
|
||||
public interface IStatisticsAnalysisService { |
||||
|
||||
/** |
||||
* 计算单个设备的同比数据 |
||||
* @param deviceId 设备id |
||||
* @param year 本期 |
||||
* @param toYear 同期 |
||||
*/ |
||||
HashMap<String,Object> computeYearOnYear(Integer deviceId, String year, String toYear); |
||||
} |
@ -0,0 +1,83 @@ |
||||
package com.psdc.service.impl; |
||||
|
||||
import com.psdc.entity.PsdcStatisticsYear; |
||||
import com.psdc.mapper.PsdcStatisticsYearMapper; |
||||
import com.psdc.service.IStatisticsAnalysisService; |
||||
import com.psdc.utils.bean.BeanUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 统计分析页面服务层 |
||||
*/ |
||||
@Service |
||||
public class StatisticsAnalysisService implements IStatisticsAnalysisService { |
||||
|
||||
@Resource |
||||
private PsdcStatisticsYearMapper psdcStatisticsYearMapper; |
||||
|
||||
/** |
||||
* 计算单个设备的同比数据 |
||||
* @param deviceId 设备id |
||||
* @param year 本期 |
||||
* @param toYear 同期 |
||||
*/ |
||||
@Override |
||||
public HashMap<String,Object> computeYearOnYear(Integer deviceId, String year, String toYear) { |
||||
|
||||
HashMap<String, Object> map = new HashMap<>(); |
||||
PsdcStatisticsYear psdcStatisticsYear = psdcStatisticsYearMapper.queryByDeviceIdAndDate(deviceId, year); |
||||
PsdcStatisticsYear psdcStatisticsYearTo = psdcStatisticsYearMapper.queryByDeviceIdAndDate(deviceId, toYear); |
||||
List<HashMap<String,Object>> mapList = new ArrayList<>(); |
||||
map.put("StatisticsYear",psdcStatisticsYear); |
||||
map.put("StatisticsToYear",psdcStatisticsYearTo); |
||||
if ( psdcStatisticsYear == null && psdcStatisticsYearTo == null){ |
||||
return map; |
||||
} |
||||
List<String> yearList = new ArrayList<>(); |
||||
List<String> toYearList = new ArrayList<>(); |
||||
BeanUtils.coverObjToList(3,15,psdcStatisticsYear,yearList); |
||||
BeanUtils.coverObjToList(3,15,psdcStatisticsYearTo,toYearList); |
||||
Double addUp = 0.0; |
||||
for (int i = 1; i < 13; i++) { |
||||
HashMap<String, Object> stringObjectHashMap = new HashMap<>(); |
||||
if(i < 10 ){ |
||||
stringObjectHashMap.put("month","0" + i + "月"); |
||||
} else { |
||||
stringObjectHashMap.put("month",i + "月"); |
||||
} |
||||
if ( yearList.isEmpty() ){ |
||||
stringObjectHashMap.put("year",null); |
||||
} else { |
||||
stringObjectHashMap.put("year",yearList.get(i)); |
||||
} |
||||
if ( toYearList.isEmpty()){ |
||||
stringObjectHashMap.put("toYear",null); |
||||
} else { |
||||
stringObjectHashMap.put("toYear",toYearList.get(i)); |
||||
} |
||||
Double compute = null; |
||||
if ( !yearList.isEmpty() && yearList.get(i) != null && ( !toYearList.isEmpty() && toYearList.get(i) != null)){ |
||||
double yearDouble = Double.parseDouble(yearList.get(i)); |
||||
double toYearDouble = Double.parseDouble(toYearList.get(i)); |
||||
if (toYearDouble == 0){ |
||||
toYearDouble = 1; |
||||
} |
||||
compute = ( yearDouble - toYearDouble ) / toYearDouble / 100; |
||||
|
||||
} |
||||
if (compute != null ){ |
||||
addUp = addUp + compute; |
||||
} |
||||
stringObjectHashMap.put("compute",compute); |
||||
stringObjectHashMap.put("addUp",addUp); |
||||
mapList.add(stringObjectHashMap); |
||||
} |
||||
map.put("yearOnYear",mapList); |
||||
return map; |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,34 @@ |
||||
package com.psdc.controller.evaluate; |
||||
|
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.psdc.core.domain.AjaxResult; |
||||
import com.psdc.service.IStatisticsAnalysisService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
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 javax.annotation.Resource; |
||||
|
||||
@RestController |
||||
@Slf4j |
||||
@RequestMapping("/evaluate/analysis") |
||||
public class EnergyAnalysisController { |
||||
|
||||
@Resource |
||||
private IStatisticsAnalysisService statisticsAnalysisService; |
||||
|
||||
@PreAuthorize("@ss.hasPermi('analyse:nhfx:nhtb')") |
||||
@PostMapping("/yearOnYearAnalyse") |
||||
public AjaxResult yearOnYearAnalyse(@RequestBody JSONObject jsonObject){ |
||||
Integer deviceId = jsonObject.getInteger("deviceId"); |
||||
String year = jsonObject.getString("year"); |
||||
String toyear = jsonObject.getString("toYear"); |
||||
log.info("设备id:{},本期年份:{},同期年份:{}",deviceId,year,toyear); |
||||
statisticsAnalysisService.computeYearOnYear(deviceId,year,toyear); |
||||
return null; |
||||
} |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue