industrial_management.go 4.1 KB

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