From 43cb4d5f8a3fa77a491b1d7be9bef2c109739a78 Mon Sep 17 00:00:00 2001 From: "November.12" <845255519@qq.com> Date: Wed, 27 Sep 2023 12:05:35 +0800 Subject: [PATCH] Update tp_scenario_action_service.go --- services/tp_scenario_action_service.go | 36 ++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/services/tp_scenario_action_service.go b/services/tp_scenario_action_service.go index 7ad8fed56..d709cb46b 100644 --- a/services/tp_scenario_action_service.go +++ b/services/tp_scenario_action_service.go @@ -112,7 +112,7 @@ func (*TpScenarioActionService) ExecuteScenarioAction(scenarioStrategyId string, } else { scenarioLog.ProcessDescription = "执行激活" } - + var scenarioLogDetailService TpScenarioLogDetailService scenarioLog.ProcessResult = "1" for _, scenarioAction := range scenarioActions { var scenarioLogDetail models.TpScenarioLogDetail @@ -163,7 +163,6 @@ func (*TpScenarioActionService) ExecuteScenarioAction(scenarioStrategyId string, } //记录日志 scenarioLogDetail.ScenarioLogId = scenarioLog.Id - var scenarioLogDetailService TpScenarioLogDetailService _, err := scenarioLogDetailService.AddTpScenarioLogDetail(scenarioLogDetail) if err != nil { logs.Error(result.Error) @@ -172,6 +171,39 @@ func (*TpScenarioActionService) ExecuteScenarioAction(scenarioStrategyId string, scenarioLog.ProcessDescription = "执行中有失败,请查看日志详情" scenarioLog.ProcessResult = "2" } + } else if scenarioAction.ActionType == "2" { + // 触发其他场景 + scenarioLogDetail.ActionType = "2" + instructMap := make(map[string]string) + err := json.Unmarshal([]byte(scenarioAction.Instruct), &instructMap) + if err != nil { + scenarioLogDetail.ProcessDescription = "instruct:" + err.Error() + scenarioLogDetail.ProcessResult = "2" + } else { + if _, ok := instructMap["automation_id"]; ok { + var s TpScenarioActionService + err = s.ExecuteScenarioAction(instructMap["automation_id"], models.AutomaticallyActivated) + if err != nil { + scenarioLogDetail.ProcessDescription = "instruct:" + err.Error() + scenarioLogDetail.ProcessResult = "2" + } + } else { + scenarioLogDetail.ProcessDescription = "instruct:参数错误" + scenarioLogDetail.ProcessResult = "2" + } + } + //记录日志 + scenarioLogDetail.ScenarioLogId = scenarioLog.Id + _, err = scenarioLogDetailService.AddTpScenarioLogDetail(scenarioLogDetail) + if err != nil { + logs.Error(result.Error) + } + if scenarioLogDetail.ProcessResult == "2" { + scenarioLog.ProcessDescription = "执行中有失败,请查看日志详情" + scenarioLog.ProcessResult = "2" + } + } else if scenarioAction.ActionType == "3" { + // 触发告警 } } _, err = scenarioLogService.UpdateTpScenarioLog(scenarioLog)