Browse Source

#数据中断告警移植

zhongwei
yang_shj 11 months ago
parent
commit
5ea36ba95c
  1. 30
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/show/vo/HandleQueryVo.java
  2. 34
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionDetailVo.java
  3. 27
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionParamVo.java
  4. 19
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionStationVo.java
  5. 25
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/vo/InterruptionVo.java
  6. 5
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java
  7. 40
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/controller/InterruptionController.java
  8. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.java
  9. 5
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.xml
  10. 13
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/InterruptionService.java
  11. 191
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/service/impl/InterruptionServiceImpl.java
  12. 1
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/InterruptionAlarmServiceImpl.java

30
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;
}

34
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;
}

27
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<String> type;
@ApiModelProperty("站点编码")
private String stationId;
}

19
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;
}

25
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;
}

5
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<IPage<AlarmHandleVo>> list(HandleQueryVo param, Query query) {
public R<IPage<AlarmHandleVo>> list(com.hnac.hzims.operational.alert.vo.HandleQueryVo param, Query query) {
IPage<AlarmHandleVo> pages = service.pageCondition(query, param);
return R.data(pages);
}

40
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<List<InterruptionStationVo>> interruptionStations() {
return R.data(interruptionService.interruptionStations());
}
@GetMapping("/page")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "分页查询")
public R<IPage<InterruptionVo>> list(InterruptionParamVo param, Query query) {
return R.data(interruptionService.pageCondition(Condition.getPage(query), param));
}
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "分页查询")
public R<IPage<InterruptionDetailVo>> detail(InterruptionParamVo param, Query query) {
return R.data(interruptionService.pageConditionDetail(Condition.getPage(query), param));
}
}

4
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<InterruptionEntity> {
List<InterruptionStationVo> interruptionStations();
}

5
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/business/interruption/mapper/InterruptionMapper.xml

@ -3,4 +3,9 @@
<mapper namespace="com.hnac.hzims.business.interruption.mapper.InterruptionMapper">
<select id="interruptionStations" resultType="com.hnac.hzims.business.interruption.vo.InterruptionStationVo">
SELECT STATION_ID,STATION_NAME
FROM HZIMS_INTERRUPTION_ALARM
GROUP BY STATION_ID,STATION_NAME
</select>
</mapper>

13
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<InterruptionEntity> {
List<InterruptionStationVo> interruptionStations();
IPage<InterruptionVo> pageCondition(IPage<InterruptionVo> page, InterruptionParamVo param);
IPage<InterruptionDetailVo> pageConditionDetail(IPage<InterruptionDetailVo> page, InterruptionParamVo param);
}

191
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<InterruptionMapper, InterruptionEntity> implements InterruptionService {
}
/**
* 数据中断站点查询
* @return
*/
@Override
public List<InterruptionStationVo> interruptionStations() {
return this.baseMapper.interruptionStations();
}
/**
* 数据中断统计
* @param page
* @param param
* @return
*/
@Override
public IPage<InterruptionVo> pageCondition(IPage<InterruptionVo> page, InterruptionParamVo param) {
QueryWrapper<InterruptionEntity> 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<InterruptionEntity> interruptions = this.list(queryWrapper);
if(CollectionUtil.isEmpty(interruptions)){
return page;
}
// 根据站点分组
Map<String,List<InterruptionEntity>> map = interruptions.stream().collect(Collectors.groupingBy(InterruptionEntity::getStationId));
List<InterruptionVo> 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<InterruptionEntity> 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<InterruptionDetailVo> pageConditionDetail(IPage<InterruptionDetailVo> page, InterruptionParamVo param) {
// 获取中断告警数据
QueryWrapper<InterruptionEntity> 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<InterruptionEntity> interruptions = this.list(queryWrapper);
if(CollectionUtil.isEmpty(interruptions)){
new ArrayList<>();
}
// 数据整理
List<InterruptionDetailVo> 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<InterruptionDetailVo> collation(List<InterruptionEntity> interruptions,String startTime,String endTime) {
List<InterruptionEntity> 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<InterruptionDetailVo> 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;
}
}

1
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<InterruptionAl
entity.setStationId(soeStations.get(0).getCode());
entity.setStationName(soeStations.get(0).getName());
entity.setCreateDept(soeStations.get(0).getRefDept());
entity.setTenantId(soeStations.get(0).getTenantId());
}
entity.setAlarmId(soe.getId());
entity.setRealId(soe.getRealId());

Loading…
Cancel
Save