yan_xuan.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_mfyx/models"
  5. "hongze/hongze_mfyx/utils"
  6. "strconv"
  7. "strings"
  8. )
  9. // 获取研选类型的文章分类Id
  10. func GetYanXuanArticleTypeIds() (articleTypeIds string, err error) {
  11. var condition string
  12. condition = " AND is_show_yanx = 1 "
  13. listType, e := models.GetCygxArticleTypeListCondition(condition)
  14. if e != nil {
  15. err = errors.New("GetCygxArticleTypeListCondition, Err: " + e.Error())
  16. return
  17. }
  18. for _, v := range listType {
  19. articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
  20. }
  21. articleTypeIds = strings.TrimRight(articleTypeIds, ",")
  22. if articleTypeIds == "" {
  23. err = errors.New("研选分类ID不能为空")
  24. return
  25. }
  26. return
  27. }
  28. // 处理研选关联的新标签
  29. func GetYanXuanIndustrialManagementIdNewMap(articleTypeIds string) (respMap map[int]bool, err error) {
  30. var condition string
  31. if articleTypeIds == "" {
  32. return
  33. }
  34. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  35. list, e := models.GetIndustrialManagementNewList(condition)
  36. if e != nil {
  37. err = errors.New("GetIndustrialManagementNewList, Err: " + e.Error())
  38. return
  39. }
  40. newMap := make(map[int]bool)
  41. for _, v := range list {
  42. newMap[v.IndustrialManagementId] = true
  43. }
  44. respMap = newMap
  45. return
  46. }
  47. // 处理研选关联的hot标签
  48. func GetYanXuanIndustrialManagementIdHotMap(articleTypeIds string) (respMap map[int]bool, err error) {
  49. var condition string
  50. var conditionOrder string
  51. if articleTypeIds == "" {
  52. return
  53. }
  54. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  55. conditionOrder = ` ORDER BY sum_num DESC `
  56. listHot, e := models.GetThemeHeatList(0, condition, conditionOrder, 0, 3)
  57. if e != nil {
  58. err = errors.New("GetIndustrialManagementNewList, Err: " + e.Error())
  59. return
  60. }
  61. hotMap := make(map[int]bool)
  62. for _, v := range listHot {
  63. hotMap[v.IndustrialManagementId] = true
  64. }
  65. respMap = hotMap
  66. return
  67. }
  68. // GetArticleSubjectName 获取文章关联的多个标的名称
  69. func GetArticleSubjectName(articleIds []int) (respMap, subjectMap map[int]string, err error) {
  70. lenarticleIds := len(articleIds)
  71. if lenarticleIds == 0 {
  72. return
  73. }
  74. var condition string
  75. var pars []interface{}
  76. condition = ` AND ag.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  77. pars = append(pars, articleIds)
  78. list, e := models.GetSubjectArticlGroupList(condition, pars)
  79. if e != nil {
  80. err = errors.New("GetIndustrialManagementNewList, Err: " + e.Error())
  81. return
  82. }
  83. artMap := make(map[int]string)
  84. subMap := make(map[int]string)
  85. for _, v := range list {
  86. artMap[v.ArticleId] += v.SubjectName + "/"
  87. subMap[v.IndustrialSubjectId] = v.SubjectName
  88. }
  89. for _, v := range list {
  90. artMap[v.ArticleId] = strings.TrimRight(artMap[v.ArticleId], "/")
  91. }
  92. respMap = artMap
  93. subjectMap = subMap
  94. return
  95. }