channel_event.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package parking
  2. import (
  3. "strconv"
  4. "time"
  5. "github.com/gin-gonic/gin"
  6. "wails-app/internal/global"
  7. "wails-app/internal/model/common/response"
  8. "wails-app/internal/service/uhf"
  9. )
  10. func GetChannelEvents(c *gin.Context) {
  11. after, _ := strconv.ParseInt(c.Query("after"), 10, 64)
  12. events := uhf.GetChannelEvents(after)
  13. response.OkWithData(events, c)
  14. }
  15. // SimulateEvent 模拟RFID扫描(测试用)
  16. func SimulateEvent(c *gin.Context) {
  17. rfid := c.Query("rfid")
  18. direction := c.Query("direction") // in / out
  19. if rfid == "" {
  20. response.FailWithMessage("rfid参数不能为空", c)
  21. return
  22. }
  23. if direction == "" {
  24. direction = "in"
  25. }
  26. // 获取第一个通道名
  27. var channelName string
  28. global.GVA_DB.Raw("SELECT channel_name FROM channel LIMIT 1").Scan(&channelName)
  29. if channelName == "" {
  30. channelName = "测试通道"
  31. }
  32. uhf.PushChannelEvent(uhf.ChannelEvent{
  33. DeviceCode: "SIM-001",
  34. RFIDTag: rfid,
  35. Direction: direction,
  36. ChannelName: channelName,
  37. Timestamp: time.Now().Unix(),
  38. })
  39. response.OkWithMessage("事件已推送", c)
  40. }