industrial_management.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/services/alarm_msg"
  8. "hongze/hz_crm_api/utils"
  9. "strconv"
  10. "time"
  11. )
  12. //func init() {
  13. // GetIndustrialManagementArticleNewPublishData(607)
  14. //}
  15. // 批量修改获取产业关联文章的最新发布时间
  16. func GetIndustrialManagementArticleNewPublishData(industrialManagementId int) (err error) {
  17. defer func() {
  18. if err != nil {
  19. fmt.Println(err)
  20. go alarm_msg.SendAlarmMsg("批量修改获取产业关联文章的最新发布时间GetIndustrialManagementArticleNewPublishData ErrMsg:"+err.Error(), 2)
  21. }
  22. }()
  23. articleNewPublishDataList, e := cygx.GetIndustrialManagementArticleNewPublishData()
  24. if e != nil {
  25. err = errors.New("获取客户剩余报名次数失败 GetIndustrialManagementArticleNewPublishData, Err: " + e.Error())
  26. return
  27. }
  28. mapUPdateTime := make(map[int]string)
  29. var industrialManagementIds []int
  30. for _, v := range articleNewPublishDataList {
  31. if v.IndustrialManagementId != industrialManagementId {
  32. continue
  33. }
  34. if v.IndustrialManagementId > 0 {
  35. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  36. }
  37. mapUPdateTime[v.IndustrialManagementId] = v.UpdateTime
  38. }
  39. if len(industrialManagementIds) == 0 {
  40. return
  41. }
  42. //时间线的更新时间
  43. listtimelinePublishdate, err := cygx.GetTimeLineReportIndustrialPublishdateList(industrialManagementIds)
  44. if err != nil && err.Error() != utils.ErrNoRow() {
  45. return
  46. }
  47. for _, v := range listtimelinePublishdate {
  48. if v.IndustrialManagementId == industrialManagementId {
  49. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  50. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  51. }
  52. }
  53. }
  54. err = cygx.UpdateIndustrialManagementArticleNewPublishData(mapUPdateTime)
  55. return
  56. }
  57. // AddUserIndustryFllowByNewId 出现了新的产业,给选择推送方式的用户自动添加关注
  58. func AddUserIndustryFllowByNewId(industrialManagementId int) (err error) {
  59. defer func() {
  60. if err != nil {
  61. fmt.Println(err)
  62. go alarm_msg.SendAlarmMsg("出现了新的产业,给选择推送方式的用户自动添加关注。失败 ErrMsg:"+err.Error()+"industrialManagementId"+strconv.Itoa(industrialManagementId), 2)
  63. }
  64. }()
  65. //获取小助手提交过勾选项的用户
  66. var condition string
  67. condition = " AND is_refuse = 0 "
  68. chooseSendtList, e := cygx.GetCygxXzsChooseSend(condition)
  69. if e != nil {
  70. err = errors.New("GetCygxXzsChooseSend , Err: " + e.Error())
  71. return
  72. }
  73. var mobiles []string
  74. for _, v := range chooseSendtList {
  75. if v.Mobile != "" {
  76. mobiles = append(mobiles, v.Mobile)
  77. }
  78. }
  79. userList, e := models.GetWxUserListByUserMobileHaveCompany(mobiles)
  80. if e != nil {
  81. err = errors.New("GetWxUserListByUserMobileHaveCompany" + e.Error())
  82. return
  83. }
  84. var industryFllowItems []*cygx.CygxIndustryFllow
  85. for _, vUser := range userList {
  86. item := new(cygx.CygxIndustryFllow)
  87. item.IndustrialManagementId = industrialManagementId
  88. item.UserId = vUser.UserId
  89. item.Email = vUser.Email
  90. item.Mobile = vUser.Mobile
  91. item.RealName = vUser.RealName
  92. item.CompanyId = vUser.CompanyId
  93. item.CompanyName = vUser.CompanyName
  94. item.Source = 3 // 通过程序或者管理员手动添加的关注
  95. item.Type = 1
  96. item.CreateTime = time.Now()
  97. item.ModifyTime = time.Now()
  98. industryFllowItems = append(industryFllowItems, item)
  99. }
  100. e = cygx.AddCygxIndustryFllowMulti(industryFllowItems)
  101. if e != nil {
  102. err = errors.New("AddCygxIndustryFllowMulti , Err: " + e.Error())
  103. return
  104. }
  105. //更新用户关注产业的标签
  106. for _, v := range industryFllowItems {
  107. IndustryFllowUserLabelLogAdd(v.IndustrialManagementId, 0, v.UserId)
  108. }
  109. return
  110. }