|
@@ -80,13 +80,15 @@ type DeviceSensor_R struct {
|
|
|
T_DeviceSensorData DeviceData_R // 传感器最新数据
|
|
|
T_DeviceSensorParameter DeviceSensorParameter_R // 设备参数
|
|
|
T_DeviceSensorType DeviceSensorType_R // 传感器类型
|
|
|
-
|
|
|
}
|
|
|
type DeviceSensor_Applet struct {
|
|
|
T_sn string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
|
|
|
T_id int // 传感器编号
|
|
|
T_name string // 标题
|
|
|
|
|
|
+ T_pid int // 公司id
|
|
|
+ T_pid_name string // 公司名称
|
|
|
+
|
|
|
T_3dview string // 3D 视图ID
|
|
|
T_sort int // 排序
|
|
|
T_Dattery int // 电量
|
|
@@ -334,6 +336,9 @@ func DeviceSensorToDeviceSensor_Applet(DeviceSensor_ DeviceSensor) (DeviceSensor
|
|
|
DeviceSensor_r.T_sn = DeviceSensor_.T_sn
|
|
|
DeviceSensor_r.T_id = DeviceSensor_.T_id
|
|
|
DeviceSensor_r.T_name = DeviceSensor_.T_name
|
|
|
+ DeviceSensor_r.T_pid = DeviceSensor_.T_pid
|
|
|
+ DeviceSensor_r.T_pid_name = Account.Read_Company_Get(DeviceSensor_.T_pid)
|
|
|
+
|
|
|
DeviceSensor_r.T_Site = DeviceSensor_.T_Site
|
|
|
DeviceSensor_r.T_Dattery = DeviceSensor_.T_Dattery
|
|
|
DeviceSensor_r.T_monitor = DeviceSensor_.T_monitor
|
|
@@ -998,9 +1003,9 @@ func Read_DeviceSensorManageList(admin_r *Account.Admin, bindSN []string, T_pid
|
|
|
sql_WHERE += " AND t_datashow =" + strconv.Itoa(T_datashow)
|
|
|
}
|
|
|
|
|
|
- sql_ORDER := " ORDER BY t_sort ASC"
|
|
|
+ sql_ORDER := " ORDER BY t_sort ASC,ds.t_id"
|
|
|
if T_sort == 1 {
|
|
|
- sql_ORDER = " ORDER BY t_sort DESC"
|
|
|
+ sql_ORDER = " ORDER BY t_sort DESC,ds.t_id"
|
|
|
}
|
|
|
|
|
|
// -------------
|
|
@@ -1472,16 +1477,26 @@ func Read_CompanyDeviceSensor_List_For_Data_ByKey(T_pids []int) (DeviceSensor_r
|
|
|
return DeviceSensor_r, cnt
|
|
|
}
|
|
|
|
|
|
-// 获取列表
|
|
|
-func Read_DeviceSensor_T_type(T_pid int, bindSN []string) (lists orm2.ParamsList, err error) {
|
|
|
+// 小程序-获取传感器类型ID
|
|
|
+func Read_DeviceSensor_T_type(admin *Account.Admin, T_pid int, bindSN []string, T_pids []int) (lists orm2.ParamsList, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
var pl_lists orm2.ParamsList
|
|
|
- sql := "SELECT DISTINCT t_type FROM device_sensor WHERE t_pid=? AND t_datashow=1 AND t__state=1"
|
|
|
+ sql := "SELECT DISTINCT t_type FROM device_sensor WHERE t_datashow=1 AND t__state=1"
|
|
|
+ if admin.T_pid > 0 {
|
|
|
+ // 客户访问自己及其子公司数据
|
|
|
+ if len(T_pids) > 0 {
|
|
|
+ sql += fmt.Sprintf(" AND t_pid in (%s) ", lib.IntListToDotStr(T_pids))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 管理员访问当前公司数据
|
|
|
+ sql += " AND t_pid = " + strconv.Itoa(T_pid)
|
|
|
+ }
|
|
|
+
|
|
|
if len(bindSN) > 0 {
|
|
|
sql += fmt.Sprintf(" AND t_sn in (%s)", lib.StringListToQuotesDotStr(bindSN))
|
|
|
}
|
|
|
sql += " LIMIT 0,1000"
|
|
|
- _, err = o.Raw(sql, T_pid).ValuesFlat(&pl_lists)
|
|
|
+ _, err = o.Raw(sql).ValuesFlat(&pl_lists)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
|
return
|
|
@@ -1491,7 +1506,8 @@ func Read_DeviceSensor_T_type(T_pid int, bindSN []string) (lists orm2.ParamsList
|
|
|
}
|
|
|
|
|
|
// 数据展示菜单下 传感器参数列表
|
|
|
-func Read_DeviceSensor_List_For_Applet(admin *Account.Admin, bindSN []string, T_pid int, T_name, T_online string, T_RealTime, T_type, page, page_z int) (DeviceSensor_r []DeviceSensor_Applet, cnt int64) {
|
|
|
+func Read_DeviceSensor_List_For_Applet(admin *Account.Admin, bindSN []string, T_pid int, T_pids []int, T_name, T_online string,
|
|
|
+ T_RealTime, T_type, page, page_z int) (DeviceSensor_r []DeviceSensor_Applet, cnt int64) {
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
// 也可以直接使用 Model 结构体作为表名
|
|
@@ -1507,7 +1523,12 @@ func Read_DeviceSensor_List_For_Applet(admin *Account.Admin, bindSN []string, T_
|
|
|
|
|
|
var r []DeviceSensor
|
|
|
cond := orm.NewCondition()
|
|
|
- cond1 := cond.And("T_pid", T_pid)
|
|
|
+ cond1 := orm.NewCondition()
|
|
|
+ if admin.T_pid > 0 {
|
|
|
+ cond1 = cond.And("T_pid__in", T_pids)
|
|
|
+ } else {
|
|
|
+ cond1 = cond.And("T_pid", T_pid)
|
|
|
+ }
|
|
|
|
|
|
if T_type > 0 {
|
|
|
cond1 = cond1.And("T_type", T_type)
|
|
@@ -1569,18 +1590,28 @@ func Read_DeviceSensor_List_For_Applet(admin *Account.Admin, bindSN []string, T_
|
|
|
return DeviceSensor_r, cnt
|
|
|
}
|
|
|
|
|
|
-// 小程序-传感器类型
|
|
|
-func Read_DeviceSensor_T_sn_ByT_type(T_pid int, bindSN []string, T_type int) (lists []string, err error) {
|
|
|
+// 小程序-通过传感器类型获取sn
|
|
|
+func Read_DeviceSensor_T_sn_ByT_type(admin *Account.Admin, T_pid int, bindSN []string, T_pids []int, T_type int) (lists []string, err error) {
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
|
|
|
- sql := "t_pid=? AND t__state=1 AND t_datashow=1 AND t_type = " + strconv.Itoa(T_type)
|
|
|
+ sql := "t__state=1 AND t_datashow=1 AND t_type = " + strconv.Itoa(T_type)
|
|
|
+
|
|
|
+ if admin.T_pid > 0 {
|
|
|
+ // 客户访问自己及其子公司数据
|
|
|
+ if len(T_pids) > 0 {
|
|
|
+ sql += fmt.Sprintf(" AND t_pid in (%s) ", lib.IntListToDotStr(T_pids))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 管理员访问当前公司数据
|
|
|
+ sql += " AND t_pid = " + strconv.Itoa(T_pid)
|
|
|
+ }
|
|
|
|
|
|
if len(bindSN) > 0 {
|
|
|
sql += fmt.Sprintf(" AND t_sn in (%s)", lib.StringListToQuotesDotStr(bindSN))
|
|
|
}
|
|
|
|
|
|
- _, err = o.Raw("SELECT DISTINCT T_sn FROM device_sensor WHERE "+sql+" LIMIT 0,1000", T_pid).QueryRows(&lists)
|
|
|
+ _, err = o.Raw("SELECT DISTINCT T_sn FROM device_sensor WHERE " + sql + " LIMIT 0,1000").QueryRows(&lists)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
|
return
|
|
@@ -1624,3 +1655,45 @@ func Read_DeviceSensor_All() (DeviceSensor_r []DeviceSensor) {
|
|
|
|
|
|
return DeviceSensor_r
|
|
|
}
|
|
|
+
|
|
|
+// 获取对接电信的实时数据
|
|
|
+func Read_Docking_Real_Data(T_pid int) (DeviceData_r []DeviceData_R) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ // 也可以直接使用 Model 结构体作为表名
|
|
|
+
|
|
|
+ qs := o.QueryTable(new(DeviceSensor))
|
|
|
+
|
|
|
+ var r []DeviceSensor
|
|
|
+ cond := orm.NewCondition()
|
|
|
+ cond1 := cond.And("T_pid", T_pid)
|
|
|
+
|
|
|
+ _, err := qs.SetCond((*orm2.Condition)(cond1)).All(&r)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range r {
|
|
|
+ sp, _ := Read_DeviceSensorParameter(v.T_sn, v.T_id)
|
|
|
+ deviceDate := Read_DeviceData(v.T_sn, v.T_id)
|
|
|
+
|
|
|
+ data := DeviceData_R{
|
|
|
+ T_sn: v.T_sn,
|
|
|
+ T_id: v.T_id,
|
|
|
+ T_t: deviceDate.T_t,
|
|
|
+ T_rh: deviceDate.T_rh,
|
|
|
+ T_site: deviceDate.T_site,
|
|
|
+ T_time: deviceDate.T_time.Format("2006-01-02 15:04:05"),
|
|
|
+ T_sp: deviceDate.T_sp,
|
|
|
+ T_name: sp.T_name,
|
|
|
+ T_tl: sp.T_Tlower,
|
|
|
+ T_tu: sp.T_Tupper,
|
|
|
+ T_rhl: sp.T_RHlower,
|
|
|
+ T_rhu: sp.T_RHupper,
|
|
|
+ }
|
|
|
+
|
|
|
+ DeviceData_r = append(DeviceData_r, data)
|
|
|
+
|
|
|
+ }
|
|
|
+ return DeviceData_r
|
|
|
+}
|