|
|
@@ -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)
|