commit
229b471f33
@ -0,0 +1,25 @@ |
||||
package com.psdc.service; |
||||
|
||||
import org.apache.poi.ss.formula.functions.T; |
||||
|
||||
import java.text.ParseException; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
public interface IStatisticsAnalysisService { |
||||
|
||||
/** |
||||
* 计算单个设备的同比数据 |
||||
* @param deviceId 设备id |
||||
* @param year 本期 |
||||
* @param toYear 同期 |
||||
*/ |
||||
HashMap<String,Object> computeYearOnYear(Integer deviceId, String year, String toYear); |
||||
|
||||
/** |
||||
* 计算环比数据 |
||||
* @param timeType 时间类型 1 日 2 月 3 年 |
||||
* @param datetime 时间 |
||||
*/ |
||||
List<HashMap<String,Object>> computeLinkRelativeRatio(Integer timeType, String datetime) throws ParseException; |
||||
} |
@ -0,0 +1,208 @@ |
||||
package com.psdc.service.impl; |
||||
|
||||
import com.psdc.entity.PsdcDevice; |
||||
import com.psdc.entity.PsdcStatisticsYear; |
||||
import com.psdc.mapper.PsdcDeviceMapper; |
||||
import com.psdc.mapper.PsdcStatisticsDayMapper; |
||||
import com.psdc.mapper.PsdcStatisticsMonthMapper; |
||||
import com.psdc.mapper.PsdcStatisticsYearMapper; |
||||
import com.psdc.service.IStatisticsAnalysisService; |
||||
import com.psdc.utils.SecurityUtils; |
||||
import com.psdc.utils.bean.BeanUtils; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.poi.ss.formula.functions.T; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.text.ParseException; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* 统计分析页面服务层 |
||||
*/ |
||||
@Service |
||||
@Slf4j |
||||
public class StatisticsAnalysisService implements IStatisticsAnalysisService { |
||||
|
||||
@Resource |
||||
private PsdcStatisticsYearMapper psdcStatisticsYearMapper; |
||||
|
||||
@Resource |
||||
private PsdcDeviceMapper psdcDeviceMapper; |
||||
|
||||
@Resource |
||||
private PsdcStatisticsMonthMapper psdcStatisticsMonthMapper; |
||||
|
||||
@Resource |
||||
private PsdcStatisticsDayMapper psdcStatisticsDayMapper; |
||||
|
||||
/** |
||||
* 计算单个设备的同比数据 |
||||
* @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<>(); |
||||
stringObjectHashMap.put("month", i < 10 ? "0" + i + "月" : i + "月"); |
||||
stringObjectHashMap.put("year",yearList.isEmpty() ? null : yearList.get(i)); |
||||
stringObjectHashMap.put("toYear",toYearList.isEmpty() ? null : toYearList.get(i)); |
||||
Double compute = null; |
||||
if ( !yearList.isEmpty() && yearList.get(i) != null && !yearList.get(i).equals("") && ( !toYearList.isEmpty() && toYearList.get(i) != null && !toYearList.get(i).equals(""))){ |
||||
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",String.format("%.2f%%",compute)); |
||||
} else { |
||||
stringObjectHashMap.put("compute",null); |
||||
} |
||||
stringObjectHashMap.put("addUp",String.format("%.2f%%",addUp)); |
||||
mapList.add(stringObjectHashMap); |
||||
} |
||||
map.put("yearOnYear",mapList); |
||||
|
||||
return map; |
||||
} |
||||
|
||||
/** |
||||
* 计算环比数据 |
||||
* @param timeType 时间类型 1 日 2 月 3 年 |
||||
* @param datetime 时间 |
||||
*/ |
||||
@Override |
||||
public List<HashMap<String,Object>> computeLinkRelativeRatio(Integer timeType, String datetime) throws ParseException { |
||||
//查找设备列表
|
||||
List<PsdcDevice> psdcDevices = psdcDeviceMapper.controlQueryByUserId(SecurityUtils.getUserId()); |
||||
List<HashMap<String,Object>> mapList = new ArrayList<>(); |
||||
|
||||
if ( timeType == 1 ){ |
||||
SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd"); |
||||
Calendar instance = Calendar.getInstance(); |
||||
instance.setTime(dayFormat.parse(datetime)); |
||||
instance.add(Calendar.DATE,-1); |
||||
String today = dayFormat.format(dayFormat.parse(datetime)); |
||||
String yesterday = dayFormat.format(instance.getTime()); |
||||
log.info("日环比,本期:{},同期:{}",today,yesterday); |
||||
mapList = psdcDevices.stream().map(psdcDevice -> { |
||||
HashMap<String, Object> stringObjectHashMap = new HashMap<>(); |
||||
Double compute = null; |
||||
Double addUp = null; |
||||
Integer deviceId = psdcDevice.getDeviceId(); |
||||
Double todayTotal = psdcStatisticsDayMapper.queryOneLineSum(deviceId, today); |
||||
Double yesterdayTotal = psdcStatisticsDayMapper.queryOneLineSum(deviceId, yesterday); |
||||
if( todayTotal == null ){ |
||||
todayTotal = 0.0; |
||||
} |
||||
if ( yesterdayTotal != null && yesterdayTotal != 0.0) { |
||||
addUp = todayTotal - yesterdayTotal; |
||||
compute = (todayTotal - yesterdayTotal) / yesterdayTotal * 100; |
||||
stringObjectHashMap.put("lastMonthTotal", String.format("%.2f", yesterdayTotal)); |
||||
stringObjectHashMap.put("addUp", String.format("%.2f", addUp)); |
||||
stringObjectHashMap.put("compute", String.format("%.2f%%", compute)); |
||||
} else { |
||||
stringObjectHashMap.put("addUp", null); |
||||
stringObjectHashMap.put("compute", null); |
||||
stringObjectHashMap.put("lastMonthTotal", null); |
||||
} |
||||
stringObjectHashMap.put("deviceId", psdcDevice.getDeviceId()); |
||||
stringObjectHashMap.put("deviceName", psdcDevice.getDeviceName()); |
||||
stringObjectHashMap.put("thisMonthTotal", String.format("%.2f", todayTotal)); |
||||
return stringObjectHashMap; |
||||
}).collect(Collectors.toList()); |
||||
} else if ( timeType == 2 ){ |
||||
SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM"); |
||||
Calendar instance = Calendar.getInstance(); |
||||
instance.setTime(monthFormat.parse(datetime)); |
||||
instance.add(Calendar.MONTH,-1); |
||||
String thisMonth = monthFormat.format(monthFormat.parse(datetime)); |
||||
String lastMonth = monthFormat.format(instance.getTime()); |
||||
log.info("月环比,本期:{},同期:{}",thisMonth,lastMonth); |
||||
mapList = psdcDevices.stream().map(psdcDevice -> { |
||||
HashMap<String, Object> stringObjectHashMap = new HashMap<>(); |
||||
Double compute = null; |
||||
Double addUp = null; |
||||
Integer deviceId = psdcDevice.getDeviceId(); |
||||
Double thisMonthTotal = psdcStatisticsMonthMapper.queryOneLineSum(deviceId, thisMonth); |
||||
Double lastMonthTotal = psdcStatisticsMonthMapper.queryOneLineSum(deviceId, lastMonth); |
||||
if( thisMonthTotal == null ){ |
||||
thisMonthTotal = 0.0; |
||||
} |
||||
if ( lastMonthTotal != null && lastMonthTotal != 0.0) { |
||||
addUp = thisMonthTotal - lastMonthTotal; |
||||
compute = (thisMonthTotal - lastMonthTotal) / lastMonthTotal * 100; |
||||
stringObjectHashMap.put("lastMonthTotal", String.format("%.2f", lastMonthTotal)); |
||||
stringObjectHashMap.put("addUp", String.format("%.2f", addUp)); |
||||
stringObjectHashMap.put("compute", String.format("%.2f%%", compute)); |
||||
} else { |
||||
stringObjectHashMap.put("addUp", null); |
||||
stringObjectHashMap.put("compute", null); |
||||
stringObjectHashMap.put("lastMonthTotal", null); |
||||
} |
||||
stringObjectHashMap.put("deviceId", psdcDevice.getDeviceId()); |
||||
stringObjectHashMap.put("deviceName", psdcDevice.getDeviceName()); |
||||
stringObjectHashMap.put("thisMonthTotal", String.format("%.2f", thisMonthTotal)); |
||||
return stringObjectHashMap; |
||||
}).collect(Collectors.toList()); |
||||
} else if ( timeType == 3){ |
||||
SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy"); |
||||
Calendar instance = Calendar.getInstance(); |
||||
instance.setTime(yearFormat.parse(datetime)); |
||||
instance.add(Calendar.YEAR,-1); |
||||
String thisYear = yearFormat.format(yearFormat.parse(datetime)); |
||||
String lastYear = yearFormat.format(instance.getTime()); |
||||
log.info("年环比,本期:{},同期:{}",thisYear,lastYear); |
||||
mapList = psdcDevices.stream().map(psdcDevice -> { |
||||
HashMap<String, Object> stringObjectHashMap = new HashMap<>(); |
||||
Double compute = null; |
||||
Double addUp = null; |
||||
Integer deviceId = psdcDevice.getDeviceId(); |
||||
Double thisYearTotal = psdcStatisticsYearMapper.queryOneLineSum(deviceId, thisYear); |
||||
Double lastYearTotal = psdcStatisticsYearMapper.queryOneLineSum(deviceId, lastYear); |
||||
if( thisYearTotal == null ){ |
||||
thisYearTotal = 0.0; |
||||
} |
||||
if ( lastYearTotal != null && lastYearTotal != 0.0) { |
||||
addUp = thisYearTotal - lastYearTotal; |
||||
compute = (thisYearTotal - lastYearTotal) / lastYearTotal * 100; |
||||
stringObjectHashMap.put("lastMonthTotal", String.format("%.2f", lastYearTotal)); |
||||
stringObjectHashMap.put("addUp", String.format("%.2f", addUp)); |
||||
stringObjectHashMap.put("compute", String.format("%.2f%%", compute)); |
||||
} else { |
||||
stringObjectHashMap.put("addUp", null); |
||||
stringObjectHashMap.put("compute", null); |
||||
stringObjectHashMap.put("lastMonthTotal", null); |
||||
} |
||||
stringObjectHashMap.put("deviceId", psdcDevice.getDeviceId()); |
||||
stringObjectHashMap.put("deviceName", psdcDevice.getDeviceName()); |
||||
stringObjectHashMap.put("thisMonthTotal", String.format("%.2f", thisYearTotal)); |
||||
return stringObjectHashMap; |
||||
}).collect(Collectors.toList()); |
||||
} |
||||
return mapList; |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,48 @@ |
||||
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; |
||||
import java.text.ParseException; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
@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); |
||||
HashMap<String, Object> stringObjectHashMap = statisticsAnalysisService.computeYearOnYear(deviceId, year, toYear); |
||||
return AjaxResult.success(stringObjectHashMap); |
||||
} |
||||
|
||||
@PreAuthorize("@ss.hasPermi('analyse:nhfx:nhhb')") |
||||
@PostMapping("/linkRelativeRatio") |
||||
public AjaxResult linkRelativeRatio(@RequestBody JSONObject jsonObject) throws ParseException { |
||||
Integer timeType = jsonObject.getInteger("timeType"); |
||||
String datetime = jsonObject.getString("datetime"); |
||||
List<HashMap<String, Object>> mapList = statisticsAnalysisService.computeLinkRelativeRatio(timeType, datetime); |
||||
return AjaxResult.success(mapList); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
|
Loading…
Reference in new issue