haungxing
12 months ago
25 changed files with 442 additions and 153 deletions
@ -0,0 +1,12 @@
|
||||
package com.hnac.hzims.scheduled.mapper.alarm; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.hnac.hzims.alarm.entity.AlarmEntity; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface AlarmQueryMapper extends BaseMapper<AlarmEntity> { |
||||
|
||||
|
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.hnac.hzims.scheduled.service.alarm; |
||||
|
||||
import com.hnac.hzims.alarm.entity.AlarmEntity; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface AlarmQueryService extends BaseService<AlarmEntity> { |
||||
|
||||
List<String> bells(List<String> codes); |
||||
|
||||
List<String> aborts(List<String> codes); |
||||
} |
@ -0,0 +1,74 @@
|
||||
package com.hnac.hzims.scheduled.service.alarm.impl; |
||||
|
||||
import cn.hutool.core.stream.CollectorUtil; |
||||
import com.baomidou.dynamic.datasource.annotation.DS; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.hnac.hzims.alarm.constants.AlarmConstants; |
||||
import com.hnac.hzims.alarm.entity.AlarmEntity; |
||||
import com.hnac.hzims.scheduled.mapper.alarm.AlarmQueryMapper; |
||||
import com.hnac.hzims.scheduled.service.alarm.AlarmQueryService; |
||||
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.StringUtil; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@AllArgsConstructor |
||||
@Service |
||||
@Slf4j |
||||
@DS("alarm") |
||||
public class AlarmQueryServiceImpl extends BaseServiceImpl<AlarmQueryMapper, AlarmEntity> implements AlarmQueryService { |
||||
|
||||
/** |
||||
* 查询站点铃铛 |
||||
* @param codes |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public List<String> bells(List<String> codes) { |
||||
List<AlarmEntity> alarms = this.list(Wrappers.<AlarmEntity>lambdaQuery() |
||||
.in(AlarmEntity::getStationId,codes) |
||||
.eq(AlarmEntity::getIsSmallBell,0) |
||||
); |
||||
if(CollectionUtil.isEmpty(alarms)){ |
||||
return new ArrayList<>(); |
||||
} |
||||
return alarms.stream().map(AlarmEntity::getStationId).distinct().collect(Collectors.toList()); |
||||
} |
||||
|
||||
/** |
||||
* 查询站点数据中断 |
||||
* @param codes |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public List<String> aborts(List<String> codes) { |
||||
List<AlarmEntity> alarms = this.list(Wrappers.<AlarmEntity>lambdaQuery() |
||||
.in(AlarmEntity::getStationId,codes) |
||||
.eq(AlarmEntity::getAlarmSource, AlarmConstants.HZ3000_ALARM) |
||||
.in(AlarmEntity::getAlarmType, Arrays.asList(AlarmConstants.INTERRUPT,AlarmConstants.ABNORMAL)) |
||||
); |
||||
if(CollectionUtil.isEmpty(alarms)){ |
||||
return new ArrayList<>(); |
||||
} |
||||
return alarms.stream().collect(Collectors.groupingBy(AlarmEntity::getStationId)).entrySet().stream().map(entry->{ |
||||
// 站点最近的一条数据中断、数据异常告警
|
||||
AlarmEntity alarm = entry.getValue().stream().sorted(Comparator.comparing(AlarmEntity::getCreateTime).reversed()).collect(Collectors.toList()).get(0); |
||||
// 状态为中断
|
||||
if(alarm.getAlarmStatus().equals(0)){ |
||||
return alarm.getStationId(); |
||||
} |
||||
return ""; |
||||
}).filter(StringUtil::isBlank).distinct().collect(Collectors.toList()); |
||||
} |
||||
} |
@ -0,0 +1,5 @@
|
||||
<?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.alarm.show.mapper.AlarmMapper"> |
||||
|
||||
</mapper> |
Loading…
Reference in new issue