|
@@ -242,12 +242,11 @@ type DeviceData_T struct {
|
|
|
// 添加
|
|
|
func Add_DeviceData(SN string, v DeviceData_T) bool {
|
|
|
//if(conf.Test_server){
|
|
|
- // fmt.Println("Add_DeviceData:",SN , t_name , t_id , t_t , t_rh , t_tl , t_tu , t_rhl , t_rhu , t_site , t_battery , t_time)
|
|
|
// return true
|
|
|
//}
|
|
|
|
|
|
key_time := SN + "|" + strconv.Itoa(v.T_id) + "|" + v.T_time.Format("2006-01-02 15:04:05")
|
|
|
- fmt.Println(key_time)
|
|
|
+ logs.Debug(key_time)
|
|
|
if redis_DeviceData.IsExist(key_time) {
|
|
|
//println("找到key:",key)
|
|
|
return true
|
|
@@ -267,7 +266,6 @@ func Add_DeviceData(SN string, v DeviceData_T) bool {
|
|
|
logs.Info(err)
|
|
|
return false
|
|
|
}
|
|
|
- //fmt.Println("maps_z[0][0]:",maps_z[0][0])
|
|
|
if lib.To_int(maps_z[0][0]) > 0 {
|
|
|
logs.Info("存在记录,跳过!")
|
|
|
return true
|
|
@@ -278,7 +276,7 @@ func Add_DeviceData(SN string, v DeviceData_T) bool {
|
|
|
sql := "INSERT INTO z_device_data_" + SN + " ( `t_id`, `t_t`, `t_rh`, `t_site`, `t_time`) " +
|
|
|
"VALUES (" + strconv.Itoa(v.T_id) + ", " + lib.To_string(v.T_t) + ", " + lib.To_string(v.T_rh) + ", '" + v.T_Site + "'," + v.T_time.Format("2006-01-02 15:04:05") + "')"
|
|
|
// 这里有时间优化 用于一次 prepare 多次 exec,以提高批量执行的速度
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
res, err := o.Raw(sql).Exec()
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -315,7 +313,7 @@ func Read_DeviceData_ById_List(SN string, T_id int, Time_start_ string, Time_end
|
|
|
}
|
|
|
|
|
|
sql := "SELECT COUNT(t_id) FROM z_device_data_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id)
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err := o.Raw(sql).ValuesList(&maps_z)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -324,14 +322,13 @@ func Read_DeviceData_ById_List(SN string, T_id int, Time_start_ string, Time_end
|
|
|
if len(maps_z) == 0 {
|
|
|
return r, 0
|
|
|
}
|
|
|
- //fmt.Println("maps_z;",maps_z[0][0])
|
|
|
- //t_tl,t_tu,t_rhl,t_rhu,
|
|
|
+
|
|
|
sql = "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,t_time AS t_time1 FROM z_device_data_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time1 DESC,t_id DESC "
|
|
|
if page_z != 9999 {
|
|
|
sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
|
|
|
}
|
|
|
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err = o.Raw(sql).QueryRows(&maps)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -376,7 +373,7 @@ func Read_DeviceData_ById_List_OrderByTimeAes(SN string, T_id int, Time_start_ s
|
|
|
}
|
|
|
|
|
|
sql := "SELECT COUNT(t_id) FROM z_device_data_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id)
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err := o.Raw(sql).ValuesList(&maps_z)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -385,14 +382,13 @@ func Read_DeviceData_ById_List_OrderByTimeAes(SN string, T_id int, Time_start_ s
|
|
|
if len(maps_z) == 0 {
|
|
|
return r, 0
|
|
|
}
|
|
|
- //fmt.Println("maps_z;",maps_z[0][0])
|
|
|
- //t_tl,t_tu,t_rhl,t_rhu,
|
|
|
+
|
|
|
sql = "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,t_time AS t_time1 FROM z_device_data_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time1,t_id DESC "
|
|
|
if page_z != 9999 {
|
|
|
sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
|
|
|
}
|
|
|
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err = o.Raw(sql).QueryRows(&maps)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -438,7 +434,7 @@ func Read_DeviceData_ByIds(SN string, ids []int, Time_start_ string, Time_end_ s
|
|
|
}
|
|
|
|
|
|
sql := "SELECT COUNT(t_id) FROM z_device_data_" + SN + " WHERE " + sql_time + " t_id in (" + lib.IntListToDotStr(ids) + ")"
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err := o.Raw(sql).ValuesList(&maps_z)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -447,14 +443,13 @@ func Read_DeviceData_ByIds(SN string, ids []int, Time_start_ string, Time_end_ s
|
|
|
if len(maps_z) == 0 {
|
|
|
return r, 0
|
|
|
}
|
|
|
- //fmt.Println("maps_z;",maps_z[0][0])
|
|
|
//t_tl,t_tu,t_rhl,t_rhu,
|
|
|
sql = "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,t_time AS t_time1 FROM z_device_data_" + SN + " WHERE " + sql_time + " t_id in (" + lib.IntListToDotStr(ids) + ") ORDER BY t_time1 DESC,t_id ASC "
|
|
|
if page_z != 9999 {
|
|
|
sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
|
|
|
}
|
|
|
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err = o.Raw(sql).QueryRows(&maps)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -489,9 +484,6 @@ func Read_DeviceData_ByIds_ForPDF(SN string, ids []int, Time_start_ string, Time
|
|
|
sql_time += " t_time <= '" + Time_end_ + "' AND "
|
|
|
}
|
|
|
|
|
|
- //fmt.Println("maps_z;",maps_z[0][0])
|
|
|
- //t_tl,t_tu,t_rhl,t_rhu,
|
|
|
-
|
|
|
selectSql := ""
|
|
|
for i, v := range ids {
|
|
|
selectSql += fmt.Sprintf("MAX(CASE WHEN t_id = %d THEN t_t END) AS t_id%d,", v, i+1)
|
|
@@ -500,7 +492,7 @@ func Read_DeviceData_ByIds_ForPDF(SN string, ids []int, Time_start_ string, Time
|
|
|
|
|
|
sql := "SELECT DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time," + selectSql + " FROM z_device_data_" + SN + " WHERE " + sql_time + " t_id in (" + lib.IntListToDotStr(ids) + ") GROUP BY t_time ORDER BY t_time"
|
|
|
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err := o.Raw(sql).QueryRows(&r)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -513,7 +505,7 @@ func Read_DeviceData_ByIds_ForPDF(SN string, ids []int, Time_start_ string, Time
|
|
|
func Read_SqlRawL(T_SQL string, T_data []string) (string, []orm2.Params) {
|
|
|
o := orm.NewOrm()
|
|
|
var lists []orm2.Params
|
|
|
- fmt.Println(T_SQL)
|
|
|
+ logs.Debug(T_SQL)
|
|
|
_, err := o.Raw(T_SQL, T_data).Values(&lists)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -541,7 +533,7 @@ func Read_DeviceData_By_T_snid_List(T_snid string, Time_start_ string, Time_end_
|
|
|
maps = append(maps, r_maps...)
|
|
|
maps_num = maps_num + int64(r_maps_num)
|
|
|
|
|
|
- fmt.Println("加载数据:", sn_id[0], sn_id[1], r_maps_num)
|
|
|
+ logs.Debug("加载数据:", sn_id[0], sn_id[1], r_maps_num)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -581,10 +573,10 @@ func Read_DeviceData_By_T_snid_List(T_snid string, Time_start_ string, Time_end_
|
|
|
}
|
|
|
|
|
|
if page_z == 9999 {
|
|
|
- fmt.Println("总数据:", maps_num, " 导出")
|
|
|
+ logs.Debug("总数据:", maps_num, " 导出")
|
|
|
return maps, maps_num
|
|
|
}
|
|
|
- fmt.Println("总数据:", maps_num, " 截取", offset, offset+page_z)
|
|
|
+ logs.Debug("总数据:", maps_num, " 截取", offset, offset+page_z)
|
|
|
return maps[offset:offset_z], maps_num
|
|
|
}
|
|
|
|
|
@@ -595,10 +587,10 @@ func Read_DeviceData_ById_Year_List(SN string) []orm2.ParamsList {
|
|
|
|
|
|
//sql = "SELECT t_name,t_t,t_rh,t_tl,t_tu,t_rhl,t_rhu,t_site,DATE_FORMAT(t_time,'%Y-%c-%d %H:%i:%s') AS t_time FROM z_device_data_"+SN+" WHERE "+sql_time+" t_id = "+ strconv.Itoa(T_id) +" ORDER BY t_time DESC "
|
|
|
sql := "SELECT DATE_FORMAT(t_time,\"%m\") AS m ,DATE_FORMAT(t_time,\"%d\") AS d FROM z_device_data_" + SN + " WHERE t_time > '" + strconv.Itoa(time.Now().Year()) + "-0-0 00:00:00' GROUP BY DATE_FORMAT(t_time,\"%m\");"
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
num, err := o.Raw(sql).ValuesList(&maps_z)
|
|
|
if err == nil && num > 0 {
|
|
|
- fmt.Println(maps_z[0][0]) // slene
|
|
|
+ logs.Debug(maps_z[0][0]) // slene
|
|
|
}
|
|
|
//value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cnt), 64)
|
|
|
//key,_ := strconv.Atoi(maps_z[0][0].(string))
|
|
@@ -614,7 +606,7 @@ func Read_DeviceData_ById_Month_List(SN string) []orm2.ParamsList {
|
|
|
|
|
|
//sql = "SELECT t_name,t_t,t_rh,t_tl,t_tu,t_rhl,t_rhu,t_site,DATE_FORMAT(t_time,'%Y-%c-%d %H:%i:%s') AS t_time FROM z_device_data_"+SN+" WHERE "+sql_time+" t_id = "+ strconv.Itoa(T_id) +" ORDER BY t_time DESC "
|
|
|
sql := "SELECT DATE_FORMAT(t_time,\"%d\") AS d FROM z_device_data_" + SN + " WHERE t_time > '" + time_x + "' GROUP BY DATE_FORMAT(t_time,\"%d\");"
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
o.Raw(sql).ValuesList(&maps_z)
|
|
|
|
|
|
//value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cnt), 64)
|
|
@@ -631,7 +623,7 @@ func Read_DeviceData_ById_Day_List(SN string) []orm2.ParamsList {
|
|
|
|
|
|
//sql = "SELECT t_name,t_t,t_rh,t_tl,t_tu,t_rhl,t_rhu,t_site,DATE_FORMAT(t_time,'%Y-%c-%d %H:%i:%s') AS t_time FROM z_device_data_"+SN+" WHERE "+sql_time+" t_id = "+ strconv.Itoa(T_id) +" ORDER BY t_time DESC "
|
|
|
sql := "SELECT DATE_FORMAT(t_time,\"%H\") AS m FROM z_device_data_" + SN + " WHERE t_time > '" + time_x + "' GROUP BY DATE_FORMAT(t_time,\"%H\");"
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
o.Raw(sql).ValuesList(&maps_z)
|
|
|
|
|
|
//value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cnt), 64)
|
|
@@ -650,7 +642,7 @@ func Read_DeviceData_List_GROUP_BY_t_time(SN string, Time_start_ string, Time_en
|
|
|
}
|
|
|
|
|
|
sql := "SELECT DATE_FORMAT(t_time,'%Y-%c-%d %H:%i:%s') AS t_time FROM z_device_data_" + SN + " WHERE " + sql_time + " GROUP BY t_time ORDER BY t_time DESC "
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err := o.Raw(sql).ValuesList(&maps_z)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -668,7 +660,7 @@ func Read_DeviceData(T_sn string, T_id int) (t DeviceData_) {
|
|
|
var maps []DeviceData_
|
|
|
sql := "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,t_time AS t_time1 FROM z_device_data_" + T_sn + " WHERE" + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time1 DESC LIMIT 0,1"
|
|
|
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err := o.Raw(sql).QueryRows(&maps)
|
|
|
|
|
|
if err != nil {
|
|
@@ -703,7 +695,7 @@ func Read_DeviceData_BackUp_List(T_snid string, Time_start_ string, Time_end_ st
|
|
|
maps = append(maps, r_maps...)
|
|
|
maps_num = maps_num + int64(r_maps_num)
|
|
|
|
|
|
- fmt.Println("加载数据:", sn_id[0], sn_id[1], r_maps_num)
|
|
|
+ logs.Debug("加载数据:", sn_id[0], sn_id[1], r_maps_num)
|
|
|
}
|
|
|
}
|
|
|
if page <= 1 {
|
|
@@ -722,10 +714,10 @@ func Read_DeviceData_BackUp_List(T_snid string, Time_start_ string, Time_end_ st
|
|
|
}
|
|
|
|
|
|
if page_z == 9999 {
|
|
|
- fmt.Println("总数据:", maps_num, " 导出")
|
|
|
+ logs.Debug("总数据:", maps_num, " 导出")
|
|
|
return maps, maps_num
|
|
|
}
|
|
|
- fmt.Println("总数据:", maps_num, " 截取", offset, offset+page_z)
|
|
|
+ logs.Debug("总数据:", maps_num, " 截取", offset, offset+page_z)
|
|
|
return maps[offset:offset_z], maps_num
|
|
|
}
|
|
|
|
|
@@ -745,7 +737,7 @@ func Read_DeviceData_BackUp(T_sn string, T_id int, Time_start_ string, Time_end_
|
|
|
|
|
|
sql := "SELECT t_id,date_format(t_time, '%Y-%m-%d') t_date, count(*) t_num FROM z_device_data_" + T_sn + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " GROUP BY t_date ORDER BY t_time DESC "
|
|
|
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
_, err := o.Raw(sql).QueryRows(&maps)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
@@ -768,7 +760,7 @@ func Read_DeviceData_By_Time(T_sn string, T_id int, Time string) (t DeviceData_)
|
|
|
var maps DeviceData_
|
|
|
sql := "SELECT t_id,t_sp,t_t,t_rh,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time,t_time AS t_time1 FROM z_device_data_" + T_sn + " WHERE" + " t_id = " + strconv.Itoa(T_id) + " AND t_time <= '" + Time + "'" + " ORDER BY t_time1 DESC LIMIT 0,1"
|
|
|
|
|
|
- fmt.Println(sql)
|
|
|
+ logs.Debug(sql)
|
|
|
err := o.Raw(sql).QueryRow(&maps)
|
|
|
|
|
|
if err != nil {
|