article.go 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  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 HandleArticleListByApi(v.ArticleId, v.Id)
  594. }
  595. return
  596. }
  597. //处理同步过来的文章
  598. func HandleArticleListByApi(artcleId, celuePushId int) (err error) {
  599. defer func() {
  600. if err != nil {
  601. go utils.SendAlarmMsg("处理同步策略平台数据失败", 2)
  602. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  603. }
  604. }()
  605. var clueApiUrl string
  606. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
  607. fmt.Println(clueApiUrl)
  608. authorization := utils.ApiAuthorization
  609. body, err := PublicGetDate(clueApiUrl, authorization)
  610. if err != nil {
  611. fmt.Println(err)
  612. return
  613. }
  614. var articleResultDate models.ArticleDetailResultApi
  615. err = json.Unmarshal(body, &articleResultDate)
  616. if err != nil {
  617. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  618. return err
  619. }
  620. articleResult := articleResultDate.Data
  621. exitMap := make(map[int]int)
  622. classMap := make(map[int]int)
  623. reportMap := make(map[int]int)
  624. summaryMap := make(map[int]int)
  625. listMap, err := models.GetArticleApiMap()
  626. if err != nil {
  627. fmt.Println("GetlistMap Err:", err.Error())
  628. return err
  629. }
  630. openIdList, err := models.GetUserRecordListByMobile(4, utils.ArticleTaskClassMobile)
  631. if err != nil {
  632. fmt.Println(err)
  633. return err
  634. }
  635. fmt.Println(openIdList)
  636. //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
  637. for _, v := range listMap {
  638. exitMap[v.Id] = v.OldId
  639. if v.IsClass == 1 {
  640. classMap[v.OldId] = 1
  641. }
  642. if v.IsReport == 1 {
  643. reportMap[v.OldId] = 1
  644. }
  645. if v.IsSummary == 1 {
  646. summaryMap[v.OldId] = 1
  647. }
  648. }
  649. var list []*models.Tactics2
  650. var listAuthor []*models.CygxArticleAuthor
  651. //状态等于 2 跟 4 的进行同步
  652. if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) {
  653. 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)
  654. item := new(models.Tactics2)
  655. itemAuthor := new(models.CygxArticleAuthor)
  656. item.ArticleId = articleResult.ArticleId
  657. item.Title = articleResult.Title
  658. item.TitleEn = articleResult.TitleEn
  659. item.File = articleResult.File
  660. if articleResult.Frequency == "日度" {
  661. item.UpdateFrequency = "daily"
  662. } else if articleResult.Frequency == "周度" {
  663. item.UpdateFrequency = "weekly"
  664. } else if articleResult.Frequency == "月度" {
  665. item.UpdateFrequency = "monthly"
  666. } else if articleResult.Frequency == "季度" {
  667. item.UpdateFrequency = "quarterly"
  668. } else if articleResult.Frequency == "年度" {
  669. item.UpdateFrequency = "yearly"
  670. } else {
  671. item.UpdateFrequency = "unknow"
  672. }
  673. item.CreateDate = articleResult.CreateDate
  674. item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
  675. item.PublishStatus = 1
  676. item.Body = articleResult.Content.Body
  677. item.Abstract = articleResult.Content.Abstract
  678. item.CategoryName = articleResult.Industry.Name
  679. item.CategoryId = exitMap[articleResult.SeriesId]
  680. item.SubCategoryName = articleResult.Series.Name
  681. if len(articleResult.Stock) > 0 {
  682. var stock string
  683. for _, vS := range articleResult.Stock {
  684. stock += vS + "/"
  685. }
  686. stock = strings.TrimRight(stock, "/")
  687. item.Stock = stock
  688. }
  689. item.FieldName = articleResult.Field.Name
  690. list = append(list, item)
  691. itemAuthor.ArticleId = articleResult.ArticleId
  692. itemAuthor.Name = articleResult.Author.Name
  693. itemAuthor.Mobile = articleResult.Author.PhoneNumber
  694. listAuthor = append(listAuthor, itemAuthor)
  695. } else {
  696. // 如果这篇文章没有发布,那么就不作处理。
  697. err = models.UpdateArticlePublish(0, artcleId)
  698. if err != nil {
  699. fmt.Println("UpdateArticlePublish Err:", err.Error())
  700. return err
  701. }
  702. return err
  703. go models.UpdateCygxArticleCeluePush(celuePushId)
  704. }
  705. //同步作者
  706. for _, v := range listAuthor {
  707. var count int
  708. count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  709. if err != nil {
  710. fmt.Println("GetActivityAuthorCount Err:", err.Error())
  711. return err
  712. }
  713. if count == 0 {
  714. _, err = models.AddCygxActivityAuthor(v)
  715. if err != nil {
  716. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  717. return err
  718. }
  719. }
  720. }
  721. fmt.Println("同步文章条数:", len(list))
  722. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  723. if err != nil {
  724. fmt.Println("GetTacticsList Err:", err.Error())
  725. return err
  726. }
  727. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  728. if errMatch != nil {
  729. fmt.Println("GetTacticsList Err:", errMatch.Error())
  730. return err
  731. }
  732. fmt.Println("list len:", len(list))
  733. 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
  734. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  735. for k, v := range list {
  736. //同步匹配类型
  737. matchTypeName := ""
  738. for _, vMatch := range listGetMatchTypeName {
  739. if v.CategoryId == vMatch.CategoryId {
  740. matchTypeName = vMatch.MatchTypeName
  741. }
  742. }
  743. //是否属于纪要库的数据
  744. if _, has := summaryMap[v.CategoryId]; has {
  745. v.IsSummary = 1
  746. }
  747. //排除不属于纪要库类型的文章
  748. for _, vArt := range listNoSummaryArticleIds {
  749. vArtInt, _ := strconv.Atoi(vArt)
  750. if v.ArticleId == vArtInt {
  751. v.IsSummary = 0
  752. }
  753. }
  754. if _, has := reportMap[v.CategoryId]; has {
  755. v.IsReport = 1
  756. if _, ok := classMap[v.CategoryId]; ok {
  757. v.IsClass = 1
  758. v.ReportType = 1 //是否属于行业报告
  759. } else {
  760. v.ReportType = 2 //是否属于产业报告
  761. }
  762. }
  763. v.Department = "弘则权益研究"
  764. //判断是否已经存在
  765. if v.ArticleId < 0 {
  766. fmt.Println("AddCygxArticle Err:")
  767. return err
  768. }
  769. var count int
  770. count, err = models.GetArticleCountById(v.ArticleId)
  771. if err != nil && err.Error() != utils.ErrNoRow() {
  772. fmt.Println("AddCygxArticle Err:", err.Error())
  773. return err
  774. }
  775. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  776. expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
  777. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  778. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  779. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  780. v.Body = strings.Replace(v.Body, "):", "", -1)
  781. }
  782. var titleNew string
  783. titleNew = v.Title
  784. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  785. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  786. if v.UpdateFrequency == "daily" {
  787. var daystr string
  788. daystr = strconv.Itoa(v.PublishDate.Day())
  789. if len(daystr) == 1 {
  790. daystr = "0" + daystr
  791. }
  792. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  793. } else if v.UpdateFrequency == "weekly" {
  794. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  795. }
  796. }
  797. if v.CategoryId == 80 {
  798. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  799. }
  800. if count > 0 {
  801. fmt.Println(k, v.ArticleId, "edit")
  802. var isCustom bool
  803. bodyText, _ := GetReportContentTextSub(v.Body)
  804. updateParams := make(map[string]interface{})
  805. //updateParams["Title"] = v.Title
  806. updateParams["Title"] = titleNew
  807. updateParams["TitleEn"] = v.TitleEn
  808. updateParams["UpdateFrequency"] = v.UpdateFrequency
  809. updateParams["CreateDate"] = v.CreateDate
  810. updateParams["PublishDate"] = v.PublishDate
  811. //updateParams["Body"] = html.EscapeString(v.Body)
  812. updateParams["Body"] = html.EscapeString(bodyReturn)
  813. updateParams["BodyText"] = bodyText
  814. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  815. updateParams["CategoryName"] = v.CategoryName
  816. for _, vCustom := range listCustomArticle {
  817. if v.ArticleId == vCustom.ArticleId {
  818. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  819. isCustom = true
  820. }
  821. }
  822. if isCustom == false {
  823. updateParams["CategoryId"] = v.CategoryId
  824. updateParams["MatchTypeName"] = matchTypeName
  825. updateParams["IsSummary"] = v.IsSummary
  826. updateParams["IsReport"] = v.IsReport
  827. updateParams["ReportType"] = v.ReportType
  828. updateParams["SubCategoryName"] = v.SubCategoryName
  829. }
  830. //updateParams["CategoryId"] = v.CategoryId
  831. updateParams["PublishStatus"] = 1
  832. updateParams["ExpertBackground"] = expertContentStr
  833. updateParams["ExpertNumber"] = expertNumStr
  834. updateParams["InterviewDate"] = interviewDateStr
  835. //updateParams["IsClass"] = v.IsClass
  836. v.Department = "弘则权益研究"
  837. updateParams["Department"] = v.Department
  838. updateParams["FileLink"] = v.File
  839. updateParams["Stock"] = v.Stock
  840. updateParams["FieldName"] = v.FieldName
  841. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  842. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  843. if err != nil {
  844. fmt.Println("UpdateByExpr Err:" + err.Error())
  845. return err
  846. }
  847. } else {
  848. fmt.Println(k, v.ArticleId, "add")
  849. item := new(models.CygxArticle)
  850. articleIdInt := v.ArticleId
  851. item.ArticleId = articleIdInt
  852. //item.Title = v.Title
  853. item.Title = titleNew
  854. item.TitleEn = v.TitleEn
  855. item.UpdateFrequency = v.UpdateFrequency
  856. item.CreateDate = v.CreateDate
  857. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  858. //item.Body = html.EscapeString(v.Body)
  859. item.Body = html.EscapeString(bodyReturn)
  860. item.Abstract = html.EscapeString(v.Abstract)
  861. item.CategoryName = v.CategoryName
  862. item.SubCategoryName = v.SubCategoryName
  863. item.CategoryId = v.CategoryId
  864. item.CategoryIdTwo = v.CategoryId
  865. item.PublishStatus = 1
  866. item.ExpertBackground = expertContentStr
  867. item.ExpertNumber = expertNumStr
  868. item.InterviewDate = interviewDateStr
  869. item.Department = v.Department
  870. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  871. item.IsClass = v.IsClass
  872. item.IsSummary = v.IsSummary
  873. item.IsReport = v.IsReport
  874. item.ReportType = v.ReportType
  875. item.FileLink = v.File
  876. item.MatchTypeName = matchTypeName
  877. item.Stock = v.Stock
  878. item.FieldName = v.FieldName
  879. newId, err := models.AddCygxArticles(item)
  880. if err != nil {
  881. fmt.Println("AddCygxArticle Err:", err.Error())
  882. return err
  883. }
  884. //fmt.Println(newId)
  885. //报告自动归类,以及推送相关模板消息
  886. if v.ReportType == 2 {
  887. var subjectStr string
  888. var industrialManagementIdStr string
  889. var industrialSubjectIdStr string
  890. var keyword1 string
  891. var keyword2 string
  892. var keyword3 string
  893. var keyword4 string
  894. sliceSubjects := strings.Split(v.Stock, "/")
  895. mapManagementForSubject := make(map[string]string)
  896. if len(sliceSubjects) > 0 {
  897. for _, vSubject := range sliceSubjects {
  898. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  899. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  900. subject := sliceXiahuaxian[0]
  901. subjectStr += "'" + subject + "',"
  902. }
  903. //获取该产业下所对应的行业图片
  904. detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
  905. if errCategory != nil {
  906. fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
  907. return err
  908. }
  909. subjectStr = strings.TrimRight(subjectStr, ",")
  910. if subjectStr != "" {
  911. listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
  912. if err != nil {
  913. fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
  914. return err
  915. }
  916. subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
  917. subjectStr = strings.Replace(subjectStr, "'", "", -1)
  918. subjectStr = "【" + subjectStr + "】"
  919. if len(listIndustrial) > 0 {
  920. for _, vIndustrial := range listIndustrial {
  921. industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
  922. industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
  923. mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
  924. }
  925. industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
  926. industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
  927. if industrialManagementIdStr != "" {
  928. err = models.ReportArticleClassificationEditNew(int(newId), industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
  929. if err != nil {
  930. fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
  931. return err
  932. }
  933. }
  934. var peoductName string
  935. for mk, mv := range mapManagementForSubject {
  936. peoductName += "【" + mk + "--" + strings.TrimRight(mv, "/") + "】"
  937. }
  938. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  939. keyword2 = "已自动关联至以下产业和标的:" + peoductName
  940. keyword3 = v.Title
  941. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  942. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  943. } else {
  944. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  945. keyword2 = "未归类"
  946. keyword3 = v.Title
  947. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  948. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  949. }
  950. }
  951. }
  952. }
  953. }
  954. //类型ID 医药(医享会:28 、药调研:301)、消费【渠道新声:32】、科技【科技前言:79】、智造【匠心智造:84】或者是纪要做消息模板推送
  955. fmt.Println(v.CategoryId)
  956. if v.IsSummary == 1 || (v.CategoryId == 28 || v.CategoryId == 301 || v.CategoryId == 32 || v.CategoryId == 79 || v.CategoryId == 84) {
  957. sliceSubjects := strings.Split(v.Stock, "/")
  958. fmt.Println(sliceSubjects)
  959. if len(sliceSubjects) > 0 {
  960. var subjectStr string
  961. for _, vSubject := range sliceSubjects {
  962. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  963. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  964. subject := sliceXiahuaxian[0]
  965. subjectStr += "'" + subject + "',"
  966. }
  967. if subjectStr != "" {
  968. subjectStr = strings.TrimRight(subjectStr, ",")
  969. activityIdList, err := models.GetActivityIdListBySubjecName(subjectStr)
  970. if err != nil {
  971. fmt.Println("GetActivityIdListBySubjecName Err:", err.Error())
  972. return err
  973. }
  974. if len(activityIdList) > 0 {
  975. var activityIdStr string
  976. for _, vAct := range activityIdList {
  977. activityIdStr += strconv.Itoa(vAct.ActivityId) + ","
  978. }
  979. activityIdStr = strings.TrimRight(activityIdStr, ",")
  980. if activityIdStr != "" {
  981. appointmentList, err := models.GetAppointmentListByActivityId(activityIdStr, "1,2,5")
  982. if err != nil {
  983. fmt.Println("GetAppointmentListByActivityId Err:", err.Error())
  984. return err
  985. }
  986. if len(appointmentList) > 0 {
  987. for _, vApp := range appointmentList {
  988. appointmentByMobileList, err := models.GetAppointmentListByActivityIdAndMobile(activityIdStr, vApp.Mobile)
  989. if err != nil {
  990. fmt.Println("GetAppointmentListByActivityId Err:", err.Error())
  991. return err
  992. }
  993. var appointmentActivityName string
  994. if len(appointmentByMobileList) > 0 {
  995. for _, vAppM := range appointmentByMobileList {
  996. appointmentActivityName += vAppM.ActivityName + ","
  997. }
  998. }
  999. appointmentActivityName = strings.TrimRight(appointmentActivityName, ",")
  1000. if vApp.ActivityTypeId == 5 && v.CategoryId != 301 {
  1001. continue
  1002. }
  1003. if vApp.Mobile != "" {
  1004. openIdListByAppointment, err := models.GetUserRecordListByMobile(4, vApp.Mobile)
  1005. if err != nil {
  1006. fmt.Println(err)
  1007. return err
  1008. }
  1009. keyword1 := "您预约的调研,有关联的纪要发布/更新了"
  1010. keyword2 := appointmentActivityName
  1011. keyword3 := v.Title
  1012. keyword4 := v.PublishDate.Format(utils.FormatDateTime)
  1013. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdListByAppointment, artcleId)
  1014. }
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. }
  1021. }
  1022. //【公司调研】系列纪要发布/更新后
  1023. if v.CategoryId == 45 || v.CategoryId == 74 || v.CategoryId == 86 || v.CategoryId == 88 {
  1024. fmt.Println("处理预约纪要")
  1025. sliceSubjects := strings.Split(v.Stock, "/")
  1026. if len(sliceSubjects) > 0 {
  1027. var subjectStr string
  1028. for _, vSubject := range sliceSubjects {
  1029. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  1030. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  1031. subject := sliceXiahuaxian[0]
  1032. subjectStr += "'" + subject + "',"
  1033. }
  1034. if subjectStr != "" {
  1035. subjectStr = strings.TrimRight(subjectStr, ",")
  1036. activityIdList, err := models.GetActivityIdListBySubjecName(subjectStr)
  1037. if err != nil {
  1038. fmt.Println("GetActivityIdListBySubjecName Err:", err.Error())
  1039. return err
  1040. }
  1041. if len(activityIdList) > 0 {
  1042. var activityIdStr string
  1043. for _, vAct := range activityIdList {
  1044. activityIdStr += strconv.Itoa(vAct.ActivityId) + ","
  1045. }
  1046. activityIdStr = strings.TrimRight(activityIdStr, ",")
  1047. if activityIdStr != "" {
  1048. appointmentList, err := models.GetAppointmentListByActivityId(activityIdStr, "3,4")
  1049. if err != nil {
  1050. fmt.Println("GetAppointmentListByActivityId Err:", err.Error())
  1051. return err
  1052. }
  1053. if len(appointmentList) > 0 {
  1054. for _, vApp := range appointmentList {
  1055. appointmentByMobileList, err := models.GetAppointmentListByActivityIdAndMobile(activityIdStr, vApp.Mobile)
  1056. if err != nil {
  1057. fmt.Println("GetAppointmentListByActivityId Err:", err.Error())
  1058. return err
  1059. }
  1060. var appointmentActivityName string
  1061. if len(appointmentByMobileList) > 0 {
  1062. for _, vAppM := range appointmentByMobileList {
  1063. appointmentActivityName += vAppM.ActivityName + ","
  1064. }
  1065. }
  1066. appointmentActivityName = strings.TrimRight(appointmentActivityName, ",")
  1067. if vApp.Mobile != "" {
  1068. openIdListByAppointment, err := models.GetUserRecordListByMobile(4, vApp.Mobile)
  1069. if err != nil {
  1070. fmt.Println(err)
  1071. return err
  1072. }
  1073. keyword1 := "您预约的调研,有关联的纪要发布/更新了"
  1074. keyword2 := appointmentActivityName
  1075. keyword3 := v.Title
  1076. keyword4 := v.PublishDate.Format(utils.FormatDateTime)
  1077. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdListByAppointment, artcleId)
  1078. }
  1079. }
  1080. }
  1081. }
  1082. }
  1083. }
  1084. }
  1085. }
  1086. //【公司调研】系列纪要发布/更新后 end
  1087. }
  1088. go models.UpdateCygxArticleCeluePush(celuePushId)
  1089. return err
  1090. }