industrial_subject.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strings"
  8. )
  9. // GetArticleGroupSubjectMap 获取文章所关联的标的
  10. func GetArticleGroupSubjectMap(articleIds []int) (mapResp map[int][]*models.IndustrialSubject, subjectMap map[int]string, err error) {
  11. lenArticleIds := len(articleIds)
  12. if lenArticleIds == 0 {
  13. return
  14. }
  15. var condition string
  16. var pars []interface{}
  17. condition = ` AND g.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  18. pars = append(pars, articleIds)
  19. list, e := models.GetArticleGroupSubjectList(pars, condition)
  20. if e != nil {
  21. err = errors.New("GetArticleGroupSubjectList " + e.Error())
  22. return
  23. }
  24. listMap := make(map[int][]*models.IndustrialSubject)
  25. subMap := make(map[int]string)
  26. mapName := make(map[int]int)
  27. if len(list) > 0 {
  28. for _, v := range list {
  29. item := models.IndustrialSubject{
  30. IndustrialSubjectId: v.IndustrialSubjectId,
  31. IndustrialManagementId: v.IndustrialManagementId,
  32. SubjectName: v.SubjectName,
  33. }
  34. listMap[v.ArticleId] = append(listMap[v.ArticleId], &item)
  35. subMap[v.IndustrialSubjectId] = v.SubjectName
  36. mapName[v.IndustrialSubjectId] = v.IndustrialManagementId
  37. }
  38. }
  39. mapResp = listMap
  40. subjectMap = subMap
  41. return
  42. }
  43. // GetArticleGroupSubjectMapByIndustrialManagementId 通过文章ID,产业;获取文章所关联的标的
  44. func GetArticleGroupSubjectMapByIndustrialManagementId(articleIds []int, industrialManagementId int) (mapResp map[int][]*models.CygxIndustrialSubject) {
  45. var err error
  46. lenArticleIds := len(articleIds)
  47. if lenArticleIds == 0 {
  48. return
  49. }
  50. defer func() {
  51. if err != nil {
  52. go utils.SendAlarmMsg(fmt.Sprint("通过文章ID,产业;获取文章所关联的标的失败 ,GetArticleGroupSubjectMapByIndustrialManagementId err"+err.Error(), "articleIds:", articleIds), 2)
  53. }
  54. }()
  55. mapSubject := make(map[string]int)
  56. listSub, e := models.GetcygxIndustrialSubject(industrialManagementId)
  57. if e != nil {
  58. err = errors.New("GetcygxIndustrialSubject, Err: " + e.Error())
  59. return
  60. }
  61. for _, v := range listSub {
  62. mapSubject[v.SubjectName] = v.IndustrialSubjectId
  63. }
  64. var condition string
  65. var pars []interface{}
  66. condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `) `
  67. pars = append(pars, articleIds)
  68. articleList, e := models.GetArticleList(condition, pars)
  69. if e != nil {
  70. err = errors.New("GetArticleList, Err: " + e.Error())
  71. return
  72. }
  73. listMap := make(map[int][]*models.CygxIndustrialSubject, 0)
  74. for _, v := range articleList {
  75. sliceSubjects := strings.Split(v.Stock, "/")
  76. for _, vSubject := range sliceSubjects {
  77. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  78. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  79. subject := sliceXiahuaxian[0]
  80. if mapSubject[subject] == 0 {
  81. continue
  82. }
  83. item := models.CygxIndustrialSubject{
  84. IndustrialSubjectId: mapSubject[subject],
  85. IndustrialManagementId: industrialManagementId,
  86. SubjectName: subject,
  87. }
  88. listMap[v.ArticleId] = append(listMap[v.ArticleId], &item)
  89. }
  90. }
  91. //condition = ` AND g.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `) AND s.industrial_management_id = ? `
  92. //pars = append(pars, articleIds, industrialManagementId)
  93. //list, e := models.GetArticleGroupSubjectList(pars, condition)
  94. //if e != nil {
  95. // err = errors.New("GetArticleGroupSubjectList " + e.Error())
  96. // return
  97. //}
  98. //
  99. //if len(list) > 0 {
  100. // for _, v := range list {
  101. // item := models.CygxIndustrialSubject{
  102. // IndustrialSubjectId: v.IndustrialSubjectId,
  103. // IndustrialManagementId: v.IndustrialManagementId,
  104. // SubjectName: v.SubjectName,
  105. // }
  106. // listMap[v.ArticleId] = append(listMap[v.ArticleId], &item)
  107. // }
  108. //}
  109. mapResp = listMap
  110. return
  111. }