channel_event.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. plate := c.Query("plate")
  19. direction := c.Query("direction") // in / out
  20. if rfid == "" && plate == "" {
  21. response.FailWithMessage("rfid或plate参数不能同时为空", c)
  22. return
  23. }
  24. if direction == "" {
  25. direction = "in"
  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. PlateNumber: plate,
  36. Direction: direction,
  37. ChannelName: channelName,
  38. Timestamp: time.Now().Unix(),
  39. })
  40. response.OkWithMessage("事件已推送", c)
  41. }