sunty
2020-08-20 9d88c7c467f8d93af4aab9ba0b6d6c01c2ffc546
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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, "")
    }
}