haungxing
2 years ago
13 changed files with 273 additions and 65 deletions
@ -0,0 +1,47 @@ |
|||||||
|
package com.hnac.hzims.operational.alert.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.mp.base.BaseEntity; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("hzims_history_level_alarm") |
||||||
|
@EqualsAndHashCode(callSuper = false) |
||||||
|
@ApiModel(value = "数据中断告警对象") |
||||||
|
public class HistoryLevelAlarmEntity extends BaseEntity { |
||||||
|
|
||||||
|
@ApiModelProperty("ID") |
||||||
|
private Long id; |
||||||
|
|
||||||
|
@ApiModelProperty("站点编码") |
||||||
|
private String stationId; |
||||||
|
|
||||||
|
@ApiModelProperty("站点名称") |
||||||
|
private String stationName; |
||||||
|
|
||||||
|
@ApiModelProperty("告警编码") |
||||||
|
private Long alarmId; |
||||||
|
|
||||||
|
@ApiModelProperty("检查点") |
||||||
|
private String realId; |
||||||
|
|
||||||
|
@ApiModelProperty("告警开始时间") |
||||||
|
private Date alarmTime; |
||||||
|
|
||||||
|
@ApiModelProperty("告警类型") |
||||||
|
private String type; |
||||||
|
|
||||||
|
@ApiModelProperty("状态") |
||||||
|
private Integer status; |
||||||
|
|
||||||
|
@ApiModelProperty("告警原因") |
||||||
|
private String soeExplain; |
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
package com.hnac.hzims.operational.alert.controller; |
||||||
|
|
||||||
|
|
||||||
|
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.entity.HistoryLevelAlarmEntity; |
||||||
|
import com.hnac.hzims.operational.alert.service.HistoryLevelAlarmService; |
||||||
|
import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import io.swagger.annotations.ApiParam; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.boot.ctrl.BladeController; |
||||||
|
import org.springblade.core.log.annotation.ApiLog; |
||||||
|
import org.springblade.core.mp.support.Condition; |
||||||
|
import org.springblade.core.mp.support.Query; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.validation.Valid; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Api(tags = {"等级告警"}) |
||||||
|
@RestController |
||||||
|
@AllArgsConstructor |
||||||
|
@RequestMapping("/level/alarm") |
||||||
|
public class LevelAlarmController extends BladeController { |
||||||
|
|
||||||
|
private HistoryLevelAlarmService service; |
||||||
|
|
||||||
|
/** |
||||||
|
* 分页 |
||||||
|
*/ |
||||||
|
@ApiLog |
||||||
|
@GetMapping("/list") |
||||||
|
@ApiOperationSupport(order = 1) |
||||||
|
@ApiOperation(value = "分页", notes = "传入HistoryAbnormalAlarmEntity") |
||||||
|
public R<IPage<HistoryLevelAlarmEntity>> list(HistoryLevelAlarmEntity entity, Query query) { |
||||||
|
IPage<HistoryLevelAlarmEntity> pages = service.pageCondition(query, entity); |
||||||
|
return R.data(pages); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 删除 |
||||||
|
*/ |
||||||
|
@PostMapping("/remove") |
||||||
|
@ApiOperationSupport(order = 2) |
||||||
|
@ApiOperation(value = "逻辑删除", notes = "传入ids") |
||||||
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { |
||||||
|
return R.status(service.deleteLogic(Func.toLongList(ids))); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 智能告警数量: 时间范围当天 |
||||||
|
*/ |
||||||
|
@ApiLog |
||||||
|
@ApiOperation(value = "智能告警数量") |
||||||
|
@ApiOperationSupport(order = 3) |
||||||
|
@RequestMapping(value = "/count", method = {RequestMethod.GET, RequestMethod.POST}) |
||||||
|
public R<List<IntelligentAlarmCountVo>> count(){ |
||||||
|
return R.data(service.alarmCount()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
package com.hnac.hzims.operational.alert.mapper; |
||||||
|
|
||||||
|
import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; |
||||||
|
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author YSJ |
||||||
|
*/ |
||||||
|
public interface HistoryLevelAlarmMapper extends UserDataScopeBaseMapper<HistoryLevelAlarmEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,6 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="com.hnac.hzims.operational.alert.mapper.HistoryLevelAlarmMapper"> |
||||||
|
|
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,21 @@ |
|||||||
|
package com.hnac.hzims.operational.alert.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; |
||||||
|
import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
import org.springblade.core.mp.support.Query; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 等级告警数据查询 |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
public interface HistoryLevelAlarmService extends BaseService<HistoryLevelAlarmEntity> { |
||||||
|
|
||||||
|
|
||||||
|
IPage<HistoryLevelAlarmEntity> pageCondition(Query query, HistoryLevelAlarmEntity entity); |
||||||
|
|
||||||
|
List<IntelligentAlarmCountVo> alarmCount(); |
||||||
|
} |
@ -0,0 +1,106 @@ |
|||||||
|
package com.hnac.hzims.operational.alert.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; |
||||||
|
import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; |
||||||
|
import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; |
||||||
|
import com.hnac.hzims.operational.alert.mapper.HistoryLevelAlarmMapper; |
||||||
|
import com.hnac.hzims.operational.alert.service.AlarmHandleService; |
||||||
|
import com.hnac.hzims.operational.alert.service.HistoryLevelAlarmService; |
||||||
|
import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; |
||||||
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
||||||
|
import com.hnac.hzims.operational.station.service.IStationService; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
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.springblade.core.tool.utils.DateUtil; |
||||||
|
import org.springblade.core.tool.utils.ObjectUtil; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* 等级告警实现类 |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@Service |
||||||
|
@RequiredArgsConstructor |
||||||
|
public class HistoryLevelAlarmServiceImpl extends BaseServiceImpl<HistoryLevelAlarmMapper, HistoryLevelAlarmEntity> implements HistoryLevelAlarmService { |
||||||
|
|
||||||
|
|
||||||
|
private final IStationService stationService; |
||||||
|
|
||||||
|
private final AlarmHandleService handleServicel; |
||||||
|
|
||||||
|
/** |
||||||
|
* 列表查询 |
||||||
|
* @param query |
||||||
|
* @param entity |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public IPage<HistoryLevelAlarmEntity> pageCondition(Query query, HistoryLevelAlarmEntity entity) { |
||||||
|
LambdaQueryWrapper<HistoryLevelAlarmEntity> wrapper = new LambdaQueryWrapper(); |
||||||
|
wrapper.between(HistoryLevelAlarmEntity::getAlarmTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00", |
||||||
|
DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); |
||||||
|
if(ObjectUtil.isNotEmpty(entity.getType())){ |
||||||
|
wrapper.eq(HistoryLevelAlarmEntity::getType, entity.getType()); |
||||||
|
} |
||||||
|
if(ObjectUtil.isNotEmpty(entity.getStationId())){ |
||||||
|
wrapper.eq(HistoryLevelAlarmEntity::getStationId, entity.getStationId()); |
||||||
|
} |
||||||
|
return super.page(Condition.getPage(query), wrapper); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 告警数量:时间范围-当天 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public List<IntelligentAlarmCountVo> alarmCount() { |
||||||
|
// 步骤1.查询用户权限站点
|
||||||
|
List<StationEntity> stations = stationService.list(); |
||||||
|
if(CollectionUtil.isEmpty(stations)){ |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
// 步骤2. 过滤已处理等級告警
|
||||||
|
LambdaQueryWrapper<AlarmHandleEntity> handleWarpper = new LambdaQueryWrapper(); |
||||||
|
handleWarpper.between(AlarmHandleEntity::getCreateTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00", |
||||||
|
DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); |
||||||
|
handleWarpper.in(AlarmHandleEntity::getStationCode, stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); |
||||||
|
List<AlarmHandleEntity> handles = handleServicel.list(); |
||||||
|
|
||||||
|
// 步骤2.查询告警数据
|
||||||
|
LambdaQueryWrapper<HistoryLevelAlarmEntity> wrapper = new LambdaQueryWrapper(); |
||||||
|
wrapper.between(HistoryLevelAlarmEntity::getAlarmTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00", |
||||||
|
DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); |
||||||
|
wrapper.in(HistoryLevelAlarmEntity::getStationId, stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); |
||||||
|
wrapper.in(HistoryLevelAlarmEntity::getType,AbnormalAlarmConstant.TYPE_LIST); |
||||||
|
if(CollectionUtil.isNotEmpty(handles)){ |
||||||
|
wrapper.notIn(HistoryLevelAlarmEntity::getAlarmId,handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList())); |
||||||
|
} |
||||||
|
List<HistoryLevelAlarmEntity> levels = this.list(wrapper); |
||||||
|
|
||||||
|
// 步骤4.遍历获取
|
||||||
|
return AbnormalAlarmConstant.TYPE_LIST.stream().map(type->{ |
||||||
|
IntelligentAlarmCountVo count = new IntelligentAlarmCountVo(); |
||||||
|
count.setType(type); |
||||||
|
count.setName(AbnormalAlarmConstant.TYPE_NAMES[Integer.valueOf(type)]); |
||||||
|
if(CollectionUtil.isEmpty(levels)){ |
||||||
|
count.setCount(0L); |
||||||
|
}else{ |
||||||
|
count.setCount(levels.stream().filter(level->level.getType().equals(type)).count()); |
||||||
|
} |
||||||
|
return count; |
||||||
|
}).collect(Collectors.toList()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue