Browse Source

no message

xingzai 1 year ago
parent
commit
ce2692a4ae
2 changed files with 180 additions and 121 deletions
  1. 179 120
      controllers/user.go
  2. 1 1
      models/user.go

+ 179 - 120
controllers/user.go

@@ -840,6 +840,14 @@ func (this *UserController) CollectList() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+
 	userId := this.User.UserId
 	var pageSize, currentIndex, startSize int
 	pageSize, _ = this.GetInt("PageSize")
@@ -868,7 +876,7 @@ func (this *UserController) CollectList() {
 	resp := new(models.ArticleReportBillboardLIstPageResp)
 	if len(list) == 0 {
 		page := paging.GetPaging(currentIndex, pageSize, total)
-		resp.List = list
+		resp.List = make([]*models.ArticleReportBillboardResp, 0)
 		resp.Paging = page
 		br.Msg = "获取成功!"
 		br.Ret = 200
@@ -876,137 +884,188 @@ func (this *UserController) CollectList() {
 		br.Data = resp
 		return
 	}
-	var condition string
-	var pars []interface{}
-	var articleIds []string
-	for _, v := range list {
-		articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
-	}
-	articleIdStr := strings.Join(articleIds, ",")
-
-	//获取文章关联的产业
-	pars = make([]interface{}, 0)
-	condition = ` AND mg.article_id IN (  ` + utils.GetOrmInReplace(len(articleIds)) + ` )  `
-	pars = append(pars, articleIds)
-	industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
+	list, err = services.HandleArticleCategoryImg(list, user)
 	if err != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
 		return
 	}
-	industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
-	if len(industrialList) > 0 {
-		for _, v := range industrialList {
-			item := new(models.IndustrialManagementIdInt)
-			item.ArticleId = v.ArticleId
-			if v.ArticleId > utils.SummaryArticleId {
-				item.IsResearch = true
-			}
-			item.IndustrialManagementId = v.IndustrialManagementId
-			item.IndustryName = v.IndustryName
-			item.ChartPermissionId = v.ChartPermissionId
-			industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
-		}
-	}
-	for k, v := range list {
-		if len(industrialMap[v.ArticleId]) > 0 {
-			list[k].List = industrialMap[v.ArticleId]
-		} else {
-			list[k].List = make([]*models.IndustrialManagementIdInt, 0)
-		}
-	}
 
-	articleMap := make(map[int]*models.ArticleDetail)
-	if articleIdStr != "" {
-		articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
-		if err != nil {
-			br.Msg = "获取数据失败"
-			br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
-			return
-		}
-		for _, v := range articleList {
-			if _, ok := articleMap[v.ArticleId]; !ok {
-				articleMap[v.ArticleId] = v
-			}
-		}
-	}
-
-	//处理文章PV收藏等数量
-	mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
-	if len(articleIds) > 0 {
-		articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取失败"
-			br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
-			return
-		}
-		for _, v := range articleCollectNumList {
-			mapArticleCollectNum[v.ArticleId] = v
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	for _, v := range list {
+		item := models.ArticleReportBillboardResp{
+			ArticleId:           v.ArticleId,
+			ArticleTypeId:       v.ArticleTypeId,
+			Title:               v.Title,
+			PublishDate:         v.PublishDate,
+			DepartmentId:        v.DepartmentId,
+			NickName:            v.NickName,
+			IsCollect:           v.IsCollect,
+			Pv:                  v.Pv,
+			CollectNum:          v.CollectNum,
+			ImgUrlPc:            v.ImgUrlPc,
+			LabelKeywordImgLink: v.LabelKeywordImgLink,
+			List:                v.List,
+			SpecialColumnId:     v.SpecialColumnId,
 		}
-	}
-
-	//研选的五张图片
-	detailResearch, err := models.GetConfigByCode("category_research_img_url")
-	if err != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,GetConfigByCode Err:" + err.Error()
-		return
-	}
-	researchList := strings.Split(detailResearch.ConfigValue, "{|}")
-
-	lenList := len(list)
-	for i := 0; i < lenList; i++ {
-		item := list[i]
-		knum := item.ArticleId % 5
-		list[i].ImgUrlPc = researchList[knum]
-
-		article := articleMap[item.ArticleId]
-		if list[i].IsSpecialInt != 1 {
-			list[i].Title = article.Title
-			list[i].DepartmentId = article.DepartmentId
-			list[i].NickName = article.NickName
-			list[i].PublishDate = article.PublishDate
-			if article.ArticleTypeId == 0 {
-				list[i].Source = 1
-			} else {
-				list[i].Source = 2
-				list[i].IsResearch = true
-			}
-			if mapArticleCollectNum[article.ArticleId] != nil {
-				list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
-				list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
-				list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
-			}
-		} else {
-			//处理研选专栏
-			list[i].IsSpecial = true
-			if list[i].CompanyTagsStr != "" {
-				list[i].CompanyTags = strings.Split(list[i].CompanyTagsStr, ",")
+		if v.IsSpecial == 1 {
+			item.IsSpecial = true
+			item.ImgUrlPc = utils.CYGX_YANXUAN_SPECIAL_IMG_PC
+			if v.CompanyTags != "" {
+				item.CompanyTags = strings.Split(v.CompanyTags, ",")
 			} else {
-				list[i].CompanyTags = []string{}
+				item.CompanyTags = []string{}
 			}
-			if list[i].IndustryTagStr != "" {
-				list[i].IndustryTags = strings.Split(list[i].IndustryTagStr, ",")
+			if v.IndustryTags != "" {
+				item.IndustryTags = strings.Split(v.IndustryTags, ",")
 			} else {
-				list[i].IndustryTags = []string{}
+				item.IndustryTags = []string{}
 			}
-			list[i].IsResearch = true
-		}
-		if item.ArticleTypeId == -1 {
-			list[i].ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
-		}
-		if item.SpecialType == 1 {
-			list[i].Title = "【笔记】" + list[i].Title
-		} else if list[i].SpecialType == 2 {
-			list[i].Title = "【观点】" + list[i].Title
-		}
-		if item.MyCollectNum > 0 {
-			list[i].IsCollect = true
+			//item.ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
+			//if v.SpecialType == 1 {
+			//	item.Title = "【笔记】" + item.Title
+			//} else if v.SpecialType == 2 {
+			//	item.Title = "【观点】" + item.Title
+			//}
+			//if v.MyCollectNum > 0 {
+			//	item.IsCollect = true
+			//}
 		}
 
+		resp.List = append(resp.List, &item)
 	}
-	page := paging.GetPaging(currentIndex, pageSize, total)
-	resp.List = list
+
+	//var condition string
+	//var pars []interface{}
+	//var articleIds []string
+	//for _, v := range list {
+	//	articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
+	//}
+	//articleIdStr := strings.Join(articleIds, ",")
+	//
+	////获取文章关联的产业
+	//pars = make([]interface{}, 0)
+	//condition = ` AND mg.article_id IN (  ` + utils.GetOrmInReplace(len(articleIds)) + ` )  `
+	//pars = append(pars, articleIds)
+	//industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
+	//if err != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
+	//	return
+	//}
+	//industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
+	//if len(industrialList) > 0 {
+	//	for _, v := range industrialList {
+	//		item := new(models.IndustrialManagementIdInt)
+	//		item.ArticleId = v.ArticleId
+	//		if v.ArticleId > utils.SummaryArticleId {
+	//			item.IsResearch = true
+	//		}
+	//		item.IndustrialManagementId = v.IndustrialManagementId
+	//		item.IndustryName = v.IndustryName
+	//		item.ChartPermissionId = v.ChartPermissionId
+	//		industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
+	//	}
+	//}
+	//for k, v := range list {
+	//	if len(industrialMap[v.ArticleId]) > 0 {
+	//		list[k].List = industrialMap[v.ArticleId]
+	//	} else {
+	//		list[k].List = make([]*models.IndustrialManagementIdInt, 0)
+	//	}
+	//}
+	//
+	//articleMap := make(map[int]*models.ArticleDetail)
+	//if articleIdStr != "" {
+	//	articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
+	//	if err != nil {
+	//		br.Msg = "获取数据失败"
+	//		br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
+	//		return
+	//	}
+	//	for _, v := range articleList {
+	//		if _, ok := articleMap[v.ArticleId]; !ok {
+	//			articleMap[v.ArticleId] = v
+	//		}
+	//	}
+	//}
+	//
+	////处理文章PV收藏等数量
+	//mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
+	//if len(articleIds) > 0 {
+	//	articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		br.Msg = "获取失败"
+	//		br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
+	//		return
+	//	}
+	//	for _, v := range articleCollectNumList {
+	//		mapArticleCollectNum[v.ArticleId] = v
+	//	}
+	//}
+	//
+	////研选的五张图片
+	//detailResearch, err := models.GetConfigByCode("category_research_img_url")
+	//if err != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取失败,GetConfigByCode Err:" + err.Error()
+	//	return
+	//}
+	//researchList := strings.Split(detailResearch.ConfigValue, "{|}")
+	//
+	//lenList := len(list)
+	//for i := 0; i < lenList; i++ {
+	//	item := list[i]
+	//	knum := item.ArticleId % 5
+	//	list[i].ImgUrlPc = researchList[knum]
+	//
+	//	article := articleMap[item.ArticleId]
+	//	if list[i].IsSpecialInt != 1 {
+	//		list[i].Title = article.Title
+	//		list[i].DepartmentId = article.DepartmentId
+	//		list[i].NickName = article.NickName
+	//		list[i].PublishDate = article.PublishDate
+	//		if article.ArticleTypeId == 0 {
+	//			list[i].Source = 1
+	//		} else {
+	//			list[i].Source = 2
+	//			list[i].IsResearch = true
+	//		}
+	//		if mapArticleCollectNum[article.ArticleId] != nil {
+	//			list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
+	//			list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
+	//			list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
+	//		}
+	//	} else {
+	//		//处理研选专栏
+	//		list[i].IsSpecial = true
+	//		if list[i].CompanyTagsStr != "" {
+	//			list[i].CompanyTags = strings.Split(list[i].CompanyTagsStr, ",")
+	//		} else {
+	//			list[i].CompanyTags = []string{}
+	//		}
+	//		if list[i].IndustryTagStr != "" {
+	//			list[i].IndustryTags = strings.Split(list[i].IndustryTagStr, ",")
+	//		} else {
+	//			list[i].IndustryTags = []string{}
+	//		}
+	//		list[i].IsResearch = true
+	//	}
+	//	if item.ArticleTypeId == -1 {
+	//		list[i].ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
+	//	}
+	//	if item.SpecialType == 1 {
+	//		list[i].Title = "【笔记】" + list[i].Title
+	//	} else if list[i].SpecialType == 2 {
+	//		list[i].Title = "【观点】" + list[i].Title
+	//	}
+	//	if item.MyCollectNum > 0 {
+	//		list[i].IsCollect = true
+	//	}
+	//
+	//}
+	//page := paging.GetPaging(currentIndex, pageSize, total)
+	//resp.List = list
 	resp.Paging = page
 	br.Msg = "获取成功!"
 	br.Ret = 200

+ 1 - 1
models/user.go

@@ -380,7 +380,7 @@ func GetArticleUserCollectCount(userId int) (count int, err error) {
 	return
 }
 
-func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*ArticleReportBillboardResp, err error) {
+func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
 	sql := `SELECT 
 		a.article_id,
 		art.category_id,