Ver código fonte

Merge branch 'feature/eta2.2.6_material' of eta_server/eta_api into master

xyxie 2 semanas atrás
pai
commit
b70db36e48

+ 1 - 1
controllers/data_manage/excel/excel_info.go

@@ -1621,7 +1621,7 @@ func (c *ExcelInfoController) GetExcelTableData() {
 		}
 		excelSource = strings.Join(sourceNameList, ",")
 		excelSourceEn = strings.Join(sourceNameEnList, ",")
-	case utils.MIXED_TABLE:
+	case utils.MIXED_TABLE, utils.BALANCE_TABLE:
 		var result request.MixedTableReq
 		err = json.Unmarshal([]byte(excelInfo.Content), &result)
 		if err != nil {

+ 9 - 0
controllers/data_manage/my_chart.go

@@ -1249,6 +1249,7 @@ func (this *MyChartController) MyChartList() {
 
 	myChartId, _ := this.GetInt("MyChartId")
 	isShared, _ := this.GetBool("IsShared")
+	keyword := this.GetString("Keyword")
 
 	var total int
 	page := paging.GetPaging(currentIndex, pageSize, total)
@@ -1285,6 +1286,14 @@ func (this *MyChartController) MyChartList() {
 			chartAdminId = myClassify.AdminId
 		}
 	}
+	if keyword != "" {
+		if this.Lang == utils.LANG_EN {
+			condition += " AND (b.chart_name_en like ?) "
+		} else {
+			condition += " AND (b.chart_name like ?) "
+		}
+		pars = append(pars, "%"+keyword+"%")
+	}
 
 	condition += " AND (a.admin_id = ? OR d.is_public = 1)"
 	pars = append(pars, chartAdminId)

+ 1899 - 0
controllers/material/material.go

@@ -0,0 +1,1899 @@
+package material
+
+import (
+	"archive/zip"
+	"encoding/json"
+	"eta/eta_api/controllers"
+	"eta/eta_api/models"
+	"eta/eta_api/models/material"
+	"eta/eta_api/services"
+	materialService "eta/eta_api/services/material"
+	"eta/eta_api/utils"
+	"fmt"
+	"github.com/h2non/filetype"
+	"github.com/rdlucklib/rdluck_tools/http"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"io/ioutil"
+	"os"
+	"path"
+	"strconv"
+	"strings"
+	"time"
+)
+
+// MaterialController 逻辑导图
+type MaterialController struct {
+	controllers.BaseAuthController
+}
+
+// AddMaterialClassify
+// @Title 新增素材库分类
+// @Description 新增材库分类接口
+// @Param	request	body data_manage.AddChartClassifyReq true "type json string"
+// @Success 200 Ret=200 保存成功
+// @router /classify/add [post]
+func (this *MaterialController) AddMaterialClassify() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req material.AddMaterialClassifyReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ClassifyName == "" {
+		br.Msg = "请输入分类名称"
+		br.IsSendEmail = false
+		return
+	}
+	if req.ParentId < 0 {
+		br.Msg = "参数错误"
+		br.IsSendEmail = false
+		return
+	}
+
+	level := 1
+	levelPath := ""
+	if req.ParentId > 0 {
+		//查找父级分类
+		parentClassify, e := material.GetMaterialClassifyById(req.ParentId)
+		if e != nil {
+			br.Msg = "获取父级分类失败"
+			br.ErrMsg = "获取父级分类失败,Err:" + e.Error()
+			return
+		}
+		level = parentClassify.Level + 1
+		levelPath = parentClassify.LevelPath
+	}
+	var count int
+	switch this.Lang {
+	case utils.LANG_EN:
+		count, err = material.GetMaterialClassifyNameEnCount(req.ClassifyName, req.ParentId)
+	default:
+		count, err = material.GetMaterialClassifyNameCount(req.ClassifyName, req.ParentId)
+	}
+
+	if err != nil {
+		br.Msg = "判断名称是否已存在失败"
+		br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
+		return
+	}
+	if count > 0 {
+		br.Msg = "分类名称已存在,请重新输入"
+		br.IsSendEmail = false
+		return
+	}
+
+	//获取该层级下最大的排序数
+	classify := new(material.MaterialClassify)
+	maxSort, _ := material.GetMaterialClassifyMaxSort(req.ParentId)
+	classify.ParentId = req.ParentId
+	classify.ClassifyName = req.ClassifyName
+	classify.ClassifyNameEn = req.ClassifyName
+	classify.CreateTime = time.Now()
+	classify.ModifyTime = time.Now()
+	classify.SysUserId = this.SysUser.AdminId
+	classify.SysUserRealName = this.SysUser.RealName
+	classify.Level = level
+	classify.Sort = maxSort + 1
+	classifyId, e := material.AddMaterialClassify(classify)
+	if e != nil {
+		br.Msg = "保存分类失败"
+		br.ErrMsg = "保存分类失败,Err:" + e.Error()
+		return
+	}
+	if req.ParentId > 0 {
+		levelPath = fmt.Sprintf("%s%d,", levelPath, classifyId)
+	} else {
+		levelPath = fmt.Sprintf("%d,", classifyId)
+	}
+	classify.ClassifyId = int(classifyId)
+	classify.LevelPath = levelPath
+	e = classify.Update([]string{"LevelPath"})
+	if e != nil {
+		br.Msg = "保存分类失败"
+		br.ErrMsg = "保存分类失败,Err:" + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Msg = "保存成功"
+	br.Success = true
+}
+
+// EditMaterialClassify
+// @Title 修改素材库分类
+// @Description 修改素材库分类接口
+// @Param	request	body data_manage.EditChartClassifyReq true "type json string"
+// @Success 200 Ret=200 修改成功
+// @router /classify/edit [post]
+func (this *MaterialController) EditMaterialClassify() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req material.EditMaterialClassifyReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ClassifyName == "" {
+		br.Msg = "请输入分类名称"
+		br.IsSendEmail = false
+		return
+	}
+
+	if req.ClassifyId <= 0 {
+		br.Msg = "参数错误"
+		br.IsSendEmail = false
+		return
+	}
+
+	// 只允许修改分类名称
+	item, err := material.GetMaterialClassifyById(req.ClassifyId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "分类不存在"
+			return
+		}
+		br.Msg = "保存失败"
+		br.Msg = "获取分类信息失败,Err:" + err.Error()
+		return
+	}
+	var count int
+	updateStr := make([]string, 0)
+	switch this.Lang {
+	case utils.LANG_EN:
+		count, err = material.GetMaterialClassifyNameEnNotSelfCount(req.ClassifyId, req.ClassifyName, item.ParentId)
+		item.ClassifyNameEn = req.ClassifyName
+		updateStr = append(updateStr, "ClassifyNameEn")
+	default:
+		count, err = material.GetMaterialClassifyNameNotSelfCount(req.ClassifyId, req.ClassifyName, item.ParentId)
+		item.ClassifyName = req.ClassifyName
+		updateStr = append(updateStr, "ClassifyName")
+	}
+
+	if err != nil {
+		br.Msg = "判断名称是否已存在失败"
+		br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
+		return
+	}
+	if count > 0 {
+		br.Msg = "分类名称已存在,请重新输入"
+		br.IsSendEmail = false
+		return
+	}
+
+	item.ModifyTime = time.Now()
+	updateStr = append(updateStr, "ModifyTime")
+	err = item.Update(updateStr)
+	if err != nil {
+		br.Msg = "保存分类失败"
+		br.ErrMsg = "保存分类失败,Err:" + err.Error()
+		return
+	}
+	//todo 测试更新子集的levelPath
+	/*levelPath := ""
+	oldLevelPath := item.LevelPath
+	if item.ParentId > 0 {
+		//查找父级分类
+		parentClassify, e := material.GetMaterialClassifyById(item.ParentId)
+		if e != nil {
+			br.Msg = "获取父级分类失败"
+			br.ErrMsg = "获取父级分类失败,Err:" + e.Error()
+			return
+		}
+		levelPath = fmt.Sprintf("%s,%d", parentClassify.LevelPath, item.ClassifyId)
+		tmpList, e := material.GetMaterialClassifyByLevelPath(oldLevelPath)
+		if e != nil {
+			br.Msg = "保存分类失败"
+			br.ErrMsg = "保存分类失败,Err:" + e.Error()
+			return
+		}
+		// 把原先的父级levePath,替换成最新的父级序列
+		for _, tmp := range tmpList {
+			tmp.LevelPath = strings.Replace(tmp.LevelPath, oldLevelPath, levelPath, -1)
+			tmp.ModifyTime = time.Now()
+			e = tmp.Update([]string{"LevelPath", "ModifyTime"})
+			if e != nil {
+				br.Msg = "保存分类失败"
+				br.ErrMsg = "保存分类失败,Err:" + e.Error()
+				return
+			}
+		}
+	} else {
+		// 只有更改了父级才需要更新levelPath
+	}*/
+
+	br.Ret = 200
+	br.Msg = "保存成功"
+	br.Success = true
+	br.IsAddLog = true
+}
+
+// DeleteMaterialClassifyCheck
+// @Title 删除素材库检测接口
+// @Description 删除素材库检测接口
+// @Param	request	body data_manage.ChartClassifyDeleteCheckResp true "type json string"
+// @Success 200 Ret=200 检测成功
+// @router /classify/del/check [post]
+func (this *MaterialController) DeleteMaterialClassifyCheck() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req material.MaterialClassifyDeleteCheckReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.ClassifyId < 0 {
+		br.Msg = "参数错误"
+		br.IsSendEmail = false
+		return
+	}
+	var deleteStatus int
+	var tipsMsg string
+	//删除分类
+	// 查询当前的分类
+	classifyInfo, err := material.GetMaterialClassifyById(req.ClassifyId)
+	if err != nil {
+		br.Msg = "分类不存在"
+		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
+		return
+	}
+	// 查找当前分类以及子分类, 截取分类ID之后的字符串
+	// 获取所有子分类
+	childList, e := material.GetMaterialClassifyByLevelPath(classifyInfo.LevelPath)
+	if e != nil {
+		err = fmt.Errorf("保存分类失败,Err:" + e.Error())
+		return
+	}
+	classifyIds := make([]int, 0)
+	if len(childList) > 0 {
+		for _, item := range childList {
+			classifyIds = append(classifyIds, item.ClassifyId)
+		}
+	}
+
+	if len(classifyIds) > 0 {
+		count, e := material.GetMaterialInfoCountByClassifyIds(classifyIds)
+		if e != nil {
+			br.Msg = "删除失败"
+			br.ErrMsg = "分类下是否含有指标失败,Err:" + e.Error()
+			return
+		}
+
+		if count > 0 {
+			deleteStatus = 1
+			tipsMsg = "该分类下关联素材库不可删除"
+		} else {
+			if len(classifyIds) > 1 {
+				deleteStatus = 2
+				tipsMsg = "确认删除当前目录及包含的子目录吗"
+			}
+		}
+	}
+
+	if deleteStatus == 0 {
+		tipsMsg = "可删除,进行删除操作"
+	}
+	if this.Lang == utils.EnLangVersion {
+		if utils.ViperConfig.InConfig(tipsMsg) {
+			tipsMsg = utils.ViperConfig.GetString(tipsMsg)
+		}
+	}
+	resp := new(material.MaterialClassifyDeleteCheckResp)
+	resp.DeleteStatus = deleteStatus
+	resp.TipsMsg = tipsMsg
+	br.Ret = 200
+	br.Msg = "检测成功"
+	br.Success = true
+	br.Data = resp
+}
+
+// DeleteMaterialClassify
+// @Title 删除素材库分类/素材库
+// @Description 删除素材库分类/素材库接口
+// @Param	request	body data_manage.DeleteChartClassifyReq true "type json string"
+// @Success 200 Ret=200 删除成功
+// @router /classify/del [post]
+func (this *MaterialController) DeleteMaterialClassify() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	var req material.DeleteMaterialClassifyReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.ClassifyId < 0 {
+		br.Msg = "参数错误"
+		br.IsSendEmail = false
+		return
+	}
+
+	// 查询当前的分类
+	classifyInfo, err := material.GetMaterialClassifyById(req.ClassifyId)
+	if err != nil {
+		br.Msg = "分类不存在"
+		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
+		return
+	}
+	// 查找当前分类以及子分类, 截取分类ID之后的字符串
+	// 获取所有子分类
+	childList, e := material.GetMaterialClassifyByLevelPath(classifyInfo.LevelPath)
+	if e != nil {
+		err = fmt.Errorf("保存分类失败,Err:" + e.Error())
+		return
+	}
+	classifyIds := make([]int, 0)
+	if len(childList) > 0 {
+		for _, item := range childList {
+			classifyIds = append(classifyIds, item.ClassifyId)
+		}
+	}
+
+	if len(classifyIds) > 0 {
+		count, e := material.GetMaterialInfoCountByClassifyIds(classifyIds)
+		if e != nil {
+			br.Msg = "删除失败"
+			br.ErrMsg = "分类下是否含有指标失败,Err:" + e.Error()
+			return
+		}
+
+		if count > 0 {
+			br.Msg = "该分类下关联素材库不可删除"
+			br.IsSendEmail = false
+			return
+		}
+
+		err = material.DeleteMaterialClassify(classifyIds)
+		if err != nil {
+			br.Msg = "删除失败"
+			br.ErrMsg = "删除失败,Err:" + err.Error()
+			return
+		}
+	}
+
+	//删除素材库
+	/*if req.MaterialId > 0 {
+		materialInfo, err := material.GetMaterialById(req.MaterialId)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				br.Msg = "素材库已删除,请刷新页面"
+				br.ErrMsg = "指标不存在,Err:" + err.Error()
+				return
+			} else {
+				br.Msg = "删除失败"
+				br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
+				return
+			}
+		}
+		if materialInfo == nil {
+			br.Msg = "素材库已删除,请刷新页面"
+			return
+		}
+		err = materialService.DeleteMaterial(req.MaterialId)
+		if err != nil {
+			br.Msg = err.Error()
+			return
+		}
+	}*/
+	br.Ret = 200
+	br.Msg = "删除成功"
+	br.Success = true
+	br.IsAddLog = true
+}
+
+// ClassifyMove
+// @Title 素材库分类移动接口
+// @Description 素材库分类移动接口
+// @Success 200 {object} data_manage.MoveChartClassifyReq
+// @router /classify/move [post]
+func (this *MaterialController) ClassifyMove() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	var req material.MoveMaterialClassifyReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.ClassifyId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "分类id小于等于0"
+		return
+	}
+	//判断分类是否存在
+	materialClassifyInfo, err := material.GetMaterialClassifyById(req.ClassifyId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "分类不存在,请刷新页面"
+			br.ErrMsg = "分类不存在,Err:" + err.Error()
+			return
+		}
+		br.Msg = "移动失败"
+		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
+		return
+	}
+	if materialClassifyInfo.ParentId != req.ParentClassifyId {
+		count, err := material.GetMaterialClassifyNameNotSelfCount(materialClassifyInfo.ClassifyId, materialClassifyInfo.ClassifyName, req.ParentClassifyId)
+		if err != nil {
+			br.Msg = "判断名称是否已存在失败"
+			br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
+			return
+		}
+		if count > 0 {
+			br.Msg = "移动失败,分类名称已存在"
+			br.IsSendEmail = false
+			return
+		}
+	}
+	err, errMsg := materialService.MoveMaterialClassify(materialClassifyInfo, &req)
+	if err != nil {
+		br.Msg = errMsg
+		if errMsg == "" {
+			br.Msg = "移动失败"
+		}
+		br.ErrMsg = err.Error()
+	}
+
+	// todo权限校验
+	//移动的是分类
+	//判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
+	/*updateCol := make([]string, 0)
+	if MaterialClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
+		parentChartClassifyInfo, err := material.GetMaterialClassifyById(req.ParentClassifyId)
+		if err != nil {
+			br.Msg = "移动失败"
+			br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
+			return
+		}
+		MaterialClassifyInfo.ParentId = parentChartClassifyInfo.ClassifyId
+		MaterialClassifyInfo.Level = parentChartClassifyInfo.Level + 1
+		MaterialClassifyInfo.ModifyTime = time.Now()
+		updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
+	} else if MaterialClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId == 0 {
+		//改为一级分类
+		MaterialClassifyInfo.ParentId = req.ParentClassifyId
+		MaterialClassifyInfo.Level = 1
+		MaterialClassifyInfo.ModifyTime = time.Now()
+		updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
+	}
+
+	//如果有传入 上一个兄弟节点分类id
+	if req.PrevId > 0 {
+		if req.PrevType == 1 {
+			//上一个节点是分类
+			//上一个兄弟节点
+			prevClassify, err := material.GetMaterialClassifyById(req.PrevId)
+			if err != nil {
+				br.Msg = "移动失败"
+				br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
+				return
+			}
+
+			//如果是移动在两个兄弟节点之间
+			if req.NextId > 0 {
+				if req.NextType == 1 {
+					//上一个节点是分类 下一个节点是分类的情况
+					//下一个兄弟节点
+					nextClassify, err := material.GetMaterialClassifyById(req.NextId)
+					if err != nil {
+						br.Msg = "移动失败"
+						br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
+						return
+					}
+					//如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
+					if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == MaterialClassifyInfo.Sort {
+						//变更兄弟节点的排序
+						updateSortStr := `sort + 2`
+						_ = material.UpdateMaterialClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
+						_ = material.UpdateMaterialSortByClassifyId(prevClassify.ClassifyId, prevClassify.Sort, 0, updateSortStr)
+					} else {
+						//如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
+						if nextClassify.Sort-prevClassify.Sort == 1 {
+							//变更兄弟节点的排序
+							updateSortStr := `sort + 1`
+							_ = material.UpdateMaterialClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
+							_ = material.UpdateMaterialSortByClassifyId(prevClassify.ClassifyId, prevClassify.Sort, 0, updateSortStr)
+						}
+					}
+				} else {
+					//上一个节点是分类 下一个节点是素材库的情况
+					//下一个兄弟节点
+					nextChartInfo, err := material.GetMaterialById(req.NextId)
+					if err != nil {
+						br.Msg = "移动失败"
+						br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
+						return
+					}
+					//如果上一个兄弟(分类)与下一个兄弟(素材库)的排序权重是一致的,那么需要将下一个兄弟(素材库)(以及下个兄弟(素材库)的同样排序权重)的排序权重+2,自己变成上一个兄弟(分类)的排序权重+1
+					if prevClassify.Sort == nextChartInfo.Sort || prevClassify.Sort == MaterialClassifyInfo.Sort {
+						//变更兄弟节点的排序
+						updateSortStr := `sort + 2`
+						_ = material.UpdateMaterialClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
+						_ = material.UpdateMaterialSortByClassifyId(prevClassify.ClassifyId, prevClassify.Sort, 0, updateSortStr)
+					} else {
+						//如果下一个兄弟(素材库)的排序权重正好是上个兄弟节点(分类)的下一层,那么需要再加一层了
+						if nextChartInfo.Sort-prevClassify.Sort == 1 {
+							//变更兄弟节点的排序
+							updateSortStr := `sort + 1`
+							_ = material.UpdateMaterialClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.ClassifyId, updateSortStr)
+							_ = material.UpdateMaterialSortByClassifyId(prevClassify.ClassifyId, prevClassify.Sort, 0, updateSortStr)
+						}
+					}
+				}
+
+			}
+
+			MaterialClassifyInfo.Sort = prevClassify.Sort + 1
+			MaterialClassifyInfo.ModifyTime = time.Now()
+			updateCol = append(updateCol, "Sort", "ModifyTime")
+
+		} else {
+			//上一个节点是素材库
+			prevMaterial, err := material.GetMaterialById(req.PrevId)
+			if err != nil {
+				br.Msg = "移动失败"
+				br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
+				return
+			}
+
+			//如果是移动在两个兄弟节点之间
+			if req.NextId > 0 {
+				if req.NextType == 1 {
+					//上一个节点是素材库 下一个节点是分类的情况
+					//下一个兄弟节点
+					nextClassify, err := material.GetMaterialClassifyById(req.NextId)
+					if err != nil {
+						br.Msg = "移动失败"
+						br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
+						return
+					}
+					//如果上一个兄弟(素材库)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(素材库)的排序权重+1
+					if prevMaterial.Sort == nextClassify.Sort || prevMaterial.Sort == MaterialClassifyInfo.Sort {
+						//变更兄弟节点的排序
+						updateSortStr := `sort + 2`
+						_ = material.UpdateMaterialClassifySortByParentId(prevMaterial.ClassifyId, 0, prevMaterial.Sort, updateSortStr)
+						_ = material.UpdateMaterialSortByClassifyId(prevMaterial.ClassifyId, prevMaterial.Sort, prevMaterial.MaterialId, updateSortStr)
+					} else {
+						//如果下一个兄弟(分类)的排序权重正好是上个兄弟(素材库)节点的下一层,那么需要再加一层了
+						if nextClassify.Sort-prevMaterial.Sort == 1 {
+							//变更兄弟节点的排序
+							updateSortStr := `sort + 1`
+							_ = material.UpdateMaterialClassifySortByParentId(prevMaterial.ClassifyId, 0, prevMaterial.Sort, updateSortStr)
+							_ = material.UpdateMaterialSortByClassifyId(prevMaterial.ClassifyId, prevMaterial.Sort, prevMaterial.MaterialId, updateSortStr)
+						}
+					}
+				} else {
+					//上一个节点是素材库 下一个节点是素材库的情况
+					//下一个兄弟节点
+					nextChartInfo, err := material.GetMaterialById(req.NextId)
+					if err != nil {
+						br.Msg = "移动失败"
+						br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
+						return
+					}
+					//如果上一个兄弟(素材库)与下一个兄弟(分类)的排序权重是一致的,那么需要将下一个兄弟(分类)(以及下个兄弟(分类)的同样排序权重)的排序权重+2,自己变成上一个兄弟(素材库)的排序权重+1
+					if prevMaterial.Sort == nextChartInfo.Sort || prevMaterial.Sort == MaterialClassifyInfo.Sort {
+						//变更兄弟节点的排序
+						updateSortStr := `sort + 2`
+						_ = material.UpdateMaterialClassifySortByParentId(prevMaterial.ClassifyId, 0, prevMaterial.Sort, updateSortStr)
+						_ = material.UpdateMaterialSortByClassifyId(prevMaterial.ClassifyId, prevMaterial.Sort, prevMaterial.MaterialId, updateSortStr)
+					} else {
+						//如果下一个兄弟(分类)的排序权重正好是上个兄弟(素材库)节点的下一层,那么需要再加一层了
+						if nextChartInfo.Sort-prevMaterial.Sort == 1 {
+							//变更兄弟节点的排序
+							updateSortStr := `sort + 1`
+							_ = material.UpdateMaterialClassifySortByParentId(prevMaterial.ClassifyId, 0, prevMaterial.Sort, updateSortStr)
+							_ = material.UpdateMaterialSortByClassifyId(prevMaterial.ClassifyId, prevMaterial.Sort, prevMaterial.MaterialId, updateSortStr)
+						}
+					}
+				}
+
+			}
+			MaterialClassifyInfo.Sort = prevMaterial.Sort + 1
+			MaterialClassifyInfo.ModifyTime = time.Now()
+			updateCol = append(updateCol, "Sort", "ModifyTime")
+
+		}
+
+	} else {
+		firstClassify, err := material.GetFirstMaterialClassifyByParentId(MaterialClassifyInfo.ParentId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "移动失败"
+			br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
+			return
+		}
+
+		//如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
+		if firstClassify != nil && firstClassify.Sort == 0 {
+			updateSortStr := ` sort + 1 `
+			_ = material.UpdateMaterialClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr)
+		}
+
+		MaterialClassifyInfo.Sort = 0 //那就是排在第一位
+		MaterialClassifyInfo.ModifyTime = time.Now()
+		updateCol = append(updateCol, "Sort", "ModifyTime")
+	}
+
+	//更新
+	if len(updateCol) > 0 {
+		err = MaterialClassifyInfo.Update(updateCol)
+		if err != nil {
+			br.Msg = "移动失败"
+			br.ErrMsg = "修改失败,Err:" + err.Error()
+			return
+		}
+		// todo 记录整个层级的分类ID
+	}*/
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "移动成功"
+}
+
+// List
+// @Title 素材列表接口
+// @Description 素材列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ClassifyId   query   int  true       "分类id"
+// @Param   Keyword   query   string  true       "搜索关键词"
+// @Param   IsShowMe   query   bool  true       "是否只看我的,true、false"
+// @Success 200 {object} data_manage.ChartListResp
+// @router /list [get]
+func (this *MaterialController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	classifyId, _ := this.GetInt("ClassifyId")
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	keyword := this.GetString("Keyword")
+	keyword = strings.Trim(keyword, " ")
+	var total int
+	page := paging.GetPaging(currentIndex, pageSize, total)
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	var condition string
+	var pars []interface{}
+
+	classifyIds := make([]string, 0)
+	childClassifyMap := make(map[int]*material.MaterialClassify)
+	if classifyId > 0 {
+		classifyIds = append(classifyIds, strconv.Itoa(classifyId))
+		// 查询当前的分类
+		classifyInfo, err := material.GetMaterialClassifyById(classifyId)
+		if err != nil {
+			br.Msg = "分类不存在"
+			br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
+			return
+		}
+		// 获取所有子分类
+		childList, e := material.GetMaterialClassifyByLevelPath(classifyInfo.LevelPath)
+		if e != nil {
+			err = fmt.Errorf("保存分类失败,Err:" + e.Error())
+			return
+		}
+		// 把原先的父级levePath,替换成最新的父级序列
+		classifyIdMap := make(map[string]struct{})
+		for _, tmp := range childList {
+			childClassifyMap[tmp.ClassifyId] = tmp
+			//获取字符串前缀的位置
+			after, _ := strings.CutPrefix(tmp.LevelPath, classifyInfo.LevelPath)
+			fmt.Println("after", after)
+			// 拼接字符串
+			if after != "" {
+				ids := strings.Split(after, ",")
+				for _, v := range ids {
+					if _, ok := classifyIdMap[v]; !ok {
+						classifyIds = append(classifyIds, v)
+						classifyIdMap[v] = struct{}{}
+					}
+				}
+			}
+		}
+	}
+
+	if len(classifyIds) > 0 {
+		condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(classifyIds)) + ") "
+		pars = append(pars, classifyIds)
+	}
+
+	if keyword != "" {
+		// 将关键词按照空格拆分,并处理查询
+		keywordList := strings.Split(keyword, " ")
+		switch this.Lang {
+		case utils.LANG_EN:
+			if len(keywordList) == 1 {
+				condition += ` AND  ( material_name_en LIKE '%` + keyword + `%' )`
+			} else {
+				condition += ` AND  (`
+				for _, key := range keywordList {
+					condition += ` material_name_en LIKE '%` + key + `%' AND`
+				}
+				condition = strings.TrimSuffix(condition, "AND")
+				condition += ` )`
+			}
+		default:
+			if len(keywordList) == 1 {
+				condition += ` AND  ( material_name LIKE '%` + keyword + `%' )`
+			} else {
+				condition += ` AND  (`
+				for _, key := range keywordList {
+					condition += ` material_name LIKE '%` + key + `%' AND`
+				}
+				condition = strings.TrimSuffix(condition, "AND")
+				condition += ` )`
+			}
+		}
+	}
+
+	//只看我的
+	isShowMe, _ := this.GetBool("IsShowMe")
+	if isShowMe {
+		condition += ` AND sys_user_id = ? `
+		pars = append(pars, sysUser.AdminId)
+	}
+
+	//获取图表信息
+	list, err := material.GetMaterialListPageByCondition(condition, pars, startSize, pageSize)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Success = true
+		br.Msg = "获取素材库信息失败"
+		br.ErrMsg = "获取素材库信息失败,Err:" + err.Error()
+		return
+	}
+
+	resp := new(material.MaterialListResp)
+	if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
+		items := make([]*material.MaterialListItems, 0)
+		resp.Paging = page
+		resp.List = items
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+
+	dataCount, err := material.GetMaterialListCountByCondition(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取指标信息失败"
+		br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
+		return
+	}
+	page = paging.GetPaging(currentIndex, pageSize, dataCount)
+	resp.Paging = page
+	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// SaveAsMaterial
+// @Title 将图表等封面上传至素材库
+// @Description 将图表等封面上传至素材库
+// @Param	request	body material.AddAndEditSandbox true "type json string"
+// @Success 200 {object} material.Material
+// @router /saveAs [post]
+func (this *MaterialController) SaveAsMaterial() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req material.SaveAsMaterialReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	req.MaterialName = strings.Trim(req.MaterialName, " ")
+	if req.MaterialName == "" {
+		br.Msg = "请填写图片名称"
+		return
+	}
+	var exist *material.Material
+	switch this.Lang {
+	case utils.LANG_EN:
+		exist, err = material.GetMaterialByNameEn(req.MaterialName)
+	default:
+		// 判断名称是否重复
+		exist, err = material.GetMaterialByName(req.MaterialName)
+	}
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	if err == nil && exist.MaterialId > 0 {
+		br.Msg = "图片名称已存在"
+		return
+	}
+	err, errMsg := materialService.AddToMaterial(req, sysUser.AdminId, sysUser.RealName)
+	if err != nil {
+		br.Msg = "保存失败!"
+		if errMsg != `` {
+			br.Msg = errMsg
+		}
+		br.ErrMsg = "保存失败,Err:" + err.Error()
+		return
+	}
+
+	msg := "保存成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+}
+
+// MyChartSaveAsMaterial
+// @Title 将我的图表等封面上传至素材库
+// @Description 将图表等封面上传至素材库
+// @Param	request	body material.AddAndEditSandbox true "type json string"
+// @Success 200 {object} material.Material
+// @router /my_chart/saveAs [post]
+func (this *MaterialController) MyChartSaveAsMaterial() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req material.MyChartSaveAsMaterialReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	materialNames := make([]string, 0)
+	namesMap := make(map[string]struct{})
+	for _, v := range req.MaterialList {
+		if v.ClassifyId <= 0 {
+			br.Msg = "请选择分类"
+			return
+		}
+		v.MaterialName = strings.Trim(v.MaterialName, " ")
+		if v.MaterialName == "" {
+			br.Msg = "请填写图片名称"
+			return
+		}
+
+		if v.ChartInfoId <= 0 {
+			br.Msg = "请选择图表"
+			return
+		}
+		if v.MyChartId <= 0 {
+			br.Msg = "请选择我的图表"
+			return
+		}
+		if _, ok := namesMap[v.MaterialName]; ok {
+			br.Msg = "图片名称不能重复"
+			return
+		}
+		namesMap[v.MaterialName] = struct{}{}
+		materialNames = append(materialNames, v.MaterialName)
+	}
+	if len(materialNames) == 0 {
+		br.Msg = "请填写图片名称"
+		return
+	}
+	existList := make([]*material.Material, 0)
+	existNameMap := make(map[string]struct{})
+	switch this.Lang {
+	case utils.LANG_EN:
+		existList, err = material.GetMaterialByNameEns(materialNames)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		if len(existList) > 0 {
+			for _, v := range existList {
+				existNameMap[v.MaterialNameEn] = struct{}{}
+			}
+		}
+	default:
+		// 判断文件名是否已存在
+		existList, err = material.GetMaterialByNames(materialNames)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		if len(existList) > 0 {
+			for _, v := range existList {
+				existNameMap[v.MaterialName] = struct{}{}
+			}
+		}
+	}
+	if len(existList) > 0 {
+		br.Msg = "图片名称已存在"
+		respData := materialService.GetMyChartExistMaterialNameListMsg(existNameMap, req.MaterialList)
+		br.Data = respData
+		return
+	}
+	if len(req.MaterialList) > 30 {
+		br.Msg = "最多支持选择30个图表"
+		return
+	}
+
+	err, errMsg := materialService.MyChartAddToMaterial(req, sysUser.AdminId, sysUser.RealName)
+	if err != nil {
+		br.Msg = "保存失败!"
+		if errMsg != `` {
+			br.Msg = errMsg
+		}
+		br.ErrMsg = "保存失败,Err:" + err.Error()
+		return
+	}
+
+	msg := "保存成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+}
+
+// Delete
+// @Title 删除素材库
+// @Description 删除素材库接口
+// @Param	request	body material.DeleteSandbox true "type json string"
+// @Success 200 标记成功
+// @router /del [post]
+func (this *MaterialController) Delete() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req material.DeleteMaterial
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.MaterialId <= 0 {
+		br.Msg = "缺少素材库编号"
+		return
+	}
+
+	//删除素材库
+	err = material.DeleteByMaterialIds([]int{req.MaterialId})
+	if err != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "操作失败,Err:" + err.Error()
+		return
+	}
+
+	msg := "删除成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+}
+
+// BatchDelete
+// @Title 批量删除素材库
+// @Description 删除素材库接口
+// @Param	request	body material.DeleteSandbox true "type json string"
+// @Success 200 标记成功
+// @router /batch/del [post]
+func (this *MaterialController) BatchDelete() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		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
+	}
+	deleteMaterialIds := make([]int, 0)
+	if req.IsSelectAll {
+		classifyId := req.ClassifyId
+		keyword := req.Keyword
+		isShowMe := req.IsShowMe
+		//获取图表信息
+		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser, this.Lang)
+		if e != nil {
+			br.Msg = "获取素材库信息失败"
+			if msg != "" {
+				br.Msg = msg
+			}
+			br.ErrMsg = "获取素材库信息失败,Err:" + e.Error()
+			return
+		}
+		notSelectIds := make(map[int]struct{})
+		if len(req.MaterialIds) >= 0 {
+			for _, v := range req.MaterialIds {
+				notSelectIds[v] = struct{}{}
+			}
+		}
+		for _, v := range list {
+			if _, ok := notSelectIds[v.MaterialId]; !ok {
+				deleteMaterialIds = append(deleteMaterialIds, v.MaterialId)
+			}
+		}
+	} else {
+		deleteMaterialIds = req.MaterialIds
+	}
+
+	if len(deleteMaterialIds) <= 0 {
+		br.Msg = "请选择删除的素材"
+		return
+	}
+
+	//删除素材库
+	err = material.DeleteByMaterialIds(deleteMaterialIds)
+	if err != nil {
+		br.Msg = err.Error()
+		return
+	}
+
+	msg := "删除成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+}
+
+// GetMaterialVersionDetail
+// @Title 获取素材库版本数据详情(已保存的)
+// @Description 获取素材库版本数据详情接口(已保存的)
+// @Param   SandboxVersionCode   query   string  true       "素材库版本code"
+// @Success 200 {object} material.MaterialVersion
+// @router /detail [get]
+func (this *MaterialController) GetMaterialDetail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	sandboxId, _ := this.GetInt("SandboxId")
+	if sandboxId == 0 {
+		br.Msg = "缺少素材库Id"
+		return
+	}
+
+	//获取素材库数据详情(已保存的)
+	materialInfo, err := material.GetMaterialById(sandboxId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	msg := "获取成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+	br.Data = materialInfo
+}
+
+// MaterialClassifyList
+// @Title 获取所有素材库分类接口-不包含素材库
+// @Description 获取所有素材库分类接口-不包含素材库
+// @Param   IsShowMe   query   bool  true       "是否只看我的,true、false"
+// @Success 200 {object} data_manage.ChartClassifyListResp
+// @router /classify/list [get]
+func (this *MaterialController) MaterialClassifyList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	resp := new(material.MaterialClassifyListResp)
+
+	rootList, err := material.GetMaterialClassifyByParentId(0)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+
+	classifyAll, err := material.GetMaterialClassifyAll()
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+
+	nodeAll := make([]*material.MaterialClassifyItems, 0)
+	for k := range rootList {
+		rootNode := rootList[k]
+		materialService.MaterialClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
+		nodeAll = append(nodeAll, rootNode)
+	}
+
+	resp.AllNodes = nodeAll
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// BatchAdd
+// @Title 批量新增素材
+// @Description 新增/编辑保存素材库接口
+// @Param	request	body material.AddAndEditSandbox true "type json string"
+// @Success 200 {object} material.Material
+// @router /batch/add [post]
+func (this *MaterialController) BatchAdd() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req material.BatchAddMaterialReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	classifyId := req.ClassifyId
+	if classifyId <= 0 {
+		br.Msg = "请选择分类"
+		return
+	}
+	materialNames := make([]string, 0)
+	namesMap := make(map[string]struct{})
+	for _, v := range req.MaterialList {
+		if v.MaterialName == "" {
+			br.Msg = "请填写图片名称"
+			return
+		}
+		if v.ImgUrl == "" {
+			br.Msg = "请上传图片"
+			return
+		}
+		if _, ok := namesMap[v.MaterialName]; ok {
+			br.Msg = "图片名称不能重复"
+			return
+		}
+		namesMap[v.MaterialName] = struct{}{}
+		materialNames = append(materialNames, v.MaterialName)
+	}
+	if len(materialNames) == 0 {
+		br.Msg = "请填写图片名称"
+		return
+	}
+	existList := make([]*material.Material, 0)
+	switch this.Lang {
+	case utils.LANG_EN:
+		existList, err = material.GetMaterialByNameEns(materialNames)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		if len(existList) > 0 {
+			msg := "图片名称:"
+			for _, v := range existList {
+				msg += v.MaterialNameEn + " "
+			}
+			br.Msg = fmt.Sprintf("%s 已存在", msg)
+			return
+		}
+	default:
+		// 判断文件名是否已存在
+		existList, err = material.GetMaterialByNames(materialNames)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		if len(existList) > 0 {
+			msg := "图片名称:"
+			for _, v := range existList {
+				msg += v.MaterialName + " "
+			}
+			br.Msg = fmt.Sprintf("%s 已存在", msg)
+			return
+		}
+	}
+	err = materialService.BatchAddMaterial(req.MaterialList, classifyId, sysUser.AdminId, sysUser.RealName)
+	if err != nil {
+		br.Msg = "文件上传失败"
+		br.ErrMsg = "文件上传失败,Err:" + err.Error()
+		return
+	}
+	msg := "添加成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+}
+
+// Upload
+// @Title 上传素材
+// @Description 上传素材接口
+// @Param	request	body material.AddAndEditSandbox true "type json string"
+// @Success 200 {object} material.Material
+// @router /upload [post]
+func (this *MaterialController) Upload() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	f, h, err := this.GetFile("file")
+	if err != nil {
+		br.Msg = "获取资源信息失败"
+		br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
+		return
+	}
+	defer f.Close() //关闭上传文件
+
+	// 不依赖于文件扩展名检查文件格式
+	fileData, e := ioutil.ReadAll(f)
+	if e != nil {
+		br.Msg = "上传失败"
+		br.ErrMsg = "读取文件失败, Err: " + e.Error()
+		return
+	}
+	pass := filetype.IsImage(fileData)
+	if !pass {
+		br.Msg = "文件格式有误"
+		br.ErrMsg = "文件格式有误"
+		return
+	}
+	ext := path.Ext(h.Filename)
+	randStr := utils.GetRandStringNoSpecialChar(28)
+	fileName := randStr + ext
+
+	// 上传到阿里云
+	ossDir := utils.RESOURCE_DIR + "material_dir/"
+	savePath := ossDir + time.Now().Format("200601/20060102/") + fileName
+	// 上传文件
+	resourceUrl, err := services.CommonUploadToOssAndFileName(h, fileName, savePath)
+	if err != nil {
+		br.Msg = "文件上传失败"
+		br.ErrMsg = "文件上传失败,Err:" + err.Error()
+		return
+	}
+
+	resp := new(models.UploadImgResp)
+	resp.ResourceUrl = resourceUrl
+
+	br.Msg = "上传成功"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}
+
+// BatchChangeClassify
+// @Title 批量更换分类
+// @Description 批量更换分类
+// @Param	request	body material.DeleteSandbox true "type json string"
+// @Success 200 标记成功
+// @router /batch/changeClassify [post]
+func (this *MaterialController) BatchChangeClassify() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req material.BatchChangeClassifyMaterialReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.NewClassifyId <= 0 {
+		br.Msg = "请选择新的分类"
+		return
+	}
+	updateMaterialIds := make([]int, 0)
+	if req.IsSelectAll {
+		classifyId := req.ClassifyId
+		keyword := req.Keyword
+		isShowMe := req.IsShowMe
+		//获取图表信息
+		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser, this.Lang)
+		if e != nil {
+			br.Msg = "获取素材库信息失败"
+			if msg != "" {
+				br.Msg = msg
+			}
+			br.ErrMsg = "获取素材库信息失败,Err:" + e.Error()
+			return
+		}
+		notSelectIds := make(map[int]struct{})
+		if len(req.MaterialIds) >= 0 {
+			for _, v := range req.MaterialIds {
+				notSelectIds[v] = struct{}{}
+			}
+		}
+		for _, v := range list {
+			if _, ok := notSelectIds[v.MaterialId]; !ok {
+				updateMaterialIds = append(updateMaterialIds, v.MaterialId)
+			}
+		}
+	} else {
+		updateMaterialIds = req.MaterialIds
+	}
+
+	if len(updateMaterialIds) <= 0 {
+		br.Msg = "请选择变更的素材"
+		return
+	}
+
+	// 判断新分类是否存在
+	_, err = material.GetMaterialClassifyById(req.NewClassifyId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "分类不存在"
+			return
+		}
+		br.Msg = "获取分类信息失败"
+		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
+	}
+	//更换分类素材库
+	err = material.UpdateClassifyByMaterialIds(updateMaterialIds, req.NewClassifyId, time.Now())
+	if err != nil {
+		br.Msg = err.Error()
+		return
+	}
+
+	msg := "操作成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+}
+
+// ChangeClassify
+// @Title 更换分类
+// @Description 批量更换分类
+// @Param	request	body material.DeleteSandbox true "type json string"
+// @Success 200 标记成功
+// @router /changeClassify [post]
+func (this *MaterialController) ChangeClassify() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req material.ChangeClassifyMaterialReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.MaterialId <= 0 {
+		br.Msg = "缺少素材库编号"
+		return
+	}
+	if req.NewClassifyId <= 0 {
+		br.Msg = "请选择新的分类"
+		return
+	}
+
+	// 判断素材是否存在
+	info, err := material.GetMaterialById(req.MaterialId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "素材不存在"
+			return
+		}
+		br.Msg = "获取素材库信息失败"
+		br.ErrMsg = "获取素材库信息失败,Err:" + err.Error()
+		return
+	}
+
+	if req.NewClassifyId == info.ClassifyId {
+		br.Msg = "请选择不同的分类"
+		return
+	}
+
+	// 判断新分类是否存在
+	_, err = material.GetMaterialClassifyById(req.NewClassifyId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "分类不存在"
+			return
+		}
+		br.Msg = "获取分类信息失败"
+		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
+	}
+	info.ClassifyId = req.NewClassifyId
+	info.ModifyTime = time.Now()
+
+	//更换分类素材库
+	err = info.Update([]string{"ClassifyId", "ModifyTime"})
+	if err != nil {
+		br.Msg = err.Error()
+		return
+	}
+
+	msg := "操作成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+}
+
+// Rename
+// @Title 素材重命名
+// @Description 素材重命名
+// @Param	request	body material.DeleteSandbox true "type json string"
+// @Success 200 标记成功
+// @router /rename [post]
+func (this *MaterialController) Rename() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		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 {
+		br.Msg = "缺少素材库编号"
+		return
+	}
+	req.MaterialName = strings.Trim(req.MaterialName, " ")
+	if req.MaterialName == "" {
+		br.Msg = "请填写图片名称"
+		return
+	}
+	// 判断素材是否存在
+	info, err := material.GetMaterialById(req.MaterialId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "素材不存在"
+			return
+		}
+		br.Msg = "获取素材库信息失败"
+		br.ErrMsg = "获取素材库信息失败,Err:" + err.Error()
+		return
+	}
+	var exist *material.Material
+	updateStr := make([]string, 0)
+	switch this.Lang {
+	case utils.LANG_EN:
+		// 判断名称是否重复
+		if info.MaterialNameEn == req.MaterialName {
+			br.Msg = "名称未修改"
+			return
+		}
+		exist, err = material.GetMaterialByNameEn(req.MaterialName)
+		info.MaterialNameEn = req.MaterialName
+		updateStr = append(updateStr, "MaterialNameEn")
+	default:
+		// 判断名称是否重复
+		if info.MaterialName == req.MaterialName {
+			br.Msg = "名称未修改"
+			return
+		}
+		exist, err = material.GetMaterialByName(req.MaterialName)
+		info.MaterialName = req.MaterialName
+		updateStr = append(updateStr, "MaterialName")
+	}
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	if err == nil && exist.MaterialId > 0 {
+		br.Msg = "图片名称已存在"
+		return
+	}
+	info.ModifyTime = time.Now()
+	updateStr = append(updateStr, "ModifyTime")
+	//更换分类素材库
+	err = info.Update(updateStr)
+	if err != nil {
+		br.Msg = err.Error()
+		return
+	}
+
+	msg := "操作成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+}
+
+// BatchDownload
+// @Title 批量下载素材
+// @Description 批量下载素材
+// @Param	request	body material.DeleteSandbox true "type json string"
+// @Success 200 标记成功
+// @router /batch/download [get]
+func (this *MaterialController) BatchDownload() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		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)
+	materialIds := strings.Split(materialIdStr, ",")
+	var err error
+	if isSelectAll {
+		//获取图表信息
+		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser, this.Lang)
+		if e != nil {
+			br.Msg = "获取素材库信息失败"
+			if msg != "" {
+				br.Msg = msg
+			}
+			br.ErrMsg = "获取素材库信息失败,Err:" + e.Error()
+			return
+		}
+		notSelectIds := make(map[int]struct{})
+		if len(materialIds) >= 0 {
+			//转成数组
+			for _, v := range materialIds {
+				id, _ := strconv.Atoi(v)
+				notSelectIds[id] = struct{}{}
+			}
+		}
+		for _, v := range list {
+			if _, ok := notSelectIds[v.MaterialId]; !ok {
+				downMaterialList = append(downMaterialList, v)
+			}
+		}
+	} else {
+		if len(materialIds) > 0 {
+			// 批量查询指标数据
+			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()
+				return
+			}
+		}
+	}
+
+	if len(downMaterialList) <= 0 {
+		br.Msg = "请选择要下载的素材"
+		return
+	}
+	// 创建zip
+	zipName := time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandString(5) + ".zip"
+	savePath := zipName
+	zipFile, err := os.Create(zipName)
+	if err != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "生成压缩文件失败, Err: " + err.Error()
+		return
+	}
+	zipWriter := zip.NewWriter(zipFile)
+	// 生成zip过程中报错关闭
+	defer func() {
+		if err != nil {
+			_ = zipWriter.Close()
+			_ = zipFile.Close()
+		}
+		_ = os.Remove(savePath)
+	}()
+
+	// 获取资源, 写入zip
+	zipFileName := ""
+	for i := range downMaterialList {
+		if downMaterialList[i].MaterialName == "" || downMaterialList[i].ImgUrl == "" {
+			continue
+		}
+		fmt.Printf("开始压缩第%d个文件\n", i+1)
+		dotIndex := strings.LastIndex(downMaterialList[i].ImgUrl, ".")
+
+		// 如果找不到点,或者点是文件名的第一个字符(不合法情况),则返回空字符串
+		if dotIndex == -1 || dotIndex == 0 {
+			continue
+		}
+
+		fileExt := downMaterialList[i].ImgUrl[dotIndex+1:]
+		ioWriter, err := zipWriter.Create(fmt.Sprintf("%s.%s", downMaterialList[i].MaterialName, fileExt))
+		if err != nil {
+			if os.IsPermission(err) {
+				br.Msg = "操作失败"
+				br.ErrMsg = "打包权限不足, Err: " + err.Error()
+				return
+			}
+			br.Msg = "操作失败"
+			br.ErrMsg = "压缩出错, Err: " + err.Error()
+			return
+		}
+
+		var content []byte
+		content, err = http.Get(downMaterialList[i].ImgUrl)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "资源获取失败, Err: " + err.Error()
+			return
+		}
+		_, err = ioWriter.Write(content)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "压缩文件写入失败, Err: " + err.Error()
+			return
+		}
+		if zipFileName == "" {
+			zipFileName = downMaterialList[i].MaterialName
+		}
+		fmt.Printf("第%d个文件写入成功\n", i+1)
+	}
+	// 生成zip后关闭,否则下载文件会损坏
+	_ = zipWriter.Close()
+	_ = zipFile.Close()
+
+	this.Ctx.Output.Download(savePath, fmt.Sprintf("%s.zip", zipFileName))
+
+	msg := "操作成功"
+	br.Ret = 200
+	br.Success = true
+	br.Msg = msg
+}
+
+// Download
+// @Title 下载素材
+// @Description 下载素材
+// @Param	request	body material.DeleteSandbox true "type json string"
+// @Success 200 标记成功
+// @router /download [get]
+func (this *MaterialController) Download() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	materialId, _ := this.GetInt("MaterialId")
+	if materialId <= 0 {
+		br.Msg = "缺少素材库编号"
+		return
+	}
+	// 判断素材是否存在
+	info, err := material.GetMaterialById(materialId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "素材不存在"
+			return
+		}
+		br.Msg = "获取素材库信息失败"
+		br.ErrMsg = "获取素材库信息失败,Err:" + err.Error()
+		return
+	}
+	if info.ImgUrl == "" {
+		br.Msg = "素材地址为空"
+		return
+	}
+
+	fileName := info.MaterialName
+	// 查找文件名中最后一个点的位置
+	dotIndex := strings.LastIndex(info.ImgUrl, ".")
+
+	// 如果找不到点,或者点是文件名的第一个字符(不合法情况),则返回空字符串
+	if dotIndex == -1 || dotIndex == 0 {
+		br.Msg = "素材地址错误"
+		return
+	}
+
+	fileName += "." + info.ImgUrl[dotIndex+1:] // 添加扩展名到文件名
+	// 获取路径中的文件名
+	urlFileName := path.Base(info.ImgUrl)
+	uploadDir := utils.STATIC_DIR + "hongze/" + time.Now().Format("20060102")
+	if e := os.MkdirAll(uploadDir, utils.DIR_MOD); e != nil {
+		br.Msg = "存储目录创建失败"
+		br.ErrMsg = "存储目录创建失败, Err:" + e.Error()
+		return
+	}
+	var content []byte
+	content, err = http.Get(info.ImgUrl)
+	if err != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "资源获取失败, Err: " + err.Error()
+		return
+	}
+	filePath := uploadDir + "/" + urlFileName
+	ioWriter, err := os.Create(filePath)
+	if err != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "文件创建失败, Err: " + err.Error()
+		return
+	}
+	n, err := ioWriter.Write(content)
+	fmt.Println("n", n)
+	if err != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "压缩文件写入失败, Err: " + err.Error()
+		return
+	}
+	this.Ctx.Output.Download(filePath, fileName)
+
+	defer func() {
+		_ = os.Remove(filePath)
+	}()
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "success"
+}

