|
@@ -870,13 +870,13 @@ func (this *MaterialController) List() {
|
|
|
br.Data = resp
|
|
|
}
|
|
|
|
|
|
-// Save
|
|
|
-// @Title 新增/编辑保存素材库
|
|
|
-// @Description 新增/编辑保存素材库接口
|
|
|
+// SaveAsMaterial
|
|
|
+// @Title 将图表等封面上传至素材库
|
|
|
+// @Description 将图表等封面上传至素材库
|
|
|
// @Param request body material.AddAndEditSandbox true "type json string"
|
|
|
// @Success 200 {object} material.Material
|
|
|
-// @router /save [post]
|
|
|
-func (this *MaterialController) Save() {
|
|
|
+// @router /saveAs [post]
|
|
|
+func (this *MaterialController) SaveAsMaterial() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
|
defer func() {
|
|
|
this.Data["json"] = br
|
|
@@ -889,60 +889,153 @@ func (this *MaterialController) Save() {
|
|
|
br.Ret = 408
|
|
|
return
|
|
|
}
|
|
|
- var req material.AddAndEditMaterial
|
|
|
+ var req material.SaveAsMaterialReq
|
|
|
err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
if err != nil {
|
|
|
br.Msg = "参数解析异常!"
|
|
|
br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
+ 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
|
|
|
+ }
|
|
|
|
|
|
- var materialResp *material.MaterialSaveResp
|
|
|
-
|
|
|
- var errMsg string
|
|
|
+ msg := "保存成功"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = msg
|
|
|
+}
|
|
|
|
|
|
- if req.MaterialId <= 0 {
|
|
|
- //新增素材库
|
|
|
- materialResp, err = materialService.AddMaterial(req, sysUser.AdminId, sysUser.RealName)
|
|
|
+// 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)
|
|
|
+ for _, v := range req.MaterialList {
|
|
|
+ if v.ClassifyId <= 0 {
|
|
|
+ br.Msg = "请选择分类"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if v.MaterialName == "" {
|
|
|
+ br.Msg = "请填写图片名称"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if v.ChartInfoId <= 0 {
|
|
|
+ br.Msg = "请选择图表"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if v.MyChartId <= 0 {
|
|
|
+ br.Msg = "请选择我的图表"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ 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 = "保存失败!"
|
|
|
- if errMsg != `` {
|
|
|
- br.Msg = errMsg
|
|
|
- }
|
|
|
- br.ErrMsg = "保存失败,Err:" + err.Error()
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- } else {
|
|
|
- //编辑素材库
|
|
|
- materialInfo := &material.Material{
|
|
|
- MaterialId: req.MaterialId,
|
|
|
- MaterialName: utils.TrimStr(req.MaterialName),
|
|
|
- ImgUrl: utils.TrimStr(req.ImgUrl),
|
|
|
- ModifyTime: time.Now(),
|
|
|
- ClassifyId: req.ClassifyId,
|
|
|
- }
|
|
|
- //缩略图为空时不更新
|
|
|
- var updateSandboxColumn = []string{}
|
|
|
- if req.ImgUrl == "" {
|
|
|
- updateSandboxColumn = []string{"Name", "Content", "MindmapData", "ModifyTime", "MaterialClassifyId", "Style"}
|
|
|
- } else {
|
|
|
- updateSandboxColumn = []string{"Name", "Content", "MindmapData", "ImgUrl", "ModifyTime", "MaterialClassifyId", "Style"}
|
|
|
+ if len(existList) > 0 {
|
|
|
+ msg := "图片名称:"
|
|
|
+ for _, v := range existList {
|
|
|
+ msg += v.MaterialNameEn + " "
|
|
|
+ }
|
|
|
+ br.Msg = fmt.Sprintf("%s 已存在", msg)
|
|
|
+ return
|
|
|
}
|
|
|
- err = materialInfo.Update(updateSandboxColumn)
|
|
|
+ default:
|
|
|
+ // 判断文件名是否已存在
|
|
|
+ existList, err = material.GetMaterialByNames(materialNames)
|
|
|
if err != nil {
|
|
|
- br.Msg = "保存失败!"
|
|
|
- if errMsg != `` {
|
|
|
- br.Msg = errMsg
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(existList) > 0 {
|
|
|
+ msg := "图片名称:"
|
|
|
+ for _, v := range existList {
|
|
|
+ msg += v.MaterialName + " "
|
|
|
}
|
|
|
- br.ErrMsg = "保存失败,Err:" + err.Error()
|
|
|
+ br.Msg = fmt.Sprintf("%s 已存在", msg)
|
|
|
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
|
|
|
- br.Data = materialResp
|
|
|
}
|
|
|
|
|
|
// Delete
|
|
@@ -1570,7 +1663,7 @@ func (this *MaterialController) Rename() {
|
|
|
// @Description 批量下载素材
|
|
|
// @Param request body material.DeleteSandbox true "type json string"
|
|
|
// @Success 200 标记成功
|
|
|
-// @router /batch/download [post]
|
|
|
+// @router /batch/download [get]
|
|
|
func (this *MaterialController) BatchDownload() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
|
defer func() {
|
|
@@ -1584,19 +1677,17 @@ func (this *MaterialController) BatchDownload() {
|
|
|
br.Ret = 408
|
|
|
return
|
|
|
}
|
|
|
- var req material.BatchDeleteMaterialReq
|
|
|
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "参数解析异常!"
|
|
|
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
+ //var req material.BatchDeleteMaterialReq
|
|
|
+ materialIdStr := this.GetString("MaterialIds")
|
|
|
+ isSelectAll, _ := this.GetBool("IsSelectAll")
|
|
|
+ classifyId, _ := this.GetInt("ClassifyId")
|
|
|
+ keyword := this.GetString("Keyword")
|
|
|
+ isShowMe, _ := this.GetBool("IsShowMe")
|
|
|
|
|
|
downMaterialList := make([]*material.MaterialListItems, 0)
|
|
|
- if req.IsSelectAll {
|
|
|
- classifyId := req.ClassifyId
|
|
|
- keyword := req.Keyword
|
|
|
- isShowMe := req.IsShowMe
|
|
|
+ materialIds := strings.Split(materialIdStr, ",")
|
|
|
+ var err error
|
|
|
+ if isSelectAll {
|
|
|
//获取图表信息
|
|
|
list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser)
|
|
|
if e != nil {
|
|
@@ -1608,9 +1699,11 @@ func (this *MaterialController) BatchDownload() {
|
|
|
return
|
|
|
}
|
|
|
notSelectIds := make(map[int]struct{})
|
|
|
- if len(req.MaterialIds) >= 0 {
|
|
|
- for _, v := range req.MaterialIds {
|
|
|
- notSelectIds[v] = struct{}{}
|
|
|
+ if len(materialIds) >= 0 {
|
|
|
+ //转成数组
|
|
|
+ for _, v := range materialIds {
|
|
|
+ id, _ := strconv.Atoi(v)
|
|
|
+ notSelectIds[id] = struct{}{}
|
|
|
}
|
|
|
}
|
|
|
for _, v := range list {
|
|
@@ -1619,9 +1712,14 @@ func (this *MaterialController) BatchDownload() {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- if len(req.MaterialIds) > 0 {
|
|
|
+ if len(materialIds) > 0 {
|
|
|
// 批量查询指标数据
|
|
|
- downMaterialList, err = material.GetMaterialByIds(req.MaterialIds)
|
|
|
+ materialIdsInt := make([]int, 0)
|
|
|
+ for _, v := range materialIds {
|
|
|
+ id, _ := strconv.Atoi(v)
|
|
|
+ materialIdsInt = append(materialIdsInt, id)
|
|
|
+ }
|
|
|
+ downMaterialList, err = material.GetMaterialByIds(materialIdsInt)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取素材库信息失败"
|
|
|
br.ErrMsg = "获取素材库信息失败,Err:" + err.Error()
|
|
@@ -1715,7 +1813,7 @@ func (this *MaterialController) BatchDownload() {
|
|
|
// @Description 下载素材
|
|
|
// @Param request body material.DeleteSandbox true "type json string"
|
|
|
// @Success 200 标记成功
|
|
|
-// @router /download [post]
|
|
|
+// @router /download [get]
|
|
|
func (this *MaterialController) Download() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
|
defer func() {
|
|
@@ -1729,20 +1827,13 @@ func (this *MaterialController) Download() {
|
|
|
br.Ret = 408
|
|
|
return
|
|
|
}
|
|
|
- var req material.RenameMaterialReq
|
|
|
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "参数解析异常!"
|
|
|
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if req.MaterialId <= 0 {
|
|
|
+ materialId, _ := this.GetInt("MaterialId")
|
|
|
+ if materialId <= 0 {
|
|
|
br.Msg = "缺少素材库编号"
|
|
|
return
|
|
|
}
|
|
|
// 判断素材是否存在
|
|
|
- info, err := material.GetMaterialById(req.MaterialId)
|
|
|
+ info, err := material.GetMaterialById(materialId)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
br.Msg = "素材不存在"
|