You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.4 KiB
95 lines
2.4 KiB
{
|
|
"properties" : { },
|
|
"id" : "b2c3d4e5f678901234567890abcdef01",
|
|
"script" : null,
|
|
"groupId" : "f8e3d2c1b0a94e5f8a7b6c5d4e3f2a1",
|
|
"name" : "市场环境监控",
|
|
"createTime" : 1781196000000,
|
|
"updateTime" : null,
|
|
"lock" : null,
|
|
"createBy" : "admin",
|
|
"updateBy" : "admin",
|
|
"path" : "/market-environment",
|
|
"method" : "GET",
|
|
"parameters" : [ ],
|
|
"options" : [ ],
|
|
"requestBody" : "",
|
|
"headers" : [ ],
|
|
"paths" : [ ],
|
|
"responseBody" : null,
|
|
"description" : "市场环境监控:温湿度(iot_device_env_data)+ 气象(iot_device_weather_data)最新一条,只读。",
|
|
"requestBodyDefinition" : null,
|
|
"responseBodyDefinition" : null
|
|
}
|
|
================================
|
|
// 只读查询,不修改任何数据
|
|
|
|
var envSql = """
|
|
SELECT
|
|
temperature,
|
|
humidity,
|
|
to_char(collect_time, 'YYYY-MM-DD HH24:MI:SS') AS collect_time
|
|
FROM iot_device_env_data
|
|
ORDER BY collect_time DESC NULLS LAST
|
|
LIMIT 1
|
|
"""
|
|
|
|
var weatherSql = """
|
|
SELECT
|
|
air_pressure,
|
|
pm25,
|
|
pm10,
|
|
uv_index,
|
|
rainfall,
|
|
wind_speed,
|
|
wind_direction,
|
|
to_char(collect_time, 'YYYY-MM-DD HH24:MI:SS') AS collect_time
|
|
FROM iot_device_weather_data
|
|
ORDER BY collect_time DESC NULLS LAST
|
|
LIMIT 1
|
|
"""
|
|
|
|
var envRows = db.select(envSql)
|
|
var weatherRows = db.select(weatherSql)
|
|
var env = envRows && envRows.length > 0 ? envRows[0] : null
|
|
var weather = weatherRows && weatherRows.length > 0 ? weatherRows[0] : null
|
|
|
|
var pickNum = (row, camelKey, snakeKey) => {
|
|
if (!row) {
|
|
return null
|
|
}
|
|
if (row[camelKey] != null) {
|
|
return row[camelKey]
|
|
}
|
|
if (row[snakeKey] != null) {
|
|
return row[snakeKey]
|
|
}
|
|
return null
|
|
}
|
|
|
|
var pickText = (row, camelKey, snakeKey) => {
|
|
if (!row) {
|
|
return ''
|
|
}
|
|
if (row[camelKey]) {
|
|
return row[camelKey]
|
|
}
|
|
if (row[snakeKey]) {
|
|
return row[snakeKey]
|
|
}
|
|
return ''
|
|
}
|
|
|
|
return {
|
|
temperature: pickNum(env, 'temperature', 'temperature'),
|
|
humidity: pickNum(env, 'humidity', 'humidity'),
|
|
envCollectTime: pickText(env, 'collectTime', 'collect_time'),
|
|
airPressure: pickNum(weather, 'airPressure', 'air_pressure'),
|
|
pm25: pickNum(weather, 'pm25', 'pm25'),
|
|
pm10: pickNum(weather, 'pm10', 'pm10'),
|
|
uvIndex: pickNum(weather, 'uvIndex', 'uv_index'),
|
|
rainfall: pickNum(weather, 'rainfall', 'rainfall'),
|
|
windSpeed: pickNum(weather, 'windSpeed', 'wind_speed'),
|
|
windDirection: pickNum(weather, 'windDirection', 'wind_direction'),
|
|
weatherCollectTime: pickText(weather, 'collectTime', 'collect_time')
|
|
}
|
|
|