+ 13 - 0
models/db.go

@@ -20,6 +20,7 @@ import (
 	edbmonitor "eta/eta_api/models/edb_monitor"
 	"eta/eta_api/models/eta_trial"
 	"eta/eta_api/models/fe_calendar"
+	"eta/eta_api/models/material"
 	"eta/eta_api/models/ppt_english"
 	"eta/eta_api/models/report"
 	"eta/eta_api/models/report_approve"
@@ -210,6 +211,9 @@ func init() {
 	// 初始化因子指标系列
 	initFactorEdbSeries()
 
+	// 注册素材库表
+	initMaterial()
+
 	// 初始化STL指标系列
 	initStlEdbInfo()
 
@@ -221,6 +225,7 @@ func init() {
 		initBinlog()
 		go binlogSvr.ListenMysql()
 	}
+
 	// 初始化部分数据表变量(直接init会有顺序问题=_=!)
 	afterInitTable()
 
@@ -662,6 +667,14 @@ func initFactorEdbSeries() {
 	)
 }
 
+// initMaterial 注册素材库表
+func initMaterial() {
+	//注册对象
+	orm.RegisterModel(
+		new(material.Material),         //素材库表
+		new(material.MaterialClassify), //素材库分类表
+	)
+}
 func initStlEdbInfo() {
 	orm.RegisterModel(
 		new(stl.CalculateStlConfig),        // STL指标配置

+ 250 - 0
models/material/material.go

@@ -0,0 +1,250 @@
+package material
+
+import (
+	"eta/eta_api/utils"
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"time"
+)
+
+type Material struct {
+	MaterialId      int       `orm:"column(material_id);pk" description:"素材id"`
+	MaterialName    string    `description:"素材名称"`
+	MaterialNameEn  string    `description:"英文素材名称"`
+	ImgUrl          string    `description:"素材图片地址"`
+	SysUserId       int       `description:"作者id"`
+	SysUserRealName string    `description:"作者名称"`
+	ModifyTime      time.Time `description:"修改时间"`
+	CreateTime      time.Time `description:"创建时间"`
+	ClassifyId      int       `description:"分类id"`
+	Sort            int       `description:"排序"`
+}
+
+// Update 素材字段变更
+func (material *Material) Update(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(material, cols...)
+	return
+}
+
+// GetMaterialById 根据素材id获取素材详情
+func GetMaterialById(MaterialId int) (materialInfo *Material, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `select * FROM material where material_id = ?`
+	err = o.Raw(sql, MaterialId).QueryRow(&materialInfo)
+	return
+}
+func DeleteByMaterialIds(ids []int) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `DELETE FROM material WHERE material_id in (` + utils.GetOrmInReplace(len(ids)) + `)`
+	_, err = o.Raw(sql, ids).Exec()
+	return
+}
+
+func UpdateClassifyByMaterialIds(ids []int, classifyId int, now time.Time) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `UPDATE material SET classify_id=?, modify_time=? WHERE material_id in (` + utils.GetOrmInReplace(len(ids)) + `) and classify_id != ?`
+	_, err = o.Raw(sql, classifyId, now, ids, classifyId).Exec()
+	return
+}
+
+// AddMultiMaterial 批量添加素材
+func AddMultiMaterial(materialInfoList []*Material) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.InsertMulti(utils.MultiAddNum, materialInfoList)
+	if err != nil {
+		return
+	}
+	return
+}
+
+// MaterialListItem 素材推演列表数据
+type MaterialListItem struct {
+	MaterialId      int    `description:"素材id"`
+	MaterialName    string `description:"素材名称"`
+	MaterialNameEn  string `description:"英文素材名称"`
+	ImgUrl          string `description:"素材图片地址"`
+	ModifyTime      string `description:"修改时间"`
+	CreateTime      string `description:"创建时间"`
+	SysUserId       int    `description:"作者id"`
+	SysUserRealName string `description:"作者名称"`
+}
+
+// MaterialSaveResp 保存素材响应体
+type MaterialSaveResp struct {
+	*Material
+}
+
+type MaterialListItems struct {
+	Material
+	ModifyTime string `description:"修改时间"`
+	CreateTime string `description:"创建时间"`
+	//ParentIds  string
+}
+
+func GetMaterialListPageByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*MaterialListItems, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM material WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += " ORDER BY create_time DESC, material_id DESC LIMIT ?,? "
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
+	return
+}
+
+func GetMaterialListByCondition(condition string, pars []interface{}) (item []*MaterialListItems, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM material WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += " ORDER BY create_time DESC, material_id DESC"
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+func GetMaterialListCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT COUNT(1) AS count FROM material WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+type MaterialListResp struct {
+	Paging *paging.PagingItem
+	List   []*MaterialListItems
+}
+
+func AddMaterial(item *Material) (lastId int64, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	lastId, err = o.Insert(item)
+	return
+}
+
+// GetMaterialByClassifyIdAndName 根据分类id和素材名获取图表信息
+func GetMaterialByClassifyIdAndName(classifyId int, name string) (item *Material, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM material WHERE classify_id = ? and material_name=? `
+	err = o.Raw(sql, classifyId, name).QueryRow(&item)
+	return
+}
+
+// GetMaterialByIds 根据素材id获取素材信息
+func GetMaterialByIds(ids []int) (items []*MaterialListItems, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM material WHERE material_id in (` + utils.GetOrmInReplace(len(ids)) + `) `
+	_, err = o.Raw(sql, ids).QueryRows(&items)
+	return
+}
+
+// SaveAsMaterialReq 添加素材的请求数据
+type SaveAsMaterialReq struct {
+	MaterialName string `description:"素材名称"`
+	ClassifyId   int    `description:"分类id"`
+	ObjectId     int    `description:"对象id"`
+	ObjectType   string `description:"对象类型:chart,excel,sandbox,sa_doc"`
+}
+
+// MyChartSaveAsMaterialReq 添加素材的
+type MyChartSaveAsMaterialReq struct {
+	MaterialList []*MyChartSaveAsMaterialItem
+}
+
+type MyChartSaveAsMaterialItem struct {
+	MaterialName string `description:"素材名称"`
+	ChartInfoId  int    `description:"图表id"`
+	MyChartId    int    `description:"我的图表ID"`
+	ClassifyId   int    `description:"分类id"`
+}
+
+// BatchAddMaterialReq 批量添加素材的请求数据
+type BatchAddMaterialReq struct {
+	MaterialList []BatchAddMaterialItem
+	ClassifyId   int `description:"分类id"`
+}
+
+type BatchAddMaterialItem struct {
+	MaterialName string `description:"素材名称"`
+	ImgUrl       string `description:"素材图片地址"`
+}
+
+// DeleteMaterial 删除素材的请求数据
+type DeleteMaterial struct {
+	MaterialId int `description:"素材id"`
+}
+
+// BatchDeleteMaterialReq 删除素材的请求数据
+type BatchDeleteMaterialReq struct {
+	MaterialIds []int  `description:"素材id"`
+	ClassifyId  int    `description:"分类id"`
+	IsShowMe    bool   `description:"操作人id,支持多选,用英文,隔开"`
+	Keyword     string `description:"关键字"`
+	IsSelectAll bool   `description:"是否选择所有素材"`
+}
+
+type BatchChangeClassifyMaterialReq struct {
+	BatchDeleteMaterialReq
+	NewClassifyId int `description:"新分类ID"`
+}
+
+type ChangeClassifyMaterialReq struct {
+	MaterialId    int `description:"素材id"`
+	NewClassifyId int `description:"新分类ID"`
+}
+
+// RenameMaterialReq 添加/编辑素材的请求数据
+type RenameMaterialReq struct {
+	MaterialId   int    `description:"素材id"`
+	MaterialName string `description:"素材名称"`
+}
+
+func GetMaterialInfoCountByClassifyIds(classifyIds []int) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT COUNT(1) AS count FROM material WHERE classify_id in(` + utils.GetOrmInReplace(len(classifyIds)) + `)`
+	err = o.Raw(sql, classifyIds).QueryRow(&count)
+	return
+}
+
+func GetMaterialByNames(materialNames []string) (items []*Material, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM material WHERE material_name in (` + utils.GetOrmInReplace(len(materialNames)) + `)`
+	_, err = o.Raw(sql, materialNames).QueryRows(&items)
+	return
+}
+
+func GetMaterialByNameEns(materialNames []string) (items []*Material, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM material WHERE material_name_en in (` + utils.GetOrmInReplace(len(materialNames)) + `)`
+	_, err = o.Raw(sql, materialNames).QueryRows(&items)
+	return
+}
+
+func GetMaterialByName(materialName string) (item *Material, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM material WHERE material_name = ?`
+	err = o.Raw(sql, materialName).QueryRow(&item)
+	return
+}
+func GetMaterialByNameEn(materialName string) (item *Material, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM material WHERE material_name_en = ?`
+	err = o.Raw(sql, materialName).QueryRow(&item)
+	return
+}
+
+// GetMaterialMaxSort 获取最大的排序数
+func GetMaterialMaxSort() (sort int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT MAX(sort) AS sort FROM material `
+	err = o.Raw(sql).QueryRow(&sort)
+	return
+}
+
+// MyChartSaveAsMaterialResp 添加素材的
+type MyChartSaveAsMaterialResp struct {
+	ExistList []*MyChartSaveAsMaterialItem
+}

