Merge branch 'spectrogram' into dev
commit
e825c6a654
@ -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;
|
@ -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<SouthYspChannel> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<YspChannelCrest> crests = new ArrayList<>();
|
||||||
|
List<Float> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<YspChannel> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<YspChannelCrest> crests = new ArrayList<>();
|
||||||
|
List<Float> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,20 @@
|
|||||||
package com.xydl.cac.service;
|
package com.xydl.cac.service;
|
||||||
|
|
||||||
import com.xydl.cac.entity.IedDlRecord;
|
import com.xydl.cac.entity.IedDlRecord;
|
||||||
|
import com.xydl.cac.exception.BusinessException;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public interface IedDlRecordService {
|
public interface IedDlRecordService {
|
||||||
|
|
||||||
Page<IedDlRecord> list(Integer configId, int pageNum, int pageSize) throws Exception;
|
Page<IedDlRecord> list(Integer configId, Integer devId, Date startTime, Date endTime, int pageNum, int pageSize) throws Exception;
|
||||||
|
|
||||||
void add(IedDlRecord item);
|
void add(IedDlRecord item);
|
||||||
|
|
||||||
boolean exist(IedDlRecord item);
|
boolean exist(IedDlRecord item);
|
||||||
|
|
||||||
|
void update(IedDlRecord item);
|
||||||
|
|
||||||
|
void rebuildData(Integer id) throws BusinessException;
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue