Browse Source

新增专家背景

rdluck 4 years ago
parent
commit
d8f4252afb
6 changed files with 132 additions and 27 deletions
  1. 4 2
      controllers/article.go
  2. 41 24
      models/article.go
  3. 6 0
      models/article_interview_apply.go
  4. 1 0
      models/db.go
  5. 73 1
      services/article.go
  6. 7 0
      services/task.go

+ 4 - 2
controllers/article.go

@@ -56,16 +56,18 @@ func (this *ArticleController) Detail() {
 		detail.IsCollect = true
 	}
 
-	interviewApplyCount, err := models.GetArticleInterviewApplyCount(uid, articleId)
+	interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 		return
 	}
 
-	if interviewApplyCount > 0 {
+	if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
 		detail.IsInterviewApply = true
+		detail.InterviewApplyStatus = interviewApplyItem.Status
 	}
+
 	hasPermission := 2
 	articlePermission, err := models.GetArticlePermission(detail.SubCategoryName)
 	if err != nil {

+ 41 - 24
models/article.go

@@ -1,18 +1,24 @@
 package models
 
-import "rdluck_tools/orm"
+import (
+	"rdluck_tools/orm"
+	"time"
+)
 
 type CygxArticle struct {
-	ArticleId       int    `description:"文章id"`
-	Title           string `description:"标题"`
-	TitleEn         string `description:"英文标题 "`
-	UpdateFrequency string `description:"更新周期"`
-	CreateDate      string `description:"创建时间"`
-	PublishDate     string `description:"发布时间"`
-	Body            string `description:"内容"`
-	Abstract        string `description:"摘要"`
-	CategoryName    string `description:"一级分类"`
-	SubCategoryName string `description:"二级分类"`
+	ArticleId        int       `description:"文章id"`
+	Title            string    `description:"标题"`
+	TitleEn          string    `description:"英文标题 "`
+	UpdateFrequency  string    `description:"更新周期"`
+	CreateDate       string    `description:"创建时间"`
+	PublishDate      string    `description:"发布时间"`
+	Body             string    `description:"内容"`
+	Abstract         string    `description:"摘要"`
+	CategoryName     string    `description:"一级分类"`
+	SubCategoryName  string    `description:"二级分类"`
+	InterviewTime    time.Time `description:"访谈时间"`
+	ExpertBackground string    `description:"专家背景"`
+	ExpertNumber     string    `description:"专家编号"`
 }
 
 type HomeArticle struct {
@@ -30,19 +36,23 @@ type HomeArticle struct {
 }
 
 type ArticleDetail struct {
-	ArticleId        int    `description:"报告id"`
-	Title            string `description:"标题"`
-	TitleEn          string `description:"英文标题 "`
-	UpdateFrequency  string `description:"更新周期"`
-	CreateDate       string `description:"创建时间"`
-	PublishDate      string `description:"发布时间"`
-	Body             string `description:"内容"`
-	Abstract         string `description:"摘要"`
-	CategoryName     string `description:"一级分类"`
-	SubCategoryName  string `description:"二级分类"`
-	IsCollect        bool   `description:"是否收藏:true,已收藏,false:未收藏"`
-	IsInterviewApply bool   `description:"是否申请访谈:true,已申请,false:未申请"`
-	BodyText         string `description:"内容"`
+	ArticleId            int       `description:"报告id"`
+	Title                string    `description:"标题"`
+	TitleEn              string    `description:"英文标题 "`
+	UpdateFrequency      string    `description:"更新周期"`
+	CreateDate           string    `description:"创建时间"`
+	PublishDate          string    `description:"发布时间"`
+	Body                 string    `description:"内容"`
+	Abstract             string    `description:"摘要"`
+	CategoryName         string    `description:"一级分类"`
+	SubCategoryName      string    `description:"二级分类"`
+	IsCollect            bool      `description:"是否收藏:true,已收藏,false:未收藏"`
+	IsInterviewApply     bool      `description:"是否申请访谈:true,已申请,false:未申请"`
+	BodyText             string    `description:"内容"`
+	InterviewApplyStatus string    `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
+	InterviewTime        time.Time `description:"访谈时间"`
+	ExpertBackground     string    `description:"专家背景"`
+	ExpertNumber         string    `description:"专家编号"`
 }
 
 func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
@@ -72,3 +82,10 @@ type ArticleDetailResp struct {
 	Detail        *ArticleDetail
 	HasPermission int `description:"1:有权限,2:无权限"`
 }
+
+func ModifyArticleExpert(articleId int, expertNumStr, expertContentStr, interviewDateStr string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_article SET expert_background=?,expert_number=?,interview_date=? WHERE article_id=? `
+	_, err = o.Raw(sql, expertContentStr, expertNumStr, interviewDateStr, articleId).Exec()
+	return
+}

+ 6 - 0
models/article_interview_apply.go

@@ -47,6 +47,12 @@ func GetArticleInterviewApplyUsersCount(articleId int) (count int, err error) {
 	return
 }
 
+func GetArticleInterviewApply(userId, articleId int) (item *CygxInterviewApply, err error) {
+	sql := `SELECT * FROM cygx_article_collect WHERE user_id=? AND article_id=? `
+	err = orm.NewOrm().Raw(sql, userId, articleId).QueryRow(&item)
+	return
+}
+
 func GetArticleInterviewApplyCount(userId, articleId int) (count int, err error) {
 	sql := `SELECT COUNT(1) AS count FROM cygx_article_collect WHERE user_id=? AND article_id=? `
 	err = orm.NewOrm().Raw(sql, userId, articleId).QueryRow(&count)

+ 1 - 0
models/db.go

@@ -37,5 +37,6 @@ func init() {
 		new(MsgCode),
 		new(Resource),
 		new(CygxApplyRecord),
+		new(CygxInterviewApply),
 	)
 }

+ 73 - 1
services/article.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"fmt"
+	"hongze/hongze_cygx/models"
 	"html"
 	"strings"
 	"github.com/PuerkitoBio/goquery"
@@ -45,7 +46,7 @@ func GetReportContentTextSub(content string) (contentSub string, err error) {
 			return
 		}
 		n++
-		contentSub = contentSub +s.Text()
+		contentSub = contentSub + s.Text()
 		//phtml, err := s.Html()
 		//if err != nil {
 		//	fmt.Println("get html err", err.Error())
@@ -57,3 +58,74 @@ func GetReportContentTextSub(content string) (contentSub string, err error) {
 	})
 	return
 }
