wenhua.zhou 2 years ago
parent 09c1251b33
commit d5a5886f57

@ -1,15 +0,0 @@
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();
}
}

@ -1,20 +0,0 @@
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);
}
};
}
}

@ -1,44 +0,0 @@
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);
}
}
}

@ -1,26 +1,18 @@
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();
public String test() {
System.out.println("===");
return "测试成功";
}
}

@ -1,21 +0,0 @@
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();
}

@ -1,21 +0,0 @@
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();
}

@ -1,34 +0,0 @@
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);
}

@ -1,21 +0,0 @@
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();
}

@ -1,24 +0,0 @@
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();
}

@ -1,24 +0,0 @@
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,12 @@
package com.xydl.mapper;
import java.util.List;
public interface OperationDB {
List<String> getAllDevId(String tableName);
String getLastTime(String tableName, String devId);
}

@ -1,25 +0,0 @@
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();
}

@ -1,24 +0,0 @@
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();
}

@ -1,25 +0,0 @@
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();
}

@ -1,22 +0,0 @@
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();
}

@ -1,22 +0,0 @@
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();
}

@ -1,30 +0,0 @@
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;
}

@ -1,33 +0,0 @@
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;
}

@ -1,65 +0,0 @@
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;
}

@ -1,33 +0,0 @@
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;
}

@ -1,42 +0,0 @@
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;
}

@ -1,36 +0,0 @@
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;
}

@ -1,30 +0,0 @@
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;
}

@ -1,42 +0,0 @@
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;
}

@ -1,22 +0,0 @@
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;
}

@ -1,35 +0,0 @@
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;
}

@ -1,43 +0,0 @@
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;
}

@ -1,231 +0,0 @@
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;
}

@ -1,33 +0,0 @@
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();
}

