|
@@ -2,21 +2,25 @@ package com.energy.manage.service.service.homepage.impl;
|
|
|
|
|
|
import com.energy.manage.common.enums.TypeRelationEnum;
|
|
|
import com.energy.manage.common.po.windrelation.WindRelationPO;
|
|
|
+import com.energy.manage.service.domain.vo.analysis.AnalysisOptionRecordsVo;
|
|
|
import com.energy.manage.service.domain.vo.analysis.AnalysisResultVo;
|
|
|
import com.energy.manage.service.domain.vo.homepage.HomePageVo;
|
|
|
import com.energy.manage.service.domain.vo.windexceptioncount.WindExceptionCountVo;
|
|
|
-import com.energy.manage.service.domain.vo.windrelation.WindRelationVo;
|
|
|
+import com.energy.manage.service.mappers.analysis.AnalysisOptionRecordsMapper;
|
|
|
import com.energy.manage.service.mappers.analysis.AnalysisResultMapper;
|
|
|
import com.energy.manage.service.mappers.windexceptioncount.WindExceptionCountMapper;
|
|
|
import com.energy.manage.service.mappers.windrelation.WindRelationMapper;
|
|
|
import com.energy.manage.service.service.homepage.HomePageService;
|
|
|
-import com.energy.manage.service.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.function.Predicate;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author chy
|
|
@@ -36,6 +40,9 @@ public class HomePageServiceImpl implements HomePageService {
|
|
|
@Autowired
|
|
|
private WindExceptionCountMapper exceptionCountMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AnalysisOptionRecordsMapper analysisOptionRecordsMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 驾驶舱首页查询
|
|
@@ -43,7 +50,7 @@ public class HomePageServiceImpl implements HomePageService {
|
|
|
* @param codeType
|
|
|
*/
|
|
|
@Override
|
|
|
- public HomePageVo query(String codeNumber, String codeType) {
|
|
|
+ public HomePageVo queryStatistics(String codeNumber, String codeType) {
|
|
|
//返回实体对象
|
|
|
HomePageVo homePageVo = new HomePageVo();
|
|
|
//风场
|
|
@@ -60,13 +67,34 @@ public class HomePageServiceImpl implements HomePageService {
|
|
|
}
|
|
|
//设置未分析、分析中、已分析数目
|
|
|
setAnalysisCount(homePageVo,fieldCodes);
|
|
|
- //设置异常数
|
|
|
- setErrCount(homePageVo,fieldCodes);
|
|
|
- //设置异常信息
|
|
|
-// setErrInfo(homePageVo,fieldCodes);
|
|
|
+ //设置异常数、异常信息
|
|
|
+ setErrCountAndInfo(homePageVo,fieldCodes);
|
|
|
return homePageVo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取操作记录
|
|
|
+ * @param codeNumber
|
|
|
+ * @param codeType
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<AnalysisOptionRecordsVo> queryOptionRecords(String codeNumber, String codeType){
|
|
|
+ List<AnalysisOptionRecordsVo> voList = new ArrayList<>();
|
|
|
+ //风场
|
|
|
+ List<String> fieldCodes = new ArrayList<>();
|
|
|
+ //根据类型判断获取风场code
|
|
|
+ if(codeType.equals(TypeRelationEnum.COMPANY_NUMBER.getCode())){
|
|
|
+ getFieldCodeList(Arrays.asList(codeNumber), fieldCodes);
|
|
|
+ }else{
|
|
|
+ fieldCodes.add(codeNumber);
|
|
|
+ }
|
|
|
+ //如果风场code为空,则不设置
|
|
|
+ if(CollectionUtils.isEmpty(fieldCodes)){
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+ return analysisOptionRecordsMapper.selectAllByTimeDesc(fieldCodes);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 递归获取风场code
|
|
@@ -123,7 +151,7 @@ public class HomePageServiceImpl implements HomePageService {
|
|
|
* @param homePageVo
|
|
|
* @param fieldCodes
|
|
|
*/
|
|
|
- public void setErrCount(HomePageVo homePageVo, List<String> fieldCodes){
|
|
|
+ public void setErrCountAndInfo(HomePageVo homePageVo, List<String> fieldCodes){
|
|
|
List<WindExceptionCountVo> exceptionCounts = exceptionCountMapper.selectByfieldCodes(fieldCodes);
|
|
|
//风机异常数
|
|
|
Set<String> engineCodes = new HashSet<>();
|
|
@@ -136,7 +164,9 @@ public class HomePageServiceImpl implements HomePageService {
|
|
|
homePageVo.setErrCounrt(homePageVo.getErrCounrt() + item.getErrCount());
|
|
|
//异常处理数
|
|
|
handleErrCount.addAndGet(item.getHandleErrCount());
|
|
|
+ //设备异常数
|
|
|
engineCodes.add(item.getEngineCode());
|
|
|
+ //叠加当月异常数
|
|
|
if(isCurrentMonth(item.getCreateTime())){
|
|
|
errCountCurrentMonth.addAndGet(item.getErrCount());
|
|
|
}
|
|
@@ -147,16 +177,30 @@ public class HomePageServiceImpl implements HomePageService {
|
|
|
homePageVo.setErrCountInCurrentMonth(errCountCurrentMonth.get());
|
|
|
//设置异常设备数
|
|
|
homePageVo.setErrDeviceCount(engineCodes.size());
|
|
|
+ //过滤属性风机编号相同的元素
|
|
|
+ exceptionCounts = exceptionCounts.stream().distinct().filter(distinctByKey(WindExceptionCountVo :: getEngineCode)).collect(Collectors.toList());
|
|
|
+ homePageVo.setErrList(exceptionCounts);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 过滤器
|
|
|
+ * @param keyExtractor
|
|
|
+ * @param <T>
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor){
|
|
|
+ Map<Object,Boolean> seen = new ConcurrentHashMap<>();
|
|
|
+ return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断是否是当月
|
|
|
- * @param createTime
|
|
|
+ * @param sourceTime
|
|
|
* @return
|
|
|
*/
|
|
|
- private Boolean isCurrentMonth(Date createTime){
|
|
|
+ private Boolean isCurrentMonth(Date sourceTime){
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(createTime);
|
|
|
+ calendar.setTime(sourceTime);
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
return calendar.get(Calendar.MONTH) == now.get(Calendar.MONTH);
|
|
|
}
|