|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package com.hnac.hzims.operational.alert.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; |
|
|
|
|
import com.hnac.hzims.operational.alert.mapper.HistoryAbnormalAlarmMapper; |
|
|
|
@ -10,12 +12,18 @@ import com.hnac.hzims.operational.station.service.IStationService;
|
|
|
|
|
import com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import net.logstash.logback.encoder.org.apache.commons.lang3.ObjectUtils; |
|
|
|
|
import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.data.domain.Page; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -56,4 +64,91 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl<HistoryAbno
|
|
|
|
|
page.setRecords(result); |
|
|
|
|
return page; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 统计告警时长 |
|
|
|
|
* @param query |
|
|
|
|
* @param entity |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public IPage<HistoryAbnormalAlarmVo> getAlarmTime(Query query, HistoryAbnormalAlarmEntity entity) { |
|
|
|
|
List<HistoryAbnormalAlarmVo> historyAbnormalAlarmVos= this.baseMapper.getAlarmEntity(entity.getType(),entity.getStationName(),entity.getStartTime(),entity.getEndTime()); |
|
|
|
|
if (historyAbnormalAlarmVos==null){ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
//赋值空的endTime
|
|
|
|
|
if(ObjectUtils.isNotEmpty(entity.getEndTime())){ |
|
|
|
|
historyAbnormalAlarmVos.stream().filter(s->s.getEndTime()==null).forEach(s->s.setEndTime(entity.getEndTime())); |
|
|
|
|
}else { |
|
|
|
|
historyAbnormalAlarmVos.stream().filter(s -> s.getEndTime() == null).forEach(s -> s.setEndTime(new Date())); |
|
|
|
|
} |
|
|
|
|
List<HistoryAbnormalAlarmVo> voList = historyAbnormalAlarmVos.parallelStream().map(s -> { |
|
|
|
|
s.setTimes((s.getEndTime().getTime() - s.getStartTime().getTime())); |
|
|
|
|
return s; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
//次数统计
|
|
|
|
|
Map<String, Long> timesList = voList.stream().collect(Collectors.groupingBy(HistoryAbnormalAlarmEntity::getStationName, |
|
|
|
|
Collectors.counting())); |
|
|
|
|
//时间统计
|
|
|
|
|
Map<String, Long> durationList = voList.stream().collect(Collectors.groupingBy(HistoryAbnormalAlarmEntity::getStationName, |
|
|
|
|
Collectors.summingLong(HistoryAbnormalAlarmVo::getTimes))); |
|
|
|
|
|
|
|
|
|
List<HistoryAbnormalAlarmVo> res=new ArrayList<>(); |
|
|
|
|
for (Map.Entry<String, Long> entry : durationList.entrySet()) { |
|
|
|
|
//累计时长
|
|
|
|
|
double v = BigDecimal.valueOf(entry.getValue() / (1000 * 60 * 60.00)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
|
HistoryAbnormalAlarmVo historyAbnormalAlarmVo = new HistoryAbnormalAlarmVo(); |
|
|
|
|
historyAbnormalAlarmVo.setDuration(v); |
|
|
|
|
String key = entry.getKey(); |
|
|
|
|
historyAbnormalAlarmVo.setStationName(key); |
|
|
|
|
historyAbnormalAlarmVo.setTimes(timesList.get(key)); |
|
|
|
|
if(StringUtils.isNotEmpty(entity.getType())){ |
|
|
|
|
historyAbnormalAlarmVo.setType(entity.getType()); |
|
|
|
|
} |
|
|
|
|
res.add(historyAbnormalAlarmVo); |
|
|
|
|
} |
|
|
|
|
//根据电站名字排序
|
|
|
|
|
res=res.stream(). |
|
|
|
|
sorted(Comparator.comparing(HistoryAbnormalAlarmVo::getStationName)) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
IPage<HistoryAbnormalAlarmVo> page = Condition.getPage(query); |
|
|
|
|
page.setTotal(res.size()); |
|
|
|
|
if (query==null){ |
|
|
|
|
page.setRecords(res); |
|
|
|
|
}else { |
|
|
|
|
if (res.size()>query.getCurrent()* query.getSize()) { |
|
|
|
|
page.setRecords(res.subList((query.getCurrent() - 1) * query.getSize(), query.getCurrent() * query.getSize())); |
|
|
|
|
}else { |
|
|
|
|
page.setRecords(res.subList((query.getCurrent() - 1) * query.getSize(), res.size())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return page; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private QueryWrapper<HistoryAbnormalAlarmEntity> getAlarmEntityQueryWrapper(HistoryAbnormalAlarmEntity entity) { |
|
|
|
|
QueryWrapper<HistoryAbnormalAlarmEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
if (entity.getStationName()!=null) { |
|
|
|
|
queryWrapper.lambda().eq(HistoryAbnormalAlarmEntity::getStationName, entity.getStationName()); |
|
|
|
|
} |
|
|
|
|
if (entity.getType()!=null) { |
|
|
|
|
queryWrapper.lambda().eq(HistoryAbnormalAlarmEntity::getType, entity.getType()); |
|
|
|
|
} |
|
|
|
|
if (entity.getStartTime()!=null) { |
|
|
|
|
queryWrapper.lambda().le(HistoryAbnormalAlarmEntity::getStartTime, entity.getStartTime()); |
|
|
|
|
} |
|
|
|
|
if (entity.getEndTime()!=null) { |
|
|
|
|
queryWrapper.lambda().ge(HistoryAbnormalAlarmEntity::getStartTime, entity.getEndTime()); |
|
|
|
|
} |
|
|
|
|
return queryWrapper; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IPage<HistoryAbnormalAlarmEntity> queryByEntity(HistoryAbnormalAlarmEntity entity,Query query) { |
|
|
|
|
QueryWrapper<HistoryAbnormalAlarmEntity> alarmEntityQueryWrapper = getAlarmEntityQueryWrapper(entity); |
|
|
|
|
IPage<HistoryAbnormalAlarmEntity> historyAbnormalAlarmEntityIPage = this.baseMapper.selectPage(Condition.getPage(query), alarmEntityQueryWrapper); |
|
|
|
|
return historyAbnormalAlarmEntityIPage; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|