|
@@ -5,6 +5,7 @@ import com.bizmatics.common.core.util.DateUtils;
|
|
|
import com.bizmatics.common.spring.util.JsonUtils;
|
|
|
import com.bizmatics.model.HadDataLog;
|
|
|
import com.bizmatics.model.HtAnalogData;
|
|
|
+import com.bizmatics.model.Site;
|
|
|
import com.bizmatics.persistence.mapper.HtAnalogDataMapper;
|
|
|
import com.bizmatics.persistence.mapper.SiteMapper;
|
|
|
import com.bizmatics.service.HadDataLogService;
|
|
@@ -14,9 +15,13 @@ import com.bizmatics.service.util.Arith;
|
|
|
import com.bizmatics.service.util.SessionLocal;
|
|
|
import com.bizmatics.service.vo.*;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.lucene.index.IndexFormatTooNewException;
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -27,11 +32,9 @@ import java.util.stream.Collectors;
|
|
|
* @author ya
|
|
|
* @since 2021-07-07
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMapper, HtAnalogData> implements HtAnalogDataService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private HtAnalogDataMapper htAnalogDataMapper;
|
|
|
@Autowired
|
|
|
private SiteMapper siteMapper;
|
|
|
|
|
@@ -47,13 +50,14 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
List<Integer> idList = siteMapper.idList(userId, null);
|
|
|
//日
|
|
|
List<HadDataLog> byToday = getByToday(DateUtils.getDayStartTime(date), date);
|
|
|
- getEpp(byToday,idList,null,null);
|
|
|
+ hadCountVO.setDayCount(getEpp(byToday, idList, null, null));
|
|
|
//月
|
|
|
List<HadDataLog> byMonth = getByMonth(DateUtils.getFirstDayOfMonth(date), date);
|
|
|
- getEpp(byMonth,idList,null,null);
|
|
|
+ hadCountVO.setMonthCount(getEpp(byMonth, idList, null, null));
|
|
|
//年
|
|
|
List<HadDataLog> byYear = getByMonth(DateUtils.getBeginDayOfYear(date), date);
|
|
|
- getEpp(byYear,idList,null,null);
|
|
|
+ hadCountVO.setYearCount(getEpp(byYear, idList, null, null));
|
|
|
+
|
|
|
return hadCountVO;
|
|
|
}
|
|
|
|
|
@@ -80,18 +84,18 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
}
|
|
|
|
|
|
public List<HadDataLog> getByMonth(Date startTime,Date endTime){
|
|
|
- List<HadDataLog> startList = hadDataLogService.list(startTime,endTime);
|
|
|
- List<HadDataLog> endList = hadDataLogService.list(DateUtils.getDayStartTime(startTime),endTime);
|
|
|
- startList.addAll(endList);
|
|
|
- return startList;
|
|
|
+
|
|
|
+// List<HadDataLog> startList = hadDataLogService.list(startTime,endTime);
|
|
|
+// List<HadDataLog> endList = hadDataLogService.list(DateUtils.getDayStartTime(startTime),endTime);
|
|
|
+// startList.addAll(endList);
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public List<CommonIcoVO> selectTrendByDate(Date date,Integer siteId) {
|
|
|
- Integer userId = SessionLocal.getUserId();
|
|
|
List<CommonIcoVO> list = new ArrayList<>();
|
|
|
- List<Integer> idList = siteMapper.idList(userId, null);
|
|
|
+ List<Integer> idList = getSiteIdList(siteId);
|
|
|
list.add(getTrendOne("today", idList, DateUtils.getDayStartTime(date), date));
|
|
|
list.add(getTrendOne("yesterday", idList, DateUtils.addDays(date, -1), date));
|
|
|
return list;
|
|
@@ -115,8 +119,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
|
|
|
@Override
|
|
|
public HadCountVO getCountBySite(Integer siteId) {
|
|
|
+ List<Integer> siteIdList = getSiteIdList(siteId);
|
|
|
Date date = new Date();
|
|
|
- Integer userId = SessionLocal.getUserId();
|
|
|
//当日开始时间
|
|
|
Date firstDayOfDate = DateUtils.getDayStartTime(date);
|
|
|
//当月开始时间
|
|
@@ -124,12 +128,27 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
//当年开始时间
|
|
|
Date firstDayOfYear = DateUtils.getBeginDayOfYear(date);
|
|
|
HadCountVO hadCountVO = new HadCountVO();
|
|
|
-// hadCountVO.setDayCount(getElectricity(userId,siteId,firstDayOfDate,date));
|
|
|
-// hadCountVO.setMonthCount(getElectricity(userId,siteId,firstDayOfMonth,date));
|
|
|
-// hadCountVO.setYearCount(getElectricity(userId,siteId,firstDayOfYear,date));
|
|
|
-// hadCountVO.setLastDayCount(getElectricity(userId,siteId,DateUtils.addDays(firstDayOfDate, -1),DateUtils.addDays(date, -1)));
|
|
|
-// hadCountVO.setLastMonthCount(getElectricity(userId,siteId,DateUtils.addMonths(firstDayOfMonth, -1),DateUtils.addMonths(date, -1)));
|
|
|
-// hadCountVO.setLastYearCount(getElectricity(userId,siteId,DateUtils.addYears(firstDayOfYear, -1),DateUtils.addYears(date, -1)));
|
|
|
+ //今日
|
|
|
+ List<HadDataLog> byToday = getByToday(firstDayOfDate, date);
|
|
|
+ hadCountVO.setDayCount(getEpp(byToday,siteIdList,null,null));
|
|
|
+ //本月
|
|
|
+ List<HadDataLog> byToMonth = getByMonth(firstDayOfMonth, date);
|
|
|
+ hadCountVO.setMonthCount(getEpp(byToMonth,siteIdList,null,null));
|
|
|
+ //本年
|
|
|
+ List<HadDataLog> byToYear = getByMonth(firstDayOfYear, date);
|
|
|
+ hadCountVO.setYearCount(getEpp(byToYear,siteIdList,null,null));
|
|
|
+ //昨天
|
|
|
+ List<HadDataLog> lastDay = getByToday(DateUtils.addDays(firstDayOfDate, -1), DateUtils.addDays(date, -1));
|
|
|
+ Double lastDayEpp = getEpp(lastDay, siteIdList, null,null);
|
|
|
+ hadCountVO.setLastDayCount(lastDayEpp);
|
|
|
+ //上月
|
|
|
+ List<HadDataLog> lastMonth = getByMonth(DateUtils.addMonths(firstDayOfMonth, -1), DateUtils.addMonths(date, -1));
|
|
|
+ Double lastMonthEpp = getEpp(lastMonth, siteIdList, null,null);
|
|
|
+ hadCountVO.setLastMonthCount(lastMonthEpp);
|
|
|
+ //去年
|
|
|
+ List<HadDataLog> lastYear = getByMonth(DateUtils.addYears(firstDayOfYear, -1), DateUtils.addYears(date, -1));
|
|
|
+ Double lastYearEpp = getEpp(lastYear, siteIdList, null, null);
|
|
|
+ hadCountVO.setLastDayCount(lastYearEpp);
|
|
|
hadCountVO.setDayRadio(Optional.ofNullable(hadCountVO.getDayCount())
|
|
|
.filter(dayCount -> 0.00 != dayCount)
|
|
|
.map(dayCount -> Arith.div(hadCountVO.getLastDayCount(), dayCount))
|
|
@@ -170,14 +189,18 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
//尖
|
|
|
Double nToe = getEpp(byToday, idList, nine, eleven);
|
|
|
Double nTot = getEpp(byToday, idList, nineTeen, twoOne);
|
|
|
+ timeShareVO.setNeed(Arith.sub(nToe,nTot));
|
|
|
//高峰
|
|
|
Double eTot = getEpp(byToday, idList, eight, ten);
|
|
|
Double hnTot = getEpp(byToday, idList, oneEight, oneNine);
|
|
|
Double tTot = getEpp(byToday, idList, twoOne, twoThree);
|
|
|
+ timeShareVO.setPeak(Arith.sub(Arith.sub(eTot,hnTot),tTot));
|
|
|
//低谷
|
|
|
Double tTos = getEpp(byToday, idList, twoThree, seven);
|
|
|
+ timeShareVO.setGrain(tTos);
|
|
|
//平谷
|
|
|
Double oToo = getEpp(byToday, idList, oneTwo, oneSeven);
|
|
|
+ timeShareVO.setFlat(oToo);
|
|
|
return timeShareVO;
|
|
|
}
|
|
|
|
|
@@ -186,26 +209,33 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
List<Integer> idList = new ArrayList<>();
|
|
|
idList.add(siteId);
|
|
|
Date date = new Date();
|
|
|
- List<HadDataLog> hadDataLogList = getByToday(date, DateUtils.getLastDayOfMonth(new Date()));
|
|
|
+ List<HadDataLog> hadDataLogList = getByToday(date, DateUtils.getLastDayOfMonth(date));
|
|
|
List<Object> maxList = new ArrayList<>();
|
|
|
List<Object> minList = new ArrayList<>();
|
|
|
List<Object> avgList = new ArrayList<>();
|
|
|
List<Object> dateList = new ArrayList<>();
|
|
|
for (int i = 1; i <= Integer.parseInt(DateUtils.getDay(date)); i++) {
|
|
|
List<HadCrVO> hadCrVoS = new ArrayList<>();
|
|
|
+ AtomicReference<Double> count = new AtomicReference<>(0.00);
|
|
|
+ AtomicReference<Integer> size = new AtomicReference<>(0);
|
|
|
Date setDays = DateUtils.setDays(date, i);
|
|
|
Date dayStartTime = DateUtils.getDayStartTime(setDays);
|
|
|
Date dayEndTime = DateUtils.getDayEndTime(setDays);
|
|
|
- hadDataLogList.forEach(hadDataLog -> {
|
|
|
- List<HadDataLogVO> hadDateList = getHadDateList(hadDataLog, idList, dayStartTime, dayEndTime);
|
|
|
+ //筛选出日期范围数据
|
|
|
+ List<HadDataLog> hadDataLogs = hadDataLogList.stream()
|
|
|
+ .filter(hadDataLog -> hadDataLog.getDataTime().after(dayStartTime) && hadDataLog.getDataTime().after(dayEndTime))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ hadDataLogs.forEach(hadDataLog -> {
|
|
|
+ List<HadDataLogVO> hadDateList = getHadDateList(hadDataLog, idList, null, null);
|
|
|
+ count.updateAndGet(v -> v + hadDateList.stream().mapToDouble(HadDataLogVO::getDemand).sum());
|
|
|
+ size.updateAndGet(v -> v + hadDateList.size());
|
|
|
Map<Integer, DoubleSummaryStatistics> collect = hadDateList.stream()
|
|
|
.collect(Collectors.groupingBy(HadDataLogVO::getSiteId, Collectors.summarizingDouble(HadDataLogVO::getDemand)));
|
|
|
checkData(collect,hadCrVoS);
|
|
|
});
|
|
|
- Map<String, Double> map = baseMapper.selectMaxAndMinAndAvg(siteId, dayStartTime,dayEndTime);
|
|
|
- maxList.add(Optional.ofNullable(map).map(max -> max.get("demandMax")).orElse(0.00));
|
|
|
- minList.add(Optional.ofNullable(map).map(max -> max.get("demandMin")).orElse(0.00));
|
|
|
- avgList.add(Optional.ofNullable(map).map(max -> max.get("demandAvd")).orElse(0.00));
|
|
|
+ maxList.add(hadCrVoS.stream().max(Comparator.comparingDouble(HadCrVO::getHadMax)).map(HadCrVO::getHadMax).orElse(0.00));
|
|
|
+ maxList.add(hadCrVoS.stream().min(Comparator.comparingDouble(HadCrVO::getHadMin)).map(HadCrVO::getHadMin).orElse(0.00));
|
|
|
+ avgList.add(Arith.div(count.get(),size.get()));
|
|
|
dateList.add(DateUtils.getDay(setDays));
|
|
|
}
|
|
|
List<CommonIcoVO> list = new ArrayList<>();
|
|
@@ -218,6 +248,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
@Override
|
|
|
public List<CommonIcoVO> getElectricIco(Integer siteId, Date date) {
|
|
|
Integer userId = SessionLocal.getUserId();
|
|
|
+ List<Integer> siteIdList = new ArrayList<>();
|
|
|
+ siteIdList.add(siteId);
|
|
|
List<Object> iaList = new ArrayList<>();
|
|
|
iaList.add(0.00);
|
|
|
List<Object> ibList = new ArrayList<>();
|
|
@@ -232,16 +264,24 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
ucList.add(0.00);
|
|
|
List<Object> dateList = new ArrayList<>();
|
|
|
dateList.add("00:00:00");
|
|
|
+ List<HadDataLog> hadDataLogList = getByToday(date, DateUtils.getDayStartTime(date));
|
|
|
for (int i = 2; i < 24 ; i+=2) {
|
|
|
//结束时间
|
|
|
Date endTime = DateUtils.addHours(date, i);
|
|
|
- HtAnalogData htAnalogData = htAnalogDataMapper.selectByEndTime(date,endTime, siteId, userId);
|
|
|
- iaList.add(Optional.ofNullable(htAnalogData).map(had -> htAnalogData.getIa()).orElse(0.00));
|
|
|
- ibList.add(Optional.ofNullable(htAnalogData).map(had -> htAnalogData.getIb()).orElse(0.00));
|
|
|
- icList.add(Optional.ofNullable(htAnalogData).map(had -> htAnalogData.getIc()).orElse(0.00));
|
|
|
- uaList.add(Optional.ofNullable(htAnalogData).map(had -> htAnalogData.getUa()).orElse(0.00));
|
|
|
- ubList.add(Optional.ofNullable(htAnalogData).map(had -> htAnalogData.getUb()).orElse(0.00));
|
|
|
- ucList.add(Optional.ofNullable(htAnalogData).map(had -> htAnalogData.getUc()).orElse(0.00));
|
|
|
+ Date finalDate = date;
|
|
|
+ List<HadDataLogVO> maxHadList = new ArrayList<>();
|
|
|
+ Comparator<HadDataLogVO> comparator = Comparator.comparing(HadDataLogVO::getDataTime);
|
|
|
+ hadDataLogList.forEach(hadDataLog -> {
|
|
|
+ List<HadDataLogVO> hadDateList = getHadDateList(hadDataLog, siteIdList, finalDate, endTime);
|
|
|
+ hadDateList.stream().max(comparator).ifPresent(maxHadList::add);
|
|
|
+ });
|
|
|
+ Optional<HadDataLogVO> max = maxHadList.stream().max(comparator);
|
|
|
+ iaList.add(max.map(HadDataLogVO::getIa).orElse(0.00));
|
|
|
+ ibList.add(max.map(HadDataLogVO::getIb).orElse(0.00));
|
|
|
+ icList.add(max.map(HadDataLogVO::getIc).orElse(0.00));
|
|
|
+ uaList.add(max.map(HadDataLogVO::getUa).orElse(0.00));
|
|
|
+ ubList.add(max.map(HadDataLogVO::getUa).orElse(0.00));
|
|
|
+ ucList.add(max.map(HadDataLogVO::getUa).orElse(0.00));
|
|
|
date = endTime;
|
|
|
dateList.add(DateUtils.getTime(endTime));
|
|
|
}
|
|
@@ -255,6 +295,18 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public List<Integer> getSiteIdList(Integer siteId){
|
|
|
+ Integer userId = SessionLocal.getUserId();
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
+ if (null == siteId){
|
|
|
+ list = siteMapper.idList(userId, null);
|
|
|
+ }else {
|
|
|
+ list.add(siteId);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 求多个站点最大值减最小值的结果
|
|
|
* @param list
|