浏览代码

我的图库批量保存到素材库

xyxie 5 月之前
父节点
当前提交
4bb6872cc0
共有 2 个文件被更改,包括 28 次插入30 次删除
  1. 26 28
      controllers/material/material.go
  2. 2 2
      routers/commentsRouter.go

+ 26 - 28
controllers/material/material.go

@@ -1663,7 +1663,7 @@ func (this *MaterialController) Rename() {
 // @Description 批量下载素材
 // @Param	request	body material.DeleteSandbox true "type json string"
 // @Success 200 标记成功
-// @router /batch/download [post]
+// @router /batch/download [get]
 func (this *MaterialController) BatchDownload() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
@@ -1677,19 +1677,17 @@ func (this *MaterialController) BatchDownload() {
 		br.Ret = 408
 		return
 	}
-	var req material.BatchDeleteMaterialReq
-	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
-	if err != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-		return
-	}
+	//var req material.BatchDeleteMaterialReq
+	materialIdStr := this.GetString("MaterialIds")
+	isSelectAll, _ := this.GetBool("IsSelectAll")
+	classifyId, _ := this.GetInt("ClassifyId")
+	keyword := this.GetString("Keyword")
+	isShowMe, _ := this.GetBool("IsShowMe")
 
 	downMaterialList := make([]*material.MaterialListItems, 0)
-	if req.IsSelectAll {
-		classifyId := req.ClassifyId
-		keyword := req.Keyword
-		isShowMe := req.IsShowMe
+	materialIds := strings.Split(materialIdStr, ",")
+	var err error
+	if isSelectAll {
 		//获取图表信息
 		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser)
 		if e != nil {
@@ -1701,9 +1699,11 @@ func (this *MaterialController) BatchDownload() {
 			return
 		}
 		notSelectIds := make(map[int]struct{})
-		if len(req.MaterialIds) >= 0 {
-			for _, v := range req.MaterialIds {
-				notSelectIds[v] = struct{}{}
+		if len(materialIds) >= 0 {
+			//转成数组
+			for _, v := range materialIds {
+				id, _ := strconv.Atoi(v)
+				notSelectIds[id] = struct{}{}
 			}
 		}
 		for _, v := range list {
@@ -1712,9 +1712,14 @@ func (this *MaterialController) BatchDownload() {
 			}
 		}
 	} else {
-		if len(req.MaterialIds) > 0 {
+		if len(materialIds) > 0 {
 			// 批量查询指标数据
-			downMaterialList, err = material.GetMaterialByIds(req.MaterialIds)
+			materialIdsInt := make([]int, 0)
+			for _, v := range materialIds {
+				id, _ := strconv.Atoi(v)
+				materialIdsInt = append(materialIdsInt, id)
+			}
+			downMaterialList, err = material.GetMaterialByIds(materialIdsInt)
 			if err != nil {
 				br.Msg = "获取素材库信息失败"
 				br.ErrMsg = "获取素材库信息失败,Err:" + err.Error()
@@ -1808,7 +1813,7 @@ func (this *MaterialController) BatchDownload() {
 // @Description 下载素材
 // @Param	request	body material.DeleteSandbox true "type json string"
 // @Success 200 标记成功
-// @router /download [post]
+// @router /download [get]
 func (this *MaterialController) Download() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
@@ -1822,20 +1827,13 @@ func (this *MaterialController) Download() {
 		br.Ret = 408
 		return
 	}
-	var req material.RenameMaterialReq
-	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
-	if err != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-		return
-	}
-
-	if req.MaterialId <= 0 {
+	materialId, _ := this.GetInt("MaterialId")
+	if materialId <= 0 {
 		br.Msg = "缺少素材库编号"
 		return
 	}
 	// 判断素材是否存在
-	info, err := material.GetMaterialById(req.MaterialId)
+	info, err := material.GetMaterialById(materialId)
 	if err != nil {
 		if err.Error() == utils.ErrNoRow() {
 			br.Msg = "素材不存在"

+ 2 - 2
routers/commentsRouter.go

@@ -7391,7 +7391,7 @@ func init() {
         beego.ControllerComments{
             Method: "BatchDownload",
             Router: `/batch/download`,
-            AllowHTTPMethods: []string{"post"},
+            AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
             Filters: nil,
             Params: nil})
@@ -7490,7 +7490,7 @@ func init() {
         beego.ControllerComments{
             Method: "Download",
             Router: `/download`,
-            AllowHTTPMethods: []string{"post"},
+            AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
             Filters: nil,
             Params: nil})