package controllers import ( "fmt" "github.com/goccy/go-json" "rtzh_elec_temperature/logger" "rtzh_elec_temperature/rtelec_app_public_lib/models/vo" "rtzh_elec_temperature/rtelec_app_public_lib/service" ) type AlarmTacticsController struct { BaseController } var alarmTacticsService = new(service.AlarmTactics) // 获取绝对值告警列表 // @Summary 获取绝对值告警列表 // @Description 获取绝对值告警列表 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Success 200 {object} ApiOK|ApiError 服务访问成功 // @Failure 401 status 认证未通过,一般是未指定token或token已失效 // @Failure 500 status 服务器|后台发生错误 // @router /abslist [get] func (c *AlarmTacticsController) GetAbsList() { lst := alarmTacticsService.GetAbsList() c.Data["json"] = c.ApiOK(lst) c.ServeJSON() return } // 保存绝对值告警信息 // @Summary 保存绝对值告警信息 // @Description 保存绝对值告警信息和对应的测点 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Param strategy_name query int64 true "策略名称." // @Param alarm_level query int true "告警等级." // @Param mod_name query string true "模型名称." // @Param mod_id query int64 true "模型id." // @Param operation_symbol query string true "操作符号." // @Param threshold query int true "阈值." // @Param mpjson query string true "测点id和测点名称组成的k,v键值对数组的json字符串" // @router /abssave [post] func (c *AlarmTacticsController) SaveAbsAlarmTactics() { info := vo.AlarmTacticsAbsInfo{} info.Strategy_name = c.GetString("strategy_name") level, err := c.GetInt("alarm_level") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取告警等级出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取告警等级出现转换错误!") c.ServeJSON() return } info.Alarm_level = level info.Mod_name = c.GetString("mod_name") modId, err := c.GetInt64("mod_id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("模型id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("模型id出现转换错误!") c.ServeJSON() return } info.Mod_id = modId info.Operation_symbol = c.GetString("operation_symbol") threshold, err := c.GetFloat("threshold") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("阈值出现转换错误:%s", err)) c.Data["json"] = c.ApiError("阈值出现转换错误!") c.ServeJSON() return } info.Threshold = float32(threshold) // 从前端获取测点的id和测点的名字,通过字符串序列化为json,找出attrname mpIdNameList := []map[string]interface{}{} jsonStr := c.GetString("mpjson") err = json.Unmarshal([]byte(jsonStr), &mpIdNameList) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取测点列表出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取测点列表出现转换错误!") c.ServeJSON() return } info.MpIdNameList = mpIdNameList id := alarmTacticsService.SaveAbsAlarmTactics(info) if id == 0 { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("保存绝对值告警设置出现转换错误:%s", err)) c.Data["json"] = c.ApiError("保存绝对值告警设置出现转换错误!") c.ServeJSON() return } c.Data["json"] = c.ApiOK(id) c.ServeJSON() return } //更新绝对值告警信息 // @Summary 更新绝对值告警信息 // @Description 更新绝对值告警信息和对应的测点 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Param id query int64 true "id." // @Param strategy_name query string true "策略名称." // @Param alarm_level query int true "告警等级." // @Param mod_name query string true "模型名称." // @Param mod_id query int64 true "模型id." // @Param operation_symbol query string true "操作符号." // @Param threshold query int true "阈值." // @Param mpjson query string true "测点id和测点名称组成的k,v键值对数组的json字符串" // @router /absupdate [post] func (c *AlarmTacticsController) UpdateAbsAlarmTactics() { info := vo.AlarmTacticsAbsInfo{} id, err := c.GetInt64("id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取告警id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取告警id出现转换错误!") c.ServeJSON() return } info.Id = id info.Strategy_name = c.GetString("strategy_name") level, err := c.GetInt("alarm_level") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取告警等级出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取告警等级出现转换错误!") c.ServeJSON() return } info.Alarm_level = level info.Mod_name = c.GetString("mod_name") modId, err := c.GetInt64("mod_id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("模型id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("模型id出现转换错误!") c.ServeJSON() return } info.Mod_id = modId info.Operation_symbol = c.GetString("operation_symbol") threshold, err := c.GetFloat("threshold") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("阈值出现转换错误:%s", err)) c.Data["json"] = c.ApiError("阈值出现转换错误!") c.ServeJSON() return } info.Threshold = float32(threshold) // 从前端获取测点的id和测点的名字,通过字符串序列化为json,找出mpid和mpname mpIdNameList := []map[string]interface{}{} jsonStr := c.GetString("mpjson") err = json.Unmarshal([]byte(jsonStr), &mpIdNameList) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取测点列表出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取测点列表出现转换错误!") c.ServeJSON() return } info.MpIdNameList = mpIdNameList upid, err := alarmTacticsService.UpdateAbsAlarmTactics(info) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("更新绝对值告警设置出现转换错误:%s", err)) c.Data["json"] = c.ApiError("更新绝对值告警设置出现转换错误!") c.ServeJSON() return } c.Data["json"] = c.ApiOK(upid) c.ServeJSON() return } // 删除绝对值告警信息 // @Summary 删除绝对值告警信息 // @Description 删除绝对值告警信息和对应的测点 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Param id query int64 true "告警信息id" // @router /absdel [post] func (c *AlarmTacticsController) DelAbsAlarmTactics() { id, err := c.GetInt64("id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("告警信息id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("告警信息id出现转换错误!") c.ServeJSON() return } flag := alarmTacticsService.DelAbsAlarmTactics(id) if !flag { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("删除绝对值告警信息错误:%s", err)) c.Data["json"] = c.ApiError("删除绝对值告警信息错误!") c.ServeJSON() return } c.Data["json"] = c.ApiOK(flag) c.ServeJSON() return } // 获取升温告警列表 // @Summary 获取升温告警列表 // @Description 获取升温告警列表 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Success 200 {object} ApiOK|ApiError 服务访问成功 // @Failure 401 status 认证未通过,一般是未指定token或token已失效 // @Failure 500 status 服务器|后台发生错误 // @router /riselist [get] func (c *AlarmTacticsController) GetRiseList() { lst := alarmTacticsService.GetRiseList() c.Data["json"] = c.ApiOK(lst) c.ServeJSON() return } // 保存升温告警信息 // @Summary 保存升温告警信息 // @Description 保存升温告警信息和对应的测点 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Param strategy_name query string true "策略名称." // @Param alarm_level query int true "告警等级." // @Param mod_name query string true "模型名称." // @Param mod_id query int64 true "模型id." // @Param upcycle query int true "上升周期." // @Param scope query int true "阈值." // @Param mpjson query string true "测点id和测点名称组成的k,v键值对数组的json字符串" // @router /risesave [post] func (c *AlarmTacticsController) SaveRiseAlarmTactics() { info := vo.AlarmTacticsRiseInfo{} info.Strategy_name = c.GetString("strategy_name") level, err := c.GetInt("alarm_level") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取告警等级出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取告警等级出现转换错误!") c.ServeJSON() return } info.Alarm_level = level info.Mod_name = c.GetString("mod_name") modId, err := c.GetInt64("mod_id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("模型id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("模型id出现转换错误!") c.ServeJSON() return } info.Mod_id = modId upcycle, err := c.GetInt("upcycle") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("上升周期出现转换错误:%s", err)) c.Data["json"] = c.ApiError("上升周期出现转换错误!") c.ServeJSON() return } info.Upcycle = upcycle scope, err := c.GetFloat("scope") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("阈值出现转换错误:%s", err)) c.Data["json"] = c.ApiError("阈值出现转换错误!") c.ServeJSON() return } info.Scope = float32(scope) // 从前端获取测点的id和测点的名字,通过字符串序列化为json,找出mpid和mpname mpIdNameList := []map[string]interface{}{} jsonStr := c.GetString("mpjson") err = json.Unmarshal([]byte(jsonStr), &mpIdNameList) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取测点列表出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取测点列表出现转换错误!") c.ServeJSON() return } info.MpIdNameList = mpIdNameList id := alarmTacticsService.SaveRiseAlarmTactics(info) if id == 0 { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("保存升温告警设置出现转换错误:%s", err)) c.Data["json"] = c.ApiError("保存升温告警设置出现转换错误!") c.ServeJSON() return } c.Data["json"] = c.ApiOK(id) c.ServeJSON() return } // 更新升温告警信息 // @Summary 更新升温告警信息 // @Description 更新升温告警信息和对应的测点 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Param id query int64 true "id." // @Param strategy_name query string true "策略名称." // @Param alarm_level query int true "告警等级." // @Param mod_name query string true "模型名称." // @Param mod_id query int64 true "模型id." // @Param upcycle query int true "上升周期." // @Param scope query int true "阈值." // @Param mpjson query string true "测点id和测点名称组成的k,v键值对数组的json字符串" // @router /riseupdate [post] func (c *AlarmTacticsController) UpdateRiseAlarmTactics() { info := vo.AlarmTacticsRiseInfo{} id, err := c.GetInt64("id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取告警id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取告警id出现转换错误!") c.ServeJSON() return } info.Id = id info.Strategy_name = c.GetString("strategy_name") level, err := c.GetInt("alarm_level") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取告警等级出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取告警等级出现转换错误!") c.ServeJSON() return } info.Alarm_level = level info.Mod_name = c.GetString("mod_name") modId, err := c.GetInt64("mod_id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("模型id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("模型id出现转换错误!") c.ServeJSON() return } info.Mod_id = modId upcycle, err := c.GetInt("upcycle") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("上升周期出现转换错误:%s", err)) c.Data["json"] = c.ApiError("上升周期出现转换错误!") c.ServeJSON() return } info.Upcycle = upcycle scope, err := c.GetFloat("scope") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("阈值出现转换错误:%s", err)) c.Data["json"] = c.ApiError("阈值出现转换错误!") c.ServeJSON() return } info.Scope = float32(scope) // 从前端获取测点的id和测点的名字,通过字符串序列化为json,找出mpid和mpname mpIdNameList := []map[string]interface{}{} jsonStr := c.GetString("mpjson") err = json.Unmarshal([]byte(jsonStr), &mpIdNameList) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取测点列表出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取测点列表出现转换错误!") c.ServeJSON() return } info.MpIdNameList = mpIdNameList upid, err := alarmTacticsService.UpdateRiseAlarmTactics(info) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("更新升温告警设置出现转换错误:%s", err)) c.Data["json"] = c.ApiError("更新升温告警设置出现转换错误!") c.ServeJSON() return } c.Data["json"] = c.ApiOK(upid) c.ServeJSON() return } // 删除升温告警信息 // @Summary 删除升温告警信息 // @Description 删除升温告警信息和对应的测点 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Param id query int64 true "告警信息id" // @router /risedel [post] func (c *AlarmTacticsController) DelRiseAlarmTactics() { id, err := c.GetInt64("id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("告警信息id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("告警信息id出现转换错误!") c.ServeJSON() return } flag, err := alarmTacticsService.DelRiseAlarmTactics(id) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("删除绝对值告警信息错误:%s", err)) c.Data["json"] = c.ApiError("删除绝对值告警信息错误!") c.ServeJSON() return } c.Data["json"] = c.ApiOK(flag) c.ServeJSON() return } // 获取温度不平衡告警列表 // @Summary 获取温度不平衡告警列表 // @Description 获取温度不平衡告警列表 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Success 200 {object} ApiOK|ApiError 服务访问成功 // @Failure 401 status 认证未通过,一般是未指定token或token已失效 // @Failure 500 status 服务器|后台发生错误 // @router /unbalancelist [get] func (c *AlarmTacticsController) GetUnbalanceList() { lst := alarmTacticsService.GetUnbalanceList() c.Data["json"] = c.ApiOK(lst) c.ServeJSON() return } // 保存温度不平衡告警信息 // @Summary 保存温度不平衡告警信息 // @Description 保存温度不平衡告警信息 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Param strategy_name query string true "策略名称." // @Param alarm_level query int true "告警等级." // @Param operation_symbol query string true "操作符号." // @Param threshold query int true "阈值." // @router /unbalancesave [post] func (c *AlarmTacticsController) SaveUnbalanceAlarmTactics() { info := vo.AlarmTacticsUnbalanceInfo{} info.Strategy_name = c.GetString("strategy_name") level, err := c.GetInt("alarm_level") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取告警等级出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取告警等级出现转换错误!") c.ServeJSON() return } info.Alarm_level = level info.Operation_symbol = c.GetString("operation_symbol") threshold, err := c.GetFloat("threshold") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("阈值出现转换错误:%s", err)) c.Data["json"] = c.ApiError("阈值出现转换错误!") c.ServeJSON() return } info.Threshold = float32(threshold) id, err := alarmTacticsService.SaveUnbalanceAlarmTactics(info) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("保存温度不平衡告警设置出现转换错误:%s", err)) c.Data["json"] = c.ApiError("保存温度不平衡告警设置出现转换错误!") c.ServeJSON() return } c.Data["json"] = c.ApiOK(id) c.ServeJSON() return } // 更新温度不平衡告警信息 // @Summary 更新温度不平衡告警信息 // @Description 更新温度不平衡告警信息 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Param id query int64 true "id." // @Param strategy_name query string true "策略名称." // @Param alarm_level query int true "告警等级." // @Param operation_symbol query string true "操作符号." // @Param threshold query int true "阈值." // @router /unbalanceupdate [post] func (c *AlarmTacticsController) UpdateUnbalanceAlarmTactics() { info := vo.AlarmTacticsUnbalanceInfo{} id, err := c.GetInt64("id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取告警id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取告警id出现转换错误!") c.ServeJSON() return } info.Id = id info.Strategy_name = c.GetString("strategy_name") level, err := c.GetInt("alarm_level") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("获取告警等级出现转换错误:%s", err)) c.Data["json"] = c.ApiError("获取告警等级出现转换错误!") c.ServeJSON() return } info.Alarm_level = level info.Operation_symbol = c.GetString("operation_symbol") threshold, err := c.GetFloat("threshold") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("阈值出现转换错误:%s", err)) c.Data["json"] = c.ApiError("阈值出现转换错误!") c.ServeJSON() return } info.Threshold = float32(threshold) upid, err := alarmTacticsService.UpdateUnbalanceAlarmTactics(info) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("更新温度不平衡告警设置出现转换错误:%s", err)) c.Data["json"] = c.ApiError("更新温度不平衡告警设置出现转换错误!") c.ServeJSON() return } c.Data["json"] = c.ApiOK(upid) c.ServeJSON() return } // 删除温度不平衡告警 // @Summary 删除温度不平衡告警 // @Description 删除温度不平衡告警 // @Tags api // @Accept x-www-form-urlencoded // @Produce json // @Param id query int64 true "告警信息id" // @router /unbalancedel [post] func (c *AlarmTacticsController) DelUnbalanceAlarmTactics() { id, err := c.GetInt64("id") if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("告警信息id出现转换错误:%s", err)) c.Data["json"] = c.ApiError("告警信息id出现转换错误!") c.ServeJSON() return } flag, err := alarmTacticsService.DelUnbalanceAlarmTactics(id) if err != nil { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("删除绝对值告警信息错误:%s", err)) c.Data["json"] = c.ApiError("删除绝对值告警信息错误!") c.ServeJSON() return } c.Data["json"] = c.ApiOK(flag) c.ServeJSON() return }