From f299201904584031340978e43e4c176f8862211d Mon Sep 17 00:00:00 2001 From: tyty Date: Wed, 15 Mar 2023 13:54:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0-=E5=8E=82=E7=AB=99=E9=80=9A?= =?UTF-8?q?=E8=AE=AF=E4=B8=AD=E6=96=AD=E5=91=8A=E8=AD=A6=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alert/controller/AbnormalAlarmController.java | 21 +++++ .../alert/mapper/HistoryAbnormalAlarmMapper.java | 2 + .../alert/mapper/HistoryAbnormalAlarmMapper.xml | 19 ++++- .../alert/service/HistoryAbnormalAlarmService.java | 4 + .../impl/HistoryAbnormalAlarmServiceImpl.java | 99 +++++++++++++++++++++- .../station/vo/HistoryAbnormalAlarmVo.java | 8 ++ 6 files changed, 150 insertions(+), 3 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java index 668f298..1b9fdf3 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; +import com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -25,7 +26,27 @@ import javax.validation.Valid; public class AbnormalAlarmController extends BladeController { private final HistoryAbnormalAlarmService service; + /** + * 统计通讯中断时间 + */ + @GetMapping("/statisticsTime") + @ApiOperationSupport(order = 2) + @ApiOperation(value = "统计通讯中断时间", notes = "传入imsDutyMainEntity") + public R> statisticsTime(HistoryAbnormalAlarmEntity entity, Query query) { + IPage pages = service.getAlarmTime(query,entity); + return R.data(pages); + } + /** + * 统计通讯中断二级目录查询 + */ + @GetMapping("/queryByEntity") + @ApiOperationSupport(order = 2) + @ApiOperation(value = "统计通讯中断二级目录查询", notes = "传入imsDutyMainEntity") + public R> queryByEntity(HistoryAbnormalAlarmEntity entity, Query query) { + IPage pages = service.queryByEntity(entity,query); + return R.data(pages); + } /** * 详情 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java index be67201..3f330b4 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java @@ -19,4 +19,6 @@ public interface HistoryAbnormalAlarmMapper extends UserDataScopeBaseMapper selectPageList(IPage page, String type, List stations); + + List getAlarmEntity(@Param("type") String type,@Param("stationName") String stationName,@Param("startTime") Date startTime,@Param("endTime") Date endTime); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml index 76d3599..a8e7014 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml @@ -11,7 +11,7 @@ + + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java index 33670db..11145a6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java @@ -18,4 +18,8 @@ public interface HistoryAbnormalAlarmService extends BaseService list(IPage page, String type); + + IPage getAlarmTime(Query query, HistoryAbnormalAlarmEntity entity); + + IPage queryByEntity(HistoryAbnormalAlarmEntity entity,Query query); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java index 5fa834f..efdc489 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java @@ -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 getAlarmTime(Query query, HistoryAbnormalAlarmEntity entity) { + List 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 voList = historyAbnormalAlarmVos.parallelStream().map(s -> { + s.setTimes((s.getEndTime().getTime() - s.getStartTime().getTime())); + return s; + }).collect(Collectors.toList()); + //次数统计 + Map timesList = voList.stream().collect(Collectors.groupingBy(HistoryAbnormalAlarmEntity::getStationName, + Collectors.counting())); + //时间统计 + Map durationList = voList.stream().collect(Collectors.groupingBy(HistoryAbnormalAlarmEntity::getStationName, + Collectors.summingLong(HistoryAbnormalAlarmVo::getTimes))); + + List res=new ArrayList<>(); + for (Map.Entry 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 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 getAlarmEntityQueryWrapper(HistoryAbnormalAlarmEntity entity) { + QueryWrapper 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 queryByEntity(HistoryAbnormalAlarmEntity entity,Query query) { + QueryWrapper alarmEntityQueryWrapper = getAlarmEntityQueryWrapper(entity); + IPage historyAbnormalAlarmEntityIPage = this.baseMapper.selectPage(Condition.getPage(query), alarmEntityQueryWrapper); + return historyAbnormalAlarmEntityIPage; + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HistoryAbnormalAlarmVo.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HistoryAbnormalAlarmVo.java index 93a460a..5f71f64 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HistoryAbnormalAlarmVo.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HistoryAbnormalAlarmVo.java @@ -1,9 +1,17 @@ package com.hnac.hzims.operational.station.vo; +import com.baomidou.mybatisplus.annotation.TableField; import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class HistoryAbnormalAlarmVo extends HistoryAbnormalAlarmEntity{ + @TableField(exist=false) + @ApiModelProperty("告警次数") + private Long times; + @TableField(exist=false) + @ApiModelProperty("告警时长") + private Double duration; }