|
@@ -48,14 +48,13 @@ func (c *EnvironmentData) GetByTime(start, end time.Time) ([]EnvironmentData, er
|
|
|
|
|
|
// EnvironmentDataDay 环境监测器天数据统计
|
|
// EnvironmentDataDay 环境监测器天数据统计
|
|
type EnvironmentDataSummary struct {
|
|
type EnvironmentDataSummary struct {
|
|
- ID int `gorm:"primary_key" json:"id"` //编号
|
|
|
|
DeviceId int `gorm:"type:int" json:"deviceId"` //设备名称
|
|
DeviceId int `gorm:"type:int" json:"deviceId"` //设备名称
|
|
//1=空气质量 2=PM2.5 3=pm10 4=温度 5=湿度 6=风速 7=气压 8=噪音 9=光照强度 10=风向 11=降雨量 12=紫外线
|
|
//1=空气质量 2=PM2.5 3=pm10 4=温度 5=湿度 6=风速 7=气压 8=噪音 9=光照强度 10=风向 11=降雨量 12=紫外线
|
|
DataType int `gorm:"type:int" json:"dataType"`
|
|
DataType int `gorm:"type:int" json:"dataType"`
|
|
- ValAvg float32 `gorm:"type:float(10, 2)" json:"valAvg"` //天均值
|
|
|
|
- ValMax float32 `gorm:"type:float(10, 2)" json:"valMax"` //天最大
|
|
|
|
- ValMin float32 `gorm:"type:float(10, 2)" json:"valMin"` //天最小
|
|
|
|
- CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
|
|
|
|
|
|
+ ValAvg float32 `gorm:"type:float(10, 2)" json:"valAvg"` //天均值
|
|
|
|
+ ValMax float32 `gorm:"type:float(10, 2)" json:"valMax"` //天最大
|
|
|
|
+ ValMin float32 `gorm:"type:float(10, 2)" json:"valMin"` //天最小
|
|
|
|
+ CreateTime time.Time `gorm:"type:datetime;index" json:"createTime"` //新增时间
|
|
}
|
|
}
|
|
|
|
|
|
func (EnvironmentDataSummary) TableName() string {
|
|
func (EnvironmentDataSummary) TableName() string {
|
|
@@ -66,9 +65,9 @@ func (c *EnvironmentDataSummary) DaySummary(start, end time.Time) error {
|
|
err := Db.Debug().Model(&c).Exec(`INSERT INTO data_environment_summary
|
|
err := Db.Debug().Model(&c).Exec(`INSERT INTO data_environment_summary
|
|
select device_id,
|
|
select device_id,
|
|
data_type,
|
|
data_type,
|
|
- round(avg(value), 2) as avg_val,
|
|
|
|
- max(value) as max_val,
|
|
|
|
- min(value) as min_val,
|
|
|
|
|
|
+ round(avg(value), 2) val_avg,
|
|
|
|
+ max(value) val_max,
|
|
|
|
+ min(value) val_min,
|
|
adddate(current_date, -1) create_time
|
|
adddate(current_date, -1) create_time
|
|
from (
|
|
from (
|
|
SELECT device_id, 2 AS data_type, pm25 AS value, create_time
|
|
SELECT device_id, 2 AS data_type, pm25 AS value, create_time
|