Browse Source

Merge branch 'cygx_13.0' of http://8.136.199.33:3000/cxzhang/hongze_clpt into debug

xingzai 1 year ago
parent
commit
6e64f3561c
5 changed files with 170 additions and 57 deletions
  1. 1 1
      controllers/search.go
  2. 9 9
      models/chart.go
  3. 24 9
      models/resource_data.go
  4. 9 0
      services/cygx_yanxuan_special.go
  5. 127 38
      services/es_comprehensive.go

+ 1 - 1
controllers/search.go

@@ -390,7 +390,7 @@ func (this *MobileSearchController) ComprehensiveList() {
 		return
 	}
 	resp := new(models.HomeResourceDataListNewResp)
-	tmpResult, tmpTotalResult, err := services.EsComprehensiveSearch(keyWord, startSize, pageSize)
+	tmpResult, tmpTotalResult, err := services.SqlComprehensiveSearch(keyWord, startSize, pageSize)
 	if err != nil {
 		br.Msg = "检索失败"
 		br.ErrMsg = "检索失败,Err:" + err.Error()

+ 9 - 9
models/chart.go

@@ -98,14 +98,14 @@ func GetChartCountById(chartId int) (count int, err error) {
 	return
 }
 
-//新增图表
+// 新增图表
 func AddCygxChart(item *CygxChart) (lastId int64, err error) {
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
 	return
 }
 
-//标签分类
+// 标签分类
 type ChartPtagResultApi struct {
 	Data []ChartPtagResultApidate `json:"data"`
 	Code int                      `json:"code"`
@@ -149,7 +149,7 @@ type ChartCollectReq struct {
 	ChartId int `description:"图表ID"`
 }
 
-//获取图表列表
+// 获取图表列表
 func GetChartList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeChartListResp, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 `
@@ -161,7 +161,7 @@ func GetChartList(condition string, pars []interface{}, startSize, pageSize int)
 	return
 }
 
-//获取所有同步过来的图表
+// 获取所有同步过来的图表
 func GetChartListAll() (items []*HomeChartListResp, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT chart_id FROM cygx_chart  `
@@ -177,7 +177,7 @@ func GetChartListAll() (items []*HomeChartListResp, err error) {
 //	return
 //}
 
-//获取图表列表
+// 获取图表列表
 func GetChartListCollection(condition string, pars []interface{}, userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT a.*,
@@ -186,7 +186,7 @@ func GetChartListCollection(condition string, pars []interface{}, userId, startS
 			( 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
@@ -201,7 +201,7 @@ func GetChartListCollection(condition string, pars []interface{}, userId, startS
 	return
 }
 
-//获取图表列表本地
+// 获取图表列表本地
 func GetChartListCollectionWithCygx(userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT
@@ -233,7 +233,7 @@ func GetChartListConfig() (items []*HomeChartListResp, err error) {
 	return
 }
 
-//获取图表数量
+// 获取图表数量
 func GetChartCount(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT COUNT(1) AS count
@@ -246,7 +246,7 @@ func GetChartCount(condition string, pars []interface{}) (count int, err error)
 	return
 }
 
-//获取图表数量
+// 获取图表数量
 func GetChartCollentCount(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT COUNT(1) AS count

+ 24 - 9
models/resource_data.go

@@ -7,15 +7,18 @@ import (
 )
 
 type CygxResourceData struct {
-	Id          int       `orm:"column(id);pk"`
-	SourceId    int       `description:"资源ID"`
-	Source      string    `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
-	Title       string    `description:"标题"`
-	Annotation  string    `description:"核心观点"`
-	CreateTime  time.Time `description:"创建时间"`
-	PublishDate string    `description:"发布时间"`
-	Abstract    string    `description:"摘要"`
-	SearchTag   string    `description:"搜索标签"`
+	Id              int       `orm:"column(id);pk"`
+	SourceId        int       `description:"资源ID"`
+	Source          string    `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
+	Title           string    `description:"标题"`
+	Annotation      string    `description:"核心观点"`
+	CreateTime      time.Time `description:"创建时间"`
+	PublishDate     string    `description:"发布时间"`
+	Abstract        string    `description:"摘要"`
+	SearchTag       string    `description:"搜索标签"`
+	SearchTitle     string    `description:"搜索匹配用的标题"`
+	SearchContent   string    `description:"搜索匹配用的内容"`
+	SearchOrderTime string    `description:"搜索排序时间"`
 }
 
 type CygxResourceDataResp struct {
@@ -122,6 +125,18 @@ func GetResourceDataList(condition string, pars []interface{}, startSize, pageSi
 	return
 }
 
+// 列表
+func GetResourceDataListCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceData, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT	 *   FROM cygx_resource_data  WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += `  ORDER BY search_order_time DESC   LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 // 获取用户报名成功数量
 func GetResourceDataCount(condition string, pars []interface{}) (count int, err error) {
 	sqlCount := `SELECT COUNT(1) AS count FROM cygx_resource_data    WHERE 1= 1 ` + condition

+ 9 - 0
services/cygx_yanxuan_special.go

@@ -257,12 +257,21 @@ func UpdateYanxuanSpecialResourceData(sourceId int) {
 			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 := 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 = publishDate
 		if totalData == 0 {
 			_, e := models.AddCygxResourceData(item)
 			if e != nil {

+ 127 - 38
services/es_comprehensive.go

@@ -310,6 +310,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  、 产品内测:productinterior
 	for _, v := range list {
 		if v.Source == "article" {
@@ -343,6 +344,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)
 		}
 	}
 	detail, e := models.GetConfigByCode("city_img_url")
@@ -477,6 +480,26 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 			mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
 		}
 	}
+	//处理报告精选
+	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
+		}
+	}
 
 	//处理活动
 	if len(activityIds) > 0 {
@@ -781,46 +804,46 @@ 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 {
-				v.Article.Title = vList.Title
-			}
-			if v.Newchart != nil && v.SourceId == vList.SourceId {
-				v.Newchart.Title = vList.Title
-			}
-			if v.Roadshow != nil && v.SourceId == vList.SourceId {
-				v.Roadshow.Title = vList.Title
-			}
-			if v.Activity != nil && v.SourceId == vList.SourceId {
-				v.Activity.ActivityName = vList.Title
-			}
-			if v.Activityvideo != nil && v.SourceId == vList.SourceId {
-				v.Activityvideo.Title = vList.Title
-			}
-			if v.Activityvoice != nil && v.SourceId == vList.SourceId {
-				v.Activityvoice.Title = vList.Title
-			}
-
-			if v.Activityspecial != nil && v.SourceId == vList.SourceId {
-				v.Activityspecial.ResearchTheme = vList.Title
-			}
-			if v.Researchsummary != nil && v.SourceId == vList.SourceId {
-				v.Researchsummary.Title = vList.Title
-			}
-			if v.Minutessummary != nil && v.SourceId == vList.SourceId {
-				v.Minutessummary.Title = vList.Title
-			}
-			if v.ProductInterior != nil && v.SourceId == vList.SourceId {
-				v.ProductInterior.Title = vList.Title
-			}
-			if v.IndustrialResource != nil && v.SourceId == vList.SourceId && v.Source == vList.Source {
-				v.IndustrialResource.UpdateTime = strings.Replace(vList.PublishDate, "00:00:00", "", -1)
-			}
-			if v.YanxuanSpecial != nil && v.SourceId == vList.SourceId {
-				v.YanxuanSpecial.Title = vList.Title
-			}
+			//if v.Article != nil && v.SourceId == vList.SourceId {
+			//	v.Article.Title = vList.Title
+			//}
+			//if v.Newchart != nil && v.SourceId == vList.SourceId {
+			//	v.Newchart.Title = vList.Title
+			//}
+			//if v.Roadshow != nil && v.SourceId == vList.SourceId {
+			//	v.Roadshow.Title = vList.Title
+			//}
+			//if v.Activity != nil && v.SourceId == vList.SourceId {
+			//	v.Activity.ActivityName = vList.Title
+			//}
+			//if v.Activityvideo != nil && v.SourceId == vList.SourceId {
+			//	v.Activityvideo.Title = vList.Title
+			//}
+			//if v.Activityvoice != nil && v.SourceId == vList.SourceId {
+			//	v.Activityvoice.Title = vList.Title
+			//}
+			//
+			//if v.Activityspecial != nil && v.SourceId == vList.SourceId {
+			//	v.Activityspecial.ResearchTheme = vList.Title
+			//}
+			//if v.Researchsummary != nil && v.SourceId == vList.SourceId {
+			//	v.Researchsummary.Title = vList.Title
+			//}
+			//if v.Minutessummary != nil && v.SourceId == vList.SourceId {
+			//	v.Minutessummary.Title = vList.Title
+			//}
+			//if v.ProductInterior != nil && v.SourceId == vList.SourceId {
+			//	v.ProductInterior.Title = vList.Title
+			//}
+			//if v.IndustrialResource != nil && v.SourceId == vList.SourceId && v.Source == vList.Source {
+			//	v.IndustrialResource.UpdateTime = strings.Replace(vList.PublishDate, "00:00:00", "", -1)
+			//}
+			//if v.YanxuanSpecial != nil && v.SourceId == vList.SourceId {
+			//	v.YanxuanSpecial.Title = vList.Title
+			//}
 			if v.SourceId == vList.SourceId && v.Source == vList.Source {
 				items = append(items, v)
 			}
@@ -834,6 +857,72 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 	return
 }
 
+func SqlComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int, err error) {
+	keyWord = "%" + keyWord + "%"
+	var conditionTitle string
+	var parsTitle []interface{}
+	conditionTitle = " AND search_title LIKE ? "
+	parsTitle = append(parsTitle, keyWord)
+	totalTitle, e := models.GetResourceDataCount(conditionTitle, parsTitle)
+	if e != nil {
+		err = errors.New("GetResourceDataCount, Err: " + e.Error())
+		return
+	}
+
+	var conditionContent string
+	var parsContent []interface{}
+
+	conditionContent = " AND search_content LIKE ? AND search_title  NOT LIKE ?  "
+	parsContent = append(parsContent, keyWord, keyWord)
+	totalContent, e := models.GetResourceDataCount(conditionContent, parsContent)
+	if e != nil {
+		err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
+		return
+	}
+	var searchTotal int
+	searchTotal = (startSize/pageSize + 1) * pageSize
+	var list []*models.CygxResourceData
+	if totalTitle >= searchTotal {
+		//全部都是标题搜索
+		list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
+			return
+		}
+	} else if totalTitle <= searchTotal-pageSize {
+		//全部都是内容搜索
+		list, e = models.GetResourceDataListCondition(conditionContent, parsContent, startSize, pageSize)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
+			return
+		}
+	} else {
+		//一半标题搜索,一半内容搜索
+		list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
+			return
+		}
+		listContent, e := models.GetResourceDataListCondition(conditionContent, parsContent, 0, pageSize-totalContent%pageSize)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
+			return
+		}
+		for _, v := range listContent {
+			list = append(list, v)
+		}
+	}
+
+	for _, v := range list {
+		item := new(SearchComprehensiveItem)
+		item.SourceId = v.SourceId
+		item.Source = v.Source
+		result = append(result, item)
+	}
+	total = totalTitle + totalContent
+	return
+}
+
 // Es研选专栏
 func EsAddYanxuanSpecial(sourceId int) {
 	var err error