Browse Source

Merge branch 'bzq/knowledge_report_add' of eta_gn_server/eta_report into debug

baoziqiang 2 months ago
parent
commit
5c48c7c1df
2 changed files with 10 additions and 5 deletions
  1. 3 3
      models/knowledge_resource.go
  2. 7 2
      services/knowledge/knowledge_resource.go

+ 3 - 3
models/knowledge_resource.go

@@ -144,7 +144,7 @@ func (k *KnowledgeClassify) GetClassifysByNameAndType(classifyName string, resou
 	return
 }
 
-func (k *KnowledgeClassify) GetChildClassifyIdByNamePath(classifyNameFirst string, classifyNameSecond string, classifyNameThird string) (id int, err error) {
+func (k *KnowledgeClassify) GetChildClassifyIdByNamePath(resourceType int, classifyNameFirst string, classifyNameSecond string, classifyNameThird string) (id int, err error) {
 	sql := `SELECT 
     c3.classify_id AS id
 	FROM knowledge_classify c1 
@@ -155,7 +155,7 @@ func (k *KnowledgeClassify) GetChildClassifyIdByNamePath(classifyNameFirst strin
 					AND c3.classify_name = ?
 					AND c3.level = 3
 	WHERE c1.classify_name = ?
-	AND c1.level = 1 `
-	err = global.DEFAULT_DmSQL.Raw(sql, classifyNameSecond, classifyNameThird, classifyNameFirst).Scan(&id).Error
+	AND c1.level = 1 AND c1.resource_type = ?`
+	err = global.DEFAULT_DmSQL.Raw(sql, classifyNameSecond, classifyNameThird, classifyNameFirst, resourceType).Scan(&id).Error
 	return
 }

+ 7 - 2
services/knowledge/knowledge_resource.go

@@ -32,7 +32,7 @@ func ReportKnowledgeResourceAdd(title string, fileUrl []string, adminId int, adm
 			classifySecond = classifyPathArr[1]
 			classifyThird = classifyPathArr[2]
 		}
-		childClassifyId, err = classifyObj.GetChildClassifyIdByNamePath(classifyFirst, classifySecond, classifyThird)
+		childClassifyId, err = classifyObj.GetChildClassifyIdByNamePath(models.KnowledgeResourceTypeReport, classifyFirst, classifySecond, classifyThird)
 		if err != nil {
 			if utils.IsErrNoRow(err) {
 				msg = "分类不存在,请检查知识资源-报告库中是否存在-" + classifyPath
@@ -45,6 +45,10 @@ func ReportKnowledgeResourceAdd(title string, fileUrl []string, adminId int, adm
 		msg = "分类不能为空"
 		return
 	}
+	if childClassifyId == 0 {
+		msg = "分类不存在,请检查知识资源-报告库中是否存在-" + classifyPath
+		return
+	}
 	obj := new(models.KnowledgeResource)
 	obj.ResourceType = models.KnowledgeResourceTypeReport
 	obj.ClassifyId = childClassifyId
@@ -260,7 +264,7 @@ func UploadFormFile(multipartFile map[string][]*multipart.FileHeader) (fileUrl [
 			}
 			saveName := fmt.Sprint(utils.MD5(f.Filename), time.Now().Format(utils.FormatDateTimeUnSpace), time.Now().Nanosecond(), ext)
 			dataDir := time.Now().Format(utils.FormatDate)
-			filePath := utils.StaticDir + "files/" + dataDir + "/" + saveName
+			filePath := utils.StaticDir + "files/" + dataDir
 			ok, _ := utils.PathExists(filePath)
 			if !ok {
 				err = os.MkdirAll(filePath, utils.DIR_MOD)
@@ -281,6 +285,7 @@ func UploadFormFile(multipartFile map[string][]*multipart.FileHeader) (fileUrl [
 				err = er
 				return
 			}
+			filePath = filePath + "/" + saveName
 			// 保存到本地
 			er = utils.SaveToFile(fileContentBytes, filePath)
 			if er != nil {