瀏覽代碼

featrue(mcs_api): 增加压差、视频摄像头、门禁、远程控制设备支持

sunmiao 3 年之前
父節點
當前提交
888ed9b68d

+ 15 - 5
backend/src/dashoo.cn/mcs_api/business/device/channels.go

@@ -42,6 +42,14 @@ type Channels struct {
 	Longitude           float32   `xorm:"FLOAT" json:"-"`
 }
 
+type Channels_ExtendInfo struct {
+	Id          int    `xorm:"<- not null pk INT(50)"`
+	EquipMentId int    `xorm:"INT(11)"`
+	Title       string `xorm:"VARCHAR(255)" json:"title"`
+	Code        string `xorm:"VARCHAR(200)" json:"id"`
+	ExtendInfo  string `xorm:"VARCHAR(1000)" json:"extend"`
+}
+
 type DeviceChannels struct {
 	Id           int     `xorm:"<- not null pk INT(50)"`
 	EquipMentId  int     `xorm:"INT(10)"`
@@ -68,13 +76,15 @@ type DeviceChannels struct {
 	O2           string
 	Co2          string
 	WindSpeed    string
-	Pressure     string
-	Ots          string //压力
-	Displacement string //位移
-	Doorlock     string //智能锁
+	Pressure     string // 压力或压差
+	Ots          string // 压力
+	Displacement string // 位移
+	Doorlock     string // 智能锁 或 门禁(海康)
+	Camera       string // 视频摄像头
+	RControl     string // 远程控制开关
 	ClO2         string
 	C2H4         string
-	C2H2         string //乙炔
+	C2H2         string // 乙炔
 	Cl2          string
 	H2O          string
 	SO2          string

+ 3 - 2
backend/src/dashoo.cn/mcs_api/conf/app.conf

@@ -7,8 +7,9 @@ copyrequestbody = true
 EnableDocs = true
 
 [server]
-#apiurl=http://1.117.158.212:10015/v1
-apiurl=http://127.0.0.1:10015/v1
+apiurl=http://1.117.158.212:10015/v1
+#apiurl=http://127.0.0.1:10015/v1
+r_control_url = http://1.116.37.6:12001
 
 [db]
 type=mysql

+ 76 - 9
backend/src/dashoo.cn/mcs_api/controllers/channels.go

@@ -1,6 +1,7 @@
 package controllers
 
 import (
+	"encoding/base64"
 	"encoding/json"
 	"fmt"
 	"strconv"
@@ -9,11 +10,11 @@ import (
 
 	"dashoo.cn/base_common/labsop"
 	"dashoo.cn/base_common/utils"
-	"dashoo.cn/mcs_common/business/actions"
 	"dashoo.cn/mcs_api/business/device"
-	"dashoo.cn/mcs_common/business/equipment"
 	"dashoo.cn/mcs_api/business/trigger"
 	"dashoo.cn/mcs_api/business/triggerhistory"
+	"dashoo.cn/mcs_common/business/actions"
+	"dashoo.cn/mcs_common/business/equipment"
 )
 
 // 动作接口说明
@@ -35,7 +36,9 @@ type ChannelLast struct {
 	Pressure     string
 	Ots          string //压力
 	Displacement string //位移
-	Doorlock     string //智能锁
+	Doorlock     string // 智能锁 或 门禁(海康)
+	Camera       string // 视频摄像头
+	RControl     string // 远程控制开关
 	ClO2         string
 	C2H4         string
 	C2H2         string
@@ -178,7 +181,9 @@ func (this *ChannelsController) DataValue() {
 		data.O3 = utils.ToStr(lastdata.O3)
 		data.TVOC = utils.ToStr(lastdata.TVOC)
 		data.H2O = utils.ToStr(lastdata.H2O)
-		data.Doorlock = utils.ToStr(lastdata.Doorlock) //智能锁
+		data.Doorlock = utils.ToStr(lastdata.Doorlock)  //智能锁 或 门禁(海康)
+		data.Camera = utils.ToStr(lastdata.RequestData) // 视频摄像头
+		data.RControl = utils.ToStr(lastdata.Doorlock)  // 远程控制开关
 		data.SO2 = utils.ToStr(lastdata.SO2)
 		data.Power = utils.ToStr(lastdata.ElectricalPower)
 		data.Supply = utils.ToStr(lastdata.ElectricalSupply)
@@ -221,6 +226,29 @@ func (this *ChannelsController) ValidCode() {
 	this.ServeJSON()
 }
 
+// @Title 获取传感器扩展信息
+// @Description 获取传感器扩展信息
+// @Param	code		path 	string	true		"设备SN"
+// @Success 200 {object} ErrorInfo
+// @Failure 403 :code 为空
+// @router /extendinfo/:code [get]
+func (this *ChannelsController) GetExtendInfo() {
+	code := this.Ctx.Input.Param(":code")
+	var entity device.Channels_ExtendInfo
+	strUrl := utils.Cfg.MustValue("server", "apiurl") + "/channels/serial?serial=" + code
+	json.Unmarshal(Apiget(strUrl), &entity)
+	extend := entity.ExtendInfo
+	if extend != "" {
+		extend = base64.RawStdEncoding.EncodeToString([]byte(extend)) //编码两遍
+		extend = base64.RawStdEncoding.EncodeToString([]byte(extend))
+	}
+	var errinfo ErrorInfo
+	errinfo.Message = extend
+	errinfo.Code = 0
+	this.Data["json"] = &errinfo
+	this.ServeJSON()
+}
+
 // @Title 创建传感器
 // @Description 创建传感器
 // @Param	body	body	business.device.DeviceChannels	"传感器信息"
@@ -341,6 +369,45 @@ func (this *ChannelsController) AddChannel() {
 			//				}
 
 			//			}
+
+			// 反向控制设备开关 传感器 添加 开 关 动作
+			if utils.ToStr(channel.DataItem) == ChannelItem_RControl {
+				var action actions.Actions
+				action.AItem = 9
+				action.AName = channel.Serial + "(开)"
+				strUrl := fmt.Sprintf(utils.Cfg.MustValue("server", "r_control_url")+"/api/socket/switch?device=%s&switch=%s", channel.Serial, "1")
+				action.SPara2 = strUrl //利用网址推送实现控制
+				action.Enabled = 1
+				var status Status
+				strUrl = utils.Cfg.MustValue("server", "apiurl") + "/actions/?u=" + u + "&p=" + p
+				json.Unmarshal(Apipost(strUrl, "POST", action), &status)
+				if status.Status == 0 {
+					action.AccCode = this.GetAccode()
+					action.Wdid = status.Id
+					action.Id, _ = utils.StrTo(status.Id).Int()
+					action.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+					action.CreateBy = this.User.Realname
+					svc.InsertEntity(&action) //插入数据库
+				}
+
+				var action2 actions.Actions
+				action2.AItem = 9
+				action2.AName = channel.Serial + "(关)"
+				strUrl = fmt.Sprintf(utils.Cfg.MustValue("server", "r_control_url")+"/api/socket/switch?device=%s&switch=%s", channel.Serial, "0")
+				action2.SPara2 = strUrl //利用网址推送实现控制
+				strUrl = utils.Cfg.MustValue("server", "apiurl") + "/actions/?u=" + u + "&p=" + p
+
+				json.Unmarshal(Apipost(strUrl, "POST", action2), &status)
+				if status.Status == 0 {
+					action2.AccCode = this.GetAccode()
+					action2.Wdid = status.Id
+					action2.Id, _ = utils.StrTo(status.Id).Int()
+					action2.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+					action2.CreateBy = this.User.Realname
+					svc.InsertEntity(&action2) //插入数据库
+				}
+			}
+
 			errinfo.Message = "保存成功!"
 			errinfo.Code = 0
 			this.Data["json"] = &errinfo
@@ -1010,7 +1077,7 @@ func (this *ChannelsController) ChannelManageview(client labsop.LabSopClient, co
 				arrvs = append(arrvs, arr)
 			}
 		}
-	case "28": //水质 单独
+	case "28": //二氧化硫
 		queryGroupCommand = fmt.Sprintf("select max(so2),min(so2),MEAN(so2) from %v where time > %vs and time < %vs", code, start, end)
 		if level == "0" {
 			queryCommand = fmt.Sprintf("select so2 from %v where time > %vs and time < %vs", code, start, end)
@@ -1029,15 +1096,15 @@ func (this *ChannelsController) ChannelManageview(client labsop.LabSopClient, co
 			}
 		}
 	case "29": //压力
-		queryGroupCommand = fmt.Sprintf("select max(ots),min(ots),MEAN(ots) from %v where time > %vs and time < %vs", code, start, end)
+		queryGroupCommand = fmt.Sprintf("select max(pressure),min(pressure),MEAN(pressure) from %v where time > %vs and time < %vs", code, start, end)
 		if level == "0" {
 			queryCommand = fmt.Sprintf("select ots from %v where time > %vs and time < %vs", code, start, end)
 		} else {
-			queryCommand = fmt.Sprintf("select MEDIAN(ots) as ots from %v where time > %vs and time < %vs group by time(%v) fill(none)", code, start, end, level)
+			queryCommand = fmt.Sprintf("select MEDIAN(pressure) as pressure from %v where time > %vs and time < %vs group by time(%v) fill(none)", code, start, end, level)
 		}
 		for i := 0; i < len(waringhistory.Items); i++ {
 			var arr []float64
-			if waringhistory.Items[i].EventFiled == "ots" {
+			if waringhistory.Items[i].EventFiled == "pressure" {
 				arr = append(arr, float64(waringhistory.Items[i].AlarmOn.Unix()*1000))
 				arr = append(arr, -9999)
 				arr = append(arr, -9999)
@@ -1064,7 +1131,7 @@ func (this *ChannelsController) ChannelManageview(client labsop.LabSopClient, co
 				arrvs = append(arrvs, arr)
 			}
 		}
-	case "31", "33": //智能锁 人脸识别锁
+	case "31", "33", "35", "36": //智能锁 人脸识别锁 35:门禁一体机,36:仪器控制终端
 		queryGroupCommand = fmt.Sprintf("select max(doorlock),min(doorlock),MEAN(doorlock) from %v where time > %vs and time < %vs", code, start, end)
 		if level == "0" {
 			queryCommand = fmt.Sprintf("select doorlock from %v where time > %vs and time < %vs", code, start, end)

+ 9 - 6
backend/src/dashoo.cn/mcs_api/controllers/common.go

@@ -210,10 +210,11 @@ func CoderGBKtoUTF8(str string) string {
 
 //设备类型汇总
 const (
-	Device_Box         = "0"                                                                         //设备,普通box
-	Device_Alertor     = "4"                                                                         //设备,报警器
-	ChannelItem_Sensor = "0,6,7,9,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33" //sensor 0:常温,6:深低温,7:o2,9:co2,10:特殊(隐藏湿度的常温),13:功率,14:外接设备1,15:外接液位设备,16:常温带定位,
-	//	17:氧气设备,18:风速,19:气压,20:二氧化氯,21:乙烯,22:氯气,23:臭氧,24:TVOC,25:乙炔,26:纯二氧化碳,27:电导率,28:二氧化硫,29:压力,30:位移,31:智能锁,32:基点5传感器,33:人脸识别锁
+	Device_Box         = "0"                                                                                  //设备,普通box
+	Device_Alertor     = "4"                                                                                  //设备,报警器
+	ChannelItem_Sensor = "0,6,7,9,10,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36" //sensor 0:常温,6:深低温,7:o2,9:co2,10:特殊(隐藏湿度的常温),13:功率,14:外接设备1,15:外接液位设备,16:常温带定位,
+	// 17:氧气设备,18:风速,19:气压,20:二氧化氯,21:乙烯,22:氯气,23:臭氧,24:TVOC,25:乙炔,26:纯二氧化碳,27:电导率,28:二氧化硫,29:微压差(压力),30:位移,31:扫码智能锁,32:基点5传感器,33:人脸识别锁
+	// 34:视频摄像头,35:门禁一体机,36:仪器控制终端
 	ChannelItem_Report          = "0,6,7,9,10,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,32" //sensor报表使用,不需要功率,常温,深低温,o2,co2,特殊(隐藏湿度的常温),外接设备1,外接液位设备,常温带定位,氧气设备
 	ChannelItem_Box             = "1"                                                                //sensor,box自身数据
 	ChannelItem_TAndH           = "0,14,16"                                                          //sensor,常温,显示温湿度
@@ -230,9 +231,9 @@ const (
 	ChannelItem_HaveLiquidLevel = "15"                                                               //含液位数据
 	ChannelItem_WindSpeed       = "18"                                                               //风速
 	ChannelItem_Pressure        = "19"                                                               //气压
-	ChannelItem_Ots             = "29"                                                               //压力大港
+	ChannelItem_MicroPressure   = "29"                                                               //微压差(压力)
 	ChannelItem_Displacement    = "30"                                                               //位移大港
-	ChannelItem_Doorlock        = "31,33"                                                            //智能锁
+	ChannelItem_Doorlock        = "31,33,35"                                                         //智能锁 门锁 或者 门禁(海康)
 	ChannelItem_ClO2            = "20"                                                               //二氧化氯
 	ChannelItem_C2H4            = "21"                                                               //乙烯
 	ChannelItem_Cl2             = "22"                                                               //氯气
@@ -241,6 +242,8 @@ const (
 	ChannelItem_C2H2            = "25"                                                               //乙炔
 	ChannelItem_H2O             = "27"                                                               //水质
 	ChannelItem_SO2             = "28"                                                               //二氧化硫
+	ChannelItem_Camera          = "34"                                                               //视频监控摄像头
+	ChannelItem_RControl        = "36"                                                               // 反向控制设备开关
 	Alertor_Alarm               = "2,4,5,8,12"                                                       //报警器,普通,纯报警,纯正常,android,条屏
 	Alertor_AlarmBindData       = "3"                                                                //报警器,绑定数据
 	Alertor_Alarm1              = "2"                                                                //报警器,普通

+ 41 - 4
backend/src/dashoo.cn/mcs_api/controllers/equipment.go

@@ -5,6 +5,8 @@ import (
 	"fmt"
 	"strings"
 
+	"dashoo.cn/mcs_common/business/actions"
+
 	"dashoo.cn/base_common/business/items"
 	"dashoo.cn/base_common/labsop"
 	"dashoo.cn/base_common/utils"
@@ -374,6 +376,45 @@ func (this *EquipmentController) SaveData() {
 				// 反写绑定状态
 				strUrl = utils.Cfg.MustValue("server", "apiurl") + "/channels/sourse/" + deviceentity.Code + "?u=" + u + "&p=" + p + "&sourse=coldchain&account=" + this.GetAccode() + "&accountname=" + this.User.Realname
 				Apipost(strUrl, "PUT", channelentity)
+
+				// 反向控制设备开关 传感器 添加 开 关 动作
+				if utils.ToStr(channelentity.DataItem) == ChannelItem_RControl {
+					var action actions.Actions
+					action.AItem = 9
+					action.AName = channelentity.Serial + "(开)"
+					strUrl := fmt.Sprintf(utils.Cfg.MustValue("server", "r_control_url")+"/api/socket/switch?device=%s&switch=%s", channelentity.Serial, "1")
+					action.SPara2 = strUrl //利用网址推送实现控制
+					action.Enabled = 1
+					var status Status
+					strUrl = utils.Cfg.MustValue("server", "apiurl") + "/actions/?u=" + u + "&p=" + p
+					json.Unmarshal(Apipost(strUrl, "POST", action), &status)
+					if status.Status == 0 {
+						action.AccCode = this.GetAccode()
+						action.Wdid = status.Id
+						action.Id, _ = utils.StrTo(status.Id).Int()
+						action.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+						action.CreateBy = this.User.Realname
+						svc.InsertEntity(&action) //插入数据库
+					}
+
+					var action2 actions.Actions
+					action2.AItem = 9
+					action2.AName = channelentity.Serial + "(关)"
+					strUrl = fmt.Sprintf(utils.Cfg.MustValue("server", "r_control_url")+"/api/socket/switch?device=%s&switch=%s", channelentity.Serial, "0")
+					action2.SPara2 = strUrl //利用网址推送实现控制
+					strUrl = utils.Cfg.MustValue("server", "apiurl") + "/actions/?u=" + u + "&p=" + p
+
+					json.Unmarshal(Apipost(strUrl, "POST", action2), &status)
+					if status.Status == 0 {
+						action2.AccCode = this.GetAccode()
+						action2.Wdid = status.Id
+						action2.Id, _ = utils.StrTo(status.Id).Int()
+						action2.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+						action2.CreateBy = this.User.Realname
+						svc.InsertEntity(&action2) //插入数据库
+					}
+				}
+
 				errinfo.Message = "保存成功!"
 				errinfo.Code = 0
 				this.Data["json"] = &errinfo
@@ -395,7 +436,6 @@ func (this *EquipmentController) SaveData() {
 			return
 		}
 	}
-
 }
 
 // @Title 创建用户
@@ -474,7 +514,6 @@ func (this *EquipmentController) EditData() {
 		this.Data["json"] = &errinfo
 		this.ServeJSON()
 	}
-
 }
 
 // @Title 设备排序
@@ -513,7 +552,6 @@ func (this *EquipmentController) SaveSort() {
 		this.Data["json"] = &errinfo
 		this.ServeJSON()
 	}
-
 }
 
 // @Title 创建用户
@@ -741,7 +779,6 @@ func (this *EquipmentController) BatchSetState() {
 			strUrl := utils.Cfg.MustValue("server", "apiurl") + "/triggers/enabled?code=c" + v + "&enabled=" + enabled + "&u=" + u + "&p=" + p
 			json.Unmarshal(Apipost(strUrl, "PUT", nil), &status)
 		}
-
 	}
 	errinfo.Message = "批量设置操作成功!"
 	errinfo.Code = 0

+ 9 - 3
backend/src/dashoo.cn/mcs_api/controllers/reports.go

@@ -220,10 +220,10 @@ func GetReportData(name string, dataitem int, showcols []string, data []labsop.D
 		dataliquidlevel = append(dataliquidlevel, "液位(mm)")
 	}
 	if DeviceItemContainint(ChannelItem_TVOC, dataitem) {
-		datatvoc = append(datatvoc, "TVOC(PPM)")
+		datatvoc = append(datatvoc, "TVOC(ppb)")
 	}
-	if DeviceItemContainint(ChannelItem_Doorlock, dataitem) {
-		datatvoc = append(dataots, "Pa")
+	if DeviceItemContainint(ChannelItem_MicroPressure, dataitem) {
+		datapressure = append(dataots, "微压差(Pa)")
 	}
 	for i, n := 0, len(data); i < 24; i++ {
 		if utils.SliceContains(showcols, utils.ToStr(i)) {
@@ -335,6 +335,9 @@ func GetReportData(name string, dataitem int, showcols []string, data []labsop.D
 			if DeviceItemContainint(ChannelItem_Pressure, dataitem) {
 				datapressure = append(datapressure, pressure)
 			}
+			if DeviceItemContainint(ChannelItem_MicroPressure, dataitem) {
+				datapressure = append(datapressure, pressure)
+			}
 			if DeviceItemContainint(ChannelItem_ClO2, dataitem) {
 				dataclo2 = append(dataclo2, clo2)
 			}
@@ -353,6 +356,9 @@ func GetReportData(name string, dataitem int, showcols []string, data []labsop.D
 			if DeviceItemContainint(ChannelItem_TVOC, dataitem) {
 				datatvoc = append(datatvoc, tvoc)
 			}
+			if DeviceItemContainint(ChannelItem_MicroPressure, dataitem) {
+				datapressure = append(datapressure, pressure)
+			}
 			if DeviceItemContainint(ChannelItem_Power, dataitem) {
 				datapower = append(datapower, power)
 				datasupply = append(datasupply, supply)

+ 1 - 1
backend/src/dashoo.cn/mcs_api/go.mod

@@ -16,7 +16,7 @@ require (
 	github.com/kr/pretty v0.2.1 // indirect
 	github.com/naoina/go-stringutil v0.1.0 // indirect
 	github.com/naoina/toml v0.1.1 // indirect
-	github.com/nsqio/go-nsq v1.0.8
+	github.com/nsqio/go-nsq v1.1.0
 	github.com/signintech/gopdf v0.9.15
 	github.com/smartystreets/goconvey v1.6.4
 	github.com/tealeg/xlsx v0.0.0

+ 2 - 0
backend/src/dashoo.cn/mcs_api/go.sum

@@ -199,6 +199,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
 github.com/nsqio/go-nsq v1.0.8 h1:3L2F8tNLlwXXlp2slDUrUWSBn2O3nMh8R1/KEDFTHPk=
 github.com/nsqio/go-nsq v1.0.8/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=
+github.com/nsqio/go-nsq v1.1.0 h1:PQg+xxiUjA7V+TLdXw7nVrJ5Jbl3sN86EhGCQj4+FYE=
+github.com/nsqio/go-nsq v1.1.0/go.mod h1:vKq36oyeVXgsS5Q8YEO7WghqidAVXQlcFxzQbQTuDEY=
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
 github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=