xingzai 3 سال پیش
والد
کامیت
4cc47fcf5b
3فایلهای تغییر یافته به همراه63 افزوده شده و 8 حذف شده
  1. 29 2
      controllers/report.go
  2. 28 0
      models/article.go
  3. 6 6
      models/article_department.go

+ 29 - 2
controllers/report.go

@@ -1847,6 +1847,7 @@ func (this *ReportController) IndustryAndArticleList() {
 // @Title 产业报告分类关联作者列表接口Pc端
 // @Description 获取产业报告分类关联作者列表接口Pc端
 // @Param   ChartPermissionId   query   int  true       "分类ID"
+// @Param   KeyWord   query   string  true       "搜索关键词"
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Success 200 {object} models.CygxArticleDepartmentListPc
@@ -1867,16 +1868,42 @@ func (this *ReportController) IndustryListByDepartmentPc() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	chartPermissionId, _ := this.GetInt("ChartPermissionId")
+	keyWord := this.GetString("KeyWord")
 	var startSize int
 	var condition string
 	condition = `  AND a.publish_status=1  AND m.chart_permission_id =` + strconv.Itoa(chartPermissionId)
-	//condition = `  AND a.publish_status=1 `
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
 	}
 	if currentIndex <= 0 {
 		currentIndex = 1
 	}
+	var articleIdGroup string
+	if keyWord != "" {
+		articleIdSub, err := models.GetArticleIdSubjectGroup(keyWord)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
+			return
+		}
+		articleIdInd, err := models.GetArticleIndustrialIdGroup(keyWord)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
+			return
+		}
+		if articleIdSub != "" && articleIdInd != "" {
+			articleIdGroup = articleIdSub + "," + articleIdInd
+		} else if articleIdSub != "" && articleIdInd == "" {
+			articleIdGroup = articleIdSub
+		} else if articleIdSub == "" && articleIdInd == "" {
+			articleIdGroup = articleIdInd
+		}
+	}
+
+	if articleIdGroup != "" {
+		condition += `  AND a.article_id IN (` + articleIdGroup + `)`
+	}
 	startSize = paging.StartIndex(currentIndex, pageSize)
 	total, err := models.GetArticleDepartmentCount(condition)
 	page := paging.GetPaging(currentIndex, pageSize, total)
@@ -1904,7 +1931,7 @@ func (this *ReportController) IndustryListByDepartmentPc() {
 		return
 	}
 	for k, v := range list {
-		artList, err := models.GetArticleByDepartmentIdPc(v.DepartmentId)
+		artList, err := models.GetArticleByDepartmentIdPc(v.DepartmentId, articleIdGroup)
 		if err != nil {
 			br.Msg = "获取信息失败"
 			br.ErrMsg = "获取文章信息失败,Err:" + err.Error()

+ 28 - 0
models/article.go

@@ -561,3 +561,31 @@ func GetArticleApiMap() (item []*ArticleApiMap, err error) {
 	_, err = o.Raw(sql).QueryRows(&item)
 	return
 }
+
+func GetArticleIdSubjectGroup(keyWord string) (articleid string, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT
+	GROUP_CONCAT(DISTINCT art.article_id   SEPARATOR ',') AS articleid
+FROM
+	cygx_article AS art
+	INNER JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
+	INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id 
+WHERE
+	s.subject_name  LIKE '%` + keyWord + `%'  `
+	err = o.Raw(sql).QueryRow(&articleid)
+	return
+}
+
+func GetArticleIndustrialIdGroup(keyWord string) (articleid string, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT
+	GROUP_CONCAT(DISTINCT art.article_id   SEPARATOR ',') AS article_id
+FROM
+	cygx_article AS art
+	INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = art.article_id
+	INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id 
+WHERE
+	m.industry_name LIKE  '%` + keyWord + `%'  `
+	err = o.Raw(sql).QueryRow(&articleid)
+	return
+}

+ 6 - 6
models/article_department.go

@@ -274,7 +274,7 @@ type IndustrialManagementIdNamePc struct {
 }
 
 //最新标的列表
-func GetArticleByDepartmentIdPc(departmentId int) (items []*IndustrialManagementIdNamePc, err error) {
+func GetArticleByDepartmentIdPc(departmentId int, articleIdGroup string) (items []*IndustrialManagementIdNamePc, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			m.industry_name,
@@ -289,11 +289,11 @@ func GetArticleByDepartmentIdPc(departmentId int) (items []*IndustrialManagement
 			LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id 
 		WHERE
 			department_id = ? 
-			AND publish_status = 1 
-		GROUP BY
-			art.article_id 
-		ORDER BY
-			publish_date DESC`
+			AND publish_status = 1`
+	if articleIdGroup != "" {
+		sql += ` AND art.article_id IN (` + articleIdGroup + `) `
+	}
+	sql += ` GROUP BY art.article_id ORDER BY publish_date DESC `
 	_, err = o.Raw(sql, departmentId).QueryRows(&items)
 	return
 }