226 lines
7.4 KiB
Go
226 lines
7.4 KiB
Go
package models
|
|
|
|
// EM3395TYDeviceInfo 表示EM3395TY设备基本信息的响应
|
|
type EM3395TYDeviceInfo struct {
|
|
Result struct {
|
|
ActiveTime int64 `json:"active_time"`
|
|
BindSpaceID string `json:"bind_space_id"`
|
|
Category string `json:"category"`
|
|
CreateTime int64 `json:"create_time"`
|
|
CustomName string `json:"custom_name"`
|
|
Icon string `json:"icon"`
|
|
ID string `json:"id"`
|
|
IP string `json:"ip"`
|
|
IsOnline bool `json:"is_online"`
|
|
Lat string `json:"lat"`
|
|
LocalKey string `json:"local_key"`
|
|
Lon string `json:"lon"`
|
|
Model string `json:"model"`
|
|
Name string `json:"name"`
|
|
ProductID string `json:"product_id"`
|
|
ProductName string `json:"product_name"`
|
|
Sub bool `json:"sub"`
|
|
TimeZone string `json:"time_zone"`
|
|
UpdateTime int64 `json:"update_time"`
|
|
UUID string `json:"uuid"`
|
|
} `json:"result"`
|
|
Success bool `json:"success"`
|
|
T int64 `json:"t"`
|
|
TID string `json:"tid"`
|
|
}
|
|
|
|
// EM3395TYDeviceStatus 表示EM3395TY设备状态的响应
|
|
type EM3395TYDeviceStatus struct {
|
|
Result EM3395TYStatusData `json:"result"`
|
|
Success bool `json:"success"`
|
|
T int64 `json:"t"`
|
|
TID string `json:"tid"`
|
|
}
|
|
|
|
// EM3395TYStatusData 表示EM3395TY设备状态数据
|
|
type EM3395TYStatusData struct {
|
|
TempCurrent int `json:"temp_current"`
|
|
HumidityValue int `json:"humidity_value"`
|
|
BatteryPercentage int `json:"battery_percentage"`
|
|
TempUnitConvert string `json:"temp_unit_convert"`
|
|
WindspeedUnitConvert string `json:"windspeed_unit_convert"`
|
|
PressureUnitConvert string `json:"pressure_unit_convert"`
|
|
RainUnitConvert string `json:"rain_unit_convert"`
|
|
BrightUnitConvert string `json:"bright_unit_convert"`
|
|
TempCurrentExternal int `json:"temp_current_external"`
|
|
HumidityOutdoor int `json:"humidity_outdoor"`
|
|
TempCurrentExternal1 int `json:"temp_current_external_1"`
|
|
HumidityOutdoor1 int `json:"humidity_outdoor_1"`
|
|
TempCurrentExternal2 int `json:"temp_current_external_2"`
|
|
HumidityOutdoor2 int `json:"humidity_outdoor_2"`
|
|
TempCurrentExternal3 int `json:"temp_current_external_3"`
|
|
HumidityOutdoor3 int `json:"humidity_outdoor_3"`
|
|
AtmosphericPressure int `json:"atmospheric_pressture"`
|
|
PressureDrop int `json:"pressure_drop"`
|
|
WindspeedAvg int `json:"windspeed_avg"`
|
|
WindspeedGust int `json:"windspeed_gust"`
|
|
Rain1h int `json:"rain_1h"`
|
|
Rain24h int `json:"rain_24h"`
|
|
RainRate int `json:"rain_rate"`
|
|
UVIndex int `json:"uv_index"`
|
|
DewPointTemp int `json:"dew_point_temp"`
|
|
FeellikeTemp int `json:"feellike_temp"`
|
|
HeatIndex int `json:"heat_index"`
|
|
WindchillIndex int `json:"windchill_index"`
|
|
}
|
|
|
|
// EM3395TYStatusItem 表示EM3395TY设备状态项
|
|
type EM3395TYStatusItem struct {
|
|
Code string `json:"code"`
|
|
Value interface{} `json:"value"`
|
|
}
|
|
|
|
// EM3395TYTokenResponse 表示获取访问令牌的响应
|
|
type EM3395TYTokenResponse struct {
|
|
Result struct {
|
|
AccessToken string `json:"access_token"`
|
|
ExpireTime int `json:"expire_time"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
UID string `json:"uid"`
|
|
} `json:"result"`
|
|
Success bool `json:"success"`
|
|
T int64 `json:"t"`
|
|
TID string `json:"tid"`
|
|
}
|
|
|
|
// 创建EM3395TY设备表的SQL语句
|
|
const CreateEM3395TYDevicesTable = `
|
|
CREATE TABLE IF NOT EXISTS em3395ty_devices (
|
|
id VARCHAR(50) PRIMARY KEY,
|
|
active_time BIGINT NOT NULL,
|
|
bind_space_id VARCHAR(50) NOT NULL,
|
|
category VARCHAR(20) NOT NULL,
|
|
create_time BIGINT NOT NULL,
|
|
custom_name VARCHAR(100),
|
|
icon VARCHAR(255),
|
|
ip VARCHAR(50) NOT NULL,
|
|
is_online BOOLEAN NOT NULL,
|
|
lat VARCHAR(20),
|
|
local_key VARCHAR(50),
|
|
lon VARCHAR(20),
|
|
model VARCHAR(50) NOT NULL,
|
|
name VARCHAR(100) NOT NULL,
|
|
product_id VARCHAR(50) NOT NULL,
|
|
product_name VARCHAR(100) NOT NULL,
|
|
sub BOOLEAN NOT NULL,
|
|
time_zone VARCHAR(10) NOT NULL,
|
|
update_time BIGINT NOT NULL,
|
|
uuid VARCHAR(50) NOT NULL,
|
|
last_query_time DATETIME,
|
|
INDEX idx_ip (ip),
|
|
INDEX idx_product_id (product_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
`
|
|
|
|
// 创建EM3395TY数据表的SQL语句
|
|
const CreateEM3395TYDataTable = `
|
|
CREATE TABLE IF NOT EXISTS em3395ty_data (
|
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
device_id VARCHAR(50) NOT NULL,
|
|
timestamp DATETIME NOT NULL,
|
|
temp_current INT,
|
|
humidity_value INT,
|
|
battery_percentage INT,
|
|
temp_unit_convert VARCHAR(10),
|
|
windspeed_unit_convert VARCHAR(10),
|
|
pressure_unit_convert VARCHAR(10),
|
|
rain_unit_convert VARCHAR(10),
|
|
bright_unit_convert VARCHAR(10),
|
|
temp_current_external INT,
|
|
humidity_outdoor INT,
|
|
temp_current_external_1 INT,
|
|
humidity_outdoor_1 INT,
|
|
temp_current_external_2 INT,
|
|
humidity_outdoor_2 INT,
|
|
temp_current_external_3 INT,
|
|
humidity_outdoor_3 INT,
|
|
atmospheric_pressture INT,
|
|
pressure_drop INT,
|
|
windspeed_avg INT,
|
|
windspeed_gust INT,
|
|
rain_1h INT,
|
|
rain_24h INT,
|
|
rain_rate INT,
|
|
uv_index INT,
|
|
dew_point_temp INT,
|
|
feellike_temp INT,
|
|
heat_index INT,
|
|
windchill_index INT,
|
|
INDEX idx_device_id (device_id),
|
|
INDEX idx_timestamp (timestamp),
|
|
FOREIGN KEY (device_id) REFERENCES em3395ty_devices(id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
`
|
|
|
|
// 插入EM3395TY设备信息的SQL语句
|
|
const InsertEM3395TYDeviceSQL = `
|
|
INSERT INTO em3395ty_devices (
|
|
id, active_time, bind_space_id, category, create_time, custom_name,
|
|
icon, ip, is_online, lat, local_key, lon, model, name, product_id,
|
|
product_name, sub, time_zone, update_time, uuid, last_query_time
|
|
) VALUES (
|
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW()
|
|
) ON DUPLICATE KEY UPDATE
|
|
active_time = VALUES(active_time),
|
|
bind_space_id = VALUES(bind_space_id),
|
|
category = VALUES(category),
|
|
create_time = VALUES(create_time),
|
|
custom_name = VALUES(custom_name),
|
|
icon = VALUES(icon),
|
|
ip = VALUES(ip),
|
|
is_online = VALUES(is_online),
|
|
lat = VALUES(lat),
|
|
local_key = VALUES(local_key),
|
|
lon = VALUES(lon),
|
|
model = VALUES(model),
|
|
name = VALUES(name),
|
|
product_id = VALUES(product_id),
|
|
product_name = VALUES(product_name),
|
|
sub = VALUES(sub),
|
|
time_zone = VALUES(time_zone),
|
|
update_time = VALUES(update_time),
|
|
uuid = VALUES(uuid),
|
|
last_query_time = NOW()
|
|
`
|
|
|
|
// 插入EM3395TY设备数据的SQL语句
|
|
const InsertEM3395TYDataSQL = `
|
|
INSERT INTO em3395ty_data (
|
|
device_id, timestamp, temp_current, humidity_value, battery_percentage,
|
|
temp_unit_convert, windspeed_unit_convert, pressure_unit_convert,
|
|
rain_unit_convert, bright_unit_convert, temp_current_external,
|
|
humidity_outdoor, temp_current_external_1, humidity_outdoor_1,
|
|
temp_current_external_2, humidity_outdoor_2, temp_current_external_3,
|
|
humidity_outdoor_3, atmospheric_pressture, pressure_drop, windspeed_avg,
|
|
windspeed_gust, rain_1h, rain_24h, rain_rate, uv_index, dew_point_temp,
|
|
feellike_temp, heat_index, windchill_index
|
|
) VALUES (
|
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
`
|
|
|
|
// 查询最新的EM3395TY设备数据的SQL语句
|
|
const QueryLatestEM3395TYDataSQL = `
|
|
SELECT * FROM em3395ty_data
|
|
WHERE device_id = ?
|
|
ORDER BY timestamp DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
// 查询指定时间范围内的EM3395TY设备数据的SQL语句
|
|
const QueryEM3395TYDataByTimeRangeSQL = `
|
|
SELECT * FROM em3395ty_data
|
|
WHERE device_id = ? AND timestamp BETWEEN ? AND ?
|
|
ORDER BY timestamp
|
|
`
|
|
|
|
// 查询设备是否存在的SQL语句
|
|
const QueryEM3395TYDeviceExistsSQL = `
|
|
SELECT COUNT(*) FROM em3395ty_devices WHERE id = ?
|
|
`
|