This commit is contained in:
xzb 2023-10-16 10:24:48 +08:00
commit 583fea2654
8 changed files with 84 additions and 81 deletions

View File

@ -16,6 +16,7 @@ import (
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory" "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
"joylink.club/bj-rtsts-server/config" "joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/dto/request_proto"
apiproto "joylink.club/bj-rtsts-server/grpcproto" apiproto "joylink.club/bj-rtsts-server/grpcproto"
"joylink.club/bj-rtsts-server/middleware" "joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service" "joylink.club/bj-rtsts-server/service"
@ -230,23 +231,24 @@ func removeTrain(c *gin.Context) {
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Authorization header string true "JWT Token" // @Param Authorization header string true "JWT Token"
// @Param RemoveTrainDto body dto.SwitchOperationReqDto true "ATS测试仿真-操作道岔" // @Param TurnoutOperationReq body request_proto.TurnoutOperationReq true "ATS测试仿真-操作道岔"
// //
// @Success 200 {object} string // @Success 200 {object} string
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/simulation/switch/operation [post] // @Router /api/v1/simulation/switch/operation [post]
func switchOperation(c *gin.Context) { func switchOperation(c *gin.Context) {
req := &dto.SwitchOperationReqDto{} req := &request_proto.TurnoutOperationReq{}
if err := c.ShouldBind(&req); err != nil { if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
} }
simulation := checkDeviceDataAndReturn(req.SimulationId) simulation := checkDeviceDataAndReturn(req.SimulationId)
slog.Info("传入状态参数", req) slog.Info("传入状态参数", req)
memory.ChangeTurnoutState(simulation, &state.SwitchState{ memory.HandleTurnoutOperation(simulation, req)
Id: req.DeviceId, // memory.ChangeTurnoutState(simulation, &state.SwitchState{
Normal: req.TurnNormal, // Id: req.DeviceId,
Reverse: req.TurnReverse, // Normal: req.TurnNormal,
}, req.MapId) // Reverse: req.TurnReverse,
// }, req.MapId)
c.JSON(http.StatusOK, "ok") c.JSON(http.StatusOK, "ok")
} }
@ -271,7 +273,7 @@ func signalOperation(c *gin.Context) {
if err := c.ShouldBind(&req); err != nil { if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
} }
simulation := checkDeviceDataAndReturn(req.SimulationId) // simulation := checkDeviceDataAndReturn(req.SimulationId)
slog.Info("传入状态参数", req) slog.Info("传入状态参数", req)
memory.ChangeSignalState(simulation, req.MapId, req.DeviceId, req.Aspect) memory.ChangeSignalState(simulation, req.MapId, req.DeviceId, req.Aspect)
c.JSON(http.StatusOK, "ok") c.JSON(http.StatusOK, "ok")

View File

@ -2,6 +2,7 @@ package memory
import ( import (
"fmt" "fmt"
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
"joylink.club/bj-rtsts-server/ats/verify/protos/state" "joylink.club/bj-rtsts-server/ats/verify/protos/state"
"joylink.club/ecs" "joylink.club/ecs"

View File

@ -5,11 +5,13 @@ import (
"joylink.club/ecs" "joylink.club/ecs"
"joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/component_proto"
"joylink.club/rtsssimulation/entity" "joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/fi" "joylink.club/rtsssimulation/fi"
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
"joylink.club/bj-rtsts-server/ats/verify/protos/state" "joylink.club/bj-rtsts-server/ats/verify/protos/state"
"joylink.club/bj-rtsts-server/dto/request_proto"
) )
// 道岔相关道岔操作方法 // 道岔相关道岔操作方法
@ -22,6 +24,31 @@ func ChangeTurnoutState(simulation *VerifySimulation, status *state.SwitchState,
} }
} }
// 处理道岔操作
func HandleTurnoutOperation(simulation *VerifySimulation, req *request_proto.TurnoutOperationReq) {
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &graphicData.Turnout{})
switch req.Operation {
case request_proto.Turnout_DC:
fi.DriveTurnoutDCOn(simulation.World, uid)
case request_proto.Turnout_CancelDC:
fi.DriveTurnoutDCOff(simulation.World, uid)
case request_proto.Turnout_FC:
fi.DriveTurnoutFCOn(simulation.World, uid)
case request_proto.Turnout_CancelFC:
fi.DriveTurnoutFCOff(simulation.World, uid)
case request_proto.Turnout_SetSB:
fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
case request_proto.Turnout_CancelSB:
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
case request_proto.Turnout_SetJC:
fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
case request_proto.Turnout_CancelJC:
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
default:
panic(fmt.Sprintf("未知的道岔操作:%s", req.Operation))
}
}
// 获取全部的道岔状态,动力学使用 // 获取全部的道岔状态,动力学使用
func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState { func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
var switchArr []*state.SwitchState var switchArr []*state.SwitchState

View File

@ -2987,11 +2987,11 @@ const docTemplate = `{
}, },
{ {
"description": "ATS测试仿真-操作道岔", "description": "ATS测试仿真-操作道岔",
"name": "RemoveTrainDto", "name": "TurnoutOperationReq",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.SwitchOperationReqDto" "$ref": "#/definitions/request_proto.TurnoutOperationReq"
} }
} }
], ],
@ -4791,31 +4791,6 @@ const docTemplate = `{
} }
} }
}, },
"dto.SwitchOperationReqDto": {
"type": "object",
"required": [
"id",
"mapId",
"simulationId"
],
"properties": {
"id": {
"type": "string"
},
"mapId": {
"type": "integer"
},
"simulationId": {
"type": "string"
},
"turnNormal": {
"type": "boolean"
},
"turnReverse": {
"type": "boolean"
}
}
},
"dto.TokenRespDto": { "dto.TokenRespDto": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -2980,11 +2980,11 @@
}, },
{ {
"description": "ATS测试仿真-操作道岔", "description": "ATS测试仿真-操作道岔",
"name": "RemoveTrainDto", "name": "TurnoutOperationReq",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.SwitchOperationReqDto" "$ref": "#/definitions/request_proto.TurnoutOperationReq"
} }
} }
], ],
@ -4784,31 +4784,6 @@
} }
} }
}, },
"dto.SwitchOperationReqDto": {
"type": "object",
"required": [
"id",
"mapId",
"simulationId"
],
"properties": {
"id": {
"type": "string"
},
"mapId": {
"type": "integer"
},
"simulationId": {
"type": "string"
},
"turnNormal": {
"type": "boolean"
},
"turnReverse": {
"type": "boolean"
}
}
},
"dto.TokenRespDto": { "dto.TokenRespDto": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -257,23 +257,6 @@ definitions:
simulationId: simulationId:
type: string type: string
type: object type: object
dto.SwitchOperationReqDto:
properties:
id:
type: string
mapId:
type: integer
simulationId:
type: string
turnNormal:
type: boolean
turnReverse:
type: boolean
required:
- id
- mapId
- simulationId
type: object
dto.TokenRespDto: dto.TokenRespDto:
properties: properties:
code: code:
@ -2414,10 +2397,10 @@ paths:
type: string type: string
- description: ATS测试仿真-操作道岔 - description: ATS测试仿真-操作道岔
in: body in: body
name: RemoveTrainDto name: TurnoutOperationReq
required: true required: true
schema: schema:
$ref: '#/definitions/dto.SwitchOperationReqDto' $ref: '#/definitions/request_proto.TurnoutOperationReq'
produces: produces:
- application/json - application/json
responses: responses:

View File

@ -0,0 +1,13 @@
package simulationdto
import (
"joylink.club/bj-rtsts-server/dto/request_proto"
)
// 道岔操作请求DTO
type TurnoutOperationReqDto struct {
SimulationId string `form:"simulationId" json:"simulationId" binding:"required"`
MapId int32 `json:"mapId" from:"mapId" binding:"required"`
DeviceId string `form:"id" json:"id" binding:"required"`
Operation request_proto.Turnout_Operation `form:"operation" json:"operation" binding:"required"`
}

View File

@ -0,0 +1,27 @@
package simulationdto_test
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"joylink.club/bj-rtsts-server/dto/request_proto"
)
func TestTurnoutOperationReqDto(t *testing.T) {
b, err := json.Marshal(&request_proto.TurnoutOperationReq{
SimulationId: "1",
MapId: 2,
DeviceId: "3",
Operation: 2,
})
if err != nil {
panic(err)
}
var o request_proto.TurnoutOperationReq
err = json.Unmarshal(b, &o)
if err != nil {
panic(err)
}
assert.Equal(t, request_proto.Turnout_Operation(2), o.Operation)
}