1.治理暂态事件、波形文件记录解析功能;日志记录功能
2.设备上线、掉线日志记录
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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("装置掉线立马发送接入请求,接入失败则进入定时接入任务");
|
||||
|
||||
@@ -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> {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.njcn.zlevent.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_event_logs")
|
||||
public class CsEventLogs {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 设备识别码
|
||||
*/
|
||||
private String ndid;
|
||||
|
||||
/**
|
||||
* 文件名称(全路径)
|
||||
*/
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 解析状态(0:失败 1:成功)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 解析完成时间
|
||||
*/
|
||||
private LocalDateTime completeTime;
|
||||
|
||||
/**
|
||||
* 波形文件起始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 波形结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.njcn.zlevent.controller;
|
||||
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理暂态文件解析日志 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-09-08
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/csEventLogs")
|
||||
@Api(tags = "暂态文件日志处理")
|
||||
@AllArgsConstructor
|
||||
@ApiIgnore
|
||||
public class CsEventLogsController extends BaseController {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.njcn.zlevent.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEventLogs;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理暂态文件解析日志 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-09-08
|
||||
*/
|
||||
public interface CsEventLogsMapper extends BaseMapper<CsEventLogs
|
||||
> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.zlevent.pojo.po.CsEventLogs;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理暂态文件解析日志 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-09-08
|
||||
*/
|
||||
public interface ICsEventLogsService extends IService<CsEventLogs> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.zlevent.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.zlevent.mapper.CsEventLogsMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEventLogs;
|
||||
import com.njcn.zlevent.service.ICsEventLogsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理暂态文件解析日志 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-09-08
|
||||
*/
|
||||
@Service
|
||||
public class CsEventLogsServiceImpl extends ServiceImpl<CsEventLogsMapper, CsEventLogs> implements ICsEventLogsService {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.njcn.zlevent.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
|
||||
@@ -115,7 +115,6 @@ public class CsWaveServiceImpl implements ICsWaveService {
|
||||
time -= 8 * 3600;
|
||||
// 将millisecond转换为长整型,并乘以1000以获取微秒
|
||||
long millisecondValue = millisecond.longValue() * 1000;
|
||||
// long millisecondValue = Long.parseLong(String.valueOf(millisecond))*1000;
|
||||
// 计算最终时间
|
||||
long finalTime = subtleTime + millisecondValue;
|
||||
// 如果finalTime大于等于1000000,将startTime增加1秒,finalTime减去1000000
|
||||
|
||||
@@ -72,6 +72,7 @@ public class EventServiceImpl implements IEventService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppEventMessage appEventMessage) {
|
||||
//todo 这边到时候装置事件、暂态事件需要分开处理
|
||||
List<CsEventPO> list1 = new ArrayList<>();
|
||||
List<String> records = new ArrayList<String>();
|
||||
List<CsEventUserPO> list2 = new ArrayList<>();
|
||||
|
||||
@@ -21,8 +21,11 @@ import com.njcn.zlevent.param.CsEventParam;
|
||||
import com.njcn.zlevent.pojo.dto.FileInfoDto;
|
||||
import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
||||
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
||||
import com.njcn.zlevent.pojo.po.CsEventLogs;
|
||||
import com.njcn.zlevent.service.ICsEventLogsService;
|
||||
import com.njcn.zlevent.service.ICsEventService;
|
||||
import com.njcn.zlevent.service.IFileService;
|
||||
import com.njcn.zlevent.utils.FileCheckUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.json.JSONObject;
|
||||
@@ -33,6 +36,10 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -57,6 +64,8 @@ public class FileServiceImpl implements IFileService {
|
||||
|
||||
private final ICsEventService csEventService;
|
||||
|
||||
private final ICsEventLogsService csEventLogsService;
|
||||
|
||||
@Override
|
||||
public void analysisFileInfo(AppFileMessage appFileMessage) {
|
||||
if (Objects.equals(appFileMessage.getCode(), AccessEnum.SUCCESS.getCode())){
|
||||
@@ -73,7 +82,7 @@ public class FileServiceImpl implements IFileService {
|
||||
} else {
|
||||
int total = (int)Math.ceil(fileSize*1.0/range) ;
|
||||
for (int i = 0; i < total; i++) {
|
||||
askFileStream(appFileMessage.getId(),mid,fileName,i*range,range-1);
|
||||
askFileStream(appFileMessage.getId(),mid,fileName,i*range,range);
|
||||
mid++;
|
||||
}
|
||||
fileInfoDto.setNumber(mid-1);
|
||||
@@ -101,11 +110,16 @@ public class FileServiceImpl implements IFileService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysisFileStream(AppFileMessage appFileMessage) {
|
||||
//日志记录
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
csEventLogs.setNdid(appFileMessage.getId());
|
||||
csEventLogs.setFileName(appFileMessage.getMsg().getName());
|
||||
try {
|
||||
//todo 目前文件先只处理暂态事件的,后续有其他文件再做处理
|
||||
String fileName = appFileMessage.getMsg().getName();
|
||||
if(fileName.contains(".cfg") || fileName.contains(".dat")) {
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
|
||||
FileStreamDto fileStreamDto = new FileStreamDto();
|
||||
String filePath;
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
@@ -124,16 +138,25 @@ public class FileServiceImpl implements IFileService {
|
||||
if(fileInfoDto.getNumber() == 1) {
|
||||
//直接解析文件
|
||||
filePath = fileStream(1,null,appFileMessage.getMsg().getData(),fileName,appFileMessage.getId());
|
||||
log.info(fileName + "解析成功");
|
||||
redisUtil.delete(fileName);
|
||||
//波形文件关联事件
|
||||
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
|
||||
correlateEvents(fileInfoDto,filePath);
|
||||
csEventLogs.setStatus(1);
|
||||
csEventLogs.setRemark("当前文件1帧,全部收到,解析成功!");
|
||||
csEventLogs.setCompleteTime(LocalDateTime.now());
|
||||
csEventLogs.setStartTime(LocalDateTime.parse(fileInfoDto.getStartTime(), fmt));
|
||||
csEventLogs.setEndTime(LocalDateTime.parse(fileInfoDto.getEndTime(), fmt));
|
||||
} else {
|
||||
//缓存文件
|
||||
map.put(appFileMessage.getMid(),appFileMessage.getMsg().getData());
|
||||
fileStreamDto.setMap(map);
|
||||
redisUtil.saveByKeyWithExpire(fileName, fileStreamDto, 3600L);
|
||||
csEventLogs.setStatus(1);
|
||||
csEventLogs.setRemark("当前文件"+fileInfoDto.getNumber()+"帧,这是第"+appFileMessage.getMid()+"帧,记录成功!");
|
||||
csEventLogs.setCompleteTime(LocalDateTime.now());
|
||||
csEventLogs.setStartTime(LocalDateTime.parse(fileInfoDto.getStartTime(), fmt));
|
||||
csEventLogs.setEndTime(LocalDateTime.parse(fileInfoDto.getEndTime(), fmt));
|
||||
}
|
||||
} else {
|
||||
//分帧传递数据,需要校验收到的文件个数
|
||||
@@ -141,38 +164,43 @@ public class FileServiceImpl implements IFileService {
|
||||
Map<Integer,String> l1 = fileStreamDto.getMap();
|
||||
l1.put(appFileMessage.getMid(),appFileMessage.getMsg().getData());
|
||||
if (l1.size() == fileInfoDto.getNumber()){
|
||||
//对数据进行排序
|
||||
// 将Map的Entry集合转换成List
|
||||
List<Map.Entry<Integer, String>> entryList = new ArrayList<>(l1.entrySet());
|
||||
// 使用Comparator按Key进行排序
|
||||
entryList.sort(new Comparator<Map.Entry<Integer, String>>() {
|
||||
@Override
|
||||
public int compare(Map.Entry<Integer, String> entry1, Map.Entry<Integer, String> entry2) {
|
||||
return entry1.getKey().compareTo(entry2.getKey());
|
||||
}
|
||||
});
|
||||
//解析文件
|
||||
filePath = fileStream(fileInfoDto.getNumber(),l1,null,fileName,appFileMessage.getId());
|
||||
log.info(fileName + "解析成功");
|
||||
redisUtil.delete(fileName);
|
||||
//波形文件关联事件
|
||||
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
|
||||
correlateEvents(fileInfoDto,filePath);
|
||||
csEventLogs.setStatus(1);
|
||||
csEventLogs.setRemark("当前文件"+l1.size()+"帧,这是第"+l1.size()+"帧,全部收到,解析成功!");
|
||||
csEventLogs.setCompleteTime(LocalDateTime.now());
|
||||
csEventLogs.setStartTime(LocalDateTime.parse(fileInfoDto.getStartTime(), fmt));
|
||||
csEventLogs.setEndTime(LocalDateTime.parse(fileInfoDto.getEndTime(), fmt));
|
||||
} else {
|
||||
//缓存
|
||||
fileStreamDto = new FileStreamDto();
|
||||
fileStreamDto.setMap(l1);
|
||||
redisUtil.saveByKeyWithExpire(fileName, fileStreamDto, 3600L);
|
||||
csEventLogs.setStatus(1);
|
||||
csEventLogs.setRemark("当前文件"+fileInfoDto.getNumber()+"帧,这是第"+appFileMessage.getMid()+"帧,记录成功!");
|
||||
csEventLogs.setCompleteTime(LocalDateTime.now());
|
||||
csEventLogs.setStartTime(LocalDateTime.parse(fileInfoDto.getStartTime(), fmt));
|
||||
csEventLogs.setEndTime(LocalDateTime.parse(fileInfoDto.getEndTime(), fmt));
|
||||
}
|
||||
}
|
||||
//记录日志
|
||||
|
||||
csEventLogsService.save(csEventLogs);
|
||||
} else {
|
||||
//todo 处理其他文件
|
||||
log.info("暂未做其他文件处理");
|
||||
}
|
||||
} catch (Exception e){
|
||||
csEventLogs.setStatus(0);
|
||||
csEventLogs.setRemark("文件解析失败,失败原因:" + e.getMessage());
|
||||
csEventLogs.setCompleteTime(LocalDateTime.now());
|
||||
//记录日志
|
||||
csEventLogsService.save(csEventLogs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 请求文件流信息
|
||||
@@ -233,6 +261,7 @@ public class FileServiceImpl implements IFileService {
|
||||
byteArray = bytes;
|
||||
}
|
||||
InputStream inputStream = new ByteArrayInputStream(byteArray);
|
||||
//todo 此处需要做文件crc校验或者md5校验,目前不知道怎么处理,先放一下
|
||||
String path = fileStorageUtil.uploadStreamSpecifyName(inputStream, OssPath.WAVE_DIR + folder + StrUtil.SLASH,fileName);
|
||||
try {
|
||||
inputStream.close();
|
||||
@@ -277,6 +306,5 @@ public class FileServiceImpl implements IFileService {
|
||||
csEventParam.setEndTime(fileInfoDto.getEndTime());
|
||||
csEventParam.setPath(path);
|
||||
csEventService.updateCsEvent(csEventParam);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.njcn.zlevent.utils;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
/**
|
||||
* 类的介绍:用于文件校验
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/9/8 13:32
|
||||
*/
|
||||
|
||||
public class FileCheckUtils {
|
||||
|
||||
/**
|
||||
* 32位CRC检验
|
||||
* @param inputStream 文件流
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static long calculateCRC32Checksum(InputStream inputStream) throws IOException {
|
||||
CRC32 crc32 = new CRC32();
|
||||
// 用于读取文件内容的缓冲区
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
crc32.update(buffer, 0, bytesRead);
|
||||
}
|
||||
return crc32.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* MD5检验
|
||||
* @param inputStream 文件流
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String calculateMD5Checksum(InputStream inputStream) throws IOException, NoSuchAlgorithmException {
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
// 用于读取文件内容的缓冲区
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
md5.update(buffer, 0, bytesRead);
|
||||
}
|
||||
byte[] digest = md5.digest();
|
||||
// 将MD5摘要转换为十六进制字符串
|
||||
StringBuilder md5Checksum = new StringBuilder();
|
||||
for (byte b : digest) {
|
||||
md5Checksum.append(String.format("%02x", b));
|
||||
}
|
||||
return md5Checksum.toString();
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,9 @@ public class AppEventConsumer extends EnhanceConsumerMessageHandler<AppEventMess
|
||||
log.info("分发至暂态事件处理");
|
||||
eventFeignClient.analysis(appEventMessage);
|
||||
break;
|
||||
case 7:
|
||||
log.info("分发至告警事件处理");
|
||||
break;
|
||||
case 16:
|
||||
log.info("分发至录波报文处理");
|
||||
waveFeignClient.analysis(appEventMessage);
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Objects;
|
||||
topic = BusinessTopic.NJCN_APP_FILE_STREAM_TOPIC,
|
||||
consumerGroup = BusinessTopic.NJCN_APP_FILE_STREAM_TOPIC,
|
||||
selectorExpression = BusinessTopic.FileTag.STREAM_TAG,
|
||||
consumeThreadNumber = 10,
|
||||
consumeThreadNumber = 1,
|
||||
enableMsgTrace = true
|
||||
)
|
||||
@Slf4j
|
||||
|
||||
Reference in New Issue
Block a user