xingzai hace 1 año
padre
commit
5a5c8f24d4
Se han modificado 2 ficheros con 31 adiciones y 18 borrados
  1. 17 6
      services/es_comprehensive.go
  2. 14 12
      utils/elastic.go

+ 17 - 6
services/es_comprehensive.go

@@ -45,9 +45,9 @@ type ElasticComprehensiveDetail struct {
 	SubjectNames string `description:"标的名称"`
 }
 
-//func init() {
-//	AddComprehensiveRoadshow()
-//}
+func init() {
+	AddComprehensiveIndustrialSource("Yx", 0)
+}
 
 // 添加文章:报告、纪要
 func AddComprehensiveArticle(articleId int) {
@@ -128,12 +128,12 @@ func AddComprehensiveChart(chartId int) {
 }
 
 // 添加产业资源包
-func AddComprehensiveIndustrialSource() {
+func AddComprehensiveIndustrialSource(sourceType string, articleId int) {
 	var err error
 	defer func() {
 		if err != nil {
 			fmt.Println(err)
-			go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error(), 2)
+			go utils.SendAlarmMsg("AddComprehensiveIndustrialSource"+err.Error(), 2)
 		}
 	}()
 	var condition string
@@ -147,6 +147,17 @@ func AddComprehensiveIndustrialSource() {
 	for _, v := range listsubject {
 		mapActivitySubject[v.IndustrialManagementId] = append(mapActivitySubject[v.IndustrialManagementId], v.SubjectName)
 	}
+	var industrialsource string
+	if sourceType == "Hz" {
+		condition = " AND a.article_type_id  = 0  " // 弘则资源包
+		industrialsource = "industrialsourceHz"
+	} else {
+		condition = " AND a.article_type_id  > 0  " //研选资源包
+		industrialsource = "industrialsourceYx"
+	}
+	if articleId > 0 {
+		condition += "  AND a.article_id = " + strconv.Itoa(articleId)
+	}
 	list, err := models.GetSearchResourceList(0, condition, 0, 0)
 	if err != nil {
 		fmt.Println(err)
@@ -156,7 +167,7 @@ func AddComprehensiveIndustrialSource() {
 	for _, v := range list {
 		item := new(ElasticComprehensiveDetail)
 		item.SourceId = v.IndustrialManagementId
-		item.Source = "industrialsource"
+		item.Source = industrialsource
 		item.IndustryName = v.IndustryName
 		item.SubjectNames = strings.Join(mapActivitySubject[v.IndustrialManagementId], ",")
 		item.PublishDate = v.PublishDate

+ 14 - 12
utils/elastic.go

@@ -2,6 +2,8 @@ package utils
 
 import (
 	"github.com/olivere/elastic/v7"
+	"log"
+	"os"
 	"time"
 )
 
@@ -14,21 +16,21 @@ const (
 )
 
 func init() {
-	//errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
-	//file := ""
-	//if RunMode == "release" {
-	//	//file = `/data/rdlucklog/hongze_cygx/eslog.log`
-	//	file = `./rdlucklog/eslog.log`
-	//} else {
-	//	file = `./rdlucklog/eslog.log`
-	//}
-	//logFile, _ := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
+	errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
+	file := ""
+	if RunMode == "release" {
+		//file = `/data/rdlucklog/hongze_cygx/eslog.log`
+		file = `./rdlucklog/eslog.log`
+	} else {
+		file = `./rdlucklog/eslog.log`
+	}
+	logFile, _ := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
 	client, err := elastic.NewClient(
 		elastic.SetURL(ES_URL),
 		elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
-		//elastic.SetTraceLog(log.New(logFile, "ES-TRACE: ", 0)),
-		//elastic.SetSniff(false), elastic.SetErrorLog(errorlog))
-		elastic.SetSniff(false))
+		elastic.SetTraceLog(log.New(logFile, "ES-TRACE: ", 0)),
+		elastic.SetSniff(false), elastic.SetErrorLog(errorlog))
+	//elastic.SetSniff(false))
 	Client = client
 	if err != nil {
 		go SendAlarmMsg("ElasticSearch连接失败", 2)