瀏覽代碼

作者下的产业文章列表

xingzai 3 年之前
父節點
當前提交
716bbc7681
共有 5 個文件被更改,包括 79 次插入23 次删除
  1. 32 13
      controllers/report.go
  2. 1 0
      models/article.go
  3. 23 4
      models/article_department.go
  4. 7 0
      models/industrial_management.go
  5. 16 6
      models/report.go

+ 32 - 13
controllers/report.go

@@ -638,7 +638,7 @@ func (this *ReportController) IndustryListByDepartment() {
 	chartPermissionId, _ := this.GetInt("ChartPermissionId")
 	chartPermissionId, _ := this.GetInt("ChartPermissionId")
 	var startSize int
 	var startSize int
 	var condition string
 	var condition string
-	condition = ` AND m.chart_permission_id =` + strconv.Itoa(chartPermissionId)
+	condition = ` AND a.publish_status=1  AND m.chart_permission_id =` + strconv.Itoa(chartPermissionId)
 	if pageSize <= 0 {
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
 		pageSize = utils.PageSize20
 	}
 	}
@@ -678,31 +678,37 @@ func (this *ReportController) IndustryListByDepartment() {
 			br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 			br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 			return
 			return
 		}
 		}
-		for k2, v2 := range listDepar {
-			condition := ` AND  mg.industrial_management_id =  ` + strconv.Itoa(v2.IndustrialManagementId)
-			listSubject, err := models.GetIndustrialSubjectNewList(condition)
+		var listSubject []*models.IndustrialManagementIdName
+		var listSubjects []*models.IndustrialManagementIdName
+		for _, v2 := range listDepar {
+			listSubject, err = models.GetIndustrialSubjectNewListByDepartmentId(v.DepartmentId, v2.IndustrialManagementId)
 			if err != nil {
 			if err != nil {
 				br.Msg = "获取失败" + strconv.Itoa(v2.IndustrialManagementId)
 				br.Msg = "获取失败" + strconv.Itoa(v2.IndustrialManagementId)
 				br.ErrMsg = "获取失败,Err:" + err.Error()
 				br.ErrMsg = "获取失败,Err:" + err.Error()
 				return
 				return
 			}
 			}
 			if len(listSubject) > 0 {
 			if len(listSubject) > 0 {
-				listDepar[k2].SubjectName = ""
-				for _, v3 := range listSubject {
-					listDepar[k2].SubjectName += v3.SubjectName + "/"
+				for k3, v3 := range listSubject {
+					listSubject[k3].IndustryName = v2.IndustryName + "—" + v3.SubjectName
+					listSubject[k3].DepartmentId = v.DepartmentId
+					haveSubject := true
+					for _, v4 := range listSubjects {
+						if v4.SubjectName == v3.SubjectName {
+							haveSubject = false
+						}
+					}
+					//判断是否存在,如果没有那么合并
+					if len(listSubjects) < 4 && haveSubject {
+						listSubjects = append(listSubjects, listSubject[k3])
+					}
 				}
 				}
-				listDepar[k2].SubjectName = strings.TrimRight(listDepar[k2].SubjectName, "/")
-			}
-			if listDepar[k2].SubjectName != "" {
-				listDepar[k2].IndustryName += "-" + listDepar[k2].SubjectName
 			}
 			}
 		}
 		}
-		list[k].List = listDepar
+		list[k].List = listSubjects
 		if v.FollowNum > 0 {
 		if v.FollowNum > 0 {
 			list[k].IsMyFollow = true
 			list[k].IsMyFollow = true
 		}
 		}
 	}
 	}
