diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/show/vo/HandleQueryVo.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/show/vo/HandleQueryVo.java new file mode 100644 index 0000000..cc57119 --- /dev/null +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/show/vo/HandleQueryVo.java @@ -0,0 +1,30 @@ +package com.hnac.hzims.operational.alert.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @author ysj + * @date 2023/03/17 10:02:33 + * @version 4.0.0 + */ +@Data +public class HandleQueryVo { + + @ApiModelProperty("处理人") + private String stationCode; + + @ApiModelProperty("处理人") + private Long handleUser; + + @ApiModelProperty("开始时间") + private Date startTime; + + @ApiModelProperty("结束时间") + private Date endTime; + + @ApiModelProperty("处理类型:1-延后 2-误报 3-缺陷 4-检修") + private Long handleWay; +} diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionDetailVo.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionDetailVo.java new file mode 100644 index 0000000..0217b0d --- /dev/null +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionDetailVo.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.business.interruption.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; +import java.util.List; + +/** + * @author ysj + */ +@Data +@ApiModel(value = "数据中断统计", description = "数据中断统计对象") +public class InterruptionDetailVo { + + @ApiModelProperty("站点编码") + private String stationId; + + @ApiModelProperty("站点名称") + private String stationName; + + @ApiModelProperty("中断类型") + private String type; + + @ApiModelProperty("中断时长") + private Double duration; + + @ApiModelProperty("开始时间") + private Date start; + + @ApiModelProperty("结束时间") + private Date end; +} \ No newline at end of file diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionParamVo.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionParamVo.java new file mode 100644 index 0000000..8d830dd --- /dev/null +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionParamVo.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.business.interruption.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author ysj + */ +@Data +@ApiModel(value = "数据中断参数对象", description = "数据中断参数对象") +public class InterruptionParamVo { + + @ApiModelProperty("开始时间") + private String startTime; + + @ApiModelProperty("结束时间") + private String endTime; + + @ApiModelProperty("中断类型") + private List type; + + @ApiModelProperty("站点编码") + private String stationId; +} \ No newline at end of file diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionStationVo.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionStationVo.java new file mode 100644 index 0000000..bf3e834 --- /dev/null +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionStationVo.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.business.interruption.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author ysj + */ +@Data +@ApiModel(value = "数据中断站点", description = "数据中断站点") +public class InterruptionStationVo { + + @ApiModelProperty("站点编码") + private String stationId; + + @ApiModelProperty("站点名称") + private String stationName; +} \ No newline at end of file diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionVo.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionVo.java new file mode 100644 index 0000000..eb64279 --- /dev/null +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionVo.java @@ -0,0 +1,25 @@ +package com.hnac.hzims.business.interruption.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author ysj + */ +@Data +@ApiModel(value = "数据中断统计", description = "数据中断统计对象") +public class InterruptionVo { + + @ApiModelProperty("站点编码") + private String stationId; + + @ApiModelProperty("站点名称") + private String stationName; + + @ApiModelProperty("中断次数") + private Integer count; + + @ApiModelProperty("中断时长") + private Double duration; +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java index 2963c71..b42a329 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java @@ -3,12 +3,11 @@ package com.hnac.hzims.alarm.show.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.alarm.show.service.AlarmHandleService; import com.hnac.hzims.alarm.config.vo.AlarmHandleVo; +import com.hnac.hzims.alarm.show.service.AlarmHandleService; import com.hnac.hzims.common.logs.annotation.OperationAnnotation; import com.hnac.hzims.common.logs.enums.BusinessType; import com.hnac.hzims.common.logs.enums.OperatorType; -import com.hnac.hzims.operational.alert.vo.HandleQueryVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; @@ -55,7 +54,7 @@ public class AlarmHandleController extends BladeController { @OperationAnnotation(moduleName = "分页查询告警处理记录", title = "查询告警处理记录", operatorType = OperatorType.MOBILE, businessType = BusinessType.GENCODE, action = "分页") - public R> list(HandleQueryVo param, Query query) { + public R> list(com.hnac.hzims.operational.alert.vo.HandleQueryVo param, Query query) { IPage pages = service.pageCondition(query, param); return R.data(pages); } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/controller/InterruptionController.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/controller/InterruptionController.java index ea7c9f4..8d12717 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/controller/InterruptionController.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/controller/InterruptionController.java @@ -1,12 +1,27 @@ package com.hnac.hzims.business.interruption.controller; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.business.interruption.service.InterruptionService; +import com.hnac.hzims.business.interruption.vo.InterruptionDetailVo; +import com.hnac.hzims.business.interruption.vo.InterruptionParamVo; +import com.hnac.hzims.business.interruption.vo.InterruptionStationVo; +import com.hnac.hzims.business.interruption.vo.InterruptionVo; +import com.hnac.hzims.operational.station.entity.StationEntity; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** * @author ysj */ @@ -16,5 +31,30 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/interruption") public class InterruptionController extends BladeController { + private final InterruptionService interruptionService; + + + @GetMapping("/interruptionStations") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "分页查询") + public R> interruptionStations() { + return R.data(interruptionService.interruptionStations()); + } + + @GetMapping("/page") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "分页查询") + public R> list(InterruptionParamVo param, Query query) { + return R.data(interruptionService.pageCondition(Condition.getPage(query), param)); + } + + + @GetMapping("/detail") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "分页查询") + public R> detail(InterruptionParamVo param, Query query) { + return R.data(interruptionService.pageConditionDetail(Condition.getPage(query), param)); + } + } \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.java index 0dc35e1..e804cd3 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.java @@ -2,10 +2,14 @@ package com.hnac.hzims.business.interruption.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.hnac.hzims.business.interruption.entity.InterruptionEntity; +import com.hnac.hzims.business.interruption.vo.InterruptionStationVo; + +import java.util.List; /** * @author ysj */ public interface InterruptionMapper extends BaseMapper { + List interruptionStations(); } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.xml b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.xml index fda3915..c4c302e 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.xml +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.xml @@ -3,4 +3,9 @@ + diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/InterruptionService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/InterruptionService.java index 621fd98..3d0d6a2 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/InterruptionService.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/InterruptionService.java @@ -1,11 +1,24 @@ package com.hnac.hzims.business.interruption.service; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.business.interruption.entity.InterruptionEntity; +import com.hnac.hzims.business.interruption.vo.InterruptionDetailVo; +import com.hnac.hzims.business.interruption.vo.InterruptionParamVo; +import com.hnac.hzims.business.interruption.vo.InterruptionStationVo; +import com.hnac.hzims.business.interruption.vo.InterruptionVo; +import com.hnac.hzims.operational.station.entity.StationEntity; import org.springblade.core.mp.base.BaseService; +import java.util.List; + /** * @author ysj */ public interface InterruptionService extends BaseService { + List interruptionStations(); + + IPage pageCondition(IPage page, InterruptionParamVo param); + + IPage pageConditionDetail(IPage page, InterruptionParamVo param); } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/impl/InterruptionServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/impl/InterruptionServiceImpl.java index 9767bb6..1d64e9e 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/impl/InterruptionServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/impl/InterruptionServiceImpl.java @@ -1,13 +1,28 @@ package com.hnac.hzims.business.interruption.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.business.interruption.entity.InterruptionEntity; import com.hnac.hzims.business.interruption.mapper.InterruptionMapper; import com.hnac.hzims.business.interruption.service.InterruptionService; +import com.hnac.hzims.business.interruption.vo.InterruptionDetailVo; +import com.hnac.hzims.business.interruption.vo.InterruptionParamVo; +import com.hnac.hzims.business.interruption.vo.InterruptionStationVo; +import com.hnac.hzims.business.interruption.vo.InterruptionVo; +import com.hnac.hzims.operational.station.entity.StationEntity; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; +import java.util.stream.Collectors; + /** * @author ysj */ @@ -16,4 +31,178 @@ import org.springframework.stereotype.Service; @Slf4j public class InterruptionServiceImpl extends BaseServiceImpl implements InterruptionService { -} \ No newline at end of file + /** + * 数据中断站点查询 + * @return + */ + @Override + public List interruptionStations() { + return this.baseMapper.interruptionStations(); + } + + /** + * 数据中断统计 + * @param page + * @param param + * @return + */ + @Override + public IPage pageCondition(IPage page, InterruptionParamVo param) { + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.lambda().in(InterruptionEntity::getType,param.getType()); + queryWrapper.lambda().ge(InterruptionEntity::getCreateTime,param.getStartTime()); + queryWrapper.lambda().le(InterruptionEntity::getCreateTime,param.getEndTime()); + queryWrapper.lambda().orderByAsc(InterruptionEntity::getAlarmTime); + if(!StringUtil.isEmpty(param.getStationId())){ + queryWrapper.lambda().eq(InterruptionEntity::getStationId,param.getStationId()); + } + List interruptions = this.list(queryWrapper); + if(CollectionUtil.isEmpty(interruptions)){ + return page; + } + // 根据站点分组 + Map> map = interruptions.stream().collect(Collectors.groupingBy(InterruptionEntity::getStationId)); + List list = map.entrySet().stream().map(entry -> { + InterruptionVo interruption = new InterruptionVo(); + interruption.setStationId(entry.getKey()); + interruption.setStationName(entry.getValue().get(0).getStationName()); + interruption.setCount((int) entry.getValue().stream().filter(o-> o.getStatus().equals(0)).count()); + long time = innterruptionTime(entry.getValue().stream().sorted(Comparator.comparing(InterruptionEntity::getAlarmTime)).collect(Collectors.toList()), DateUtil.parse(param.getStartTime(),DateUtil.PATTERN_DATETIME),DateUtil.parse(param.getEndTime(),DateUtil.PATTERN_DATETIME)); + interruption.setDuration(BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + return interruption; + }).collect(Collectors.toList()); + page.setTotal(map.size()); + page.setRecords(list.stream().sorted(Comparator.comparing(InterruptionVo::getStationId)).skip((page.getCurrent() - 1) * page.getSize()).limit(page.getSize()).collect(Collectors.toList())); + return page; + } + + /** + * 获取中断时长 + * @param interruptions + * @param startDate + * @param endDate + * @return + */ + private long innterruptionTime(List interruptions, Date startDate, Date endDate) { + if(interruptions.size() == 1){ + // 一直中断 + if(interruptions.get(0).getStatus() == 0){ + return endDate.getTime() - interruptions.get(0).getAlarmTime().getTime(); + } + // 一直恢复 + return 0; + } + long time=0; + // 遍历累计中断时长 + for(int i = 0; i< interruptions.size() ; i++){ + // 记录为恢复状态 就计算到下次关机的时间差 + if(interruptions.get(i).getStatus() == 1){ + continue; + } + Date endTime,startTime = interruptions.get(i).getAlarmTime(); + // 遍历至最后一条数据,累计至当前时间 + if(i == interruptions.size() - 1){ + endTime = endDate; + }else { + endTime = interruptions.get(i+1).getAlarmTime(); + } + time += endTime.getTime() - startTime.getTime(); + } + return time; + } + + /** + * 站点数据中断统计详情 + * @param page + * @return + */ + @Override + public IPage pageConditionDetail(IPage page, InterruptionParamVo param) { + // 获取中断告警数据 + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.lambda().in(InterruptionEntity::getType,param.getType()); + queryWrapper.lambda().ge(InterruptionEntity::getCreateTime,param.getStartTime()); + queryWrapper.lambda().le(InterruptionEntity::getCreateTime,param.getEndTime()); + queryWrapper.lambda().orderByAsc(InterruptionEntity::getAlarmTime); + if(!StringUtil.isEmpty(param.getStationId())){ + queryWrapper.lambda().eq(InterruptionEntity::getStationId,param.getStationId()); + } + List interruptions = this.list(queryWrapper); + if(CollectionUtil.isEmpty(interruptions)){ + new ArrayList<>(); + } + // 数据整理 + List details = this.collation(interruptions,param.getStartTime(),param.getEndTime()); + page.setTotal(details.size()); + page.setRecords(details.stream().sorted(Comparator.comparing(InterruptionDetailVo::getStart)).skip((page.getCurrent() - 1) * page.getSize()).limit(page.getSize()).collect(Collectors.toList())); + return page; + } + + /** + * 告警数据整理 + * @param interruptions + * @return + */ + private List collation(List interruptions,String startTime,String endTime) { + List collations = new ArrayList<>(); + // 遍历数据 + for(int i = 0; i< interruptions.size() ; i++){ + // 第一个数据保存下来 + if(i == 0){ + collations.add(interruptions.get(i)); + continue; + } + // 遍历数据状态 + Integer status = interruptions.get(i).getStatus(); + // 上一条数据状态 + Integer up_status = interruptions.get(i-1).getStatus(); + if(status.equals(up_status)){ + continue; + } + collations.add(interruptions.get(i)); + } + // 返回数据集合 + List details = new ArrayList<>(); + int j = 0; + if(1 == collations.get(0).getStatus()){ + j = 1; + for(;j < collations.size() ;j++){ + if(j % 2 == 1){ + InterruptionDetailVo detail = new InterruptionDetailVo(); + detail.setType(collations.get(j).getType()); + detail.setStationId(collations.get(j).getStationId()); + detail.setStationName(collations.get(j).getStationName()); + detail.setStart(collations.get(j).getAlarmTime()); + if( j + 1 == collations.size()){ + detail.setEnd(DateUtil.parse(endTime,DateUtil.PATTERN_DATETIME)); + }else{ + detail.setEnd(collations.get(j + 1).getAlarmTime()); + } + long time = detail.getEnd().getTime() - detail.getStart().getTime(); + detail.setDuration(BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + details.add(detail); + } + } + }else{ + for(;j < collations.size() ;j++){ + if(j % 2 == 0){ + InterruptionDetailVo detail = new InterruptionDetailVo(); + detail.setType(collations.get(j).getType()); + detail.setStationId(collations.get(j).getStationId()); + detail.setStationName(collations.get(j).getStationName()); + detail.setStart(collations.get(j).getAlarmTime()); + if( j + 1 == collations.size()){ + detail.setEnd(DateUtil.parse(endTime,DateUtil.PATTERN_DATETIME)); + }else{ + detail.setEnd(collations.get(j + 1).getAlarmTime()); + } + long time = detail.getEnd().getTime() - detail.getStart().getTime(); + detail.setDuration(BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + details.add(detail); + } + } + } + return details; + } + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/InterruptionAlarmServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/InterruptionAlarmServiceImpl.java index 4b1e416..d49f4bf 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/InterruptionAlarmServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/InterruptionAlarmServiceImpl.java @@ -82,6 +82,7 @@ public class InterruptionAlarmServiceImpl extends BaseServiceImpl