package parking import ( "github.com/gin-gonic/gin" commonModel "wails-app/internal/model/common" "wails-app/internal/model/common/response" incidentService "wails-app/internal/modules/incident/service" utils "wails-app/internal/pkg" "wails-app/internal/service" parkingService "wails-app/internal/service/parking" ) var passageService = &service.ServiceGroupApp.ParkingServiceGroup.PassageService var incidentSvc = incidentService.NewIncidentService() // ListGateDevices 返回进出场工作台可用的道闸设备。 func ListGateDevices(c *gin.Context) { devices, err := passageService.ListGateDevices() if err != nil { response.FailWithMessage(err.Error(), c) return } response.OkWithData(devices, c) } // OpenGate 人工开闸。可携带 reason(原因)、plate_number / session_id(关联上下文), // 每次操作生成可审计的异常记录(manual_raise 或 gate_failed)。 func OpenGate(c *gin.Context) { var req commonModel.GateControlRequest if err := c.ShouldBindJSON(&req); err != nil { response.FailWithMessage(err.Error(), c) return } operatorID := utils.GetUserID(c) commandLogID, err := passageService.OpenGateWithContext(parkingService.GateCommandContext{ Source: incidentService.SourceManual, OperatorID: operatorID, SessionID: req.SessionID, }, req.DeviceCode, req.ValidTime) if err != nil { incidentID := incidentSvc.RecordIncident(incidentService.RecordIncidentRequest{ Category: incidentService.CategoryGateFailed, Source: incidentService.SourceManual, VehicleRecordID: req.SessionID, PlateNumber: req.PlateNumber, DeviceCode: req.DeviceCode, GateCommandID: commandLogID, OperatorID: operatorID, Description: "人工开闸失败", Detail: err.Error(), HandleRemark: req.Reason, }) incidentSvc.LinkIncidentToCommand(commandLogID, incidentID) response.FailWithMessage(err.Error(), c) return } incidentSvc.RecordIncident(incidentService.RecordIncidentRequest{ Category: incidentService.CategoryManualRaise, Source: incidentService.SourceManual, VehicleRecordID: req.SessionID, PlateNumber: req.PlateNumber, DeviceCode: req.DeviceCode, GateCommandID: commandLogID, OperatorID: operatorID, Description: "人工开闸", HandleType: incidentService.HandleManualGate, HandleRemark: req.Reason, }) response.OkWithDetailed(gin.H{"device_code": req.DeviceCode, "action": "open"}, "开闸成功", c) } // CloseGate 人工关闸。同样生成可审计记录。 func CloseGate(c *gin.Context) { var req commonModel.GateControlRequest if err := c.ShouldBindJSON(&req); err != nil { response.FailWithMessage(err.Error(), c) return } operatorID := utils.GetUserID(c) commandLogID, err := passageService.CloseGateWithContext(parkingService.GateCommandContext{ Source: incidentService.SourceManual, OperatorID: operatorID, SessionID: req.SessionID, }, req.DeviceCode, req.ValidTime) if err != nil { incidentID := incidentSvc.RecordIncident(incidentService.RecordIncidentRequest{ Category: incidentService.CategoryGateFailed, Source: incidentService.SourceManual, VehicleRecordID: req.SessionID, PlateNumber: req.PlateNumber, DeviceCode: req.DeviceCode, GateCommandID: commandLogID, OperatorID: operatorID, Description: "人工关闸失败", Detail: err.Error(), HandleRemark: req.Reason, }) incidentSvc.LinkIncidentToCommand(commandLogID, incidentID) response.FailWithMessage(err.Error(), c) return } incidentSvc.RecordIncident(incidentService.RecordIncidentRequest{ Category: incidentService.CategoryManualRaise, Source: incidentService.SourceManual, VehicleRecordID: req.SessionID, PlateNumber: req.PlateNumber, DeviceCode: req.DeviceCode, GateCommandID: commandLogID, OperatorID: operatorID, Description: "人工关闸", HandleType: incidentService.HandleManualGate, HandleRemark: req.Reason, }) response.OkWithDetailed(gin.H{"device_code": req.DeviceCode, "action": "close"}, "关闸成功", c) }