/* * @Author: lilig * @Date: 2022-10-04 10:07:52 * @LastEditors: lilifor * @LastEditTime: 2022-10-04 10:44:58 * @FilePath: \SCD\controllers\wsController.go * @Description: * * Copyright (c) 2022 by lilig/jujutong, All Rights Reserved. */ package controllers import ( "scd_check_tools/models/bo" "strconv" ) //校验规则管理服务 type RuleController struct { BaseController } func init() { } // @Summary 获取校验规则列表 // @Description 获取校验规则列表 // @Tags 校验规则管理服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param pageindex query int false "当前页码。默认为1 " // @Param pagesize query int false "每页显示记录数。默认为20" // @Param id query int false "规则ID" // @Param enable query int false "是否启用。默认为全部" // @Param object_name query string false "规则的对象名称" // @Param object_type query int false "规则的对象分类" // @Param alert_level query string false "规则的告警级别。值为error\alert\hint之一。" // @Param apply_standard query string false "规则标准" // @Success 200 {object} ResultOK 成功 // @Failure 500 status 失败 // @router /scd/rule/list [get] func (c *RuleController) GetRuleDefList() { rule_type := c.GetString("rule_type") enable := c.GetString("enable") object_name := c.GetString("object_name") object_type := c.GetString("object_type") alert_level := c.GetString("alert_level") rule_id := c.GetString("id") pageno, _ := c.GetInt("pageindex", 1) pagesize, _ := c.GetInt("pagesize", 20) if rule_type == "" { rule_type = "logic" } obj := new(bo.ScdNodeRule) para := map[string]interface{}{} para["rule_id"] = rule_id para["rule_type"] = rule_type para["enable"] = enable para["object_name"] = object_name para["object_type"] = object_type para["alert_level"] = alert_level para["check_type"] = c.GetString("check_type") para["apply_standard"] = c.GetString("apply_standard") rowset, cnt, err := obj.GetDefList(para, pageno, pagesize) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK(rowset, cnt) c.ServeJSON() } /** * @description: 保存信息 * @Author: liling * @method: post * @parameter: * @url: /save * @content-type: application/json * @return json格式 */ // @Summary 保存校验规则 // @Description 保存校验规则 // @Tags 校验规则管理服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int false "规则ID。不为0时表示编辑" // @Param enable formData int false "是否启用。默认为全部" // @Param object_name formData string false "规则的对象名称" // @Param object_type formData int false "规则的对象分类" // @Param alert_level formData string false "规则的告警级别。值为error\alert\hint之一。" // @Param apply_standard formData string false "规则标准" // @Success 200 {object} ResultOK 成功 // @Failure 500 status 失败 // @router /scd/rule/save [post] func (c *RuleController) SaveScdRuleDef() { //变电站ID //station_id := c.GetString("station_id") rule_type := c.GetString("rule_type") if rule_type == "" { rule_type = "logic" } param := map[string]string{} flowObj := new(bo.ScdNodeRule) flowObj.SetUserInfo(c.GetCurrentUserInfo()) for k, v := range c.Ctx.Request.PostForm { param[k] = v[0] } err := flowObj.AddRuleDef(param, rule_type) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } /** * @description: 删除信息 * @Author: liling * @method: post * @parameter: user_id,id * @url: /remove * @content-type: application/json * @return json格式 */ // @Summary 删除校验规则 // @Description 删除校验规则 // @Tags 校验规则管理服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param id formData int true "规则ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 status 失败 // @router /scd/rule/remove [post] func (c *RuleController) DeleteScdRuleDef() { id := c.GetString("id") if id == "" { c.Data["json"] = c.ResultError("规则编号不能为空!") c.ServeJSON() return } rule_type := c.GetString("rule_type") if rule_type == "" { rule_type = "logic" } flowObj := new(bo.ScdNodeRule) flowObj.SetUserInfo(c.GetCurrentUserInfo()) err := flowObj.DeleteRuleDef(id, rule_type) if err != nil { c.Data["json"] = c.ResultError(err.Error()) c.ServeJSON() return } c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() } //重新校验指定scd // @Summary 重新校验指定scd // @Description 重新校验指定scd // @Tags 校验规则管理服务接口 // @Accept x-www-form-urlencoded // @Produce json // @Param scd_id formData int true "SCD文件ID" // @Success 200 {object} ResultOK 成功 // @Failure 500 status 失败 // @router /scd/rule/reset [post] func (c *RuleController) ResetRule() { id := c.GetString("scd_id") if id == "" { c.Data["json"] = c.ResultError("校验的SCD文件编号不能为空!") c.ServeJSON() return } flowObj := new(bo.ScdNodeRule) flowObj.SetUserInfo(c.GetCurrentUserInfo()) flowObj.ScdID, _ = strconv.ParseInt(id, 10, 64) flowObj.TestCheckRule() c.Data["json"] = c.ResultOK("", 0) c.ServeJSON() }