research_summary.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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. if len(detailIndustryNameList) > 0 {
  306. var industrialIds []int
  307. for _, v := range detailIndustryNameList {
  308. industrialIds = append(industrialIds, v.IndustrialManagementId)
  309. }
  310. var conditionFollow string
  311. var parsFollow []interface{}
  312. //根据产业关注ID,获取用户不感兴趣的产业信息
  313. conditionFollow = " AND industrial_management_id IN (" + utils.GetOrmInReplace(len(industrialIds)) + ") AND follow_type = 3 "
  314. parsFollow = append(parsFollow, industrialIds)
  315. userFllowListUninterested, e := cygx.GetCygxIndustryFllowList(conditionFollow, parsFollow, 0, 0)
  316. if e != nil {
  317. err = errors.New("GetCygxIndustryFllowList, Err: " + e.Error())
  318. return
  319. }
  320. var userFllowNum = make(map[int]int)
  321. for _, v := range userFllowListUninterested {
  322. userFllowNum[v.UserId]++
  323. //如果活动对应的产业数量,跟用户不感兴趣的产业数量一致,就不做推送
  324. if userFllowNum[v.UserId] == len(detailIndustryNameList) {
  325. mapOpenidRefuset[v.UserId] = "_"
  326. }
  327. }
  328. }
  329. //获取提交过推送规则的用户的 openid
  330. mapUserIdChooseSend := make(map[int]int)
  331. chooseSendtList, err := cygx.GetCygxXzsChooseSend("")
  332. if err != nil && err.Error() != utils.ErrNoRow() {
  333. return err
  334. }
  335. for _, v := range chooseSendtList {
  336. mapUserIdChooseSend[v.UserId] = v.UserId
  337. }
  338. //已经推送了的openid
  339. mapOpenidPushed := make(map[int]string)
  340. keyword2 := articleInfo.Title
  341. keyword3 := articleInfo.PublishDate.Format(utils.FormatDate)
  342. if source == 2 {
  343. keyword3 = time.Now().Format(utils.FormatDate)
  344. }
  345. keyword4 := articleInfo.Abstract
  346. if source == 1 {
  347. if articleInfo.IsSummary == 1 {
  348. //优先推送1: 预约纪要
  349. if industrialSubjectIds != "" {
  350. mapActivityMobile := make(map[string]string)
  351. appointmentSummaryList, err := cygx.GetCygxAppointmentSummaryListBySubjectId(industrialSubjectIds)
  352. if err != nil && err.Error() != utils.ErrNoRow() {
  353. fmt.Println(err)
  354. return err
  355. }
  356. if len(appointmentSummaryList) > 0 {
  357. for _, v := range appointmentSummaryList {
  358. mapActivityMobile[fmt.Sprintf(v.Mobile)] += v.ActivityName + ","
  359. }
  360. if len(mapActivityMobile) > 0 {
  361. for k := range mapActivityMobile {
  362. openIditem, err := cygx.GetUserRecordOpenidByMobile(k)
  363. if err != nil && err.Error() != utils.ErrNoRow() {
  364. return err
  365. }
  366. //mfyxOpenIditem, err := cygx.GetMfyxUserRecordOpenidByMobile(k)
  367. if err != nil && err.Error() != utils.ErrNoRow() {
  368. return err
  369. }
  370. //如果没有权限或者没有获取到 openID的就不推送
  371. if openIditem == nil || mapOpenidPower[openIditem.UserId] == "" {
  372. continue
  373. }
  374. first := "您预约的调研,有关联的纪要发布/更新了"
  375. keyword1 := "您预约的调研,有关联的纪要发布/更新了"
  376. //keyword1 := strings.TrimRight(v, ",")
  377. //如果有权限而且小助手没有提交过信息的 就做正常推送
  378. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  379. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  380. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  381. // 研选发类目模板消息
  382. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew("您预约的调研,有新报告发布", "已发布", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  383. }
  384. //如果小助手勾选了对应的权限信息 就做正常推送
  385. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" {
  386. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  387. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  388. // 研选发类目模板消息
  389. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew("您预约的调研,有新报告发布", "已发布", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. fmt.Println(openidDepartmentFllowList)
  397. //优先推送2: 关注作者
  398. for _, v := range openidDepartmentFllowList {
  399. //如果是已经推送的就不做推送
  400. if mapOpenidPushed[v.UserId] != "" {
  401. continue
  402. }
  403. //如果没有权限 的就不推送
  404. if mapOpenidPower[v.UserId] == "" {
  405. continue
  406. }
  407. openIditem := new(cygx.OpenIdList)
  408. openIditem.UserId = v.UserId
  409. openIditem.OpenId = v.OpenId
  410. first := "您关注的作者发布了新的报告"
  411. keyword1 := "作者【" + articleInfo.NickName + "】发布了新的报告"
  412. //如果有权限而且小助手没有提交过信息的 就做正常推送
  413. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  414. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  415. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  416. // 研选发类目模板消息
  417. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(articleInfo.NickName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  418. }
  419. //如果小助手勾选了对应的权限信息 就做正常推送
  420. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidDepartmentFllow[openIditem.UserId] != "" {
  421. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  422. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  423. // 研选发类目模板消息
  424. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(articleInfo.NickName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  425. }
  426. }
  427. //优先推送3: 关注产业
  428. for _, v := range openidFllowList {
  429. //如果是已经推送的就不做推送
  430. if mapOpenidPushed[v.UserId] != "" {
  431. continue
  432. }
  433. //如果没有权限 的就不推送
  434. if mapOpenidPower[v.UserId] == "" {
  435. continue
  436. }
  437. openIditem := new(cygx.OpenIdList)
  438. openIditem.UserId = v.UserId
  439. openIditem.OpenId = v.OpenId
  440. //first := "您关注的产业有更新报告"
  441. //keyword1 := industryName
  442. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  443. keyword1 := "【" + industryName + "】有报告发布/更新"
  444. //如果有权限而且小助手没有提交过信息的 就做正常推送
  445. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  446. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  447. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  448. // 研选发类目模板消息
  449. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  450. }
  451. //如果小助手勾选了对应的权限信息 就做正常推送
  452. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" {
  453. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  454. mapOpenidPushed[openIditem.UserId] = openIditem.OpenId
  455. // 研选发类目模板消息
  456. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  457. }
  458. }
  459. //针对哪些没有关注作者,没有关注产业,没有预约纪要的人的推送
  460. for k, v := range mapOpenidPower {
  461. //如果是已经推送的就不做推送
  462. if mapOpenidPushed[k] != "" {
  463. continue
  464. }
  465. openIditem := new(cygx.OpenIdList)
  466. openIditem.UserId = k
  467. openIditem.OpenId = v
  468. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  469. keyword1 := "【" + industryName + "】有报告发布/更新"
  470. //如果有权限而且小助手没有提交过信息的 就做正常推送
  471. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  472. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  473. // 研选发类目模板消息
  474. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  475. }
  476. //如果小助手勾选了对应的权限信息 就做正常推送
  477. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" {
  478. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  479. // 研选发类目模板消息
  480. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  481. }
  482. }
  483. } else {
  484. reportMapDetail, err := cygx.GetCygxReportMappingRespByid(articleInfo.CategoryId)
  485. if err != nil {
  486. return err
  487. }
  488. //如果是策略就按照策略的推送方式来写
  489. if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME {
  490. //获取提交过推送规则的用户的 openid
  491. mapUserFllowCeLue := make(map[int]string)
  492. userFllowCeLueList, err := cygx.GetCygxUserFllowCeLueOpenid(articleInfo.CategoryId)
  493. if err != nil {
  494. return err
  495. }
  496. for _, v := range userFllowCeLueList {
  497. mapUserFllowCeLue[v.UserId] = v.OpenId
  498. }
  499. industryName := reportMapDetail.SubCategoryName
  500. for k, v := range mapOpenidPower {
  501. if mapOpenidPushed[k] != "" {
  502. continue
  503. }
  504. openIditem := new(cygx.OpenIdList)
  505. openIditem.UserId = k
  506. openIditem.OpenId = v
  507. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  508. keyword1 := "【" + industryName + "】有报告发布/更新"
  509. //如果有权限而且小助手没有提交过信息的 就做正常推送
  510. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  511. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  512. // 研选发类目模板消息
  513. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  514. }
  515. //如果小助手勾选了对应的权限信息 就做正常推送
  516. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != "" {
  517. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  518. // 研选发类目模板消息
  519. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  520. }
  521. }
  522. } else {
  523. for k, v := range mapOpenidPower {
  524. openIditem := new(cygx.OpenIdList)
  525. openIditem.UserId = k
  526. openIditem.OpenId = v
  527. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  528. keyword1 := "【" + industryName + "】有报告发布/更新"
  529. //如果有权限而且小助手没有提交过信息的 就做正常推送
  530. if mapUserIdChooseSend[openIditem.UserId] == 0 {
  531. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  532. // 研选发类目模板消息
  533. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  534. }
  535. //如果小助手勾选了对应的权限信息 就做正常推送
  536. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" {
  537. services.SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  538. // 研选发类目模板消息
  539. go services.SendWxCategoryMsgWithCygxActivityAppointmentNew(industryName, "发布了新报告", utils.TruncateActivityNameString(articleInfo.Title), articleInfo.PublishDate.Format(utils.FormatDateTimeMinute2), openIditem, articleId)
  540. }
  541. }
  542. }
  543. }
  544. go cygx.UpdateIsClassFail(articleInfo)
  545. return
  546. }
  547. //func init() {
  548. // DoThisWeekLastWeekWxTemplateMsg("标题", "20220909", "摘要", 2, 1)
  549. //}
  550. // 处理本周研究汇总,上周纪要汇总,报告精选
  551. func DoThisWeekLastWeekWxTemplateMsg(title, publishDate, abstract string, articleId int, source int) (err error) {
  552. cacheKey := fmt.Sprint("Source:", source, "_ArticleId:", articleId)
  553. isExist := utils.Rc.IsExist(cacheKey)
  554. if isExist {
  555. return err
  556. }
  557. setNX := utils.Rc.SetNX(cacheKey, articleId, time.Minute*30)
  558. //如果key 设置成功就走推送
  559. if setNX {
  560. var msg string
  561. defer func() {
  562. //fmt.Println()
  563. if err != nil {
  564. fmt.Println("err:", err)
  565. go alarm_msg.SendAlarmMsg("过滤策略平台报告,研选报告重复推送,以及权限勾选的推送,发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  566. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  567. }
  568. if msg != "" {
  569. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  570. }
  571. }()
  572. OpenIdList, err := models.GetCygxUserAllOpneid()
  573. if err != nil {
  574. return err
  575. }
  576. if len(OpenIdList) > 0 {
  577. var first, keyword1 string
  578. if source == 1 {
  579. keyword1 = "【报告精选】已发布"
  580. } else if source == 2 {
  581. keyword1 = "【本周研究汇总】已发布"
  582. } else {
  583. keyword1 = "【上周纪要汇总】已发布"
  584. }
  585. //keyword1 := "--"
  586. keyword2 := title
  587. keyword3 := strings.Replace(publishDate, "00:00:00", "", -1)
  588. keyword4 := abstract
  589. services.SendWxMsgThisWeekLastWeek(first, keyword1, keyword2, keyword3, keyword4, OpenIdList, articleId, source)
  590. }
  591. } else {
  592. go alarm_msg.SendAlarmMsg("发送模版消息失败,设置Redis Key 过期时间失败:key"+cacheKey, 3)
  593. }
  594. return
  595. }
  596. // 根据行业处理所选的全部赛道字段
  597. func DoXzsChooseSend(chartPermissionName string) string {
  598. var allIn string
  599. if chartPermissionName == utils.YI_YAO_NAME {
  600. allIn = "all_in_yi_yao"
  601. } else if chartPermissionName == utils.XIAO_FEI_NAME {
  602. allIn = "all_in_xiao_fei"
  603. } else if chartPermissionName == utils.KE_JI_NAME {
  604. allIn = "all_in_ke_ji"
  605. } else if chartPermissionName == utils.ZHI_ZAO_NAME {
  606. allIn = "all_in_zhi_zao"
  607. } else if chartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  608. allIn = "all_in_yan_xuan"
  609. }
  610. return allIn
  611. }
  612. //func init() {
  613. // //MakeArticleMomentsImg(1000408)
  614. // var condition string
  615. // var pars []interface{}
  616. // condition = " AND article_type_id > 0 AND publish_status = 1 ORDER BY article_id DESC "
  617. // list, errList := cygx.GetCygxArticleList(condition, pars, 0, 999)
  618. // if errList != nil {
  619. // fmt.Println(errList)
  620. // return
  621. // }
  622. // fmt.Println("list", len(list))
  623. // //return
  624. // for k, v := range list {
  625. // fmt.Println(k)
  626. // MakeArticleMomentsImg(v.ArticleId)
  627. // }
  628. //}
  629. // 生成文章分享到朋友圈的图片
  630. func MakeArticleMomentsImg(articleId int) {
  631. var err error
  632. //time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒
  633. defer func() {
  634. if err != nil {
  635. fmt.Println("err:", err)
  636. go alarm_msg.SendAlarmMsg("生成文章分享到朋友圈的图片,MakeArticleMomentsImg Err:"+err.Error()+"文章ID"+strconv.Itoa(articleId), 3)
  637. }
  638. }()
  639. articleInfo, e := cygx.GetArticleInfoOtherByArticleId(articleId)
  640. if e != nil {
  641. err = errors.New("GetArticleInfoOtherByArticleId, Err: " + e.Error())
  642. return
  643. }
  644. configCode := "article_moments_img_html"
  645. detailConfig, e := cygx.GetCygxConfigDetailByCode(configCode)
  646. if e != nil {
  647. err = errors.New("GetCygxConfigDetailByCode 获取生成文章分享到朋友圈的图片格式信息失败, Err: " + e.Error())
  648. return
  649. }
  650. configValue := detailConfig.ConfigValue
  651. configValue = strings.Replace(configValue, "{{Title}}", articleInfo.Title, -1)
  652. configValue = strings.Replace(configValue, "{{HeadImgUrl}}", articleInfo.HeadImgUrl, -1)
  653. configValue = strings.Replace(configValue, "{{NickName}}", articleInfo.NickName, -1)
  654. configValue = strings.Replace(configValue, "{{PublishDate}}", articleInfo.PublishDate.Format(utils.FormatDateTime), -1)
  655. configValue = strings.Replace(configValue, "{{Abstract}}", articleInfo.Abstract, -1)
  656. configValue = strings.Replace(configValue, "{{BodyText}}", articleInfo.BodyText, -1)
  657. htm2ImgReq := make(map[string]interface{})
  658. htm2ImgReq["html_content"] = configValue
  659. htm2ImgReq["width"] = 2250
  660. htm2ImgReq["height"] = 3813
  661. res, err := postHtml2Img(htm2ImgReq)
  662. if err != nil || res == nil {
  663. err = errors.New("html转图片失败: " + res.Msg)
  664. return
  665. }
  666. if res.Code != 200 {
  667. err = errors.New("html转图片失败: " + res.Msg)
  668. return
  669. }
  670. imgUrl := res.Data
  671. //fmt.Println(imgUrl)
  672. // 记录海报信息
  673. err = cygx.UpdateCygxArticleMomentsImg(imgUrl, articleId)
  674. return
  675. }