Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request ThingsPanel#221 from November-12/main
Browse files Browse the repository at this point in the history
执行激活+告警
  • Loading branch information
November-12 authored Sep 27, 2023
2 parents 80ba227 + 3323fe6 commit 3ae2ce9
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions services/tp_scenario_action_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 3ae2ce9

Please sign in to comment.