@ -1,528 +0,0 @@
package com.xydl.service.impl;
import com.xydl.mapper.*;
import com.xydl.model.*;
import com.xydl.service.EiaService;
import com.xydl.util.CommonUtils;
import com.xydl.util.DataSourceUtils;
import com.xydl.util.FormatUtil;
import com.xydl.util.MqttUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
@Service
public class EiaServiceImpl implements EiaService {
private static final Logger logger = LoggerFactory.getLogger(EiaServiceImpl.class);
private static final String SYNC_TABLE = "sync_tables_info";
@Autowired
private EaifMapper eaifMapper;
@Autowired
private EpaMapper epaMapper;
@Autowired
private EiaMapper eiaMapper;
@Autowired
private EtpMapper etpMapper;
@Autowired
private MicMapper micMapper;
@Autowired
private MoaMapper moaMapper;
@Autowired
private PdMapper pdMapper;
@Autowired
private RptTemperMapper rptTemperMapper;
@Autowired
private ScurMapper scurMapper;
@Autowired
private Sf6Mapper sf6Mapper;
@Autowired
private Sf6envMapper sf6envMapper;
@Override
public List<Eaif> getEaif() {
return eaifMapper.getEaif();
//
}
@Override
public List<Eia> getEia() {
return eiaMapper.getEia();
}
@Override
public void getEpa() {
List<String> tableNames = epaMapper.getTableNamesBySyncTable(SYNC_TABLE);
// for(String tableName : tableNames){
// System.out.println(tableName);
// List<Integer> eqmids = epaMapper.getEqmidsByTableName(tableName);
// for(int eqmid : eqmids){
// List<Epa> epas = epaMapper.getEpa(eqmid);
// String jsonStringEpa = FormatUtil.list2Json(epas);
// MqttUtil.publish2MQTT(jsonStringEpa);
// }
// }
for(String tableName : tableNames){
String sql = epaMapper.getSqlBySyncTable(SYNC_TABLE,tableName);
List<Integer> eqmids = epaMapper.getEqmidsByTableName(tableName);
if(sql.contains("?")){
for(int eqmid : eqmids){
String newSql = sql.replaceAll("\\?",eqmid+"");
List<SuperModel> epas = epaMapper.getData(newSql);
String jsonStringEpa = FormatUtil.list2Json(epas);
MqttUtil.publish2MQTT(jsonStringEpa);
}
}
}
}
@Override
public List<Etp> getEtp() {
return etpMapper.getEtp();
}
@Override
public List<Microclimate> getMic() {
return micMapper.getMicroclimate();
}
@Override
public List<Moa> getMoa() {
return moaMapper.getMoa();
}
@Override
public List<Pd> getPd() {
return pdMapper.getPd();
}
@Override
public List<RptTemper> getRptTemper() {
return rptTemperMapper.getRptTemper();
}
@Override
public List<Scur> getScur() {
return scurMapper.getScur();
}
@Override
public List<Sf6> getSf6() {
return sf6Mapper.getSf6();
}
@Override
public List<Sf6env> getSf6env() {
return sf6envMapper.getSf6env();
}
public List<String> getAllTableName() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<String> tableNames = new ArrayList<>();
try {
conn = DataSourceUtils.getConnection();
String sql = "select table_name from sync_tables_info";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
tableNames.add(rs.getString("table_name"));
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return tableNames;
}
public Map<String,String> getFieldMap(String tableName) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Map<String,String> fieldsMap = new HashMap<>();
try {
conn = DataSourceUtils.getConnection();
String sql = "select sync_fields_info.field_name, sync_fields_info.dest_field_name " +
"from sync_fields_info,sync_tables_info " +
"where sync_fields_info.client_id = 10 and sync_fields_info.table_name = sync_tables_info.table_name and sync_tables_info.table_name=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
rs = pstmt.executeQuery();
ResultSetMetaData metaData = rs.getMetaData();
while(rs.next()){
fieldsMap.put(rs.getString("field_name"),rs.getString("dest_field_name"));
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return fieldsMap;
}
// public String getLastRecordTimeSended(String tableName,String deviceId) {
// Connection conn = null;
// PreparedStatement pstmt = null;
// ResultSet rs = null;
// Timestamp timeStamp = null;
// try {
// conn = DataSourceUtils.getConnection();
// String sql = "select field_val2 from sync_records where table_name =? and devid_val=?";
// pstmt = conn.prepareStatement(sql);
// pstmt.setString(1, tableName);
// pstmt.setString(2, deviceId);
// rs = pstmt.executeQuery();
// if(rs.next()){
// timeStamp = rs.getTimestamp("field_val2");
//
// }
// } catch (SQLException e) {
// logger.error("execute sql exception:", e);
// } finally {
// DataSourceUtils.closeResource(rs, pstmt, conn);
// }
//
// return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timeStamp);
// }
// public List<String> getDeviceID(String tableName) {
// Connection conn = null;
// PreparedStatement pstmt = null;
// ResultSet rs = null;
// String sqlExecuting = null ;
// List<String> deviceIDs = new ArrayList<>();
// try {
// conn = DataSourceUtils.getConnection();
// String sql = "select distinct devid_val from sync_records where table_name =?";
// pstmt = conn.prepareStatement(sql);
// pstmt.setString(1, tableName);
// rs = pstmt.executeQuery();
// while(rs.next()){
// deviceIDs.add(rs.getString("devid_val"));
// }
// } catch (SQLException e) {
// logger.error("execute sql exception:", e);
// } finally {
// DataSourceUtils.closeResource(rs, pstmt, conn);
// }
//
// return deviceIDs;
// }
public Map<String,Object> getDeviceID1(String tableName) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sqlExecuting = null ;
Map<String,Object> devIDTimeMap = new HashMap<>();
try {
conn = DataSourceUtils.getConnection();
String sql = "select devid_val,field_val2 from sync_records where table_name =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
rs = pstmt.executeQuery();
while(rs.next()){
devIDTimeMap.put(rs.getString("devid_val"),rs.getString("field_val2"));
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return devIDTimeMap;
}
public String getSQL(String tableName) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sqlExecuting = null ;
try {
conn = DataSourceUtils.getConnection();
String sql = "select * from sync_tables_info where table_name =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
rs = pstmt.executeQuery();
if(rs.next()){
sqlExecuting = rs.getString("sql");
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return sqlExecuting;
}
public List<Map<String,Object>> getData(String sqlExecuting, String deviceId, String timeStamp) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<Map<String,Object>> records = new ArrayList<>();
try {
conn = DataSourceUtils.getConnection();
String sql = sqlExecuting;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, deviceId);
pstmt.setString(2,timeStamp);
rs = pstmt.executeQuery();
int columnCount = rs.getMetaData().getColumnCount(); //获取列的数量
while(rs.next()){
Map<String,Object> record = new HashMap<>();
for (int col = 0; col < columnCount; col++) {
String columnName = rs.getMetaData().getColumnName(col + 1);
String columnValue = rs.getString(columnName);
record.put(columnName,columnValue);
}
records.add(record);
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return records;
}
// @Scheduled(initialDelay=1000, fixedRate = 1000 * 3600) //通过@Scheduled声明该方法是计划任务使用fixedRate属性每隔固定时间执行
// public void reportRecord(){
// List<String> allTableNames = getAllTableName();
// Map<String,Map<String,String>> tableFieldMap = new HashMap<>();
// Map<String, List<Map<String,List<Map<String,Object>>>>> allTableData = new HashMap<>();
// for(String tablenName : allTableNames){
// //if用来测试
// if(!"data_eaif_h".equals(tablenName)){
// Map<String,String> fieldMap = getFieldMap(tablenName);
// tableFieldMap.put(tablenName,fieldMap);
//
// String sqlExecuting = getSQL(tablenName);
// List<String> deviceIDs = getDeviceID(tablenName);
// List<Map<String,List<Map<String,Object>>>> dataOfoneTable = new ArrayList<>();
// for(String deviceID : deviceIDs){
// Map<String,List<Map<String,Object>>> deviceIDMap = new HashMap<>();
// String timeStamp = getLastRecordTimeSended(tablenName,deviceID);
// List<Map<String,Object>> dataOfoneDeviceID = getData(sqlExecuting,deviceID,timeStamp);
//
// deviceIDMap.put(deviceID,dataOfoneDeviceID);
// dataOfoneTable.add(deviceIDMap);
// }
// allTableData.put(tablenName,dataOfoneTable);
// }
//
// }
// System.out.println("旧数据: "+allTableData);
// System.out.println("===============================");
//
//
// Map<String,List<Map<String, List<Map<String, Object>>>>> newAllData = new HashMap<>();
// for(Map.Entry<String, List<Map<String,List<Map<String,Object>>>>> dataEntry : allTableData.entrySet()){
// List<Map<String, List<Map<String, Object>>>> newRecords = transformFields(dataEntry.getKey(),tableFieldMap,dataEntry.getValue());
// newAllData.put(dataEntry.getKey(),newRecords);
// }
//
// for(String tableName : newAllData.keySet()){
// List<Map<String, List<Map<String, Object>>>> records = newAllData.get(tableName);
// String jsonStringData = FormatUtil.list2Json(records);
// if(MqttUtil.publish2MQTT(jsonStringData)){
// updateLastRecordTimeSended(tableName,records);
// }else{
// System.out.println("消息推送失败");
// }
// }
//
// }
@Scheduled(initialDelay=1000, fixedRate = 1000 * 3600) //通过@Scheduled声明该方法是计划任务使用fixedRate属性每隔固定时间执行
public void reportRecord1(){
List<String> allTableNames = getAllTableName();
Map<String,Map<String,String>> tableFieldMap = new HashMap<>();
Map<String, List<Map<String,List<Map<String,Object>>>>> allTableData = new HashMap<>();
for(String tableName : allTableNames){
//if用来测试
if(!"data_eaif_h".equals(tableName)){
Map<String,String> fieldMap = getFieldMap(tableName);
String sqlExecuting = getSQL(tableName);
Map<String,Object> devIDLastTimeMap = getDeviceID1(tableName);
for(String deviceID : devIDLastTimeMap.keySet()){
List<Map<String,Object>> dataOfoneDeviceID = getData(sqlExecuting,deviceID, (String) devIDLastTimeMap.get(deviceID));
List<Map<String,Object>> newDataOfoneDeviceID = transformList(fieldMap,dataOfoneDeviceID);
String jsonStringData = FormatUtil.list2Json(newDataOfoneDeviceID);
if(MqttUtil.publish2MQTT(jsonStringData)){
updateSyncRecordsTable(tableName,deviceID, (String) devIDLastTimeMap.get(deviceID));
}else{
System.out.println("消息推送失败");
}
}
}
}
// System.out.println("旧数据: "+allTableData);
// System.out.println("===============================");
// Map<String,List<Map<String, List<Map<String, Object>>>>> newAllData = new HashMap<>();
// for(Map.Entry<String, List<Map<String,List<Map<String,Object>>>>> dataEntry : allTableData.entrySet()){
// List<Map<String, List<Map<String, Object>>>> newRecords = transformFields(dataEntry.getKey(),tableFieldMap,dataEntry.getValue());
// newAllData.put(dataEntry.getKey(),newRecords);
// }
// for(String tableName : newAllData.keySet()){
// List<Map<String, List<Map<String, Object>>>> records = newAllData.get(tableName);
// String jsonStringData = FormatUtil.list2Json(records);
// if(MqttUtil.publish2MQTT(jsonStringData)){
// updateLastRecordTimeSended(tableName,records);
// }else{
// System.out.println("消息推送失败");
// }
// }
}
// //返回替换字段名的records
// private List<Map<String,List<Map<String,Object>>>> transformFields(String recordTableName, Map<String,Map<String,String>> tableFieldMap, List<Map<String,List<Map<String,Object>>>> records) {
// List<Map<String,List<Map<String,Object>>>> newRecords = new ArrayList<>();
// if(tableFieldMap.containsKey(recordTableName)){
// for(Map<String,List<Map<String,Object>>> record : records ){
// newRecords.add(transformMore(tableFieldMap.get(recordTableName),record));
// }
// }
// return newRecords;
// }
//
// private Map<String,List<Map<String,Object>>> transformMore(Map<String,String> fieldMap, Map<String,List<Map<String,Object>>> deviceIDDataMap) {
// Map<String,List<Map<String,Object>>> newDeviceIDData = new HashMap<>();
// for(Map.Entry<String,List<Map<String,Object>>> entry : deviceIDDataMap.entrySet()){
// newDeviceIDData.put(entry.getKey(),transformMoreAgain(fieldMap, entry.getValue()));
// }
// return newDeviceIDData;
// }
//
// private List<Map<String,Object>> transformMoreAgain(Map<String,String> fieldMap, List<Map<String,Object>> deviceIDData) {
// List<Map<String,Object>> newDeviceIDData = new ArrayList<>();
// for(Map<String,Object> fieldValueMap : deviceIDData){
// newDeviceIDData.add(transformMoreAgain2(fieldMap,fieldValueMap));
// }
// return newDeviceIDData;
// }
//
// private Map<String,Object> transformMoreAgain2(Map<String,String> fieldMap, Map<String,Object> fieldValueMap) {
// Map<String,Object> newFieldValueMap = new HashMap<>();
// for(String field : fieldMap.keySet()){
// for(String columnName : fieldValueMap.keySet() ){
// if(Objects.equals(field,columnName)){
// newFieldValueMap.put(fieldMap.get(field),fieldValueMap.get(columnName) );
// }
// }
// }
// return newFieldValueMap;
// }
private List<Map<String,Object>> transformList(Map<String,String> fieldMap, List<Map<String,Object>> deviceIDData) {
List<Map<String,Object>> newDeviceIDData = new ArrayList<>();
for(Map<String,Object> fieldValueMap : deviceIDData){
newDeviceIDData.add(transformOneRecord(fieldMap,fieldValueMap));
}
return newDeviceIDData;
}
private Map<String,Object> transformOneRecord(Map<String,String> fieldMap, Map<String,Object> fieldValueMap) {
Map<String,Object> newFieldValueMap = new HashMap<>();
for(String field : fieldMap.keySet()){
if(fieldValueMap.containsKey(field)){
newFieldValueMap.put(fieldMap.get(field),fieldValueMap.get(field) );
}
}
return newFieldValueMap;
}
//
// public void updateLastRecordTimeSended(String tableName, List<Map<String,List<Map<String, Object>>>> records) {
// List<String> deviceIDs = getDeviceID(tableName);
// for(String deviceID : deviceIDs){
// String lastRecordTimesJustSended = null;
// for(Map<String,List<Map<String, Object>>> recordMap : records){
// if(recordMap.get(deviceID) != null){
// List<Map<String, Object>> deviceIDData = recordMap.get(deviceID);
// lastRecordTimesJustSended = (String) deviceIDData.get(deviceIDData.size()-1).get("AcquisitionTime");
// System.out.println(tableName+"表"+deviceID+"最后一条记录时间: "+lastRecordTimesJustSended);
// }
//
// }
//// updateSyncRecordsTable(tableName, deviceID, lastRecordTimesJustSended);
//
// }
//
// }
public boolean updateSyncRecordsTable(String tableName, String deviceID, String time) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = DataSourceUtils.getConnection();
String sql = "update sync_records set field_val2 = ? where table_name = ? and devid_val = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, time);
pstmt.setString(2, tableName);
pstmt.setString(3, deviceID);
pstmt.executeUpdate();
} catch (SQLException e) {
logger.error("execute sql exception:", e);
return false;
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return true;
}
@Scheduled(fixedDelay = Long.MAX_VALUE) // 用一个非常大的延迟值,确保只执行一次
public void subScribeSamle() {
System.out.println("subScribe执行一次 "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
MqttUtil.subScribeMQTT();
}
}

@ -0,0 +1,349 @@
package com.xydl.service.impl;
import com.xydl.mapper.OperationDB;
import com.xydl.util.DataSourceUtils;
import com.xydl.util.FormatUtil;
import com.xydl.util.MqttUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
@Service
public class MqttServiceImpl {
private static final Logger logger = LoggerFactory.getLogger(MqttServiceImpl.class);
@Autowired
OperationDB operationDBMapper;
private static final String SYNC_TABLE = "sync_tables_info";
public List<String> getAllTableNameFromSyncTable() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<String> tableNames = new ArrayList<>();
try {
conn = DataSourceUtils.getConnection();
String sql = "select table_name from sync_tables_info";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
tableNames.add(rs.getString("table_name"));
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return tableNames;
}
public boolean tableNameIfExitsSyncRec(String tableName) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = DataSourceUtils.getConnection();
String sql = "select devid_val from sync_records where table_name = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
rs = pstmt.executeQuery();
if(rs.next()){
return true;
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return false;
}
public Map<String,String> getFieldMap(String tableName) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Map<String,String> fieldsMap = new HashMap<>();
try {
conn = DataSourceUtils.getConnection();
String sql = "select sync_fields_info.field_name, sync_fields_info.dest_field_name " +
"from sync_fields_info,sync_tables_info " +
"where sync_fields_info.client_id = 10 and sync_fields_info.table_name = sync_tables_info.table_name and sync_tables_info.table_name=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
rs = pstmt.executeQuery();
ResultSetMetaData metaData = rs.getMetaData();
while(rs.next()){
fieldsMap.put(rs.getString("field_name"),rs.getString("dest_field_name"));
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return fieldsMap;
}
public Map<String,Object> getDeviceIDAndtime(String tableName) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sqlExecuting = null ;
Map<String,Object> devIDTimeMap = new HashMap<>();
try {
conn = DataSourceUtils.getConnection();
String sql = "select devid_val,field_val2 from sync_records where table_name =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
rs = pstmt.executeQuery();
while(rs.next()){
devIDTimeMap.put(rs.getString("devid_val"),rs.getString("field_val2"));
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return devIDTimeMap;
}
public String getSQL(String tableName) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sqlExecuting = null ;
try {
conn = DataSourceUtils.getConnection();
String sql = "select * from sync_tables_info where table_name =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
rs = pstmt.executeQuery();
if(rs.next()){
sqlExecuting = rs.getString("sql");
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return sqlExecuting;
}
public List<Map<String,Object>> getData(String sqlExecuting, String deviceId, String timeStamp) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<Map<String,Object>> records = new ArrayList<>();
try {
conn = DataSourceUtils.getConnection();
String sql = sqlExecuting;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, deviceId);
pstmt.setString(2,timeStamp);
rs = pstmt.executeQuery();
int columnCount = rs.getMetaData().getColumnCount(); //获取列的数量
while(rs.next()){
Map<String,Object> record = new HashMap<>();
for (int col = 0; col < columnCount; col++) {
String columnName = rs.getMetaData().getColumnName(col + 1);
String columnValue = rs.getString(columnName);
record.put(columnName,columnValue);
}
records.add(record);
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return records;
}
public void addEarliestTime2SyncRecord(String tableName, String devId, String lastTime) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = DataSourceUtils.getConnection();
String sql = "insert into sync_records (client_id,table_name,devid_val,field_val2) values (?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, 10);
pstmt.setString(2, tableName);
pstmt.setString(3, devId);
pstmt.setString(4, lastTime);
pstmt.executeUpdate();
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
}
public List<String> getAllDevId(String tableName) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sqlExecuting = null ;
List<String> devIDs = new ArrayList<>();
try {
conn = DataSourceUtils.getConnection();
String sql = "select distinct eqmid from ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
rs = pstmt.executeQuery();
while(rs.next()){
devIDs.add(rs.getString("eqmid"));
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return devIDs;
}
public String getLastTime(String tableName, String devId) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = DataSourceUtils.getConnection();
String sql = "select d_time from ? where eqmid=? ORDER BY d_time asc limit 1";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
pstmt.setString(2, devId);
rs = pstmt.executeQuery();
if(rs.next()){
return rs.getString("d_time");
}
} catch (SQLException e) {
logger.error("execute sql exception:", e);
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return null;
}
private List<Map<String,Object>> transformList(Map<String,String> fieldMap, List<Map<String,Object>> deviceIDData) {
List<Map<String,Object>> newDeviceIDData = new ArrayList<>();
for(Map<String,Object> fieldValueMap : deviceIDData){
newDeviceIDData.add(transformOneRecord(fieldMap,fieldValueMap));
}
return newDeviceIDData;
}
private Map<String,Object> transformOneRecord(Map<String,String> fieldMap, Map<String,Object> fieldValueMap) {
Map<String,Object> newFieldValueMap = new HashMap<>();
for(String field : fieldMap.keySet()){
if(fieldValueMap.containsKey(field)){
newFieldValueMap.put(fieldMap.get(field),fieldValueMap.get(field) );
}
}
return newFieldValueMap;
}
public boolean updateSyncRecordsTable(String tableName, String deviceID, String time) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = DataSourceUtils.getConnection();
String sql = "update sync_records set field_val2 = ? where table_name = ? and devid_val = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, time);
pstmt.setString(2, tableName);
pstmt.setString(3, deviceID);
pstmt.executeUpdate();
} catch (SQLException e) {
logger.error("execute sql exception:", e);
return false;
} finally {
DataSourceUtils.closeResource(rs, pstmt, conn);
}
return true;
}
@Scheduled(initialDelay=1000, fixedRate = 1000 * 3600) //通过@Scheduled声明该方法是计划任务使用fixedRate属性每隔固定时间执行
public void reportRecord(){
logger.info("开始执行");
List<String> allTableNames = getAllTableNameFromSyncTable();
for(String tableName : allTableNames){
Map<String,String> fieldMap = getFieldMap(tableName);
String sqlExecuting = getSQL(tableName);
Map<String,Object> devIDLastTimeMap = getDeviceIDAndtime(tableName);
for(String deviceID : devIDLastTimeMap.keySet()){
List<Map<String,Object>> dataOfoneDeviceID = getData(sqlExecuting,deviceID, (String) devIDLastTimeMap.get(deviceID));
List<Map<String,Object>> newDataOfoneDeviceID = transformList(fieldMap,dataOfoneDeviceID);
String jsonStringData = FormatUtil.list2Json(newDataOfoneDeviceID);
logger.info("表{}设备{}推送数据:{}",tableName,deviceID,jsonStringData);
if(MqttUtil.publish2MQTT(jsonStringData)){
updateSyncRecordsTable(tableName,deviceID, (String) devIDLastTimeMap.get(deviceID));
logger.info("推送成功");
}else{
logger.info("消息推送失败");
}
}
}
}
@Scheduled(fixedDelay = Long.MAX_VALUE) // 用一个非常大的延迟值,确保只执行一次
public void subScribeSamle() {
logger.info("开始订阅===subScribe执行一次==={}",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
MqttUtil.subScribeMQTT();
}
@Scheduled(fixedRate = 1000 * 3600) //通过@Scheduled声明该方法是计划任务使用fixedRate属性每隔固定时间执行
public void checkDevIdTimer() {
logger.info("每小时检测一次同步的表是否在‘同步记录表’");
List<String> allTableNames = getAllTableNameFromSyncTable();
for(String tableName : allTableNames){
if(!tableNameIfExitsSyncRec(tableName)){
logger.info("有不存在的表,把所有的devId及最早的时间更新到'同步记录表'");
List<String> devIds = operationDBMapper.getAllDevId(tableName);
for(String devId : devIds){
String lastTime = operationDBMapper.getLastTime(tableName,devId);
addEarliestTime2SyncRecord(tableName,devId,lastTime);
}
}
}
}
}

@ -41,135 +41,21 @@ public class CommonUtils {
}
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");

@ -19,15 +19,12 @@ public class DataSourceUtils {
}
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");
}
Properties 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();
@ -42,13 +39,6 @@ public class DataSourceUtils {
return dataSource.getConnection();
}
public static String getDatabaseIp() {
try {
return url.substring(url.indexOf("//") + 2, url.lastIndexOf(":"));
} catch (IndexOutOfBoundsException ignored) {
}
return "";
}
// 提供关闭资源的方法【connection是归还到连接池】
// 提供关闭资源的方法 【方法重载】3 dql

@ -17,6 +17,12 @@ spring:
#mode: always
#设置数据源类型C
type: com.alibaba.druid.pool.DruidDataSource
#初始化执行sql
initialization-mode: always
schema:
- classpath:/sql/mqtt-schema.sql
continue-on-error: true
mybatis:
configuration:
map-underscore-to-camel-case: true

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.EaifMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<select id="getEaif" resultType="com.xydl.model.Eaif">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime, t1.maxtemp, t1.mintemp, t1.avgtemp, t2.phase
FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=165 AND t1.capturetime>'2017-01-17 16:00:00' ORDER BY t1.capturetime LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -1,69 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.EiaMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getEia" resultType="com.xydl.model.Eia">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.d_time, t1.d_ct_1, t2.phase
FROM `data_eia_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=152 AND t1.d_time>'2017-01-17 16:00:00' ORDER BY t1.d_time LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -1,86 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.EpaMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getEpa" resultType="com.xydl.model.Epa">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.d_time,t1.h2ppm,t1.ch4ppm,t1.c2h6ppm,t1.c2h4ppm,t1.c2h2ppm,t1.coppm,t1.co2ppm,t1.o2ppm,t1.n2ppm,t1.totalhydrocarbon,t1.gaspress,t1.h2oppm,t2.`Phase`
FROM `data_epa_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=#{devid} AND t1.d_time>(select DISTINCT syrec.field_val2 from sync_records as syrec, sync_tables_info as sytab, data_epa_h as epa
where sytab.client_id = 10 and syrec.client_id = sytab.client_id and syrec.table_name = sytab.table_name and epa.eqmid = syrec.devid_val and epa.eqmid = #{devid})
ORDER BY t1.d_time LIMIT 1000
</select>
<select id="getData" resultType="com.xydl.model.SuperModel">
${value}
</select>
<select id="getEqmidsByTableName" resultType="java.lang.Integer">
select DISTINCT tableName.eqmid from ${tableName} as tableName
</select>
<select id="getTableNamesBySyncTable" resultType="java.lang.String">
select DISTINCT syncTableName.table_name from ${sycTableName} as syncTableName
</select>
<select id="getSqlBySyncTable" resultType="java.lang.String">
select syncTable.sql from ${syncTable} as syncTable where table_name=#{tableName}
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -1,69 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.EtpMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getEtp" resultType="com.xydl.model.Etp">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.d_time,t1.t1
FROM `data_etp_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=160 AND t1.d_time>'2017-01-17 16:00:00' ORDER BY t1.d_time LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -1,70 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.MicMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getMicroclimate" resultType="com.xydl.model.Microclimate">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.d_time, t1.envtmp, t1.envpres, t1.envhum, t1.rnfll, t2.phase
FROM `data_microclimate_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=152 AND t1.d_time>'2017-01-17 16:00:00' ORDER BY t1.d_time LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.MoaMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getMoa" resultType="com.xydl.model.Moa">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.d_time, t1.pt1, t1.lc1, t1.rc1, t1.ligcnt1, t1.lastligtm1, t2.phase
FROM `data_moa_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=163 AND t1.d_time>'2017-01-17 16:00:00' ORDER BY t1.d_time LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xydl.mapper.OperationDB">
<select id="getAllDevId" parameterType="String" resultType="String">
select distinct eqmid from ${tableName}
</select>
<select id="getLastTime" parameterType="String" resultType="String">
select d_time from ${tableName} where eqmid=#{devId} ORDER BY d_time asc limit 1
</select>
</mapper>

@ -1,69 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.PdMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getPd" resultType="com.xydl.model.Pd">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.d_time, t1.waveform, t1.plsnum, t1.apppadsch, t2.phase
FROM `data_pd_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=242 AND t1.d_time>'2017-01-17 16:00:00' ORDER BY t1.d_time LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.RptTemperMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getRptTemper" resultType="com.xydl.model.RptTemper">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid, t1.create_time, t1.a_o_temper, t1.b_o_temper, t1.c_o_temper, t1.a_i_temper, t1.b_i_temper, t1.c_i_temper, t1.box_temper,t2.phase
FROM `rpt_temper` AS t1 JOIN i2relation AS t2 ON t1.eqm_id=t2.eqmid
WHERE t1.eqm_id=165 AND t1.create_time>'2017-01-17 16:00:00' ORDER BY t1.create_time LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.ScurMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getScur" resultType="com.xydl.model.Scur">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.d_time, t1.current_val, t2.phase
FROM `data_scur_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=395 AND t1.d_time>'2017-01-17 16:00:00' ORDER BY t1.d_time LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -1,67 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.Sf6Mapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getSf6" resultType="com.xydl.model.Sf6">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.d_time, t1.temp1, t1.md1, t1.pressure1+900, t1.pressure1, t1.pm1, t2.phase
FROM `data_sf6_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=164 AND t1.d_time>'2017-01-17 16:00:00' ORDER BY t1.d_time LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--MyBatis的映射文件 编写sql-->
<!--一个数据表对应一个实体类一个实体类对应一个mapper映射文件-->
<mapper namespace="com.xydl.mapper.Sf6envMapper">
<!-- <resultMap id="EiaResultMap" type="com.xydl.model.Eia">-->
<!-- <result column="SubDeviceID" property="subDeviceID"/>-->
<!-- <result column="sensorid" property="sensorId"/>-->
<!-- <result column="capturetime" property="captureTime"/>-->
<!-- <result column="maxtemp" property="maxTemp"/>-->
<!-- <result column="mintemp" property="minTemp"/>-->
<!-- <result column="avgtemp" property="avgTemp"/>-->
<!-- <result column="Phase" property="phase"/>-->
<!-- </resultMap>-->
<!-- <select id="getEia" resultType="com.xydl.model.Eia">-->
<!-- SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.capturetime,t1.maxtemp,t1.mintemp,t1.avgtemp,t2.`Phase`-->
<!-- FROM `data_eaif_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid-->
<!-- WHERE t1.eqmid=394 AND t1.capturetime>'2019-12-19 04:55:31' ORDER BY t1.capturetime LIMIT 1000-->
<!-- </select>-->
<select id="getSf6env" resultType="com.xydl.model.Sf6env">
SELECT t2.equipmentid AS SubDeviceID, t2.sensorid,t1.d_time, t1.gas1, t1.yq1, t1.md1, t1.pm1, t1.gascnt1, t1.hmcnt1,t1.sf6warn1, t1.o2warn1,t2.phase
FROM `data_sf6env_h` AS t1 JOIN i2relation AS t2 ON t1.eqmid=t2.eqmid
WHERE t1.eqmid=165 AND t1.d_time>'2017-01-17 16:00:00' ORDER BY t1.d_time LIMIT 10
</select>
<!--int insertEmp(Employee employee);-->
<insert id="insertEmp">
insert into employee values (#{id},#{lastName},#{email},#{gender},#{department.id})
</insert>
<update id="update">
update employee
<set>
<if test="employee.lastName!=null">
last_name=#{employee.lastName},
</if>
<if test="employee.email!=null">
email=#{employee.email},
</if>
<if test="employee.gender!=null">
gender=#{employee.gender},
</if>
<if test="employee.department!=null">
d_id=#{employee.department.id}
</if>
</set>
where id = #{id}
</update>
<!--int deleteEmpById(Integer id);-->
<delete id="deleteEmpById">
delete from employee where id=#{id}
</delete>
</mapper>

@ -0,0 +1,59 @@
/*
Navicat Premium Data Transfer
Source Server :
Source Server Type : MySQL
Source Server Version : 80100
Source Host : localhost:3306
Source Schema : cac
Target Server Type : MySQL
Target Server Version : 80100
File Encoding : 65001
Date: 05/12/2023 10:26:24
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for sync_tables_info
-- ----------------------------
DROP TABLE IF EXISTS `sync_tables_info`;
CREATE TABLE `sync_tables_info` (
`client_id` int UNSIGNED NOT NULL,
`table_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`sql` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`devid_field_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`outer_devid_fname` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`field_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`field_type` tinyint NOT NULL DEFAULT 1 COMMENT '1: 整数 2: 字符串 3: 日期 4: 浮点数',
`update_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0),
PRIMARY KEY (`client_id`, `table_name`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
DROP TABLE IF EXISTS `sync_records`;
CREATE TABLE `sync_records` (
`client_id` int UNSIGNED NOT NULL,
`table_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`devid_val` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`field_val1` bigint UNSIGNED NULL DEFAULT 0,
`field_val2` datetime(0) NULL DEFAULT '1999-01-01 01:00:00',
`update_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0),
PRIMARY KEY (`client_id`, `table_name`, `devid_val`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
DROP TABLE IF EXISTS `sync_fields_info`;
CREATE TABLE `sync_fields_info` (
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`client_id` int UNSIGNED NOT NULL,
`table_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`field_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`field_type` tinyint UNSIGNED NOT NULL DEFAULT 0,
`dest_field_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
PRIMARY KEY (`id`) USING BTREE,
INDEX `fields`(`client_id`, `table_name`, `field_name`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 41 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;
Loading…
Cancel
Save