gate.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package parking
  2. import (
  3. "github.com/gin-gonic/gin"
  4. commonModel "wails-app/internal/model/common"
  5. "wails-app/internal/model/common/response"
  6. incidentService "wails-app/internal/modules/incident/service"
  7. utils "wails-app/internal/pkg"
  8. "wails-app/internal/service"
  9. parkingService "wails-app/internal/service/parking"
  10. )
  11. var passageService = &service.ServiceGroupApp.ParkingServiceGroup.PassageService
  12. var incidentSvc = incidentService.NewIncidentService()
  13. // ListGateDevices 返回进出场工作台可用的道闸设备。
  14. func ListGateDevices(c *gin.Context) {
  15. devices, err := passageService.ListGateDevices()
  16. if err != nil {
  17. response.FailWithMessage(err.Error(), c)
  18. return
  19. }
  20. response.OkWithData(devices, c)
  21. }
  22. // OpenGate 人工开闸。可携带 reason(原因)、plate_number / session_id(关联上下文),
  23. // 每次操作生成可审计的异常记录(manual_raise 或 gate_failed)。
  24. func OpenGate(c *gin.Context) {
  25. var req commonModel.GateControlRequest
  26. if err := c.ShouldBindJSON(&req); err != nil {
  27. response.FailWithMessage(err.Error(), c)
  28. return
  29. }
  30. operatorID := utils.GetUserID(c)
  31. commandLogID, err := passageService.OpenGateWithContext(parkingService.GateCommandContext{
  32. Source: incidentService.SourceManual,
  33. OperatorID: operatorID,
  34. SessionID: req.SessionID,
  35. }, req.DeviceCode, req.ValidTime)
  36. if err != nil {
  37. incidentID := incidentSvc.RecordIncident(incidentService.RecordIncidentRequest{
  38. Category: incidentService.CategoryGateFailed,
  39. Source: incidentService.SourceManual,
  40. VehicleRecordID: req.SessionID,
  41. PlateNumber: req.PlateNumber,
  42. DeviceCode: req.DeviceCode,
  43. GateCommandID: commandLogID,
  44. OperatorID: operatorID,
  45. Description: "人工开闸失败",
  46. Detail: err.Error(),
  47. HandleRemark: req.Reason,
  48. })
  49. incidentSvc.LinkIncidentToCommand(commandLogID, incidentID)
  50. response.FailWithMessage(err.Error(), c)
  51. return
  52. }
  53. incidentSvc.RecordIncident(incidentService.RecordIncidentRequest{
  54. Category: incidentService.CategoryManualRaise,
  55. Source: incidentService.SourceManual,
  56. VehicleRecordID: req.SessionID,
  57. PlateNumber: req.PlateNumber,
  58. DeviceCode: req.DeviceCode,
  59. GateCommandID: commandLogID,
  60. OperatorID: operatorID,
  61. Description: "人工开闸",
  62. HandleType: incidentService.HandleManualGate,
  63. HandleRemark: req.Reason,
  64. })
  65. response.OkWithDetailed(gin.H{"device_code": req.DeviceCode, "action": "open"}, "开闸成功", c)
  66. }
  67. // CloseGate 人工关闸。同样生成可审计记录。
  68. func CloseGate(c *gin.Context) {
  69. var req commonModel.GateControlRequest
  70. if err := c.ShouldBindJSON(&req); err != nil {
  71. response.FailWithMessage(err.Error(), c)
  72. return
  73. }
  74. operatorID := utils.GetUserID(c)
  75. commandLogID, err := passageService.CloseGateWithContext(parkingService.GateCommandContext{
  76. Source: incidentService.SourceManual,
  77. OperatorID: operatorID,
  78. SessionID: req.SessionID,
  79. }, req.DeviceCode, req.ValidTime)
  80. if err != nil {
  81. incidentID := incidentSvc.RecordIncident(incidentService.RecordIncidentRequest{
  82. Category: incidentService.CategoryGateFailed,
  83. Source: incidentService.SourceManual,
  84. VehicleRecordID: req.SessionID,
  85. PlateNumber: req.PlateNumber,
  86. DeviceCode: req.DeviceCode,
  87. GateCommandID: commandLogID,
  88. OperatorID: operatorID,
  89. Description: "人工关闸失败",
  90. Detail: err.Error(),
  91. HandleRemark: req.Reason,
  92. })
  93. incidentSvc.LinkIncidentToCommand(commandLogID, incidentID)
  94. response.FailWithMessage(err.Error(), c)
  95. return
  96. }
  97. incidentSvc.RecordIncident(incidentService.RecordIncidentRequest{
  98. Category: incidentService.CategoryManualRaise,
  99. Source: incidentService.SourceManual,
  100. VehicleRecordID: req.SessionID,
  101. PlateNumber: req.PlateNumber,
  102. DeviceCode: req.DeviceCode,
  103. GateCommandID: commandLogID,
  104. OperatorID: operatorID,
  105. Description: "人工关闸",
  106. HandleType: incidentService.HandleManualGate,
  107. HandleRemark: req.Reason,
  108. })
  109. response.OkWithDetailed(gin.H{"device_code": req.DeviceCode, "action": "close"}, "关闸成功", c)
  110. }