|
@@ -45,6 +45,7 @@ type DeviceData_ struct {
|
|
|
type DeviceData_R struct {
|
|
|
T_sn string `json:"t_sn"` //设备
|
|
|
T_id int `json:"t_id"` // 传感器id
|
|
|
+ T_sp int `json:"t_sp"` // 传感器参数id
|
|
|
T_name string `json:"t_name"` // 传感器名称
|
|
|
T_t float32 `json:"t_t"` // 温度
|
|
|
T_rh float32 `json:"t_rh"` // 湿度
|
|
@@ -84,11 +85,12 @@ func DeviceData_ToDeviceData_R(r DeviceData_, maps map[int]DeviceSensorParameter
|
|
|
t.T_time = r.T_time.Format("2006-01-02 15:04:05")
|
|
|
t.Create_Time = r.Create_time.Format("2006-01-02 15:04:05")
|
|
|
if sp, ok := maps[r.T_sp]; ok {
|
|
|
+ t.T_sp = sp.T_sp
|
|
|
t.T_name = sp.T_name
|
|
|
t.T_tl = sp.T_Tlower
|
|
|
t.T_tu = sp.T_Tupper
|
|
|
t.T_rhl = sp.T_RHlower
|
|
|
- t.T_rhu = sp.T_Tupper
|
|
|
+ t.T_rhu = sp.T_RHupper
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -274,7 +276,7 @@ func Read_DeviceData_ById_List(SN string, T_id int, Time_start_ string, Time_end
|
|
|
sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
|
|
|
}
|
|
|
|
|
|
- fmt.Println(sql)
|
|
|
+ //fmt.Println(sql)
|
|
|
_, err = o.Raw(sql).QueryRows(&maps)
|
|
|
|
|
|
//value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cnt), 64)
|
|
@@ -507,14 +509,32 @@ func Read_DeviceData_Execl_ISREPEAT(sn, t_time, t_id string) bool {
|
|
|
}
|
|
|
*/
|
|
|
// Update_DeviceSensorData 更新设备数据
|
|
|
-func Update_DeviceSensorData(v DeviceData_R, fieldName, val string) {
|
|
|
+func Update_DeviceSensorData(v DeviceData_R, fieldName, val string) error {
|
|
|
o := orm.NewOrm()
|
|
|
- sqlStatemt := fmt.Sprintf("update z_device_data_%s set %s = ? where t_id = ? and t_t = ? and t_rh = ? and t_site = ? and create_time = ?", v.T_sn, fieldName)
|
|
|
- log.Println(sqlStatemt)
|
|
|
- log.Println("创建时间:", v.Create_Time)
|
|
|
- _, err := o.Raw(sqlStatemt, val, v.T_id, v.T_t, v.T_rh, v.T_site, v.Create_Time).Exec()
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err.Error())
|
|
|
+ if fieldName == "t__tlower" {
|
|
|
+ split := strings.Split(val, "|")
|
|
|
+ i := strings.Split(split[0], "~")
|
|
|
+ t__tlower := i[0]
|
|
|
+ t__tupper := i[1]
|
|
|
+ i2 := strings.Split(split[1], "~")
|
|
|
+ t__r_hlower := i2[0]
|
|
|
+ t__r_hupper := i2[1]
|
|
|
+ sqlStatemt := fmt.Sprintf("update device_sensor_parameter set t__tlower =%s , t__tupper = %s , t__r_hlower = %s , t__r_hupper = %s where id =%d ", t__tlower, t__tupper, t__r_hlower, t__r_hupper, v.T_sp)
|
|
|
+ //log.Println(sqlStatemt)
|
|
|
+ _, err := o.Raw(sqlStatemt).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ } else {
|
|
|
+ sqlStatemt := fmt.Sprintf("update z_device_data_%s set %s = ? where t_id = ? and t_t = ? and t_rh = ? and t_site = ? and create_time = ?", v.T_sn, fieldName)
|
|
|
+ log.Println(sqlStatemt)
|
|
|
+ log.Println("创建时间:", v.Create_Time)
|
|
|
+ _, err := o.Raw(sqlStatemt, val, v.T_id, v.T_t, v.T_rh, v.T_site, v.Create_Time).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -616,3 +636,21 @@ func Read_DeviceData_List_GROUP_BY_t_time(SN string, Time_start_ string, Time_en
|
|
|
o.Raw(sql).ValuesList(&maps_z)
|
|
|
return maps_z
|
|
|
}
|
|
|
+
|
|
|
+// GetCompanyBySn 根据sn查询公司名称
|
|
|
+func GetCompanyBySn(sn string) (string, error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sqls := fmt.Sprintf("SELECT t_pid FROM `device` WHERE t_sn='%s'", sn)
|
|
|
+ var TPid string
|
|
|
+ err := o.Raw(sqls).QueryRow(&TPid)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ sqlCompany := fmt.Sprintf("SELECT t_name FROM `company` WHERE id='%s'", TPid)
|
|
|
+ var TName string
|
|
|
+ err = o.Raw(sqlCompany).QueryRow(&TName)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ return TName, nil
|
|
|
+}
|