activity_task.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package services
  2. import (
  3. "context"
  4. "crypto/tls"
  5. "encoding/json"
  6. "errors"
  7. "fmt"
  8. "hongze/hongze_cygx/models"
  9. "hongze/hongze_cygx/utils"
  10. "io/ioutil"
  11. "net/http"
  12. "strings"
  13. "time"
  14. )
  15. //专门处理活动定时任务相关的业务逻辑
  16. type VmpRobotMeeting struct {
  17. ModeID int `json:"mode_id"`
  18. PhoneNumber string `json:"phone_number"`
  19. MeetingPassword string `json:"meeting_password"`
  20. MeetingStartTime string `json:"meeting_start_time"`
  21. MeetingTitle string `json:"meeting_title"`
  22. MeetingTypeID int `json:"meeting_type_id"`
  23. ParsingMethodID int `json:"parsing_method_id"`
  24. IndustryID int `json:"industry_id"`
  25. FieldID int `json:"field_id"`
  26. Stock string `json:"stock"`
  27. Remark string `json:"remark"`
  28. ProjectID int `json:"project_id"`
  29. AuthorPhoneNumber int64 `json:"author_phone_number"`
  30. ExecutionStatusID int `json:"execution_status_id"`
  31. ParsingID int `json:"parsing_id"`
  32. SerialNumber string `json:"serial_number"`
  33. ChannelID int `json:"channel_id"`
  34. IsActive int `json:"is_active"`
  35. }
  36. type VmpRobotMeetingDataResult struct {
  37. Code int `json:"code"`
  38. Msg string `json:"msg"`
  39. Data VmpRobotMeetingResult `json:"data"`
  40. }
  41. type VmpRobotMeetingResult struct {
  42. ModeID int `json:"mode_id"`
  43. PhoneNumber string `json:"phone_number"`
  44. MeetingPassword string `json:"meeting_password"`
  45. MeetingStartTime string `json:"meeting_start_time"`
  46. MeetingTitle string `json:"meeting_title"`
  47. MeetingTypeID int `json:"meeting_type_id"`
  48. ParsingMethodID int `json:"parsing_method_id"`
  49. IndustryID int `json:"industry_id"`
  50. FieldID int `json:"field_id"`
  51. Stock string `json:"stock"`
  52. Remark string `json:"remark"`
  53. ProjectID int `json:"project_id"`
  54. AuthorPhoneNumber int64 `json:"author_phone_number"`
  55. ExecutionStatusID int `json:"execution_status_id"`
  56. ParsingID int `json:"parsing_id"`
  57. SerialNumber string `json:"serial_number"`
  58. ChannelID int `json:"channel_id"`
  59. IsActive int `json:"is_active"`
  60. VmpRobotMeetinId int `json:"id"`
  61. }
  62. //func init() {
  63. // PushVmpRobotMeeting()
  64. //}
  65. // 研选活动会前15分钟推送给上海那边的机器人
  66. func PushVmpRobotMeeting(cont context.Context) (err error) {
  67. //func PushVmpRobotMeeting() (err error) {
  68. defer func() {
  69. if err != nil {
  70. //go utils.SendAlarmMsg("15分钟会议消息提醒失败err :"+err.Error(), 2)
  71. go utils.SendAlarmMsg(fmt.Sprint("研选活动会前15分钟推送给上海那边的机器人失败 PushVmpRobotMeeting Err:", err.Error()), 2)
  72. //fmt.Println("发送失败,Err:", err.Error())
  73. }
  74. }()
  75. postUrl := "https://vmp.hzinsights.com/v2api/meeting"
  76. authorization := "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxNTAwMDEyMzA1NiIsInBob25lX251bWJlciI6IjE1MDAwMTIzMDU2IiwibmFtZSI6IumrmOS6puaWhyIsImVudHJhbmNlIjoicGFzc3d3b3JkIiwiaWF0IjoxNzAzODM1OTc4LCJleHAiOjE3MDM4Mzk1Nzh9.qX6EFkVPn2R0SqIQXJ4tyub--iiqKqrJnz9lbdcVetw"
  77. var condition string
  78. var pars []interface{}
  79. endDate := time.Now().Add(+time.Minute * 15).Format(utils.FormatDateTime)
  80. condition = ` AND activity_time <= ? AND activity_time >= NOW() AND publish_status = 1 AND chart_permission_id = ? AND vmp_robot_meeting_id = 0 AND active_state = 1 AND mainland_tell != '' `
  81. pars = append(pars, endDate, utils.CHART_PERMISSION_ID_YANXUAN)
  82. listActivity, e := models.GetCygxActivityList(condition, pars, 0, 10)
  83. if e != nil && e.Error() != utils.ErrNoRow() {
  84. err = errors.New("GetCygxActivityList, Err: " + e.Error())
  85. return
  86. }
  87. //fmt.Println(len(listActivity))
  88. //return
  89. if len(listActivity) == 0 {
  90. return
  91. }
  92. for _, v := range listActivity {
  93. item := new(VmpRobotMeeting)
  94. item.ModeID = 2
  95. item.PhoneNumber = utils.GetArabicNumbers(v.MainlandTell)
  96. item.MeetingPassword = utils.GetArabicNumbers(v.ParticipationCode) + "#" // 业务需求,必须带有一个#
  97. item.MeetingStartTime = v.ActivityTime
  98. item.MeetingTitle = v.ActivityName
  99. item.MeetingTypeID = 1
  100. item.ParsingMethodID = 0
  101. item.IndustryID = 13
  102. item.FieldID = 0
  103. item.Stock = ""
  104. item.Remark = v.Remarks // 处理HTML格式样式
  105. item.ProjectID = 1
  106. item.AuthorPhoneNumber = 15000123056 // 高亦文 手机号
  107. item.ExecutionStatusID = 0
  108. item.ParsingID = 0
  109. item.SerialNumber = ""
  110. item.ChannelID = -1
  111. item.IsActive = 1
  112. jsonBody, e := json.Marshal(item)
  113. if e != nil {
  114. err = errors.New("json.Marshal, Err: " + e.Error())
  115. fmt.Println("json.Marshal Err:" + err.Error())
  116. return
  117. }
  118. //fmt.Println(item)
  119. //return
  120. tr := &http.Transport{
  121. TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
  122. }
  123. client := &http.Client{Transport: tr}
  124. req, e := http.NewRequest("POST", postUrl, strings.NewReader(string(jsonBody)))
  125. if e != nil {
  126. err = e
  127. return
  128. }
  129. req.Header.Set("Content-Type", "application/json")
  130. req.Header.Set("Authorization", authorization)
  131. resp, e := client.Do(req)
  132. if e != nil {
  133. err = errors.New("client.Do Err: " + e.Error())
  134. fmt.Println("client.Do Err:" + err.Error())
  135. return
  136. }
  137. //fmt.Println(resp)
  138. defer resp.Body.Close()
  139. body, e := ioutil.ReadAll(resp.Body)
  140. if e != nil {
  141. fmt.Println("err:" + err.Error())
  142. err = e
  143. return
  144. }
  145. result := new(VmpRobotMeetingDataResult)
  146. e = json.Unmarshal(body, &result)
  147. if e != nil {
  148. fmt.Println(" json.Unmarshal Err:" + err.Error())
  149. err = errors.New("json.Unmarshal Err: " + e.Error())
  150. return
  151. }
  152. vmpRobotMeetinId := result.Data.VmpRobotMeetinId
  153. e = models.UpdateActivityVmpRobotMeetingId(vmpRobotMeetinId, v.ActivityId)
  154. if e != nil {
  155. fmt.Println("UpdateActivityVmpRobotMeetingId Err:" + err.Error())
  156. err = errors.New("UpdateActivityVmpRobotMeetingId Err: " + e.Error())
  157. return
  158. }
  159. itemlog := new(models.CygxShanghaiCompanyLog)
  160. itemlog.CreateTime = time.Now()
  161. itemlog.Url = postUrl
  162. itemlog.Body = string(jsonBody)
  163. itemlog.Result = string(body)
  164. go models.AddCygxShanghaiCompanyLog(itemlog)
  165. }
  166. return
  167. }