+
+//解析报告
+func GetArticleExpert() {
+	articleId := 3526
+	item, err := models.GetArticleDetailById(articleId)
+	if err != nil {
+		fmt.Println("GetArticleDetailById Err:" + err.Error())
+		return
+	}
+	content := item.Body
+	content = html.UnescapeString(content)
+	doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
+	if err != nil {
+		fmt.Println("create doc err:", err.Error())
+		return
+	}
+
+	var expertNumArr []string
+	var expertContentArr []string
+	var interviewDateArr []string
+
+	doc.Find("p").Each(func(i int, s *goquery.Selection) {
+		contentTxt := s.Text()
+		if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
+			interviewDate := s.Next().Text()
+			interviewDateArr = append(interviewDateArr, interviewDate)
+		}
+		if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
+			expertContent := s.Next().Text()
+			if expertContent == "" {
+				expertContent=contentTxt
+			}
+			if expertContent != "" {
+				rightIndex := strings.Index(expertContent, ")")
+				if rightIndex == 0 {
+					rightIndex = strings.Index(expertContent, ")")
+				}
+				expertNum := expertContent[:rightIndex]
+				expertNum = strings.Replace(expertNum, "(", "", -1)
+				expertNum = strings.Replace(expertNum, "(", "", -1)
+				expertNum = strings.Replace(expertNum, "专家评价", "", -1)
+				if expertNum != "" {
+					expertNumArr = append(expertNumArr, expertNum)
+					rightIndex = rightIndex
+					expertContentStr := expertContent[rightIndex:]
+					expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
+					expertContentStr = strings.TrimLeft(expertContentStr, ":")
+					expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
+					expertContentArr = append(expertContentArr, expertContentStr)
+				}
+			}
+		}
+	})
+	var expertNumStr, expertContentStr, interviewDateStr string
+	if len(expertNumArr) > 0 {
+		expertNumStr = expertNumArr[0]
+	}
+	if len(expertContentArr) > 0 {
+		expertContentStr = expertContentArr[0]
+	}
+
+	if len(interviewDateArr) > 0 {
+		interviewDateStr = interviewDateArr[0]
+	}
+	fmt.Println(articleId, expertNumStr, expertContentStr, interviewDateStr)
+	err = models.ModifyArticleExpert(articleId, expertNumStr, expertContentStr, interviewDateStr)
+	if err != nil {
+		fmt.Println("ModifyArticleExpert Err:" + err.Error())
+		return
+	}
+}

+ 7 - 0
services/task.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"fmt"
+	"hongze/hongze_cygx/utils"
 )
 
 func Task() {
@@ -11,5 +12,11 @@ func Task() {
 	//SearchByKeyWord(keyWord, pageSize)
 	//SaveData()
 	//GetIndustryMap()
+	//解析报告
+	//GetArticleExpert()
+
+
+	pwd:=utils.GetRandStringNoSpecialChar(16)
+	fmt.Println(pwd)
 	fmt.Println("end")
 }