product_interior.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/services"
  8. "hongze/hz_crm_api/services/alarm_msg"
  9. "hongze/hz_crm_api/utils"
  10. "strconv"
  11. "strings"
  12. )
  13. // 获取产品内测的阅读数据
  14. func GetCygxProductInteriorHistoryListMap(productInteriorIs []int) (mapPv, mapUv map[int]int) {
  15. var err error
  16. defer func() {
  17. if err != nil {
  18. fmt.Println(err)
  19. go alarm_msg.SendAlarmMsg("获取产品内测的阅读数据,信息失败,Err:"+err.Error(), 3)
  20. }
  21. }()
  22. lenproductInteriorIs := len(productInteriorIs)
  23. if lenproductInteriorIs == 0 {
  24. return
  25. }
  26. var condition string
  27. var pars []interface{}
  28. condition = ` AND product_interior_id IN (` + utils.GetOrmInReplace(lenproductInteriorIs) + `)`
  29. pars = append(pars, productInteriorIs)
  30. list, err := cygx.GetCygxProductInteriorHistoryList(condition, pars)
  31. if err != nil {
  32. return
  33. }
  34. mapPv = make(map[int]int, 0)
  35. mapUv = make(map[int]int, 0)
  36. mapUvCount := make(map[string]int, 0)
  37. for _, v := range list {
  38. mapPv[v.ProductInteriorId]++
  39. if _, ok := mapUvCount[fmt.Sprint("UID_", v.UserId, "ProductInteriorId_", v.ProductInteriorId)]; !ok {
  40. mapUvCount[fmt.Sprint("UID_", v.UserId, "ProductInteriorId_", v.ProductInteriorId)] = v.ProductInteriorId
  41. mapUv[v.ProductInteriorId]++
  42. }
  43. }
  44. return
  45. }
  46. // 获取产品内测的留言数据
  47. func GetCygxProductInteriorMsgListMap(productInteriorIs []int) (mapResp map[int]int) {
  48. var err error
  49. defer func() {
  50. if err != nil {
  51. fmt.Println(err)
  52. go alarm_msg.SendAlarmMsg("获取产品内测的阅读数据,信息失败,Err:"+err.Error(), 3)
  53. }
  54. }()
  55. lenproductInteriorIs := len(productInteriorIs)
  56. if lenproductInteriorIs == 0 {
  57. return
  58. }
  59. var condition string
  60. var pars []interface{}
  61. condition = ` AND product_interior_id IN (` + utils.GetOrmInReplace(lenproductInteriorIs) + `)`
  62. pars = append(pars, productInteriorIs)
  63. list, err := cygx.GetCygxProductInteriorMsgList(condition, pars)
  64. if err != nil {
  65. return
  66. }
  67. mapResp = make(map[int]int, 0)
  68. for _, v := range list {
  69. mapResp[v.ProductInteriorId]++
  70. }
  71. return
  72. }
  73. // 获取产品内测的标签数据
  74. func GetCygxProductInteriorLabelListMap(productInteriorIs []int) (mapResp map[int]string) {
  75. var err error
  76. defer func() {
  77. if err != nil {
  78. fmt.Println(err)
  79. go alarm_msg.SendAlarmMsg("获取产品内测的阅读数据,信息失败,Err:"+err.Error(), 3)
  80. }
  81. }()
  82. lenproductInteriorIs := len(productInteriorIs)
  83. if lenproductInteriorIs == 0 {
  84. return
  85. }
  86. var condition string
  87. var pars []interface{}
  88. condition = ` AND product_interior_id IN (` + utils.GetOrmInReplace(lenproductInteriorIs) + `)`
  89. pars = append(pars, productInteriorIs)
  90. industrialList, err := cygx.GetProductInteriorIndustrialGroupManagement(condition, pars)
  91. if err != nil {
  92. return
  93. }
  94. subjectList, err := cygx.GetProductInteriorIndustrialGroupSubjectt(condition, pars)
  95. if err != nil {
  96. return
  97. }
  98. mapIndustrial := make(map[int]string)
  99. mapSubject := make(map[string]string)
  100. //合并活动对应的多个标的
  101. for _, v := range subjectList {
  102. mapSubject[fmt.Sprint(v.ProductInteriorId, "_", v.IndustrialManagementId)] += v.SubjectName + "/"
  103. }
  104. //活动对应的产业
  105. for _, v := range industrialList {
  106. var labelSubject string
  107. labelSubject = mapSubject[fmt.Sprint(v.ProductInteriorId, "_", v.IndustrialManagementId)]
  108. if labelSubject != "" {
  109. mapIndustrial[v.ProductInteriorId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + ","
  110. } else {
  111. mapIndustrial[v.ProductInteriorId] += v.IndustryName + ","
  112. }
  113. }
  114. for _, v := range industrialList {
  115. mapIndustrial[v.ProductInteriorId] = strings.TrimRight(mapIndustrial[v.ProductInteriorId], ",")
  116. }
  117. mapResp = mapIndustrial
  118. return
  119. }
  120. //func init() {
  121. // SendWxMsgWithCygxProductInterior(20)
  122. //}
  123. // 模版消息推送
  124. func SendWxMsgWithCygxProductInterior(productInteriorId int) (err error) {
  125. defer func() {
  126. if err != nil {
  127. fmt.Println("err:", err)
  128. go alarm_msg.SendAlarmMsg("查研观向处理活动是否进行模板消息推送,发送模版消息失败,Err:"+err.Error(), 3)
  129. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error()))
  130. }
  131. }()
  132. detail, e := cygx.GetCygxProductInteriorDetail(productInteriorId)
  133. if e != nil {
  134. err = errors.New("获取详情失败" + e.Error())
  135. return
  136. }
  137. if detail == nil {
  138. err = errors.New("获取详情失败")
  139. return
  140. }
  141. if detail.IsSendWxMsg == 1 {
  142. return
  143. }
  144. if detail.MatchTypeId > 0 {
  145. matchDetail, e := cygx.GetCygxReportMappingCygxDetail(detail.MatchTypeId)
  146. if e != nil {
  147. err = errors.New("GetCygxReportMappingCygxDetail" + e.Error())
  148. return
  149. }
  150. if matchDetail != nil {
  151. detail.MatchTypeName = matchDetail.MatchTypeName
  152. }
  153. }
  154. permissionStr, e := company.GetPermissionIdById(strconv.Itoa(detail.ChartPermissionId))
  155. if e != nil {
  156. err = errors.New("获取主客观权限失败" + e.Error())
  157. return
  158. }
  159. // 获取所有有权的用户的 openid
  160. openidPowerList, e := cygx.GetCygxUserRecordPower(permissionStr)
  161. if e != nil {
  162. err = errors.New("获取所有有权的用户的 openid失败" + e.Error())
  163. return
  164. }
  165. //var industrialName string
  166. //industrialList, e := cygx.GetProductInteriorIndustrialGroupManagementList(productInteriorId)
  167. //if e != nil && e.Error() != utils.ErrNoRow() {
  168. // err = errors.New("GetProductInteriorIndustrialGroupManagementList,Err:" + e.Error())
  169. // return
  170. //}
  171. //
  172. //if len(industrialList) == 0 {
  173. // return
  174. //}
  175. //mapOpenidFllow := make(map[int]string)
  176. //
  177. //for _, vindustr := range industrialList {
  178. // //获取关注对应产业的用户信息
  179. // industryFllowList, e := cygx.GetCygxUserindustryFllowOpenid(vindustr.IndustrialManagementId)
  180. // if e != nil {
  181. // err = errors.New("获取关注对应产业的用户信息失败 " + e.Error())
  182. // return
  183. // }
  184. // for _, v := range industryFllowList {
  185. // mapOpenidFllow[v.UserId] = v.OpenId
  186. // }
  187. // industrialName += vindustr.IndustryName + ";"
  188. //}
  189. //industrialName = strings.TrimRight(industrialName, ";")
  190. ////获取拒绝接收推送的的用户的 openid
  191. //mapOpenidRefuset := make(map[int]string)
  192. //openidRefusetList, e := cygx.GetCygxUserRefusetOpenid()
  193. //if e != nil && e.Error() != utils.ErrNoRow() {
  194. // err = errors.New("获取拒绝接收推送的的用户的 openid 失败" + e.Error())
  195. // return
  196. //}
  197. //for _, v := range openidRefusetList {
  198. // mapOpenidRefuset[v.UserId] = v.OpenId
  199. //}
  200. //获取提交过推送规则的用户的 openid
  201. mapUserIdChooseSend := make(map[int]int)
  202. chooseSendtList, err := cygx.GetCygxXzsChooseSend("")
  203. if err != nil && err.Error() != utils.ErrNoRow() {
  204. return err
  205. }
  206. for _, v := range chooseSendtList {
  207. mapUserIdChooseSend[v.UserId] = v.UserId
  208. }
  209. openIdArr := make([]string, len(openidPowerList))
  210. for i, v := range openidPowerList {
  211. //if _, ok := mapOpenidRefuset[v.UserId]; ok {
  212. // continue //如果用户选择了拒绝推送消息,那么就不做模板消息推送
  213. //}
  214. //if _, ok := mapUserIdChooseSend[v.UserId]; ok {
  215. // if _, ok := mapOpenidFllow[v.UserId]; !ok {
  216. // continue //如果用户提交过关注信息,而且这个产业他没有关注,那么不做推送
  217. // }
  218. //}
  219. openIdArr[i] = v.OpenId
  220. }
  221. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  222. keyword1 := "【宏观" + detail.ChartPermissionName + "】有报告发布/更新"
  223. keyword2 := detail.Title
  224. keyword3 := utils.TimeRemoveHms2(detail.PublishTime)
  225. keyword4 := detail.Abstract
  226. remark := "点击查看报告详情"
  227. var redirectUrl string
  228. redirectUrl = utils.WX_MSG_PATH_PRODUCTINTERIOR_DETAIL + strconv.Itoa(detail.ProductInteriorId) + "&IsSendWx=1"
  229. sendInfo := new(services.SendWxTemplate)
  230. sendInfo.First = first
  231. sendInfo.Keyword1 = keyword1
  232. sendInfo.Keyword2 = keyword2
  233. sendInfo.Keyword3 = keyword3
  234. sendInfo.Keyword4 = keyword4
  235. sendInfo.Remark = remark
  236. sendInfo.TemplateId = utils.TemplateIdByProductXzs
  237. sendInfo.RedirectUrl = redirectUrl
  238. sendInfo.RedirectTarget = 3
  239. sendInfo.Resource = strconv.Itoa(detail.ProductInteriorId)
  240. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ROADSHOW_VIDEO
  241. sendInfo.OpenIdArr = openIdArr
  242. e = services.SendTemplateMsg(sendInfo)
  243. if e != nil {
  244. err = errors.New("推送模板消息失败" + e.Error())
  245. return
  246. }
  247. e = cygx.UpdateProductInteriorIsSendWxMsg(productInteriorId, 1)
  248. if e != nil {
  249. err = errors.New("修改推送状态失败" + e.Error())
  250. return
  251. }
  252. return
  253. }