sunty
2020-08-20 9303b69ea569bcb5e581147543a3fd58e90d0d25
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package controllers
 
import (
    "basic.com/valib/logger.git"
    "basic.com/dbapi.git"
    "webserver/extend/code"
    "webserver/extend/util"
    "github.com/gin-gonic/gin"
    "strconv"
)
 
type FileStackController struct {
 
}
 
// @Security ApiKeyAuth
// @Summary 获取数据栈列表
// @Description 获取数据栈列表
// @Produce json
// @Tags 数据栈
// @Param name query string false "根据数据栈名称查询"
// @Param type query int true "0:全部视频,1:视频,2:图片,3:音频,4:其他数据"
// @Param page query int true "当前页"
// @Param size query int 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/fileStack/findAllByPage [get]
func (fsc FileStackController) FindAllByPage(c *gin.Context) {
    name := c.Query("name")
    page,_ := strconv.Atoi(c.Query("page"))
    size,_ := strconv.Atoi(c.Query("size"))
    fType,_ := strconv.Atoi(c.Query("type"))
    logger.Debug("FindAllFile fileName:",name,"page:",page,"size:",size,"fType:",fType)
    if page < 0 {
        page = 1
    }
    if size <= 0 {
        size = 20
    }
    var api dbapi.FileStackApi 
    b,d := api.FindAllByPage(name, fType, page, size)
    if b {
        util.ResponseFormat(c,code.Success, d)
    } else {
        util.ResponseFormat(c,code.ComError, "")
    }
}
 
type FileStackSave struct {
    Id                  string      `json:"id"`
    Name                string      `json:"name"`
    Type                int         `json:"type"`
    Enable              bool        `json:"enable"`
    IsAutoDelFile       bool        `json:"isAutoDelFile"`
    Status              int         `json:"status"`
    CreateTime          string      `json:"createTime"`
    UpdateTime          string      `json:"updateTime"`
    Sort                int         `json:"sort"`
}
 
// @Security ApiKeyAuth
// @Summary 新增或者更新
// @Description 新增或者更新,更新时id不能为空
// @Accept json
// @Produce json
// @Tags 数据栈
// @Param reqBody body controllers.FileStackSave 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/fileStack/save [post]
func (fsc FileStackController) Save(c *gin.Context) {
    var reqBody FileStackSave
    if err := c.BindJSON(&reqBody);err !=nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    paramBody := util.Struct2Map(reqBody)
    var api dbapi.FileStackApi
    if api.Save(paramBody) {
        util.ResponseFormat(c,code.Success, "保存成功")
    } else {
        util.ResponseFormat(c,code.ComError,"保存失败")
    }
}
 
// @Security ApiKeyAuth
// @Summary 查看数据栈详情
// @Description 查看数据栈详情
// @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/fileStack/show/{id} [get]
func (fsc FileStackController) Show(c *gin.Context) {
    id := c.Param("id")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.FileStackApi
    b, d := api.Show(id)
    if b {
        util.ResponseFormat(c, code.Success, d)
    } else {
        util.ResponseFormat(c, code.ComError, "")
    }
}
 
// @Security ApiKeyAuth
// @Summary 删除
// @Description 删除
// @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/fileStack/delete/{id} [delete]
func (fsc FileStackController) Delete(c *gin.Context) {
    id := c.Param("id")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    var api dbapi.FileStackApi
    if api.Delete(id) {
        util.ResponseFormat(c, code.Success, "删除成功")
    } else {
        util.ResponseFormat(c, code.ComError, "删除失败")
    }
}
 
type EnableVo struct {
   Id string `json:"id"`
   Enable bool `json:"enable"`
}
 
// @Security ApiKeyAuth
// @Summary 切换enable
// @Description 切换enable
// @Accept json
// @Produce json
// @Tags 数据栈
// @Param reqBody body controllers.EnableVo true "切换enable"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/fileStack/changeEnable [post]
func (fsc FileStackController) ChangeEnable(c *gin.Context) {
    var reqBody EnableVo
    c.BindJSON(&reqBody)
    if reqBody.Id == "" {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.FileStackApi
    if api.ChangeEnable(reqBody.Id, reqBody.Enable) {
        util.ResponseFormat(c, code.UpdateSuccess, "更新成功")
    } else {
        util.ResponseFormat(c, code.UpdateFail, "更新失败")
    }
}