Sfoglia il codice sorgente

FUNC:新增nats 通过公司key获取传感器信息

zoie 11 mesi fa
parent
commit
6379092d2b

+ 48 - 0
Nats/Nats.go

@@ -410,4 +410,52 @@ func NatsInit() {
 		_ = lib.Nats.Publish(m.Reply, b)
 		_ = lib.Nats.Publish(m.Reply, b)
 	})
 	})
 
 
+	// 请求-响应 通过key获取传感器列表
+	_, _ = lib.Nats.Subscribe("Cold_CompanyDeviceSensor_List_ByKey", func(m *nats.Msg) {
+		fmt.Printf("Cold_CompanyDeviceSensor_List_ByKey message: %s\n", string(m.Data))
+		type T_Req struct {
+			T_sn  string `xml:"T_sn"`
+			T_key string `xml:"T_key"`
+		}
+		type T_R struct {
+			Code  int16                   `xml:"Code"`
+			Msg   string                  `xml:"Msg"`
+			Count int64                   `xml:"Count"`
+			Data  []Device.DeviceSensor_R `xml:"Data"` // 泛型
+		}
+		var t_Req T_Req
+		var t_R T_R
+
+		err := msgpack.Unmarshal(m.Data, &t_Req)
+		if err != nil {
+			t_R.Code = 202
+			t_R.Msg = "Unmarshal error"
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+
+		// 查询公司
+		Company_r, err := Account.Read_Company_ByKey(t_Req.T_key)
+		if err != nil {
+			t_R.Code = 202
+			t_R.Msg = "T_key error"
+			b, _ := msgpack.Marshal(&t_R)
+			_ = lib.Nats.Publish(m.Reply, b)
+			return
+		}
+		// 查询公司下面所有子公司id
+		T_pids := Account.ReadCompanyIds_T_path(Company_r.T_path)
+		Account.Read_Company_All_Maps()
+
+		deviceData, cnt := Device.Read_CompanyDeviceSensor_List_For_Data_ByKey(T_pids, t_Req.T_sn)
+
+		t_R.Code = 200
+		t_R.Msg = "ok"
+		t_R.Count = cnt
+		t_R.Data = deviceData
+
+		b, _ := msgpack.Marshal(&t_R)
+		_ = lib.Nats.Publish(m.Reply, b)
+	})
 }
 }

+ 0 - 1
Nats/NatsServer/NatsWorkOrder.go

@@ -28,5 +28,4 @@ func Read_WorkOrderT_State_Count(T_pids string) (int64, int64) {
 	}
 	}
 
 
 	return t_R.TodayWorkOrderNum, t_R.UntreatedWorkOrderNum
 	return t_R.TodayWorkOrderNum, t_R.UntreatedWorkOrderNum
-
 }
 }

+ 2 - 1
controllers/Data.go

