|
@@ -31,6 +31,8 @@ type DeviceSensor struct {
|
|
|
T_sort int `orm:"index;size(200);default(1)"` // 排序
|
|
|
T_3dview string `orm:"size(256);null"` // 3D 视图ID
|
|
|
T_type int `orm:"index;size(4);null"` // Device.DeviceSensorType 1库房 2移动
|
|
|
+ T_link int `orm:"index;size(4):default(1)"` // 0:断开/故障 1连接 实时数据
|
|
|
+ T_State int `orm:"index;size(2);default(1)"` // 0 屏蔽 1 正常 (屏蔽后 只有内部管理员才能看到,用户 输入SN\名称 搜索时 也能看到)
|
|
|
|
|
|
// 设备同步参数
|
|
|
T_Dattery int `orm:"size(4);null"` // 电量
|
|
@@ -38,7 +40,6 @@ type DeviceSensor struct {
|
|
|
T_monitor int `orm:"index;size(2);null"` // 监控状态 0 未监控 1 监控
|
|
|
T_online int `orm:"index;size(2);default(1)"` // 在线状态 0 未启用 1 在线 2 离线
|
|
|
T_online_s int `orm:"index;size(2);default(0)"` // 在线状态-备用 0 未启用 1 在线 2 离线
|
|
|
- T_State int `orm:"index;size(2);default(1)"` // 0 屏蔽 1 正常 (屏蔽后 只有内部管理员才能看到,用户 输入SN\名称 搜索时 也能看到)
|
|
|
|
|
|
CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
|
|
|
UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
|
|
@@ -68,6 +69,8 @@ type DeviceSensor_R struct {
|
|
|
T_online_s int // 在线状态-备用 0 未启用 1 在线 2 离线
|
|
|
T_datashow int // 0 屏蔽数据展示 1 正常数据展示
|
|
|
T_type int // 类型
|
|
|
+ T_link int // 0:断开/故障 1连接 实时数据
|
|
|
+ T_State int // 0 屏蔽 1 正常 (屏蔽后 只有内部管理员才能看到,用户 输入SN\名称 搜索时 也能看到)
|
|
|
|
|
|
T_DeviceSensorData DeviceData_R // 传感器最新数据
|
|
|
T_DeviceSensorParameter DeviceSensorParameter_R // 设备参数
|
|
@@ -88,6 +91,8 @@ type DeviceSensor_Applet struct {
|
|
|
T_online_s int // 在线状态-备用 0 未启用 1 在线 2 离线
|
|
|
T_datashow int // 0 屏蔽数据展示 1 正常数据展示
|
|
|
T_type int // 1库房 2移动
|
|
|
+ T_link int // 0:断开/故障 1连接 实时数据
|
|
|
+ T_State int // 0 屏蔽 1 正常 (屏蔽后 只有内部管理员才能看到,用户 输入SN\名称 搜索时 也能看到)
|
|
|
|
|
|
T_DeviceSensorData DeviceData_R // 传感器最新数据
|
|
|
T_DeviceSensorParameter DeviceSensorParameter_R // 设备参数
|
|
@@ -96,6 +101,32 @@ type DeviceSensor_Applet struct {
|
|
|
|
|
|
}
|
|
|
|
|
|
+type DeviceSensor_Company 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 // 电量
|
|
|
+ T_Site string // GPS
|
|
|
+ T_monitor int // 记录状态
|
|
|
+ T_online int // 在线状态 1 在线 0 离线
|
|
|
+ T_online_s int // 在线状态-备用 0 未启用 1 在线 2 离线
|
|
|
+ T_datashow int // 0 屏蔽数据展示 1 正常数据展示
|
|
|
+ T_type int // 类型
|
|
|
+ T_link int // 0:断开/故障 1连接 实时数据
|
|
|
+ T_State int // 0 屏蔽 1 正常 (屏蔽后 只有内部管理员才能看到,用户 输入SN\名称 搜索时 也能看到)
|
|
|
+
|
|
|
+ T_DeviceSensorData DeviceData_R // 传感器最新数据
|
|
|
+ T_DeviceSensorParameter DeviceSensorParameter_R // 设备参数
|
|
|
+ T_DeviceSensorType DeviceSensorType_R // 传感器类型
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
// 传感器管理
|
|
|
type DeviceSensor_P struct {
|
|
|
T_sn string // 设备序列号 KF开头,环境监测主机。 YD开头,温途监测主机
|
|
@@ -206,6 +237,8 @@ func DeviceSensorToDeviceSensor_R(DeviceSensor_ DeviceSensor) (DeviceSensor_r De
|
|
|
DeviceSensor_r.T_3dview = DeviceSensor_.T_3dview
|
|
|
DeviceSensor_r.T_type = DeviceSensor_.T_type
|
|
|
DeviceSensor_r.T_sort = DeviceSensor_.T_sort
|
|
|
+ DeviceSensor_r.T_link = DeviceSensor_.T_link
|
|
|
+ DeviceSensor_r.T_State = DeviceSensor_.T_State
|
|
|
|
|
|
DeviceSensor_r.T_datashow = DeviceSensor_.T_datashow
|
|
|
|
|
@@ -213,9 +246,56 @@ func DeviceSensorToDeviceSensor_R(DeviceSensor_ DeviceSensor) (DeviceSensor_r De
|
|
|
DeviceSensor_r.T_online = DeviceSensor_.T_online
|
|
|
DeviceSensor_r.T_online_s = DeviceSensor_.T_online_s
|
|
|
DeviceSensor_r.T_monitor = DeviceSensor_.T_monitor
|
|
|
- if DeviceSensor_.T_online == 2 && (DeviceSensor_.T_online_s == 0 || DeviceSensor_.T_online_s == 2) && DeviceSensor_.T_monitor == 1 {
|
|
|
- DeviceSensor_r.T_monitor = 2
|
|
|
- }
|
|
|
+ //if DeviceSensor_.T_online == 2 && (DeviceSensor_.T_online_s == 0 || DeviceSensor_.T_online_s == 2) && DeviceSensor_.T_monitor == 1 {
|
|
|
+ // DeviceSensor_r.T_monitor = 2
|
|
|
+ //}
|
|
|
+
|
|
|
+ // 最新系统参数
|
|
|
+ DeviceSensor_r.T_DeviceSensorParameter, _ = Read_DeviceSensorParameter(DeviceSensor_.T_sn, DeviceSensor_.T_id)
|
|
|
+
|
|
|
+ // 最新数据
|
|
|
+ //key_data := DeviceSensor_.T_sn + "|" + strconv.Itoa(DeviceSensor_.T_id)
|
|
|
+ //DeviceSensor_r.T_DeviceSensorData, _ = RedisDeviceData_Get(key_data)
|
|
|
+ DeviceData := Read_DeviceData(DeviceSensor_.T_sn, DeviceSensor_.T_id)
|
|
|
+ //DeviceData, _ := RedisDeviceData_Get(DeviceSensor_.T_sn + "|" + strconv.Itoa(DeviceSensor_.T_id))
|
|
|
+
|
|
|
+ DeviceSensor_r.T_DeviceSensorData = DeviceDataToDeviceData_R2(device, DeviceSensor_r.T_DeviceSensorParameter, DeviceData)
|
|
|
+
|
|
|
+ deviceSensorType := Read_DeviceSensorType_Get(DeviceSensor_.T_type)
|
|
|
+ DeviceSensor_r.T_DeviceSensorType = DeviceSensorTypeToDeviceSensorType_R(deviceSensorType)
|
|
|
+ return
|
|
|
+}
|
|
|
+func DeviceSensorToDeviceSensor_Company(DeviceSensor_ DeviceSensor) (DeviceSensor_r DeviceSensor_Company) {
|
|
|
+
|
|
|
+ device, _ := Read_Device_ByT_sn(DeviceSensor_.T_sn)
|
|
|
+
|
|
|
+ //lib.DeviceRealSnMap[DeviceSensor_.T_sn] = 3 // 连续请求 实时数据
|
|
|
+ lib.DeviceRealSnMap.Store(DeviceSensor_.T_sn+"|"+device.T_mqttid, 0) // 连续请求 实时数据
|
|
|
+
|
|
|
+ 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
|
|
|
+ DeviceSensor_r.T_3dview = DeviceSensor_.T_3dview
|
|
|
+ DeviceSensor_r.T_type = DeviceSensor_.T_type
|
|
|
+ DeviceSensor_r.T_sort = DeviceSensor_.T_sort
|
|
|
+ DeviceSensor_r.T_link = DeviceSensor_.T_link
|
|
|
+ DeviceSensor_r.T_State = DeviceSensor_.T_State
|
|
|
+
|
|
|
+ DeviceSensor_r.T_datashow = DeviceSensor_.T_datashow
|
|
|
+
|
|
|
+ DeviceSensor_r.T_Dattery = DeviceSensor_.T_Dattery
|
|
|
+ DeviceSensor_r.T_online = DeviceSensor_.T_online
|
|
|
+ DeviceSensor_r.T_online_s = DeviceSensor_.T_online_s
|
|
|
+ DeviceSensor_r.T_monitor = DeviceSensor_.T_monitor
|
|
|
+ //if DeviceSensor_.T_online == 2 && (DeviceSensor_.T_online_s == 0 || DeviceSensor_.T_online_s == 2) && DeviceSensor_.T_monitor == 1 {
|
|
|
+ // DeviceSensor_r.T_monitor = 2
|
|
|
+ //}
|
|
|
|
|
|
// 最新系统参数
|
|
|
DeviceSensor_r.T_DeviceSensorParameter, _ = Read_DeviceSensorParameter(DeviceSensor_.T_sn, DeviceSensor_.T_id)
|
|
@@ -248,6 +328,8 @@ func DeviceSensorToDeviceSensor_Applet(DeviceSensor_ DeviceSensor) (DeviceSensor
|
|
|
DeviceSensor_r.T_3dview = DeviceSensor_.T_3dview
|
|
|
DeviceSensor_r.T_type = DeviceSensor_.T_type
|
|
|
DeviceSensor_r.T_sort = DeviceSensor_.T_sort
|
|
|
+ DeviceSensor_r.T_link = DeviceSensor_.T_link
|
|
|
+ DeviceSensor_r.T_State = DeviceSensor_.T_State
|
|
|
|
|
|
DeviceSensor_r.T_datashow = DeviceSensor_.T_datashow
|
|
|
|
|
@@ -255,9 +337,9 @@ func DeviceSensorToDeviceSensor_Applet(DeviceSensor_ DeviceSensor) (DeviceSensor
|
|
|
DeviceSensor_r.T_online = DeviceSensor_.T_online
|
|
|
DeviceSensor_r.T_online_s = DeviceSensor_.T_online_s
|
|
|
DeviceSensor_r.T_monitor = DeviceSensor_.T_monitor
|
|
|
- if DeviceSensor_.T_online == 2 && (DeviceSensor_.T_online_s == 0 || DeviceSensor_.T_online_s == 2) && DeviceSensor_.T_monitor == 1 {
|
|
|
- DeviceSensor_r.T_monitor = 2
|
|
|
- }
|
|
|
+ //if DeviceSensor_.T_online == 2 && (DeviceSensor_.T_online_s == 0 || DeviceSensor_.T_online_s == 2) && DeviceSensor_.T_monitor == 1 {
|
|
|
+ // DeviceSensor_r.T_monitor = 2
|
|
|
+ //}
|
|
|
|
|
|
// 最新系统参数
|
|
|
DeviceSensor_r.T_DeviceSensorParameter, _ = Read_DeviceSensorParameter(DeviceSensor_.T_sn, DeviceSensor_.T_id)
|
|
@@ -296,7 +378,7 @@ func Read_DeviceSensor_Num_ByT_sn(T_sn string) int {
|
|
|
}
|
|
|
|
|
|
// 获取列表
|
|
|
-func Read_DeviceSensorList(admin_r *Account.Admin, T_pid int, T_sn string, T_name string, T_Class_id, T_datashow int, T_type string, T_State int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
|
|
|
+func Read_DeviceSensorList(admin_r *Account.Admin, bindSN []string, T_pid int, T_sn string, T_name string, T_Class_id, T_datashow int, T_type string, T_State int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
// 也可以直接使用 Model 结构体作为表名
|
|
@@ -319,6 +401,10 @@ func Read_DeviceSensorList(admin_r *Account.Admin, T_pid int, T_sn string, T_nam
|
|
|
cond1 = cond1.And("T_Class__icontains", T_Class)
|
|
|
}
|
|
|
|
|
|
+ if len(bindSN) > 0 {
|
|
|
+ cond1 = cond1.And("T_sn__in", bindSN)
|
|
|
+ }
|
|
|
+
|
|
|
if len(T_type) > 0 {
|
|
|
list := strings.Split(T_type, ",")
|
|
|
cond1 = cond1.And("T_type__in", list)
|
|
@@ -326,17 +412,17 @@ func Read_DeviceSensorList(admin_r *Account.Admin, T_pid int, T_sn string, T_nam
|
|
|
|
|
|
if len(T_sn) > 0 {
|
|
|
cond1 = cond1.And("T_sn__icontains", T_sn)
|
|
|
+ } else {
|
|
|
+ // 不是内部权限(T_pid>0),T_State=1 0 屏蔽 1 正常
|
|
|
+ if admin_r.T_pid > 0 || T_State == 1 {
|
|
|
+ cond1 = cond1.And("T_State", 1)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if len(T_name) > 0 {
|
|
|
cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name))
|
|
|
}
|
|
|
|
|
|
- // 不是内部权限(T_pid>0),T_State=1 0 屏蔽 1 正常
|
|
|
- if admin_r.T_pid > 0 || T_State == 1 {
|
|
|
- cond1 = cond1.And("T_State", 1)
|
|
|
- }
|
|
|
-
|
|
|
if T_datashow == 1 { // 0 屏蔽数据展示 1 正常数据展示
|
|
|
cond1 = cond1.And("T_datashow", 1)
|
|
|
}
|
|
@@ -763,7 +849,7 @@ func Update_Device_To_DeviceSensor(r_Device Device) bool {
|
|
|
}
|
|
|
|
|
|
// 传感器管理列列表 -------------------
|
|
|
-func Read_DeviceSensorManageList(admin_r *Account.Admin, T_pid int, T_name string, T_calss_id, T_en, T_free, T_datashow, T_sort, page, page_z int) (DeviceSensor_p []DeviceSensor_P, cnt int64) {
|
|
|
+func Read_DeviceSensorManageList(admin_r *Account.Admin, bindSN []string, T_pid int, T_name string, T_calss_id, T_en, T_free, T_datashow, T_sort, page, page_z int) (DeviceSensor_p []DeviceSensor_P, cnt int64) {
|
|
|
o := orm.NewOrm()
|
|
|
var maps []DeviceSensor_P
|
|
|
var maps_z []orm2.ParamsList
|
|
@@ -777,6 +863,10 @@ func Read_DeviceSensorManageList(admin_r *Account.Admin, T_pid int, T_name strin
|
|
|
|
|
|
sql_WHERE := "t_pid = " + strconv.Itoa(T_pid)
|
|
|
|
|
|
+ if len(bindSN) > 0 {
|
|
|
+ sql_WHERE += fmt.Sprintf(" AND t_sn in (%s)", lib.StringListToQuotesDotStr(bindSN))
|
|
|
+ }
|
|
|
+
|
|
|
if admin_r.T_pid > 0 {
|
|
|
sql_WHERE += " AND t__state = 1"
|
|
|
}
|
|
@@ -842,9 +932,9 @@ func Read_DeviceSensorManageList(admin_r *Account.Admin, T_pid int, T_name strin
|
|
|
}
|
|
|
|
|
|
// 数据展示菜单下 传感器参数列表
|
|
|
-// 实时数据页面 温湿度一场数据往前排
|
|
|
+// 实时数据页面 温湿度异常数据往前排
|
|
|
// 轨迹展示页面
|
|
|
-func Read_DeviceSensor_List_For_Data(T_pid int, T_name string, T_Class_id, T_type, T_RealTime, T_MapShow int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
|
|
|
+func Read_DeviceSensor_List_For_Data(admin Account.Admin, bindSN []string, T_pid int, T_name string, T_Class_id, T_type, T_RealTime, T_MapShow int, page int, page_z int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
// 也可以直接使用 Model 结构体作为表名
|
|
@@ -859,7 +949,11 @@ func Read_DeviceSensor_List_For_Data(T_pid int, T_name string, T_Class_id, T_typ
|
|
|
|
|
|
var r []DeviceSensor
|
|
|
cond := orm.NewCondition()
|
|
|
- cond1 := cond.And("T_pid", T_pid).And("T_State", 1)
|
|
|
+ cond1 := cond.And("T_pid", T_pid)
|
|
|
+
|
|
|
+ if len(bindSN) > 0 {
|
|
|
+ cond1 = cond1.And("T_sn__in", bindSN)
|
|
|
+ }
|
|
|
|
|
|
if T_Class_id > 0 {
|
|
|
T_Class := "C" + strconv.Itoa(T_Class_id) + "|"
|
|
@@ -870,13 +964,22 @@ func Read_DeviceSensor_List_For_Data(T_pid int, T_name string, T_Class_id, T_typ
|
|
|
if T_type > 0 {
|
|
|
cond1 = cond1.And("T_type", T_type)
|
|
|
}
|
|
|
-
|
|
|
- if len(T_name) == 16 {
|
|
|
- cond1 = cond1.And("T_sn", T_name)
|
|
|
- } else if len(T_name) > 0 {
|
|
|
- cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_datashow", 1)
|
|
|
+ if admin.T_pid > 0 {
|
|
|
+ if len(T_name) >= 16 {
|
|
|
+ cond1 = cond1.And("T_sn", T_name)
|
|
|
+ } else if len(T_name) > 0 && len(T_name) < 16 {
|
|
|
+ cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_State", 1).And("T_datashow", 1)
|
|
|
+ } else {
|
|
|
+ cond1 = cond1.And("T_State", 1).And("T_datashow", 1)
|
|
|
+ }
|
|
|
} else {
|
|
|
- cond1 = cond1.And("T_datashow", 1)
|
|
|
+ if len(T_name) >= 16 {
|
|
|
+ cond1 = cond1.And("T_sn", T_name)
|
|
|
+ } else if len(T_name) > 0 && len(T_name) < 16 {
|
|
|
+ cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_State", 1).And("T_datashow", 1)
|
|
|
+ } else {
|
|
|
+ cond1 = cond1.And("T_State", 1).And("T_datashow", 1)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if T_MapShow == 1 {
|
|
@@ -929,11 +1032,113 @@ func Read_DeviceSensor_List_For_Data(T_pid int, T_name string, T_Class_id, T_typ
|
|
|
return DeviceSensor_r, cnt
|
|
|
}
|
|
|
|
|
|
+// 公司管理 实时数据
|
|
|
+// 查询当前公司及其下面所有子公司的传感器列表
|
|
|
+func Read_CompanyDeviceSensor_List_For_Data(admin *Account.Admin, T_pids []int, T_name string, T_Class_id, T_type, T_RealTime, T_MapShow int, page int, page_z int) (DeviceSensor_r []DeviceSensor_Company, cnt int64) {
|
|
|
+
|
|
|
+ o := orm.NewOrm()
|
|
|
+ // 也可以直接使用 Model 结构体作为表名
|
|
|
+
|
|
|
+ qs := o.QueryTable(new(DeviceSensor))
|
|
|
+ var offset int
|
|
|
+ if page <= 1 {
|
|
|
+ offset = 0
|
|
|
+ } else {
|
|
|
+ offset = (page - 1) * page_z
|
|
|
+ }
|
|
|
+
|
|
|
+ var r []DeviceSensor
|
|
|
+ cond := orm.NewCondition()
|
|
|
+ cond1 := cond.And("T_pid__in", T_pids)
|
|
|
+
|
|
|
+ if T_Class_id > 0 {
|
|
|
+ T_Class := "C" + strconv.Itoa(T_Class_id) + "|"
|
|
|
+ fmt.Println("T_Class:", T_Class)
|
|
|
+ cond1 = cond1.And("T_Class__icontains", T_Class)
|
|
|
+ }
|
|
|
+
|
|
|
+ if T_type > 0 {
|
|
|
+ cond1 = cond1.And("T_type", T_type)
|
|
|
+ }
|
|
|
+
|
|
|
+ if admin.T_pid > 0 {
|
|
|
+ if len(T_name) >= 16 {
|
|
|
+ cond1 = cond1.And("T_sn", T_name)
|
|
|
+ } else if len(T_name) > 0 && len(T_name) < 16 {
|
|
|
+ cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_State", 1).And("T_datashow", 1)
|
|
|
+ } else {
|
|
|
+ cond1 = cond1.And("T_State", 1).And("T_datashow", 1)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if len(T_name) >= 16 {
|
|
|
+ cond1 = cond1.And("T_sn", T_name)
|
|
|
+ } else if len(T_name) > 0 && len(T_name) < 16 {
|
|
|
+ cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_State", 1).And("T_datashow", 1)
|
|
|
+ } else {
|
|
|
+ cond1 = cond1.And("T_State", 1).And("T_datashow", 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if T_MapShow == 1 {
|
|
|
+ cond1 = cond1.AndNot("T_Site", "")
|
|
|
+ }
|
|
|
+ cnt, err := qs.SetCond((*orm2.Condition)(cond1)).Count()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 实时数据页面,温度或者湿度不在正常区间,排在最前面
|
|
|
+ if T_RealTime == 1 {
|
|
|
+ offset_z := offset + page_z
|
|
|
+ if cnt < int64(offset_z) {
|
|
|
+ offset_z = int(cnt)
|
|
|
+ }
|
|
|
+ if offset > offset_z {
|
|
|
+ offset = offset_z
|
|
|
+ }
|
|
|
+ _, err = qs.SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var DeviceSensor_unusual []DeviceSensor_Company
|
|
|
+ for _, v := range r {
|
|
|
+ v_r := DeviceSensorToDeviceSensor_Company(v)
|
|
|
+ data := v_r.T_DeviceSensorData
|
|
|
+ // 温度或者湿度不在正常区间,排在最前面
|
|
|
+ if data.T_t > data.T_tu || data.T_t < data.T_tl || data.T_rh > data.T_rhu || data.T_rh < data.T_rhl {
|
|
|
+ DeviceSensor_unusual = append(DeviceSensor_unusual, v_r)
|
|
|
+ } else {
|
|
|
+ DeviceSensor_r = append(DeviceSensor_r, v_r)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DeviceSensor_unusual = append(DeviceSensor_unusual, DeviceSensor_r...)
|
|
|
+ return DeviceSensor_unusual[offset:offset_z], cnt
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("T_sort", "T_id").All(&r)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(lib.FuncName(), err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range r {
|
|
|
+ DeviceSensor_r = append(DeviceSensor_r, DeviceSensorToDeviceSensor_Company(v))
|
|
|
+ }
|
|
|
+ return DeviceSensor_r, cnt
|
|
|
+}
|
|
|
+
|
|
|
// 获取列表
|
|
|
-func Read_DeviceSensor_T_type(T_pid int) (lists orm2.ParamsList, err error) {
|
|
|
+func Read_DeviceSensor_T_type(T_pid int, bindSN []string) (lists orm2.ParamsList, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
var pl_lists orm2.ParamsList
|
|
|
- _, err = o.Raw("SELECT DISTINCT t_type FROM device_sensor WHERE t_pid=? AND t_datashow=1 AND t__state=1 LIMIT 0,1000", T_pid).ValuesFlat(&pl_lists)
|
|
|
+ sql := "SELECT DISTINCT t_type FROM device_sensor WHERE t_pid=? AND t_datashow=1 AND t__state=1"
|
|
|
+ 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)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|
|
|
return
|
|
@@ -943,7 +1148,7 @@ func Read_DeviceSensor_T_type(T_pid int) (lists orm2.ParamsList, err error) {
|
|
|
}
|
|
|
|
|
|
// 数据展示菜单下 传感器参数列表
|
|
|
-func Read_DeviceSensor_List_For_Applet(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_name, T_online string, T_RealTime, T_type, page, page_z int) (DeviceSensor_r []DeviceSensor_Applet, cnt int64) {
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
// 也可以直接使用 Model 结构体作为表名
|
|
@@ -959,18 +1164,32 @@ func Read_DeviceSensor_List_For_Applet(T_pid int, T_name, T_online string, T_Rea
|
|
|
|
|
|
var r []DeviceSensor
|
|
|
cond := orm.NewCondition()
|
|
|
- cond1 := cond.And("T_pid", T_pid).And("T_State", 1)
|
|
|
+ cond1 := cond.And("T_pid", T_pid)
|
|
|
|
|
|
if T_type > 0 {
|
|
|
cond1 = cond1.And("T_type", T_type)
|
|
|
}
|
|
|
|
|
|
- if len(T_name) == 16 {
|
|
|
- cond1 = cond1.And("T_sn", T_name)
|
|
|
- } else if len(T_name) > 0 {
|
|
|
- cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_datashow", 1)
|
|
|
+ if len(bindSN) > 0 {
|
|
|
+ cond1 = cond1.And("T_sn__in", bindSN)
|
|
|
+ }
|
|
|
+
|
|
|
+ if admin.T_pid > 0 {
|
|
|
+ if len(T_name) >= 16 {
|
|
|
+ cond1 = cond1.And("T_sn", T_name)
|
|
|
+ } else if len(T_name) > 0 && len(T_name) < 16 {
|
|
|
+ cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_State", 1).And("T_datashow", 1)
|
|
|
+ } else {
|
|
|
+ cond1 = cond1.And("T_State", 1).And("T_datashow", 1)
|
|
|
+ }
|
|
|
} else {
|
|
|
- cond1 = cond1.And("T_datashow", 1)
|
|
|
+ if len(T_name) >= 16 {
|
|
|
+ cond1 = cond1.And("T_sn", T_name)
|
|
|
+ } else if len(T_name) > 0 && len(T_name) < 16 {
|
|
|
+ cond1 = cond1.AndCond(cond.Or("T_name__icontains", T_name).Or("T_sn__icontains", T_name)).And("T_State", 1).And("T_datashow", 1)
|
|
|
+ } else {
|
|
|
+ cond1 = cond1.And("T_State", 1).And("T_datashow", 1)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 0 未监控 1 监控中 2 无网络 3 全部
|
|
@@ -1008,12 +1227,16 @@ func Read_DeviceSensor_List_For_Applet(T_pid int, T_name, T_online string, T_Rea
|
|
|
}
|
|
|
|
|
|
// 小程序-传感器类型
|
|
|
-func Read_DeviceSensor_T_sn_ByT_type(T_pid, T_type int) (lists []string, err error) {
|
|
|
+func Read_DeviceSensor_T_sn_ByT_type(T_pid int, bindSN []string, 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)
|
|
|
|
|
|
+ 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)
|
|
|
if err != nil {
|
|
|
logs.Error(lib.FuncName(), err)
|