research_summary.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  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. "time"
  13. )
  14. func AppendItemsLog(items []*cygx.CygxResearchSummaryLog, item []*cygx.CygxRSlChartPermission, logType, sort string) (itemsResult []*cygx.CygxResearchSummaryLog, msg string, err error) {
  15. mapSort := make(map[string]int)
  16. for _, v := range item {
  17. for _, v2 := range v.List {
  18. item := new(cygx.CygxResearchSummaryLog)
  19. if mapSort[v.ChartPermissionSort] != 0 && mapSort[v.ChartPermissionSort] != v.ChartPermissionId {
  20. msg = "有内容行业分类,序号不能为空"
  21. return
  22. }
  23. mapSort[v.ChartPermissionSort] = v.ChartPermissionId
  24. item.Type = logType
  25. item.Sort = strings.ToUpper(sort)
  26. item.ChartPermissionId = v.ChartPermissionId
  27. item.ChartPermissionSort = v.ChartPermissionSort
  28. item.CreateTime = time.Now()
  29. item.Body = GetRichtext(v2.Body)
  30. item.ReportLink = v2.ReportLink
  31. if item.ReportLink != "" {
  32. articleIdLink, errArt := GetReportLinkToArticleid(item.ReportLink)
  33. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  34. msg = "获取信息失败"
  35. err = errArt
  36. return
  37. }
  38. item.LinkArticleId = articleIdLink
  39. }
  40. items = append(items, item)
  41. }
  42. }
  43. itemsResult = items
  44. return
  45. }
  46. func AppendMinutesItemsLog(items []*cygx.CygxMinutesSummaryLog, item []*cygx.CygxRSlChartPermission, logType, sort string) (itemsResult []*cygx.CygxMinutesSummaryLog, msg string, err error) {
  47. mapSort := make(map[string]int)
  48. for _, v := range item {
  49. for _, v2 := range v.List {
  50. item := new(cygx.CygxMinutesSummaryLog)
  51. if mapSort[v.ChartPermissionSort] != 0 && mapSort[v.ChartPermissionSort] != v.ChartPermissionId {
  52. msg = "有内容行业分类,序号不能为空"
  53. return
  54. }
  55. mapSort[v.ChartPermissionSort] = v.ChartPermissionId
  56. item.Type = logType
  57. item.Sort = strings.ToUpper(sort)
  58. item.ChartPermissionId = v.ChartPermissionId
  59. item.ChartPermissionSort = v.ChartPermissionSort
  60. item.CreateTime = time.Now()
  61. item.Body = GetRichtext(v2.Body)
  62. item.ReportLink = v2.ReportLink
  63. if item.ReportLink != "" {
  64. articleIdLink, errArt := GetReportLinkToArticleid(item.ReportLink)
  65. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  66. msg = "获取信息失败"
  67. err = errArt
  68. return
  69. }
  70. item.LinkArticleId = articleIdLink
  71. }
  72. items = append(items, item)
  73. }
  74. }
  75. itemsResult = items
  76. return
  77. }
  78. // 通过接解析获取文章ID
  79. func GetReportLinkToArticleid(reportLink string) (articleId int, err error) {
  80. var artMd5 string
  81. //处理报告的
  82. strnum1 := strings.Index(reportLink, "id=")
  83. if strnum1 > 0 {
  84. sliceId := strings.Split(reportLink, "id=")
  85. if len(sliceId) > 1 {
  86. reportLink = sliceId[1]
  87. sliceMd5Id := strings.Split(reportLink, "&")
  88. artMd5 = sliceMd5Id[0]
  89. }
  90. if artMd5 != "" {
  91. detail, errArt := cygx.GetArticleDetailByMd5Id(artMd5)
  92. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  93. err = errArt
  94. return
  95. }
  96. if detail != nil {
  97. articleId = detail.ArticleId
  98. }
  99. }
  100. } else {
  101. //处理活动的
  102. linkList := strings.Split(reportLink, "/")
  103. if linkList[len(linkList)-1] != "" {
  104. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  105. if linkArticleId > 0 {
  106. articleInfo, errArt := cygx.GetArticleIdInfoByArticleId(linkArticleId)
  107. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  108. err = errArt
  109. return
  110. }
  111. if articleInfo != nil {
  112. articleId = articleInfo.ArticleId
  113. }
  114. }
  115. }
  116. }
  117. return
  118. }
  119. //
  120. //func init() {
  121. // DoArticleOnenIdWxTemplateMsg(1000614, 1)
  122. //}
  123. // 过滤策略平台报告,研选报告重复推送,以及权限勾选的推送
  124. func DoArticleOnenIdWxTemplateMsg(articleId int, source int) (err error) {
  125. //优先排序: 预约纪要 > 关注作者 > 关注产业
  126. //source 来源 1研选 ,2 策略平台的报告
  127. //industrialSubjectIds 标的ID ,发布活动的时候使用
  128. var msg string
  129. var industrialSubjectIds string
  130. defer func() {
  131. //fmt.Println()
  132. if err != nil {
  133. fmt.Println("err:", err)
  134. go alarm_msg.SendAlarmMsg("过滤策略平台报告,研选报告重复推送,以及权限勾选的推送,发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  135. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  136. }
  137. if msg != "" {
  138. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  139. }
  140. }()
  141. articleInfo, err := cygx.GetArticleInfoOtherByArticleId(articleId)
  142. if err != nil {
  143. return
  144. }
  145. //对于已归类的报告,修改产业不做二次推送
  146. if articleInfo.IsClassFail == 0 && articleInfo.ArticleId < utils.SummaryArticleId {
  147. return err
  148. }
  149. articleInfo.Abstract, _ = utils.GetReportContentTextSub(articleInfo.Abstract)
  150. industrialSubjectIds, err = cygx.GetSubjectIds(articleId)
  151. if err != nil {
  152. return err
  153. }
  154. var chartPermissionId int
  155. if source == 1 {
  156. chartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  157. } else {
  158. var chartPermissionName string
  159. reportMapDetail, err := cygx.GetCygxReportMappingRespByid(articleInfo.CategoryId)
  160. if err != nil {
  161. return err
  162. }
  163. //处理策略与非策略 的权限判断
  164. if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME {
  165. chartPermissionId = utils.CE_LUE_ID
  166. } else {
  167. if reportMapDetail.PermissionType == 1 {
  168. chartPermissionName = reportMapDetail.ChartPermissionName + "(主观)"
  169. } else {
  170. chartPermissionName = reportMapDetail.ChartPermissionName + "(客观)"
  171. }
  172. chartPermissionDetail, err := models.GetChartPermissionByRemark(chartPermissionName)
  173. if err != nil {
  174. return err
  175. }
  176. chartPermissionId = chartPermissionDetail.ChartPermissionId
  177. }
  178. }
  179. //文章关联的产业
  180. var industryName string
  181. var industrialManagementId string
  182. detailIndustryNameList, err := cygx.GetIndustrialManagemenDetailByAaticleID(articleId)
  183. if err != nil && err.Error() != utils.ErrNoRow() {
  184. return err
  185. }
  186. for _, v := range detailIndustryNameList {
  187. industryName += v.IndustryName + ","
  188. industrialManagementId += strconv.Itoa(v.IndustrialManagementId) + ","
  189. }
  190. industryName = strings.TrimRight(industryName, ",")
  191. industrialManagementId = strings.TrimRight(industrialManagementId, ",")
  192. charInfo, err := cygx.GetCategoryInfoById(chartPermissionId)
  193. if err != nil {
  194. return err
  195. }
  196. //处理勾选了全部行业赛道的用户
  197. var allIn string
  198. allIn = DoXzsChooseSend(charInfo.PermissionName)
  199. if allIn != "" {
  200. allInList, err := cygx.GetCygxXzsChooseSendByAllIn(allIn)
  201. if err != nil && err.Error() != utils.ErrNoRow() {
  202. return err
  203. }
  204. if len(allInList) > 0 {
  205. var allInUserId string
  206. for _, v := range allInList {
  207. allInUserId += strconv.Itoa(v.UserId) + ","
  208. }
  209. allInUserId = strings.TrimRight(allInUserId, ",")
  210. userFllowIndustrialList, err := cygx.GetUserFllowIndustrialListByUserIdAndIndustrial(allInUserId, industrialManagementId)
  211. if err != nil && err.Error() != utils.ErrNoRow() {
  212. return err
  213. }
  214. mapUserFllowed := make(map[string]int)
  215. for _, v := range userFllowIndustrialList {
  216. //用户ID与其关注的产业组成唯一索引,判断是否存在,如果不存在就进行自动关注
  217. mapUserFllowed[fmt.Sprint("uid:", v.UserId, "_Industrial:", v.IndustrialManagementId)] = v.UserId
  218. }
  219. //获取这些allIN用户的的信息进行遍历生成需要插入的数据
  220. userList, err := models.GetWxUserListByUserIdsHaveCompany(allInUserId)
  221. if err != nil && err.Error() != utils.ErrNoRow() {
  222. return err
  223. }
  224. var industryFllowItems []*cygx.CygxIndustryFllow
  225. for _, v := range detailIndustryNameList {
  226. for _, vUser := range userList {
  227. //如果用户这个用户没有关注这个产业就进行自动关注
  228. if mapUserFllowed[fmt.Sprint("uid:", vUser.UserId, "_Industrial:", v.IndustrialManagementId)] == 0 {
  229. item := new(cygx.CygxIndustryFllow)
  230. item.IndustrialManagementId = v.IndustrialManagementId
  231. item.UserId = vUser.UserId
  232. item.Email = vUser.Email
  233. item.Mobile = vUser.Mobile
  234. item.RealName = vUser.RealName
  235. item.CompanyId = vUser.CompanyId
  236. item.CompanyName = vUser.CompanyName
  237. item.Source = 3
  238. item.Type = 1
  239. item.CreateTime = time.Now()
  240. item.ModifyTime = time.Now()
  241. industryFllowItems = append(industryFllowItems, item)
  242. }
  243. }
  244. }
  245. err = cygx.AddCygxIndustryFllowMulti(industryFllowItems)
  246. if err != nil {
  247. go alarm_msg.SendAlarmMsg("用户关注全部赛道,出现新赛道批量添加失败 ,AddCygxIndustryFllowMulti ErrMsg:"+err.Error(), 2)
  248. }
  249. }
  250. }
  251. //处理勾选了全部行业赛道的用户之后,再判断是否推送过
  252. cacheKey := fmt.Sprint("Source:ADMIN", "_ArticleId:", articleId)
  253. isExist := utils.Rc.IsExist(cacheKey)
  254. if isExist {
  255. return err
  256. }
  257. setNX := utils.Rc.SetNX(cacheKey, articleId, time.Minute*30)
  258. if !setNX {
  259. go alarm_msg.SendAlarmMsg("发送模版消息失败,设置Redis Key 过期时间失败:key"+cacheKey, 3)
  260. return err
  261. }
  262. //cacheKey := fmt.Sprint("Source:ADMIN", "_ArticleId:", articleId)
  263. //ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  264. //if ttlTime > 0 {
  265. // return err
  266. //}
  267. //
  268. //utils.Rc.Put(cacheKey, articleId, time.Minute*30)
  269. // 获取所有有权的用户的 openid
  270. mapOpenidPower := make(map[int]string)
  271. openidPowerList, err := cygx.GetCygxUserRecordPower(strconv.Itoa(chartPermissionId))
  272. if err != nil && err.Error() != utils.ErrNoRow() {
  273. return err
  274. }
  275. for _, v := range openidPowerList {
  276. mapOpenidPower[v.UserId] = v.OpenId
  277. }
  278. //获取关注这个文章对应产业的用户的 openid
  279. mapOpenidFllow := make(map[int]string)
  280. openidFllowList, err := cygx.GetCygxUserFllowOpenid(articleId)
  281. if err != nil && err.Error() != utils.ErrNoRow() {
  282. return err
  283. }
  284. for _, v := range openidFllowList {
  285. mapOpenidFllow[v.UserId] = v.OpenId
  286. }
  287. //获取关注这个文章对应作者的用户的 openid
  288. mapOpenidDepartmentFllow := make(map[int]string)
  289. openidDepartmentFllowList, err := cygx.GetCygxUserFllowDepartmentOpenid(articleId)
  290. if err != nil && err.Error() != utils.ErrNoRow() {
  291. return err
  292. }
  293. for _, v := range openidDepartmentFllowList {
  294. mapOpenidDepartmentFllow[v.UserId] = v.OpenId
  295. }
  296. //获取拒绝接收推送的的用户的 openid
  297. mapOpenidRefuset := make(map[int]string)
  298. openidRefusetList, err := cygx.GetCygxUserRefusetOpenid()
  299. if err != nil && err.Error() != utils.ErrNoRow() {
  300. return err
  301. }
  302. for _, v := range openidRefusetList {
  303. mapOpenidRefuset[v.UserId] = v.OpenId
  304. }
  305. //获取提交过推送规则的用户的 openid
  306. mapUserIdChooseSend := make(map[int]int)
  307. chooseSendtList, err := cygx.GetCygxXzsChooseSend("")
  308. if err != nil && err.Error() != utils.ErrNoRow() {
  309. return err
  310. }
  311. for _, v := range chooseSendtList {
  312. mapUserIdChooseSend[v.UserId] = v.UserId
  313. }
  314. //已经推送了的openid
  315. mapOpenidPushed := make(map[int]string)
  316. keyword2 := articleInfo.Title
  317. keyword3 := articleInfo.PublishDate.Format(utils.FormatDate)
  318. if source == 2 {
  319. keyword3 = time.Now().Format(utils.FormatDate)
  320. }
  321. keyword4 := articleInfo.Abstract
  322. if source == 1 {
  323. if articleInfo.IsSummary == 1 {
  324. //优先推送1: 预约纪要
  325. if industrialSubjectIds != "" {
  326. mapActivityMobile := make(map[string]string)
  327. appointmentSummaryList, err := cygx.GetCygxAppointmentSummaryListBySubjectId(industrialSubjectIds)
  328. if err != nil && err.Error() != utils.ErrNoRow() {
  329. fmt.Println(err)
  330. return err
  331. }
  332. if len(appointmentSummaryList) > 0 {
  333. for _, v := range appointmentSummaryList {
  334. mapActivityMobile[fmt.Sprintf(v.Mobile)] += v.ActivityName + ","
  335. }
  336. if len(mapActivityMobile) > 0 {
  337. for k := range mapActivityMobile {
  338. openIditem, err := cygx.GetUserRecordOpenidByMobile(k)
  339. if err != nil && err.Error() != utils.ErrNoRow() {
  340. return err
  341. }
  342. //mfyxOpenIditem, err := cygx.GetMfyxUserRecordOpenidByMobile(k)
  343. if err != nil && err.Error() != utils.ErrNoRow() {
  344. return err
  345. }
  346. //如果没有权限或者没有获取到 openID的就不推送
  347. if openIditem == nil || mapOpenidPower[openIditem.UserId] == "" {
  348. continue
  349. }
  350. first := "您预约的调研,有关联的纪要发布/更新了"
  351. keyword1 := "您预约的调研,有关联的纪要发布/更新了"
  352. //keyword1 := strings.TrimRight(v, ",")
  353. //如果有权限而且小助手没有提交过信息的 就做正常推送
  354. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  355. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  356. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  357. // 研选发类目模板消息
  358. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew("您预约的调研,有新报告发布", "已发布", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  359. }
  360. //如果小助手勾选了对应的权限信息 就做正常推送
  361. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" {
  362. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  363. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  364. // 研选发类目模板消息
  365. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew("您预约的调研,有新报告发布", "已发布", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }
  372. fmt.Println(openidDepartmentFllowList)
  373. //优先推送2: 关注作者
  374. for _, v := range openidDepartmentFllowList {
  375. //如果是已经推送的就不做推送
  376. if mapOpenidPushed[v.UserId] != "" {
  377. continue
  378. }
  379. //如果没有权限 的就不推送
  380. if mapOpenidPower[v.UserId] == "" {
  381. continue
  382. }
  383. openIditem := new(cygx.OpenIdList)
  384. openIditem.UserId = v.UserId
  385. openIditem.OpenId = v.OpenId
  386. first := "您关注的作者发布了新的报告"
  387. keyword1 := "作者【" + articleInfo.NickName + "】发布了新的报告"
  388. //如果有权限而且小助手没有提交过信息的 就做正常推送
  389. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  390. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  391. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  392. // 研选发类目模板消息
  393. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(articleInfo.NickName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  394. }
  395. //如果小助手勾选了对应的权限信息 就做正常推送
  396. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidDepartmentFllow[openIditem.UserId] != "" {
  397. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  398. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  399. // 研选发类目模板消息
  400. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(articleInfo.NickName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  401. }
  402. }
  403. //优先推送3: 关注产业
  404. for _, v := range openidFllowList {
  405. //如果是已经推送的就不做推送
  406. if mapOpenidPushed[v.UserId] != "" {
  407. continue
  408. }
  409. //如果没有权限 的就不推送
  410. if mapOpenidPower[v.UserId] == "" {
  411. continue
  412. }
  413. openIditem := new(cygx.OpenIdList)
  414. openIditem.UserId = v.UserId
  415. openIditem.OpenId = v.OpenId
  416. //first := "您关注的产业有更新报告"
  417. //keyword1 := industryName
  418. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  419. keyword1 := "【" + industryName + "】有报告发布/更新"
  420. //如果有权限而且小助手没有提交过信息的 就做正常推送
  421. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  422. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  423. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  424. // 研选发类目模板消息
  425. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  426. }
  427. //如果小助手勾选了对应的权限信息 就做正常推送
  428. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" {
  429. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  430. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  431. // 研选发类目模板消息
  432. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  433. }
  434. }
  435. //针对哪些没有关注作者,没有关注产业,没有预约纪要的人的推送
  436. for k, v := range mapOpenidPower {
  437. //如果是已经推送的就不做推送
  438. if mapOpenidPushed[k] != "" {
  439. continue
  440. }
  441. openIditem := new(cygx.OpenIdList)
  442. openIditem.UserId = k
  443. openIditem.OpenId = v
  444. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  445. keyword1 := "【" + industryName + "】有报告发布/更新"
  446. //如果有权限而且小助手没有提交过信息的 就做正常推送
  447. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  448. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  449. // 研选发类目模板消息
  450. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  451. }
  452. //如果小助手勾选了对应的权限信息 就做正常推送
  453. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" {
  454. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  455. // 研选发类目模板消息
  456. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  457. }
  458. }
  459. } else {
  460. reportMapDetail, err := cygx.GetCygxReportMappingRespByid(articleInfo.CategoryId)
  461. if err != nil {
  462. return err
  463. }
  464. //如果是策略就按照策略的推送方式来写
  465. if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME {
  466. //获取提交过推送规则的用户的 openid
  467. mapUserFllowCeLue := make(map[int]string)
  468. userFllowCeLueList, err := cygx.GetCygxUserFllowCeLueOpenid(articleInfo.CategoryId)
  469. if err != nil {
  470. return err
  471. }
  472. for _, v := range userFllowCeLueList {
  473. mapUserFllowCeLue[v.UserId] = v.OpenId
  474. }
  475. industryName := reportMapDetail.SubCategoryName
  476. for k, v := range mapOpenidPower {
  477. if mapOpenidPushed[k] != "" {
  478. continue
  479. }
  480. openIditem := new(cygx.OpenIdList)
  481. openIditem.UserId = k
  482. openIditem.OpenId = v
  483. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  484. keyword1 := "【" + industryName + "】有报告发布/更新"
  485. //如果有权限而且小助手没有提交过信息的 就做正常推送
  486. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  487. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  488. // 研选发类目模板消息
  489. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  490. }
  491. //如果小助手勾选了对应的权限信息 就做正常推送
  492. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != "" {
  493. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  494. // 研选发类目模板消息
  495. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  496. }
  497. }
  498. } else {
  499. for k, v := range mapOpenidPower {
  500. openIditem := new(cygx.OpenIdList)
  501. openIditem.UserId = k
  502. openIditem.OpenId = v
  503. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  504. keyword1 := "【" + industryName + "】有报告发布/更新"
  505. //如果有权限而且小助手没有提交过信息的 就做正常推送
  506. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  507. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  508. // 研选发类目模板消息
  509. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  510. }
  511. //如果小助手勾选了对应的权限信息 就做正常推送
  512. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" {
  513. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  514. // 研选发类目模板消息
  515. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  516. }
  517. }
  518. }
  519. }
  520. go cygx.UpdateIsClassFail(articleInfo)
  521. return
  522. }
  523. //func init() {
  524. // DoThisWeekLastWeekWxTemplateMsg("标题", "20220909", "摘要", 2, 1)
  525. //}
  526. // 处理本周研究汇总,上周纪要汇总,报告精选
  527. func DoThisWeekLastWeekWxTemplateMsg(title, publishDate, abstract string, articleId int, source int) (err error) {
  528. cacheKey := fmt.Sprint("Source:", source, "_ArticleId:", articleId)
  529. isExist := utils.Rc.IsExist(cacheKey)
  530. if isExist {
  531. return err
  532. }
  533. setNX := utils.Rc.SetNX(cacheKey, articleId, time.Minute*30)
  534. //如果key 设置成功就走推送
  535. if setNX {
  536. var msg string
  537. defer func() {
  538. //fmt.Println()
  539. if err != nil {
  540. fmt.Println("err:", err)
  541. go alarm_msg.SendAlarmMsg("过滤策略平台报告,研选报告重复推送,以及权限勾选的推送,发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  542. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  543. }
  544. if msg != "" {
  545. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  546. }
  547. }()
  548. OpenIdList, err := models.GetCygxUserAllOpneid()
  549. if err != nil {
  550. return err
  551. }
  552. if len(OpenIdList) > 0 {
  553. var first, keyword1 string
  554. if source == 1 {
  555. keyword1 = "【报告精选】已发布"
  556. } else if source == 2 {
  557. keyword1 = "【本周研究汇总】已发布"
  558. } else {
  559. keyword1 = "【上周纪要汇总】已发布"
  560. }
  561. //keyword1 := "--"
  562. keyword2 := title
  563. keyword3 := strings.Replace(publishDate, "00:00:00", "", -1)
  564. keyword4 := abstract
  565. services.SendWxMsgThisWeekLastWeek(first, keyword1, keyword2, keyword3, keyword4, OpenIdList, articleId, source)
  566. }
  567. } else {
  568. go alarm_msg.SendAlarmMsg("发送模版消息失败,设置Redis Key 过期时间失败:key"+cacheKey, 3)
  569. }
  570. return
  571. }
  572. // 根据行业处理所选的全部赛道字段
  573. func DoXzsChooseSend(chartPermissionName string) string {
  574. var allIn string
  575. if chartPermissionName == utils.YI_YAO_NAME {
  576. allIn = "all_in_yi_yao"
  577. } else if chartPermissionName == utils.XIAO_FEI_NAME {
  578. allIn = "all_in_xiao_fei"
  579. } else if chartPermissionName == utils.KE_JI_NAME {
  580. allIn = "all_in_ke_ji"
  581. } else if chartPermissionName == utils.ZHI_ZAO_NAME {
  582. allIn = "all_in_zhi_zao"
  583. } else if chartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  584. allIn = "all_in_yan_xuan"
  585. }
  586. return allIn
  587. }
  588. //func init() {
  589. // //MakeArticleMomentsImg(1000408)
  590. // var condition string
  591. // var pars []interface{}
  592. // condition = " AND article_type_id > 0 AND publish_status = 1 ORDER BY article_id DESC "
  593. // list, errList := cygx.GetCygxArticleList(condition, pars, 0, 999)
  594. // if errList != nil {
  595. // fmt.Println(errList)
  596. // return
  597. // }
  598. // fmt.Println("list", len(list))
  599. // //return
  600. // for k, v := range list {
  601. // fmt.Println(k)
  602. // MakeArticleMomentsImg(v.ArticleId)
  603. // }
  604. //}
  605. // 生成文章分享到朋友圈的图片
  606. func MakeArticleMomentsImg(articleId int) {
  607. var err error
  608. //time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒
  609. defer func() {
  610. if err != nil {
  611. fmt.Println("err:", err)
  612. go alarm_msg.SendAlarmMsg("生成文章分享到朋友圈的图片,MakeArticleMomentsImg Err:"+err.Error()+"文章ID"+strconv.Itoa(articleId), 3)
  613. }
  614. }()
  615. articleInfo, e := cygx.GetArticleInfoOtherByArticleId(articleId)
  616. if e != nil {
  617. err = errors.New("GetArticleInfoOtherByArticleId, Err: " + e.Error())
  618. return
  619. }
  620. configCode := "article_moments_img_html"
  621. detailConfig, e := cygx.GetCygxConfigDetailByCode(configCode)
  622. if e != nil {
  623. err = errors.New("GetCygxConfigDetailByCode 获取生成文章分享到朋友圈的图片格式信息失败, Err: " + e.Error())
  624. return
  625. }
  626. configValue := detailConfig.ConfigValue
  627. configValue = strings.Replace(configValue, "{{Title}}", articleInfo.Title, -1)
  628. configValue = strings.Replace(configValue, "{{HeadImgUrl}}", articleInfo.HeadImgUrl, -1)
  629. configValue = strings.Replace(configValue, "{{NickName}}", articleInfo.NickName, -1)
  630. configValue = strings.Replace(configValue, "{{PublishDate}}", articleInfo.PublishDate.Format(utils.FormatDateTime), -1)
  631. configValue = strings.Replace(configValue, "{{Abstract}}", articleInfo.Abstract, -1)
  632. configValue = strings.Replace(configValue, "{{BodyText}}", articleInfo.BodyText, -1)
  633. htm2ImgReq := make(map[string]interface{})
  634. htm2ImgReq["html_content"] = configValue
  635. htm2ImgReq["width"] = 2250
  636. htm2ImgReq["height"] = 3813
  637. res, err := postHtml2Img(htm2ImgReq)
  638. if err != nil || res == nil {
  639. err = errors.New("html转图片失败: " + res.Msg)
  640. return
  641. }
  642. if res.Code != 200 {
  643. err = errors.New("html转图片失败: " + res.Msg)
  644. return
  645. }
  646. imgUrl := res.Data
  647. //fmt.Println(imgUrl)
  648. // 记录海报信息
  649. err = cygx.UpdateCygxArticleMomentsImg(imgUrl, articleId)
  650. return
  651. }