@@ -183,6 +183,7 @@ func (c *DataController) Company_Device_Sensor_List() {
 func (c *DataController) Company_Device_Sensor_List_ByKey() {
 func (c *DataController) Company_Device_Sensor_List_ByKey() {
 	var r_jsons lib.R_JSONS
 	var r_jsons lib.R_JSONS
 	key := c.GetString("key")
 	key := c.GetString("key")
+	T_sn := c.GetString("T_sn")
 	// 查询公司
 	// 查询公司
 	Company_r, err := Account.Read_Company_ByKey(key)
 	Company_r, err := Account.Read_Company_ByKey(key)
 	if err != nil {
 	if err != nil {
@@ -193,7 +194,7 @@ func (c *DataController) Company_Device_Sensor_List_ByKey() {
 	// 查询公司下面所有子公司id
 	// 查询公司下面所有子公司id
 	T_pids := Account.ReadCompanyIds_T_path(Company_r.T_path)
 	T_pids := Account.ReadCompanyIds_T_path(Company_r.T_path)
 	Account.Read_Company_All_Maps()
 	Account.Read_Company_All_Maps()
-	r_jsons.Data, r_jsons.Num = Device.Read_CompanyDeviceSensor_List_For_Data_ByKey(T_pids)
+	r_jsons.Data, r_jsons.Num = Device.Read_CompanyDeviceSensor_List_For_Data_ByKey(T_pids, T_sn)
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
 	c.ServeJSON()
 	c.ServeJSON()
 	return
 	return

+ 4 - 4
go.mod

@@ -5,11 +5,15 @@ go 1.19
 require (
 require (
 	github.com/astaxie/beego v1.12.3
 	github.com/astaxie/beego v1.12.3
 	github.com/beego/beego/v2 v2.0.7
 	github.com/beego/beego/v2 v2.0.7
+	github.com/go-resty/resty/v2 v2.7.0
 	github.com/go-sql-driver/mysql v1.7.0
 	github.com/go-sql-driver/mysql v1.7.0
+	github.com/gomodule/redigo v2.0.0+incompatible
 	github.com/mssola/user_agent v0.6.0
 	github.com/mssola/user_agent v0.6.0
 	github.com/nats-io/nats.go v1.22.1
 	github.com/nats-io/nats.go v1.22.1
 	github.com/qiniu/go-sdk/v7 v7.14.0
 	github.com/qiniu/go-sdk/v7 v7.14.0
+	github.com/robfig/cron/v3 v3.0.1
 	github.com/satori/go.uuid v1.2.0
 	github.com/satori/go.uuid v1.2.0
+	github.com/shopspring/decimal v1.3.1
 	github.com/signintech/gopdf v0.15.1
 	github.com/signintech/gopdf v0.15.1
 	github.com/vmihailenco/msgpack/v5 v5.3.5
 	github.com/vmihailenco/msgpack/v5 v5.3.5
 	github.com/xuri/excelize/v2 v2.7.0
 	github.com/xuri/excelize/v2 v2.7.0
@@ -18,9 +22,7 @@ require (
 require (
 require (
 	github.com/beorn7/perks v1.0.1 // indirect
 	github.com/beorn7/perks v1.0.1 // indirect
 	github.com/cespare/xxhash/v2 v2.1.2 // indirect
 	github.com/cespare/xxhash/v2 v2.1.2 // indirect
-	github.com/go-resty/resty/v2 v2.7.0 // indirect
 	github.com/golang/protobuf v1.5.2 // indirect
 	github.com/golang/protobuf v1.5.2 // indirect
-	github.com/gomodule/redigo v2.0.0+incompatible // indirect
 	github.com/hashicorp/golang-lru v0.5.4 // indirect
 	github.com/hashicorp/golang-lru v0.5.4 // indirect
 	github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
 	github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
 	github.com/mitchellh/mapstructure v1.5.0 // indirect
 	github.com/mitchellh/mapstructure v1.5.0 // indirect
@@ -36,9 +38,7 @@ require (
 	github.com/prometheus/procfs v0.8.0 // indirect
 	github.com/prometheus/procfs v0.8.0 // indirect
 	github.com/richardlehane/mscfb v1.0.4 // indirect
 	github.com/richardlehane/mscfb v1.0.4 // indirect
 	github.com/richardlehane/msoleps v1.0.3 // indirect
 	github.com/richardlehane/msoleps v1.0.3 // indirect
-	github.com/robfig/cron/v3 v3.0.1 // indirect
 	github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
 	github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
-	github.com/shopspring/decimal v1.3.1 // indirect
 	github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
 	github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
 	github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect
 	github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect
 	github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
 	github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect

+ 1 - 1
models/Account/Admin.go

@@ -21,7 +21,7 @@ type Admin struct {
 	Id      int    `orm:"column(ID);size(11);auto;pk"`
 	Id      int    `orm:"column(ID);size(11);auto;pk"`
 	T_uuid  string `orm:"size(256);null"`      // 用户编号
 	T_uuid  string `orm:"size(256);null"`      // 用户编号
 	T_pid   int    `orm:"size(200);null"`      // 绑定公司 ( 只有创建公司用户时添加,内部人员 为0)
 	T_pid   int    `orm:"size(200);null"`      // 绑定公司 ( 只有创建公司用户时添加,内部人员 为0)
-	T_pids  string `orm:"size(200);null"`      // 绑定公司管理 Pid| 如 P1|P2
+	T_pids  string `orm:"type(text);null"`     // 绑定公司管理 Pid| 如 P1|P2
 	T_power int    `orm:"size(20);default(0)"` // 权限 (关联权限表)
 	T_power int    `orm:"size(20);default(0)"` // 权限 (关联权限表)
 	T_user  string `orm:"size(256);null"`      // 用户名 (唯一)
 	T_user  string `orm:"size(256);null"`      // 用户名 (唯一)
 	T_pass  string `orm:"size(256);null"`      // MD5
 	T_pass  string `orm:"size(256);null"`      // MD5

+ 4 - 1
models/Device/DeviceSensor.go

@@ -1449,7 +1449,7 @@ func Read_CompanyDeviceSensor_List_For_Data1(T_pids []int, T_name string, T_Clas
 	return DeviceSensor_r, cnt
 	return DeviceSensor_r, cnt
 }
 }
 
 
-func Read_CompanyDeviceSensor_List_For_Data_ByKey(T_pids []int) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
+func Read_CompanyDeviceSensor_List_For_Data_ByKey(T_pids []int, T_sn string) (DeviceSensor_r []DeviceSensor_R, cnt int64) {
 
 
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
 	// 也可以直接使用 Model 结构体作为表名
@@ -1459,6 +1459,9 @@ func Read_CompanyDeviceSensor_List_For_Data_ByKey(T_pids []int) (DeviceSensor_r
 	var r []DeviceSensor
 	var r []DeviceSensor
 	cond := orm.NewCondition()
 	cond := orm.NewCondition()
 	cond1 := cond.And("T_pid__in", T_pids)
 	cond1 := cond.And("T_pid__in", T_pids)
+	if len(T_sn) > 0 {
+		cond1 = cond1.And("T_sn", T_sn)
+	}
 
 
 	cnt, err := qs.SetCond((*orm2.Condition)(cond1)).Count()
 	cnt, err := qs.SetCond((*orm2.Condition)(cond1)).Count()
 	if err != nil {
 	if err != nil {