Przeglądaj źródła

水表,电表,电梯,车位,温控器,巡更点

huangyan 3 tygodni temu
rodzic
commit
fc5002e9f2

+ 46 - 0
internal/handler/broadcast.go

@@ -4,6 +4,8 @@ import (
 	"city_chips/internal/model"
 	"city_chips/internal/service"
 	"city_chips/pkg/helper/resp"
+	"encoding/json"
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/spf13/viper"
 	"math/rand"
@@ -61,3 +63,47 @@ func (h *BroadcastHandler) GetBroadcast(ctx *gin.Context) {
 	m["PlaybackControls"] = device        //播放控制
 	resp.HandleSuccess(ctx, m)
 }
+
+// Getbroadcast 获取广播系统数据
+func (h *BroadcastHandler) GetBroadcastState(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 `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
+		Code      int32  `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
+		Msg       string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
+		Data      any    `json:"data"`
+	}
+	stationNo := ctx.Query("id")
+	if len(stationNo) == 0 {
+		resp.HandleError(ctx, 1201, "缺少必要参数", nil)
+		return
+	}
+	var response Response
+	for conn {
+		select {
+		case <-notify:
+			conn = false
+			fmt.Println("断开连接")
+			return
+		default:
+			// 模拟数据
+			data := make(map[string]any)
+			response.Code = 200
+			response.RequestId = stationNo
+			response.Msg = "success"
+			data["state"] = rand.Intn(2) // // 1开  0关  2故障
+			data["广播名称"] = model.GetRandomItem(model.GBDeviceName)
+			response.Data = data
+			res, _ := json.Marshal(&response)
+			fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
+			ctx.Writer.Flush()
+			time.Sleep(10 * time.Second)
+		}
+	}
+}

+ 49 - 0
internal/handler/elevator.go

@@ -1,9 +1,13 @@
 package handler
 
 import (
+	"city_chips/internal/model"
 	"city_chips/internal/service"
 	"city_chips/pkg/helper/resp"
+	"encoding/json"
+	"fmt"
 	"math/rand"
+	"time"
 
 	"github.com/gin-gonic/gin"
 	"github.com/spf13/viper"
@@ -70,3 +74,48 @@ func (h *ElevatorHandler) GetElevator(ctx *gin.Context) {
 	m["TrappedPerson"] = TrappedPerson //困人报警
 	resp.HandleSuccess(ctx, m)
 }
+
+// GetElevatorData 获取电梯数据
+func (h *ElevatorHandler) GetElevatorData(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 `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
+		Code      int32  `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
+		Msg       string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
+		Data      any    `json:"data"`
+	}
+	stationNo := ctx.Query("id")
+	if len(stationNo) == 0 {
+		resp.HandleError(ctx, 1201, "缺少必要参数", nil)
+		return
+	}
+	var response Response
+	for conn {
+		select {
+		case <-notify:
+			conn = false
+			fmt.Println("断开连接")
+			return
+		default:
+			// 模拟数据
+			data := make(map[string]any)
+			response.Code = 200
+			response.RequestId = stationNo
+			response.Msg = "success"
+			data["state"] = rand.Intn(2) // // 1开  0关  2故障
+			data["楼层"] = model.GetRandomItem(model.ElevatorFloors)
+			data["电梯名称"] = model.GetRandomItem(model.ElevatorDeviceNames)
+			response.Data = data
+			res, _ := json.Marshal(&response)
+			fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
+			ctx.Writer.Flush()
+			time.Sleep(10 * time.Second)
+		}
+	}
+}

+ 88 - 0
internal/handler/energy.go

@@ -115,3 +115,91 @@ func (h *EnergyHandler) GetWaterMmeter(ctx *gin.Context) {
 		}
 	}
 }
