Compare commits
No commits in common. 'hc-jna3' and 'main' have entirely different histories.
@ -1,22 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
ALTER TABLE `n_sensor`
|
|
||||||
ADD COLUMN `order_num` INT NULL AFTER `icd_id`,
|
|
||||||
ADD INDEX `idxOrd` (`order_num` ASC),
|
|
||||||
ADD INDEX `idxZsb` (`zsb_id` ASC, `order_num` ASC);
|
|
@ -1,33 +0,0 @@
|
|||||||
ALTER TABLE `n_sensor`
|
|
||||||
ADD COLUMN `ip` VARCHAR(45) NULL AFTER `order_num`,
|
|
||||||
ADD COLUMN `port` INT NULL AFTER `ip`,
|
|
||||||
ADD COLUMN `username` VARCHAR(45) NULL AFTER `port`,
|
|
||||||
ADD COLUMN `passwd` VARCHAR(45) NULL AFTER `username`,
|
|
||||||
ADD COLUMN `tm_id` INT NULL AFTER `passwd`,
|
|
||||||
ADD COLUMN `tm_type` INT NULL AFTER `tm_id`;
|
|
||||||
|
|
||||||
CREATE TABLE `thermal_config` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`type_id` int(11) DEFAULT NULL COMMENT '类型id',
|
|
||||||
`maxtemp` varchar(45) DEFAULT NULL,
|
|
||||||
`mintemp` varchar(45) DEFAULT NULL,
|
|
||||||
`avertemp` varchar(45) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `data_eaif_h`;
|
|
||||||
CREATE TABLE `data_eaif_h` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自动编号',
|
|
||||||
`eqmid` int(11) NOT NULL COMMENT '设备ID',
|
|
||||||
`areaid` int(11) DEFAULT NULL COMMENT '点、线、区域ID',
|
|
||||||
`capturetime` datetime NOT NULL COMMENT '采集时间',
|
|
||||||
`maxtemp` float(18,4) DEFAULT NULL COMMENT '最大温度',
|
|
||||||
`mintemp` float(18,4) DEFAULT NULL COMMENT '最小温度',
|
|
||||||
`avgtemp` float(18,4) DEFAULT NULL COMMENT '平均温度',
|
|
||||||
`unit` tinyint(2) DEFAULT NULL COMMENT '1=>摄氏度2=>华氏度',
|
|
||||||
`type` tinyint(2) DEFAULT NULL COMMENT '1->点2->线3->框',
|
|
||||||
`mid` float(10,4) DEFAULT NULL COMMENT '中间差',
|
|
||||||
`std` float(10,4) DEFAULT NULL COMMENT '标准方差值',
|
|
||||||
PRIMARY KEY (`id`) USING BTREE,
|
|
||||||
KEY `idx` (`eqmid`,`capturetime`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='红外区域测温数据表';
|
|
@ -1,22 +0,0 @@
|
|||||||
CREATE TABLE `iec_104_point` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`eqmid` int(11) DEFAULT NULL,
|
|
||||||
`field` varchar(45) DEFAULT NULL,
|
|
||||||
`stype` varchar(45) DEFAULT NULL COMMENT '类型 1:遥信 2:遥测',
|
|
||||||
`sadr` int(11) DEFAULT NULL COMMENT '点位',
|
|
||||||
`create_time` datetime DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
ALTER TABLE `ied_dl_config`
|
|
||||||
ADD COLUMN `upload` INT NULL COMMENT '0:不传; 1:要传;' AFTER `active`;
|
|
||||||
|
|
||||||
ALTER TABLE `ied_dl_record`
|
|
||||||
ADD COLUMN `upload` INT(11) NULL DEFAULT NULL COMMENT '0:未传; 1:已传;' AFTER `data`;
|
|
||||||
|
|
||||||
ALTER TABLE `i2sync_field`
|
|
||||||
ADD COLUMN `conversion` VARCHAR(45) NULL COMMENT '单位换算' AFTER `attach`;
|
|
||||||
|
|
||||||
ALTER TABLE `n_sensor`
|
|
||||||
ADD COLUMN `sdk_type` INT NULL COMMENT '1:大华 2:海康' AFTER `tm_type`,
|
|
||||||
ADD COLUMN `channel` INT NULL COMMENT '通道' AFTER `sdk_type`;
|
|
File diff suppressed because it is too large
Load Diff
@ -1,50 +0,0 @@
|
|||||||
package com.xydl.cac.controller;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.Iec104Point;
|
|
||||||
import com.xydl.cac.exception.BusinessException;
|
|
||||||
import com.xydl.cac.model.Response;
|
|
||||||
import com.xydl.cac.service.Iec104PointService;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@Api(tags = {"Iec104点表接口"})
|
|
||||||
@RequestMapping("iec104")
|
|
||||||
@Slf4j
|
|
||||||
public class Iec104PointController extends BasicController {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
Iec104PointService iec104PointService;
|
|
||||||
|
|
||||||
@GetMapping("list")
|
|
||||||
@ApiOperation("查询104点表")
|
|
||||||
public Response<List<Iec104Point>> list() {
|
|
||||||
List<Iec104Point> result = iec104PointService.findAll();
|
|
||||||
return Response.success(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("add")
|
|
||||||
@ApiOperation("新增")
|
|
||||||
public Response<Iec104Point> add(@Validated @RequestBody Iec104Point iec104Point) throws Exception {
|
|
||||||
Iec104Point add = iec104PointService.add(iec104Point);
|
|
||||||
return Response.success(add);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("del")
|
|
||||||
@ApiOperation("删除")
|
|
||||||
public Response<String> del(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception {
|
|
||||||
if (id == null) {
|
|
||||||
throw new BusinessException("id不能为空!");
|
|
||||||
}
|
|
||||||
iec104PointService.delete(id);
|
|
||||||
return Response.success("OK");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package com.xydl.cac.controller;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.ThermalConfig;
|
|
||||||
import com.xydl.cac.model.Response;
|
|
||||||
import com.xydl.cac.service.ThermalConfigService;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@Api(tags = {"热成像测温相关接口"})
|
|
||||||
@RequestMapping("thermal")
|
|
||||||
@Slf4j
|
|
||||||
public class ThermalConfigController extends BasicController {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
ThermalConfigService configService;
|
|
||||||
|
|
||||||
@GetMapping("getConfig")
|
|
||||||
@ApiOperation("查询配置")
|
|
||||||
public Response<ThermalConfig> getConfig() {
|
|
||||||
ThermalConfig result = configService.getConfig();
|
|
||||||
return Response.success(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("saveConfig")
|
|
||||||
@ApiOperation("修改配置")
|
|
||||||
public Response<String> saveConfig(@Validated @RequestBody ThermalConfig model) throws Exception {
|
|
||||||
configService.saveConfig(model);
|
|
||||||
return Response.success("OK");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package com.xydl.cac.entity;
|
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Entity
|
|
||||||
@Table(name = "iec_104_point")
|
|
||||||
@ApiModel("IEC104点表配置")
|
|
||||||
public class Iec104Point {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@Column(name = "id")
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@NotNull(message = "eqmid不能为空")
|
|
||||||
@Column(name = "eqmid")
|
|
||||||
private Integer eqmid;
|
|
||||||
|
|
||||||
@NotBlank(message = "字段不能为空")
|
|
||||||
@ApiModelProperty("字段")
|
|
||||||
@Column(name = "field")
|
|
||||||
private String field;
|
|
||||||
|
|
||||||
@ApiModelProperty("点位类型")
|
|
||||||
@Column(name = "stype")
|
|
||||||
private String stype;
|
|
||||||
|
|
||||||
@NotNull(message = "点位不能为空")
|
|
||||||
@ApiModelProperty("点位")
|
|
||||||
@Column(name = "sadr")
|
|
||||||
private Integer sadr;
|
|
||||||
|
|
||||||
@ApiModelProperty("创建时间")
|
|
||||||
@Column(name = "create_time")
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package com.xydl.cac.entity;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Entity
|
|
||||||
@Table(name = "thermal_config")
|
|
||||||
@ApiModel("热成像测温配置表")
|
|
||||||
public class ThermalConfig {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@Column(name = "id")
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@NotNull(message = "typeId不能为空")
|
|
||||||
@Column(name = "type_id")
|
|
||||||
@ApiModelProperty("类型Id")
|
|
||||||
private Integer typeId;
|
|
||||||
|
|
||||||
@ApiModelProperty("最高温度字段")
|
|
||||||
@Column(name = "maxtemp")
|
|
||||||
private String maxtemp;
|
|
||||||
|
|
||||||
@ApiModelProperty("最低温度字段")
|
|
||||||
@Column(name = "mintemp")
|
|
||||||
private String mintemp;
|
|
||||||
|
|
||||||
@ApiModelProperty("平均温度字段")
|
|
||||||
@Column(name = "avertemp")
|
|
||||||
private String avertemp;
|
|
||||||
}
|
|
@ -1,132 +0,0 @@
|
|||||||
package com.xydl.cac.iec104;
|
|
||||||
|
|
||||||
import com.xydl.cac.model.StaticVariable;
|
|
||||||
import com.xydl.cac.socket.WebSocketServer;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.openmuc.j60870.*;
|
|
||||||
import org.openmuc.j60870.ie.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class Iec104Client implements ConnectionEventListener {
|
|
||||||
public String ip;
|
|
||||||
public Integer port;
|
|
||||||
Connection connection = null;
|
|
||||||
ClientConnectionBuilder clientConnectionBuilder = null;
|
|
||||||
private WebSocketServer webSocketServer;
|
|
||||||
public boolean keep = false;
|
|
||||||
public boolean connected = false;
|
|
||||||
public int retry = 0;
|
|
||||||
public int seconds = 0;
|
|
||||||
private boolean inRetry = false;
|
|
||||||
|
|
||||||
public Iec104Client(WebSocketServer _webSocketServer) {
|
|
||||||
webSocketServer = _webSocketServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void connect(String _ip, Integer _port) throws Exception {
|
|
||||||
ip = _ip;
|
|
||||||
port = _port;
|
|
||||||
InetAddress address = InetAddress.getByName(ip);
|
|
||||||
clientConnectionBuilder = new ClientConnectionBuilder(address)
|
|
||||||
.setMessageFragmentTimeout(5_000)
|
|
||||||
.setConnectionTimeout(20_000)
|
|
||||||
.setPort(port)
|
|
||||||
.setConnectionEventListener(this);
|
|
||||||
connection = clientConnectionBuilder.build();
|
|
||||||
connection.startDataTransfer();
|
|
||||||
log.info("IEC104客户端已连接上" + ip + ":" + port);
|
|
||||||
connected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnect() {
|
|
||||||
try {
|
|
||||||
connected = false;
|
|
||||||
connection.stopDataTransfer();
|
|
||||||
connection.close();
|
|
||||||
connection = null;
|
|
||||||
log.info("IEC104客户端已断开" + ip + ":" + port);
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void reconnect() throws Exception {
|
|
||||||
if (StaticVariable.shutdown == 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
retry++;
|
|
||||||
seconds = 0;
|
|
||||||
connection = clientConnectionBuilder.build();
|
|
||||||
connection.startDataTransfer();
|
|
||||||
log.info("IEC104客户端断线重连成功, ip=" + ip + ", port=" + port);
|
|
||||||
connected = true;
|
|
||||||
retry = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void interrogation() throws Exception {
|
|
||||||
connection.interrogation(1, CauseOfTransmission.ACTIVATION,
|
|
||||||
new IeQualifierOfInterrogation(20));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void newASdu(Connection connection, ASdu aSdu) {
|
|
||||||
if (aSdu == null)
|
|
||||||
return;
|
|
||||||
log.info("Got new ASdu, " + aSdu.toString());
|
|
||||||
InformationObject[] objs = aSdu.getInformationObjects();
|
|
||||||
if (objs != null && objs.length > 0) {
|
|
||||||
for (InformationObject obj : objs) {
|
|
||||||
int addr = obj.getInformationObjectAddress();
|
|
||||||
InformationElement[][] elements = obj.getInformationElements();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connectionClosed(Connection connection, IOException e) {
|
|
||||||
if (keep && !inRetry) {
|
|
||||||
inRetry = true;
|
|
||||||
retry = 0;
|
|
||||||
seconds = 0;
|
|
||||||
this.disconnect();
|
|
||||||
while (!connected && StaticVariable.shutdown == 0) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
seconds++;
|
|
||||||
if (retry < 10 && seconds > 60) {
|
|
||||||
this.reconnect();
|
|
||||||
} else if (seconds > 60 * 60) {
|
|
||||||
this.reconnect();
|
|
||||||
}
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
String err = "IEC104客户端断线重连失败" + retry + "次, ip=" + ip + ", port=" + port;
|
|
||||||
log.warn(err);
|
|
||||||
if (webSocketServer != null && retry >= 10) {
|
|
||||||
webSocketServer.sendMessage(err, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inRetry = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dataTransferStateChanged(Connection connection, boolean b) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Iec104Client client = new Iec104Client(null);
|
|
||||||
try {
|
|
||||||
client.connect("192.168.1.190", 2404);
|
|
||||||
client.interrogation();
|
|
||||||
while (true) {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package com.xydl.cac.iec104;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.openmuc.j60870.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class Iec104Server implements ServerEventListener {
|
|
||||||
Server _server;
|
|
||||||
int idCounter = 1;
|
|
||||||
public boolean started = false;
|
|
||||||
public Integer port = null;
|
|
||||||
|
|
||||||
public Iec104Server() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start(int port) throws Exception {
|
|
||||||
if (!started) {
|
|
||||||
_server = Server.builder()
|
|
||||||
.setPort(port)
|
|
||||||
.setIoaFieldLength(3)
|
|
||||||
.setCommonAddressFieldLength(2)
|
|
||||||
.setCotFieldLength(2)
|
|
||||||
.build();
|
|
||||||
_server.start(this);
|
|
||||||
started = true;
|
|
||||||
this.port = port;
|
|
||||||
log.info("已启动IEC104服务端在" + port + "端口");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
if (_server != null) {
|
|
||||||
_server.stop();
|
|
||||||
log.info("已停止IEC104服务端于" + port + "端口");
|
|
||||||
}
|
|
||||||
started = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConnectionEventListener connectionIndication(Connection connection) {
|
|
||||||
return new ServerConnectionEventListener(connection, idCounter++);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void serverStoppedListeningIndication(IOException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connectionAttemptFailed(IOException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package com.xydl.cac.iec104;
|
|
||||||
|
|
||||||
import com.xydl.cac.exception.BusinessException;
|
|
||||||
import com.xydl.cac.model.StaticVariable;
|
|
||||||
import com.xydl.cac.service.Iec104PointService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class Iec104ServerService {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
Iec104PointService iec104PointService;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
private void init() {
|
|
||||||
try {
|
|
||||||
iec104PointService.findAll();
|
|
||||||
if (!CollectionUtils.isEmpty(StaticVariable.point104_Cache)) {
|
|
||||||
this.startServer(2404);
|
|
||||||
}
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startServer(int port) throws BusinessException {
|
|
||||||
try {
|
|
||||||
Iec104Server server = new Iec104Server();
|
|
||||||
server.start(port);
|
|
||||||
StaticVariable.iec104Server = server;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("启动IEC104服务端异常.", e);
|
|
||||||
throw new BusinessException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopServer() {
|
|
||||||
this.doStopServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doStopServer() {
|
|
||||||
if (StaticVariable.iec104Server != null) {
|
|
||||||
StaticVariable.iec104Server.stop();
|
|
||||||
StaticVariable.iec104Server = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreDestroy
|
|
||||||
private void stop() {
|
|
||||||
StaticVariable.shutdown = 1;
|
|
||||||
this.doStopServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package com.xydl.cac.iec104;
|
|
||||||
|
|
||||||
|
|
||||||
import com.xydl.cac.exception.BusinessException;
|
|
||||||
import com.xydl.cac.model.StaticVariable;
|
|
||||||
import com.xydl.cac.socket.WebSocketServer;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class RealTime104DataService {
|
|
||||||
@Resource
|
|
||||||
WebSocketServer webSocketServer;
|
|
||||||
|
|
||||||
public static boolean inDoing = false;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
private void init() {
|
|
||||||
try {
|
|
||||||
// this.startCollect("192.168.1.177");
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startCollect(String ip) throws BusinessException {
|
|
||||||
inDoing = true;
|
|
||||||
try {
|
|
||||||
Iec104Client client = new Iec104Client(webSocketServer);
|
|
||||||
client.connect(ip, 2404);
|
|
||||||
client.keep = true;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
String err = "IEC104客户端连接异常, ip=" + ip;
|
|
||||||
log.error(err, ex);
|
|
||||||
throw new BusinessException(err);
|
|
||||||
} finally {
|
|
||||||
inDoing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopCollect() {
|
|
||||||
if (StaticVariable.realTime104Client != null) {
|
|
||||||
StaticVariable.realTime104Client.keep = false;
|
|
||||||
StaticVariable.realTime104Client.disconnect();
|
|
||||||
StaticVariable.realTime104Client = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreDestroy
|
|
||||||
private void stop() {
|
|
||||||
log.info("关闭IEC104客户端.");
|
|
||||||
StaticVariable.shutdown = 1;
|
|
||||||
this.stopCollect();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,123 +0,0 @@
|
|||||||
package com.xydl.cac.iec104;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.Iec104Point;
|
|
||||||
import com.xydl.cac.model.StaticVariable;
|
|
||||||
import com.xydl.cac.util.DateUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.openmuc.j60870.*;
|
|
||||||
import org.openmuc.j60870.ie.*;
|
|
||||||
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class ServerConnectionEventListener implements ConnectionEventListener {
|
|
||||||
Connection connection;
|
|
||||||
int connectionId;
|
|
||||||
boolean selected = false;
|
|
||||||
|
|
||||||
public ServerConnectionEventListener(Connection connection, int connectionId) {
|
|
||||||
this.connection = connection;
|
|
||||||
this.connectionId = connectionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void newASdu(Connection connection, ASdu aSdu) {
|
|
||||||
log.info("Got new ASdu, type=" + aSdu.getTypeIdentification());
|
|
||||||
InformationObject informationObject = null;
|
|
||||||
try {
|
|
||||||
switch (aSdu.getTypeIdentification()) {
|
|
||||||
// interrogation command
|
|
||||||
case C_IC_NA_1:
|
|
||||||
log.debug("Got interrogation command (100). Will send scaled measured values.");
|
|
||||||
connection.sendConfirmation(aSdu);
|
|
||||||
|
|
||||||
this.sendAll104(connection);
|
|
||||||
|
|
||||||
connection.sendActivationTermination(aSdu);
|
|
||||||
break;
|
|
||||||
case C_SC_NA_1:
|
|
||||||
informationObject = aSdu.getInformationObjects()[0];
|
|
||||||
IeSingleCommand singleCommand = (IeSingleCommand) informationObject
|
|
||||||
.getInformationElements()[0][0];
|
|
||||||
|
|
||||||
if (informationObject.getInformationObjectAddress() != 5000) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (singleCommand.isSelect()) {
|
|
||||||
log.debug("Got single command (45) with select true. Select command.");
|
|
||||||
selected = true;
|
|
||||||
connection.sendConfirmation(aSdu);
|
|
||||||
} else if (!singleCommand.isSelect() && selected) {
|
|
||||||
log.debug("Got single command (45) with select false. Execute selected command.");
|
|
||||||
selected = false;
|
|
||||||
connection.sendConfirmation(aSdu);
|
|
||||||
} else {
|
|
||||||
log.debug("Got single command (45) with select false. But no command is selected, no execution.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case C_CS_NA_1:
|
|
||||||
IeTime56 ieTime56 = new IeTime56(System.currentTimeMillis());
|
|
||||||
log.debug("Got Clock synchronization command (103). Send current time: " + ieTime56.toString());
|
|
||||||
connection.synchronizeClocks(aSdu.getCommonAddress(), ieTime56);
|
|
||||||
break;
|
|
||||||
case C_SE_NB_1:
|
|
||||||
log.debug("Got Set point command, scaled value (49)");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
log.debug("Got unknown request: " + aSdu.toString(),
|
|
||||||
". Send negative confirm with CoT UNKNOWN_TYPE_ID(44)");
|
|
||||||
connection.sendConfirmation(aSdu, aSdu.getCommonAddress(), true,
|
|
||||||
CauseOfTransmission.UNKNOWN_TYPE_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (EOFException e) {
|
|
||||||
log.debug("Will quit listening for commands on connection (" + connectionId,
|
|
||||||
") because socket was closed.");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.debug("Will quit listening for commands on connection (" + connectionId, ") because of error: ",
|
|
||||||
e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendAll104(Connection conn) throws Exception {
|
|
||||||
List<Iec104Point> list = StaticVariable.point104_Cache;
|
|
||||||
for (Iec104Point item : list) {
|
|
||||||
this.sendOne104(conn, item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendOne104(Connection conn, Iec104Point item) throws Exception {
|
|
||||||
HashMap<String, String> map = StaticVariable.sensorLastDataMap.get(item.getEqmid());
|
|
||||||
String value = map.get(item.getField());
|
|
||||||
String time = map.get("acquisitionTime");
|
|
||||||
if (value != null && time != null) {
|
|
||||||
Date date = DateUtil.parse(time);
|
|
||||||
Float f = Float.valueOf(value);
|
|
||||||
InformationObject infoObj = new InformationObject(item.getSadr(), new InformationElement[][]{
|
|
||||||
{new IeShortFloat(f),
|
|
||||||
new IeQuality(false, false, false, false, false),
|
|
||||||
new IeTime56(date.getTime())}
|
|
||||||
});
|
|
||||||
ASdu obj = new ASdu(ASduType.M_ME_TF_1, true, CauseOfTransmission.INTERROGATED_BY_STATION,
|
|
||||||
false, false, 0, 1, infoObj);
|
|
||||||
conn.send(obj);
|
|
||||||
log.info("104服务端发送: sadr=" + item.getSadr() + ", value=" + value + ", time=" + time);
|
|
||||||
} else {
|
|
||||||
log.info("数据不全,104服务端不发送: sadr=" + item.getSadr() + ", value=" + value + ", time=" + time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connectionClosed(Connection connection, IOException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dataTransferStateChanged(Connection connection, boolean b) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
package com.xydl.cac.model.spectrogram;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class SouthPd extends SpectrogramModel {
|
|
||||||
Float version;
|
|
||||||
Float fileVersion;
|
|
||||||
Short code;
|
|
||||||
String flag;
|
|
||||||
String name;
|
|
||||||
String pdType;
|
|
||||||
String warnLevel;
|
|
||||||
String probabilityFlag;
|
|
||||||
Float probability1;
|
|
||||||
Float probability2;
|
|
||||||
Float probability3;
|
|
||||||
Float probability4;
|
|
||||||
Float probability5;
|
|
||||||
Float probability6;
|
|
||||||
Float probability7;
|
|
||||||
Integer m;
|
|
||||||
Integer n;
|
|
||||||
Integer p;
|
|
||||||
Float hz50;
|
|
||||||
Float hz100;
|
|
||||||
String picType;
|
|
||||||
String unit;
|
|
||||||
Float minLimit;
|
|
||||||
Float maxLimit;
|
|
||||||
|
|
||||||
List<List<Integer>> dataPD;
|
|
||||||
List<List<Float>> dataPS;
|
|
||||||
|
|
||||||
public void readFrom(DataInputStream dis) throws Exception {
|
|
||||||
version = readLittleEndianFloat(dis);
|
|
||||||
fileVersion = readLittleEndianFloat(dis);
|
|
||||||
code = readLittleEndianShort(dis);
|
|
||||||
createTime = readLittleEndianLong(dis);
|
|
||||||
flag = readString(dis, 1);
|
|
||||||
name = readString(dis, 32);
|
|
||||||
pdType = readString(dis, 1);
|
|
||||||
warnLevel = readString(dis, 1);
|
|
||||||
probabilityFlag = readString(dis, 1);
|
|
||||||
probability1 = readLittleEndianFloat(dis);
|
|
||||||
probability2 = readLittleEndianFloat(dis);
|
|
||||||
probability3 = readLittleEndianFloat(dis);
|
|
||||||
probability4 = readLittleEndianFloat(dis);
|
|
||||||
probability5 = readLittleEndianFloat(dis);
|
|
||||||
probability6 = readLittleEndianFloat(dis);
|
|
||||||
probability7 = readLittleEndianFloat(dis);
|
|
||||||
m = readLittleEndianInt(dis);
|
|
||||||
n = readLittleEndianInt(dis);
|
|
||||||
p = readLittleEndianInt(dis);
|
|
||||||
hz50 = readLittleEndianFloat(dis);
|
|
||||||
hz100 = readLittleEndianFloat(dis);
|
|
||||||
picType = readString(dis, 1);
|
|
||||||
unit = readString(dis, 1);
|
|
||||||
minLimit = readLittleEndianFloat(dis);
|
|
||||||
maxLimit = readLittleEndianFloat(dis);
|
|
||||||
dis.readInt();
|
|
||||||
|
|
||||||
if ("0".equalsIgnoreCase(picType)) {
|
|
||||||
dataPD = new ArrayList<>();
|
|
||||||
for (int i = 0; i < m; i++) {
|
|
||||||
List<Integer> list = new ArrayList<>();
|
|
||||||
for (int j = 0; j < n; j++) {
|
|
||||||
Integer v = readLittleEndianInt(dis);
|
|
||||||
list.add(v);
|
|
||||||
}
|
|
||||||
dataPD.add(list);
|
|
||||||
}
|
|
||||||
} else if ("1".equalsIgnoreCase(picType)) {
|
|
||||||
dataPS = new ArrayList<>();
|
|
||||||
for (int i = 0; i < p; i++) {
|
|
||||||
List<Float> list = new ArrayList<>();
|
|
||||||
for (int j = 0; j < m; j++) {
|
|
||||||
Float v = readLittleEndianFloat(dis);
|
|
||||||
list.add(v);
|
|
||||||
}
|
|
||||||
dataPS.add(list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
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;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
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 +0,0 @@
|
|||||||
package com.xydl.cac.repository;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.Iec104Point;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface Iec104PointRepository extends JpaRepository<Iec104Point, Integer>, JpaSpecificationExecutor<Iec104Point> {
|
|
||||||
List<Iec104Point> findBySadr(Integer sadr);
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.xydl.cac.repository;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.ThermalConfig;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface ThermalConfigRepository extends JpaRepository<ThermalConfig, Integer>, JpaSpecificationExecutor<ThermalConfig> {
|
|
||||||
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.xydl.cac.service;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.Iec104Point;
|
|
||||||
import com.xydl.cac.exception.BusinessException;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface Iec104PointService {
|
|
||||||
|
|
||||||
List<Iec104Point> findAll();
|
|
||||||
|
|
||||||
Iec104Point add(Iec104Point point) throws BusinessException;
|
|
||||||
|
|
||||||
void delete(Integer id);
|
|
||||||
|
|
||||||
}
|
|
@ -1,20 +1,13 @@
|
|||||||
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, Integer devId, Date startTime, Date endTime, int pageNum, int pageSize) throws Exception;
|
Page<IedDlRecord> list(Integer configId, 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;
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
package com.xydl.cac.service;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.ThermalConfig;
|
|
||||||
|
|
||||||
|
|
||||||
public interface ThermalConfigService {
|
|
||||||
|
|
||||||
ThermalConfig getConfig();
|
|
||||||
|
|
||||||
void saveConfig(ThermalConfig model);
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package com.xydl.cac.service.impl;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.Iec104Point;
|
|
||||||
import com.xydl.cac.exception.BusinessException;
|
|
||||||
import com.xydl.cac.model.StaticVariable;
|
|
||||||
import com.xydl.cac.repository.Iec104PointRepository;
|
|
||||||
import com.xydl.cac.service.Iec104PointService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public class Iec104PointServiceImpl implements Iec104PointService {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
Iec104PointRepository iec104PointRepository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Iec104Point> findAll() {
|
|
||||||
StaticVariable.point104_Cache = iec104PointRepository.findAll();
|
|
||||||
return StaticVariable.point104_Cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iec104Point add(Iec104Point point) throws BusinessException {
|
|
||||||
List<Iec104Point> list = iec104PointRepository.findBySadr(point.getSadr());
|
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
|
||||||
point.setId(null);
|
|
||||||
point.setCreateTime(new Date());
|
|
||||||
return iec104PointRepository.save(point);
|
|
||||||
} else {
|
|
||||||
throw new BusinessException("该点位已存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(Integer id) {
|
|
||||||
iec104PointRepository.deleteById(id);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package com.xydl.cac.service.impl;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.ThermalConfig;
|
|
||||||
import com.xydl.cac.repository.ThermalConfigRepository;
|
|
||||||
import com.xydl.cac.service.ThermalConfigService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public class ThermalConfigServiceImpl implements ThermalConfigService {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
ThermalConfigRepository repository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ThermalConfig getConfig() {
|
|
||||||
ThermalConfig result = null;
|
|
||||||
List<ThermalConfig> list = repository.findAll();
|
|
||||||
if (!CollectionUtils.isEmpty(list)) {
|
|
||||||
result = list.get(0);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveConfig(ThermalConfig model) {
|
|
||||||
repository.deleteAll();
|
|
||||||
model.setId(null);
|
|
||||||
repository.save(model);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package com.xydl.cac.spectrogram;
|
|
||||||
|
|
||||||
import com.xydl.cac.model.spectrogram.SouthPd;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class ProcessorPd {
|
|
||||||
|
|
||||||
public SouthPd process(String localFilePath) {
|
|
||||||
try (DataInputStream dis = new DataInputStream(new FileInputStream(localFilePath))) {
|
|
||||||
SouthPd model = this.readOneBlock(dis);
|
|
||||||
return model;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析文件失败" + localFilePath, e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private SouthPd readOneBlock(DataInputStream dis) throws Exception {
|
|
||||||
SouthPd model = new SouthPd();
|
|
||||||
model.readFrom(dis);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
ProcessorPd processorYsp = new ProcessorPd();
|
|
||||||
processorYsp.process("C:/Code/cac/局放谱图/50100055_5__001_01_20250409180000.dat");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
package com.xydl.cac.spectrogram;
|
|
||||||
|
|
||||||
import com.xydl.cac.config.BizConfig;
|
|
||||||
import com.xydl.cac.entity.IedDlRecord;
|
|
||||||
import com.xydl.cac.entity.ModevType;
|
|
||||||
import com.xydl.cac.model.spectrogram.SouthPd;
|
|
||||||
import com.xydl.cac.model.spectrogram.SouthYsp;
|
|
||||||
import com.xydl.cac.model.spectrogram.SpectrogramModel;
|
|
||||||
import com.xydl.cac.service.ModevTypeService;
|
|
||||||
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
|
|
||||||
ModevTypeService modevTypeService;
|
|
||||||
@Resource
|
|
||||||
ProcessorYsp processorYsp;
|
|
||||||
@Resource
|
|
||||||
ProcessorPd processorPd;
|
|
||||||
|
|
||||||
public void processFile(IedDlRecord record) {
|
|
||||||
record.setCreateTime(new Date());
|
|
||||||
if (record.getTypeId() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String localFilePath = record.getPath().replaceFirst(bizConfig.getDataNginxPath(), bizConfig.getDatapath());
|
|
||||||
try {
|
|
||||||
ModevType modevType = modevTypeService.detail(record.getTypeId());
|
|
||||||
|
|
||||||
// 谱图解析
|
|
||||||
if (modevType.getMc().contains("油色谱")) {
|
|
||||||
SouthYsp model = processorYsp.process(localFilePath);
|
|
||||||
this.setData(record, model);
|
|
||||||
log.info("解析油色谱谱图文件成功");
|
|
||||||
} else if (modevType.getMc().contains("局部放电")) {
|
|
||||||
SouthPd model = processorPd.process(localFilePath);
|
|
||||||
this.setData(record, model);
|
|
||||||
log.info("解析局部放电谱图文件成功");
|
|
||||||
} else {
|
|
||||||
log.error("缺少该类型" + record.getTypeId() + "的谱图处理模块");
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("解析谱图文件失败, typeId=" + record.getTypeId() + ", devId=" + record.getDevId()
|
|
||||||
+ ", file=" + localFilePath, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setData(IedDlRecord record, SpectrogramModel model) {
|
|
||||||
String json = JSONUtil.object2Json(model);
|
|
||||||
record.setData(json);
|
|
||||||
try {
|
|
||||||
String str = String.valueOf(model.getCreateTime());
|
|
||||||
Date dtime = DateUtil.parse(str, "yyyyMMddHHmmss");
|
|
||||||
record.setDTime(dtime);
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void jsonToModel(IedDlRecord record) {
|
|
||||||
if (record.getTypeId() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (record.getData() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ModevType modevType = modevTypeService.detail(record.getTypeId());
|
|
||||||
if (modevType.getMc().contains("油色谱")) {
|
|
||||||
SouthYsp model = JSONUtil.json2Object(record.getData(), SouthYsp.class);
|
|
||||||
record.setModel(model);
|
|
||||||
record.setData(null);
|
|
||||||
} else if (modevType.getMc().contains("局部放电")) {
|
|
||||||
SouthPd model = JSONUtil.json2Object(record.getData(), SouthPd.class);
|
|
||||||
record.setModel(model);
|
|
||||||
record.setData(null);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("谱图数据data内容存在异常, typeId=" + record.getTypeId() + ", devId=" + record.getDevId()
|
|
||||||
+ ", file=" + record.getPath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
package com.xydl.cac.task;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.ModevType;
|
|
||||||
import com.xydl.cac.entity.NSensor;
|
|
||||||
import com.xydl.cac.entity.ThermalConfig;
|
|
||||||
import com.xydl.cac.model.StaticVariable;
|
|
||||||
import com.xydl.cac.repository.NSensorRepository;
|
|
||||||
import com.xydl.cac.service.ModevTypeService;
|
|
||||||
import com.xydl.cac.service.ThermalConfigService;
|
|
||||||
import com.xydl.cac.thermal.ThermalCollectService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class ClientThermalTask {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
ThermalConfigService configService;
|
|
||||||
@Resource
|
|
||||||
ModevTypeService modevTypeService;
|
|
||||||
@Resource
|
|
||||||
NSensorRepository sensorRepository;
|
|
||||||
@Resource
|
|
||||||
ThermalCollectService collectService;
|
|
||||||
|
|
||||||
int shutdown = 0;
|
|
||||||
boolean inDoing = false;
|
|
||||||
|
|
||||||
@PreDestroy
|
|
||||||
private void preDestroy() {
|
|
||||||
shutdown = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 * * * * ?")
|
|
||||||
public void collectAll() {
|
|
||||||
if (!StaticVariable.ready) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ThermalConfig config = configService.getConfig();
|
|
||||||
if (config == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (inDoing) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
inDoing = true;
|
|
||||||
try {
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
int h = cal.get(Calendar.HOUR_OF_DAY);
|
|
||||||
int m = cal.get(Calendar.MINUTE);
|
|
||||||
m = h * 60 + m;
|
|
||||||
|
|
||||||
ModevType modevType = modevTypeService.detail(config.getTypeId());
|
|
||||||
int intervals = 30;
|
|
||||||
if (modevType.getIntervals() != null) {
|
|
||||||
intervals = modevType.getIntervals();
|
|
||||||
}
|
|
||||||
int x = m % intervals;
|
|
||||||
if (x == 0) {
|
|
||||||
this.collectOneConfig(config, modevType);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("ClientThermalTask.collectAll error.", e);
|
|
||||||
} finally {
|
|
||||||
inDoing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void collectOneConfig(ThermalConfig config, ModevType modevType) {
|
|
||||||
if (shutdown == 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<NSensor> list = sensorRepository.findByTypeId(modevType.getId());
|
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (NSensor sensor : list) {
|
|
||||||
sensor.setTableName(modevType.getTablename());
|
|
||||||
}
|
|
||||||
collectService.collectAndSave(list, config);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package com.xydl.cac.thermal;
|
|
||||||
|
|
||||||
import com.hcsdk.HCNetSDK;
|
|
||||||
import com.sun.jna.Pointer;
|
|
||||||
import com.xydl.cac.entity.NSensor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class HCRemoteConfigCallBack implements HCNetSDK.FRemoteConfigCallBack {
|
|
||||||
|
|
||||||
public boolean done;
|
|
||||||
public NSensor item;
|
|
||||||
public String time;
|
|
||||||
public HCThermalService service;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invoke(int dwType, Pointer lpBuffer, int dwBufLen, Pointer pUserData) {
|
|
||||||
if (done) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD data = new HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD();
|
|
||||||
Pointer pointer = data.getPointer();
|
|
||||||
pointer.write(0, lpBuffer.getByteArray(0, data.size()), 0, data.size());
|
|
||||||
data.read();
|
|
||||||
float max, min, aver;
|
|
||||||
if (0 == data.byRuleCalibType) {
|
|
||||||
max = data.struPointThermCfg.fTemperature;
|
|
||||||
min = max;
|
|
||||||
aver = max;
|
|
||||||
log.info("海康热成像采集到max=" + max + ", min=" + min + ", aver=" + aver);
|
|
||||||
service.save(item.getTableName(), item.getDevId(),
|
|
||||||
max, min, aver, time);
|
|
||||||
done = true;
|
|
||||||
} else if (1 == data.byRuleCalibType || 2 == data.byRuleCalibType) {
|
|
||||||
aver = data.struLinePolygonThermCfg.fAverageTemperature;
|
|
||||||
min = data.struLinePolygonThermCfg.fMinTemperature;
|
|
||||||
max = data.struLinePolygonThermCfg.fMaxTemperature;
|
|
||||||
log.info("海康热成像采集到max=" + max + ", min=" + min + ", aver=" + aver);
|
|
||||||
service.save(item.getTableName(), item.getDevId(),
|
|
||||||
max, min, aver, time);
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("HCRemoteConfigCallBack异常", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
package com.xydl.cac.thermal;
|
|
||||||
|
|
||||||
import com.hcsdk.HCModule;
|
|
||||||
import com.xydl.cac.entity.NSensor;
|
|
||||||
import com.xydl.cac.entity.ThermalConfig;
|
|
||||||
import com.xydl.cac.model.StaticVariable;
|
|
||||||
import com.xydl.cac.service.DataService;
|
|
||||||
import com.xydl.cac.util.DateUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class HCThermalService {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
DataService dataService;
|
|
||||||
@Resource
|
|
||||||
HCRemoteConfigCallBack _callBack;
|
|
||||||
|
|
||||||
ThermalConfig _config;
|
|
||||||
int shutdown = 0;
|
|
||||||
int maxWait = 20;
|
|
||||||
|
|
||||||
@PreDestroy
|
|
||||||
private void preDestroy() {
|
|
||||||
shutdown = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void collectAndSave(List<NSensor> list, ThermalConfig config) {
|
|
||||||
if (shutdown == 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_config = config;
|
|
||||||
try {
|
|
||||||
HCModule.init();
|
|
||||||
NSensor sensor = list.get(0);
|
|
||||||
boolean r = HCModule.login(sensor.getIp(), sensor.getPort().shortValue(), sensor.getUsername(), sensor.getPasswd());
|
|
||||||
if (r) {
|
|
||||||
log.info("海康热成像登入成功" + sensor.getIp() + ":" + sensor.getPort()
|
|
||||||
+ ", 用户名:" + sensor.getUsername() + ", 密码:" + sensor.getPasswd());
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (NSensor item : list) {
|
|
||||||
_callBack.done = false;
|
|
||||||
_callBack.item = item;
|
|
||||||
_callBack.time = DateUtil.format(new Date());
|
|
||||||
_callBack.service = this;
|
|
||||||
r = HCModule.startRemoteConfig(_callBack, item.getChannel(), item.getTmId());
|
|
||||||
if (r) {
|
|
||||||
int sec = 0;
|
|
||||||
while (shutdown == 0 && sec < maxWait && !_callBack.done) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
sec++;
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HCModule.stopRemoteConfig();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HCModule.logout();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("海康热成像测温采集异常, " + ex.getMessage(), ex);
|
|
||||||
} finally {
|
|
||||||
HCModule.cleanup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Async
|
|
||||||
public void save(String tableName, Integer devId,
|
|
||||||
float max, float min, float aver, String time) {
|
|
||||||
if (StringUtils.isNotBlank(_config.getMaxtemp())) {
|
|
||||||
String value = String.valueOf(max);
|
|
||||||
dataService.insertData(tableName, devId, time, _config.getMaxtemp(), value);
|
|
||||||
// 更新最新数据缓存
|
|
||||||
StaticVariable.updateLastData(devId, _config.getMaxtemp(), value, time);
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(_config.getMintemp())) {
|
|
||||||
String value = String.valueOf(min);
|
|
||||||
dataService.insertData(tableName, devId, time, _config.getMintemp(), value);
|
|
||||||
// 更新最新数据缓存
|
|
||||||
StaticVariable.updateLastData(devId, _config.getMintemp(), value, time);
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(_config.getAvertemp())) {
|
|
||||||
String value = String.valueOf(aver);
|
|
||||||
dataService.insertData(tableName, devId, time, _config.getAvertemp(), value);
|
|
||||||
// 更新最新数据缓存
|
|
||||||
StaticVariable.updateLastData(devId, _config.getAvertemp(), value, time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package com.xydl.cac.thermal;
|
|
||||||
|
|
||||||
import com.xydl.cac.entity.NSensor;
|
|
||||||
import com.xydl.cac.entity.ThermalConfig;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class ThermalCollectService {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
HCThermalService thermalService;
|
|
||||||
|
|
||||||
public void collectAndSave(List<NSensor> list, ThermalConfig config) {
|
|
||||||
HashMap<String, List<NSensor>> map = new HashMap<>();
|
|
||||||
for (NSensor sensor : list) {
|
|
||||||
if (sensor.canTempMeasure()) {
|
|
||||||
String key = sensor.getIp() + sensor.getPort() + sensor.getUsername();
|
|
||||||
List<NSensor> sub = map.get(key);
|
|
||||||
if (sub == null) {
|
|
||||||
sub = new ArrayList<>();
|
|
||||||
map.put(key, sub);
|
|
||||||
}
|
|
||||||
sub.add(sensor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Iterator<String> it = map.keySet().iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
String key = it.next();
|
|
||||||
List<NSensor> sub = map.get(key);
|
|
||||||
thermalService.collectAndSave(sub, config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
package com.xydl.cac.util;
|
|
||||||
|
|
||||||
import com.jcraft.jsch.JSchException;
|
|
||||||
import com.xydl.cac.entity.IedDlRecord;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class JkpgFtp {
|
|
||||||
@Value("${cac.jkpg.ip:}")
|
|
||||||
private String ip;
|
|
||||||
@Value("${cac.jkpg.port:22}")
|
|
||||||
private Integer port;
|
|
||||||
@Value("${cac.jkpg.user:}")
|
|
||||||
private String user;
|
|
||||||
@Value("${cac.jkpg.pass:}")
|
|
||||||
private String pass;
|
|
||||||
@Value("${cac.jkpg.pass:}")
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
SFTPTool sftpTool = new SFTPTool();
|
|
||||||
boolean connected = false;
|
|
||||||
|
|
||||||
public void connect() {
|
|
||||||
if (StringUtils.isBlank(ip)) {
|
|
||||||
log.error("健康评估的IP未配置");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(user)) {
|
|
||||||
log.error("健康评估的user未配置");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
sftpTool.connect(ip, port, user, pass);
|
|
||||||
sftpTool.cdmkdir(path);
|
|
||||||
connected = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("SFTP连接健康评估失败", e);
|
|
||||||
connected = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void upload(IedDlRecord record) {
|
|
||||||
if (!connected) {
|
|
||||||
this.connect();
|
|
||||||
}
|
|
||||||
if (connected) {
|
|
||||||
try {
|
|
||||||
sftpTool.upload(record.getLocalFullPath(), record.getFilename());
|
|
||||||
log.info("SFTP上传健康评估成功, " + record.getFilename());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("SFTP上传健康评估失败, " + record.getFilename(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue