|
@@ -9,6 +9,7 @@ import (
|
|
|
"fmt"
|
|
|
"go.uber.org/zap"
|
|
|
"math/rand"
|
|
|
+ "net/http"
|
|
|
"regexp"
|
|
|
"strconv"
|
|
|
"time"
|
|
@@ -218,6 +219,7 @@ func (h *IntelligentBuildingControlHandler) GetGetPoint(ctx *gin.Context) {
|
|
|
resp.HandleSuccess(ctx, m)
|
|
|
|
|
|
}
|
|
|
+
|
|
|
func (h *IntelligentBuildingControlHandler) GetGetPointSSE(ctx *gin.Context) {
|
|
|
// 设置响应头
|
|
|
ctx.Header("Content-Type", "text/event-stream")
|
|
@@ -320,6 +322,141 @@ func (h *IntelligentBuildingControlHandler) GetGetPointSSE(ctx *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//func (h *IntelligentBuildingControlHandler) GetGetPointSSE(ctx *gin.Context) {
|
|
|
+// // 设置响应头
|
|
|
+// ctx.Header("Content-Type", "text/event-stream")
|
|
|
+// ctx.Header("Cache-Control", "no-cache")
|
|
|
+// ctx.Header("Connection", "keep-alive")
|
|
|
+//
|
|
|
+// // 监听客户端断开连接
|
|
|
+// conn := true
|
|
|
+// notify := ctx.Writer.CloseNotify()
|
|
|
+//
|
|
|
+// type Response struct {
|
|
|
+// RequestId string `json:"requestId,omitempty"`
|
|
|
+// Code int32 `json:"code,omitempty"`
|
|
|
+// Msg string `json:"msg,omitempty"`
|
|
|
+// Data any `json:"data"`
|
|
|
+// }
|
|
|
+//
|
|
|
+// 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")
|
|
|
+//
|
|
|
+// var response Response
|
|
|
+// for conn {
|
|
|
+// select {
|
|
|
+// case <-notify:
|
|
|
+// conn = false
|
|
|
+// fmt.Println("客户端断开连接")
|
|
|
+// return
|
|
|
+// default:
|
|
|
+// m := make(map[string]any)
|
|
|
+// points, _, err := h.intelligentBuildingControlService.GetPoint(conds, 1, 100)
|
|
|
+// if err != nil {
|
|
|
+// resp.HandleError(ctx, 1201, "查询点位失败", nil)
|
|
|
+// conn = false
|
|
|
+// continue
|
|
|
+// }
|
|
|
+//
|
|
|
+// var wg sync.WaitGroup
|
|
|
+// var mutex sync.Mutex
|
|
|
+// sem := make(chan struct{}, 10) // 控制最大并发数为10
|
|
|
+//
|
|
|
+// for _, v := range *points {
|
|
|
+// select {
|
|
|
+// case sem <- struct{}{}:
|
|
|
+// default:
|
|
|
+// <-sem
|
|
|
+// sem <- struct{}{}
|
|
|
+// }
|
|
|
+// wg.Add(1)
|
|
|
+// go func(v model.Point) {
|
|
|
+// defer func() {
|
|
|
+// <-sem
|
|
|
+// wg.Done()
|
|
|
+// }()
|
|
|
+//
|
|
|
+// url := baseUrl + v.FullPath
|
|
|
+// request, err := obix.SendSecureRequest(url, h.conf.GetString("obix.username"), h.conf.GetString("obix.password"))
|
|
|
+// if err != nil {
|
|
|
+// h.logger.Error("发送请求失败", zap.String("url", url), 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]
|
|
|
+// result := obix.DetectType(value)
|
|
|
+//
|
|
|
+// mutex.Lock()
|
|
|
+// defer mutex.Unlock()
|
|
|
+//
|
|
|
+// switch val := result.(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
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// h.logger.Warn("未找到 val 值", zap.String("url", url))
|
|
|
+// }
|
|
|
+// }(v)
|
|
|
+// }
|
|
|
+//
|
|
|
+// wg.Wait() // 等待所有 goroutine 完成
|
|
|
+//
|
|
|
+// response.Code = 200
|
|
|
+// response.RequestId = ctx.ClientIP()
|
|
|
+// response.Msg = "success"
|
|
|
+// response.Data = m
|
|
|
+//
|
|
|
+// res, _ := json.Marshal(&response)
|
|
|
+// fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
|
|
|
+// ctx.Writer.Flush()
|
|
|
+// time.Sleep(10 * time.Second)
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|
|
|
+
|
|
|
// GetPointType 获取点位类型
|
|
|
func (h *IntelligentBuildingControlHandler) GetPointType(ctx *gin.Context) {
|
|
|
points, err := h.intelligentBuildingControlService.GetPointType()
|
|
@@ -365,3 +502,18 @@ func (h *IntelligentBuildingControlHandler) GetDevices(ctx *gin.Context) {
|
|
|
}
|
|
|
resp.PageHandleSuccess(ctx, devices, total, pageNum, pageSize)
|
|
|
}
|
|
|
+
|
|
|
+// ConfigurationDiagram 获取设备组态图
|
|
|
+func (h *IntelligentBuildingControlHandler) ConfigurationDiagram(c *gin.Context) {
|
|
|
+ // 获取查询参数
|
|
|
+ deviceName := c.Query("deviceName")
|
|
|
+ if deviceName == "" {
|
|
|
+ c.String(http.StatusBadRequest, "缺少 deviceName 参数")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 传递变量给模板
|
|
|
+ c.HTML(http.StatusOK, "PAU.html", gin.H{
|
|
|
+ "deviceName": deviceName,
|
|
|
+ })
|
|
|
+}
|