Browse Source

z_devicedata 删除ID, T_id

zoie 6 months ago
parent
commit
a787d09a9e
3 changed files with 10 additions and 7 deletions
  1. 1 1
      controllers/Device.go
  2. 8 5
      models/Device/DeviceData.go
  3. 1 1
      models/Task/TaskData.go

+ 1 - 1
controllers/Device.go

@@ -253,7 +253,7 @@ func (c *DeviceController) Device_Data() {
 	r_jsons.Page = page
 	r_jsons.Page_size = int(page_size)
 	r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
-	r_jsons.Num = int(cnt)
+	r_jsons.Num = cnt
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
 	c.ServeJSON()

+ 8 - 5
models/Device/DeviceData.go

@@ -215,7 +215,6 @@ func CREATE_DeviceData(SN string) bool {
 //}
 
 type DeviceData_ struct {
-	T_id   int     `orm:"column(t_id);size(10);null"`           // ID
 	T_t    float32 `orm:"column(t_t);size(10);null"`            // 温度
 	T_rh   float32 `orm:"column(t_rh);size(10);null"`           // 湿度
 	T_time string  `orm:"column(t_time);type(timestamp);null;"` // 采集时间
@@ -273,7 +272,8 @@ func Read_DeviceSensorData_ById_List(SN string, Time_start_ string, Time_end_ st
 		return maps, 0
 	}
 	//fmt.Println("maps_z;",maps_z[0][0])
-	sql = "SELECT t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN
+	//sql = "SELECT t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN
+	sql = "SELECT t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN
 	if len(sql_time) > 0 {
 		sql += " WHERE " + sql_time
 	}
@@ -312,7 +312,8 @@ func Read_DeviceData_By_snid(SN string, T_id int, Time_start_ string, Time_end_
 		sql_time += " t_time <= '" + Time_end_ + "' AND "
 	}
 
-	sql := "SELECT t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
+	//sql := "SELECT t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
+	sql := "SELECT t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
 	sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(limit)
 	fmt.Println(sql)
 	_, err := o.Raw(sql).QueryRows(&maps)
@@ -389,7 +390,8 @@ func Read_DeviceSensorData_List(SN string, Time_start_ string, Time_end_ string,
 		return maps, 0
 	}
 	//fmt.Println("maps_z;",maps_z[0][0])
-	sql = "SELECT t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " " + sql_time + " ORDER BY t_time DESC "
+	//sql = "SELECT t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " " + sql_time + " ORDER BY t_time DESC "
+	sql = "SELECT t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " " + sql_time + " ORDER BY t_time DESC "
 	if page_z != 9999 {
 		sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(pagez)
 	}
@@ -449,7 +451,8 @@ func Read_DeviceSensorData_ById_New(SN string, T_id int) (DeviceData_New, bool)
 	}
 
 	//fmt.Println("maps_z;",maps_z[0][0])
-	sql := "SELECT t_id,t_t,t_rh,t_time  FROM z_devicedata_" + SN + " WHERE " + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
+	//sql := "SELECT t_id,t_t,t_rh,t_time  FROM z_devicedata_" + SN + " WHERE " + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
+	sql := "SELECT t_t,t_rh,t_time  FROM z_devicedata_" + SN + " WHERE " + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
 	sql = sql + " LIMIT 0,1 "
 
 	fmt.Println(sql)

+ 1 - 1
models/Task/TaskData.go

@@ -96,7 +96,7 @@ func Import_TaskData(Sn string, T_id string, T_task_id string, Time_start string
 	o := orm.NewOrm()
 
 	// 开始插入数据
-	sql := "insert into z_task_data_" + T_task_id + "(t_id,t_t,t_rh,t_time) select t_id,t_t,t_rh,t_time from z_devicedata_" + Sn
+	sql := "insert into z_task_data_" + T_task_id + "(t_id,t_t,t_rh,t_time) select " + T_id + ",t_t,t_rh,t_time from z_devicedata_" + Sn
 	sql = sql + " WHERE t_time >= '" + Time_start + "' AND t_time <= '" + Time_end + "'"
 	//  这里有时间优化  用于一次 prepare 多次 exec,以提高批量执行的速度
 	logs.Println(sql)