morning_meeting.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_mfyx/models"
  7. "hongze/hongze_mfyx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. //
  13. //func init() {
  14. //
  15. // for i := 180; i > 0; i-- {
  16. // MakeMorningMeetingReviews(i)
  17. // }
  18. //
  19. //}
  20. func MakeMorningMeetingReviews(cont context.Context) (err error) {
  21. //func MakeMorningMeetingReviews(day int) (err error) {
  22. //func init12(day int) (err error) {
  23. defer func() {
  24. if err != nil {
  25. fmt.Println(err)
  26. go utils.SendAlarmMsg("定时生成晨会精华汇总失败,err:"+err.Error(), 2)
  27. }
  28. }()
  29. day := 0
  30. hourstr := " 10:30:00 "
  31. DayTime := time.Now().AddDate(0, 0, -day)
  32. startSize := 0
  33. pageSize := 100
  34. var condition string
  35. var pars []interface{}
  36. startDate := DayTime.AddDate(0, 0, -1).Format(utils.FormatDate) + hourstr
  37. endDate := DayTime.Format(utils.FormatDate) + hourstr
  38. condition = ` AND publish_time = ? `
  39. pars = append(pars, endDate)
  40. total, err := models.GetCygxMorningMeetingGatherCount(condition, pars)
  41. if err != nil {
  42. return
  43. }
  44. if total > 0 {
  45. return
  46. }
  47. pars = make([]interface{}, 0)
  48. condition = ` AND publish_time BETWEEN ? AND ? `
  49. pars = append(pars, startDate, endDate)
  50. list, err := models.GetCygxMorningMeetingReviewsList(condition, pars, startSize, pageSize)
  51. if err != nil {
  52. return
  53. }
  54. if len(list) == 0 {
  55. return
  56. }
  57. item := new(models.CygxMorningMeetingGather)
  58. for _, v := range list {
  59. item.MeetingIds += strconv.Itoa(v.Id) + ","
  60. }
  61. item.MeetingIds = strings.TrimRight(item.MeetingIds, ",")
  62. item.Title = utils.GetTimeDateHourAndDay(DayTime) + "(" + utils.StrDateTimeToWeek(DayTime.Format(utils.FormatDateTime)) + ")" + "|晨会精华"
  63. item.CreateTime = time.Now()
  64. item.ModifyTime = time.Now()
  65. item.PublishTime = endDate
  66. item.Status = 1
  67. err = models.AddCygxMorningMeetingGather(item)
  68. return
  69. }
  70. // 添加晨会点评点击记录
  71. func AddCygxMorningMeetingReviewChapterHistory(user *models.WxUserItem, articleId int, sourcePage string) (err error) {
  72. defer func() {
  73. if err != nil {
  74. go utils.SendAlarmMsg(fmt.Sprint("添加晨会点评点击记录失败 ,AddCygxMorningMeetingReviewChapterHistory err"+err.Error(), "id:", articleId, "sourcePage:", sourcePage, "userid:", user.UserId), 2)
  75. }
  76. }()
  77. detail, e := models.GetCygxMorningMeetingReviewChapterDetail(articleId)
  78. if e != nil {
  79. err = errors.New("GetCygxMorningMeetingReviewChapterDetail, Err: " + e.Error())
  80. return
  81. }
  82. historyRecord := new(models.CygxMorningMeetingReviewChapterHistory)
  83. historyRecord.UserId = user.UserId
  84. historyRecord.ArticleId = articleId
  85. historyRecord.SourcePage = sourcePage
  86. historyRecord.CreateTime = time.Now()
  87. historyRecord.Mobile = user.Mobile
  88. historyRecord.Email = user.Email
  89. historyRecord.CompanyId = user.CompanyId
  90. historyRecord.CompanyName = user.CompanyName
  91. historyRecord.MeetingId = int(detail.MeetingId)
  92. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  93. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  94. if e != nil && e.Error() != utils.ErrNoRow() {
  95. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  96. return
  97. }
  98. historyRecord.RealName = user.RealName
  99. if sellerItem != nil {
  100. historyRecord.SellerName = sellerItem.RealName
  101. }
  102. _, e = models.AddCygxMorningMeetingReviewChapterHistory(historyRecord)
  103. if e != nil {
  104. err = errors.New("AddCygxMorningMeetingReviewChapterHistorymodels, Err: " + e.Error())
  105. return
  106. }
  107. return
  108. }
  109. // 通过晨会精华子ID,获取出参列表详情
  110. func GetCygxMorningMeetingReviewChapterListByIds(meetingreviewchaptIds []int) (items []*models.CygxMorningMeetingGatherDetailListResp, err error) {
  111. lenArr := len(meetingreviewchaptIds)
  112. if lenArr == 0 {
  113. return
  114. }
  115. defer func() {
  116. if err != nil {
  117. go utils.SendAlarmMsg(fmt.Sprint("通过晨会精华子ID,获取出参列表详情失败 ,GetCygxMorningMeetingReviewChapterListByIds err"+err.Error(), "meetingreviewchaptIds:", meetingreviewchaptIds), 2)
  118. }
  119. }()
  120. var condition string
  121. var pars []interface{}
  122. pars = make([]interface{}, 0)
  123. condition = ` AND c.id IN (` + utils.GetOrmInReplace(lenArr) + `)`
  124. pars = append(pars, meetingreviewchaptIds)
  125. //查询晨会
  126. listrMeet, e := models.GetCygxMorningMeetingReviewChapterList(condition, pars)
  127. if e != nil {
  128. err = errors.New("GetCygxMorningMeetingReviewChapterList, Err: " + e.Error())
  129. return
  130. }
  131. //获取晨会相关的标的
  132. var subjectIds []string
  133. for _, v := range listrMeet {
  134. if v.IndustrialSubjectIds != "" {
  135. slice := strings.Split(v.IndustrialSubjectIds, ",")
  136. for _, vS := range slice {
  137. subjectIds = append(subjectIds, vS)
  138. }
  139. }
  140. }
  141. lensubjectIds := len(subjectIds)
  142. if lensubjectIds > 0 {
  143. //获取标的信息
  144. pars = make([]interface{}, 0)
  145. condition = ` AND industrial_subject_id IN (` + utils.GetOrmInReplace(lensubjectIds) + `)`
  146. pars = append(pars, subjectIds)
  147. listsubject, e := models.GetCygxIndustrialSubjectListCondition(condition, pars)
  148. if e != nil {
  149. err = errors.New("GetCygxIndustrialSubjectListCondition, Err: " + e.Error())
  150. return
  151. }
  152. var meetSubjectItems = make(map[string]*models.CygxIndustrialSubject)
  153. for _, v := range listsubject {
  154. meetSubjectItems[strconv.Itoa(v.IndustrialSubjectId)] = v
  155. }
  156. //建立标的与晨会的映射关系
  157. for _, v := range listrMeet {
  158. if v.IndustrialSubjectIds != "" {
  159. slice := strings.Split(v.IndustrialSubjectIds, ",")
  160. for _, vS := range slice {
  161. if meetSubjectItems[vS] != nil {
  162. v.ListSubject = append(v.ListSubject, meetSubjectItems[vS])
  163. }
  164. }
  165. }
  166. }
  167. }
  168. items = listrMeet
  169. return
  170. }