Browse Source

报告搜索添加分页

xingzai 2 years ago
parent
commit
6a5e669b33
7 changed files with 414 additions and 14 deletions
  1. 208 1
      controllers/report.go
  2. 10 11
      models/article.go
  3. 42 0
      models/industrial_management.go
  4. 18 0
      models/industry_fllow.go
  5. 118 1
      models/report.go
  6. 18 0
      routers/commentsRouter.go
  7. 0 1
      services/keyword.go

+ 208 - 1
controllers/report.go

@@ -97,7 +97,13 @@ func (this *MobileReportController) TradeList() {
 		var pars []interface{}
 		condition = " AND  a.category_id_two =  " + strconv.Itoa(v.CategoryId)
 		if ChartPermissionId != utils.CE_LUE_ID {
-			listArticle, err := models.GetHomeList(condition, pars, 0, 6)
+			var pageSize int
+			if ChartPermissionId == utils.KE_JI_ID {
+				pageSize = 12
+			} else {
+				pageSize = 6
+			}
+			listArticle, err := models.GetHomeList(condition, pars, 0, pageSize)
 			if err != nil {
 				br.Msg = "获取信息失败"
 				br.Msg = "GetHomeList,Err:" + err.Error()
@@ -577,3 +583,204 @@ func (this *ReportController) CategoryFllow() {
 	br.Success = true
 	br.Data = resp
 }
+
+// @Title 报告搜索
+// @Description 报告搜索接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Success 200 {object} models.ReoprtSearchResp
+// @router /searchReport [get]
+func (this *MobileReportController) SearchReport() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	keyWord := this.GetString("KeyWord")
+	var condition string
+	var conditionSql string
+	//var sqlGroup string
+	var total int
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	//匹配报告标题、
+	condition = ` AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
+
+	conditionSql = ` AND a.article_id <  ` + strconv.Itoa(utils.SummaryArticleId) + condition + ` OR ( article_type = 'lyjh' ` + condition + ` ) `
+	total, err := models.GetReoprtSearchCount(conditionSql)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.Msg = "获取总数失败,Err:" + err.Error()
+		return
+	}
+	//listHz, err := models.GetReoprtSearchList(` AND a.article_id <  `+strconv.Itoa(utils.SummaryArticleId)+condition+` OR ( article_type = 'lyjh' `+condition+` ) `+sqlGroup, user.UserId, startSize, pageSize)
+	listHz, err := models.GetReoprtSearchList(conditionSql, user.UserId, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
+		return
+	}
+	for k, _ := range listHz {
+		listHz[k].Source = 1
+	}
+	var articleIds string
+	for _, v := range listHz {
+		articleIds += strconv.Itoa(v.ArticleId) + ","
+	}
+	articleIds = strings.TrimRight(articleIds, ",")
+	silcearticleIds := strings.Split(articleIds, ",")
+	//获取文章关联的产业
+	var pars []interface{}
+	pars = make([]interface{}, 0)
+	articleIdList := make([]string, 0)
+	for _, v := range silcearticleIds {
+		articleIdList = append(articleIdList, v)
+	}
+	condition = ` AND mg.article_id IN (  ` + utils.GetOrmInReplace(len(silcearticleIds)) + ` )  `
+	pars = append(pars, articleIdList)
+	industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
+		return
+	}
+	industrialMap := make(map[int][]*models.IndustrialManagementResp)
+	if len(industrialList) > 0 {
+		for _, v := range industrialList {
+			item := new(models.IndustrialManagementResp)
+			//item.ArticleId = v.ArticleId
+			item.IndustrialManagementId = v.IndustrialManagementId
+			item.IndustryName = v.IndustryName
+			industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
+		}
+	}
+	for k, v := range listHz {
+		if len(industrialMap[v.ArticleId]) > 0 {
+			listHz[k].List = industrialMap[v.ArticleId]
+		} else {
+			listHz[k].List = make([]*models.IndustrialManagementResp, 0)
+		}
+	}
+	if keyWord != "" {
+		go services.AddUserSearchLog(user, keyWord, 5)
+	}
+	if len(listHz) == 0 {
+		listHz = make([]*models.ArticleCollectionResp, 0)
+	}
+
+	page = paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(models.ReoprtSearchResp)
+	resp.Paging = page
+	resp.ListHz = listHz
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 资源包搜索
+// @Description 资源包搜索接口
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Success 200 {object} models.SearchResourceResp
+// @router /searchResource [get]
+func (this *MobileReportController) SearchResource() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	fllowList, err := models.GetUserFllowIndustrialList(uid)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,GetUserFllowIndustrialList Err:" + err.Error()
+		return
+	}
+	fllowMap := make(map[int]int)
+	if len(fllowList) > 0 {
+		for _, v := range fllowList {
+			fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
+		}
+	}
+	keyWord := this.GetString("KeyWord")
+	var condition string
+	var conditionOr string
+	conditionOr += `  OR ( m.subject_names LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + `  AND publish_status = 1 ) `
+	condition = ` AND m.industry_name LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + conditionOr
+
+	listHz, err := models.GetSearchResourceList(condition)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+		return
+	}
+	//合并产业关联的标的
+	listSubjcet, err := models.GetThemeHeatSubjectList("")
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
+		return
+	}
+	industrialIdArr := make([]int, 0)
+	for k, v := range listHz {
+		listHz[k].Source = 1
+		if fllowMap[v.IndustrialManagementId] > 0 {
+			listHz[k].IsFollow = true
+		}
+		industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
+	}
+
+	if len(industrialIdArr) > 0 {
+		//合并产业关联的标的
+		listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
+			return
+		}
+		mapIndustrial := make(map[string]int)
+		for _, v := range listSubjcet {
+			for k2, v2 := range listHz {
+				if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
+					listHz[k2].IndustrialSubjectList = append(listHz[k2].IndustrialSubjectList, v)
+					mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
+				}
+			}
+		}
+	}
+
+	if keyWord != "" {
+		go services.AddUserSearchLog(user, keyWord, 4)
+	}
+	resp := new(models.SearchResourceResp)
+	if len(listHz) == 0 {
+		listHz = make([]*models.IndustrialManagement, 0)
+	}
+	resp.ListHz = listHz
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 10 - 11
models/article.go

@@ -98,17 +98,16 @@ func GetArticleCountById(articleId int) (count int, err error) {
 
 //用户收藏榜start
 type ArticleCollectionResp struct {
-	ArticleId              int    `description:"文章id"`
-	Title                  string `description:"标题"`
-	PublishDate            string `description:"发布时间"`
-	IndustrialManagementId int    `description:"产业Id"`
-	IndustryName           string `description:"产业名称"`
-	DepartmentId           int    `description:"作者Id"`
-	NickName               string `description:"作者昵称"`
-	IsCollect              bool   `description:"本人是否收藏"`
-	Pv                     int    `description:"PV"`
-	CollectNum             int    `description:"收藏人数"`
-	Source                 int    `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
+	ArticleId    int                         `description:"文章id"`
+	Title        string                      `description:"标题"`
+	PublishDate  string                      `description:"发布时间"`
+	DepartmentId int                         `description:"作者Id"`
+	NickName     string                      `description:"作者昵称"`
+	IsCollect    bool                        `description:"本人是否收藏"`
+	Pv           int                         `description:"PV"`
+	CollectNum   int                         `description:"收藏人数"`
+	Source       int                         `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
+	List         []*IndustrialManagementResp `description:"产业列表"`
 }
 
 //列表

+ 42 - 0
models/industrial_management.go

@@ -52,6 +52,11 @@ type IndustrialSubject struct {
 	IndustryName           string `description:"产业名称"`
 }
 
+type IndustrialSubjectResp struct {
+	IndustrialSubjectId int    `orm:"column(industrial_subject_id);pk" description:"标的id"`
+	SubjectName         string `description:"标的名称"`
+}
+
 type IndustrialManagementArticle struct {
 	IndustrialManagementId int    `description:"产业Id"`
 	IndustryName           string `description:"产业名称"`
@@ -59,6 +64,11 @@ type IndustrialManagementArticle struct {
 	PublishDate            string `description:"发布时间"`
 }
 
+type IndustrialManagementResp struct {
+	IndustrialManagementId int    `description:"产业Id"`
+	IndustryName           string `description:"产业名称"`
+}
+
 //产业列表
 func GetIndustrialManagementAllCount(condition string) (count int, err error) {
 	o := orm.NewOrm()
@@ -199,3 +209,35 @@ func GetindustrialManagement() (items []*IndustrialManagementRep, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+//标的列表
+func GetIndustrialSubjectAllByIndustrialId(industrialIdArr []int) (items []*IndustrialSubject, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_industrial_subject WHERE industrial_management_id IN  (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)   `
+	_, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
+	return
+}
+
+//标的列表
+func GetIndustrialSubjectAllByIndustrialId111(industrialIdArr []int) (items []*IndustrialSubject, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_industrial_subject WHERE industrial_management_id IN  (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)   `
+	_, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
+	return
+}
+
+//获取标的列表
+func GetIndustrialListByarticleId(pars []interface{}, condition string) (items []*IndustrialManagementIdInt, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			mg.article_id,
+			m.industry_name,
+			mg.industrial_management_id 
+		FROM
+			cygx_industrial_management AS m
+			INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id 
+		WHERE
+			1 = 1  ` + condition + ` GROUP BY  mg.article_id,	mg.industrial_management_id `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 18 - 0
models/industry_fllow.go

@@ -75,3 +75,21 @@ func GetCountCygxIndustryFllowByUidAndChartPermissionId(userId, ChartPermissionI
 	err = orm.NewOrm().Raw(sql, userId, ChartPermissionId).QueryRow(&count)
 	return
 }
+
+//获取用户关注的产业列表
+func GetUserFllowIndustrialList(userId int) (items []*CygxIndustryFllow, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			f.user_id,
+			m.industry_name,
+			m.industrial_management_id 
+		FROM
+			cygx_industry_fllow AS f
+			INNER JOIN wx_user AS u ON f.user_id = u.user_id
+			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id 
+		WHERE
+			1 = 1 
+			AND f.user_id = ? `
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	return
+}

+ 118 - 1
models/report.go

@@ -1,6 +1,9 @@
 package models
 
-import "github.com/rdlucklib/rdluck_tools/paging"
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
 
 type IndustrialManagementList struct {
 	Paging *paging.PagingItem
@@ -18,6 +21,7 @@ type IndustrialManagement struct {
 	IsShowRoadshow         bool                 `description:"是否展示 微路演 标签"`
 	ArticleReadNum         int                  `description:"文章阅读数量"`
 	ArticleId              int                  `description:"文章id"`
+	Source                 int                  `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
 	IndustrialSubjectList  []*IndustrialSubject `description:"标的列表"`
 }
 
@@ -26,4 +30,117 @@ type TacticsListResp struct {
 	MatchTypeName    string `description:"匹配类型"`
 	CategoryImgUrlPc string `description:"图片"`
 	List             []*HomeArticle
+	ListSubject      []*IndustrialSubjectResp
 }
+
+//报告搜索start
+type ReoprtSearchResp struct {
+	Paging *paging.PagingItem
+	ListHz []*ArticleCollectionResp `description:"弘则报告"`
+}
+
+//搜索资源包 start
+type SearchResourceResp struct {
+	ListHz []*IndustrialManagement `description:"弘则"`
+}
+
+//用户收藏榜start
+//type IndustrialManagementHotResp struct {
+//	IndustrialManagementId int                  `orm:"column(industrial_management_id);pk" description:"产业id"`
+//	IndustryName           string               `description:"产业名称"`
+//	IsFollw                bool                 `description:"是否关注"`
+//	FllowNum               int                  `description:"关注数量"`
+//	IsNew                  bool                 `description:"是否新标签"`
+//	IsHot                  bool                 `description:"是否新标签"`
+//	PublishDate            string               `description:"发布时间"`
+//	ArticleReadNum         int                  `description:"文章阅读数量"`
+//	Source                 int                  `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
+//	IndustrialSubjectList  []*IndustrialSubject `description:"标的列表"`
+//}
+
+//获取列表数量
+func GetReoprtSearchCount(condition string) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			COUNT( 1 ) AS count 
+		FROM
+			cygx_article AS a 
+		WHERE
+			1 = 1 
+			AND a.article_id < 1000000 `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql).QueryRow(&count)
+	return
+}
+
+//列表
+func GetReoprtSearchList(condition string, userId, startSize, pageSize int) (items []*ArticleCollectionResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			a.article_id,
+			a.title,
+			date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
+			m.industry_name,
+			m.industrial_management_id,
+			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id  AND user_id = ?) AS my_collect_num
+		FROM
+			cygx_article AS a
+			LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
+			LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
+		WHERE
+			1 = 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY  a.article_id  ORDER BY a.publish_date DESC  LIMIT ?,? `
+	_, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
+	return
+} //end
+
+//列表
+func GetSearchResourceList(condition string) (items []*IndustrialManagement, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			m.industry_name,
+			m.industrial_management_id,
+ 			MAX( a.publish_date ) as publish_date_order,
+			date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date 
+		FROM
+			cygx_industrial_management AS m
+			INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
+			INNER JOIN cygx_article AS a ON a.article_id = mg.article_id  AND  a.article_type != 'lyjh'
+		WHERE
+			1 = 1
+			AND publish_status = 1 ` + condition + `  GROUP BY m.industrial_management_id  ORDER BY publish_date_order DESC `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//标的列表
+func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			m.subject_name,
+			m.industrial_management_id,
+			m.industrial_subject_id 
+		FROM
+			cygx_article AS a
+			INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
+			INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id 
+		WHERE
+			1 = 1`
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` AND publish_status = 1 
+		GROUP BY
+			m.industrial_subject_id 
+		ORDER BY
+			publish_date DESC`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+} //end

+ 18 - 0
routers/commentsRouter.go

@@ -106,6 +106,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:MobileReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:MobileReportController"],
+        beego.ControllerComments{
+            Method: "SearchReport",
+            Router: `/searchReport`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:MobileReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:MobileReportController"],
+        beego.ControllerComments{
+            Method: "SearchResource",
+            Router: `/searchResource`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:MobileReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:MobileReportController"],
         beego.ControllerComments{
             Method: "TradeList",

+ 0 - 1
services/keyword.go

@@ -45,7 +45,6 @@ func AddUserSearchLog(user *models.WxUserItem, keyWord string, source int) (err
 		if err != nil {
 			fmt.Println(err)
 			go utils.SendAlarmMsg(" 记录用户搜索关键词的日志"+err.Error(), 2)
-			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改活动状态至进行中失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
 		}
 	}()
 	item := new(models.CygxSearchKeyWordLog)