article.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/PuerkitoBio/goquery"
  7. "github.com/beego/beego/v2/client/orm"
  8. "hongze/hongze_cygx/models"
  9. "hongze/hongze_cygx/utils"
  10. "html"
  11. "net/url"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. func GetReportContentSub(content string) (contentSub string, err error) {
  17. content = html.UnescapeString(content)
  18. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  19. if err != nil {
  20. fmt.Println("create doc err:", err.Error())
  21. return
  22. }
  23. n := 0
  24. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  25. if n > 3 {
  26. return
  27. }
  28. n++
  29. phtml, err := s.Html()
  30. if err != nil {
  31. fmt.Println("get html err", err.Error())
  32. return
  33. }
  34. if s.Text() != "" || strings.Contains(phtml, "src") {
  35. contentSub = contentSub + "<p>" + phtml + "</p>"
  36. }
  37. })
  38. return
  39. }
  40. func GetReportContentTextSub(content string) (contentSub string, err error) {
  41. content = html.UnescapeString(content)
  42. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  43. docText := doc.Text()
  44. bodyRune := []rune(docText)
  45. bodyRuneLen := len(bodyRune)
  46. if bodyRuneLen > 200 {
  47. bodyRuneLen = 200
  48. }
  49. body := string(bodyRune[:bodyRuneLen])
  50. contentSub = body
  51. contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
  52. return
  53. }
  54. func GetReportContentTextSubNew(content string) (contentSub string, err error) {
  55. content = html.UnescapeString(content)
  56. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  57. docText := doc.Text()
  58. bodyRune := []rune(docText)
  59. bodyRuneLen := len(bodyRune)
  60. body := string(bodyRune[:bodyRuneLen])
  61. contentSub = body
  62. contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
  63. return
  64. }
  65. //解析文章内容
  66. func GetArticleAll() {
  67. var err error
  68. defer func() {
  69. if err != nil {
  70. fmt.Println("err:", err.Error())
  71. return
  72. }
  73. }()
  74. list, err := models.GetArticleAll()
  75. if err != nil {
  76. return
  77. }
  78. for _, v := range list {
  79. fmt.Println(v.ArticleId, v.Title)
  80. FixArticleContent(v.ArticleId)
  81. }
  82. }
  83. //解析报告
  84. func FixArticleContent(articleId int) {
  85. item, err := models.GetArticleDetailById(articleId)
  86. if err != nil {
  87. fmt.Println("GetArticleDetailById Err:" + err.Error())
  88. return
  89. }
  90. content := item.Body
  91. bodyText, _ := GetReportContentTextSub(content)
  92. content = html.UnescapeString(content)
  93. content = strings.Replace(content, "http", "https", -1)
  94. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  95. if err != nil {
  96. fmt.Println("create doc err:", err.Error())
  97. return
  98. }
  99. var expertNumArr []string
  100. var expertContentArr []string
  101. var interviewDateArr []string
  102. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  103. contentTxt := s.Text()
  104. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  105. interviewDate := s.Next().Text()
  106. interviewDateArr = append(interviewDateArr, interviewDate)
  107. }
  108. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  109. expertContent := s.Next().Text()
  110. if expertContent == "" {
  111. expertContent = contentTxt
  112. }
  113. if expertContent != "" {
  114. rightIndex := strings.Index(expertContent, ")")
  115. if rightIndex == 0 {
  116. rightIndex = strings.Index(expertContent, ")")
  117. }
  118. if rightIndex > 0 {
  119. expertNum := expertContent[:rightIndex]
  120. expertNum = strings.Replace(expertNum, "(", "", -1)
  121. expertNum = strings.Replace(expertNum, "(", "", -1)
  122. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  123. if expertNum != "" {
  124. expertNumArr = append(expertNumArr, expertNum)
  125. rightIndex = rightIndex
  126. expertContentStr := expertContent[rightIndex:]
  127. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  128. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  129. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  130. expertContentArr = append(expertContentArr, expertContentStr)
  131. }
  132. }
  133. }
  134. }
  135. })
  136. if len(expertContentArr) <= 0 {
  137. doc.Find("pre").Each(func(i int, pre *goquery.Selection) {
  138. pre.Find("span").Each(func(n int, span *goquery.Selection) {
  139. contentTxt := span.Text()
  140. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  141. span.Find("span").Each(func(m int, subspan *goquery.Selection) {
  142. subspanText := subspan.Text()
  143. if strings.Contains(subspanText, "专家评价") {
  144. expertContent := subspan.Next().Text()
  145. if expertContent != "" {
  146. rightIndex := strings.Index(expertContent, ")")
  147. if rightIndex == 0 {
  148. rightIndex = strings.Index(expertContent, ")")
  149. }
  150. if rightIndex > 0 {
  151. expertNum := expertContent[:rightIndex]
  152. expertNum = strings.Replace(expertNum, "(", "", -1)
  153. expertNum = strings.Replace(expertNum, "(", "", -1)
  154. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  155. if expertNum != "" {
  156. expertNumArr = append(expertNumArr, expertNum)
  157. rightIndex = rightIndex
  158. expertContentStr := expertContent[rightIndex:]
  159. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  160. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  161. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  162. expertContentArr = append(expertContentArr, expertContentStr)
  163. }
  164. }
  165. }
  166. }
  167. })
  168. }
  169. span.Find("span").Each(func(k int, sspan *goquery.Selection) {
  170. sspanText := sspan.Text()
  171. if strings.Contains(sspanText, "访谈时间") {
  172. sspanText = strings.Replace(sspanText, "#访谈时间:", "", -1)
  173. sspanText = strings.Replace(sspanText, "访谈时间:", "", -1)
  174. sspanText = strings.Replace(sspanText, "\n", "", -1)
  175. sspanText = strings.Replace(sspanText, " ", "", -1)
  176. sspanText = strings.Trim(sspanText, " ")
  177. sspanText = sspanText[:10]
  178. interviewDate := sspanText
  179. if interviewDate != "" {
  180. interviewDateArr = append(interviewDateArr, interviewDate)
  181. }
  182. }
  183. })
  184. })
  185. })
  186. }
  187. if len(expertContentArr) <= 0 {
  188. doc.Find("span").Each(func(i int, span *goquery.Selection) {
  189. span.Find("strong").Each(func(n int, strong *goquery.Selection) {
  190. spanText := span.Text()
  191. strongText := strong.Text()
  192. if strings.Contains(strongText, "#专家评价") || strings.Contains(strongText, "专家评价") {
  193. expertContent := strong.Parents().Text()
  194. if expertContent != "" {
  195. rightIndex := strings.Index(expertContent, ")")
  196. if rightIndex == 0 {
  197. rightIndex = strings.Index(expertContent, ")")
  198. }
  199. if rightIndex > 0 {
  200. expertNum := expertContent[:rightIndex]
  201. expertNum = strings.Replace(expertNum, "(", "", -1)
  202. expertNum = strings.Replace(expertNum, "(", "", -1)
  203. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  204. expertNum = strings.Replace(expertNum, "#", "", -1)
  205. expertNum = strings.Replace(expertNum, ":", "", -1)
  206. expertNum = strings.Replace(expertNum, "\n", "", -1)
  207. if expertNum != "" {
  208. expertNumArr = append(expertNumArr, expertNum)
  209. rightIndex = rightIndex
  210. expertContentStr := expertContent[rightIndex:]
  211. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  212. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  213. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  214. expertContentArr = append(expertContentArr, expertContentStr)
  215. return
  216. }
  217. }
  218. }
  219. }
  220. if strings.Contains(spanText, "访谈时间") {
  221. spanText = strings.Replace(spanText, "#访谈时间:", "", -1)
  222. spanText = strings.Replace(spanText, "访谈时间:", "", -1)
  223. spanText = strings.Replace(spanText, "\n", "", -1)
  224. spanText = strings.Replace(spanText, " ", "", -1)
  225. spanText = strings.Trim(spanText, " ")
  226. spanText = spanText[:10]
  227. interviewDate := spanText
  228. if interviewDate != "" {
  229. interviewDateArr = append(interviewDateArr, interviewDate)
  230. }
  231. }
  232. })
  233. })
  234. }
  235. var expertNumStr, expertContentStr, interviewDateStr string
  236. if len(expertNumArr) > 0 {
  237. expertNumStr = expertNumArr[0]
  238. }
  239. if len(expertContentArr) > 0 {
  240. expertContentStr = expertContentArr[0]
  241. }
  242. if len(interviewDateArr) > 0 {
  243. interviewDateStr = interviewDateArr[0]
  244. }
  245. expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
  246. err = models.ModifyArticleExpert(articleId, expertNumStr, expertContentStr, interviewDateStr, bodyText)
  247. if err != nil {
  248. fmt.Println("ModifyArticleExpert Err:" + err.Error())
  249. return
  250. }
  251. }
  252. func FixArticleImgUrl(body string) (contentSub string, err error) {
  253. r := strings.NewReader(string(body))
  254. doc, err := goquery.NewDocumentFromReader(r)
  255. if err != nil {
  256. fmt.Println(err)
  257. }
  258. doc.Find("img").Each(func(i int, s *goquery.Selection) {
  259. src, _ := s.Attr("src")
  260. if i == 0 && src != "" {
  261. contentSub = src
  262. }
  263. })
  264. return
  265. }
  266. //获取标签里的第一个内容
  267. func FixArticleFirstCount(body string) (contentSub string, err error) {
  268. doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
  269. if err != nil {
  270. fmt.Println("create doc err:", err.Error())
  271. return
  272. }
  273. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  274. contentTxt := s.Text()
  275. fmt.Println(contentTxt)
  276. })
  277. return
  278. }
  279. func SynchronizationArtclehistory() {
  280. fmt.Println("同步开始")
  281. list, err := models.GetArticleHistoryList()
  282. if err != nil {
  283. fmt.Println("获取列表失败", err)
  284. }
  285. fmt.Println(len(list))
  286. for _, v := range list {
  287. //endDate := v.ModifyTime.Add(+time.Minute * 10).Format(utils.FormatDateTime)
  288. //detail, err := models.GetNewArticleHistoryRecordNewpv(v.UserId, v.ArticleId, endDate)
  289. //if err != nil && err.Error() != utils.ErrNoRow() {
  290. // fmt.Println("获取信息失败", err)
  291. //}
  292. v.OutType = 1
  293. //fmt.Println(v.Id)
  294. //if detail == nil {
  295. // _, err = models.AddCygxArticleViewRecordNewpv(v)
  296. // if err != nil {
  297. // fmt.Println("新增失败", err)
  298. // }
  299. //} else {
  300. // err = models.UpdateCygxArticleViewRecordNewpvList(v, v.StopTime)
  301. // if err != nil {
  302. // fmt.Println("修改失败", err)
  303. // }
  304. //}
  305. newId, err := models.AddCygxArticleViewRecordNewpv(v)
  306. fmt.Println("新增", newId)
  307. if err != nil {
  308. fmt.Println("新增失败", err)
  309. }
  310. }
  311. fmt.Println("同步结束")
  312. }
  313. //统计报表
  314. func StatisticalReport() {
  315. var isSummaryNumAll, isClassNum, pvNumAll, uvNumAll int
  316. list, err := models.GetChartPermissionActivity()
  317. if err != nil {
  318. fmt.Println("获取列表失败", err)
  319. }
  320. for _, v := range list {
  321. var listPv []*models.ReportMappingStatistical
  322. if v.PermissionName == "研选" {
  323. listPv, err = models.GetStatisticalReportArtilceExpert()
  324. if err != nil {
  325. fmt.Println("获取Pv列表失败", err)
  326. }
  327. } else {
  328. listPv, err = models.GetStatisticalReportArtilce(v.ChartPermissionId)
  329. if err != nil {
  330. fmt.Println("获取Pv列表失败", err)
  331. }
  332. }
  333. var pvNum, uvNum, isSummaryNum int
  334. for _, v2 := range listPv {
  335. pvNum += v2.Pv
  336. uvNum += v2.Uv
  337. if v2.IsSummary == "1" {
  338. isSummaryNum += 1
  339. }
  340. if v2.IsClass == "1" && v.ChartPermissionId <= 22 {
  341. isClassNum += 1
  342. }
  343. if v2.IsSummary == "1" && v.ChartPermissionId <= 22 {
  344. isSummaryNumAll += 1
  345. }
  346. }
  347. if v.ChartPermissionId <= 22 {
  348. pvNumAll += pvNum
  349. uvNumAll += uvNum
  350. }
  351. fmt.Println(v.PermissionName+"行业", len(listPv), "篇,其中主观类报告", isSummaryNum, "篇,客观类报告", len(listPv)-isSummaryNum, "篇。共产生阅读量pv-,", pvNum, ",uv-", uvNum)
  352. }
  353. fmt.Println("目前同步四大行业的总报告(已归类)数量", isClassNum, "篇,其中主观类报告", isSummaryNumAll, "篇,客观类报告", isClassNum-isSummaryNumAll, "篇。共产生阅读量pv-", pvNumAll, ",uv-", uvNumAll)
  354. var totalOnline int //线上
  355. var totalOffline int //线下
  356. var totalPeople int //共累计预约外呼人数
  357. var totalSignUpOff int //线下报名人数
  358. var totalSignUpOffTime int //线下报名人数
  359. var totalPeopleMeet int //线下参会人数
  360. o := orm.NewOrm()
  361. sql := `SELECT COUNT(1) FROM cygx_activity WHERE activity_type_id IN (1,2,3) AND publish_status = 1 AND is_submit_meeting = 1 AND activity_time <= NOW();`
  362. err = o.Raw(sql).QueryRow(&totalOnline)
  363. if err != nil {
  364. fmt.Println("获取线上", err)
  365. }
  366. sql = `SELECT COUNT(1) FROM cygx_activity WHERE activity_type_id IN (4,5,6) AND publish_status = 1 AND is_submit_meeting = 1 AND activity_time <= NOW();`
  367. err = o.Raw(sql).QueryRow(&totalOffline)
  368. if err != nil {
  369. fmt.Println("获取线下", err)
  370. }
  371. sql = `SELECT COUNT( 1 ) FROM
  372. cygx_activity_signup as s
  373. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  374. WHERE
  375. s.do_fail_type = 0
  376. AND a.is_submit_meeting = 1
  377. AND a.activity_time <= NOW()
  378. AND a.publish_status = 1`
  379. err = o.Raw(sql).QueryRow(&totalPeople)
  380. if err != nil {
  381. fmt.Println("共累计预约外呼人数", err)
  382. }
  383. sql = `SELECT COUNT( 1 ) FROM
  384. cygx_activity_signup as s
  385. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  386. WHERE
  387. s.do_fail_type = 0
  388. AND a.is_submit_meeting = 1
  389. AND a.activity_time <= NOW()
  390. AND a.activity_type_id IN (4,5,6)
  391. AND a.publish_status = 1`
  392. err = o.Raw(sql).QueryRow(&totalSignUpOff)
  393. if err != nil {
  394. fmt.Println("共累计预约外呼人数", err)
  395. }
  396. sql = `SELECT COUNT( 1 ) FROM
  397. cygx_activity_signup as s
  398. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  399. WHERE
  400. s.do_fail_type = 0
  401. AND a.publish_status = 1
  402. AND a.is_submit_meeting = 1
  403. AND a.activity_time <= NOW()
  404. AND a.is_submit_meeting = 1
  405. AND a.activity_type_id IN (4,5,6);`
  406. err = o.Raw(sql).QueryRow(&totalSignUpOffTime)
  407. if err != nil {
  408. fmt.Println("线下报名参会人数", err)
  409. }
  410. sql = `SELECT COUNT( 1 ) FROM
  411. cygx_activity_signup as s
  412. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  413. WHERE
  414. s.do_fail_type = 0
  415. AND a.is_submit_meeting = 1
  416. AND a.activity_time <= NOW()
  417. AND a.publish_status = 1
  418. AND s.is_meeting = 1
  419. AND a.activity_type_id IN (4,5,6);`
  420. err = o.Raw(sql).QueryRow(&totalPeopleMeet)
  421. if err != nil {
  422. fmt.Println("线下参会人数", err)
  423. }
  424. fmt.Println("共上线活动", totalOnline+totalOffline, "个,其中线上", totalOnline, "个,线下", totalOffline, "个")
  425. fmt.Println("共累计预约外呼人数", totalPeople, "人")
  426. fmt.Println("报名线下参会", totalSignUpOff, "人,实际到会人数", totalPeopleMeet, "人,线下到会率约", totalPeopleMeet*100/totalSignUpOff, "%")
  427. num := totalPeopleMeet / totalSignUpOffTime
  428. fmt.Println(num)
  429. fmt.Println(totalOnline)
  430. fmt.Println(totalOffline)
  431. fmt.Println(totalPeople)
  432. fmt.Println(totalSignUpOff)
  433. fmt.Println(totalPeopleMeet)
  434. fmt.Println(totalSignUpOffTime)
  435. fmt.Println(totalPeopleMeet / totalSignUpOffTime)
  436. return
  437. }
  438. // UserViewRedisData 阅读数据
  439. type UserViewRedisData struct {
  440. Mobile string `json:"mobile"`
  441. Email string `json:"email"`
  442. RealName string `json:"real_name"`
  443. CompanyName string `json:"company_name"`
  444. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  445. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  446. CompanyId int `json:"company_id" description:"客户id"`
  447. }
  448. type ReportViewRecord struct {
  449. Id int `orm:"column(id);pk"`
  450. UserId int `description:"用户id"`
  451. ReportId int `description:"报告id"`
  452. Mobile string `description:"手机号"`
  453. Email string `description:"邮箱"`
  454. RealName string `description:"用户实际姓名"`
  455. CompanyName string `description:"公司名称"`
  456. CreateTime time.Time `description:"创建时间"`
  457. }
  458. // PushViewRecordNewRedisData 阅读数据加入到redis
  459. func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
  460. data := &UserViewRedisData{
  461. Mobile: reportViewRecord.Mobile,
  462. Email: reportViewRecord.Email,
  463. RealName: reportViewRecord.RealName,
  464. CompanyName: reportViewRecord.CompanyName,
  465. ViewTime: reportViewRecord.CreateTime.Format(utils.FormatDateTime),
  466. ProductId: 2,
  467. CompanyId: companyId,
  468. }
  469. if utils.Re == nil {
  470. err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
  471. if err != nil {
  472. fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
  473. }
  474. return true
  475. }
  476. return false
  477. }
  478. //func GetCeLueArticlePv() {
  479. // sum := 0
  480. // for i := 0; i <= 450; i++ {
  481. // if i >= 102 {
  482. // //GetCeLueArticlePvs(strconv.Itoa(i * 1000))
  483. // }
  484. // }
  485. // fmt.Println(sum)
  486. //}
  487. //获取策略平台报告阅读数据
  488. func GetCeLueArticlePv(cont context.Context) (err error) {
  489. defer func() {
  490. if err != nil {
  491. go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
  492. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  493. }
  494. }()
  495. startTime := time.Now().Add(-time.Minute * 12).Format("2006-01-02 15:04:05")
  496. endTime := time.Now().Format("2006-01-02 15:04:05")
  497. requestUrl := utils.ApiUrl + "backend/statistics_access?take=1000&skip=0&sort=ASC&mode=all&"
  498. encodeData := url.Values{}
  499. encodeData.Add("start_dt", startTime)
  500. encodeData.Add("end_dt", endTime)
  501. encodeStr := encodeData.Encode()
  502. requestUrl += encodeStr
  503. authorization := utils.ApiAuthorization
  504. body, err := PublicGetDate(requestUrl, authorization)
  505. if err != nil {
  506. return
  507. }
  508. var chartResult models.CeLueArticleResultApi
  509. err = json.Unmarshal(body, &chartResult)
  510. if err != nil {
  511. fmt.Println(err)
  512. return err
  513. }
  514. mapMobileArticleId := make(map[string]int)
  515. //获取当天阅读记录
  516. listPv, err := models.GetArticleHistoryRecordAllList()
  517. if err != nil && err.Error() != utils.ErrNoRow() {
  518. fmt.Println("获取当天阅读记录失败", err)
  519. return err
  520. }
  521. if len(listPv) > 0 {
  522. for _, v := range listPv {
  523. mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
  524. }
  525. }
  526. for _, v := range chartResult.Data {
  527. //fmt.Println(v.ArticleId)
  528. item := new(models.CygxCelueArticleHistoryRecord)
  529. item.CelueHistoryId = v.CelueHistoryId
  530. item.Mobile = v.Mobile
  531. item.ArticleId = v.ArticleId
  532. if v.CrmUser != nil {
  533. item.RealName = v.CrmUser.RealName
  534. }
  535. if v.CompanyName != nil {
  536. item.CompanyName = v.CompanyName.RealName
  537. }
  538. item.CreateDateApi = time.Now()
  539. t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
  540. item.CreateTime = t1.Add(+time.Hour * 8).Format(utils.FormatDateTime)
  541. count, err := models.GetCeLueArticleCountById(v.CelueHistoryId)
  542. if err != nil && err.Error() != utils.ErrNoRow() {
  543. return err
  544. }
  545. if count == 0 {
  546. _, err := models.AddCeLueArticle(item, mapMobileArticleId)
  547. if err != nil {
  548. fmt.Println(err)
  549. return err
  550. }
  551. }
  552. }
  553. //处理同步过来的阅读记录所属用户
  554. var condition string
  555. condition = ` AND create_time > ` + "'" + startTime + "'"
  556. listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
  557. if err != nil {
  558. fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
  559. }
  560. for _, v := range listArticlePv {
  561. if v.Mobile != "" {
  562. user, err := models.GetWxUserItemByMobile(v.Mobile)
  563. if err != nil && err.Error() != utils.ErrNoRow() {
  564. fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  565. }
  566. if user != nil {
  567. err = models.UpdateCygxArticleHistoryRecordAll(user)
  568. if err != nil {
  569. fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
  570. }
  571. }
  572. }
  573. }
  574. return
  575. }
  576. func GetArticleListByApi(cont context.Context) (err error) {
  577. defer func() {
  578. if err != nil {
  579. //fmt.Println("GetArticleListByApi Err:" + err.Error())
  580. go utils.SendAlarmMsg("同步策略平台数据失败", 2)
  581. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  582. }
  583. }()
  584. listUpdateArticle, err := models.GetArticleCeluePushList()
  585. if err != nil && err.Error() != utils.ErrNoRow() {
  586. return err
  587. }
  588. //如果长度为零就不处理
  589. if len(listUpdateArticle) == 0 {
  590. return err
  591. }
  592. for _, v := range listUpdateArticle {
  593. // 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
  594. err = HandleArticleListByApi(v.ArticleId, v.Id)
  595. if err != nil {
  596. utils.FileLog.Info("WxGetToken Result:%s ", err.Error())
  597. }
  598. }
  599. return
  600. }
  601. //处理同步过来的文章
  602. func HandleArticleListByApi(artcleId, celuePushId int) (err error) {
  603. defer func() {
  604. if err != nil {
  605. go utils.SendAlarmMsg("处理同步策略平台数据失败"+"GetArticleListByApi ErrMsg:"+err.Error(), 2)
  606. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  607. }
  608. }()
  609. var clueApiUrl string
  610. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
  611. fmt.Println(clueApiUrl)
  612. authorization := utils.ApiAuthorization
  613. body, err := PublicGetDate(clueApiUrl, authorization)
  614. if err != nil {
  615. fmt.Println(err)
  616. return
  617. }
  618. var articleResultDate models.ArticleDetailResultApi
  619. err = json.Unmarshal(body, &articleResultDate)
  620. if err != nil {
  621. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  622. return err
  623. }
  624. articleResult := articleResultDate.Data
  625. exitMap := make(map[int]int)
  626. classMap := make(map[int]int)
  627. reportMap := make(map[int]int)
  628. summaryMap := make(map[int]int)
  629. listMap, err := models.GetArticleApiMap()
  630. if err != nil {
  631. fmt.Println("GetlistMap Err:", err.Error())
  632. return err
  633. }
  634. openIdList, err := models.GetUserRecordListByMobile(4, utils.ArticleTaskClassMobile)
  635. if err != nil {
  636. fmt.Println(err)
  637. return err
  638. }
  639. fmt.Println(openIdList)
  640. //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
  641. for _, v := range listMap {
  642. exitMap[v.Id] = v.OldId
  643. if v.IsClass == 1 {
  644. classMap[v.OldId] = 1
  645. }
  646. if v.IsReport == 1 {
  647. reportMap[v.OldId] = 1
  648. }
  649. if v.IsSummary == 1 {
  650. summaryMap[v.OldId] = 1
  651. }
  652. }
  653. var list []*models.Tactics2
  654. var listAuthor []*models.CygxArticleAuthor
  655. //状态等于 2 跟 4 的进行同步
  656. if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) {
  657. articleResult.PublishDate = time.Date(articleResult.PublishDate.Year(), articleResult.PublishDate.Month(), articleResult.PublishDate.Day(), articleResult.PublishDate.Hour(), articleResult.PublishDate.Minute(), articleResult.PublishDate.Second(), articleResult.PublishDate.Nanosecond(), time.Local)
  658. item := new(models.Tactics2)
  659. itemAuthor := new(models.CygxArticleAuthor)
  660. item.ArticleId = articleResult.ArticleId
  661. item.Title = articleResult.Title
  662. item.TitleEn = articleResult.TitleEn
  663. item.File = articleResult.File
  664. if articleResult.Frequency == "日度" {
  665. item.UpdateFrequency = "daily"
  666. } else if articleResult.Frequency == "周度" {
  667. item.UpdateFrequency = "weekly"
  668. } else if articleResult.Frequency == "月度" {
  669. item.UpdateFrequency = "monthly"
  670. } else if articleResult.Frequency == "季度" {
  671. item.UpdateFrequency = "quarterly"
  672. } else if articleResult.Frequency == "年度" {
  673. item.UpdateFrequency = "yearly"
  674. } else {
  675. item.UpdateFrequency = "unknow"
  676. }
  677. item.CreateDate = articleResult.CreateDate
  678. item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
  679. item.PublishStatus = 1
  680. item.Body = articleResult.Content.Body
  681. item.Abstract = articleResult.Content.Abstract
  682. item.CategoryName = articleResult.Industry.Name
  683. item.CategoryId = exitMap[articleResult.SeriesId]
  684. item.SubCategoryName = articleResult.Series.Name
  685. if len(articleResult.Stock) > 0 {
  686. var stock string
  687. for _, vS := range articleResult.Stock {
  688. stock += vS + "/"
  689. }
  690. stock = strings.TrimRight(stock, "/")
  691. item.Stock = stock
  692. }
  693. item.FieldName = articleResult.Field.Name
  694. list = append(list, item)
  695. itemAuthor.ArticleId = articleResult.ArticleId
  696. itemAuthor.Name = articleResult.Author.Name
  697. itemAuthor.Mobile = articleResult.Author.PhoneNumber
  698. listAuthor = append(listAuthor, itemAuthor)
  699. } else {
  700. // 如果这篇文章没有发布,那么就不作处理。
  701. err = models.UpdateArticlePublish(0, artcleId)
  702. if err != nil {
  703. fmt.Println("UpdateArticlePublish Err:", err.Error())
  704. return err
  705. }
  706. go models.UpdateCygxArticleCeluePush(celuePushId)
  707. return err
  708. }
  709. //同步作者
  710. for _, v := range listAuthor {
  711. var count int
  712. count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  713. if err != nil {
  714. fmt.Println("GetActivityAuthorCount Err:", err.Error())
  715. return err
  716. }
  717. if count == 0 {
  718. _, err = models.AddCygxActivityAuthor(v)
  719. if err != nil {
  720. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  721. return err
  722. }
  723. }
  724. }
  725. fmt.Println("同步文章条数:", len(list))
  726. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  727. if err != nil {
  728. fmt.Println("GetTacticsList Err:", err.Error())
  729. return err
  730. }
  731. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  732. if errMatch != nil {
  733. fmt.Println("GetTacticsList Err:", errMatch.Error())
  734. return err
  735. }
  736. fmt.Println("list len:", len(list))
  737. noSummaryArticleIds := "3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470" //非纪要库类型的文章ID
  738. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  739. for k, v := range list {
  740. //同步匹配类型
  741. matchTypeName := ""
  742. for _, vMatch := range listGetMatchTypeName {
  743. if v.CategoryId == vMatch.CategoryId {
  744. matchTypeName = vMatch.MatchTypeName
  745. }
  746. }
  747. //是否属于纪要库的数据
  748. if _, has := summaryMap[v.CategoryId]; has {
  749. v.IsSummary = 1
  750. }
  751. //排除不属于纪要库类型的文章
  752. for _, vArt := range listNoSummaryArticleIds {
  753. vArtInt, _ := strconv.Atoi(vArt)
  754. if v.ArticleId == vArtInt {
  755. v.IsSummary = 0
  756. }
  757. }
  758. if _, has := reportMap[v.CategoryId]; has {
  759. v.IsReport = 1
  760. if _, ok := classMap[v.CategoryId]; ok {
  761. v.IsClass = 1
  762. v.ReportType = 1 //是否属于行业报告
  763. } else {
  764. v.ReportType = 2 //是否属于产业报告
  765. }
  766. }
  767. v.Department = "弘则权益研究"
  768. //判断是否已经存在
  769. if v.ArticleId < 0 {
  770. fmt.Println("AddCygxArticle Err:")
  771. return err
  772. }
  773. var count int
  774. count, err = models.GetArticleCountById(v.ArticleId)
  775. if err != nil && err.Error() != utils.ErrNoRow() {
  776. fmt.Println("AddCygxArticle Err:", err.Error())
  777. return err
  778. }
  779. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  780. expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
  781. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  782. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  783. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  784. v.Body = strings.Replace(v.Body, "):", "", -1)
  785. }
  786. var titleNew string
  787. titleNew = v.Title
  788. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  789. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  790. if v.UpdateFrequency == "daily" {
  791. var daystr string
  792. daystr = strconv.Itoa(v.PublishDate.Day())
  793. if len(daystr) == 1 {
  794. daystr = "0" + daystr
  795. }
  796. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  797. } else if v.UpdateFrequency == "weekly" {
  798. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  799. }
  800. }
  801. if v.CategoryId == 80 {
  802. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  803. }
  804. if count > 0 {
  805. fmt.Println(k, v.ArticleId, "edit")
  806. var isCustom bool
  807. bodyText, _ := GetReportContentTextSub(v.Body)
  808. updateParams := make(map[string]interface{})
  809. //updateParams["Title"] = v.Title
  810. updateParams["Title"] = titleNew
  811. updateParams["TitleEn"] = v.TitleEn
  812. updateParams["UpdateFrequency"] = v.UpdateFrequency
  813. updateParams["CreateDate"] = v.CreateDate
  814. updateParams["PublishDate"] = v.PublishDate
  815. //updateParams["Body"] = html.EscapeString(v.Body)
  816. updateParams["Body"] = html.EscapeString(bodyReturn)
  817. updateParams["BodyText"] = bodyText
  818. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  819. updateParams["CategoryName"] = v.CategoryName
  820. for _, vCustom := range listCustomArticle {
  821. if v.ArticleId == vCustom.ArticleId {
  822. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  823. isCustom = true
  824. }
  825. }
  826. if isCustom == false {
  827. updateParams["CategoryId"] = v.CategoryId
  828. updateParams["MatchTypeName"] = matchTypeName
  829. updateParams["IsSummary"] = v.IsSummary
  830. updateParams["IsReport"] = v.IsReport
  831. updateParams["ReportType"] = v.ReportType
  832. updateParams["SubCategoryName"] = v.SubCategoryName
  833. }
  834. //updateParams["CategoryId"] = v.CategoryId
  835. updateParams["PublishStatus"] = 1
  836. updateParams["ExpertBackground"] = expertContentStr
  837. updateParams["ExpertNumber"] = expertNumStr
  838. updateParams["InterviewDate"] = interviewDateStr
  839. //updateParams["IsClass"] = v.IsClass
  840. v.Department = "弘则权益研究"
  841. updateParams["Department"] = v.Department
  842. updateParams["FileLink"] = v.File
  843. updateParams["Stock"] = v.Stock
  844. updateParams["FieldName"] = v.FieldName
  845. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  846. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  847. if err != nil {
  848. fmt.Println("UpdateByExpr Err:" + err.Error())
  849. return err
  850. }
  851. } else {
  852. fmt.Println(k, v.ArticleId, "add")
  853. item := new(models.CygxArticle)
  854. articleIdInt := v.ArticleId
  855. item.ArticleId = articleIdInt
  856. //item.Title = v.Title
  857. item.Title = titleNew
  858. item.TitleEn = v.TitleEn
  859. item.UpdateFrequency = v.UpdateFrequency
  860. item.CreateDate = v.CreateDate
  861. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  862. //item.Body = html.EscapeString(v.Body)
  863. item.Body = html.EscapeString(bodyReturn)
  864. item.Abstract = html.EscapeString(v.Abstract)
  865. item.CategoryName = v.CategoryName
  866. item.SubCategoryName = v.SubCategoryName
  867. item.CategoryId = v.CategoryId
  868. item.CategoryIdTwo = v.CategoryId
  869. item.PublishStatus = 1
  870. item.ExpertBackground = expertContentStr
  871. item.ExpertNumber = expertNumStr
  872. item.InterviewDate = interviewDateStr
  873. item.Department = v.Department
  874. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  875. item.IsClass = v.IsClass
  876. item.IsSummary = v.IsSummary
  877. item.IsReport = v.IsReport
  878. item.ReportType = v.ReportType
  879. item.FileLink = v.File
  880. item.MatchTypeName = matchTypeName
  881. item.Stock = v.Stock
  882. item.FieldName = v.FieldName
  883. newId, err := models.AddCygxArticles(item)
  884. if err != nil {
  885. fmt.Println("AddCygxArticle Err:", err.Error())
  886. return err
  887. }
  888. //fmt.Println(newId)
  889. //报告自动归类,以及推送相关模板消息
  890. if v.ReportType == 2 {
  891. var subjectStr string
  892. var industrialManagementIdStr string
  893. var industrialSubjectIdStr string
  894. var keyword1 string
  895. var keyword2 string
  896. var keyword3 string
  897. var keyword4 string
  898. sliceSubjects := strings.Split(v.Stock, "/")
  899. mapManagementForSubject := make(map[string]string)
  900. if len(sliceSubjects) > 0 {
  901. for _, vSubject := range sliceSubjects {
  902. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  903. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  904. subject := sliceXiahuaxian[0]
  905. subjectStr += "'" + subject + "',"
  906. }
  907. //获取该产业下所对应的行业图片
  908. detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
  909. if errCategory != nil {
  910. fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
  911. return err
  912. }
  913. subjectStr = strings.TrimRight(subjectStr, ",")
  914. if subjectStr != "" {
  915. listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
  916. if err != nil {
  917. fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
  918. return err
  919. }
  920. subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
  921. subjectStr = strings.Replace(subjectStr, "'", "", -1)
  922. subjectStr = "【" + subjectStr + "】"
  923. if len(listIndustrial) > 0 {
  924. for _, vIndustrial := range listIndustrial {
  925. industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
  926. industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
  927. mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
  928. }
  929. industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
  930. industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
  931. if industrialManagementIdStr != "" {
  932. err = models.ReportArticleClassificationEditNew(int(newId), industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
  933. if err != nil {
  934. fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
  935. return err
  936. }
  937. }
  938. var peoductName string
  939. for mk, mv := range mapManagementForSubject {
  940. peoductName += "【" + mk + "--" + strings.TrimRight(mv, "/") + "】"
  941. }
  942. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  943. keyword2 = "已自动关联至以下产业和标的:" + peoductName
  944. keyword3 = v.Title
  945. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  946. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  947. } else {
  948. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  949. keyword2 = "未归类"
  950. keyword3 = v.Title
  951. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  952. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  953. }
  954. }
  955. }
  956. }
  957. }
  958. //类型ID 医药(医享会:28 、药调研:301)、消费【渠道新声:32】、科技【科技前言:79】、智造【匠心智造:84】或者是纪要做消息模板推送
  959. fmt.Println(v.CategoryId)
  960. if v.IsSummary == 1 || (v.CategoryId == 28 || v.CategoryId == 301 || v.CategoryId == 32 || v.CategoryId == 79 || v.CategoryId == 84) {
  961. sliceSubjects := strings.Split(v.Stock, "/")
  962. fmt.Println(sliceSubjects)
  963. if len(sliceSubjects) > 0 {
  964. var subjectStr string
  965. for _, vSubject := range sliceSubjects {
  966. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  967. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  968. subject := sliceXiahuaxian[0]
  969. subjectStr += "'" + subject + "',"
  970. }
  971. if subjectStr != "" {
  972. subjectStr = strings.TrimRight(subjectStr, ",")
  973. activityIdList, err := models.GetActivityIdListBySubjecName(subjectStr)
  974. if err != nil {
  975. fmt.Println("GetActivityIdListBySubjecName Err:", err.Error())
  976. return err
  977. }
  978. if len(activityIdList) > 0 {
  979. var activityIdStr string
  980. for _, vAct := range activityIdList {
  981. activityIdStr += strconv.Itoa(vAct.ActivityId) + ","
  982. }
  983. activityIdStr = strings.TrimRight(activityIdStr, ",")
  984. if activityIdStr != "" {
  985. appointmentList, err := models.GetAppointmentListByActivityId(activityIdStr, "1,2,5")
  986. if err != nil {
  987. fmt.Println("GetAppointmentListByActivityId Err:", err.Error())
  988. return err
  989. }
  990. if len(appointmentList) > 0 {
  991. for _, vApp := range appointmentList {
  992. appointmentByMobileList, err := models.GetAppointmentListByActivityIdAndMobile(activityIdStr, vApp.Mobile)
  993. if err != nil {
  994. fmt.Println("GetAppointmentListByActivityId Err:", err.Error())
  995. return err
  996. }
  997. var appointmentActivityName string
  998. if len(appointmentByMobileList) > 0 {
  999. for _, vAppM := range appointmentByMobileList {
  1000. appointmentActivityName += vAppM.ActivityName + ","
  1001. }
  1002. }
  1003. appointmentActivityName = strings.TrimRight(appointmentActivityName, ",")
  1004. if vApp.ActivityTypeId == 5 && v.CategoryId != 301 {
  1005. continue
  1006. }
  1007. if vApp.Mobile != "" {
  1008. openIdListByAppointment, err := models.GetUserRecordListByMobile(4, vApp.Mobile)
  1009. if err != nil {
  1010. fmt.Println(err)
  1011. return err
  1012. }
  1013. keyword1 := "您预约的调研,有关联的纪要发布/更新了"
  1014. keyword2 := appointmentActivityName
  1015. keyword3 := v.Title
  1016. keyword4 := v.PublishDate.Format(utils.FormatDateTime)
  1017. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdListByAppointment, artcleId)
  1018. }
  1019. }
  1020. }
  1021. }
  1022. }
  1023. }
  1024. }
  1025. }
  1026. //【公司调研】系列纪要发布/更新后
  1027. if v.CategoryId == 45 || v.CategoryId == 74 || v.CategoryId == 86 || v.CategoryId == 88 {
  1028. fmt.Println("处理预约纪要")
  1029. sliceSubjects := strings.Split(v.Stock, "/")
  1030. if len(sliceSubjects) > 0 {
  1031. var subjectStr string
  1032. for _, vSubject := range sliceSubjects {
  1033. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  1034. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  1035. subject := sliceXiahuaxian[0]
  1036. subjectStr += "'" + subject + "',"
  1037. }
  1038. if subjectStr != "" {
  1039. subjectStr = strings.TrimRight(subjectStr, ",")
  1040. activityIdList, err := models.GetActivityIdListBySubjecName(subjectStr)
  1041. if err != nil {
  1042. fmt.Println("GetActivityIdListBySubjecName Err:", err.Error())
  1043. return err
  1044. }
  1045. if len(activityIdList) > 0 {
  1046. var activityIdStr string
  1047. for _, vAct := range activityIdList {
  1048. activityIdStr += strconv.Itoa(vAct.ActivityId) + ","
  1049. }
  1050. activityIdStr = strings.TrimRight(activityIdStr, ",")
  1051. if activityIdStr != "" {
  1052. appointmentList, err := models.GetAppointmentListByActivityId(activityIdStr, "3,4")
  1053. if err != nil {
  1054. fmt.Println("GetAppointmentListByActivityId Err:", err.Error())
  1055. return err
  1056. }
  1057. if len(appointmentList) > 0 {
  1058. for _, vApp := range appointmentList {
  1059. appointmentByMobileList, err := models.GetAppointmentListByActivityIdAndMobile(activityIdStr, vApp.Mobile)
  1060. if err != nil {
  1061. fmt.Println("GetAppointmentListByActivityId Err:", err.Error())
  1062. return err
  1063. }
  1064. var appointmentActivityName string
  1065. if len(appointmentByMobileList) > 0 {
  1066. for _, vAppM := range appointmentByMobileList {
  1067. appointmentActivityName += vAppM.ActivityName + ","
  1068. }
  1069. }
  1070. appointmentActivityName = strings.TrimRight(appointmentActivityName, ",")
  1071. if vApp.Mobile != "" {
  1072. openIdListByAppointment, err := models.GetUserRecordListByMobile(4, vApp.Mobile)
  1073. if err != nil {
  1074. fmt.Println(err)
  1075. return err
  1076. }
  1077. keyword1 := "您预约的调研,有关联的纪要发布/更新了"
  1078. keyword2 := appointmentActivityName
  1079. keyword3 := v.Title
  1080. keyword4 := v.PublishDate.Format(utils.FormatDateTime)
  1081. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdListByAppointment, artcleId)
  1082. }
  1083. }
  1084. }
  1085. }
  1086. }
  1087. }
  1088. }
  1089. }
  1090. //【公司调研】系列纪要发布/更新后 end
  1091. }
  1092. go models.UpdateCygxArticleCeluePush(celuePushId)
  1093. return err
  1094. }