|
|
@ -2,7 +2,6 @@ package com.hnac.hzims.alarm.show.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
|
|
|
import com.hnac.hzims.alarm.entity.AlarmEntity; |
|
|
|
import com.hnac.hzims.alarm.entity.AlarmEntity; |
|
|
|
import com.hnac.hzims.alarm.show.service.AlarmService; |
|
|
|
import com.hnac.hzims.alarm.show.service.AlarmService; |
|
|
|
import com.hnac.hzims.alarm.show.service.FdpAlarmService; |
|
|
|
import com.hnac.hzims.alarm.show.service.FdpAlarmService; |
|
|
@ -16,15 +15,13 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
@ -64,47 +61,22 @@ public class FdpAlarmServiceImpl implements FdpAlarmService { |
|
|
|
return JSONObject.toJSONString(map); |
|
|
|
return JSONObject.toJSONString(map); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 接收服务推送消息 |
|
|
|
* 转换接收服务推送消息 |
|
|
|
* @param message |
|
|
|
* @param message |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void receiveMessage(String message) { |
|
|
|
public List<AlarmEntity> receiveMessage(String message) { |
|
|
|
// 对象转换
|
|
|
|
// 对象转换
|
|
|
|
List<FdpAlarmVo> alarms = JSONObject.parseArray(message, FdpAlarmVo.class); |
|
|
|
List<FdpAlarmVo> alarms = JSONObject.parseArray(message, FdpAlarmVo.class); |
|
|
|
if(CollectionUtil.isEmpty(alarms)){ |
|
|
|
if (CollectionUtil.isEmpty(alarms)) { |
|
|
|
return; |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
} |
|
|
|
// R<List<StationEntity>> listAll = stationClient.getListAll();
|
|
|
|
List<AlarmEntity> res = alarms.stream().map(s -> { |
|
|
|
// if (!listAll.isSuccess()||CollectionUtil.isEmpty(listAll.getData())){
|
|
|
|
AlarmEntity entity = getAlarmEntity(s); |
|
|
|
// throw new ServiceException("FdpAlarm send message is null");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// List<StationEntity> stations = listAll.getData();
|
|
|
|
|
|
|
|
// 查询当天已经记录的告警
|
|
|
|
|
|
|
|
List<AlarmEntity> historys = alarmService.list(Wrappers.<AlarmEntity>lambdaQuery(). |
|
|
|
|
|
|
|
ge(AlarmEntity::getCreateTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00") |
|
|
|
|
|
|
|
.eq(AlarmEntity::getAlarmSource, EARLY_WARNING)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 数据过滤
|
|
|
|
|
|
|
|
List<AlarmEntity> entitys = alarms.stream() |
|
|
|
|
|
|
|
.filter(alarm -> CollectionUtil.isNotEmpty(historys) || !historys.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList()).contains(alarm.getFaultId())) |
|
|
|
|
|
|
|
.map(item->{ |
|
|
|
|
|
|
|
//转换对象
|
|
|
|
|
|
|
|
AlarmEntity entity = getAlarmEntity(item); |
|
|
|
|
|
|
|
// 短信
|
|
|
|
|
|
|
|
CompletableFuture.runAsync(() -> messageService.message(entity)); |
|
|
|
|
|
|
|
// web/app消息推送
|
|
|
|
|
|
|
|
CompletableFuture.runAsync(() -> messageService.webAppMessage(entity)); |
|
|
|
|
|
|
|
// 微信公众号推送
|
|
|
|
|
|
|
|
CompletableFuture.runAsync(() -> messageService.weChatMessage(entity)); |
|
|
|
|
|
|
|
return entity; |
|
|
|
return entity; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
if(CollectionUtil.isEmpty(entitys)){ |
|
|
|
return res; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 批量保存
|
|
|
|
|
|
|
|
alarmService.saveBatch(entitys); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private AlarmEntity getAlarmEntity(FdpAlarmVo item) { |
|
|
|
private AlarmEntity getAlarmEntity(FdpAlarmVo item) { |
|
|
@ -116,10 +88,13 @@ public class FdpAlarmServiceImpl implements FdpAlarmService { |
|
|
|
entity.setAlarmStatus(Integer.valueOf(String.valueOf(item.getStatus()))); |
|
|
|
entity.setAlarmStatus(Integer.valueOf(String.valueOf(item.getStatus()))); |
|
|
|
entity.setStationId(item.getStation()); |
|
|
|
entity.setStationId(item.getStation()); |
|
|
|
entity.setAlarmStatus(EARLY_WARNING); |
|
|
|
entity.setAlarmStatus(EARLY_WARNING); |
|
|
|
|
|
|
|
entity.setTenantId("200000"); |
|
|
|
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation()); |
|
|
|
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation()); |
|
|
|
if (stationByCode.isSuccess()&& ObjectUtils.isNotEmpty(stationByCode.getData())){ |
|
|
|
if (stationByCode.isSuccess()&& ObjectUtils.isNotEmpty(stationByCode.getData())){ |
|
|
|
entity.setCreateDept(stationByCode.getData().getCreateDept()); |
|
|
|
entity.setCreateDept(stationByCode.getData().getCreateDept()); |
|
|
|
|
|
|
|
entity.setStationName(stationByCode.getData().getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
return entity; |
|
|
|
return entity; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|