Explorar o código

报告搜索、资源包搜索接口

xingzai %!s(int64=2) %!d(string=hai) anos
pai
achega
723f71d158
Modificáronse 4 ficheiros con 198 adicións e 8 borrados
  1. 3 3
      controllers/activity.go
  2. 173 4
      controllers/report.go
  3. 13 1
      models/report.go
  4. 9 0
      routers/commentsRouter.go

+ 3 - 3
controllers/activity.go

@@ -949,7 +949,7 @@ func (this *ActivityCoAntroller) Detail() {
 				var condition string
 				condition = ` AND m.industrial_management_id IN (` + industrialManagementId + `)`
 				condition += ` AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId)
-				listIndustrialGrop, err := models.GetSearchResourceList(condition)
+				listIndustrialGrop, err := models.GetSearchResourceList(condition, 0, 0)
 				if err != nil && err.Error() != utils.ErrNoRow() {
 					br.Msg = "获取信息失败"
 					br.ErrMsg = "GetSearchResourceList,Err:" + err.Error() + "activityId:" + strconv.Itoa(activityId)
@@ -2785,7 +2785,7 @@ func (this *ActivityCoAntroller) ActivityListNew() {
 	activityTypeId := this.GetString("ActivityTypeId")
 	keyWord := this.GetString("KeyWord")
 	playBack, _ := this.GetInt("PlayBack")
-	activityId, _ := this.GetInt("ActivityId")	// 仅用于判断【新】标签
+	activityId, _ := this.GetInt("ActivityId") // 仅用于判断【新】标签
 
 	if label == "undefined" {
 		label = ""
@@ -3618,7 +3618,7 @@ func (this *ActivityCoAntroller) LabelTypeListV5() {
 	}
 
 	//获取对应活动的数量并排序
-	activityIds := make([]int, 0)	// 用于查询活动【新】标签Map
+	activityIds := make([]int, 0) // 用于查询活动【新】标签Map
 	intArr := make([]int, 0)
 	var items []*models.ActivityTypeHome
 	for _, v := range list {

+ 173 - 4
controllers/report.go

@@ -2332,8 +2332,6 @@ func (this *ReportController) SearchReport() {
 	condition = `AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
 	sqlGroup = ` GROUP BY  a.article_id  ORDER BY a.publish_date DESC  `
 	//对应产业名称、标的名称。
-	//OR a.article_id IN ( SELECT article_id FROM cygx_industrial_article_group_subject WHERE industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_subject WHERE subject_name LIKE '%` + keyWord + `%' ) )
-	//OR a.article_id IN ( SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_management WHERE industry_name LIKE '%` + keyWord + `%' ) )
 	listYx, err := models.GetArticleCollectionList(` AND a.article_id >= 1000000 `+condition+sqlGroup, user.UserId)
 	if err != nil {
 		br.Msg = "获取信息失败"
@@ -2419,7 +2417,7 @@ func (this *ReportController) SearchResource() {
 	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)
+	listHz, err := models.GetSearchResourceList(condition, 0, 0)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -2429,7 +2427,7 @@ func (this *ReportController) SearchResource() {
 	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
 
-	listYx, err := models.GetSearchResourceList(condition)
+	listYx, err := models.GetSearchResourceList(condition, 0, 0)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
@@ -2509,3 +2507,174 @@ func (this *ReportController) SearchResource() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 报告搜索、资源包搜索接口
+// @Description 报告搜索、资源包搜索接口接口
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Success 200 {object} models.SearchReportAndResourceResp
+// @router /searchReportAndResource [get]
+func (this *ReportController) SearchReportAndResource() {
+	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
+	keyWord := this.GetString("KeyWord")
+	pageSize, _ := this.GetInt("PageSize")
+	var condition string
+	var sqlGroup string
+	//匹配报告标题、
+	condition = `AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
+	sqlGroup = ` GROUP BY  a.article_id  ORDER BY a.publish_date DESC  `
+	if pageSize > 0 {
+		sqlGroup += ` LIMIT 5 `
+	}
+	ListYxReport, err := models.GetArticleCollectionList(` AND a.article_id >= 1000000 `+condition+sqlGroup, user.UserId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
+		return
+	}
+	for k, v := range ListYxReport {
+		ListYxReport[k].Source = 2
+		if v.MyCollectNum > 0 {
+			ListYxReport[k].IsCollect = true
+		}
+	}
+	ListHzReport, err := models.GetReoprtSearchList(` AND a.article_id < 1000000 `+condition+` OR ( article_type = 'lyjh' `+condition+` ) `+sqlGroup, user.UserId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
+		return
+	}
+	for k, v := range ListHzReport {
+		ListHzReport[k].Source = 1
+		if v.MyCollectNum > 0 {
+			ListHzReport[k].IsCollect = true
+		}
+	}
+
+	if len(ListYxReport) == 0 {
+		ListYxReport = make([]*models.ArticleCollectionResp, 0)
+	}
+	if len(ListHzReport) == 0 {
+		ListHzReport = make([]*models.ArticleCollectionResp, 0)
+	}
+
+	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
+		}
+	}
+
+	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
+
+	listHzResource, err := models.GetSearchResourceList(condition, 0, pageSize)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+		return
+	}
+
+	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
+
+	listYxResource, err := models.GetSearchResourceList(condition, 0, pageSize)
+	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 listHzResource {
+		listHzResource[k].Source = 1
+		if fllowMap[v.IndustrialManagementId] > 0 {
+			listHzResource[k].IsFollw = true
+		}
+		industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
+	}
+
+	for k, v := range listYxResource {
+		listYxResource[k].Source = 2
+		if fllowMap[v.IndustrialManagementId] > 0 {
+			listYxResource[k].IsFollw = 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 listYxResource {
+				if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Yx", v.SubjectName)] == 0 {
+					listYxResource[k2].IndustrialSubjectList = append(listYxResource[k2].IndustrialSubjectList, v)
+					mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Yx", v.SubjectName)] = v2.IndustrialManagementId
+				}
+			}
+			for k2, v2 := range listHzResource {
+				if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
+					listHzResource[k2].IndustrialSubjectList = append(listHzResource[k2].IndustrialSubjectList, v)
+					mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
+				}
+			}
+		}
+	}
+
+	resp := new(models.SearchReportAndResourceResp)
+	if len(listYxResource) == 0 {
+		listYxResource = make([]*models.IndustrialManagementHotResp, 0)
+	}
+	if len(listHzResource) == 0 {
+		listHzResource = make([]*models.IndustrialManagementHotResp, 0)
+	}
+
+	if keyWord != "" {
+		keyWordItem := new(models.CygxUserSearchKeyWord)
+		keyWordItem.UserId = user.UserId
+		keyWordItem.KeyWord = keyWord
+		keyWordItem.PageType = "ReortSearch"
+		keyWordItem.CreateTime = time.Now()
+		go models.AddUserSearchKeyWord(keyWordItem)
+		go services.AddUserSearchLog(user, keyWord, 5)
+	}
+
+	resp.ListHzResource = listHzResource
+	resp.ListYxResource = listYxResource
+	resp.ListYxReport = ListYxReport
+	resp.ListHzReport = ListHzReport
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 13 - 1
models/report.go

@@ -664,8 +664,16 @@ type SearchResourceResp struct {
 	ListYx []*IndustrialManagementHotResp `description:"研选"`
 }
 
+//搜索资源包 start
+type SearchReportAndResourceResp struct {
+	ListHzResource []*IndustrialManagementHotResp `description:"弘则资源包"`
+	ListYxResource []*IndustrialManagementHotResp `description:"研选资源包"`
+	ListYxReport   []*ArticleCollectionResp       `description:"研选报告"`
+	ListHzReport   []*ArticleCollectionResp       `description:"弘则报告"`
+}
+
 //产业列表
-func GetSearchResourceList(condition string) (items []*IndustrialManagementHotResp, err error) {
+func GetSearchResourceList(condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			m.industry_name,
@@ -679,6 +687,10 @@ func GetSearchResourceList(condition string) (items []*IndustrialManagementHotRe
 		WHERE
 			1 = 1
 			AND publish_status = 1 ` + condition + `  GROUP BY m.industrial_management_id  ORDER BY publish_date_order DESC `
+
+	if startSize > 0 || pageSize > 0 {
+		sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
+	}
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 9 - 0
routers/commentsRouter.go

@@ -754,6 +754,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ReportController"],
+        beego.ControllerComments{
+            Method: "SearchReportAndResource",
+            Router: `/searchReportAndResource`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ReportController"],
         beego.ControllerComments{
             Method: "SearchResource",