Browse Source

2023-08-04 小程序统计列表

zoie 1 year ago
parent
commit
373fdc5970
5 changed files with 38 additions and 25 deletions
  1. 3 3
      Nats/Nats.go
  2. 6 0
      controllers/Device.go
  3. 2 3
      controllers/DeviceReal.go
  4. 18 10
      models/Device/Device.go
  5. 9 9
      models/Device/DeviceSensor.go

+ 3 - 3
Nats/Nats.go

@@ -48,7 +48,7 @@ func NatsInit() {
 
 	// 获取微信二维码 返回结果
 	_, _ = lib.Nats.Subscribe("Wx_BasicMessage_Event_QRCode", func(m *nats.Msg) {
-		fmt.Printf(" => Nats   Wx_BasicMessage_Event_QRCode message: %s\n", string(m.Data))
+		//fmt.Printf(" => Nats   Wx_BasicMessage_Event_QRCode message: %s\n", string(m.Data))
 
 		type Person_QRCode struct {
 			ToUserName   string `xml:"ToUserName"`   //注意这里有个反引号
@@ -64,8 +64,8 @@ func NatsInit() {
 			return
 		}
 		// 进入 二维码配对
-		fmt.Println("FromUserName-", person_QRCode.FromUserName)
-		fmt.Println("EventKey-", person_QRCode.EventKey)
+		//fmt.Println("FromUserName-", person_QRCode.FromUserName)
+		//fmt.Println("EventKey-", person_QRCode.EventKey)
 
 		// 开始  处理消息
 		if strings.Contains(person_QRCode.EventKey, "@宝智达冷链 微信公众号通知") {

+ 6 - 0
controllers/Device.go

@@ -1859,6 +1859,12 @@ func (c *DeviceController) Device_Applet_Stat() {
 	var r_jsons R_JSONS
 
 	r_jsons.Data.T_type = T_type
+	if len(snList) == 0 {
+		c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
+		c.ServeJSON()
+		return
+	}
+
 	// 0 未启用  1 在线  2 离线
 	r_jsons.Data.Count = Device.Read_Device_Count_ByT_online(c.T_pid, snList, "")
 	r_jsons.Data.Online = Device.Read_Device_Count_ByT_online(c.T_pid, snList, "1")

+ 2 - 3
controllers/DeviceReal.go

@@ -60,8 +60,7 @@ func DeviceRealTime() {
 	time.Sleep(time.Second * 3)
 	for true {
 		// 如果能拿到key,10s等待时间还没结束,则不继续往下执行
-		if Device.Redis_DeviceRealWait_IsExist("DeviceRealWait10Second"+conf.MqttServer_id) {
-			fmt.Println("-----------------------",time.Now())
+		if Device.Redis_DeviceRealWait_IsExist("DeviceRealWait10Second" + conf.MqttServer_id) {
 			time.Sleep(time.Second * 1)
 			continue
 		}
@@ -115,7 +114,7 @@ func DeviceRealTime() {
 		//	return true
 		//})
 
-		Device.Redis_DeviceRealWait_Set("DeviceRealWait10Second"+conf.MqttServer_id)
+		Device.Redis_DeviceRealWait_Set("DeviceRealWait10Second" + conf.MqttServer_id)
 		time.Sleep(time.Second * 10)
 	}
 }

+ 18 - 10
models/Device/Device.go

@@ -349,32 +349,40 @@ func Read_Device_List_ByT_model(T_model string) (r []Device) {
 }
 
 // 数据展示菜单下 传感器参数列表
-func Read_Device_Count_ByT_online(T_pid int, snList []interface{}, T_online string) (cnt int64) {
+func Read_Device_Count_ByT_online(T_pid int, snList []string, T_online string) (cnt int64) {
 
-	o := orm.NewOrm()
+	o := orm2.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 
 	qs := o.QueryTable(new(Device))
 
-	cond := orm.NewCondition()
+	cond := orm2.NewCondition()
 	cond1 := cond.And("T_pid", T_pid).And("T_State", 1)
 
 	if len(snList) > 0 {
 		cond1 = cond1.And("T_sn__in", snList)
-
 	}
 
-	//0 未启用  1 在线  2 离线
+	// T_online 0 未启用  1 在线  2 离线
+	//if T_online == "1" {
+	//	cond1 = cond1.AndCond(cond.Or("T_online", 1).Or("T_online_s", 1))
+	//} else if T_online == "2" {
+	//	cond1 = cond1.AndCond(cond.And("T_online", 2).And("T_online_s", 0)).
+	//		OrCond(cond.And("T_online", 0).And("T_online_s", 2))
+	//} else if T_online == "0" {
+	//	cond1 = cond1.And("T_online", 0).And("T_online_s", 0)
+	//}
+
 	if T_online == "1" {
-		cond1 = cond1.AndCond(cond.Or("T_online", 1).Or("T_online_s", 1))
+		cond1 = cond1.And("T_monitor", 1)
 	} else if T_online == "2" {
-		cond1 = cond1.AndCond(cond.AndCond(cond.And("T_online", 2).And("T_online_s", 0)).
-			OrCond(cond.And("T_online", 0).And("T_online_s", 2)))
+		cond1 = cond1.AndCond(cond.AndCond(cond.AndNot("T_online", 1)).
+			AndCond(cond.AndNot("T_online_s", 1)))
 	} else if T_online == "0" {
-		cond1 = cond1.And("T_online", 0).And("T_online_s", 0)
+		cond1 = cond1.And("T_monitor", 0)
 	}
 
-	cnt, err := qs.SetCond((*orm2.Condition)(cond1)).Count()
+	cnt, err := qs.SetCond(cond1).Count()
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
 		return

+ 9 - 9
models/Device/DeviceSensor.go

@@ -933,7 +933,7 @@ func Read_DeviceSensor_List_For_Data(T_pid int, T_name string, T_Class_id, T_typ
 func Read_DeviceSensor_T_type(T_pid int) (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 LIMIT 0,1000", T_pid).ValuesFlat(&pl_lists)
+	_, 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)
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
 		return
@@ -973,13 +973,14 @@ func Read_DeviceSensor_List_For_Applet(T_pid int, T_name, T_online string, T_Rea
 		cond1 = cond1.And("T_datashow", 1)
 	}
 
+	// 0 未监控 1 监控中 2 无网络 3 全部
 	if T_online == "1" {
-		cond1 = cond1.AndCond(cond.Or("T_online", 1).Or("T_online_s", 1))
+		cond1 = cond1.And("T_monitor", 1)
 	} else if T_online == "2" {
-		cond1 = cond1.AndCond(cond.AndCond(cond.And("T_online", 2).And("T_online_s", 0)).
-			OrCond(cond.And("T_online", 0).And("T_online_s", 2)))
+		cond1 = cond1.AndCond(cond.AndCond(cond.AndNot("T_online", 1)).
+			AndCond(cond.AndNot("T_online_s", 1)))
 	} else if T_online == "0" {
-		cond1 = cond1.And("T_online", 0).And("T_online_s", 0)
+		cond1 = cond1.And("T_monitor", 0)
 	}
 
 	var err error
@@ -1007,20 +1008,19 @@ 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 orm2.ParamsList, err error) {
+func Read_DeviceSensor_T_sn_ByT_type(T_pid, 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)
 
-	var pl_lists orm2.ParamsList
-	_, err = o.Raw("SELECT DISTINCT T_sn FROM device_sensor WHERE "+sql+" LIMIT 0,1000", T_pid).ValuesFlat(&pl_lists)
+	_, 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)
 		return
 	}
 
-	return pl_lists, nil
+	return lists, nil
 }
 
 func Read_DeviceSensorCount_ByT_pids(T_pids []int) (cnt int64) {