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" binding:"required"`
|
}
|
|
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)
|
}
|
}
|