package controllers
|
|
import (
|
"basic.com/dbapi.git"
|
"github.com/gin-gonic/gin"
|
"github.com/gogo/protobuf/jsonpb"
|
"webserver/extend/code"
|
"webserver/extend/util"
|
)
|
|
type RuleTemplateController struct {
|
|
}
|
|
var jsonpbMarshaler = &jsonpb.Marshaler{
|
EnumsAsInts: true,
|
EmitDefaults: true,
|
OrigName: true,
|
}
|
|
type RuleTemplateVo struct {
|
Id string `json:"id"` //场景模板id
|
Name string `json:"name"` //模板名称
|
Desc string `json:"desc"` //场景描述
|
Txt string `json:"txt"` //场景策略规则组合文字
|
Rules string `json:"rules"` //具体的小规则集合
|
}
|
|
// @Summary 保存场景模板
|
// @Description 保存场景模板
|
// @Accept json
|
// @Produce json
|
// @Tags 场景模板
|
// @Param reqBody body controllers.RuleTemplateVo true "模板保存参数"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/template/rule/save [post]
|
func (rtc RuleTemplateController) Save(c *gin.Context) {
|
var reqBody map[string]interface{}
|
c.BindJSON(&reqBody)
|
var api dbapi.RuleTemplateApi
|
if api.Save(reqBody) {
|
util.ResponseFormat(c, code.Success, "保存成功")
|
} else {
|
util.ResponseFormat(c, code.ComError, "保存失败")
|
}
|
}
|
|
// @Summary 编辑
|
// @Description 编辑
|
// @Accept json
|
// @Produce json
|
// @Tags 场景模板
|
// @Param id path string true "模板id"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/template/rule/{id} [get]
|
func (rtc RuleTemplateController) Show(c *gin.Context) {
|
id := c.Param("id")
|
if id == "" {
|
util.ResponseFormat(c,code.RequestParamError, "参数有误")
|
return
|
}
|
var api dbapi.RuleTemplateApi
|
b, d := api.Show(id)
|
if b {
|
util.ResponseFormat(c,code.Success, d)
|
} else {
|
util.ResponseFormat(c,code.ComError, "")
|
}
|
}
|
|
// @Summary 根据id删除场景模板
|
// @Description 根据id删除场景模板
|
// @Accept json
|
// @Produce json
|
// @Tags 场景模板
|
// @Param id path string true "模板id"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/template/rule/{id} [delete]
|
func (rtc RuleTemplateController) Delete(c *gin.Context) {
|
id := c.Param("id")
|
if id == "" {
|
util.ResponseFormat(c,code.RequestParamError, "参数有误")
|
return
|
}
|
var api dbapi.RuleTemplateApi
|
if api.Delete(id) {
|
util.ResponseFormat(c,code.Success, "删除成功")
|
} else {
|
util.ResponseFormat(c,code.ComError, "")
|
}
|
}
|
|
// @Summary 查找所有场景模板
|
// @Description 查找所有场景模板
|
// @Accept json
|
// @Produce json
|
// @Tags 场景模板
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/template/rule [get]
|
func (rtc RuleTemplateController) FindAll(c *gin.Context) {
|
var api dbapi.RuleTemplateApi
|
b, templates := api.FindAll()
|
if b {
|
util.ResponseFormat(c,code.Success, templates)
|
} else {
|
util.ResponseFormat(c, code.ComError, "")
|
}
|
}
|