172f65b14c
【调整消息服务代码】 【删除多余代码】 【调整方法、结构体名称】
229 lines
8.8 KiB
Go
229 lines
8.8 KiB
Go
package memory
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
|
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
|
|
"joylink.club/bj-rtsts-server/ts/protos/state"
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component/component_proto"
|
|
"joylink.club/rtsssimulation/consts"
|
|
"joylink.club/rtsssimulation/fi"
|
|
"joylink.club/rtsssimulation/repository"
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
)
|
|
|
|
func ChangeSignalState(simulation *VerifySimulation, req *dto.SignalOperationReqDto) {
|
|
signalUid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &graphicData.Signal{})
|
|
signalModel, err := simulation.Repo.FindModel(signalUid, proto.DeviceType_DeviceType_Signal)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("信号机[%s]模型不存在", signalUid))
|
|
}
|
|
signalGroupCode := signalModel.(*repository.Signal).Code()
|
|
slog.Info("信号机操作", "uid", signalUid, "组合类型码", signalGroupCode)
|
|
switch req.Operation {
|
|
case request_proto.Signal_Display: //信号机显示信号设置
|
|
{
|
|
switch signalGroupCode {
|
|
case consts.SIGNAL_2XH1:
|
|
changeSignal2XH1State(simulation.World, signalUid, req.Aspect)
|
|
case consts.SIGNAL_3XH1:
|
|
changeSignal3XH1State(simulation.World, signalUid, req.Aspect)
|
|
case consts.SIGNAL_3XH2:
|
|
changeSignal3XH2State(simulation.World, signalUid, req.Aspect)
|
|
case consts.SIGNAL_3XH3:
|
|
changeSignal3XH3State(simulation.World, signalUid, req.Aspect)
|
|
case consts.SIGNAL_3XH4:
|
|
changeSignal3XH4State(simulation.World, signalUid, req.Aspect)
|
|
case consts.SIGNAL_DCXH:
|
|
changeSignalDCXHState(simulation.World, signalUid, req.Aspect)
|
|
case consts.SIGNAL_JCKXH:
|
|
changeSignalJCKXHState(simulation.World, signalUid, req.Aspect)
|
|
default:
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: fmt.Sprintf("操作[%s]的信号机,无法识别组合类型[%s]", signalUid, signalGroupCode)})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightHFaultDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_H, component_proto.Signal_DS, true)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightHCancelDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_H, component_proto.Signal_DS, false)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightLFaultDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_L, component_proto.Signal_DS, true)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightLCancelDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_L, component_proto.Signal_DS, false)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightUFaultDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_U, component_proto.Signal_DS, true)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightUCancelDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_U, component_proto.Signal_DS, false)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightAFaultDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_A, component_proto.Signal_DS, true)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightACancelDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_A, component_proto.Signal_DS, false)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightBFaultDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_B, component_proto.Signal_DS, true)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
case request_proto.Signal_LightBCancelDs:
|
|
{
|
|
e := fi.UpdateSignalLightFault(simulation.World, signalUid, component_proto.Light_B, component_proto.Signal_DS, false)
|
|
if e != nil {
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalError, Message: dto.ErrorTipMap[dto.OperationOfSignalError]})
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
func changeSignalJCKXHState(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
|
|
switch toAspect {
|
|
case state.Signal_U:
|
|
fi.DriveSignalJCKXHLx(w, signalUid)
|
|
case state.Signal_B:
|
|
fi.DriveSignalJCKXHDx(w, signalUid)
|
|
case state.Signal_H:
|
|
fi.DriveSignalJCKXHNon(w, signalUid)
|
|
default:
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
|
|
}
|
|
}
|
|
func changeSignalDCXHState(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
|
|
switch toAspect {
|
|
case state.Signal_B:
|
|
fi.DriveSignalDCXHDx(w, signalUid)
|
|
case state.Signal_A:
|
|
fi.DriveSignalDCXHNon(w, signalUid)
|
|
default:
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
|
|
}
|
|
}
|
|
func changeSignal3XH4State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
|
|
switch toAspect {
|
|
case state.Signal_OFF:
|
|
fi.DriveSignal3XH4Dd(w, signalUid, false)
|
|
case state.Signal_L:
|
|
fi.DriveSignal3XH4Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH4Lx(w, signalUid, true)
|
|
case state.Signal_U:
|
|
fi.DriveSignal3XH4Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH4Lx(w, signalUid, false)
|
|
case state.Signal_H:
|
|
fi.DriveSignal3XH4Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH4Non(w, signalUid)
|
|
default:
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
|
|
}
|
|
}
|
|
func changeSignal3XH3State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
|
|
switch toAspect {
|
|
case state.Signal_OFF:
|
|
fi.DriveSignal3XH3Dd(w, signalUid, false)
|
|
case state.Signal_U:
|
|
fi.DriveSignal3XH3Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH3Lx(w, signalUid)
|
|
case state.Signal_HU:
|
|
fi.DriveSignal3XH3Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH3Yx(w, signalUid)
|
|
case state.Signal_H:
|
|
fi.DriveSignal3XH3Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH3Non(w, signalUid)
|
|
default:
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
|
|
}
|
|
}
|
|
func changeSignal3XH2State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
|
|
switch toAspect {
|
|
case state.Signal_OFF:
|
|
fi.DriveSignal3XH2Dd(w, signalUid, false)
|
|
case state.Signal_L:
|
|
fi.DriveSignal3XH2Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH2Lx(w, signalUid)
|
|
case state.Signal_HU:
|
|
fi.DriveSignal3XH2Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH2Yx(w, signalUid)
|
|
case state.Signal_H:
|
|
fi.DriveSignal3XH2Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH2Non(w, signalUid)
|
|
default:
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
|
|
}
|
|
}
|
|
func changeSignal3XH1State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
|
|
switch toAspect {
|
|
case state.Signal_OFF:
|
|
fi.DriveSignal3XH1Dd(w, signalUid, false)
|
|
case state.Signal_L:
|
|
fi.DriveSignal3XH1Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH1Lx(w, signalUid, true)
|
|
case state.Signal_U:
|
|
fi.DriveSignal3XH1Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH1Lx(w, signalUid, false)
|
|
case state.Signal_HU:
|
|
fi.DriveSignal3XH1Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH1Yx(w, signalUid)
|
|
case state.Signal_H:
|
|
fi.DriveSignal3XH1Dd(w, signalUid, true)
|
|
fi.DriveSignal3XH1Non(w, signalUid)
|
|
default:
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
|
|
}
|
|
}
|
|
func changeSignal2XH1State(w ecs.World, signalUid string, toAspect state.Signal_Aspect) {
|
|
switch toAspect {
|
|
case state.Signal_OFF:
|
|
fi.DriveSignal2XH1Dd(w, signalUid, false)
|
|
case state.Signal_L:
|
|
fi.DriveSignal2XH1Dd(w, signalUid, true)
|
|
fi.DriveSignal2XH1Lx(w, signalUid)
|
|
case state.Signal_H:
|
|
fi.DriveSignal2XH1Dd(w, signalUid, true)
|
|
fi.DriveSignal2XH1Non(w, signalUid)
|
|
default:
|
|
panic(dto.ErrorDto{Code: dto.OperationOfSignalNotSupported, Message: dto.ErrorTipMap[dto.OperationOfSignalNotSupported]})
|
|
}
|
|
}
|