+ 215 - 0
models/material/material_classify.go

@@ -0,0 +1,215 @@
+package material
+
+import (
+	"eta/eta_api/utils"
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type MaterialClassify struct {
+	ClassifyId      int       `orm:"column(classify_id);pk"`
+	ClassifyName    string    `description:"分类名称"`
+	ClassifyNameEn  string    `description:"英文分类名称"`
+	ParentId        int       `description:"父级id"`
+	CreateTime      time.Time `description:"创建时间"`
+	ModifyTime      time.Time `description:"修改时间"`
+	SysUserId       int       `description:"创建人id"`
+	SysUserRealName string    `description:"创建人姓名"`
+	Level           int       `description:"层级"`
+	Sort            int       `description:"排序字段,越小越靠前,默认值:10"`
+	LevelPath       string    `description:"层级路径"`
+}
+
+func AddMaterialClassify(item *MaterialClassify) (lastId int64, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	lastId, err = o.Insert(item)
+	return
+}
+
+// GetMaterialClassifyByParentId
+func GetMaterialClassifyByParentId(parentId int) (items []*MaterialClassifyItems, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM material_classify WHERE parent_id=? order by sort asc,classify_id asc`
+	_, err = o.Raw(sql, parentId).QueryRows(&items)
+	return
+}
+
+// GetMaterialClassifyAll
+func GetMaterialClassifyAll() (items []*MaterialClassifyItems, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM material_classify WHERE parent_id<>0 order by sort asc,classify_id asc`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+type MaterialClassifyItems struct {
+	ClassifyId     int       `orm:"column(classify_id);pk"`
+	ClassifyName   string    `description:"分类名称"`
+	ClassifyNameEn string    `description:"英文分类名称"`
+	ParentId       int       `description:"父级id"`
+	CreateTime     time.Time `description:"创建时间"`
+	ModifyTime     time.Time `description:"修改时间"`
+	SysUserId      int       `description:"创建人id"`
+	SysUserName    string    `description:"创建人姓名"`
+	Level          int       `description:"层级"`
+	Sort           int       `description:"排序字段,越小越靠前,默认值:10"`
+	Children       []*MaterialClassifyItems
+}
+
+type MaterialClassifyListResp struct {
+	AllNodes []*MaterialClassifyItems
+}
+
+type AddMaterialClassifyReq struct {
+	ClassifyName string `description:"分类名称"`
+	ParentId     int    `description:"父级id,第一级传0"`
+	//Level               int    `description:"层级,第一级传0,其余传上一级的层级"`
+}
+
+func GetMaterialClassifyNameCount(classifyName string, parentId int) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT COUNT(1) AS count FROM material_classify WHERE parent_id=? AND classify_name=? `
+	err = o.Raw(sql, parentId, classifyName).QueryRow(&count)
+	return
+}
+
+func GetMaterialClassifyNameEnCount(classifyName string, parentId int) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT COUNT(1) AS count FROM material_classify WHERE parent_id=? AND classify_name_en=? `
+	err = o.Raw(sql, parentId, classifyName).QueryRow(&count)
+	return
+}
+
+func GetMaterialClassifyNameNotSelfCount(id int, classifyName string, parentId int) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT COUNT(1) AS count FROM material_classify WHERE classify_id !=? AND parent_id=? AND classify_name=? `
+	err = o.Raw(sql, id, parentId, classifyName).QueryRow(&count)
+	return
+}
+
+func GetMaterialClassifyNameEnNotSelfCount(id int, classifyName string, parentId int) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT COUNT(1) AS count FROM material_classify WHERE classify_id !=? AND parent_id=? AND classify_name_en=? `
+	err = o.Raw(sql, id, parentId, classifyName).QueryRow(&count)
+	return
+}
+
+// GetMaterialClassifyMaxSort 获取沙盘分类下最大的排序数
+func GetMaterialClassifyMaxSort(parentId int) (sort int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT MAX(sort) AS sort FROM material_classify WHERE parent_id=? `
+	err = o.Raw(sql, parentId).QueryRow(&sort)
+	return
+}
+
+type EditMaterialClassifyReq struct {
+	ClassifyName string `description:"分类名称"`
+	ClassifyId   int    `description:"分类id"`
+}
+
+func GetMaterialClassifyById(classifyId int) (item *MaterialClassify, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM material_classify WHERE classify_id=? `
+	err = o.Raw(sql, classifyId).QueryRow(&item)
+	return
+}
+
+type MaterialClassifyDeleteCheckReq struct {
+	ClassifyId int `description:"分类id"`
+}
+
+type MaterialClassifyDeleteCheckResp struct {
+	DeleteStatus int    `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
+	TipsMsg      string `description:"提示信息"`
+}
+
+type DeleteMaterialClassifyReq struct {
+	ClassifyId int `description:"分类id"`
+	//	MaterialId int `description:"素材id"`
+}
+
+func DeleteMaterialClassify(classifyIds []int) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` DELETE FROM material_classify WHERE classify_id IN(` + utils.GetOrmInReplace(len(classifyIds)) + `) `
+	_, err = o.Raw(sql, classifyIds).Exec()
+	return
+}
+
+// MoveMaterialClassifyReq 移动沙盘分类请求参数
+type MoveMaterialClassifyReq struct {
+	ClassifyId int `description:"分类id"`
+	//MaterialId       int `description:"沙盘ID"`
+	ParentClassifyId int `description:"目标父级分类id"`
+	PrevClassifyId   int `description:"上一个兄弟节点分类id"`
+	NextClassifyId   int `description:"下一个兄弟节点分类id"`
+	//PrevType         int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
+	//NextType         int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
+}
+
+// UpdateMaterialClassifySortByParentId 根据沙盘父类id更新排序
+func UpdateMaterialClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` update material_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
+	if classifyId > 0 {
+		sql += ` or ( classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
+	}
+	_, err = o.Raw(sql, parentId, nowSort).Exec()
+	return
+}
+
+// GetFirstMaterialClassifyByParentId 获取当前父级沙盘分类下的排序第一条的数据
+func GetFirstMaterialClassifyByParentId(parentId int) (item *MaterialClassify, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM material_classify WHERE parent_id=? order by sort asc,classify_id asc limit 1`
+	err = o.Raw(sql, parentId).QueryRow(&item)
+	return
+}
+
+// Update 更新沙盘分类基础信息
+func (m *MaterialClassify) Update(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(m, cols...)
+	return
+}
+
+// GetMaterialClassifyAndInfoByParentId
+func GetMaterialClassifyAndInfoByParentId(parentId int) (items []*MaterialClassifyItems, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT *
+FROM
+	material_classify 
+WHERE
+	parent_id = ?
+ORDER BY
+	sort ASC,
+	classify_id ASC`
+	_, err = o.Raw(sql, parentId).QueryRows(&items)
+	return
+}
+
+type SandboxLinkCheckReq struct {
+	EdbInfoIdList   []int `description:"指标id列表"`
+	ChartInfoIdList []int `description:"图库id列表"`
+	ReportIdList    []int `description:"报告id列表"`
+}
+
+type SandboxLinkCheckItem struct {
+	Id         int    `description:"id"`
+	Name       string `description:"名称"`
+	UniqueCode string `description:"唯一编码"`
+	ClassifyId int    `description:"分类id"`
+}
+
+type SandboxLinkCheckResp struct {
+	EdbInfoIdList   []*SandboxLinkCheckItem `description:"指标id列表"`
+	ChartInfoIdList []*SandboxLinkCheckItem `description:"图库id列表"`
+	ReportIdList    []*SandboxLinkCheckItem `description:"报告id列表"`
+}
+
+func GetMaterialClassifyByLevelPath(levelPath string) (items []*MaterialClassify, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM material_classify where level_path like "` + levelPath + `%"`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 26 - 0
models/move_interface.go

@@ -0,0 +1,26 @@
+package models
+
+import "time"
+
+// SingleMoveNodeReq 移动请求参数
+type SingleMoveNodeReq struct {
+	NodeId       int `description:"id"`
+	ParentNodeId int `description:"父级id"`
+	PrevNodeId   int `description:"上一个兄弟节点id"`
+	NextNodeId   int `description:"下一个兄弟节点id"`
+	NodeType     int
+	/*ChartInfoId      int `description:"图表ID, 如果图表ID有值,则移动对象为图表,否则认为移动对象分类"`
+	PrevChartInfoId  int `description:"上一个图表ID"`
+	NextChartInfoId  int `description:"下一个图表ID"`*/
+}
+
+type NodeInfo struct {
+	NodeId     int `description:"id"`
+	NodeName   string
+	ParentId   int `description:"父级id"`
+	Sort       int
+	Level      int
+	LevelPath  string
+	ModifyTime time.Time
+	//Update     func([]string) (err error)
+}

+ 4 - 0
models/resource.go

@@ -57,3 +57,7 @@ type ImageSvgToPngResp struct {
 	Ret         int64  `json:"Ret"`
 	Success     bool   `json:"Success"`
 }
+
+type UploadImgResp struct {
+	ResourceUrl string `description:"资源地址"`
+}

+ 171 - 0
routers/commentsRouter.go

@@ -8134,6 +8134,177 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "BatchAdd",
+            Router: `/batch/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "BatchChangeClassify",
+            Router: `/batch/changeClassify`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "BatchDelete",
+            Router: `/batch/del`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "BatchDownload",
+            Router: `/batch/download`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "ChangeClassify",
+            Router: `/changeClassify`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "AddMaterialClassify",
+            Router: `/classify/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "DeleteMaterialClassify",
+            Router: `/classify/del`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "DeleteMaterialClassifyCheck",
+            Router: `/classify/del/check`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "EditMaterialClassify",
+            Router: `/classify/edit`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "MaterialClassifyList",
+            Router: `/classify/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "ClassifyMove",
+            Router: `/classify/move`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "Delete",
+            Router: `/del`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "GetMaterialDetail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "Download",
+            Router: `/download`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "MyChartSaveAsMaterial",
+            Router: `/my_chart/saveAs`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "Rename",
+            Router: `/rename`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "SaveAsMaterial",
+            Router: `/saveAs`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/material:MaterialController"],
+        beego.ControllerComments{
+            Method: "Upload",
+            Router: `/upload`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"],
         beego.ControllerComments{
             Method: "Approve",

+ 6 - 0
routers/router.go

@@ -29,6 +29,7 @@ import (
 	"eta/eta_api/controllers/english_report"
 	"eta/eta_api/controllers/eta_trial"
 	"eta/eta_api/controllers/fe_calendar"
+	"eta/eta_api/controllers/material"
 	"eta/eta_api/controllers/report_approve"
 	"eta/eta_api/controllers/residual_analysis"
 	"eta/eta_api/controllers/roadshow"
@@ -403,6 +404,11 @@ func init() {
 				&document_manage.DocumentManageController{},
 			),
 		),
+		web.NSNamespace("/material",
+			web.NSInclude(
+				&material.MaterialController{},
+			),
+		),
 		web.NSNamespace("/stl_decompose",
 			web.NSInclude(
 				&stl.STLController{},

+ 46 - 0
services/file.go

@@ -89,6 +89,17 @@ func saveToFile(fileMulti multipart.File, tofile string) error {
 	return nil
 }
 
+func saveToFileByHeader(fileHeader *multipart.FileHeader, tofile string) error {
+	src, err := fileHeader.Open()
+	f, err := os.OpenFile(tofile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
+	if err != nil {
+		return err
+	}
+	defer f.Close()
+	io.Copy(f, src)
+	return nil
+}
+
 // GetResourceUrlBySvgImg
 // @Description: 通过svg图片生成图片资源地址(传到OSS后的地址)
 // @author: Roc
@@ -267,3 +278,38 @@ func AddWatermarks(rs io.ReadSeeker, w io.Writer, selectedPages []string, wmList
 
 	return api.Write(ctx, w, conf)
 }
+
+// CommonUploadToOssAndFileName 通用上传文件
+func CommonUploadToOssAndFileName(fileHeader *multipart.FileHeader, newFileName, savePath string) (resourceUrl string, err error) {
+	dateDir := time.Now().Format("20060102")
+	uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
+	err = os.MkdirAll(uploadDir, utils.DIR_MOD)
+	if err != nil {
+		err = errors.New("存储目录创建失败,Err:" + err.Error())
+		return
+	}
+
+	//本地地址
+	fpath := uploadDir + "/" + newFileName
+	err = saveToFileByHeader(fileHeader, fpath)
+	if err != nil {
+		err = errors.New("文件上传失败,Err:" + err.Error())
+		return
+	}
+
+	ossClient := NewOssClient()
+	if ossClient == nil {
+		err = fmt.Errorf("初始化OSS服务失败")
+		return
+	}
+	resourceUrl, err = ossClient.UploadFile(newFileName, fpath, savePath)
+	if err != nil {
+		err = fmt.Errorf("文件上传失败, Err: %s", err.Error())
+		return
+	}
+
+	defer func() {
+		os.Remove(fpath)
+	}()
+	return
+}

+ 194 - 0
services/interface/move_interface.go

@@ -0,0 +1,194 @@
+package _interface
+
+import (
+	"errors"
+	"eta/eta_api/models"
+	"eta/eta_api/utils"
+	"time"
+)
+
+type SingleNodeMoveInterface interface {
+	GetNodeInfoById(nodeId int) (nodeInfo *models.NodeInfo, err error)
+	UpdateNodeInfoSortByParentIdAndSource(parentNodeId, nodeId, prevNodeSort int, updateSortStr string, nodeType int) (err error)
+	GetNodeMaxSort(parentId, nodeType int) (maxSort int, err error)
+	GetFirstNodeInfoByParentId(parentId int) (nodeInfo *models.NodeInfo, err error)
+}
+
+// MoveSingleNode 移动节点
+func MoveSingleNode(sm SingleNodeMoveInterface, req models.SingleMoveNodeReq) (newNodeInfo *models.NodeInfo, updateCol []string, err error, errMsg string) {
+	nodeId := req.NodeId
+	parentNodeId := req.ParentNodeId
+	prevNodeId := req.PrevNodeId
+	nextNodeId := req.NextNodeId
+	source := req.NodeType
+
+	//首先确定移动的对象是分类还是指标
+	//判断上一个节点是分类还是指标
+	//判断下一个节点是分类还是指标
+	//同时更新分类目录下的分类sort和指标sort
+	//更新当前移动的分类或者指标sort
+
+	var parentChartNodeInfo *models.NodeInfo
+	if parentNodeId > 0 {
+		parentChartNodeInfo, err = sm.GetNodeInfoById(parentNodeId)
+		if err != nil {
+			errMsg = "移动失败"
+			err = errors.New("获取上级分类信息失败,Err:" + err.Error())
+			return
+		}
+	}
+
+	//如果有传入 上一个兄弟节点分类id
+	var (
+		//nodeInfo *models.NodeInfo
+		prevNode *models.NodeInfo
+		nextNode *models.NodeInfo
+		prevSort int
+		nextSort int
+	)
+
+	// 移动对象为分类
+	nodeInfo, err := sm.GetNodeInfoById(nodeId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			errMsg = "当前分类不存在"
+			err = errors.New("获取分类信息失败,Err:" + err.Error())
+			return
+		}
+		errMsg = "移动失败"
+		err = errors.New("获取分类信息失败,Err:" + err.Error())
+		return
+	}
+
+	if prevNodeId > 0 {
+		prevNode, err = sm.GetNodeInfoById(prevNodeId)
+		if err != nil {
+			errMsg = "移动失败"
+			err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
+			return
+		}
+		prevSort = prevNode.Sort
+	}
+
+	if nextNodeId > 0 {
+		//下一个兄弟节点
+		nextNode, err = sm.GetNodeInfoById(nextNodeId)
+		if err != nil {
+			errMsg = "移动失败"
+			err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
+			return
+		}
+		nextSort = nextNode.Sort
+	}
+
+	newNodeInfo, updateCol, err, errMsg = moveSingleNode(sm, parentChartNodeInfo, nodeInfo, prevNode, nextNode, parentNodeId, prevSort, nextSort, source)
+	return
+}
+
+// moveSingleNode 移动节点
+func moveSingleNode(sm SingleNodeMoveInterface, parentChartNodeInfo, nodeInfo, prevNode, nextNode *models.NodeInfo, parentNodeId, prevSort, nextSort, source int) (newNodeInfo *models.NodeInfo, updateCol []string, err error, errMsg string) {
+	updateCol = make([]string, 0)
+	newNodeInfo = nodeInfo
+	// 移动对象为分类, 判断分类是否存在
+	oldParentId := nodeInfo.ParentId
+	//oldLevel := nodeInfo.Level
+	if oldParentId != parentNodeId {
+		// todo 更新子分类对应的level
+	}
+	//判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
+	if nodeInfo.ParentId != parentNodeId && parentNodeId != 0 {
+		if nodeInfo.Level != parentChartNodeInfo.Level+1 { //禁止层级调整
+			errMsg = "不支持目录层级变更"
+			err = errors.New("不支持目录层级变更")
+			return
+		}
+		newNodeInfo.ParentId = parentChartNodeInfo.NodeId
+		//nodeInfo.RootId = parentChartNodeInfo.RootId
+		newNodeInfo.Level = parentChartNodeInfo.Level + 1
+		newNodeInfo.ModifyTime = time.Now()
+		//updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
+		updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
+	} else if nodeInfo.ParentId != parentNodeId && parentNodeId == 0 {
+		errMsg = "不支持目录层级变更"
+		err = errors.New("不支持目录层级变更")
+		return
+	}
+
+	if prevSort > 0 {
+		//如果是移动在两个兄弟节点之间
+		if nextSort > 0 {
+			//下一个兄弟节点
+			//如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
+			if prevSort == nextSort || prevSort == nodeInfo.Sort {
+				//变更兄弟节点的排序
+				updateSortStr := `sort + 2`
+
+				//变更分类
+				if prevNode != nil {
+					_ = sm.UpdateNodeInfoSortByParentIdAndSource(parentNodeId, prevNode.NodeId, prevNode.Sort, updateSortStr, source)
+				} else {
+					_ = sm.UpdateNodeInfoSortByParentIdAndSource(parentNodeId, 0, prevSort, updateSortStr, source)
+				}
+			} else {
+				//如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
+				if nextSort-prevSort == 1 {
+					//变更兄弟节点的排序
+					updateSortStr := `sort + 1`
+
+					//变更分类
+					if prevNode != nil {
+						_ = sm.UpdateNodeInfoSortByParentIdAndSource(parentNodeId, prevNode.NodeId, prevSort, updateSortStr, source)
+					} else {
+						_ = sm.UpdateNodeInfoSortByParentIdAndSource(parentNodeId, 0, prevSort, updateSortStr, source)
+					}
+				}
+			}
+		}
+
+		newNodeInfo.Sort = prevSort + 1
+		newNodeInfo.ModifyTime = time.Now()
+		updateCol = append(updateCol, "Sort", "ModifyTime")
+	} else if prevNode == nil && nextNode == nil && parentNodeId > 0 {
+		//处理只拖动到目录里,默认放到目录底部的情况
+		var maxSort int
+		maxSort, err = sm.GetNodeMaxSort(parentNodeId, source)
+		if err != nil {
+			errMsg = "移动失败"
+			err = errors.New("查询组内排序信息失败,Err:" + err.Error())
+			return
+		}
+		newNodeInfo.Sort = maxSort + 1 //那就是排在组内最后一位
+		newNodeInfo.ModifyTime = time.Now()
+		updateCol = append(updateCol, "Sort", "ModifyTime")
+	} else {
+		// 拖动到父级分类的第一位
+		firstClassify, tmpErr := sm.GetFirstNodeInfoByParentId(parentNodeId)
+		if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+			errMsg = "移动失败"
+			err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
+			return
+		}
+
+		//如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
+		if firstClassify != nil && firstClassify.Sort == 0 {
+			updateSortStr := ` sort + 1 `
+			_ = sm.UpdateNodeInfoSortByParentIdAndSource(parentNodeId, firstClassify.NodeId-1, 0, updateSortStr, source)
+		}
+
+		newNodeInfo.Sort = 0 //那就是排在第一位
+		newNodeInfo.ModifyTime = time.Now()
+		updateCol = append(updateCol, "Sort", "ModifyTime")
+	}
+
+	// todo 更新层级
+	if len(updateCol) > 0 {
+		/*err = nodeInfo.Update(updateCol)
+		if err != nil {
+			errMsg = "移动失败"
+			err = errors.New("修改失败,Err:" + err.Error())
+			return
+		}*/
+		// todo 更新对应分类的root_id和层级
+	}
+	return
+}

+ 522 - 0
services/material/material.go

@@ -0,0 +1,522 @@
+package materialService
+
+import (
+	"eta/eta_api/models"
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/models/data_manage/excel"
+	"eta/eta_api/models/material"
+	"eta/eta_api/models/sandbox"
+	"eta/eta_api/models/semantic_analysis"
+	"eta/eta_api/models/system"
+	"eta/eta_api/services"
+	_interface "eta/eta_api/services/interface"
+	"eta/eta_api/utils"
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/http"
+	"os"
+	"path"
+	"strconv"
+	"strings"
+	"time"
+)
+
+func materialClassifyHaveChild(allNode []*material.MaterialClassifyItems, node *material.MaterialClassifyItems) (childs []*material.MaterialClassifyItems, yes bool) {
+	for _, v := range allNode {
+		if v.ParentId == node.ClassifyId {
+			childs = append(childs, v)
+		}
+	}
+	if len(childs) > 0 {
+		yes = true
+	}
+	return
+}
+
+func MaterialClassifyItemsMakeTree(sysUser *system.Admin, allNode []*material.MaterialClassifyItems, node *material.MaterialClassifyItems) {
+
+	childs, _ := materialClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
+	if len(childs) > 0 {
+
+		node.Children = append(node.Children, childs[0:]...) //添加子节点
+		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
+			_, has := materialClassifyHaveChild(allNode, v)
+			if has {
+				MaterialClassifyItemsMakeTree(sysUser, allNode, v) //递归添加节点
+			} else {
+				childrenArr := make([]*material.MaterialClassifyItems, 0)
+				v.Children = childrenArr
+			}
+		}
+	} else {
+		childrenArr := make([]*material.MaterialClassifyItems, 0)
+		node.Children = childrenArr
+	}
+}
+
+func BatchAddMaterial(materialList []material.BatchAddMaterialItem, classifyId, opUserId int, opUserName string) (err error) {
+	addList := make([]*material.Material, 0)
+	sort, err := material.GetMaterialMaxSort()
+	if err != nil {
+		return
+	}
+	for _, v := range materialList {
+		sort = sort + 1
+		addList = append(addList, &material.Material{
+			MaterialName:    v.MaterialName,
+			MaterialNameEn:  v.MaterialName,
+			ImgUrl:          v.ImgUrl,
+			SysUserId:       opUserId,
+			SysUserRealName: opUserName,
+			ModifyTime:      time.Now(),
+			CreateTime:      time.Now(),
+			ClassifyId:      classifyId,
+			Sort:            sort,
+		})
+	}
+	if len(addList) > 0 {
+		err = material.AddMultiMaterial(addList)
+	}
+	return
+}
+
+// AddToMaterial 将图库等封面上传至素材库
+func AddToMaterial(req material.SaveAsMaterialReq, opUserId int, opUserName string) (err error, errMsg string) {
+	// 判断出对应的类型,得倒最终的资源地址
+	oldRsourceUrl := ""
+	switch req.ObjectType {
+	case "chart":
+		// 获取图表封面地址
+		chartInfo, e := data_manage.GetChartInfoById(req.ObjectId)
+		if e != nil {
+			if e.Error() == utils.ErrNoRow() {
+				errMsg = "图表不存在"
+				err = fmt.Errorf("图表不存在")
+				return
+			}
+			errMsg = "获取图表信息失败"
+			err = e
+			return
+		}
+		if chartInfo.ChartImage == "" {
+			errMsg = "图表封面为空"
+			err = fmt.Errorf("图表封面为空")
+			return
+		}
+		oldRsourceUrl = chartInfo.ChartImage
+	case "sandbox":
+		// 获取逻辑图
+		sandboxInfo, e := sandbox.GetSandboxById(req.ObjectId)
+		if e != nil {
+			if e.Error() == utils.ErrNoRow() {
+				errMsg = "逻辑图不存在"
+				err = fmt.Errorf("逻辑图不存在")
+				return
+			}
+			errMsg = "获取逻辑图信息失败"
+			err = e
+			return
+		}
+		if sandboxInfo.PicUrl == "" { // 获取逻辑图封面地址
+			errMsg = "逻辑图封面为空"
+			err = fmt.Errorf("逻辑图封面为空")
+			return
+		}
+		oldRsourceUrl = sandboxInfo.PicUrl
+	case "excel":
+		// 获取表格封面地址
+		excelInfo, e := excel.GetExcelViewInfoByExcelInfoId(req.ObjectId)
+		if e != nil {
+			if e.Error() == utils.ErrNoRow() {
+				errMsg = "表格不存在"
+				err = fmt.Errorf("表格不存在")
+				return
+			}
+			errMsg = "获取表格信息失败"
+			err = e
+			return
+		}
+		if excelInfo.ExcelImage == "" {
+			errMsg = "表格封面为空"
+			err = fmt.Errorf("表格封面为空")
+			return
+		}
+		oldRsourceUrl = excelInfo.ExcelImage
+	case "sa_doc":
+		// 获取文档封面地址
+		docObj := new(semantic_analysis.SaCompare)
+		e := docObj.GetItemById(req.ObjectId)
+		if e != nil { // 获取文档信息
+			if e.Error() == utils.ErrNoRow() {
+				errMsg = "文档不存在"
+				err = fmt.Errorf("文档不存在")
+				return
+			}
+			errMsg = "获取文档信息失败"
+			err = e
+			return
+		}
+		if docObj.ResultImg == "" {
+			errMsg = "文档封面为空"
+			err = fmt.Errorf("文档封面为空")
+			return
+		}
+
+		oldRsourceUrl = docObj.ResultImg
+	default:
+		errMsg = "不支持的类型"
+		err = fmt.Errorf("不支持的类型")
+		return
+	}
+
+	resourceUrl, err, errMsg := uploadToMaterial(oldRsourceUrl)
+	if err != nil {
+		return
+	}
+	// 新增素材库
+
+	sort, err := material.GetMaterialMaxSort()
+	if err != nil {
+		return
+	}
+	//素材主表信息
+	materialInfo := &material.Material{
+		MaterialName:    req.MaterialName,
+		MaterialNameEn:  req.MaterialName,
+		ImgUrl:          resourceUrl,
+		SysUserId:       opUserId,
+		SysUserRealName: opUserName,
+		ModifyTime:      time.Now(),
+		CreateTime:      time.Now(),
+		ClassifyId:      req.ClassifyId,
+		Sort:            sort + 1,
+	}
+
+	//新增素材
+	id, err := material.AddMaterial(materialInfo)
+	if err != nil {
+		return
+	}
+	materialInfo.MaterialId = int(id)
+	return
+}
+
+// MyChartAddToMaterial 将我的
+func MyChartAddToMaterial(req material.MyChartSaveAsMaterialReq, opUserId int, opUserName string) (err error, errMsg string) {
+	// 判断出对应的类型,得倒最终的资源地址
+	// 获取图表ID
+	chartInfoIds := make([]int, 0)
+	for _, v := range req.MaterialList {
+		chartInfoIds = append(chartInfoIds, v.ChartInfoId)
+	}
+	// 获取图表信息
+	if len(chartInfoIds) <= 0 {
+		return
+	}
+	chartInfoList, e := data_manage.GetChartInfoByIdList(chartInfoIds)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			errMsg = "图表不存在"
+			err = fmt.Errorf("图表不存在")
+			return
+		}
+		errMsg = "获取图表信息失败"
+		err = e
+		return
+	}
+	chartInfoMap := make(map[int]string)
+	for _, v := range chartInfoList {
+		if v.ChartImage == "" {
+			errMsg = "图表封面为空"
+			err = fmt.Errorf("图表封面为空")
+			return
+		}
+		chartInfoMap[v.ChartInfoId] = v.ChartImage
+	}
+	addList := make([]*material.Material, 0)
+	sort, err := material.GetMaterialMaxSort()
+	if err != nil {
+		return
+	}
+	for _, v := range req.MaterialList {
+		sort = sort + 1
+		oldResourceUrl, ok := chartInfoMap[v.ChartInfoId]
+		if !ok {
+			return
+		}
+		resourceUrl := ""
+		resourceUrl, err, errMsg = uploadToMaterial(oldResourceUrl)
+		if err != nil {
+			return
+		}
+		// 新增素材库
+
+		//素材主表信息
+		materialInfo := &material.Material{
+			MaterialName:    v.MaterialName,
+			MaterialNameEn:  v.MaterialName,
+			ImgUrl:          resourceUrl,
+			SysUserId:       opUserId,
+			SysUserRealName: opUserName,
+			ModifyTime:      time.Now(),
+			CreateTime:      time.Now(),
+			ClassifyId:      v.ClassifyId,
+			Sort:            sort,
+		}
+		addList = append(addList, materialInfo)
+	}
+	if len(addList) > 0 {
+		err = material.AddMultiMaterial(addList)
+	}
+	return
+}
+func uploadToMaterial(oldRsourceUrl string) (resourceUrl string, err error, errMsg string) {
+	// 下载资源地址内容,并上传至存储空间得倒最终的素材地址
+	urlFileName := path.Base(oldRsourceUrl)
+	uploadDir := utils.STATIC_DIR + "hongze/" + time.Now().Format("20060102")
+	if e := os.MkdirAll(uploadDir, utils.DIR_MOD); e != nil {
+		errMsg = "存储目录创建失败"
+		err = fmt.Errorf("存储目录创建失败, Err:" + e.Error())
+		return
+	}
+	var content []byte
+	content, err = http.Get(oldRsourceUrl)
+	if err != nil {
+		errMsg = "操作失败"
+		err = fmt.Errorf("资源获取失败, Err: " + err.Error())
+		return
+	}
+	filePath := uploadDir + "/" + urlFileName
+	ioWriter, err := os.Create(filePath)
+	if err != nil {
+		errMsg = "操作失败"
+		err = fmt.Errorf("文件创建失败, Err: " + err.Error())
+		return
+	}
+	n, err := ioWriter.Write(content)
+	fmt.Println("n", n)
+	if err != nil {
+		errMsg = "操作失败"
+		err = fmt.Errorf("压缩文件写入失败, Err: " + err.Error())
+		return
+	}
+	ext := path.Ext(urlFileName)
+	randStr := utils.GetRandStringNoSpecialChar(28)
+	newFileName := randStr + ext
+
+	// 上传到阿里云
+	ossDir := utils.RESOURCE_DIR + "material_dir/"
+	savePath := ossDir + time.Now().Format("200601/20060102/") + newFileName
+	// 上传文件
+	ossClient := services.NewOssClient()
+	if ossClient == nil {
+		err = fmt.Errorf("初始化OSS服务失败")
+		return
+	}
+	resourceUrl, err = ossClient.UploadFile(newFileName, filePath, savePath)
+	if err != nil {
+		err = fmt.Errorf("文件上传失败, Err: %s", err.Error())
+		return
+	}
+
+	defer func() {
+		os.Remove(filePath)
+	}()
+	return
+}
+
+func MoveMaterialClassify(classifyInfo *material.MaterialClassify, req *material.MoveMaterialClassifyReq) (err error, errMsg string) {
+	nodeMove := models.SingleMoveNodeReq{}
+	nodeMove.NodeId = req.ClassifyId
+	nodeMove.ParentNodeId = req.ParentClassifyId
+	nodeMove.PrevNodeId = req.PrevClassifyId
+	nodeMove.NextNodeId = req.NextClassifyId
+
+	materialClassifyMove := new(ClassifyMove)
+
+	nodeInfo, updateCol, err, errMsg := _interface.MoveSingleNode(materialClassifyMove, nodeMove)
+	if err != nil {
+		return
+	}
+	oldParentId := classifyInfo.ParentId
+	oldLevelPath := classifyInfo.LevelPath
+	if len(updateCol) > 0 {
+		classifyInfo.Sort = nodeInfo.Sort
+		classifyInfo.ModifyTime = nodeInfo.ModifyTime
+		classifyInfo.ParentId = nodeInfo.ParentId
+
+		levelPath := classifyInfo.LevelPath
+		if classifyInfo.ParentId != oldParentId {
+			//查找父级分类
+			parentClassify, e := material.GetMaterialClassifyById(classifyInfo.ParentId)
+			if e != nil {
+				errMsg = "获取父级分类失败"
+				err = fmt.Errorf("获取父级分类失败,Err:" + e.Error())
+				return
+			}
+			levelPath = fmt.Sprintf("%s%d,", parentClassify.LevelPath, classifyInfo.ClassifyId)
+			classifyInfo.LevelPath = levelPath
+			updateCol = append(updateCol, "LevelPath")
+		}
+		err = classifyInfo.Update(updateCol)
+		if err != nil {
+			err = fmt.Errorf("修改失败,Err:" + err.Error())
+			return
+		}
+
+		if classifyInfo.ParentId != oldParentId {
+			tmpList, e := material.GetMaterialClassifyByLevelPath(oldLevelPath)
+			if e != nil {
+				err = fmt.Errorf("保存分类失败,Err:" + e.Error())
+				return
+			}
+			// 把原先的父级levePath,替换成最新的父级序列
+			for _, tmp := range tmpList {
+				//获取字符串前缀的位置
+				after, _ := strings.CutPrefix(tmp.LevelPath, oldLevelPath)
+				fmt.Println("after", after)
+				// 拼接字符串
+				if after != "" {
+					tmp.LevelPath = levelPath + after
+					tmp.ModifyTime = time.Now()
+					e = tmp.Update([]string{"LevelPath", "ModifyTime"})
+					if e != nil {
+						err = fmt.Errorf("修改子分类,Err:" + e.Error())
+						return
+					}
+				}
+			}
+		}
+	}
+	return
+}
+
+type ClassifyMove struct{}
+
+func (m *ClassifyMove) GetNodeInfoById(nodeId int) (nodeInfo *models.NodeInfo, err error) {
+	classifyInfo, err := material.GetMaterialClassifyById(nodeId)
+	if err != nil {
+		return
+	}
+	nodeInfo = &models.NodeInfo{
+		NodeId:     classifyInfo.ClassifyId,
+		NodeName:   classifyInfo.ClassifyName,
+		ParentId:   classifyInfo.ParentId,
+		Level:      classifyInfo.Level,
+		Sort:       classifyInfo.Sort,
+		ModifyTime: classifyInfo.ModifyTime,
+	}
+	return
+}
+
+func (m *ClassifyMove) UpdateNodeInfoSortByParentIdAndSource(parentNodeId, nodeId, prevNodeSort int, updateSortStr string, nodeType int) (err error) {
+	err = material.UpdateMaterialClassifySortByParentId(parentNodeId, nodeId, prevNodeSort, updateSortStr)
+	return
+}
+
+func (m *ClassifyMove) GetNodeMaxSort(parentId, nodeType int) (maxSort int, err error) {
+	maxSort, err = material.GetMaterialClassifyMaxSort(parentId)
+	return
+}
+
+func (m *ClassifyMove) GetFirstNodeInfoByParentId(parentId int) (nodeInfo *models.NodeInfo, err error) {
+	classifyInfo, err := material.GetFirstMaterialClassifyByParentId(parentId)
+	if err != nil {
+		return
+	}
+	nodeInfo = &models.NodeInfo{
+		NodeId:     classifyInfo.ClassifyId,
+		NodeName:   classifyInfo.ClassifyName,
+		ParentId:   classifyInfo.ParentId,
+		Level:      classifyInfo.Level,
+		Sort:       classifyInfo.Sort,
+		ModifyTime: classifyInfo.ModifyTime,
+	}
+	return
+}
+
+func GetBatchSelectedMaterialList(classifyId int, keyword string, isShowMe bool, sysUser *system.Admin, lang string) (list []*material.MaterialListItems, err error, errMsg string) {
+	var condition string
+	var pars []interface{}
+
+	if classifyId <= 0 {
+		errMsg = "请选择分类"
+		err = fmt.Errorf(errMsg)
+		return
+	}
+	// 查询当前的分类
+	classifyInfo, e := material.GetMaterialClassifyById(classifyId)
+	if e != nil {
+		errMsg = "分类不存在"
+		err = fmt.Errorf("获取分类信息失败,Err:" + e.Error())
+		return
+	}
+	// 获取所有子分类
+	childList, e := material.GetMaterialClassifyByLevelPath(classifyInfo.LevelPath)
+	if e != nil {
+		errMsg = "获取分类失败"
+		err = fmt.Errorf("获取子分类失败,Err:" + e.Error())
+		return
+	}
+	// 把原先的父级levePath,替换成最新的父级序列
+	classifyIdMap := make(map[string]struct{})
+	classifyIds := make([]string, 0)
+	childClassifyMap := make(map[int]*material.MaterialClassify)
+	for _, tmp := range childList {
+		childClassifyMap[tmp.ClassifyId] = tmp
+		//获取字符串前缀的位置
+		after, _ := strings.CutPrefix(tmp.LevelPath, classifyInfo.LevelPath)
+		fmt.Println("after", after)
+		// 拼接字符串
+		if after != "" {
+			ids := strings.Split(after, ",")
+			for _, v := range ids {
+				if _, ok := classifyIdMap[v]; !ok {
+					classifyIds = append(classifyIds, v)
+					classifyIdMap[v] = struct{}{}
+				}
+			}
+		}
+	}
+	classifyIds = append(classifyIds, strconv.Itoa(classifyId))
+	if len(classifyIds) > 0 {
+		condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(classifyIds)) + ") "
+		pars = append(pars, classifyIds)
+	}
+
+	if keyword != "" {
+		switch lang {
+		case utils.LANG_EN:
+			condition += ` AND  ( material_name_en LIKE '%` + keyword + `%' )`
+		default:
+			condition += ` AND  ( material_name LIKE '%` + keyword + `%' )`
+		}
+	}
+
+	//只看我的
+	if isShowMe {
+		condition += ` AND sys_user_id = ? `
+		pars = append(pars, sysUser.AdminId)
+	}
+
+	//获取图表信息
+	list, err = material.GetMaterialListByCondition(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		errMsg = "获取素材库信息失败"
+		err = fmt.Errorf("获取素材库信息失败,Err:" + err.Error())
+		return
+	}
+	return
+}
+
+func GetMyChartExistMaterialNameListMsg(nameList map[string]struct{}, reqList []*material.MyChartSaveAsMaterialItem) (nameResp material.MyChartSaveAsMaterialResp) {
+	existNameList := make([]*material.MyChartSaveAsMaterialItem, 0)
+	for _, v := range reqList {
+		if _, ok := nameList[v.MaterialName]; ok {
+			existNameList = append(existNameList, v)
+		}
+	}
+	nameResp = material.MyChartSaveAsMaterialResp{
+		ExistList: existNameList,
+	}
+	return
+}

+ 2 - 0
static/ErrMsgConfig.json

@@ -60,6 +60,8 @@
   "删除失败": "Deletion failed.",
   "指标数据异常,请检查": "The metric data is abnormal, please check.",
   "原指标与替换指标存在引用关系,不允许替换": "Original indicators and replacement indicators have a referencing relationship, which is not allowed to be replaced.",
+  "该分类下关联素材库不可删除": "The category associated with the material library cannot be deleted.",
+  "请输入图片名称": "Please enter the image name",
   "指标名称已存在,请重新填写": "The metric name already exists, please re-enter.",
   "请选择分类": "Please Select a Category",
   "分类已存在": "The category already exists."