|
@@ -10,7 +10,7 @@ import (
|
|
|
"go.uber.org/zap"
|
|
|
"math/rand"
|
|
|
"regexp"
|
|
|
- "sync"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
@@ -76,8 +76,10 @@ func (h *IntelligentBuildingControlHandler) GetPoint(ctx *gin.Context) {
|
|
|
floor := ctx.PostForm("floor")
|
|
|
section := ctx.PostForm("section")
|
|
|
device_name := ctx.PostForm("deviceName")
|
|
|
+ pageNum, err := strconv.Atoi(ctx.PostForm("pageNum"))
|
|
|
+ pageSize, err := strconv.Atoi(ctx.PostForm("pageSize"))
|
|
|
conds := make(map[string]any)
|
|
|
- var pointType []model.PointType
|
|
|
+ //var pointType []model.PointType
|
|
|
if pointName != "" {
|
|
|
conds["point_name"] = pointName
|
|
|
}
|
|
@@ -97,55 +99,124 @@ func (h *IntelligentBuildingControlHandler) GetPoint(ctx *gin.Context) {
|
|
|
conds["device_name"] = device_name
|
|
|
}
|
|
|
|
|
|
- baseUrl := h.conf.GetString("obix.baseUrl")
|
|
|
- points, err := h.intelligentBuildingControlService.GetPoint(conds)
|
|
|
+ //baseUrl := h.conf.GetString("obix.baseUrl")
|
|
|
+ point, total, err := h.intelligentBuildingControlService.GetPoint(conds, pageNum, pageSize)
|
|
|
if err != nil {
|
|
|
resp.HandleError(ctx, 1201, "查询点位失败", nil)
|
|
|
return
|
|
|
}
|
|
|
+ //
|
|
|
+ //var wg sync.WaitGroup
|
|
|
+ //var mutex sync.Mutex // 保护切片并发写入
|
|
|
+ //m := make(map[string]string)
|
|
|
+ //sem := make(chan struct{}, 10) // 最大并发数为10
|
|
|
+ //
|
|
|
+ //for _, v := range *points {
|
|
|
+ // url := baseUrl + v.FullPath
|
|
|
+ // wg.Add(1)
|
|
|
+ // sem <- struct{}{}
|
|
|
+ // go func(url string, pointName string) {
|
|
|
+ // defer func() {
|
|
|
+ // <-sem
|
|
|
+ // wg.Done()
|
|
|
+ // }()
|
|
|
+ //
|
|
|
+ // request, err := obix.SendSecureRequest(url, h.conf.GetString("obix.username"), h.conf.GetString("obix.password"))
|
|
|
+ // if err != nil {
|
|
|
+ // h.logger.Error("发送请求失败", zap.Error(err))
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // re := regexp.MustCompile(`val="([^"]+)"`)
|
|
|
+ // matches := re.FindStringSubmatch(request)
|
|
|
+ //
|
|
|
+ // mutex.Lock()
|
|
|
+ // defer mutex.Unlock()
|
|
|
+ //
|
|
|
+ // if len(matches) > 1 {
|
|
|
+ // s := model.PointName[pointName]
|
|
|
+ // m[s] = matches[1]
|
|
|
+ // pointType = append(pointType, model.PointType{Type: m})
|
|
|
+ // } else {
|
|
|
+ // h.logger.Warn("未找到 val 值", zap.String("url", url))
|
|
|
+ // }
|
|
|
+ // }(url, v.PointName)
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //// 等待所有协程完成
|
|
|
+ //wg.Wait()
|
|
|
|
|
|
- var wg sync.WaitGroup
|
|
|
- var mutex sync.Mutex // 保护切片并发写入
|
|
|
- m := make(map[string]string)
|
|
|
- sem := make(chan struct{}, 10) // 最大并发数为10
|
|
|
+ // 统一返回结果
|
|
|
+ resp.PageHandleSuccess(ctx, point, total, pageNum, pageSize)
|
|
|
+}
|
|
|
|
|
|
+// GetGetPoint 获取点位设备数据
|
|
|
+func (h *IntelligentBuildingControlHandler) GetGetPoint(ctx *gin.Context) {
|
|
|
+ pointName := ctx.Query("pointName")
|
|
|
+ deviceType := ctx.Query("deviceType")
|
|
|
+ building := ctx.Query("building")
|
|
|
+ floor := ctx.Query("floor")
|
|
|
+ section := ctx.Query("section")
|
|
|
+ device_name := ctx.Query("deviceName")
|
|
|
+ conds := make(map[string]any)
|
|
|
+ if pointName != "" {
|
|
|
+ conds["point_name"] = pointName
|
|
|
+ }
|
|
|
+ if deviceType != "" {
|
|
|
+ conds["device_type"] = deviceType
|
|
|
+ }
|
|
|
+ if building != "" {
|
|
|
+ conds["building"] = building
|
|
|
+ }
|
|
|
+ if floor != "" {
|
|
|
+ conds["floor"] = floor
|
|
|
+ }
|
|
|
+ if section != "" {
|
|
|
+ conds["section"] = section
|
|
|
+ }
|
|
|
+ if device_name != "" {
|
|
|
+ conds["device_name"] = device_name
|
|
|
+ }
|
|
|
+ baseUrl := h.conf.GetString("obix.baseUrl")
|
|
|
+ m := make(map[string]any)
|
|
|
+ points, _, err := h.intelligentBuildingControlService.GetPoint(conds, 1, 100)
|
|
|
+ if err != nil {
|
|
|
+ resp.HandleError(ctx, 1201, "查询点位失败", nil)
|
|
|
+ }
|
|
|
for _, v := range *points {
|
|
|
url := baseUrl + v.FullPath
|
|
|
- wg.Add(1)
|
|
|
- sem <- struct{}{}
|
|
|
- go func(url string, pointName string) {
|
|
|
- defer func() {
|
|
|
- <-sem
|
|
|
- wg.Done()
|
|
|
- }()
|
|
|
-
|
|
|
- request, err := obix.SendSecureRequest(url, h.conf.GetString("obix.username"), h.conf.GetString("obix.password"))
|
|
|
- if err != nil {
|
|
|
- h.logger.Error("发送请求失败", zap.Error(err))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- re := regexp.MustCompile(`val="([^"]+)"`)
|
|
|
- matches := re.FindStringSubmatch(request)
|
|
|
-
|
|
|
- mutex.Lock()
|
|
|
- defer mutex.Unlock()
|
|
|
-
|
|
|
- if len(matches) > 1 {
|
|
|
- s := model.PointName[pointName]
|
|
|
- m[s] = matches[1]
|
|
|
- pointType = append(pointType, model.PointType{Type: m})
|
|
|
- } else {
|
|
|
- h.logger.Warn("未找到 val 值", zap.String("url", url))
|
|
|
+ request, err := obix.SendSecureRequest(url, h.conf.GetString("obix.username"), h.conf.GetString("obix.password"))
|
|
|
+ if err != nil {
|
|
|
+ h.logger.Error("发送请求失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ re := regexp.MustCompile(`val="([^"]+)"`)
|
|
|
+ matches := re.FindStringSubmatch(request)
|
|
|
+ if len(matches) > 1 {
|
|
|
+ s := model.PointName[v.PointName]
|
|
|
+ if s != "" {
|
|
|
+ value := matches[1]
|
|
|
+ switch val := obix.DetectType(value).(type) {
|
|
|
+ case int:
|
|
|
+ m[s] = val
|
|
|
+ case float64:
|
|
|
+ m[s] = fmt.Sprintf("%.2f", val) // 保留两位小数输出
|
|
|
+ case bool:
|
|
|
+ if val {
|
|
|
+ m[s] = "是"
|
|
|
+ } else {
|
|
|
+ m[s] = "否"
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ m[s] = value // 原样输出字符串
|
|
|
+ }
|
|
|
}
|
|
|
- }(url, v.PointName)
|
|
|
+ } else {
|
|
|
+ h.logger.Warn("未找到 val 值", zap.String("url", url))
|
|
|
+ }
|
|
|
}
|
|
|
+ resp.HandleSuccess(ctx, m)
|
|
|
|
|
|
- // 等待所有协程完成
|
|
|
- wg.Wait()
|
|
|
-
|
|
|
- // 统一返回结果
|
|
|
- resp.HandleSuccess(ctx, pointType)
|
|
|
}
|
|
|
func (h *IntelligentBuildingControlHandler) GetGetPointSSE(ctx *gin.Context) {
|
|
|
// 设置响应头
|
|
@@ -198,7 +269,7 @@ func (h *IntelligentBuildingControlHandler) GetGetPointSSE(ctx *gin.Context) {
|
|
|
return
|
|
|
default:
|
|
|
m := make(map[string]any)
|
|
|
- points, err := h.intelligentBuildingControlService.GetPoint(conds)
|
|
|
+ points, _, err := h.intelligentBuildingControlService.GetPoint(conds, 1, 100)
|
|
|
if err != nil {
|
|
|
resp.HandleError(ctx, 1201, "查询点位失败", nil)
|
|
|
conn = false
|
|
@@ -251,27 +322,6 @@ func (h *IntelligentBuildingControlHandler) GetGetPointSSE(ctx *gin.Context) {
|
|
|
|
|
|
// GetPointType 获取点位类型
|
|
|
func (h *IntelligentBuildingControlHandler) GetPointType(ctx *gin.Context) {
|
|
|
- var tempS1 model.NumericPoint
|
|
|
- // var xmlData = `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
- //<real val="27.49811553955078" display="27.50 °C {ok}" unit="obix:units/celsius">
|
|
|
- // <str name="facets" val="units=u:celsius;°C;(K);+273.15;" display="units=°C"/>
|
|
|
- // <ref name="proxyExt" display="analogInput:1:Present Value:-1:REAL"/>
|
|
|
- // <real name="out" val="27.49811553955078" display="27.50 °C {ok}"/>
|
|
|
- // <ref name="tag" display="Point Tag"/>
|
|
|
- //</real>`
|
|
|
- //err2 := ctx.ShouldBindXML(&tempS1)
|
|
|
- //err2 := xml.Unmarshal([]byte(xmlData), &tempS1)
|
|
|
- //if err2 != nil {
|
|
|
- // resp.HandleError(ctx, 1201, "绑定XML失败", nil)
|
|
|
- // return
|
|
|
- //}
|
|
|
- request, err2 := obix.SendSecureRequest("https://10.1.201.253/obix/config/Drivers/BacnetNetwork/DDC_9B_1F_1a/points/PAU/PAU_9B_1F_1/PAUAlr1", h.conf.GetString("obix.username"), h.conf.GetString("obix.password"))
|
|
|
- if err2 != nil {
|
|
|
- resp.HandleError(ctx, 1201, "发送请求失败", nil)
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println(request, "===========")
|
|
|
- fmt.Println(tempS1)
|
|
|
points, err := h.intelligentBuildingControlService.GetPointType()
|
|
|
if err != nil {
|
|
|
resp.HandleError(ctx, 1201, "查询点位类型失败", nil)
|
|
@@ -279,6 +329,8 @@ func (h *IntelligentBuildingControlHandler) GetPointType(ctx *gin.Context) {
|
|
|
}
|
|
|
resp.HandleSuccess(ctx, points)
|
|
|
}
|
|
|
+
|
|
|
+// GetDeviceType 获取设备类型
|
|
|
func (h *IntelligentBuildingControlHandler) GetDeviceType(ctx *gin.Context) {
|
|
|
points, err := h.intelligentBuildingControlService.DeviceType()
|
|
|
if err != nil {
|
|
@@ -291,3 +343,25 @@ func (h *IntelligentBuildingControlHandler) GetDeviceType(ctx *gin.Context) {
|
|
|
}
|
|
|
resp.HandleSuccess(ctx, m)
|
|
|
}
|
|
|
+
|
|
|
+// GetDevices 获取设备列表
|
|
|
+func (h *IntelligentBuildingControlHandler) GetDevices(ctx *gin.Context) {
|
|
|
+ conds := make(map[string]any)
|
|
|
+ pageNum, err := strconv.Atoi(ctx.Query("pageNum"))
|
|
|
+ pageSize, err := strconv.Atoi(ctx.Query("pageSize"))
|
|
|
+ device_type := ctx.Query("device_type")
|
|
|
+ if len(device_type) == 0 || device_type == "" {
|
|
|
+ resp.HandleError(ctx, 1201, "设备类型不能为空", nil)
|
|
|
+ }
|
|
|
+ conds["device_type"] = device_type
|
|
|
+ if err != nil {
|
|
|
+ resp.HandleError(ctx, 1201, "获取分页参数失败", nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ devices, total, err := h.intelligentBuildingControlService.GetDevices(conds, pageNum, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ resp.HandleError(ctx, 1201, "查询设备类型失败", nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.PageHandleSuccess(ctx, devices, total, pageNum, pageSize)
|
|
|
+}
|