Browse Source

请求入参限制

xyxie 4 tháng trước cách đây
mục cha
commit
501d133f90
2 tập tin đã thay đổi với 29 bổ sung7 xóa
  1. 22 5
      controllers/material/material.go
  2. 7 2
      services/material/material.go

+ 22 - 5
controllers/material/material.go

@@ -819,7 +819,12 @@ func (this *MaterialController) List() {
 	}
 
 	if keyword != "" {
-		condition += ` AND  ( material_name LIKE '%` + keyword + `%' )`
+		switch this.Lang {
+		case utils.LANG_EN:
+			condition += ` AND  ( material_name_en LIKE '%` + keyword + `%' )`
+		default:
+			condition += ` AND  ( material_name LIKE '%` + keyword + `%' )`
+		}
 	}
 
 	//只看我的
@@ -960,6 +965,7 @@ func (this *MaterialController) MyChartSaveAsMaterial() {
 		return
 	}
 	materialNames := make([]string, 0)
+	namesMap := make(map[string]struct{})
 	for _, v := range req.MaterialList {
 		if v.ClassifyId <= 0 {
 			br.Msg = "请选择分类"
@@ -977,10 +983,15 @@ func (this *MaterialController) MyChartSaveAsMaterial() {
 			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 = "请填写图片名称"
+		br.Msg = "请填写素材名称"
 		return
 	}
 	existList := make([]*material.Material, 0)
@@ -1116,7 +1127,7 @@ func (this *MaterialController) BatchDelete() {
 		keyword := req.Keyword
 		isShowMe := req.IsShowMe
 		//获取图表信息
-		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser)
+		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser, this.Lang)
 		if e != nil {
 			br.Msg = "获取素材库信息失败"
 			if msg != "" {
@@ -1273,6 +1284,7 @@ func (this *MaterialController) BatchAdd() {
 		return
 	}
 	materialNames := make([]string, 0)
+	namesMap := make(map[string]struct{})
 	for _, v := range req.MaterialList {
 		if v.MaterialName == "" {
 			br.Msg = "请填写图片名称"
@@ -1282,6 +1294,11 @@ func (this *MaterialController) BatchAdd() {
 			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 {
@@ -1435,7 +1452,7 @@ func (this *MaterialController) BatchChangeClassify() {
 		keyword := req.Keyword
 		isShowMe := req.IsShowMe
 		//获取图表信息
-		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser)
+		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser, this.Lang)
 		if e != nil {
 			br.Msg = "获取素材库信息失败"
 			if msg != "" {
@@ -1689,7 +1706,7 @@ func (this *MaterialController) BatchDownload() {
 	var err error
 	if isSelectAll {
 		//获取图表信息
-		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser)
+		list, e, msg := materialService.GetBatchSelectedMaterialList(classifyId, keyword, isShowMe, sysUser, this.Lang)
 		if e != nil {
 			br.Msg = "获取素材库信息失败"
 			if msg != "" {

+ 7 - 2
services/material/material.go

@@ -485,7 +485,7 @@ func (m *ClassifyMove) GetFirstNodeInfoByParentId(parentId int) (nodeInfo *model
 	return
 }
 
-func GetBatchSelectedMaterialList(classifyId int, keyword string, isShowMe bool, sysUser *system.Admin) (list []*material.MaterialListItems, err error, errMsg string) {
+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{}
 
@@ -535,7 +535,12 @@ func GetBatchSelectedMaterialList(classifyId int, keyword string, isShowMe bool,
 	}
 
 	if keyword != "" {
-		condition += ` AND  ( material_name LIKE '%` + keyword + `%' )`
+		switch lang {
+		case utils.LANG_EN:
+			condition += ` AND  ( material_name_en LIKE '%` + keyword + `%' )`
+		default:
+			condition += ` AND  ( material_name LIKE '%` + keyword + `%' )`
+		}
 	}
 
 	//只看我的