liuxiaolong
2020-06-08 2a4041f16c6588921c87df93927e9076c2cc309d
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package controllers
 
import (
    "basic.com/dbapi.git"
    "github.com/gin-gonic/gin"
    "strconv"
    "webserver/extend/code"
    "webserver/extend/util"
)
 
type FileAnalysisController struct {
 
}
 
// @Security ApiKeyAuth
// @Summary 获取本地文件列表
// @Description 获取本地文件列表
// @Produce json
// @Tags 本地文件
// @Param fileName query string false "根据文件名称查询"
// @Param page query int true "当前页"
// @Param size query int true "每页数量"
// @Param type query int true "0:处理完成,1:处理中,2:未配规则,3:处理失败"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/fileAnalysis/findAllFile [get]
func (fac FileAnalysisController) FindAllFile(c *gin.Context) {
    fileName := c.Query("fileName")
    page,_ := strconv.Atoi(c.Query("page"))
    size,_ := strconv.Atoi(c.Query("size"))
    fType,_ := strconv.Atoi(c.Query("type"))
    var api dbapi.FileAnalysisApi
    b, d := api.FindAllFile(fileName, fType, page, size)
    if b {
        util.ResponseFormat(c,code.Success, d)
    } else {
        util.ResponseFormat(c,code.Success,[]interface{}{})
    }
}
 
type IdArrVo struct {
    Ids []string  `json:"ids" binding:"required"`
}
 
 
type SortVo struct {
    Id string `json:"id" binding:"required"`
    Direct int `json:"direct" binding:"required"`
}
 
type FileStatusVo struct {
    Ids []string `json:"ids" binding:"required"`
    Status int `json:"status"`
}
 
const (
    File_Img_Id_Pre = "img_"
    File_Video_Id_Pre = "video_"
    File_Audio_Id_Pre = "audio_"
)
 
// @Security ApiKeyAuth
// @Summary 开启或暂停文件分析
// @Description 开启或暂停文件分析
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param reqBody body controllers.FileStatusVo true "开启暂停参数,暂停status=0,开启status=1"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/fileAnalysis/updateStatus [post]
func (fac FileAnalysisController) UpdateStatus(c *gin.Context) {
    var reqBody FileStatusVo
    err := c.BindJSON(&reqBody)
    if err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
 
    var api dbapi.FileAnalysisApi
    if api.UpdateStatus(reqBody.Ids, reqBody.Status) {
        util.ResponseFormat(c,code.Success,"")
    } else {
        util.ResponseFormat(c,code.ComError,"")
    }
}
 
// @Security ApiKeyAuth
// @Summary 删除本地文件
// @Description 删除本地文件
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param reqBody body controllers.IdArrVo 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/fileAnalysis/delete [post]
func (fac FileAnalysisController) Delete(c *gin.Context) {
    var reqBody IdArrVo
    err := c.BindJSON(&reqBody)
    if err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
 
    var api dbapi.FileAnalysisApi
    if api.Delete(reqBody.Ids) {
        util.ResponseFormat(c,code.DelSuccess,"")
    } else {
        util.ResponseFormat(c,code.ComError,"")
    }
}
 
const (
    Sort_Up = 1
    Sort_Down = 2
)
 
// @Security ApiKeyAuth
// @Summary 本地文件排序
// @Description 本地文件排序
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param reqBody body controllers.SortVo true "排序参数,向上direct=1,向下direct=2"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/fileAnalysis/sortFile [post]
func (fac FileAnalysisController) SortFile(c *gin.Context) {
    var reqBody SortVo
    err := c.BindJSON(&reqBody)
    if err !=nil || (reqBody.Direct !=Sort_Up && reqBody.Direct !=Sort_Down) {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
 
    var api dbapi.FileAnalysisApi
    if api.SortFile(reqBody.Id,reqBody.Direct) {
        util.ResponseFormat(c,code.UpdateSuccess,"更新成功")
    } else {
        util.ResponseFormat(c,code.UpdateFail,"更新失败")
    }
 
}
 
// @Security ApiKeyAuth
// @Summary 按数据栈id查找文件
// @Description 按数据栈id查找文件
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param stackId query string true "stackId"
// @Param type query int true "type"
// @Param name query string false "搜索条件"
// @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/fileAnalysis/findByStackId [get]
func (fac FileAnalysisController) FindByStackId(c *gin.Context) {
    stackId := c.Query("stackId")
    if stackId == "" {
        util.ResponseFormat(c,code.RequestParamError, "")
        return
    }
    typ,_ := strconv.Atoi(c.Query("type"))
    page,_ := strconv.Atoi(c.Query("page"))
    size,_ := strconv.Atoi(c.Query("size"))
    name := c.Query("name")
    if page <= 0 {
        page = 1
    }
    if size <= 0 {
        size = 20
    }
    var api dbapi.FileAnalysisApi
    b,d := api.FindByStackId(stackId, typ, name, page, size)
    if !b {
        util.ResponseFormat(c,code.ComError, "")
    } else {
        util.ResponseFormat(c,code.Success, d)
    }
}
 
// @Summary 重命名
// @Description 重命名
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param id formData string true "文件id"
// @Param name formData string 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/fileAnalysis/rename [post]
func (fac FileAnalysisController) Rename(c *gin.Context) {
    id := c.Request.FormValue("id")
    name := c.Request.FormValue("name")
    if id == "" || name == "" {
        util.ResponseFormat(c,code.RequestParamError,"")
        return
    }
    var api dbapi.FileAnalysisApi
    if api.Rename(id, name) {
        util.ResponseFormat(c,code.Success, "")
    } else {
        util.ResponseFormat(c,code.ComError,"")
    }
}
 
// @Summary 移动
// @Description 移动
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param id formData string true "文件id"
// @Param stackId formData 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/fileAnalysis/move [post]
func (fac FileAnalysisController) Move(c *gin.Context) {
    id := c.Request.FormValue("id")
    stackId := c.Request.FormValue("stackId")
    if id == "" || stackId == "" {
        util.ResponseFormat(c,code.RequestParamError,"")
        return
    }
    var api dbapi.FileAnalysisApi
    if api.Move(id, stackId) {
        util.ResponseFormat(c,code.Success, "")
    } else {
        util.ResponseFormat(c,code.ComError,"")
    }
}
 
type FileMoveVo struct {
    Id string `json:"id" binding:"required"`
    StackIds []string `json:"stackIds" binding:"required"`
}
 
// @Summary 复制
// @Description 复制
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param reqBody body controllers.FileMoveVo 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/fileAnalysis/copy [post]
func (fac FileAnalysisController) Copy(c *gin.Context) {
    var reqBody FileMoveVo
    err := c.BindJSON(&reqBody)
    if err != nil {
        util.ResponseFormat(c,code.RequestParamError,"")
        return
    }
 
    var api dbapi.FileAnalysisApi
    if api.Copy(reqBody.Id, reqBody.StackIds) {
        util.ResponseFormat(c,code.Success, "")
    } else {
        util.ResponseFormat(c,code.ComError,"")
    }
}