| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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)
- }
|