liuxiaolong
2020-06-05 7c811247ecf143e08c576986a884bedadc57dd66
controllers/fileAnalysis.go
@@ -3,6 +3,7 @@
import (
   "basic.com/dbapi.git"
   "github.com/gin-gonic/gin"
   "strconv"
   "webserver/extend/code"
   "webserver/extend/util"
)
@@ -17,13 +18,19 @@
// @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)
   b, d := api.FindAllFile(fileName, fType, page, size)
   if b {
      util.ResponseFormat(c,code.Success, d)
   } else {
@@ -38,13 +45,19 @@
type SortVo struct {
   Id string `json:"id" binding:"required"`
   Direct int `json:"direct" binding:"required" example:"1:向上,2:向下"`
   Direct int `json:"direct" binding:"required"`
}
type FileStatusVo struct {
   Ids []string `json:"ids" binding:"required"`
   Status int `json:"status" 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 开启或暂停文件分析
@@ -52,7 +65,7 @@
// @Accept json
// @Produce json
// @Tags 本地文件
// Param reqBody body controllers.FileStatusVo true "开启暂停参数,暂停status=0,开启status=1"
// @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]
@@ -78,7 +91,7 @@
// @Accept json
// @Produce json
// @Tags 本地文件
// Param reqBody body controllers.IdArrVo true "删除文件id列表"
// @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]
@@ -109,7 +122,7 @@
// @Accept json
// @Produce json
// @Tags 本地文件
// Param reqBody body controllers.SortVo true "排序参数,向上direct=1,向下direct=2"
// @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]
@@ -129,3 +142,122 @@
   }
}
// @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,"")
   }
}