+
+// 电表数据
+func (h *EnergyHandler) GetAmmeter(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 `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
+		Code      int32  `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
+		Msg       string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
+		Data      any    `json:"data"`
+	}
+	stationNo := ctx.Query("id")
+	if len(stationNo) == 0 {
+		resp.HandleError(ctx, 1201, "缺少必要参数", nil)
+		return
+	}
+	var response Response
+	for conn {
+		select {
+		case <-notify:
+			conn = false
+			fmt.Println("断开连接")
+			return
+		default:
+			// 模拟数据
+			data := make(map[string]any)
+			response.Code = 200
+			response.RequestId = strconv.Itoa(rand.Intn(1000))
+			response.Msg = "success"
+			data["今日用电量"] = rand.Intn(1000)
+			data["昨日用电量"] = rand.Intn(1000)
+			data["本月用水量"] = rand.Intn(1000)
+			response.Data = data
+			res, _ := json.Marshal(&response)
+			fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
+			ctx.Writer.Flush()
+			time.Sleep(10 * time.Second)
+		}
+	}
+}
+func (h *EnergyHandler) GetTemperature(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 `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
+		Code      int32  `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
+		Msg       string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
+		Data      any    `json:"data"`
+	}
+	stationNo := ctx.Query("id")
+	if len(stationNo) == 0 {
+		resp.HandleError(ctx, 1201, "缺少必要参数", nil)
+		return
+	}
+	var response Response
+	for conn {
+		select {
+		case <-notify:
+			conn = false
+			fmt.Println("断开连接")
+			return
+		default:
+			// 模拟数据
+			data := make(map[string]any)
+			response.Code = 200
+			response.RequestId = strconv.Itoa(rand.Intn(1000))
+			response.Msg = "success"
+			data["温度"] = rand.Intn(100)
+			data["湿度"] = rand.Intn(100)
+			data["时间"] = time.Now().Format("2006-01-02 15:04:05")
+			response.Data = data
+			res, _ := json.Marshal(&response)
+			fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
+			ctx.Writer.Flush()
+			time.Sleep(10 * time.Second)
+		}
+	}
+}

+ 47 - 0
internal/handler/hikvision.go

@@ -151,6 +151,53 @@ func (h *HikvisionHandler) GetElectronicInspections(ctx *gin.Context) {
 	resp.HandleSuccess(ctx, m)
 }
 
