From 6365826a23e3ea636452492b209679160674ed47 Mon Sep 17 00:00:00 2001 From: marktreyvon Date: Thu, 28 Sep 2023 11:06:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/auth.go b/controllers/auth.go index 5643ddc31..0bdc6ae15 100644 --- a/controllers/auth.go +++ b/controllers/auth.go @@ -209,7 +209,7 @@ func (c *AuthController) TenantRegister() { if err != nil { response.SuccessWithMessage(400, err.Error(), (*context2.Context)(c.Ctx)) } else { - response.SuccessWithMessage(400, "注册成功", (*context2.Context)(c.Ctx)) + response.SuccessWithMessage(200, "注册成功", (*context2.Context)(c.Ctx)) } } From 06e03357f72d1c5f87b81460d7273f02ac684f36 Mon Sep 17 00:00:00 2001 From: "November.12" <845255519@qq.com> Date: Thu, 28 Sep 2023 11:07:18 +0800 Subject: [PATCH 2/2] add --- services/tp_scenario_strategy_service.go | 21 +++++++++++++++++++++ validate/tp_scenario_action_validate.go | 15 ++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/services/tp_scenario_strategy_service.go b/services/tp_scenario_strategy_service.go index 8fdc5a144..5af27e034 100644 --- a/services/tp_scenario_strategy_service.go +++ b/services/tp_scenario_strategy_service.go @@ -166,6 +166,27 @@ func (*TpScenarioStrategyService) EditTpScenarioStrategy(tp_scenario_strategy va if scenarioAction.DeviceId == "" { delete(scenarioActionMap, "DeviceId") } + + // 告警 + if scenarioAction.ActionType == "3" { + // 创建策略 + delete(scenarioActionMap, "Instruct") + scenarioAction.WarningStrategy.Id = utils.GetUuid() + result := tx.Model(&models.TpWarningStrategy{}).Create(scenarioAction.WarningStrategy) + if result.Error != nil { + tx.Rollback() + logs.Error(result.Error.Error()) + return tp_scenario_strategy, result.Error + } + warning_strategy := make(map[string]interface{}) + warning_strategy["warning_strategy_id"] = scenarioAction.WarningStrategy.Id + jsonData, err := json.Marshal(warning_strategy) + if err != nil { + return tp_scenario_strategy, err + } + scenarioActionMap["instruct"] = jsonData + } + delete(scenarioActionMap, "WarningStrategy") result := tx.Model(&models.TpScenarioAction{}).Create(scenarioActionMap) if result.Error != nil { tx.Rollback() diff --git a/validate/tp_scenario_action_validate.go b/validate/tp_scenario_action_validate.go index 5899f339c..0b123b350 100644 --- a/validate/tp_scenario_action_validate.go +++ b/validate/tp_scenario_action_validate.go @@ -3,13 +3,14 @@ package valid import "ThingsPanel-Go/models" type EditTpScenarioActionValidate struct { - Id string `json:"id" gorm:"primaryKey" valid:"MaxSize(36)"` - ScenarioStrategyId string `json:"scenario_strategy_id,omitempty" valid:"MaxSize(36)"` - ActionType string `json:"action_type,omitempty" valid:"MaxSize(2)"` - DeviceId string `json:"device_id,omitempty" valid:"MaxSize(36)"` - DeviceModel string `json:"device_model,omitempty" valid:"MaxSize(2)"` // 模型类型1-设定属性 2-调动服务 - Instruct string `json:"instruct,omitempty" valid:"MaxSize(999)"` // 指令 - Remark string `json:"remark,omitempty" valid:"MaxSize(255)"` + Id string `json:"id" gorm:"primaryKey" valid:"MaxSize(36)"` + ScenarioStrategyId string `json:"scenario_strategy_id,omitempty" valid:"MaxSize(36)"` + ActionType string `json:"action_type,omitempty" valid:"MaxSize(2)"` + DeviceId string `json:"device_id,omitempty" valid:"MaxSize(36)"` + DeviceModel string `json:"device_model,omitempty" valid:"MaxSize(2)"` // 模型类型1-设定属性 2-调动服务 + Instruct string `json:"instruct,omitempty" valid:"MaxSize(999)"` // 指令 + Remark string `json:"remark,omitempty" valid:"MaxSize(255)"` + WarningStrategy AddTpWarningStrategyValidate `json:"warning_strategy,omitempty"` } type AddTpScenarioActionValidate struct {