mqtt
parent
6806673b96
commit
1d39ab3c93
@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.xydl</groupId>
|
||||
<artifactId>mqtt</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.1</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- MQTT依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
<!--mysql驱动依赖-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.28</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 阿里巴巴JSON -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.31_noneautotype</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--mybatis-plus相关依赖-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
|
||||
<!--数据连接池druid-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,18 @@
|
||||
package com.xydl;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@EnableScheduling
|
||||
@MapperScan(basePackages = "com.xydl.mapper")
|
||||
@SpringBootApplication//标识该类为主程序启动类
|
||||
public class MqttApplication {
|
||||
//主程序启动方法
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MqttApplication.class,args);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.xydl.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class DruidConfig {
|
||||
@ConfigurationProperties(prefix = "spring.datasource")
|
||||
@Bean
|
||||
public DruidDataSource getDurid(){
|
||||
return new DruidDataSource();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.xydl.config;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MyBatisConfig {
|
||||
|
||||
public ConfigurationCustomizer configurationCustomizer(){
|
||||
return new ConfigurationCustomizer() {
|
||||
@Override
|
||||
public void customize(MybatisConfiguration configuration) {
|
||||
//下划线与驼峰命名进行自动映射
|
||||
configuration.setMapUnderscoreToCamelCase(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.xydl.controller;
|
||||
|
||||
import com.xydl.util.DataSourceUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.*;
|
||||
|
||||
|
||||
@RestController
|
||||
public class JDBCController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataSourceUtils.class);
|
||||
|
||||
|
||||
@RequestMapping("/data")
|
||||
public void getData() {
|
||||
Connection conn = null;
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
conn = DataSourceUtils.getConnection();
|
||||
String sql = "insert into pop_id(node_id,id) values(?,?)";
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setString(1, "");
|
||||
pstmt.setInt(2, 100);
|
||||
pstmt.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
logger.error("execute sql exception:", e);
|
||||
} finally {
|
||||
DataSourceUtils.closeResource(pstmt, conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.xydl.controller;
|
||||
|
||||
|
||||
import com.xydl.model.Eia;
|
||||
import com.xydl.service.EiaService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
@Autowired
|
||||
private EiaService eiaService;
|
||||
|
||||
@RequestMapping("/eia")
|
||||
@ResponseBody
|
||||
public List<Eia> eia() {
|
||||
System.out.println("get eia");
|
||||
return eiaService.getEia();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
|
||||
import com.xydl.model.Eaif;
|
||||
import com.xydl.model.Epa;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface EaifMapper {
|
||||
|
||||
|
||||
//红外测温
|
||||
List<Eaif> getEaif();
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
import com.xydl.model.Eia;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface EiaMapper {
|
||||
|
||||
|
||||
//铁芯、夹件、电容性设备
|
||||
List<Eia> getEia();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
import com.xydl.model.Epa;
|
||||
import com.xydl.model.SuperModel;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface EpaMapper {
|
||||
|
||||
|
||||
//油色谱
|
||||
List<Epa> getEpa(int devid);
|
||||
|
||||
List<SuperModel> getData(String sql);
|
||||
|
||||
List<Integer> getEqmidsByTableName(String tableName);
|
||||
|
||||
List<String> getTableNamesBySyncTable(String syncTable);
|
||||
|
||||
String getSqlBySyncTable(String syncTable, String tableName);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
import com.xydl.model.Etp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface EtpMapper {
|
||||
|
||||
|
||||
//绕组测温
|
||||
List<Etp> getEtp();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
|
||||
import com.xydl.model.Epa;
|
||||
import com.xydl.model.Microclimate;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface MicMapper {
|
||||
|
||||
|
||||
|
||||
//微气象
|
||||
List<Microclimate> getMicroclimate();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
|
||||
import com.xydl.model.Epa;
|
||||
import com.xydl.model.Moa;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface MoaMapper {
|
||||
|
||||
|
||||
|
||||
//绝缘监测-金属氧化物
|
||||
List<Moa> getMoa();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
|
||||
import com.xydl.model.Epa;
|
||||
import com.xydl.model.Pd;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface PdMapper {
|
||||
|
||||
|
||||
|
||||
//局放监测
|
||||
List<Pd> getPd();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
import com.xydl.model.Eia;
|
||||
import com.xydl.model.Epa;
|
||||
import com.xydl.model.Etp;
|
||||
import com.xydl.model.RptTemper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface RptTemperMapper {
|
||||
|
||||
|
||||
|
||||
//测温点
|
||||
List<RptTemper> getRptTemper();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
|
||||
import com.xydl.model.Epa;
|
||||
import com.xydl.model.Scur;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface ScurMapper {
|
||||
|
||||
|
||||
|
||||
//电缆环流
|
||||
List<Scur> getScur();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
import com.xydl.model.Epa;
|
||||
import com.xydl.model.Sf6;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface Sf6Mapper {
|
||||
|
||||
|
||||
//SF6监测
|
||||
List<Sf6> getSf6();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.xydl.mapper;
|
||||
|
||||
|
||||
import com.xydl.model.Epa;
|
||||
import com.xydl.model.Sf6env;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface Sf6envMapper {
|
||||
|
||||
|
||||
//SF6环境
|
||||
List<Sf6env> getSf6env();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Eaif {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String captureTime;
|
||||
|
||||
@JsonProperty("MaxTmp")
|
||||
private double maxTemp;
|
||||
|
||||
@JsonProperty("MinTmp")
|
||||
private double minTemp;
|
||||
|
||||
@JsonProperty("AvgTmp")
|
||||
private double avgTemp;
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Eia {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String captureTime;
|
||||
|
||||
@JsonProperty("MaxTmp")
|
||||
private String maxTemp;
|
||||
|
||||
@JsonProperty("MinTmp")
|
||||
private String minTemp;
|
||||
|
||||
@JsonProperty("AvgTmp")
|
||||
private String avgTemp;
|
||||
|
||||
@JsonProperty("Phase")
|
||||
private String phase;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/*
|
||||
油色谱
|
||||
*/
|
||||
@Data
|
||||
public class Epa {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String dTime ;
|
||||
|
||||
@JsonProperty("H2")
|
||||
private double h2ppm;
|
||||
|
||||
@JsonProperty("CH4")
|
||||
private double ch4ppm;
|
||||
|
||||
@JsonProperty("C2H6")
|
||||
private double c2h6ppm;
|
||||
|
||||
@JsonProperty("C2H4")
|
||||
private double c2h4ppm;
|
||||
|
||||
@JsonProperty("C2H2")
|
||||
private double c2h2ppm;
|
||||
|
||||
@JsonProperty("CO")
|
||||
private double coppm;
|
||||
|
||||
@JsonProperty("CO2")
|
||||
private double co2ppm;
|
||||
|
||||
@JsonProperty("O2")
|
||||
private double o2ppm;
|
||||
|
||||
@JsonProperty("N2")
|
||||
private double n2ppm;
|
||||
|
||||
@JsonProperty("TotalHydrocarbon")
|
||||
private double totalHydroCarbon;
|
||||
|
||||
@JsonProperty("GasPress")
|
||||
private double gaspress;
|
||||
|
||||
@JsonProperty("H2O")
|
||||
private double h2oppm;
|
||||
|
||||
@JsonProperty("Phase")
|
||||
private String phase;
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Etp {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String dTime;
|
||||
|
||||
@JsonProperty("MaxTmp")
|
||||
private double t1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Microclimate {
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String dTime;
|
||||
|
||||
@JsonProperty("AirTemperature")
|
||||
private double envTmp;
|
||||
|
||||
@JsonProperty("AirPressure")
|
||||
private double envPres;
|
||||
|
||||
@JsonProperty("Humidity")
|
||||
private double envHum;
|
||||
|
||||
@JsonProperty("Precipitation")
|
||||
private double rnfll;
|
||||
|
||||
@JsonProperty("PrecipitationIntensity")
|
||||
private double PreciInten = 0;
|
||||
|
||||
@JsonProperty("RadiationIntensity")
|
||||
private double radiInten = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Moa {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String captureTime;
|
||||
|
||||
@JsonProperty("SystemVoltage")
|
||||
private double pt1;
|
||||
|
||||
@JsonProperty("TotalCurrent")
|
||||
private double lc1;
|
||||
|
||||
@JsonProperty("ResistiveCurrent")
|
||||
private double rc1;
|
||||
|
||||
@JsonProperty("ActionCount")
|
||||
private double ligcnt1;
|
||||
|
||||
@JsonProperty("LastActionTime")
|
||||
private String lastligtm1;
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Pd {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String dTime;
|
||||
|
||||
@JsonProperty("DischargeCapacity")
|
||||
private double waveForm;
|
||||
|
||||
@JsonProperty("DischargePosition")
|
||||
private double apppadsch;
|
||||
|
||||
@JsonProperty("PulseCount")
|
||||
private double plsNum;
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class RptTemper {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String createTime;
|
||||
|
||||
@JsonProperty("OlTmpA")
|
||||
private double aoTemper;
|
||||
|
||||
@JsonProperty("OlTmpB")
|
||||
private double boTemper;
|
||||
|
||||
@JsonProperty("OlTmpC")
|
||||
private double coTemper;
|
||||
|
||||
@JsonProperty("IlTmpA")
|
||||
private double aiTemper;
|
||||
|
||||
@JsonProperty("IlTmpB")
|
||||
private double biTemper;
|
||||
|
||||
@JsonProperty("IlTmpC")
|
||||
private double ciTemper;
|
||||
|
||||
@JsonProperty("OntologyTmp")
|
||||
private double boxTemper;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Scur {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String dTime;
|
||||
|
||||
@JsonProperty("CoreCurrent")
|
||||
private double currentVal;
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Sf6 {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String dTime;
|
||||
|
||||
@JsonProperty("Temperature")
|
||||
private double temp1;
|
||||
|
||||
@JsonProperty("Pressure20C")
|
||||
private double pressure1;
|
||||
|
||||
@JsonProperty("AbsolutePressure")
|
||||
private double AbsolutePressure = pressure1 + 900;
|
||||
|
||||
@JsonProperty("Density")
|
||||
private double md1;
|
||||
|
||||
@JsonProperty("Moisture")
|
||||
private double pm1;
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Sf6env {
|
||||
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String dTime;
|
||||
|
||||
@JsonProperty("gas1")
|
||||
private double gas1;
|
||||
|
||||
@JsonProperty("yq1")
|
||||
private double yq1;
|
||||
|
||||
@JsonProperty("md1")
|
||||
private double md1;
|
||||
|
||||
@JsonProperty("pm1")
|
||||
private double pm1;
|
||||
|
||||
@JsonProperty("gascnt1")
|
||||
private double gascnt1;
|
||||
|
||||
@JsonProperty("hmcnt1")
|
||||
private double hmcnt1;
|
||||
|
||||
@JsonProperty("sf6warn1")
|
||||
private double sf6warn1;
|
||||
|
||||
@JsonProperty("o2warn1")
|
||||
private double o2warn1;
|
||||
}
|
@ -0,0 +1,231 @@
|
||||
package com.xydl.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class SuperModel {
|
||||
|
||||
/**
|
||||
* EPA
|
||||
*/
|
||||
@JsonProperty("SubDeviceID")
|
||||
private String subDeviceID;
|
||||
|
||||
@JsonProperty("SensorCode")
|
||||
private String sensorId;
|
||||
|
||||
@JsonProperty("AcquisitionTime")
|
||||
private String dTime ;
|
||||
|
||||
@JsonProperty("H2")
|
||||
private double h2ppm;
|
||||
|
||||
@JsonProperty("CH4")
|
||||
private double ch4ppm;
|
||||
|
||||
@JsonProperty("C2H6")
|
||||
private double c2h6ppm;
|
||||
|
||||
@JsonProperty("C2H4")
|
||||
private double c2h4ppm;
|
||||
|
||||
@JsonProperty("C2H2")
|
||||
private double c2h2ppm;
|
||||
|
||||
@JsonProperty("CO")
|
||||
private double coppm;
|
||||
|
||||
@JsonProperty("CO2")
|
||||
private double co2ppm;
|
||||
|
||||
@JsonProperty("O2")
|
||||
private double o2ppm;
|
||||
|
||||
@JsonProperty("N2")
|
||||
private double n2ppm;
|
||||
|
||||
@JsonProperty("TotalHydrocarbon")
|
||||
private double totalHydroCarbon;
|
||||
|
||||
@JsonProperty("GasPress")
|
||||
private double gaspress;
|
||||
|
||||
@JsonProperty("H2O")
|
||||
private double h2oppm;
|
||||
|
||||
@JsonProperty("Phase")
|
||||
private String phase;
|
||||
|
||||
/**
|
||||
* Eaif
|
||||
*/
|
||||
|
||||
// @JsonProperty("AcquisitionTime")
|
||||
// private String captureTime;
|
||||
|
||||
@JsonProperty("MaxTmp")
|
||||
private double maxTemp;
|
||||
|
||||
@JsonProperty("MinTmp")
|
||||
private double minTemp;
|
||||
|
||||
@JsonProperty("AvgTmp")
|
||||
private double avgTemp;
|
||||
|
||||
/**
|
||||
* Eia
|
||||
*/
|
||||
|
||||
/**
|
||||
* Etp
|
||||
*/
|
||||
|
||||
|
||||
// @JsonProperty("MaxTmp")
|
||||
// private double t1;
|
||||
|
||||
|
||||
/**
|
||||
* Microclimate
|
||||
*/
|
||||
|
||||
|
||||
@JsonProperty("AirTemperature")
|
||||
private double envTmp;
|
||||
|
||||
@JsonProperty("AirPressure")
|
||||
private double envPres;
|
||||
|
||||
@JsonProperty("Humidity")
|
||||
private double envHum;
|
||||
|
||||
@JsonProperty("Precipitation")
|
||||
private double rnfll;
|
||||
|
||||
@JsonProperty("PrecipitationIntensity")
|
||||
private double PreciInten = 0;
|
||||
|
||||
@JsonProperty("RadiationIntensity")
|
||||
private double radiInten = 0;
|
||||
|
||||
/**
|
||||
* Moa
|
||||
*/
|
||||
|
||||
|
||||
@JsonProperty("SystemVoltage")
|
||||
private double pt1;
|
||||
|
||||
@JsonProperty("TotalCurrent")
|
||||
private double lc1;
|
||||
|
||||
@JsonProperty("ResistiveCurrent")
|
||||
private double rc1;
|
||||
|
||||
@JsonProperty("ActionCount")
|
||||
private double ligcnt1;
|
||||
|
||||
@JsonProperty("LastActionTime")
|
||||
private String lastligtm1;
|
||||
|
||||
/**
|
||||
* Pd
|
||||
*/
|
||||
|
||||
|
||||
@JsonProperty("DischargeCapacity")
|
||||
private double waveForm;
|
||||
|
||||
@JsonProperty("DischargePosition")
|
||||
private double apppadsch;
|
||||
|
||||
@JsonProperty("PulseCount")
|
||||
private double plsNum;
|
||||
|
||||
/**
|
||||
* RptTemper
|
||||
*/
|
||||
|
||||
|
||||
// @JsonProperty("AcquisitionTime")
|
||||
// private String createTime;
|
||||
|
||||
@JsonProperty("OlTmpA")
|
||||
private double aoTemper;
|
||||
|
||||
@JsonProperty("OlTmpB")
|
||||
private double boTemper;
|
||||
|
||||
@JsonProperty("OlTmpC")
|
||||
private double coTemper;
|
||||
|
||||
@JsonProperty("IlTmpA")
|
||||
private double aiTemper;
|
||||
|
||||
@JsonProperty("IlTmpB")
|
||||
private double biTemper;
|
||||
|
||||
@JsonProperty("IlTmpC")
|
||||
private double ciTemper;
|
||||
|
||||
@JsonProperty("OntologyTmp")
|
||||
private double boxTemper;
|
||||
|
||||
/**
|
||||
* Scur
|
||||
*/
|
||||
|
||||
|
||||
@JsonProperty("CoreCurrent")
|
||||
private double currentVal;
|
||||
|
||||
/**
|
||||
* Sf6
|
||||
*/
|
||||
|
||||
|
||||
@JsonProperty("Temperature")
|
||||
private double temp1;
|
||||
|
||||
@JsonProperty("Pressure20C")
|
||||
private double pressure1;
|
||||
|
||||
@JsonProperty("AbsolutePressure")
|
||||
private double AbsolutePressure = pressure1 + 900;
|
||||
|
||||
@JsonProperty("Density")
|
||||
private double md1Sf6;
|
||||
|
||||
@JsonProperty("Moisture")
|
||||
private double pm1Sf6;
|
||||
|
||||
|
||||
/**
|
||||
* Sf6env
|
||||
*/
|
||||
|
||||
@JsonProperty("gas1")
|
||||
private double gas1;
|
||||
|
||||
@JsonProperty("yq1")
|
||||
private double yq1;
|
||||
|
||||
@JsonProperty("md1")
|
||||
private double md1;
|
||||
|
||||
@JsonProperty("pm1")
|
||||
private double pm1;
|
||||
|
||||
@JsonProperty("gascnt1")
|
||||
private double gascnt1;
|
||||
|
||||
@JsonProperty("hmcnt1")
|
||||
private double hmcnt1;
|
||||
|
||||
@JsonProperty("sf6warn1")
|
||||
private double sf6warn1;
|
||||
|
||||
@JsonProperty("o2warn1")
|
||||
private double o2warn1;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.xydl.service;
|
||||
|
||||
import com.xydl.model.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface EiaService {
|
||||
|
||||
List<Eaif> getEaif();
|
||||
|
||||
List<Eia> getEia();
|
||||
|
||||
void getEpa();
|
||||
|
||||
List<Etp> getEtp();
|
||||
|
||||
List<Microclimate> getMic();
|
||||
|
||||
List<Moa> getMoa();
|
||||
|
||||
List<Pd> getPd();
|
||||
|
||||
List<RptTemper> getRptTemper();
|
||||
|
||||
List<Scur> getScur();
|
||||
|
||||
List<Sf6> getSf6();
|
||||
|
||||
List<Sf6env> getSf6env();
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,259 @@
|
||||
package com.xydl.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Array;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class CommonUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CommonUtils.class);
|
||||
|
||||
private static final boolean languageZh = getPropertyValue("system.language", "zh").equals("zh");
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
|
||||
private static final long startupTime = System.currentTimeMillis();
|
||||
private static final int startingTime = Integer.parseInt(getPropertyValue("system.startup.time", "60000"));
|
||||
|
||||
|
||||
|
||||
public static long getStartupTime() {
|
||||
return startupTime;
|
||||
}
|
||||
|
||||
public static boolean started() {
|
||||
return System.currentTimeMillis() - startupTime > startingTime;
|
||||
}
|
||||
|
||||
public static boolean isLanguageZh() {
|
||||
return languageZh;
|
||||
}
|
||||
|
||||
|
||||
private static boolean updateConfig(String name, Map<String, Object> value) {
|
||||
Connection conn = null;
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
conn = DataSourceUtils.getConnection();
|
||||
String sql = "update global_configuration set value=?::json where name=?";
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setString(1, CommonUtils.getJsonFromObject(value));
|
||||
pstmt.setString(2, name);
|
||||
pstmt.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
logger.error("execute sql exception:", e);
|
||||
return false;
|
||||
} finally {
|
||||
DataSourceUtils.closeResource(pstmt, conn);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean addConfig(String name, Map<String, Object> value) {
|
||||
Connection conn = null;
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
conn = DataSourceUtils.getConnection();
|
||||
String sql = "INSERT INTO global_configuration(name, value) VALUES (?, ?::json)";
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setString(1, name);
|
||||
pstmt.setString(2, CommonUtils.getJsonFromObject(value));
|
||||
pstmt.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
logger.error("execute sql exception:", e);
|
||||
return false;
|
||||
} finally {
|
||||
DataSourceUtils.closeResource(pstmt, conn);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ObjectMapper getObjectMapper() {
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
public static <T> T convertJsonToObject(String content, Class<T> valueType) {
|
||||
if (content == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return objectMapper.readValue(content.getBytes(StandardCharsets.UTF_8), valueType);
|
||||
} catch (IOException e) {
|
||||
logger.error("convert json to Object exception:", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> List<T> convertJsonToList(String content, Class<T> valueType) {
|
||||
if (content == null || content.length() == 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
try {
|
||||
List<T> list = objectMapper.readValue(content.getBytes(StandardCharsets.UTF_8), new TypeReference<List<T>>() {
|
||||
});
|
||||
List<T> ret = new ArrayList<>();
|
||||
for (T t : list) {
|
||||
ret.add(objectMapper.convertValue(t, valueType));
|
||||
}
|
||||
return ret;
|
||||
} catch (IOException e) {
|
||||
logger.error("convert json to Object exception:", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getJsonFromObject(Object object) {
|
||||
String json = null;
|
||||
try {
|
||||
json = CommonUtils.getObjectMapper().writeValueAsString(object);
|
||||
} catch (JsonProcessingException ignored) {
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getJsonValue(String jsonString, String key) {
|
||||
Map<String, String> jsonMap;
|
||||
try {
|
||||
jsonMap = objectMapper.readValue(jsonString, new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
} catch (IOException ignored) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return jsonMap.get(key);
|
||||
}
|
||||
|
||||
public static String getJsonString(Map<String, Object> map) {
|
||||
String result = "";
|
||||
try {
|
||||
result = objectMapper.writeValueAsString(map);
|
||||
} catch (JsonProcessingException ignored) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<String, String> getJsonMap(String jsonString) {
|
||||
Map<String, String> jsonMap;
|
||||
try {
|
||||
jsonMap = objectMapper.readValue(jsonString, new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
} catch (IOException ignored) {
|
||||
jsonMap = new HashMap<>();
|
||||
}
|
||||
return jsonMap;
|
||||
}
|
||||
|
||||
public static Map<String, Object> getMapFromJson(String jsonString) {
|
||||
try {
|
||||
return objectMapper.readValue(jsonString, new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
public static String getPropertyValue(String propertyName) {
|
||||
Properties properties = loadPropertyFile("sdwan.common.cfg");
|
||||
if (properties != null) {
|
||||
return properties.getProperty(propertyName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPropertyValue(String propertyName, String defaultValue) {
|
||||
Properties properties = loadPropertyFile("sdwan.common.cfg");
|
||||
if (properties != null) {
|
||||
String value = properties.getProperty(propertyName);
|
||||
return value == null ? defaultValue : value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static Properties loadPropertyFile(String fileName) {
|
||||
String filePath = System.getProperty("user.dir").concat("/etc/").concat(fileName);
|
||||
File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(is);
|
||||
return properties;
|
||||
} catch (IOException e) {
|
||||
logger.error("load property file exception:", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean setProperty(String fileName, String key, String value) {
|
||||
Properties properties = loadPropertyFile(fileName);
|
||||
if (properties == null) {
|
||||
properties = new Properties();
|
||||
}
|
||||
properties.setProperty(key, value);
|
||||
return savePropertyFile(fileName, properties);
|
||||
}
|
||||
|
||||
public static boolean savePropertyFile(String fileName, Properties properties) {
|
||||
String filePath = System.getProperty("user.dir").concat("/etc/").concat(fileName);
|
||||
File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try (OutputStream os = new FileOutputStream(file)) {
|
||||
properties.store(os, null);
|
||||
} catch (IOException e) {
|
||||
logger.error("write file exception:", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<T> getListFromArray(Array array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Arrays.asList((T[]) array.getArray());
|
||||
} catch (SQLException ignored) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static String formatDate(Date date) {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// public static void main(String args[]) {
|
||||
// System.out.println(CommonUtils.getLanguage());
|
||||
// }
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package com.xydl.util;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidDataSourceFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class DataSourceUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataSourceUtils.class);
|
||||
private static DataSource dataSource;
|
||||
private static String url;
|
||||
|
||||
static {
|
||||
initDataSource();
|
||||
}
|
||||
|
||||
private static void initDataSource() {
|
||||
Properties properties = CommonUtils.loadPropertyFile("sdwan.datasource.druid.cfg");
|
||||
if (properties == null) {
|
||||
logger.error("init dataSource failed, no config found.");
|
||||
properties = new Properties();
|
||||
properties.setProperty("driverClassName", "com.mysql.cj.jdbc.Driver");
|
||||
properties.setProperty("url", "jdbc:mysql://localhost:3306/cac");
|
||||
properties.setProperty("username", "root");
|
||||
properties.setProperty("password", "root");
|
||||
}
|
||||
try {
|
||||
dataSource = DruidDataSourceFactory.createDataSource(properties);
|
||||
url = ((DruidDataSource) dataSource).getUrl();
|
||||
} catch (Exception e) {
|
||||
logger.error("init dataSource exception:", e);
|
||||
}
|
||||
logger.info("Data source has been initialized successfully!");
|
||||
}
|
||||
|
||||
// 提供获取连接的方法
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
public static String getDatabaseIp() {
|
||||
try {
|
||||
return url.substring(url.indexOf("//") + 2, url.lastIndexOf(":"));
|
||||
} catch (IndexOutOfBoundsException ignored) {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// 提供关闭资源的方法【connection是归还到连接池】
|
||||
// 提供关闭资源的方法 【方法重载】3 dql
|
||||
public static void closeResource(ResultSet resultSet, Statement statement, Connection connection) {
|
||||
// 关闭结果集
|
||||
closeResultSet(resultSet);
|
||||
// 关闭语句执行者
|
||||
closeStatement(statement);
|
||||
// 关闭连接
|
||||
closeConnection(connection);
|
||||
}
|
||||
|
||||
// 提供关闭资源的方法 【方法重载】 2 dml
|
||||
public static void closeResource(Statement statement, Connection connection) {
|
||||
// 关闭语句执行者
|
||||
closeStatement(statement);
|
||||
// 关闭连接
|
||||
closeConnection(connection);
|
||||
}
|
||||
|
||||
private static void closeConnection(Connection connection) {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
logger.error("closeConnection exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeStatement(Statement statement) {
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
} catch (SQLException e) {
|
||||
logger.error("closeStatement exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeResultSet(ResultSet resultSet) {
|
||||
if (resultSet != null) {
|
||||
try {
|
||||
resultSet.close();
|
||||
} catch (SQLException e) {
|
||||
logger.error("closeResultSet exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.xydl.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FormatUtil {
|
||||
|
||||
public static String list2Json(List list){
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
List<Map<String,Object>> assetList = new ArrayList<>();
|
||||
assetList.add(new HashMap<String,Object>(){{
|
||||
put("AssetCode","ironCore");
|
||||
put("AttributeList",list);
|
||||
put("Timestamp", 1606800979591089792L);
|
||||
}});
|
||||
Map<String,Object> resultMap = new HashMap<String,Object>(){{
|
||||
put("AssetList",assetList);
|
||||
}};
|
||||
String jsonString = null;
|
||||
try {
|
||||
jsonString = objectMapper.writeValueAsString(resultMap);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package com.xydl.util;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class MqttUtil {
|
||||
|
||||
public static boolean publish2MQTT(String content){
|
||||
String broker = "tcp://139.196.211.222:10883";
|
||||
String topic = "mqtt/test";
|
||||
// String content = "Hello MQTT";
|
||||
int qos = 0;
|
||||
String username = "test";
|
||||
String password = "AliOS%1688";
|
||||
String clientid = "publish_client";
|
||||
MqttClient client;
|
||||
MqttDeliveryToken token;
|
||||
try {
|
||||
client = new MqttClient(broker, clientid, new MemoryPersistence());
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setUserName(username);
|
||||
options.setPassword(password.toCharArray());
|
||||
options.setConnectionTimeout(60);
|
||||
options.setKeepAliveInterval(30);
|
||||
// connect
|
||||
try {
|
||||
client.connect(options);
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// create message and setup QoS
|
||||
MqttMessage message = new MqttMessage(content.getBytes());
|
||||
message.setQos(qos);
|
||||
// publish message
|
||||
try {
|
||||
token = client.getTopic(topic).publish(message);
|
||||
token.waitForCompletion();
|
||||
//打印发送状态
|
||||
System.out.println("messagei is published completely!" + token.isComplete());
|
||||
// client.publish(topic, message);
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println("Message published");
|
||||
System.out.println("topic: " + topic);
|
||||
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+ " message content推送: " + content);
|
||||
// disconnect
|
||||
try {
|
||||
client.disconnect();
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// close client
|
||||
try {
|
||||
client.close();
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return token.isComplete();
|
||||
}
|
||||
|
||||
public static void subScribeMQTT(){
|
||||
String broker = "tcp://139.196.211.222:10883";
|
||||
String topic = "mqtt/test";
|
||||
String username = "test";
|
||||
String password = "AliOS%1688";
|
||||
String clientid = "subscribe_client";
|
||||
int qos = 0;
|
||||
try {
|
||||
MqttClient client = new MqttClient(broker, clientid, new MemoryPersistence());
|
||||
// connect options
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setUserName(username);
|
||||
options.setPassword(password.toCharArray());
|
||||
options.setConnectionTimeout(60);
|
||||
options.setKeepAliveInterval(30);
|
||||
// setup callback
|
||||
client.setCallback(new MqttCallback() {
|
||||
public void connectionLost(Throwable cause) {
|
||||
System.out.println("connectionLost: " + cause.getMessage());
|
||||
}
|
||||
public void messageArrived(String topic, MqttMessage message) {
|
||||
System.out.println("topic: " + topic);
|
||||
System.out.println("Qos: " + message.getQos());
|
||||
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+" message content接收: " + new String(message.getPayload()));
|
||||
|
||||
}
|
||||
public void deliveryComplete(IMqttDeliveryToken token) {
|
||||
System.out.println("deliveryComplete---------" + token.isComplete());
|
||||
}
|
||||
});
|
||||
client.connect(options);
|
||||
client.subscribe(topic, qos);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); }
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#端口号
|
||||
server:
|
||||
port: 8088
|
||||
|
||||
#数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/cac?characterEncoding=utf-8&serverTimezone=UTC
|
||||
username: root
|
||||
password: root
|
||||
#sql:
|
||||
#init:
|
||||
#指定脚本文件位置
|
||||
#schema-locations: classpath:user.sql
|
||||
#初始化方式
|
||||
#mode: always
|
||||
#设置数据源类型C
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
mybatis:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
#mybatis:
|
||||
#指定mybatis配置文件的位置
|
||||
#config-location: classpath:mybatis/mybatis-config.xml
|
||||
#指定映射文件的位置
|
||||
mapper-locations: classpath:mybatis/mapper/*.xml
|
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1> ${list}</h1>
|
||||
<h1> ${name}</h1>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue