product_interior.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. industrialName = detail.ColumnName //用栏目名称
  167. //industrialList, e := cygx.GetProductInteriorIndustrialGroupManagementList(productInteriorId)
  168. //if e != nil && e.Error() != utils.ErrNoRow() {
  169. // err = errors.New("GetProductInteriorIndustrialGroupManagementList,Err:" + e.Error())
  170. // return
  171. //}
  172. //
  173. ////关联的产业推送产业,没有关联产业的推送行业 p2_867 2023-8-30
  174. //if len(industrialList) == 0 {
  175. // industrialName = detail.ColumnName //用栏目名称
  176. //} else {
  177. // //mapOpenidFllow := make(map[int]string)
  178. // //
  179. // for _, vindustr := range industrialList {
  180. // //获取关注对应产业的用户信息
  181. // //industryFllowList, e := cygx.GetCygxUserindustryFllowOpenid(vindustr.IndustrialManagementId)
  182. // //if e != nil {
  183. // // err = errors.New("获取关注对应产业的用户信息失败 " + e.Error())
  184. // // return
  185. // //}
  186. // //for _, v := range industryFllowList {
  187. // // mapOpenidFllow[v.UserId] = v.OpenId
  188. // //}
  189. // industrialName += vindustr.IndustryName + ";"
  190. // }
  191. // industrialName = strings.TrimRight(industrialName, ";")
  192. //}
  193. ////获取拒绝接收推送的的用户的 openid
  194. //mapOpenidRefuset := make(map[int]string)
  195. //openidRefusetList, e := cygx.GetCygxUserRefusetOpenid()
  196. //if e != nil && e.Error() != utils.ErrNoRow() {
  197. // err = errors.New("获取拒绝接收推送的的用户的 openid 失败" + e.Error())
  198. // return
  199. //}
  200. //for _, v := range openidRefusetList {
  201. // mapOpenidRefuset[v.UserId] = v.OpenId
  202. //}
  203. //获取提交过推送规则的用户的 openid
  204. //mapUserIdChooseSend := make(map[int]int)
  205. //chooseSendtList, err := cygx.GetCygxXzsChooseSend("")
  206. //if err != nil && err.Error() != utils.ErrNoRow() {
  207. // return err
  208. //}
  209. //for _, v := range chooseSendtList {
  210. // mapUserIdChooseSend[v.UserId] = v.UserId
  211. //}
  212. openIdArr := make([]string, len(openidPowerList))
  213. for i, v := range openidPowerList {
  214. //if _, ok := mapOpenidRefuset[v.UserId]; ok {
  215. // continue //如果用户选择了拒绝推送消息,那么就不做模板消息推送
  216. //}
  217. //if _, ok := mapUserIdChooseSend[v.UserId]; ok {
  218. // if _, ok := mapOpenidFllow[v.UserId]; !ok {
  219. // continue //如果用户提交过关注信息,而且这个产业他没有关注,那么不做推送
  220. // }
  221. //}
  222. openIdArr[i] = v.OpenId
  223. }
  224. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  225. keyword1 := "【" + industrialName + "】有报告发布/更新"
  226. keyword2 := detail.Title
  227. keyword3 := utils.TimeRemoveHms2(detail.PublishTime)
  228. keyword4 := detail.Abstract
  229. remark := "点击查看报告详情"
  230. var redirectUrl string
  231. redirectUrl = utils.WX_MSG_PATH_PRODUCTINTERIOR_DETAIL + strconv.Itoa(detail.ProductInteriorId) + "&IsSendWx=1"
  232. sendInfo := new(services.SendWxTemplate)
  233. sendInfo.First = first
  234. sendInfo.Keyword1 = keyword1
  235. sendInfo.Keyword2 = keyword2
  236. sendInfo.Keyword3 = keyword3
  237. sendInfo.Keyword4 = keyword4
  238. sendInfo.Remark = remark
  239. sendInfo.TemplateId = utils.TemplateIdByProductXzs
  240. sendInfo.RedirectUrl = redirectUrl
  241. sendInfo.RedirectTarget = 3
  242. sendInfo.Resource = strconv.Itoa(detail.ProductInteriorId)
  243. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ROADSHOW_VIDEO
  244. sendInfo.OpenIdArr = openIdArr
  245. e = services.SendTemplateMsg(sendInfo)
  246. if e != nil {
  247. err = errors.New("推送模板消息失败" + e.Error())
  248. return
  249. }
  250. e = cygx.UpdateProductInteriorIsSendWxMsg(productInteriorId, 1)
  251. if e != nil {
  252. err = errors.New("修改推送状态失败" + e.Error())
  253. return
  254. }
  255. return
  256. }