rdluck 4 years ago
parent
commit
4ff1f09bad
5 changed files with 68 additions and 13 deletions
  1. 11 9
      controllers/user.go
  2. 2 2
      models/article.go
  3. 49 0
      services/elasticsearch.go
  4. 1 1
      services/sms.go
  5. 5 1
      services/task.go

+ 11 - 9
controllers/user.go

@@ -494,15 +494,17 @@ func (this *UserController) BrowseHistoryList() {
 	for i := 0; i < lenList; i++ {
 		item := list[i]
 		article := articleMap[item.ArticleId]
-		list[i].Title = article.Title
-		list[i].TitleEn = article.TitleEn
-		list[i].UpdateFrequency = article.UpdateFrequency
-		list[i].CreateDate = article.CreateDate
-		list[i].PublishDate = article.PublishDate
-		list[i].Body, _ = services.GetReportContentTextSub(article.Body)
-		list[i].Abstract = article.Abstract
-		list[i].CategoryName = article.CategoryName
-		list[i].SubCategoryName = article.SubCategoryName
+		if article!=nil {
+			list[i].Title = article.Title
+			list[i].TitleEn = article.TitleEn
+			list[i].UpdateFrequency = article.UpdateFrequency
+			list[i].CreateDate = article.CreateDate
+			list[i].PublishDate = article.PublishDate
+			list[i].Body, _ = services.GetReportContentTextSub(article.Body)
+			list[i].Abstract = article.Abstract
+			list[i].CategoryName = article.CategoryName
+			list[i].SubCategoryName = article.SubCategoryName
+		}
 	}
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp := new(models.ArticleBrowseHistoryListResp)

+ 2 - 2
models/article.go

@@ -3,7 +3,7 @@ package models
 import "rdluck_tools/orm"
 
 type CygxArticle struct {
-	Article_id      int    `description:"文章id"`
+	ArticleId      int    `description:"文章id"`
 	Title           string `description:"标题"`
 	TitleEn         string `description:"英文标题 "`
 	UpdateFrequency string `description:"更新周期"`
@@ -16,7 +16,7 @@ type CygxArticle struct {
 }
 
 type HomeArticle struct {
-	Article_id       int    `description:"文章id"`
+	ArticleId       int    `description:"文章id"`
 	Title            string `description:"标题"`
 	TitleEn          string `description:"英文标题 "`
 	UpdateFrequency  string `description:"更新周期"`

+ 49 - 0
services/elasticsearch.go

@@ -0,0 +1,49 @@
+package services
+
+import (
+	"fmt"
+	"context"
+	"gopkg.in/olivere/elastic.v5"
+	"gopkg.in/olivere/elastic.v5/config"
+	"hongze/hongze_cygx/models"
+)
+
+const (
+	ES_URL      = "http://es-cn-oew21y5tl000i1wxm.public.elasticsearch.aliyuncs.com:9200"     //<1>
+	ES_USERNAME = "elastic"        //<2>
+	ES_PASSWORD = "hongze@2021"       //<3>
+)
+
+func SaveData()  {
+	fmt.Println("start")
+	var sniff = false    //<4>
+	cfg := &config.Config{
+		URL:      ES_URL,
+		Username: ES_USERNAME,
+		Password: ES_PASSWORD,
+	}
+
+	cfg.Sniff = &sniff
+	var client, err = elastic.NewClientFromConfig(cfg)
+	if err != nil {
+		fmt.Println("NewClientFromConfig Err:"+err.Error())
+		return
+	}
+	var esIndex = "cygx_article"
+	exists, err := client.IndexExists(esIndex).Do(context.Background())   //<5>
+	if err != nil {
+		fmt.Println("IndexExists Err:"+err.Error())
+		return
+	}
+	if !exists {
+		_,err=client.CreateIndex(esIndex).Do(context.Background())
+		if err!=nil {
+			fmt.Println("CreateIndex Err:"+err.Error())
+			return
+		}
+	}
+	//item:=new(models.CygxArticle)
+	//item.Article_id
+	fmt.Println(exists)
+	fmt.Println("end")
+}

+ 1 - 1
services/sms.go

@@ -5,8 +5,8 @@ import (
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
-	"net/url"
 	"net/http"
+	"net/url"
 )
 
 func SendSmsCode(mobile, vcode string) bool {

+ 5 - 1
services/task.go

@@ -1,5 +1,9 @@
 package services
 
-func Task() {
+import "fmt"
 
+func Task() {
+	fmt.Println("start")
+	//SaveData()
+	fmt.Println("end")
 }