+// GetPatrolPoint 获取巡更点
+func (h *HikvisionHandler) GetPatrolPoint(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 `protobuf:"bytes,1,opt,name=requestId,proto3" json:"requestId,omitempty"`
+		Code      int32  `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
+		Msg       string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
+		Data      any    `json:"data"`
+	}
+	stationNo := ctx.Query("id")
+	if len(stationNo) == 0 {
+		resp.HandleError(ctx, 1201, "缺少必要参数", nil)
+		return
+	}
+	var response Response
+	for conn {
+		select {
+		case <-notify:
+			conn = false
+			fmt.Println("断开连接")
+			return
+		default:
+			// 模拟数据
+			data := make(map[string]any)
+			response.Code = 200
+			response.RequestId = stationNo
+			response.Msg = "success"
+			data["state"] = rand.Intn(2) // // 1开  0关  2故障
+			data["巡更名称"] = model.GetRandomItem(model.Locations)
+			data["巡更人"] = model.GetRandomItem(model.Names)
+			data["巡更时间"] = time.Now().Format("2006-01-02 15:04:05")
+			data["巡更位置"] = model.GetRandomItem(model.InspectionLocations)
+			response.Data = data
+			res, _ := json.Marshal(&response)
+			fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
+			ctx.Writer.Flush()
+			time.Sleep(10 * time.Second)
+		}
+	}
+}
+
 // GetVisitor 访客系统
 func (h *HikvisionHandler) GetVisitor(ctx *gin.Context) {
 	m := make(map[string]any)

+ 16 - 0
internal/handler/intelligentbuildingcontrol.go

@@ -4,6 +4,7 @@ import (
 	"city_chips/internal/model"
 	"city_chips/internal/service"
 	"city_chips/pkg/helper/resp"
+	"fmt"
 	"math/rand"
 	"time"
 
@@ -102,6 +103,21 @@ func (h *IntelligentBuildingControlHandler) GetPoint(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
+	}
+	fmt.Println(tempS1)
 	points, err := h.intelligentBuildingControlService.GetPointType()
 	if err != nil {
 		resp.HandleError(ctx, 1201, "查询点位类型失败", nil)

+ 52 - 0
internal/model/intelligentbuildingcontrol.go

@@ -30,6 +30,58 @@ var DeviceType = map[string]string{
 	"EAF": "送排风机",
 }
 
+// NumericPoint TempS1
+type NumericPoint struct {
+	Val      float64       `xml:"val,attr"`
+	Href     string        `xml:"href,attr,omitempty"`
+	Is       string        `xml:"is,attr,omitempty"`
+	Display  string        `xml:"display,attr,omitempty"`
+	Icon     string        `xml:"icon,attr,omitempty"`
+	Unit     string        `xml:"unit,attr,omitempty"`
+	Facets   *Facets       `xml:"str"`
+	ProxyExt *ProxyExt     `xml:"ref"`
+	Out      *OutputValue  `xml:"real[name=out]"`
+	Tag      *TagReference `xml:"ref[name=tag]"`
+}
+
+type Facets struct {
+	Name        string `xml:"name,attr"`
+	Val         string `xml:"val,attr"`
+	Href        string `xml:"href,attr,omitempty"`
+	Display     string `xml:"display,attr,omitempty"`
+	DisplayName string `xml:"displayName,attr,omitempty"`
+}
+
+type ProxyExt struct {
+	Name        string `xml:"name,attr"`
+	Href        string `xml:"href,attr,omitempty"`
+	Is          string `xml:"is,attr,omitempty"`
+	Display     string `xml:"display,attr,omitempty"`
+	DisplayName string `xml:"displayName,attr,omitempty"`
+	Icon        string `xml:"icon,attr,omitempty"`
+}
+
+type OutputValue struct {
+	Name        string  `xml:"name,attr"`
+	Val         float64 `xml:"val,attr"`
+	Href        string  `xml:"href,attr,omitempty"`
+	Is          string  `xml:"is,attr,omitempty"`
+	Display     string  `xml:"display,attr,omitempty"`
+	DisplayName string  `xml:"displayName,attr,omitempty"`
+	Icon        string  `xml:"icon,attr,omitempty"`
+	Unit        string  `xml:"unit,attr,omitempty"`
+}
+
+type TagReference struct {
+	Name    string `xml:"name,attr"`
+	Href    string `xml:"href,attr,omitempty"`
+	Is      string `xml:"is,attr,omitempty"`
+	Display string `xml:"display,attr,omitempty"`
+	Icon    string `xml:"icon,attr,omitempty"`
+}
+
+//TempS1 end
+
 func (p *Point) TableName() string {
 	return "point"
 }

+ 38 - 0
internal/model/mock.go

@@ -16,6 +16,44 @@ var GBDeviceName = []string{
 	"分区控制器", "远程控制终端", "背景音乐播放器", "紧急广播麦克风", "网络音频终端",
 }
 
+// 真实电梯设备名称列表
+var ElevatorDeviceNames = []string{
+	"东侧客梯T1",
+	"西侧货梯W2",
+	"中央高速电梯C3",
+	"北区员工专用梯B4",
+	"南门观光电梯N5",
+	"消防电梯E1",
+	"无障碍电梯A2",
+	"地下车库提升机G1",
+	"办公楼主梯O1",
+	"商业区扶梯M1",
+}
+
+// 电梯所在楼层列表
+var ElevatorFloors = []string{
+	"B2",
+	"B1",
+	"1F",
+	"2F",
+	"3F",
+	"4F",
+	"5F",
+	"6F",
+	"7F",
+	"8F",
+	"9F",
+	"10F",
+	"11F",
+	"12F",
+	"13F",
+	"14F",
+	"15F",
+	"16F",
+	"17F",
+	"18F",
+}
+
 // 终端日志内容
 var GBterminalLogs = []string{
 	"系统启动成功", "设备已上线", "音频播放测试完成", "分区3扬声器无响应", "功率放大器过热警告",

+ 7 - 0
internal/server/http.go

@@ -27,6 +27,8 @@ func NewServerHTTP(
 	r.Use(
 		middleware.CORSMiddleware(),
 	)
+	// 使用 HTTP/2 必须启用 HTTPS
+	//r.RunTLS(":443", "cert.pem", "key.pem")
 	r.LoadHTMLGlob("templates/h5player.html")
 	r.Static("/static", "./templates/static")
 
@@ -52,6 +54,7 @@ func NewServerHTTP(
 		Hikvision.GET("/getDoorSearch", hikvision.GetDoorSearch)
 		Hikvision.GET("/doControl", hikvision.DoControl)
 		Hikvision.GET("/eventLogs", hikvision.RealTimeInspection)
+		Hikvision.GET("/getPatrolPoint", hikvision.GetPatrolPoint)
 	}
 	//会议系统
 	Conference := r.Group("/Conference")
@@ -73,11 +76,13 @@ func NewServerHTTP(
 	el := r.Group("/elevator")
 	{
 		el.GET("/count", elevator.GetElevator)
+		el.GET("/elevatorData", elevator.GetElevatorData)
 	}
 	//广播控制系统
 	bro := r.Group("/broadcast")
 	{
 		bro.GET("/count", broadcast.GetBroadcast)
+		bro.GET("/getBroadcast", broadcast.GetBroadcastState)
 	}
 	//物业管理系统
 	pro := r.Group("/property")
@@ -101,6 +106,8 @@ func NewServerHTTP(
 	{
 		ener.GET("/count", energy.GetEnergy)
 		ener.GET("/GetWaterMmeter", energy.GetWaterMmeter)
+		ener.GET("/getAmmeter", energy.GetAmmeter)
+		ener.GET("/getTemperature", energy.GetTemperature)
 	}
 	//楼宇智控
 	inte := r.Group("/intell")