【修复创建仿真入参】

This commit is contained in:
weizhihong 2023-10-26 18:09:09 +08:00
parent 199d0b012b
commit 15ce038f89
4 changed files with 15 additions and 11 deletions

View File

@ -89,16 +89,17 @@ func createByProjectId(c *gin.Context) {
mapIds[i] = mapInfo.ID mapIds[i] = mapInfo.ID
} }
// 运行环境配置 // 运行环境配置
var runConfigStr string
runConfig := service.QueryRunConfig(req.ProjectRunConfigId) runConfig := service.QueryRunConfig(req.ProjectRunConfigId)
if runConfig != nil { simulationId, err := ts.CreateSimulation(req.ProjectId, mapIds, runConfig)
runConfigStr = runConfig.ConfigContent
}
simulationId, err := ts.CreateSimulation(req.ProjectId, mapIds, runConfigStr)
if err != nil { if err != nil {
panic(sys_error.New("测试启动失败", err)) panic(sys_error.New("测试启动失败", err))
} }
rsp := dto.SimulationCreateRspDto{ProjectId: req.ProjectId, MapId: mapIds[0], MapIds: mapIds} rsp := dto.SimulationCreateRspDto{
ProjectId: req.ProjectId,
MapId: mapIds[0],
MapIds: mapIds,
ProjectRunConfigId: req.ProjectRunConfigId,
}
rsp.SimulationId = simulationId rsp.SimulationId = simulationId
c.JSON(http.StatusOK, &rsp) c.JSON(http.StatusOK, &rsp)
} }

View File

@ -25,6 +25,8 @@ type SimulationCreateRspDto struct {
SimulationId string `json:"simulationId" form:"simulationId"` SimulationId string `json:"simulationId" form:"simulationId"`
// 地图列表 // 地图列表
MapIds []int32 `json:"mapIds" form:"mapIds"` MapIds []int32 `json:"mapIds" form:"mapIds"`
// 运行环境ID
ProjectRunConfigId int32 `json:"runConfigId" form:"runConfigId"`
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -89,7 +89,7 @@ func NewWaysideMemory() *WaysideMemory {
} }
// 创建仿真对象 // 创建仿真对象
func CreateSimulation(projectId int32, mapIds []int32, runConfig string) (*VerifySimulation, error) { func CreateSimulation(projectId int32, mapIds []int32, runConfig *dto.ProjectRunConfigDto) (*VerifySimulation, error) {
// 地图信息 // 地图信息
sort.Slice(mapIds, func(i, j int) bool { sort.Slice(mapIds, func(i, j int) bool {
return mapIds[i] < mapIds[j] return mapIds[i] < mapIds[j]
@ -417,16 +417,17 @@ func (s *VerifySimulation) CollectRelayInfo() []*message.InterlockSendMsgPkg {
} }
// 初始化仿真运行配置 // 初始化仿真运行配置
func (s *VerifySimulation) initRunConfig(configStr string) error { func (s *VerifySimulation) initRunConfig(runConfig *dto.ProjectRunConfigDto) error {
if configStr == "" { if runConfig == nil || runConfig.ConfigContent == "" {
return nil return nil
} }
var configMap config.ThridPartyConfig var configMap config.ThridPartyConfig
err := json.Unmarshal([]byte(configStr), &configMap) err := json.Unmarshal([]byte(runConfig.ConfigContent), &configMap)
if err != nil { if err != nil {
return sys_error.New("配置信息格式错误", err) return sys_error.New("配置信息格式错误", err)
} }
s.runConfig = &configMap s.runConfig = &configMap
s.runConfig.Id = runConfig.Id
return nil return nil
} }

View File

@ -32,7 +32,7 @@ func IsExistSimulation() bool {
} }
// 创建仿真对象 // 创建仿真对象
func CreateSimulation(projectId int32, mapIds []int32, runConfig string) (string, error) { func CreateSimulation(projectId int32, mapIds []int32, runConfig *dto.ProjectRunConfigDto) (string, error) {
simulationId := createSimulationId(projectId) simulationId := createSimulationId(projectId)
_, e := simulationMap.Load(simulationId) _, e := simulationMap.Load(simulationId)
if !e && IsExistSimulation() { if !e && IsExistSimulation() {