暂态事件处理
This commit is contained in:
@@ -8,6 +8,32 @@
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-db</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-microservice</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-mq</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<artifactId>zl-event-api</artifactId>
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.zlevent.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.zlevent.api.fallback.EventClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.CS_ZL_EVENT_BOOT, path = "/event", fallbackFactory = EventClientFallbackFactory.class,contextId = "event")
|
||||
public interface EventFeignClient {
|
||||
|
||||
@PostMapping("/analysis")
|
||||
HttpResult<String> analysis(AppEventMessage appEventMessage);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.zlevent.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.zlevent.api.EventFeignClient;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class EventClientFallbackFactory implements FallbackFactory<EventFeignClient> {
|
||||
@Override
|
||||
public EventFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new EventFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> analysis(AppEventMessage appEventMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","数据解析",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.njcn.zlevent.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件表
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
@Data
|
||||
@TableName("cs_event")
|
||||
public class CsEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 监测点id
|
||||
*/
|
||||
private String lineId;
|
||||
|
||||
/**
|
||||
* 事件名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 展示名称
|
||||
*/
|
||||
private String showName;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.njcn.zlevent.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件详情表
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
@Data
|
||||
@TableName("cs_event_detail")
|
||||
public class CsEventDetail {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 暂态事件id
|
||||
*/
|
||||
private String pid;
|
||||
|
||||
/**
|
||||
* 指标名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 指标别名
|
||||
*/
|
||||
private String showName;
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 数值
|
||||
*/
|
||||
private Double data;
|
||||
|
||||
/**
|
||||
* 相别
|
||||
*/
|
||||
private String phasic;
|
||||
|
||||
|
||||
}
|
||||
@@ -20,6 +20,15 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-db</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-web</artifactId>
|
||||
@@ -39,6 +48,31 @@
|
||||
<artifactId>common-db</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-mq</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>cs-device-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>stat-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>zl-event-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>system-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.njcn.zlevent.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.zlevent.service.IEventService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/14 9:23
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/event")
|
||||
@Api(tags = "暂态事件处理")
|
||||
@AllArgsConstructor
|
||||
public class EventController extends BaseController {
|
||||
|
||||
private final IEventService eventService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/analysis")
|
||||
@ApiOperation("事件解析")
|
||||
@ApiImplicitParam(name = "appEventMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> analysis(@RequestBody AppEventMessage appEventMessage){
|
||||
String methodDescribe = getMethodDescribe("analysis");
|
||||
eventService.analysis(appEventMessage);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.zlevent.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @crateTime 2023/8/23 9:59
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/wave")
|
||||
@Api(tags = "录波处理")
|
||||
@AllArgsConstructor
|
||||
public class WaveController extends BaseController {
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/analysis")
|
||||
@ApiOperation("录波解析")
|
||||
@ApiImplicitParam(name = "appAutoDataMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> analysis(){
|
||||
String methodDescribe = getMethodDescribe("analysis");
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.njcn.zlevent.handler;
|
||||
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.validation.Validator;
|
||||
|
||||
/**
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @date 2023年08月23日 09:41
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class MqttMessageHandler {
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
@Autowired
|
||||
Validator validator;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.njcn.zlevent.listener;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.pojo.dto.EpdDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年04月02日 14:31
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
|
||||
|
||||
@Resource
|
||||
private EpdFeignClient epdFeignClient;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
super(listenerContainer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 针对redis数据失效事件,进行数据处理
|
||||
* 注意message.toString()可以获取失效的key
|
||||
*/
|
||||
@Override
|
||||
@Order(0)
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
if (StringUtils.isBlank(message.toString())) {
|
||||
return;
|
||||
}
|
||||
//判断失效的key
|
||||
String expiredKey = message.toString();
|
||||
if(expiredKey.equals(AppRedisKey.ELE_EPD_PQD)){
|
||||
Map<String,String> map = new HashMap<>();
|
||||
List<EpdDTO> list = epdFeignClient.findAll().getData();
|
||||
if (CollectionUtil.isEmpty(list)){
|
||||
throw new BusinessException(StatResponseEnum.DICT_NULL);
|
||||
}
|
||||
list.forEach(item->{
|
||||
map.put(item.getDictName(),item.getTableName());
|
||||
});
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.ELE_EPD_PQD,map,3600L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.zlevent.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEventDetail;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件详情表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
public interface CsEventDetailMapper extends BaseMapper<CsEventDetail> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.zlevent.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEvent;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
public interface CsEventMapper extends BaseMapper<CsEvent> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.zlevent.pojo.po.CsEventDetail;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件详情表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
public interface ICsEventDetailService extends IService<CsEventDetail> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.zlevent.pojo.po.CsEvent;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
public interface ICsEventService extends IService<CsEvent> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
public interface IEventService {
|
||||
|
||||
/**
|
||||
* 解析事件数据
|
||||
* @param
|
||||
*/
|
||||
void analysis(AppEventMessage appEventMessage);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.zlevent.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.zlevent.mapper.CsEventDetailMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEventDetail;
|
||||
import com.njcn.zlevent.service.ICsEventDetailService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件详情表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
@Service
|
||||
public class CsEventDetailServiceImpl extends ServiceImpl<CsEventDetailMapper, CsEventDetail> implements ICsEventDetailService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.zlevent.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.zlevent.mapper.CsEventMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEvent;
|
||||
import com.njcn.zlevent.service.ICsEventService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
@Service
|
||||
public class CsEventServiceImpl extends ServiceImpl<CsEventMapper, CsEvent> implements ICsEventService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.njcn.zlevent.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.zlevent.pojo.po.CsEvent;
|
||||
import com.njcn.zlevent.pojo.po.CsEventDetail;
|
||||
import com.njcn.zlevent.service.ICsEventDetailService;
|
||||
import com.njcn.zlevent.service.ICsEventService;
|
||||
import com.njcn.zlevent.service.IEventService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/14 9:32
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class EventServiceImpl implements IEventService {
|
||||
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
private final ICsEventService csEventService;
|
||||
|
||||
private final ICsEventDetailService csEventDetailService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppEventMessage appEventMessage) {
|
||||
List<CsEvent> list1 = new ArrayList<>();
|
||||
List<CsEventDetail> list2 = new ArrayList<>();
|
||||
//获取监测点id
|
||||
String lineId = null;
|
||||
Object object1 = redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId());
|
||||
if (Objects.isNull(object1)){
|
||||
lineInfo(appEventMessage.getId());
|
||||
}
|
||||
if (Objects.equals(appEventMessage.getDid(),1)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appEventMessage.getDid(),2)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
//处理事件数据
|
||||
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
String id = IdUtil.fastSimpleUUID();
|
||||
//事件入库
|
||||
CsEvent csEvent = new CsEvent();
|
||||
csEvent.setId(id);
|
||||
csEvent.setLineId(lineId);
|
||||
csEvent.setName(item.getName());
|
||||
csEvent.setShowName(epdFeignClient.findByName(item.getName()).getData().getShowName());
|
||||
csEvent.setStartTime(timeFormat(item.getDataTimeSec(),item.getDataTimeUSec()));
|
||||
List<AppEventMessage.Param> params = item.getParam();
|
||||
for (AppEventMessage.Param item2 : params) {
|
||||
CsEventDetail csEventDetail = new CsEventDetail();
|
||||
csEventDetail.setPid(id);
|
||||
csEventDetail.setName(item2.getName());
|
||||
csEventDetail.setShowName(epdFeignClient.findByName(item2.getName()).getData().getShowName());
|
||||
csEventDetail.setType(item2.getType());
|
||||
csEventDetail.setUnit(item2.getUnit());
|
||||
if (Objects.equals(item2.getName(),"Evt_VVaPhas")){
|
||||
csEventDetail.setPhasic(item2.getData().toString());
|
||||
} else {
|
||||
csEventDetail.setData(Double.parseDouble(item2.getData().toString()));
|
||||
}
|
||||
list2.add(csEventDetail);
|
||||
}
|
||||
list1.add(csEvent);
|
||||
}
|
||||
csEventService.saveBatch(list1);
|
||||
csEventDetailService.saveBatch(list2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存监测点相关信息
|
||||
*/
|
||||
public void lineInfo(String id) {
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
List<CsLinePO> lineList = csLineFeignClient.findByNdid(id).getData();
|
||||
if (CollectionUtil.isEmpty(lineList)){
|
||||
throw new BusinessException(StatResponseEnum.LINE_NULL);
|
||||
}
|
||||
for (CsLinePO item : lineList) {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.isNull(dictData)){
|
||||
throw new BusinessException(StatResponseEnum.DICT_NULL);
|
||||
}
|
||||
if (Objects.equals(dictData.getCode(), DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
map.put(0,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.LOAD_SIDE.getCode())){
|
||||
map.put(1,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.LINE_POSITION+id,map,600L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间转换
|
||||
*/
|
||||
public LocalDateTime timeFormat(Long time1, Long time2) {
|
||||
//设置格式
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String timeText = format.format(time1 * 1000);
|
||||
String time = timeText + "." + time2;
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
|
||||
return LocalDateTime.parse(time, fmt);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user