浏览代码

fix:知识资源修改发布时间格式,修改es检索功能

zqbao 2 月之前
父节点
当前提交
b4e11f8815
共有 2 个文件被更改,包括 33 次插入11 次删除
  1. 11 3
      controllers/knowledge/resource.go
  2. 22 8
      services/knowledge/es.go

+ 11 - 3
controllers/knowledge/resource.go

@@ -243,7 +243,7 @@ func (this *ResourceController) List() {
 		var startTime, endTime string
 		if v.StartTime != nil && !v.StartTime.IsZero() {
 			startTime = v.StartTime.In(time.Local).Format(utils.FormatDateTime)
-			if resourceType == knowledge.KnowledgeResourceTypeReport || resourceType == knowledge.KnowledgeResourceTypeKnow {
+			if resourceType == knowledge.KnowledgeResourceTypeReport || resourceType == knowledge.KnowledgeResourceTypeKnow || resourceType == knowledge.KnowledgeResourceTypeOpinion {
 				startTime = v.StartTime.In(time.Local).Format(utils.FormatDate)
 			}
 		}
@@ -324,6 +324,7 @@ func (this *ResourceController) List() {
 // @Param   IncludeFile   query   string  true       "是否包含文件, no:不包含"
 // @Param   SourceFrom   query   string  true       "来源, 用英文逗号分隔"
 // @Param   IsShowMe   query   string  true       "只看我, false:全部, true:只看我"
+// @Param   IsQueryRef   query   string  true       "是否查询引用, false:否, true: 是"
 // @Success 200 {object} knowledge.KnowledgeResourceListResp
 // @router /resource/search_by_es [get]
 func (this *ResourceController) Search() {
@@ -348,7 +349,9 @@ func (this *ResourceController) Search() {
 
 	includeFile := this.GetString("IncludeFile")
 
-	IsShowMe, _ := this.GetBool("IsShowMe")
+	isShowMe, _ := this.GetBool("IsShowMe")
+
+	isQueryRef, _ := this.GetBool("IsQueryRef")
 
 	var startSize int
 	if pageSize <= 0 {
@@ -374,7 +377,11 @@ func (this *ResourceController) Search() {
 		}
 	}
 	var myId int
-	if IsShowMe {
+	if isShowMe {
+		myId = this.SysUser.AdminId
+	}
+
+	if isQueryRef {
 		myId = this.SysUser.AdminId
 	}
 
@@ -409,6 +416,7 @@ func (this *ResourceController) Search() {
 		sourceFromArr,
 		tagIdsInt,
 		isIncludeFile,
+		isQueryRef,
 		startSize,
 		pageSize,
 	)

+ 22 - 8
services/knowledge/es.go

@@ -14,7 +14,7 @@ import (
 )
 
 // SearchChartInfoData 查询es中的图表数据
-func SearchKnowledgeResourceByEs(resourceType int, keywordStr string, showSysIds []int, myId int, classifyIds []int, sourceList []string, tagIds []int, isIncludeFile bool, from, size int) (list []*knowledge.KnowledgeResource, total int64, err error) {
+func SearchKnowledgeResourceByEs(resourceType int, keywordStr string, showSysIds []int, myId int, classifyIds []int, sourceList []string, tagIds []int, isIncludeFile, isQueryRef bool, from, size int) (list []*knowledge.KnowledgeResource, total int64, err error) {
 	indexName := utils.EsKnowledgeResourceIndexName
 	list = make([]*knowledge.KnowledgeResource, 0)
 	defer func() {
@@ -32,13 +32,6 @@ func SearchKnowledgeResourceByEs(resourceType int, keywordStr string, showSysIds
 			"ResourceType": resourceType,
 		},
 	})
-	if resourceType == knowledge.KnowledgeResourceTypeOpinion {
-		mustMap = append(mustMap, map[string]interface{}{
-			"term": map[string]interface{}{
-				"State": knowledge.KnowledgeResourceStatePassed,
-			},
-		})
-	}
 
 	//指标来源
 	if len(showSysIds) > 0 {
@@ -90,6 +83,27 @@ func SearchKnowledgeResourceByEs(resourceType int, keywordStr string, showSysIds
 		})
 	}
 
+	if isQueryRef && resourceType == knowledge.KnowledgeResourceTypeOpinion {
+		shouldMap := map[string]interface{}{
+			"should": []interface{}{
+				map[string]interface{}{
+					"term": map[string]interface{}{
+						"State": knowledge.KnowledgeResourceStatePassed,
+					},
+				},
+				map[string]interface{}{
+					"term": map[string]interface{}{
+						"AdminId": myId,
+					},
+				},
+			},
+			"minimum_should_match": 1,
+		}
+		mustMap = append(mustMap, map[string]interface{}{
+			"bool": shouldMap,
+		})
+	}
+
 	if keywordStr != "" {
 		shouldMap := map[string]interface{}{
 			"should": []interface{}{