qixiaoning
2025-07-08 fe724b50b3f1b3dfe2219eb9af4bcca96c89a158
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package controllers
 
import (
    "basic.com/valib/bhomeclient.git"
    "basic.com/valib/logger.git"
    "encoding/json"
    "github.com/satori/go.uuid"
    "strconv"
    "time"
    "vamicro/stack-service/models"
    "vamicro/stack-service/service"
    "vamicro/stack-service/vo"
)
 
type FileAnalysisController struct {
 
}
 
// @Summary 获取本地文件列表
// @Description 获取本地文件列表
// @Produce json
// @Tags 本地文件
// @Param stackId query string true "数据栈id"
// @Param fileName 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/fileAnalysis/findAllFile [get]
func (fac FileAnalysisController) FindAllFile(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    fileName := c.Query("fileName")
    stackId := c.Query("stackId")
    page,_ := strconv.Atoi(c.Query("page"))
    size,_ := strconv.Atoi(c.Query("size"))
    fType,_ := strconv.Atoi(c.Query("type"))
    logger.Debug("FindAllFile fileName:",fileName,"page:",page,"size:",size,"fType:",fType,"stackId:",stackId)
    if page < 0 {
        page = 1
    }
    if size <= 0 {
        size = 20
    }
    sv := service.FileAnalysisService{Bk: h.Bk}
    result := sv.FindAllByPage(fileName, fType, page, size, stackId)
 
    return &bhomeclient.Reply{Success:true, Data:result}
}
 
