1.治理暂态事件、波形文件记录解析功能;日志记录功能

2.设备上线、掉线日志记录
This commit is contained in:
2023-09-08 16:04:31 +08:00
parent d537021ffd
commit f91670786f
19 changed files with 503 additions and 69 deletions

View File

@@ -0,0 +1,47 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 设备状态日志表,记录设备掉线上线的情况
* </p>
*
* @author xuyang
* @since 2023-09-08
*/
@Data
@TableName("cs_device_online_logs")
public class CsDeviceOnlineLogs {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* 设备识别码
*/
private String ndid;
/**
* 掉线时间
*/
private LocalDateTime offlineTime;
/**
* 上线时间
*/
private LocalDateTime onlineTime;
}

View File

@@ -0,0 +1,54 @@
package com.njcn.access.controller;
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
import com.njcn.access.service.ICsDevModelService;
import com.njcn.access.service.ICsDeviceOnlineLogsService;
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.annotation.ReturnMsg;
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.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.njcn.web.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;
/**
* <p>
* 设备状态日志表,记录设备掉线上线的情况 前端控制器
* </p>
*
* @author xuyang
* @since 2023-09-08
*/
@Slf4j
@RestController
@RequestMapping("/csDeviceOnlineLogs")
@Api(tags = "设备上线日志表")
@AllArgsConstructor
public class CsDeviceOnlineLogsController extends BaseController {
private final ICsDeviceOnlineLogsService csDeviceOnlineLogsService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/find")
@ApiOperation("find")
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
public HttpResult<CsDeviceOnlineLogs> devRegister(@RequestParam String nDid){
CsDeviceOnlineLogs vo = csDeviceOnlineLogsService.findLastData(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, "123");
}
}

View File

@@ -16,8 +16,10 @@ import com.njcn.access.pojo.dto.*;
import com.njcn.access.pojo.dto.file.FileDto;
import com.njcn.access.pojo.dto.heart.HeartBeatDto;
import com.njcn.access.pojo.param.ReqAndResParam;
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
import com.njcn.access.pojo.po.CsLineModel;
import com.njcn.access.pojo.po.CsTopic;
import com.njcn.access.service.ICsDeviceOnlineLogsService;
import com.njcn.access.service.ICsEquipmentDeliveryService;
import com.njcn.access.service.ICsLineModelService;
import com.njcn.access.service.ICsTopicService;
@@ -50,6 +52,7 @@ import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -87,6 +90,8 @@ public class MqttMessageHandler {
private final AppFileStreamMessageTemplate appFileStreamMessageTemplate;
private final ICsDeviceOnlineLogsService onlineLogsService;
@Autowired
Validator validator;
@@ -309,6 +314,21 @@ public class MqttMessageHandler {
//修改装置状态
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.ACCESS.getCode());
csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode());
//记录设备上线
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
CsDeviceOnlineLogs csDeviceOnlineLogs = new CsDeviceOnlineLogs();
if(Objects.isNull(record)) {
csDeviceOnlineLogs.setNdid(nDid);
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
onlineLogsService.save(csDeviceOnlineLogs);
} else {
LocalDateTime time = record.getOfflineTime();
if (!Objects.isNull(time)){
csDeviceOnlineLogs.setNdid(nDid);
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
onlineLogsService.save(csDeviceOnlineLogs);
}
}
} else {
log.info(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage());
logDto.setResult(0);

View File

@@ -1,6 +1,8 @@
package com.njcn.access.listener;
import com.njcn.access.enums.AccessEnum;
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
import com.njcn.access.service.ICsDeviceOnlineLogsService;
import com.njcn.access.service.ICsEquipmentDeliveryService;
import com.njcn.access.service.ICsTopicService;
import com.njcn.access.service.impl.CsDeviceServiceImpl;
@@ -17,6 +19,7 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -43,6 +46,9 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
@Resource
private CsLogsFeignClient csLogsFeignClient;
@Resource
private ICsDeviceOnlineLogsService onlineLogsService;
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
super(listenerContainer);
}
@@ -74,6 +80,10 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
logDto.setOperate("装置掉线,装置为:" + nDid);
csLogsFeignClient.addUserLog(logDto);
//记录装置下线日志
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
record.setOfflineTime(LocalDateTime.now());
onlineLogsService.updateById(record);
//立马发起接入请求
String version = csTopicService.getVersion(nDid);
log.info("装置掉线立马发送接入请求,接入失败则进入定时接入任务");

View File

@@ -0,0 +1,16 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
/**
* <p>
* 设备状态日志表,记录设备掉线上线的情况 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-09-08
*/
public interface CsDeviceOnlineLogsMapper extends BaseMapper<CsDeviceOnlineLogs> {
}

View File

@@ -0,0 +1,23 @@
package com.njcn.access.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
/**
* <p>
* 设备状态日志表,记录设备掉线上线的情况 服务类
* </p>
*
* @author xuyang
* @since 2023-09-08
*/
public interface ICsDeviceOnlineLogsService extends IService<CsDeviceOnlineLogs> {
/**
* 根据nDid查询最新的一条记录
* @param nDid
* @return
*/
CsDeviceOnlineLogs findLastData(String nDid);
}

View File

@@ -0,0 +1,25 @@
package com.njcn.access.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.mapper.CsDeviceOnlineLogsMapper;
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
import com.njcn.access.service.ICsDeviceOnlineLogsService;
import org.springframework.stereotype.Service;
/**
* <p>
* 设备状态日志表,记录设备掉线上线的情况 服务实现类
* </p>
*
* @author xuyang
* @since 2023-09-08
*/
@Service
public class CsDeviceOnlineLogsServiceImpl extends ServiceImpl<CsDeviceOnlineLogsMapper, CsDeviceOnlineLogs> implements ICsDeviceOnlineLogsService {
@Override
public CsDeviceOnlineLogs findLastData(String nDid) {
return this.lambdaQuery().eq(CsDeviceOnlineLogs::getNdid,nDid).orderByDesc(CsDeviceOnlineLogs::getOnlineTime).last("LIMIT 1").one();
}
}