-
 	resp.ListnNew, err = models.GetIndustrialSubjectByDepartmentNew(chartPermissionId)
 	resp.ListnNew, err = models.GetIndustrialSubjectByDepartmentNew(chartPermissionId)
 	if err != nil {
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.Msg = "获取信息失败"
@@ -817,6 +823,7 @@ func (this *ReportController) FllowDepartment() {
 // @Description 获取研选文章列表接口
 // @Description 获取研选文章列表接口
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ArticleId      query   int  true       "文章id"
 // @Param   DepartmentId   query   int  true       "作者ID"
 // @Param   DepartmentId   query   int  true       "作者ID"
 // @Param   IndustrialManagementId   query   int  true       "产业ID"
 // @Param   IndustrialManagementId   query   int  true       "产业ID"
 // @Success 200 {object} models.ReportArticleWhichIndustrialRepList
 // @Success 200 {object} models.ReportArticleWhichIndustrialRepList
@@ -838,6 +845,7 @@ func (this *ReportController) ReportList() {
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	departmentId, _ := this.GetInt("DepartmentId")
 	departmentId, _ := this.GetInt("DepartmentId")
 	industrialManagementId, _ := this.GetInt("IndustrialManagementId")
 	industrialManagementId, _ := this.GetInt("IndustrialManagementId")
+	articleId, _ := this.GetInt("ArticleId")
 	var condition string
 	var condition string
 	var startSize int
 	var startSize int
 	if pageSize <= 0 {
 	if pageSize <= 0 {
@@ -870,8 +878,19 @@ func (this *ReportController) ReportList() {
 		condition += ` AND art.department_id = ` + strconv.Itoa(departmentId)
 		condition += ` AND art.department_id = ` + strconv.Itoa(departmentId)
 	}
 	}
 	if industrialManagementId > 0 {
 	if industrialManagementId > 0 {
+
 		condition += ` AND m.industrial_management_id = ` + strconv.Itoa(industrialManagementId)
 		condition += ` AND m.industrial_management_id = ` + strconv.Itoa(industrialManagementId)
 	}
 	}
+	if articleId > 0 {
+		detail, err := models.GetArticleDetailById(articleId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取信息失败,Err:" + err.Error()
+			return
+		}
+		condition += ` AND art.subject_ids = '` + detail.SubjectIds + `'`
+	}
+
 	total, err = models.GetWhichDepartmentCount(condition)
 	total, err = models.GetWhichDepartmentCount(condition)
 	if err != nil {
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.Msg = "获取信息失败"

+ 1 - 0
models/article.go

@@ -118,6 +118,7 @@ type ArticleDetail struct {
 	FollowNum            int    `description:"关注数量"`
 	FollowNum            int    `description:"关注数量"`
 	CollectionNum        int    `description:"收藏数量"`
 	CollectionNum        int    `description:"收藏数量"`
 	DepartmentId         int    `description:"作者ID"`
 	DepartmentId         int    `description:"作者ID"`
+	SubjectIds           string `description:"文章关联标的的ID字符串"`
 	SellerList           []*SellerRep
 	SellerList           []*SellerRep
 }
 }
 
 

+ 23 - 4
models/article_department.go

@@ -16,13 +16,13 @@ type CygxArticleDepartment struct {
 }
 }
 
 
 type CygxArticleDepartmentRep struct {
 type CygxArticleDepartmentRep struct {
-	DepartmentId int    `description:"主键ID"`
+	DepartmentId int    `description:"作者ID"`
 	CreateTime   string `description:"创建时间"`
 	CreateTime   string `description:"创建时间"`
 	NickName     string `description:"昵称"`
 	NickName     string `description:"昵称"`
 	ImgUrl       string `description:"头像链接"`
 	ImgUrl       string `description:"头像链接"`
 	FollowNum    int    `description:"是否关注 1是 ,0 否"`
 	FollowNum    int    `description:"是否关注 1是 ,0 否"`
 	IsMyFollow   bool   `description:"是否关注"`
 	IsMyFollow   bool   `description:"是否关注"`
-	List         []*IndustrialManagementIdInt
+	List         []*IndustrialManagementIdName
 }
 }
 
 
 type CygxArticleDepartmentId struct {
 type CygxArticleDepartmentId struct {
@@ -66,7 +66,7 @@ func GetArticleDepartmentCount(condition string) (count int, err error) {
 func GetCygxArticleDepartmentList(startSize, pageSize int, condition string, uid int) (items []*CygxArticleDepartmentRep, err error) {
 func GetCygxArticleDepartmentList(startSize, pageSize int, condition string, uid int) (items []*CygxArticleDepartmentRep, err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	sql := `SELECT d.*,
 	sql := `SELECT d.*,
-		( SELECT COUNT( 1 ) FROM cygx_article AS a INNER JOIN cygx_article_history_record as h ON h.article_id = a.article_id WHERE  a.department_id = d.department_id  ) AS art_num,
+		( SELECT COUNT( 1 ) FROM cygx_article AS a INNER JOIN cygx_article_history_record as h ON h.article_id = a.article_id WHERE  a.department_id = d.department_id  AND a.publish_status = 1  AND a.is_report = 1  ) AS art_num,
 		( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS f  WHERE f.department_id = d.department_id AND f.user_id = ? AND f.type = 1 ) AS follow_num
 		( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS f  WHERE f.department_id = d.department_id AND f.user_id = ? AND f.type = 1 ) AS follow_num
 		FROM
 		FROM
 		cygx_article_department AS d
 		cygx_article_department AS d
@@ -98,7 +98,7 @@ func GetIndustrialSubjectByDepartment(departmentId int) (items []*IndustrialMana
 			WHERE 1= 1
 			WHERE 1= 1
 			AND d.department_id = ?
 			AND d.department_id = ?
 			AND a.publish_status = 1
 			AND a.publish_status = 1
-			GROUP BY m.industrial_management_id
+			GROUP BY a.article_id
 			ORDER BY art_time DESC
 			ORDER BY art_time DESC
 			LIMIT 4 `
 			LIMIT 4 `
 	_, err = o.Raw(sql, departmentId).QueryRows(&items)
 	_, err = o.Raw(sql, departmentId).QueryRows(&items)
@@ -116,6 +116,7 @@ func GetIndustrialSubjectByDepartmentNew(industrialManagementId int) (items []*I
 			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id 
 			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id 
 			WHERE 1 = 1 
 			WHERE 1 = 1 
 			AND m.chart_permission_id = ?
 			AND m.chart_permission_id = ?
+			AND a.publish_status=1 
 			GROUP BY
 			GROUP BY
 			m.industrial_management_id 
 			m.industrial_management_id 
 			ORDER BY art_time DESC LIMIT 6 `
 			ORDER BY art_time DESC LIMIT 6 `
@@ -154,3 +155,21 @@ func GetIndustrialSubjectNewList(condition string) (items []*IndustrialSubjectLi
 	_, err = o.Raw(sql).QueryRows(&items)
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 	return
 }
 }
+
+//最新标的列表
+func GetIndustrialSubjectNewListByDepartmentId(departmentId, industrialManagementId int) (items []*IndustrialManagementIdName, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT art.article_id,
+			( SELECT GROUP_CONCAT( DISTINCT s.subject_name ORDER BY s.industrial_subject_id DESC SEPARATOR '/' )  ) AS subject_name
+			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
+				department_id = ?
+				AND s.industrial_management_id = ?
+				GROUP BY art.article_id
+				ORDER BY s.create_time DESC  LIMIT 4`
+	_, err = o.Raw(sql, departmentId, industrialManagementId).QueryRows(&items)
+	return
+}

+ 7 - 0
models/industrial_management.go

@@ -224,6 +224,13 @@ type IndustrialManagementIdInt struct {
 	SubjectName            string `description:"标的名称"`
 	SubjectName            string `description:"标的名称"`
 }
 }
 
 
+type IndustrialManagementIdName struct {
+	DepartmentId int    `description:"作者ID"`
+	ArticleId    int    `description:"文章id"`
+	IndustryName string `description:"产业名称"`
+	SubjectName  string `description:"标的名称"`
+}
+
 //获取归类产业报告数量大于10的
 //获取归类产业报告数量大于10的
 func GetIndustrialManagementIds() (items []*IndustrialManagementIdInt, err error) {
 func GetIndustrialManagementIds() (items []*IndustrialManagementIdInt, err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()

+ 16 - 6
models/report.go

@@ -1,7 +1,6 @@
 package models
 package models
 
 
 import (
 import (
-	"fmt"
 	"rdluck_tools/orm"
 	"rdluck_tools/orm"
 	"rdluck_tools/paging"
 	"rdluck_tools/paging"
 	"strconv"
 	"strconv"
@@ -182,9 +181,22 @@ FROM
 
 
 func GetWhichDepartmentCount(condition string) (count int, err error) {
 func GetWhichDepartmentCount(condition string) (count int, err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
-	sql := `SELECT COUNT(*) count 
-			FROM(
-			SELECT COUNT(1) count 
+	//sql := `SELECT COUNT(*) count
+	//		FROM(
+	//		SELECT COUNT(1) count
+	//		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
+	//		INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
+	//		WHERE 1 = 1
+	//		AND art.publish_status = 1`
+	//if condition != "" {
+	//	sql += condition
+	//}
+	//sql += ` ) AS num`
+
+	sql := `SELECT COUNT(1) count 
 			FROM
 			FROM
 			cygx_article AS art
 			cygx_article AS art
 			INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id 
 			INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id 
@@ -195,8 +207,6 @@ func GetWhichDepartmentCount(condition string) (count int, err error) {
 	if condition != "" {
 	if condition != "" {
 		sql += condition
 		sql += condition
 	}
 	}
-	sql += ` ) AS num`
-	fmt.Println(sql)
 	err = o.Raw(sql).QueryRow(&count)
 	err = o.Raw(sql).QueryRow(&count)
 	return
 	return
 }
 }