// @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/fileAnalysis/show [get]
func (fac FileAnalysisController) Show(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    id := c.Query("id")
    if id == "" {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
    var file models.FileAnalysis
    rows, _ := file.SelectById(id)
    if rows >0 {
        return &bhomeclient.Reply{Success:true, Data:file}
    } else {
        return &bhomeclient.Reply{Msg:"记录不存在"}
    }
}
 
// @Summary 获取本地做任务的文件列表
// @Description 获取本地做任务的文件列表
// @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/fileAnalysis/getAnalysisFiles [get]
func (fac FileAnalysisController) GetAnalysisFiles(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    sv := service.FileAnalysisService{Bk: h.Bk}
    arr, _ := sv.GetAnalysisFiles()
    if arr !=nil && len(arr) >0 {
        return &bhomeclient.Reply{Success:true, Data:arr}
    } else {
        return &bhomeclient.Reply{Success:true, Data:[]models.FileAnalysis{}}
    }
}
 
type FileProgressVo struct {
    Ids []string `json:"ids" binding:"required"`
    Progress int `json:"progress" binding:"required"`
}
 
// @Summary 更新文件分析进度
// @Description 更新文件分析进度
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param reqBody body controllers.FileProgressVo true "更新进度参数,progress为1-100"
// @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/updateProgress [post]
func (fac FileAnalysisController) UpdateProgress(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    var reqBody FileProgressVo
    err := c.BindJSON(&reqBody)
    logger.Debug("updateProgress reqBody:",reqBody,"bindJson err:",err)
    if err !=nil {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
 
    sv := service.FileAnalysisService{Bk: h.Bk}
    if sv.UpdateProgress(reqBody.Ids, reqBody.Progress) {
        if reqBody.Progress == bhomeclient.File_Status_Complete {
            type donePub struct {
                Topic string
                Ids   []string
            }
            param := donePub{
                Topic: "FileDecodeDone",
                Ids: reqBody.Ids,
            }
            data,_ := json.Marshal(param)
            h.Bk.Publish(service.ProcName, data)
        }
 
        return &bhomeclient.Reply{Success:true, Msg:"更新成功"}
    } else {
        return &bhomeclient.Reply{Msg:"更新失败"}
    }
}
 
type FileStatusVo struct {
    Ids []string `json:"ids" binding:"required"`
    Status int `json:"status"`
}
 
// @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(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    var reqBody FileStatusVo
    err := c.BindJSON(&reqBody)
    if err !=nil {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
 
    sv := service.FileAnalysisService{Bk: h.Bk}
    if sv.UpdateStatus(reqBody.Ids, reqBody.Status) {
        return &bhomeclient.Reply{Success:true, Msg:"更新成功"}
    } else {
        return &bhomeclient.Reply{Msg:"更新失败"}
    }
}
 
 
// @Summary 删除本地文件
// @Description 删除本地文件
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param reqBody body vo.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(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    var reqBody vo.IdArrVo
    err := c.BindJSON(&reqBody)
    if err !=nil {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
 
    sv := service.FileAnalysisService{Bk: h.Bk}
    if sv.Delete(&reqBody) {
        return &bhomeclient.Reply{Success:true, Msg:"删除成功"}
    } else {
        return &bhomeclient.Reply{Msg:"删除失败"}
    }
}
 
// @Summary 本地文件排序
// @Description 本地文件排序
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param reqBody body vo.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(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    var reqBody vo.SortVo
    err := c.BindJSON(&reqBody)
    if err !=nil || (reqBody.Direct !=service.Sort_Up && reqBody.Direct !=service.Sort_Down) {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
 
    sv := service.FileAnalysisService{Bk: h.Bk}
    if sv.SortFile(&reqBody) {
        return &bhomeclient.Reply{Success:true, Msg:"更新成功"}
    } else {
        return &bhomeclient.Reply{Msg:"更新失败"}
    }
}
 
// @Summary 新增文件
// @Description 新增文件
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param reqBody body models.FileAnalysis true "文件新增json"
// @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/save [post]
func (fac FileAnalysisController) Save(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    var reqBody models.FileAnalysis
    err := c.BindJSON(&reqBody)
    if err !=nil || reqBody.StackId == "" {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
    logger.Debug("file add reqBody:", reqBody)
    if reqBody.Id == "" {
        reqBody.Id = uuid.NewV4().String()
    }
 
    reqBody.CreateTime = time.Now().Format("2006-01-02 15:04:05")
    var tmpMax models.FileAnalysis
    rows, err := tmpMax.GetMaxSortFile(reqBody.StackId)
    if err == nil && rows >0 {
        reqBody.Sort = tmpMax.Sort +1
    }
    sv := service.FileAnalysisService{Bk: h.Bk}
    if sv.Add(reqBody) {
        return &bhomeclient.Reply{Success:true, Msg:"保存成功"}
    } else {
        return &bhomeclient.Reply{Msg:"保存失败"}
    }
}
 
// @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 "每页数量"
func (fac FileAnalysisController) FindByStackId(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    stackId := c.Query("stackId")
    if stackId == "" {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
    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
    }
    sv := service.FileAnalysisService{Bk: h.Bk}
    result := sv.FindByStackId(stackId, typ, name, page, size)
    return &bhomeclient.Reply{Success:true, Data: result}
}
 
// @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(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    id := c.PostForm("id")
    name := c.PostForm("name")
    if id == "" || name == "" {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
    sv := service.FileAnalysisService{Bk: h.Bk}
    if sv.Rename(id, name) {
        return &bhomeclient.Reply{Success: true, Msg:"修改成功"}
    } else {
        return &bhomeclient.Reply{Msg:"修改失败"}
    }
}
 
// @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(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    id := c.PostForm("id")
    stackId := c.PostForm("stackId")
    if id == "" || stackId == "" {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
    var tmp models.FileAnalysis
    rows, err := tmp.SelectById(id)
    if rows > 0 && err == nil {
        sv := service.FileAnalysisService{Bk: h.Bk}
        if sv.Move(id, stackId) {
            return &bhomeclient.Reply{Success:true, Msg:"移动成功"}
        }
    }
    return &bhomeclient.Reply{Msg:"移动失败"}
}
 
// @Summary 复制
// @Description 复制
// @Accept json
// @Produce json
// @Tags 本地文件
// @Param reqBody body vo.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(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply{
    var reqBody vo.FileMoveVo
    err := c.BindJSON(&reqBody)
    if err != nil {
        return &bhomeclient.Reply{Msg:"参数有误"}
    }
 
    var tmp models.FileAnalysis
    rows, err := tmp.SelectById(reqBody.Id)
    if rows > 0 && err == nil {
        sv := service.FileAnalysisService{Bk: h.Bk}
        for _,sckId := range reqBody.StackIds {
            if sckId != tmp.StackId {
                tmp.Id = uuid.NewV4().String()
                tmp.StackId = sckId
                sv.Add(tmp)
            }
        }
 
        return &bhomeclient.Reply{Success: true, Msg:"拷贝成功"}
    }
    return &bhomeclient.Reply{Msg:"拷贝失败"}
}