Procházet zdrojové kódy

Merge branch 'cygx_13.0' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai před 1 rokem
rodič
revize
28ad64d654

+ 13 - 1
models/chart.go

@@ -95,6 +95,7 @@ type CygxChartDetail struct {
 	IsCollection  bool   `description:"是否收藏 "`
 	CollectionNum int    `description:"本人收藏数量 "`
 	HttpUrl       string `orm:"column(iframe)";description:"文章链接跳转地址"`
+	CreateDate    string `description:"本地创建时间"`
 }
 
 func GetChartCountById(chartId int) (count int, err error) {
@@ -234,7 +235,7 @@ func GetChartListCollectionNew(condition string, pars []interface{}, userId, sta
 			( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS is_top,
 			( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c 
 		FROM
-			cygx_chart_all AS a
+			cygx_chart AS a
 			LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
 			LEFT JOIN cygx_chart_collect AS c ON c.chart_id = a.chart_id 
 		WHERE
@@ -319,6 +320,17 @@ func GetChartDetailById(chartId, uid int) (item *CygxChartDetail, err error) {
 	return
 }
 
+func GetChartDetailByChartId(chartId int) (item *CygxChartDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * 
+		FROM
+			cygx_chart  as a 
+		WHERE
+			a.chart_id =? `
+	err = o.Raw(sql, chartId).QueryRow(&item)
+	return
+}
+
 // 删除
 func DeleteCygxChart(chartId int) (err error) {
 	o, err := orm.NewOrm().Begin()

+ 8 - 1
models/industrial_article_group_management.go

@@ -79,8 +79,15 @@ func GetIndustrialArticleGroupManagementList(condition string, pars []interface{
 	return
 }
 
+type IndustrialActivityGroupManagementRep struct {
+	IndustrialManagementId int    `description:"cygx_industrial_management表的主键ID"`
+	IndustryName           string `description:"产业名称"`
+	ChartPermissionId      int    `description:"权限id"`
+	PermissionName         string `description:"行业名称"`
+}
+
 // 列表
-func GetIndustrialArticleGroupManagementListByArticleId(articleId int) (items []*CygxIndustrialArticleGroupManagement, err error) {
+func GetIndustrialArticleGroupManagementListByArticleId(articleId int) (items []*IndustrialActivityGroupManagementRep, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			m.chart_permission_id,

+ 7 - 1
models/resource_data.go

@@ -17,6 +17,9 @@ type CygxResourceData struct {
 	PublishDate       string    `description:"发布时间"`
 	Abstract          string    `description:"摘要"`
 	SearchTag         string    `description:"搜索标签"`
+	SearchTitle       string    `description:"搜索匹配用的标题"`
+	SearchContent     string    `description:"搜索匹配用的内容"`
+	SearchOrderTime   string    `description:"搜索排序时间"`
 }
 
 type CygxResourceDataResp struct {
@@ -68,7 +71,7 @@ func GetResourceDataListCondition(condition string, pars []interface{}, startSiz
 	if condition != "" {
 		sql += condition
 	}
-	sql += `   LIMIT ?,? `
+	sql += `  ORDER BY search_order_time DESC   LIMIT ?,? `
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
@@ -110,6 +113,9 @@ func UpdateResourceDataByItem(item *CygxResourceData) (err error) {
 	updateParams := make(map[string]interface{})
 	updateParams["PublishDate"] = item.PublishDate
 	updateParams["SearchTag"] = item.SearchTag
+	updateParams["SearchTitle"] = item.SearchTitle
+	updateParams["SearchContent"] = item.SearchContent
+	updateParams["SearchOrderTime"] = item.SearchOrderTime
 	ptrStructOrTableName := "cygx_resource_data"
 	whereParam := map[string]interface{}{"source_id": item.SourceId, "source": item.Source}
 	qs := o.QueryTable(ptrStructOrTableName)

+ 3 - 60
services/cygx_yanxuan_special.go

@@ -225,66 +225,9 @@ func SendWxMsgSpecialAuthor(specialId, status int) (err error) {
 	return
 }
 
-// 更新研选专栏  写入首页最新  cygx_resource_data 表
-func UpdateYanxuanSpecialResourceData(sourceId int) {
-	var err error
-	defer func() {
-		if err != nil {
-			go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId, "ErrMsg", err.Error()), 2)
-		}
-	}()
-	var source = utils.CYGX_OBJ_YANXUANSPECIAL
-	var condition string
-	var pars []interface{}
-	condition = ` AND status = 3  AND  id = ?  `
-	pars = append(pars, sourceId)
-	total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
-	if e != nil {
-		err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
-		return
-	}
-	//如果取消发布了就做删除处理
-	if total == 0 {
-		e = models.DeleteResourceData(sourceId, source)
-		if e != nil {
-			err = errors.New("DeleteResourceData, Err: " + e.Error())
-			return
-		}
-	} else {
-		//判断是否存在,如果不存在就新增,存在就更新
-		totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
-		if e != nil {
-			err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
-			return
-		}
-
-		detail, e := models.GetYanxuanSpecialBySpecialId(sourceId)
-		if e != nil {
-			err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
-			return
-		}
-		publishDate := detail.PublishTime
-		item := new(models.CygxResourceData)
-		item.SourceId = sourceId
-		item.Source = source
-		item.PublishDate = publishDate
-		item.CreateTime = time.Now()
-		if totalData == 0 {
-			_, e := models.AddCygxResourceData(item)
-			if e != nil {
-				err = errors.New("AddCygxResourceData, Err: " + e.Error())
-				return
-			}
-		} else {
-			e = models.UpdateResourceDataByItem(item)
-			if e != nil {
-				err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
-				return
-			}
-		}
-	}
-	return
-}
+//func init() {
+//	UpdateYanxuanSpecialResourceData(229)
+//}
 
 // 获取研选专栏用户信息
 func GetYanxuanSpecialAuthorInfo(user *models.WxUserItem) (isAuthor, isImproveInformation bool) {

+ 34 - 4
services/es_comprehensive.go

@@ -167,6 +167,10 @@ func AddComprehensiveChart(chartId int) {
 	}
 }
 
+//func init() {
+//	AddComprehensiveIndustrialSource("Hz", 9433)
+//}
+
 // 添加产业资源包
 func AddComprehensiveIndustrialSource(sourceType string, articleId int) {
 	var err error
@@ -212,7 +216,7 @@ func AddComprehensiveIndustrialSource(sourceType string, articleId int) {
 	}
 	//indexName := utils.IndexNameComprehensive
 	for _, v := range list {
-		time.Sleep(200 * time.Millisecond)
+		//time.Sleep(200 * time.Millisecond)
 		item := new(ElasticComprehensiveDetail)
 		item.SourceId = v.IndustrialManagementId
 		item.Source = industrialsource
@@ -228,6 +232,7 @@ func AddComprehensiveIndustrialSource(sourceType string, articleId int) {
 		}
 		fmt.Println(item)
 		EsAddOrEditComprehensiveData(item)
+		UpdateComprehensiveIndustrialResourceData(item)
 	}
 }
 
@@ -1003,6 +1008,7 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 	var industrialResourceIdsYx []int // 研选产业资源包
 	var yanxuanSpecialIds []int       // 研选专栏
 	var askserieVideoIds []string     //问答系列视频
+	var reportselectionIds []int      //报告精选
 	//Source      string    `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt "`
 	for _, v := range list {
 		if v.Source == "article" {
@@ -1036,6 +1042,8 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 			yanXuanbodyHighlight[v.SourceId] = v.Body
 		} else if v.Source == utils.CYGX_OBJ_ASKSERIEVIDEO {
 			askserieVideoIds = append(askserieVideoIds, strconv.Itoa(v.SourceId))
+		} else if v.Source == "reportselection" {
+			reportselectionIds = append(reportselectionIds, v.SourceId)
 		}
 	}
 	//处理文章
@@ -1141,6 +1149,27 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 		}
 	}
 
+	//处理报告精选
+	lenreportselectionIds := len(reportselectionIds)
+	if lenreportselectionIds > 0 {
+		pars = make([]interface{}, 0)
+		condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenreportselectionIds) + `)`
+		pars = append(pars, reportselectionIds)
+		listreportselection, e := models.GetReportSelectionList(condition, pars, 0, lenreportselectionIds)
+		if e != nil {
+			err = errors.New("GetReportSelectionList, Err: " + e.Error())
+			return
+		}
+		mapPv := GetCygxReportHistoryRecordListMap(reportselectionIds, "bgjx")
+		for _, v := range listreportselection {
+			v.Title += "(第" + v.Periods + "期)"
+			v.MarketStrategy = AnnotationHtml(v.MarketStrategy)
+			v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
+			v.Pv = mapPv[v.ArticleId]
+			mapItems[fmt.Sprint("reportselection", v.ArticleId)].ReportSelection = v
+		}
+	}
+
 	detail, e := models.GetConfigByCode("city_img_url")
 	if e != nil {
 		err = errors.New("GetResourceDataList, Err: " + e.Error())
@@ -1469,7 +1498,7 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 	for _, vList := range list {
 		for _, v := range mapItems {
 			//如果这些类型都为空,那么就不合并
-			if v.Article == nil && v.Newchart == nil && v.Roadshow == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.Activityspecial == nil && v.Researchsummary == nil && v.Minutessummary == nil && v.Meetingreviewchapt == nil && v.ProductInterior == nil && v.IndustrialResource == nil && v.YanxuanSpecial == nil && v.AskserieVideo == nil {
+			if v.Article == nil && v.Newchart == nil && v.Roadshow == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.Activityspecial == nil && v.Researchsummary == nil && v.Minutessummary == nil && v.Meetingreviewchapt == nil && v.ProductInterior == nil && v.IndustrialResource == nil && v.YanxuanSpecial == nil && v.AskserieVideo == nil && v.ReportSelection == nil {
 				continue
 			}
 			//if v.Article != nil && v.SourceId == vList.SourceId {
@@ -1546,9 +1575,10 @@ func SqlComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*
 		return
 	}
 	var searchTotal int
-	searchTotal = (startSize + 1) * pageSize
+	searchTotal = (startSize/pageSize + 1) * pageSize
 	var list []*models.CygxResourceData
-	fmt.Println(totalTitle)
+	fmt.Println("totalTitle", totalTitle)
+	fmt.Println("totalContent", totalContent)
 	fmt.Println(searchTotal)
 	if totalTitle >= searchTotal {
 		fmt.Println("1")

+ 214 - 10
services/resource_data.go

@@ -483,6 +483,76 @@ func UpdateResourceData(sourceId int, source, doType, publishDate string) (err e
 	return
 }
 
+//func init() {
+//	UpdateNewchartResourceData(5509)
+//}
+
+// 更新图表
+func UpdateNewchartResourceData(sourceId int) {
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("更新图表同步到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId)+"资源类型", 3)
+		}
+	}()
+	var source = utils.CYGX_OBJ_NEWCHART
+	var condition string
+	var pars []interface{}
+	condition = ` AND chart_id = ?  `
+	pars = append(pars, sourceId)
+	total, e := models.GetChartCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetChartCount, Err: " + e.Error())
+		return
+	}
+	//如果取消发布了就做删除处理
+	if total == 0 {
+		e = models.DeleteResourceData(sourceId, source)
+		if e != nil {
+			err = errors.New("DeleteResourceData, Err: " + e.Error())
+			return
+		}
+	} else {
+		//判断是否存在,如果不存在就新增,存在就更新
+		totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
+		if e != nil {
+			err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
+			return
+		}
+		detail, e := models.GetChartDetailByChartId(sourceId)
+		if e != nil {
+			err = errors.New("GetArticleDetailById, Err: " + e.Error())
+			return
+		}
+		publishDate := time.Now().Format(utils.FormatDateTime)
+		item := new(models.CygxResourceData)
+
+		item.SourceId = sourceId
+		item.Source = source
+		item.PublishDate = publishDate
+		item.CreateTime = time.Now()
+		item.SearchTitle = detail.Title
+		item.SearchContent = ""
+		item.SearchOrderTime = detail.CreateDate
+
+		if totalData == 0 {
+			_, e = models.AddCygxResourceData(item)
+			if e != nil {
+				err = errors.New("AddCygxResourceData, Err: " + e.Error())
+				return
+			}
+
+		} else {
+			e = models.UpdateResourceDataByItem(item)
+			if e != nil {
+				err = errors.New("UpdateResourceData, Err: " + e.Error())
+				return
+			}
+		}
+	}
+	return
+}
+
 // 批量删除最新图表数据
 func Deletenewchart(chartIdsDelete []int) (err error) {
 	defer func() {
@@ -564,10 +634,47 @@ func UpdateArticleResourceData(sourceId int) {
 				item.ChartPermissionId = detailCategory.ChartPermissionId
 			}
 		}
+		var industrialName string
+		var subjectName string
+		//建立首页资源表,与产业的关系
+		industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+			return
+		}
+
+		for _, v := range industrialList {
+			industrialName += v.IndustryName
+		}
+
+		//建立首页资源表,与标的 的关系
+		subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+			return
+		}
+
+		for _, v := range subjectList {
+			subjectName += v.SubjectName
+		}
 		item.SourceId = sourceId
 		item.Source = source
 		item.PublishDate = publishDate
 		item.CreateTime = time.Now()
+		item.SearchTitle = detail.Title
+		annotation, e := utils.GetHtmlContentText(detail.Annotation)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+			return
+		}
+		abstract, e := utils.GetHtmlContentText(detail.Abstract)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+			return
+		}
+		item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
+		item.SearchOrderTime = detail.PublishDate
+
 		if totalData == 0 {
 			newId, e := models.AddCygxResourceData(item)
 			if e != nil {
@@ -590,11 +697,6 @@ func UpdateArticleResourceData(sourceId int) {
 		}
 
 		//建立首页资源表,与产业的关系
-		industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
-		if e != nil && e.Error() != utils.ErrNoRow() {
-			err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
-			return
-		}
 		var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
 		for _, v := range industrialList {
 			var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
@@ -607,11 +709,6 @@ func UpdateArticleResourceData(sourceId int) {
 		}
 
 		//建立首页资源表,与标的 的关系
-		subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
-		if e != nil && e.Error() != utils.ErrNoRow() {
-			err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
-			return
-		}
 		var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
 		for _, v := range subjectList {
 			var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
@@ -632,3 +729,110 @@ func UpdateArticleResourceData(sourceId int) {
 	}
 	return
 }
+
+// 更新产业资源包
+func UpdateComprehensiveIndustrialResourceData(itemSource *ElasticComprehensiveDetail) {
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("更新产业资源包到最新数据表失败,Err:"+err.Error()+"资源ID"+strconv.Itoa(itemSource.SourceId), 3)
+		}
+	}()
+	sourceId := itemSource.SourceId
+	var source = itemSource.Source
+
+	//判断是否存在,如果不存在就新增,存在就更新
+	totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
+	if e != nil {
+		err = errors.New("GetCygxResourceDataBySourceAndIdCount, Err: " + e.Error())
+		return
+	}
+
+	item := new(models.CygxResourceData)
+	item.SourceId = sourceId
+	item.Source = source
+	item.PublishDate = itemSource.PublishDate
+	item.CreateTime = time.Now()
+	item.SearchTitle = itemSource.IndustryName + itemSource.SubjectNames
+	item.SearchContent = ""
+	item.SearchOrderTime = itemSource.PublishDate
+
+	if totalData == 0 {
+		_, e = models.AddCygxResourceData(item)
+		if e != nil {
+			err = errors.New("AddCygxResourceData, Err: " + e.Error())
+			return
+		}
+	} else {
+		e = models.UpdateResourceDataByItem(item)
+		if e != nil {
+			err = errors.New("UpdateResourceData, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}
+
+// 更新研选专栏  写入首页最新  cygx_resource_data 表
+func UpdateYanxuanSpecialResourceData(sourceId int) {
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId, "ErrMsg", err.Error()), 2)
+		}
+	}()
+	var source = utils.CYGX_OBJ_YANXUANSPECIAL
+	var condition string
+	var pars []interface{}
+	condition = ` AND status = 3  AND  id = ?  `
+	pars = append(pars, sourceId)
+	total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
+		return
+	}
+	//如果取消发布了就做删除处理
+	if total == 0 {
+		e = models.DeleteResourceData(sourceId, source)
+		if e != nil {
+			err = errors.New("DeleteResourceData, Err: " + e.Error())
+			return
+		}
+	} else {
+		//判断是否存在,如果不存在就新增,存在就更新
+		totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
+		if e != nil {
+			err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
+			return
+		}
+
+		detail, e := models.GetYanxuanSpecialBySpecialId(sourceId)
+		if e != nil {
+			err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
+			return
+		}
+		publishDate := detail.PublishTime
+		item := new(models.CygxResourceData)
+		item.SourceId = sourceId
+		item.Source = source
+		item.PublishDate = publishDate
+		item.CreateTime = time.Now()
+		item.SearchTitle = detail.Title
+		item.SearchContent = ""
+		item.SearchOrderTime = publishDate
+		if totalData == 0 {
+			_, e := models.AddCygxResourceData(item)
+			if e != nil {
+				err = errors.New("AddCygxResourceData, Err: " + e.Error())
+				return
+			}
+		} else {
+			e = models.UpdateResourceDataByItem(item)
+			if e != nil {
+				err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
+				return
+			}
+		}
+	}
+	return
+}

+ 19 - 0
utils/common.go

@@ -8,6 +8,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
+	"html"
 	"image"
 	"image/png"
 	"math"
@@ -935,3 +936,21 @@ func ExtractText(body string) (result string, err error) {
 
 	return
 }
+
+// 提取的纯文本内容
+func GetHtmlContentText(content string) (contentSub string, err error) {
+	if content == "" {
+		return
+	}
+	content = html.UnescapeString(content)
+	doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
+	if err != nil {
+		return
+	}
+	docText := doc.Text()
+	bodyRune := []rune(docText)
+	bodyRuneLen := len(bodyRune)
+	body := string(bodyRune[:bodyRuneLen])
+	contentSub = body
+	return
+}

+ 1 - 0
utils/constants.go

@@ -244,6 +244,7 @@ const (
 	CYGX_OBJ_MINUTESSUMMARY     string = "minutessummary"     // 对象类型:上周纪要汇总
 	CYGX_OBJ_YANXUANSPECIAL     string = "yanxuanspecial"     // 对象类型:研选专栏
 	CYGX_OBJ_ASKSERIEVIDEO      string = "askserievideo"      // 对象类型:问答系列视频
+	CYGX_OBJ_NEWCHART           string = "newchart"           // 对象类型:图表
 )
 
 const (