|
@@ -1,25 +1,36 @@
|
|
|
package com.persagy.apm.energy.report.centermiddleware.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.persagy.apm.common.response.PoemsFeignResponse;
|
|
|
import com.persagy.apm.energy.report.centermiddleware.client.CenterMiddlewareWebClient;
|
|
|
-import com.persagy.apm.energy.report.centermiddleware.model.dto.QueryEnergyDataDTO;
|
|
|
-import com.persagy.apm.energy.report.centermiddleware.model.dto.QueryItemInfoDTO;
|
|
|
-import com.persagy.apm.energy.report.centermiddleware.model.vo.EnergyDataInfoVO;
|
|
|
-import com.persagy.apm.energy.report.centermiddleware.model.vo.EnergyItemInfoVO;
|
|
|
+import com.persagy.apm.energy.report.centermiddleware.model.dto.*;
|
|
|
+import com.persagy.apm.energy.report.centermiddleware.model.vo.*;
|
|
|
import com.persagy.apm.energy.report.centermiddleware.service.ICenterMiddlewareWebService;
|
|
|
+import com.persagy.apm.energy.report.common.utils.DataUtils;
|
|
|
import com.persagy.apm.energy.report.common.utils.DateUtils;
|
|
|
+import com.persagy.apm.energy.report.monthly.detail.common.model.vo.DateGraphItemVO;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ICenterMiddlewareWebServiceImp implements ICenterMiddlewareWebService {
|
|
|
|
|
|
@Autowired
|
|
|
private CenterMiddlewareWebClient centerMiddlewareWebClient;
|
|
|
|
|
|
+ @Value("cooling.capacity")
|
|
|
+ String coolingCapacity;
|
|
|
+
|
|
|
+ @Value("power.consumption")
|
|
|
+ String powerConsumption;
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, String> getItemNameMap(QueryItemInfoDTO queryItemInfoDTO) {
|
|
|
if (null == queryItemInfoDTO) {
|
|
@@ -62,4 +73,179 @@ public class ICenterMiddlewareWebServiceImp implements ICenterMiddlewareWebServi
|
|
|
}
|
|
|
return resultMap;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ProjectEERDataVo> getProjectEERDataList(List<String> pjIdList, String groupCode, Date reportDate) {
|
|
|
+ if (CollectionUtils.isEmpty(pjIdList) || StringUtils.isEmpty(groupCode) || null == reportDate) {
|
|
|
+ log.info("查询ProjectEERDataVo时参数为空,故不进行查询");
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<ProjectEERDataVo> resultList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ for (String pjId : pjIdList) {
|
|
|
+ ProjectEERDataVo projectEERDataVo = new ProjectEERDataVo();
|
|
|
+ List<Date> dateList = DateUtils.getDayList(reportDate, DateUtils.getMonthOff(reportDate, 1));
|
|
|
+ List<String> coolClassCodeList = JSONObject.parseArray(coolingCapacity, String.class);
|
|
|
+ TreeMap<Date, Double> date_coolingCapacityMap = getDayCountData(pjId, groupCode, reportDate, "accCool", coolClassCodeList, dateList);
|
|
|
+ List<String> powerClassCodeList = JSONObject.parseArray(powerConsumption, String.class);
|
|
|
+ TreeMap<Date, Double> date_powerConsumptionMap = getDayCountData(pjId, groupCode, reportDate, "accElecConsum", powerClassCodeList, dateList);
|
|
|
+ List<DateGraphItemVO> dateGraphItemVOList = new ArrayList<>();
|
|
|
+ Double allCoolingCapacity = null;
|
|
|
+ Double allPowerConsumption = null;
|
|
|
+ for (Date date : dateList) {
|
|
|
+ DateGraphItemVO dateGraphItemVO = new DateGraphItemVO();
|
|
|
+ dateGraphItemVO.setDate(date);
|
|
|
+ Double coolingCapacity = date_coolingCapacityMap.get(date);
|
|
|
+ Double powerConsumption = date_powerConsumptionMap.get(date);
|
|
|
+ Double eer = null;
|
|
|
+ if (coolingCapacity != null && powerConsumption != null) {
|
|
|
+ eer = coolingCapacity / powerConsumption;
|
|
|
+ if (null == allCoolingCapacity) {
|
|
|
+ allCoolingCapacity = 0.0;
|
|
|
+ }
|
|
|
+ allCoolingCapacity = allCoolingCapacity + coolingCapacity;
|
|
|
+ if (null == allPowerConsumption) {
|
|
|
+ allPowerConsumption = 0.0;
|
|
|
+ }
|
|
|
+ allPowerConsumption = allPowerConsumption + powerConsumption;
|
|
|
+ }
|
|
|
+ dateGraphItemVO.setValue(eer);
|
|
|
+ dateGraphItemVOList.add(dateGraphItemVO);
|
|
|
+ }
|
|
|
+ Double allEer = null;
|
|
|
+ if (allCoolingCapacity != null && allPowerConsumption != null) {
|
|
|
+ allEer = allCoolingCapacity / allPowerConsumption;
|
|
|
+ }
|
|
|
+ projectEERDataVo.setProjectId(pjId);
|
|
|
+ projectEERDataVo.setEer(allEer);
|
|
|
+ projectEERDataVo.setCoolingCapacityCurrentMonth(allCoolingCapacity);
|
|
|
+ projectEERDataVo.setEerDetailInfo(dateGraphItemVOList);
|
|
|
+ projectEERDataVo.setMaxEerTimeList(getMaxOrMinDateList(dateGraphItemVOList, -1));
|
|
|
+ projectEERDataVo.setMinEerTimeList(getMaxOrMinDateList(dateGraphItemVOList, 1));
|
|
|
+ resultList.add(projectEERDataVo);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("计算ProjectEERDataVo异常:", e);
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Date> getMaxOrMinDateList(List<DateGraphItemVO> dateGraphItemVOList, Integer orderType) {
|
|
|
+ Map<String, Integer> sortMap = new HashMap<>();
|
|
|
+ sortMap.put("value", orderType);
|
|
|
+ DataUtils.sort(dateGraphItemVOList, sortMap);
|
|
|
+ List<Date> resultList = new ArrayList<>();
|
|
|
+ Double maxOrMinData = null;
|
|
|
+ for (DateGraphItemVO vo : dateGraphItemVOList) {
|
|
|
+ if (vo.getValue() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (maxOrMinData == null) {
|
|
|
+ maxOrMinData = vo.getValue();
|
|
|
+ } else if (maxOrMinData != vo.getValue()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ resultList.add(vo.getDate());
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private TreeMap<Date, Double> getDayCountData(String pjId, String groupCode, Date reportDate, String infoCode, List<String> classCodeList, List<Date> dateList) {
|
|
|
+ List<String> objectIdList = getObjectIdList(pjId, groupCode, classCodeList);
|
|
|
+ if (!CollectionUtils.isEmpty(objectIdList)) {
|
|
|
+ TreeMap<Date, Double> date_dataMap = new TreeMap<>();
|
|
|
+ TreeMap<Date, Double> day_coolDataMap = getInfoCodePeriodDataCountMap(pjId, groupCode, objectIdList, reportDate, infoCode, "1d");
|
|
|
+ for (Date date : dateList) {
|
|
|
+ Double currentDayCoolData = day_coolDataMap.get(date);
|
|
|
+ Double nextDayCoolData = day_coolDataMap.get(DateUtils.getDayOff(date, 1));
|
|
|
+ if (currentDayCoolData != null && nextDayCoolData != null) {
|
|
|
+ date_dataMap.put(date, nextDayCoolData - currentDayCoolData);
|
|
|
+ } else {
|
|
|
+ date_dataMap.put(date, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return date_dataMap;
|
|
|
+ }
|
|
|
+ return new TreeMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getObjectIdList(String pjId, String groupCode, List<String> classCodeList) {
|
|
|
+ if (StringUtils.isEmpty(pjId) || StringUtils.isEmpty(groupCode) || CollectionUtils.isEmpty(classCodeList)) {
|
|
|
+ log.info("查询中台对象信息时参数为空,故不进行查询");
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<String> resultList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ QueryObjectInfoDTO queryObjectInfoDTO = new QueryObjectInfoDTO();
|
|
|
+ queryObjectInfoDTO.setProjectId(pjId);
|
|
|
+ queryObjectInfoDTO.setGroupCode(groupCode);
|
|
|
+ Criteria criteria = new Criteria();
|
|
|
+ criteria.setClassCode(classCodeList);
|
|
|
+ queryObjectInfoDTO.setCriteria(criteria);
|
|
|
+ PoemsFeignResponse<ObjectInfoVO> response = centerMiddlewareWebClient.getObjectInfo(queryObjectInfoDTO);
|
|
|
+ List<ObjectInfoVO> objectInfoVOList = response.getContent();
|
|
|
+ if (!CollectionUtils.isEmpty(objectInfoVOList)) {
|
|
|
+ for (ObjectInfoVO vo : objectInfoVOList) {
|
|
|
+ resultList.add(vo.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询中台对象信息时异常:", e);
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private TreeMap<Date, Double> getInfoCodePeriodDataCountMap(String pjId, String groupCode, List<String> objectIdList, Date reportDate, String infoCode, String period) {
|
|
|
+ if (StringUtils.isEmpty(pjId) || StringUtils.isEmpty(groupCode) || CollectionUtils.isEmpty(objectIdList) || null == reportDate) {
|
|
|
+ log.info("查询历史数据时参数为空,故不进行查询");
|
|
|
+ return new TreeMap<>();
|
|
|
+ }
|
|
|
+ TreeMap<Date, Double> dataMap = new TreeMap<>();
|
|
|
+ try {
|
|
|
+ BatchQueryPeriodDataDTO batchQueryPeriodDataDTO = new BatchQueryPeriodDataDTO();
|
|
|
+ batchQueryPeriodDataDTO.setProjectId(pjId);
|
|
|
+ batchQueryPeriodDataDTO.setGroupCode(groupCode);
|
|
|
+ List<CriteriasObjDTO> criteriasObjDTOList = new ArrayList<>();
|
|
|
+ Map receivetime = new HashMap();
|
|
|
+ String startTime = DateUtils.date2Str(reportDate, DateUtils.SDFSECOND);
|
|
|
+ String endTime = DateUtils.date2Str(DateUtils.getDayOff(DateUtils.getMonthOff(reportDate, 1), 1), DateUtils.SDFSECOND);
|
|
|
+ receivetime.put("$gte", startTime);
|
|
|
+ receivetime.put("$lt", endTime);
|
|
|
+ for (String objectId : objectIdList) {
|
|
|
+ CriteriasObjDTO dto = new CriteriasObjDTO();
|
|
|
+ dto.setId(objectId);
|
|
|
+ dto.setCode(infoCode);
|
|
|
+ dto.setInterpolation(true);
|
|
|
+ dto.setPeriod(period);
|
|
|
+ dto.setReceivetime(receivetime);
|
|
|
+ criteriasObjDTOList.add(dto);
|
|
|
+ }
|
|
|
+ batchQueryPeriodDataDTO.setCriterias(criteriasObjDTOList);
|
|
|
+ PoemsFeignResponse<PoemsFeignResponse<PeriodDataInfoVO>> response = centerMiddlewareWebClient.getPeriodDataInfo(batchQueryPeriodDataDTO);
|
|
|
+ List<PoemsFeignResponse<PeriodDataInfoVO>> responseList = response.getContent();
|
|
|
+ if (!CollectionUtils.isEmpty(responseList)) {
|
|
|
+ for (PoemsFeignResponse<PeriodDataInfoVO> responseVo : responseList) {
|
|
|
+ List<PeriodDataInfoVO> periodDataInfoVOList = responseVo.getContent();
|
|
|
+ if (CollectionUtils.isEmpty(periodDataInfoVOList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (PeriodDataInfoVO vo : periodDataInfoVOList) {
|
|
|
+ if (null == vo.getData_value() || StringUtils.isEmpty(vo.getData_time())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Double data = dataMap.get(DateUtils.str2Date(vo.getData_time(), DateUtils.SDF_SECOND));
|
|
|
+ if (null == data) {
|
|
|
+ data = 0.0;
|
|
|
+ }
|
|
|
+ data = data + vo.getData_value();
|
|
|
+ dataMap.put(DateUtils.str2Date(vo.getData_time(), DateUtils.SDF_SECOND), data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询中台对象信息时异常:", e);
|
|
|
+ }
|
|
|
+ return dataMap;
|
|
|
+ }
|
|
|
+
|
|
|
}
|