industrial_subject.go 2.6 KB

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