channel_event.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. afterID, _ := strconv.ParseUint(c.Query("after_id"), 10, 64)
  12. if afterID == 0 {
  13. afterID, _ = strconv.ParseUint(c.Query("after"), 10, 64)
  14. }
  15. events := uhf.GetChannelEvents(afterID)
  16. response.OkWithData(events, c)
  17. }
  18. // SimulateEvent 模拟RFID/车牌识别(测试用)
  19. func SimulateEvent(c *gin.Context) {
  20. rfid := c.Query("rfid")
  21. plate := c.Query("plate")
  22. direction := c.Query("direction") // in / out
  23. if rfid == "" && plate == "" {
  24. response.FailWithMessage("rfid或plate参数不能同时为空", c)
  25. return
  26. }
  27. if direction == "" {
  28. direction = "in"
  29. }
  30. var channelName string
  31. global.GVA_DB.Raw("SELECT channel_name FROM channel LIMIT 1").Scan(&channelName)
  32. if channelName == "" {
  33. channelName = "测试通道"
  34. }
  35. uhf.PushChannelEvent(uhf.ChannelEvent{
  36. DeviceCode: "SIM-001",
  37. RFIDTag: rfid,
  38. PlateNumber: plate,
  39. Direction: direction,
  40. ChannelName: channelName,
  41. Timestamp: time.Now().Unix(),
  42. Status: "completed",
  43. Message: "模拟通道事件",
  44. })
  45. response.OkWithMessage("事件已推送", c)
  46. }