rts-sim-testing-service/dto/trainManage.go

112 lines
3.2 KiB
Go

package dto
import (
"google.golang.org/protobuf/proto"
"joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
)
type PageTrainInfoReqDto struct {
PageQueryDto
Name string `json:"name" form:"name"`
}
type TrainInfoReqDto struct {
Name string `json:"name" form:"name"`
}
type TrainInfoDto struct {
Id int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
TrainModel int32 `json:"train_model" form:"train_model"`
CarriageLength int32 `json:"carriage_length" form:"carriage_length"`
TotalLength int32 `json:"total_length" form:"total_length"`
MinDiameter int32 `json:"min_diameter" form:"min_diameter"`
MaxDiameter int32 `json:"max_diameter" form:"max_diameter"`
TrainSets string `json:"train_sets" form:"train_sets"`
Description string `json:"description" form:"description"`
}
func ConvertToTrainInfoDto(trailInfos []*model.TrainInfo) []*TrainInfoDto {
var result []*TrainInfoDto
for _, t := range trailInfos {
result = append(result, ConvertDtoFromTrainInfo(t))
}
return result
}
func ConvertDtoFromTrainInfo(t *model.TrainInfo) *TrainInfoDto {
message := &graphicData.Train{}
proto.Unmarshal(t.Proto, message)
return &TrainInfoDto{
Id: t.ID,
Name: t.Name,
Description: t.Description,
TrainModel: int32(message.TrainModel),
CarriageLength: message.CarriageLength,
TotalLength: message.TotalLength,
MinDiameter: message.MinDiameter,
MaxDiameter: message.MaxDiameter,
TrainSets: message.TrainSets,
}
}
func ConvertTrainInfoFromDto(t *TrainInfoDto) *model.TrainInfo {
info := &model.TrainInfo{Name: t.Name, Description: t.Description}
message := &graphicData.Train{
TrainModel: graphicData.Train_TrainModel(t.TrainModel),
CarriageLength: t.CarriageLength,
TotalLength: t.TotalLength,
MinDiameter: t.MinDiameter,
MaxDiameter: t.MaxDiameter,
TrainSets: t.TrainSets,
}
b, _ := proto.Marshal(message)
info.Proto = b
return info
}
// TODO: 前端修改完毕后以下代码全部删除
type PageTrainManageReqDto struct {
PageQueryDto
Name string `json:"name" form:"name"`
}
type TrainManageReqDto struct {
Name string `json:"name" form:"name"`
}
type TrainModelDto struct {
Id int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
}
type TrainSizeDto struct {
Id int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
CarriageLength int32 `json:"carriage_length" form:"carriage_length"`
TotalLength int32 `json:"total_length" form:"total_length"`
Description string `json:"description" form:"description"`
}
func ConvertFromTrainSizeDto(giSlice []*model.TrainSize) []*TrainSizeDto {
var result []*TrainSizeDto
for _, gi := range giSlice {
result = append(result, &TrainSizeDto{
Id: gi.ID,
Name: gi.Name,
CarriageLength: gi.CarriageLength,
TotalLength: gi.TotalLength,
Description: gi.Description,
})
}
return result
}
type TrainWheelDto struct {
Id int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
MinDiameter int32 `json:"min_diameter" form:"min_diameter"`
MaxDiameter int32 `json:"max_diameter" form:"max_diameter"`
}