diff --git a/db/upgrade20250227.sql b/db/upgrade20250227.sql new file mode 100644 index 0000000..e991d58 --- /dev/null +++ b/db/upgrade20250227.sql @@ -0,0 +1,17 @@ +DROP TABLE IF EXISTS `ied_dl_record`; + +CREATE TABLE `ied_dl_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `config_id` int(11) DEFAULT NULL, + `remote_path` varchar(200) DEFAULT NULL COMMENT '源路径', + `filename` varchar(200) DEFAULT NULL COMMENT '文件名', + `path` varchar(200) DEFAULT NULL COMMENT '本地路径', + `create_time` datetime DEFAULT NULL, + `d_time` datetime DEFAULT NULL, + `dev_id` int(11) DEFAULT NULL COMMENT '装置ID', + `type_id` int(11) DEFAULT NULL COMMENT '类型id', + `data` mediumtext, + PRIMARY KEY (`id`), + KEY `idxDev` (`dev_id`,`d_time`), + KEY `idxConfig` (`config_id`,`d_time`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/src/main/java/com/xydl/cac/controller/IedDlController.java b/src/main/java/com/xydl/cac/controller/IedDlController.java index a257384..c6e3b64 100644 --- a/src/main/java/com/xydl/cac/controller/IedDlController.java +++ b/src/main/java/com/xydl/cac/controller/IedDlController.java @@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.constraints.NotNull; +import java.util.Date; import java.util.List; @RestController @@ -66,15 +67,28 @@ public class IedDlController extends BasicController { @GetMapping("listDownload") @ApiOperation("查询下载记录列表") - public Response> list(@ApiParam("类型") @RequestParam(value = "configId", required = false) Integer configId, + public Response> list(@ApiParam("配置Id") @RequestParam(value = "configId", required = false) Integer configId, + @ApiParam("devId") @RequestParam(value = "devId", required = false) Integer devId, + @ApiParam("开始时间") @RequestParam(value = "startTime", required = false) Date startTime, + @ApiParam("结束时间") @RequestParam(value = "endTime", required = false) Date endTime, @ApiParam("页码") @RequestParam(value = "pageNum", required = false) Integer pageNum, @ApiParam("每页数量") @RequestParam(value = "pageSize", required = false) Integer pageSize) throws Exception { pageNum = this.initPageNum(pageNum); pageSize = this.initPageSize(pageSize); - Page result = recordService.list(configId, pageNum, pageSize); + Page result = recordService.list(configId, devId, startTime, endTime, pageNum, pageSize); return Response.success(result); } + @PostMapping("rebuildData") + @ApiOperation("rebuildData") + public Response rebuildData(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception { + if (id == null) { + throw new BusinessException("id不能为空!"); + } + recordService.rebuildData(id); + return Response.success("OK"); + } + @GetMapping("listFiles") @ApiOperation("查询文件和目录") public Response> listFiles(Integer iedId, String path) throws Exception { diff --git a/src/main/java/com/xydl/cac/entity/IedDlRecord.java b/src/main/java/com/xydl/cac/entity/IedDlRecord.java index 7e52967..e16b61f 100644 --- a/src/main/java/com/xydl/cac/entity/IedDlRecord.java +++ b/src/main/java/com/xydl/cac/entity/IedDlRecord.java @@ -1,6 +1,6 @@ package com.xydl.cac.entity; -import com.fasterxml.jackson.annotation.JsonInclude; +import com.xydl.cac.model.spectrogram.SpectrogramModel; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -11,7 +11,6 @@ import lombok.NoArgsConstructor; import javax.persistence.*; import java.util.Date; -@JsonInclude(JsonInclude.Include.NON_NULL) @Data @Builder @AllArgsConstructor @@ -42,11 +41,29 @@ public class IedDlRecord { @Column(name = "filename") private String filename; + @ApiModelProperty("采集时间") + @Column(name = "d_time") + private Date dTime; + @ApiModelProperty("创建时间") @Column(name = "create_time") private Date createTime; + @ApiModelProperty("devId") + @Column(name = "dev_id") + private Integer devId; + + @ApiModelProperty("typeId") + @Column(name = "type_id") + private Integer typeId; + + @ApiModelProperty("解析后数据") + @Column(name = "data") + private String data; + @Transient IedDlConfig config; + @Transient + SpectrogramModel model; } \ No newline at end of file diff --git a/src/main/java/com/xydl/cac/entity/constants/Constants.java b/src/main/java/com/xydl/cac/entity/constants/Constants.java index a5f3c6d..f9a133d 100644 --- a/src/main/java/com/xydl/cac/entity/constants/Constants.java +++ b/src/main/java/com/xydl/cac/entity/constants/Constants.java @@ -13,10 +13,13 @@ public class Constants { public static final Integer Server = 1; public static final Integer Client = 0; + public static final Integer TypeYSP = 1; + public static String Float = "float"; public static String Int = "int"; public static String Varchar = "varchar"; public static String Text = "text"; public static String DateTime = "datetime"; public static String Miss = "miss"; + } diff --git a/src/main/java/com/xydl/cac/iec/IEDCollectService.java b/src/main/java/com/xydl/cac/iec/IEDCollectService.java index fb9e108..dcdcb53 100644 --- a/src/main/java/com/xydl/cac/iec/IEDCollectService.java +++ b/src/main/java/com/xydl/cac/iec/IEDCollectService.java @@ -10,6 +10,7 @@ import com.xydl.cac.repository.*; import com.xydl.cac.service.DataService; import com.xydl.cac.service.IedDlRecordService; import com.xydl.cac.socket.WebSocketServer; +import com.xydl.cac.spectrogram.SpectrogramHandler; import com.xydl.cac.util.DateUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -33,6 +34,7 @@ public class IEDCollectService { WebSocketServer _webSocketServer; BizConfig _bizConfig; WarningRepository _warningRepository; + SpectrogramHandler _spectrogramHandler; String folder = "/record"; HashMap eqmidTimeMap = new HashMap<>(); @@ -42,7 +44,7 @@ public class IEDCollectService { IedDlRecordService dlRecordService, DataService dataService, String xml, IcdIed ied, WebSocketServer webSocketServer, BizConfig bizConfig, - WarningRepository warningRepository) { + WarningRepository warningRepository, SpectrogramHandler spectrogramHandler) { _configRepository = configRepository; _attRepository = attRepository; _instRepository = instRepository; @@ -54,6 +56,7 @@ public class IEDCollectService { _webSocketServer = webSocketServer; _bizConfig = bizConfig; _warningRepository = warningRepository; + _spectrogramHandler = spectrogramHandler; iecClient = new IecClient(); } @@ -216,16 +219,19 @@ public class IEDCollectService { && matchContain(filename, config.getContain())) { IedDlRecord record = new IedDlRecord(); record.setConfigId(config.getId()); + record.setDevId(config.getDevId()); + record.setTypeId(config.getSensor().getTypeId()); record.setFilename(filename); record.setRemotePath(config.getPath() + filename); boolean exist = _dlRecordService.exist(record); if (!exist) { - String localFilePath = localPath + "/" + filename; - iecClient.getFile(record.getRemotePath(), _bizConfig.getDatapath() + localFilePath, config.getTodel()); - record.setPath(_bizConfig.getDataNginxPath() + localFilePath); - record.setCreateTime(new Date()); - _dlRecordService.add(record); + String relativePath = localPath + "/" + filename; + String localFullPath = _bizConfig.getDatapath() + relativePath; + iecClient.getFile(record.getRemotePath(), localFullPath, config.getTodel()); + record.setPath(_bizConfig.getDataNginxPath() + relativePath); log.info("采集到" + record.getRemotePath()); + _spectrogramHandler.processFile(record); + _dlRecordService.add(record); } } } diff --git a/src/main/java/com/xydl/cac/model/spectrogram/SouthYsp.java b/src/main/java/com/xydl/cac/model/spectrogram/SouthYsp.java new file mode 100644 index 0000000..b8547cd --- /dev/null +++ b/src/main/java/com/xydl/cac/model/spectrogram/SouthYsp.java @@ -0,0 +1,48 @@ +package com.xydl.cac.model.spectrogram; + +import lombok.Data; + +import java.io.DataInputStream; +import java.util.ArrayList; +import java.util.List; + +@Data +public class SouthYsp extends SpectrogramModel { + Float version; + Float fileVersion; + Short type; + Long createTime; + String flag; + String name; + Float xInterval; + Float yMax; + String xUnit; + String yUnit; + Integer k; + Integer m; + List channels = new ArrayList<>(); + + public void readFrom(DataInputStream dis) throws Exception { + version = readLittleEndianFloat(dis); + fileVersion = readLittleEndianFloat(dis); + type = readLittleEndianShort(dis); + createTime = readLittleEndianLong(dis); + flag = readString(dis, 1); + name = readString(dis, 32); + xInterval = readLittleEndianFloat(dis); + yMax = readLittleEndianFloat(dis); + xUnit = readString(dis, 1); + yUnit = readString(dis, 1); + k = readLittleEndianInt(dis); + m = dis.read(); + for (int i = 0; i < m; i++) { + SouthYspChannel channel = new SouthYspChannel(); + channel.readFrom(dis); + channels.add(channel); + } + dis.readInt(); + for (SouthYspChannel channel : channels) { + channel.readDataFrom(dis, k); + } + } +} diff --git a/src/main/java/com/xydl/cac/model/spectrogram/SouthYspChannel.java b/src/main/java/com/xydl/cac/model/spectrogram/SouthYspChannel.java new file mode 100644 index 0000000..f2a5174 --- /dev/null +++ b/src/main/java/com/xydl/cac/model/spectrogram/SouthYspChannel.java @@ -0,0 +1,32 @@ +package com.xydl.cac.model.spectrogram; + +import lombok.Data; + +import java.io.DataInputStream; +import java.util.ArrayList; +import java.util.List; + +import static com.xydl.cac.model.spectrogram.SpectrogramModel.readLittleEndianFloat; + +@Data +public class SouthYspChannel { + Integer n; + List crests = new ArrayList<>(); + List data = new ArrayList<>(); + + public void readFrom(DataInputStream dis) throws Exception { + n = dis.read(); + for (int i = 0; i < n; i++) { + YspChannelCrest crest = new YspChannelCrest(); + crest.readFrom(dis); + crests.add(crest); + } + } + + public void readDataFrom(DataInputStream dis, Integer k) throws Exception { + for (int i = 0; i < k; i++) { + Float v = readLittleEndianFloat(dis); + data.add(v); + } + } +} diff --git a/src/main/java/com/xydl/cac/model/spectrogram/SpectrogramModel.java b/src/main/java/com/xydl/cac/model/spectrogram/SpectrogramModel.java new file mode 100644 index 0000000..02997fe --- /dev/null +++ b/src/main/java/com/xydl/cac/model/spectrogram/SpectrogramModel.java @@ -0,0 +1,57 @@ +package com.xydl.cac.model.spectrogram; + +import lombok.Data; + +import java.io.DataInputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.charset.StandardCharsets; + +@Data +public class SpectrogramModel { + + // 读取小端序的int(4字节) + public static int readLittleEndianInt(DataInputStream dis) throws IOException { + byte[] bytes = new byte[4]; + dis.readFully(bytes); + return ByteBuffer.wrap(bytes) + .order(ByteOrder.LITTLE_ENDIAN) + .getInt(); + } + + // 读取小端序的short(2字节) + public static short readLittleEndianShort(DataInputStream dis) throws IOException { + byte[] bytes = new byte[2]; + dis.readFully(bytes); + return ByteBuffer.wrap(bytes) + .order(ByteOrder.LITTLE_ENDIAN) + .getShort(); + } + + // 读取小端序的long(8字节) + public static long readLittleEndianLong(DataInputStream dis) throws IOException { + byte[] bytes = new byte[8]; + dis.readFully(bytes); + return ByteBuffer.wrap(bytes) + .order(ByteOrder.LITTLE_ENDIAN) + .getLong(); + } + + // 读取小端序的float(4字节) + public static float readLittleEndianFloat(DataInputStream dis) throws IOException { + byte[] bytes = new byte[4]; + dis.readFully(bytes); + return ByteBuffer.wrap(bytes) + .order(ByteOrder.LITTLE_ENDIAN) + .getFloat(); + } + + // 读取String + public static String readString(DataInputStream dis, int length) throws IOException { + byte[] bytes = new byte[length]; + dis.readFully(bytes); + String str = new String(bytes, StandardCharsets.UTF_8); + return str.replaceAll("\u0000", ""); + } +} diff --git a/src/main/java/com/xydl/cac/model/spectrogram/Ysp.java b/src/main/java/com/xydl/cac/model/spectrogram/Ysp.java new file mode 100644 index 0000000..2d168ab --- /dev/null +++ b/src/main/java/com/xydl/cac/model/spectrogram/Ysp.java @@ -0,0 +1,40 @@ +package com.xydl.cac.model.spectrogram; + +import lombok.Data; + +import java.io.DataInputStream; +import java.util.ArrayList; +import java.util.List; + +@Data +public class Ysp extends SpectrogramModel { + Integer code; + Integer length; + Long createTime; + Integer flag; + Float xInterval; + Float yMax; + Integer xUnit; + Integer yUnit; + Integer k; + Integer m; + List channels = new ArrayList<>(); + + public void readFrom(DataInputStream dis) throws Exception { + code = dis.read(); + length = readLittleEndianInt(dis); + createTime = readLittleEndianLong(dis); + flag = dis.read(); + xInterval = readLittleEndianFloat(dis); + yMax = readLittleEndianFloat(dis); + xUnit = dis.read(); + yUnit = dis.read(); + k = readLittleEndianInt(dis); + m = dis.read(); + for (int i = 0; i < m; i++) { + YspChannel channel = new YspChannel(); + channel.readFrom(dis, k); + channels.add(channel); + } + } +} diff --git a/src/main/java/com/xydl/cac/model/spectrogram/YspChannel.java b/src/main/java/com/xydl/cac/model/spectrogram/YspChannel.java new file mode 100644 index 0000000..c73a52e --- /dev/null +++ b/src/main/java/com/xydl/cac/model/spectrogram/YspChannel.java @@ -0,0 +1,29 @@ +package com.xydl.cac.model.spectrogram; + +import lombok.Data; + +import java.io.DataInputStream; +import java.util.ArrayList; +import java.util.List; + +import static com.xydl.cac.model.spectrogram.SpectrogramModel.readLittleEndianFloat; + +@Data +public class YspChannel { + Integer n; + List crests = new ArrayList<>(); + List data = new ArrayList<>(); + + public void readFrom(DataInputStream dis, Integer k) throws Exception { + n = dis.read(); + for (int i = 0; i < n; i++) { + YspChannelCrest crest = new YspChannelCrest(); + crest.readFrom(dis); + crests.add(crest); + } + for (int i = 0; i < k; i++) { + Float v = readLittleEndianFloat(dis); + data.add(v); + } + } +} diff --git a/src/main/java/com/xydl/cac/model/spectrogram/YspChannelCrest.java b/src/main/java/com/xydl/cac/model/spectrogram/YspChannelCrest.java new file mode 100644 index 0000000..d167bbc --- /dev/null +++ b/src/main/java/com/xydl/cac/model/spectrogram/YspChannelCrest.java @@ -0,0 +1,28 @@ +package com.xydl.cac.model.spectrogram; + +import lombok.Data; + +import java.io.DataInputStream; + +import static com.xydl.cac.model.spectrogram.SpectrogramModel.*; + +@Data +public class YspChannelCrest { + String name; + Integer j; + Float time; + Float startTime; + Float endTime; + Float height; + Float area; + + public void readFrom(DataInputStream dis) throws Exception { + name = readString(dis, 10); + j = dis.read(); + time = readLittleEndianFloat(dis); + startTime = readLittleEndianFloat(dis); + endTime = readLittleEndianFloat(dis); + height = readLittleEndianFloat(dis); + area = readLittleEndianFloat(dis); + } +} diff --git a/src/main/java/com/xydl/cac/service/IedDlRecordService.java b/src/main/java/com/xydl/cac/service/IedDlRecordService.java index 0615d99..95c754d 100644 --- a/src/main/java/com/xydl/cac/service/IedDlRecordService.java +++ b/src/main/java/com/xydl/cac/service/IedDlRecordService.java @@ -1,13 +1,20 @@ package com.xydl.cac.service; import com.xydl.cac.entity.IedDlRecord; +import com.xydl.cac.exception.BusinessException; import org.springframework.data.domain.Page; +import java.util.Date; + public interface IedDlRecordService { - Page list(Integer configId, int pageNum, int pageSize) throws Exception; + Page list(Integer configId, Integer devId, Date startTime, Date endTime, int pageNum, int pageSize) throws Exception; void add(IedDlRecord item); boolean exist(IedDlRecord item); + + void update(IedDlRecord item); + + void rebuildData(Integer id) throws BusinessException; } diff --git a/src/main/java/com/xydl/cac/service/impl/IedDlRecordServiceImpl.java b/src/main/java/com/xydl/cac/service/impl/IedDlRecordServiceImpl.java index c214d04..a144c92 100644 --- a/src/main/java/com/xydl/cac/service/impl/IedDlRecordServiceImpl.java +++ b/src/main/java/com/xydl/cac/service/impl/IedDlRecordServiceImpl.java @@ -2,40 +2,55 @@ package com.xydl.cac.service.impl; import com.xydl.cac.entity.IedDlConfig; import com.xydl.cac.entity.IedDlRecord; +import com.xydl.cac.exception.BusinessException; import com.xydl.cac.repository.IedDlRecordRepository; import com.xydl.cac.service.IedDlConfigService; import com.xydl.cac.service.IedDlRecordService; +import com.xydl.cac.spectrogram.SpectrogramHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import javax.persistence.criteria.Predicate; +import java.util.Date; import java.util.List; +import java.util.Optional; @Service @Slf4j -@Transactional(rollbackFor = Exception.class) public class IedDlRecordServiceImpl implements IedDlRecordService { @Resource IedDlRecordRepository repository; @Resource IedDlConfigService configService; + @Resource + SpectrogramHandler spectrogramHandler; @Override - public Page list(Integer configId, int pageNum, int pageSize) throws Exception { + public Page list(Integer configId, Integer devId, Date startTime, Date endTime, int pageNum, int pageSize) throws Exception { PageRequest request = PageRequest.of(pageNum - 1, pageSize); Specification specification = (root, query, builder) -> { Predicate predicate = builder.conjunction(); if (configId != null) { predicate.getExpressions().add(builder.equal(root.get("configId"), configId)); + query.orderBy(builder.desc(root.get("dTime"))); + } else if (devId != null) { + predicate.getExpressions().add(builder.equal(root.get("devId"), devId)); + query.orderBy(builder.desc(root.get("dTime"))); + } else { + query.orderBy(builder.desc(root.get("id"))); + } + if (startTime != null) { + predicate.getExpressions().add(builder.greaterThan(root.get("dTime"), startTime)); + } + if (endTime != null) { + predicate.getExpressions().add(builder.lessThanOrEqualTo(root.get("dTime"), endTime)); } - query.orderBy(builder.desc(root.get("id"))); return predicate; }; Page result = repository.findAll(specification, request); @@ -48,6 +63,7 @@ public class IedDlRecordServiceImpl implements IedDlRecordService { break; } } + spectrogramHandler.jsonToModel(item); } } return result; @@ -69,4 +85,20 @@ public class IedDlRecordServiceImpl implements IedDlRecordService { } } + @Override + public void update(IedDlRecord item) { + repository.save(item); + } + + @Override + public void rebuildData(Integer id) throws BusinessException { + Optional optional = repository.findById(id); + if (!optional.isPresent()) { + throw new BusinessException("未找到该记录"); + } + IedDlRecord record = optional.get(); + spectrogramHandler.processFile(record); + repository.save(record); + } + } diff --git a/src/main/java/com/xydl/cac/spectrogram/ProcessorYsp.java b/src/main/java/com/xydl/cac/spectrogram/ProcessorYsp.java new file mode 100644 index 0000000..29c5fd0 --- /dev/null +++ b/src/main/java/com/xydl/cac/spectrogram/ProcessorYsp.java @@ -0,0 +1,34 @@ +package com.xydl.cac.spectrogram; + +import com.xydl.cac.model.spectrogram.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.io.DataInputStream; +import java.io.FileInputStream; + +@Service +@Slf4j +public class ProcessorYsp { + + public SouthYsp process(String localFilePath) { + try (DataInputStream dis = new DataInputStream(new FileInputStream(localFilePath))) { + SouthYsp model = this.readOneBlock(dis); + return model; + } catch (Exception e) { + log.error("解析文件失败" + localFilePath, e); + return null; + } + } + + private SouthYsp readOneBlock(DataInputStream dis) throws Exception { + SouthYsp model = new SouthYsp(); + model.readFrom(dis); + return model; + } + + public static void main(String[] args) { + ProcessorYsp processorYsp = new ProcessorYsp(); + processorYsp.process("C:/Code/cac/谱图文件/0312B12000042A3840001_203_07_20250113163055.dat"); + } +} diff --git a/src/main/java/com/xydl/cac/spectrogram/SpectrogramHandler.java b/src/main/java/com/xydl/cac/spectrogram/SpectrogramHandler.java new file mode 100644 index 0000000..559df49 --- /dev/null +++ b/src/main/java/com/xydl/cac/spectrogram/SpectrogramHandler.java @@ -0,0 +1,72 @@ +package com.xydl.cac.spectrogram; + +import com.xydl.cac.config.BizConfig; +import com.xydl.cac.entity.IedDlRecord; +import com.xydl.cac.entity.constants.Constants; +import com.xydl.cac.model.spectrogram.SouthYsp; +import com.xydl.cac.util.DataUtil; +import com.xydl.cac.util.DateUtil; +import com.xydl.cac.util.JSONUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; + +@Service +@Slf4j +public class SpectrogramHandler { + + @Resource + BizConfig bizConfig; + @Resource + ProcessorYsp processorYsp; + + public void processFile(IedDlRecord record) { + if (record.getTypeId() == null) { + return; + } + String localFilePath = record.getPath().replaceFirst(bizConfig.getDataNginxPath(), bizConfig.getDatapath()); + try { + // 油色谱谱图 + if (record.getTypeId() == Constants.TypeYSP) { + SouthYsp model = processorYsp.process(localFilePath); + String json = JSONUtil.object2Json(model); + record.setData(json); + record.setCreateTime(new Date()); + try { + String str = String.valueOf(model.getCreateTime()); + Date dtime = DateUtil.parse(str, "yyyyMMddHHmmss"); + record.setDTime(dtime); + } catch (Exception ignore) { + } + log.info("解析油色谱谱图文件成功"); + } else { + log.error("缺少该类型" + record.getTypeId() + "的谱图处理模块"); + } + } catch (Exception ex) { + log.error("解析谱图文件失败, typeId=" + record.getTypeId() + ", devId=" + record.getDevId() + + ", file=" + localFilePath, ex); + } + } + + public void jsonToModel(IedDlRecord record) { + if (record.getTypeId() == null) { + return; + } + if (record.getData() == null) { + return; + } + try { + if (Constants.TypeYSP == record.getTypeId()) { + SouthYsp model = JSONUtil.json2Object(record.getData(), SouthYsp.class); + record.setModel(model); + record.setData(null); + } + } catch (Exception ex) { + log.error("谱图数据data内容存在异常, typeId=" + record.getTypeId() + ", devId=" + record.getDevId() + + ", file=" + record.getPath()); + } + } + +} diff --git a/src/main/java/com/xydl/cac/task/AsyncTask.java b/src/main/java/com/xydl/cac/task/AsyncTask.java index 454402e..7205d62 100644 --- a/src/main/java/com/xydl/cac/task/AsyncTask.java +++ b/src/main/java/com/xydl/cac/task/AsyncTask.java @@ -9,6 +9,7 @@ import com.xydl.cac.repository.*; import com.xydl.cac.service.DataService; import com.xydl.cac.service.IedDlRecordService; import com.xydl.cac.socket.WebSocketServer; +import com.xydl.cac.spectrogram.SpectrogramHandler; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -35,6 +36,8 @@ public class AsyncTask { BizConfig bizConfig; @Resource WarningRepository warningRepository; + @Resource + SpectrogramHandler spectrogramHandler; @Async public void collectIed(String xml, IcdIed ied, List rptList, List dlList) { @@ -43,7 +46,7 @@ public class AsyncTask { dlRecordService, dataService, xml, ied, webSocketServer, bizConfig, - warningRepository); + warningRepository, spectrogramHandler); iedService.collectAndSave(rptList, dlList); } } diff --git a/src/main/java/com/xydl/cac/task/Client61850Task.java b/src/main/java/com/xydl/cac/task/Client61850Task.java index d43f726..202e8ff 100644 --- a/src/main/java/com/xydl/cac/task/Client61850Task.java +++ b/src/main/java/com/xydl/cac/task/Client61850Task.java @@ -88,11 +88,19 @@ public class Client61850Task { if (CollectionUtils.isEmpty(rptList) && CollectionUtils.isEmpty(dlList)) { return; } + List dlNewList = new ArrayList<>(); + for (IedDlConfig item : dlList) { + List senList = sensorRepository.findByDevId(item.getDevId()); + if (!CollectionUtils.isEmpty(senList)) { + item.setSensor(senList.get(0)); + dlNewList.add(item); + } + } List icdFileList = fileRepository.findAll(); if (!CollectionUtils.isEmpty(icdFileList)) { for (IcdFile icdFile : icdFileList) { - this.collectIcdFile(icdFile, rptList, dlList); + this.collectIcdFile(icdFile, rptList, dlNewList); } } }