Quellcode durchsuchen

feat: 通道事件模拟接口——GET /channel/test-event?rfid=xxx&direction=in

lq vor 1 Monat
Ursprung
Commit
99385e1cd8
2 geänderte Dateien mit 32 neuen und 0 gelöschten Zeilen
  1. 31 0
      internal/api/v1/parking/channel_event.go
  2. 1 0
      internal/router/parking/parking.go

+ 31 - 0
internal/api/v1/parking/channel_event.go

@@ -2,8 +2,10 @@ package parking
 
 import (
 	"strconv"
+	"time"
 
 	"github.com/gin-gonic/gin"
+	"wails-app/internal/global"
 	"wails-app/internal/model/common/response"
 	"wails-app/internal/service/uhf"
 )
@@ -13,3 +15,32 @@ func GetChannelEvents(c *gin.Context) {
 	events := uhf.GetChannelEvents(after)
 	response.OkWithData(events, c)
 }
+
+// SimulateEvent 模拟RFID扫描(测试用)
+func SimulateEvent(c *gin.Context) {
+	rfid := c.Query("rfid")
+	direction := c.Query("direction") // in / out
+	if rfid == "" {
+		response.FailWithMessage("rfid参数不能为空", c)
+		return
+	}
+	if direction == "" {
+		direction = "in"
+	}
+
+	// 获取第一个通道名
+	var channelName string
+	global.GVA_DB.Raw("SELECT channel_name FROM channel LIMIT 1").Scan(&channelName)
+	if channelName == "" {
+		channelName = "测试通道"
+	}
+
+	uhf.PushChannelEvent(uhf.ChannelEvent{
+		DeviceCode:  "SIM-001",
+		RFIDTag:     rfid,
+		Direction:   direction,
+		ChannelName: channelName,
+		Timestamp:   time.Now().Unix(),
+	})
+	response.OkWithMessage("事件已推送", c)
+}

+ 1 - 0
internal/router/parking/parking.go

@@ -9,6 +9,7 @@ import (
 
 func SetupParkingRouter(router *gin.RouterGroup) {
 	router.GET("/channel/events", parking.GetChannelEvents)
+	router.GET("/channel/test-event", parking.SimulateEvent)
 
 	parkingGroup := router.Group("/parking")
 	parkLotGroup := parkingGroup.Group("/lot")