Преглед изворни кода

研选最新主题关键词文章列表接口修改

xingzai пре 3 година
родитељ
комит
d8a2503727
4 измењених фајлова са 205 додато и 86 уклоњено
  1. 126 22
      controllers/report.go
  2. 38 36
      models/article.go
  3. 20 13
      models/article_department.go
  4. 21 15
      models/industrial_management.go

+ 126 - 22
controllers/report.go

@@ -636,7 +636,7 @@ func (this *ReportController) IndustryListByDepartment() {
 	chartPermissionId, _ := this.GetInt("ChartPermissionId")
 	var startSize int
 	var condition string
-	condition = `	AND a.is_report = 1  AND a.publish_status=1  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 {
 		pageSize = utils.PageSize20
 	}
@@ -725,17 +725,12 @@ func (this *ReportController) IndustryListByDepartment() {
 	}
 	if len(listnNew) > 0 {
 		for _, v := range listnNew {
-			total, err := models.GetIndustrialManagementSubjectCount(v.IndustrialManagementId)
-			if err != nil {
-				br.Msg = "获取信息失败"
-				br.ErrMsg = "获取关联标的总数失败,Err:" + err.Error()
-				return
-			}
+			firstStr := strings.Index(v.IndustrialAndSubjectIds, "—")
 			Management := new(models.IndustrialManagementIdInt)
-			if total == 0 {
+			if firstStr == 0 {
 				Management.IndustryName = v.IndustryName
 			} else {
-				listSub, err := models.GetIndustrialManagementSubjectList(v.IndustrialManagementId)
+				listSub, err := models.GetIndustrialManagementSubjectList(v.ArticleId)
 				if err != nil {
 					br.Msg = "获取信息失败"
 					br.ErrMsg = "获取关联标的列表失败,Err:" + err.Error()
@@ -748,20 +743,8 @@ func (this *ReportController) IndustryListByDepartment() {
 				subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
 				Management.IndustryName = subjectNamesNew
 			}
-			//if v.SubjectNames != "" {
-			//	var subjectNamesNew string
-			//	slice := strings.Split(v.SubjectNames, ",")
-			//	for k1, v1 := range slice {
-			//		if k1 < 4 && k1 < len(slice)-1 {
-			//			subjectNamesNew += v1 + "/"
-			//		}
-			//	}
-			//	subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
-			//	Management.IndustryName = subjectNamesNew
-			//} else {
-			//	Management.IndustryName = v.IndustryName
-			//}
 			Management.IndustrialManagementId = v.IndustrialManagementId
+			Management.ArticleId = v.ArticleId
 			resp.ListnNew = append(resp.ListnNew, Management)
 		}
 	}
@@ -999,3 +982,124 @@ func (this *ReportController) ReportList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 研选最新主题关键词文章列表接口
+// @Description 获取研选最新主题关键词文章列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ArticleId      query   int  true       "文章id"
+// @Success 200 {object} models.ReportArticleWhichIndustrialRepList
+// @router /industry/reportListNew [get]
+func (this *ReportController) ReportListNew() {
+	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
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	articleId, _ := this.GetInt("ArticleId")
+	var condition string
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	var pars []interface{}
+	var total int
+	resp := new(models.ReportArticleWhichIndustrialRepList)
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	userType, _, err := services.GetUserType(user.CompanyId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	if userType == 1 {
+		resp.Paging = page
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+	resp.HaveResearch = true
+	if articleId > 0 {
+		detail, err := models.GetArticleDetailById(articleId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取信息失败,Err:" + err.Error()
+			return
+		}
+		fmt.Println(detail.IndustrialAndSubjectIds)
+		fmt.Println(detail.IndustrialManagementId)
+		firstStr := strings.Index(detail.IndustrialAndSubjectIds, "—")
+		fmt.Println(firstStr)
+		if firstStr == 0 {
+			condition += ` AND art.industrial_management_id = '` + strconv.Itoa(detail.IndustrialManagementId) + `'`
+		} else {
+			condition += ` AND art.industrial_and_subject_ids = '` + detail.IndustrialAndSubjectIds + `'`
+		}
+	}
+	total, err = models.GetWhichDepartmentCount(condition)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
+		return
+	}
+	page = paging.GetPaging(currentIndex, pageSize, total)
+	condition += `  GROUP BY art.article_id ORDER BY art.publish_date DESC`
+	list, err := models.IndustrialToArticleWhichDepartment(condition, pars, uid, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	for k, v := range list {
+		if v.Readnum == 0 {
+			list[k].IsRed = true
+		}
+		list[k].IsResearch = true
+		subjectNames, err := models.GetSubjectNames(v.ArticleId)
+		if err != nil {
+			br.Msg = "获取失败" + strconv.Itoa(v.ArticleId)
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		var subjectNamesNew string
+		if len(subjectNames) > 0 {
+			slice := strings.Split(subjectNames, "/")
+			for k3, v3 := range slice {
+				if k3 < 4 {
+					subjectNamesNew += v3 + "/"
+				}
+			}
+		}
+		industryName, err := models.GetIndustrialNames(v.ArticleId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败" + strconv.Itoa(v.ArticleId)
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
+		list[k].SubjectName = subjectNamesNew
+		list[k].IndustryName = industryName + "-" + subjectNamesNew
+		resp.IndustryName = industryName
+	}
+	resp.List = list
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 38 - 36
models/article.go

@@ -84,42 +84,44 @@ type HomeArticle struct {
 }
 
 type ArticleDetail struct {
-	ArticleId            int    `description:"报告id"`
-	Title                string `description:"标题"`
-	TitleEn              string `description:"英文标题 "`
-	UpdateFrequency      string `description:"更新周期"`
-	CreateDate           string `description:"创建时间"`
-	PublishDate          string `description:"发布时间"`
-	Body                 string `description:"内容"`
-	Abstract             string `description:"摘要"`
-	CategoryName         string `description:"一级分类"`
-	SubCategoryName      string `description:"二级分类"`
-	IsCollect            bool   `description:"是否收藏:true,已收藏,false:未收藏"`
-	IsInterviewApply     bool   `description:"是否申请访谈:true,已申请,false:未申请"`
-	BodyText             string `description:"内容"`
-	InterviewApplyStatus string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
-	InterviewDate        string `description:"访谈时间"`
-	ExpertBackground     string `description:"专家背景"`
-	ExpertNumber         string `description:"专家编号"`
-	Department           string `description:"作者"`
-	SellerMobile         string `description:"销售手机号"`
-	SellerName           string `description:"销售名称"`
-	ArticleIdMd5         string `description:"纪要id"`
-	IsClass              int    `description:"是否归类,1是,0否"`
-	CategoryId           int    `description:"分类ID"`
-	IsSummary            int    `description:"是否是纪要库,1是,0否"`
-	IsReport             int    `description:"是否属于报告,1是,0否"`
-	IsResearch           bool   `description:"是否属于研选"`
-	FileLink             string `description:"下载预览链接"`
-	SellerAndMobile      string `description:"销售和手机号"`
-	IsFollow             bool   `description:"是否关注,1是,0否"`
-	IsBelongSummary      bool   `description:"是否属于纪要库"`
-	IsBelongReport       bool   `description:"是否属于报告"`
-	FollowNum            int    `description:"关注数量"`
-	CollectionNum        int    `description:"收藏数量"`
-	DepartmentId         int    `description:"作者ID"`
-	SubjectIds           string `description:"文章关联标的的ID字符串"`
-	SellerList           []*SellerRep
+	ArticleId               int    `description:"报告id"`
+	Title                   string `description:"标题"`
+	TitleEn                 string `description:"英文标题 "`
+	UpdateFrequency         string `description:"更新周期"`
+	CreateDate              string `description:"创建时间"`
+	PublishDate             string `description:"发布时间"`
+	Body                    string `description:"内容"`
+	Abstract                string `description:"摘要"`
+	CategoryName            string `description:"一级分类"`
+	SubCategoryName         string `description:"二级分类"`
+	IsCollect               bool   `description:"是否收藏:true,已收藏,false:未收藏"`
+	IsInterviewApply        bool   `description:"是否申请访谈:true,已申请,false:未申请"`
+	BodyText                string `description:"内容"`
+	InterviewApplyStatus    string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
+	InterviewDate           string `description:"访谈时间"`
+	ExpertBackground        string `description:"专家背景"`
+	ExpertNumber            string `description:"专家编号"`
+	Department              string `description:"作者"`
+	SellerMobile            string `description:"销售手机号"`
+	SellerName              string `description:"销售名称"`
+	ArticleIdMd5            string `description:"纪要id"`
+	IsClass                 int    `description:"是否归类,1是,0否"`
+	CategoryId              int    `description:"分类ID"`
+	IsSummary               int    `description:"是否是纪要库,1是,0否"`
+	IsReport                int    `description:"是否属于报告,1是,0否"`
+	IsResearch              bool   `description:"是否属于研选"`
+	FileLink                string `description:"下载预览链接"`
+	SellerAndMobile         string `description:"销售和手机号"`
+	IsFollow                bool   `description:"是否关注,1是,0否"`
+	IsBelongSummary         bool   `description:"是否属于纪要库"`
+	IsBelongReport          bool   `description:"是否属于报告"`
+	FollowNum               int    `description:"关注数量"`
+	CollectionNum           int    `description:"收藏数量"`
+	DepartmentId            int    `description:"作者ID"`
+	SubjectIds              string `description:"文章关联标的的ID字符串"`
+	IndustrialAndSubjectIds string `description:"文章关联产业和标的的ID字符串"`
+	IndustrialManagementId  int    `description:"文章关联产业ID"`
+	SellerList              []*SellerRep
 }
 
 type ArticleDetailFileLink struct {

+ 20 - 13
models/article_department.go

@@ -115,19 +115,26 @@ func GetIndustrialSubjectByDepartment(departmentId int) (items []*IndustrialMana
 //最新产业列表
 func GetIndustrialSubjectByDepartmentNew() (items []*IndustrialManagementIdInts, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT m.*, MAX( a.publish_date ) art_time
-			FROM
-			cygx_article_department AS d
-			INNER JOIN cygx_article AS a ON a.department_id = d.department_id
-			INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
-			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id 
-			WHERE 1 = 1
-			AND a.publish_status=1 
-			AND a.subject_ids != ''
-			AND a.is_report=1 
-			GROUP BY
-			m.industrial_management_id 
-			ORDER BY art_time DESC LIMIT 6 `
+	sql := `SELECT
+	a.article_id,
+	a.industrial_and_subject_ids,
+	m.*,
+	MAX( a.publish_date ) art_time
+FROM
+	cygx_article_department AS d
+	INNER  JOIN cygx_article AS a ON a.department_id = d.department_id
+	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 
+	LEFT JOIN cygx_industrial_article_group_subject AS sg  ON sg.article_id = a.article_id
+WHERE
+	1 = 1 
+	AND a.publish_status = 1 
+	AND a.industrial_and_subject_ids != '' 
+GROUP BY
+	a.industrial_and_subject_ids 
+ORDER BY
+	art_time DESC 
+	LIMIT 6 `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 21 - 15
models/industrial_management.go

@@ -222,12 +222,15 @@ type IndustrialManagementIdInt struct {
 	IndustrialManagementId int    `description:"产业Id"`
 	IndustryName           string `description:"产业名称"`
 	SubjectName            string `description:"标的名称"`
+	ArticleId              int    `description:"文章ID"`
 }
 
 type IndustrialManagementIdInts struct {
-	IndustrialManagementId int    `description:"产业Id"`
-	IndustryName           string `description:"产业名称"`
-	SubjectNames           string `description:"标的名称"`
+	IndustrialManagementId  int    `description:"产业Id"`
+	IndustryName            string `description:"产业名称"`
+	SubjectNames            string `description:"标的名称"`
+	ArticleId               int    `description:"文章ID"`
+	IndustrialAndSubjectIds string `description:"关联标的以及产业ID"`
 }
 
 type IndustrialManagementIdName struct {
@@ -313,19 +316,22 @@ func GetIndustrialManagementSubjectCount(industrialManagementId int) (count int,
 }
 
 //获取产业关联标的列表
-func GetIndustrialManagementSubjectList(industrialManagementId int) (items []*IndustrialSubject, err error) {
+func GetIndustrialManagementSubjectList(articleId int) (items []*IndustrialSubject, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
-			s.subject_name 
-		    FROM
-			cygx_industrial_subject AS s 
-			INNER JOIN cygx_industrial_article_group_subject as sg ON sg.industrial_subject_id = s.industrial_subject_id
-			INNER JOIN cygx_article as a ON a.article_id = sg.article_id
-			WHERE a.industrial_management_id = ?
-			AND a.publish_status = 1
-			GROUP BY s.industrial_subject_id
-			ORDER BY sg.create_time DESC 
-			LIMIT 4`
-	_, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
+	s.subject_name 
+FROM
+	cygx_industrial_subject AS s
+	INNER JOIN cygx_industrial_article_group_subject AS sg ON sg.industrial_subject_id = s.industrial_subject_id
+	INNER JOIN cygx_article AS a 
+WHERE
+	sg.article_id = ? 
+	AND a.publish_status = 1 
+GROUP BY
+	s.industrial_subject_id 
+ORDER BY
+	sg.create_time DESC 
+	LIMIT 4`
+	_, err = o.Raw(sql, articleId).QueryRows(&items)
 	return
 }