article.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/PuerkitoBio/goquery"
  7. "hongze/hongze_cygx/models"
  8. "hongze/hongze_cygx/utils"
  9. "html"
  10. "io/ioutil"
  11. nhttp "net/http"
  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. return
  52. }
  53. //解析文章内容
  54. func GetArticleAll() {
  55. var err error
  56. defer func() {
  57. if err != nil {
  58. fmt.Println("err:", err.Error())
  59. return
  60. }
  61. }()
  62. list, err := models.GetArticleAll()
  63. if err != nil {
  64. return
  65. }
  66. for _, v := range list {
  67. fmt.Println(v.ArticleId, v.Title)
  68. FixArticleContent(v.ArticleId)
  69. }
  70. }
  71. //解析报告
  72. func FixArticleContent(articleId int) {
  73. item, err := models.GetArticleDetailById(articleId)
  74. if err != nil {
  75. fmt.Println("GetArticleDetailById Err:" + err.Error())
  76. return
  77. }
  78. content := item.Body
  79. bodyText, _ := GetReportContentTextSub(content)
  80. content = html.UnescapeString(content)
  81. content = strings.Replace(content, "http", "https", -1)
  82. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  83. if err != nil {
  84. fmt.Println("create doc err:", err.Error())
  85. return
  86. }
  87. var expertNumArr []string
  88. var expertContentArr []string
  89. var interviewDateArr []string
  90. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  91. contentTxt := s.Text()
  92. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  93. interviewDate := s.Next().Text()
  94. interviewDateArr = append(interviewDateArr, interviewDate)
  95. }
  96. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  97. expertContent := s.Next().Text()
  98. if expertContent == "" {
  99. expertContent = contentTxt
  100. }
  101. if expertContent != "" {
  102. rightIndex := strings.Index(expertContent, ")")
  103. if rightIndex == 0 {
  104. rightIndex = strings.Index(expertContent, ")")
  105. }
  106. if rightIndex > 0 {
  107. expertNum := expertContent[:rightIndex]
  108. expertNum = strings.Replace(expertNum, "(", "", -1)
  109. expertNum = strings.Replace(expertNum, "(", "", -1)
  110. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  111. if expertNum != "" {
  112. expertNumArr = append(expertNumArr, expertNum)
  113. rightIndex = rightIndex
  114. expertContentStr := expertContent[rightIndex:]
  115. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  116. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  117. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  118. expertContentArr = append(expertContentArr, expertContentStr)
  119. }
  120. }
  121. }
  122. }
  123. })
  124. if len(expertContentArr) <= 0 {
  125. doc.Find("pre").Each(func(i int, pre *goquery.Selection) {
  126. pre.Find("span").Each(func(n int, span *goquery.Selection) {
  127. contentTxt := span.Text()
  128. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  129. span.Find("span").Each(func(m int, subspan *goquery.Selection) {
  130. subspanText := subspan.Text()
  131. if strings.Contains(subspanText, "专家评价") {
  132. expertContent := subspan.Next().Text()
  133. if expertContent != "" {
  134. rightIndex := strings.Index(expertContent, ")")
  135. if rightIndex == 0 {
  136. rightIndex = strings.Index(expertContent, ")")
  137. }
  138. if rightIndex > 0 {
  139. expertNum := expertContent[:rightIndex]
  140. expertNum = strings.Replace(expertNum, "(", "", -1)
  141. expertNum = strings.Replace(expertNum, "(", "", -1)
  142. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  143. if expertNum != "" {
  144. expertNumArr = append(expertNumArr, expertNum)
  145. rightIndex = rightIndex
  146. expertContentStr := expertContent[rightIndex:]
  147. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  148. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  149. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  150. expertContentArr = append(expertContentArr, expertContentStr)
  151. }
  152. }
  153. }
  154. }
  155. })
  156. }
  157. span.Find("span").Each(func(k int, sspan *goquery.Selection) {
  158. sspanText := sspan.Text()
  159. if strings.Contains(sspanText, "访谈时间") {
  160. sspanText = strings.Replace(sspanText, "#访谈时间:", "", -1)
  161. sspanText = strings.Replace(sspanText, "访谈时间:", "", -1)
  162. sspanText = strings.Replace(sspanText, "\n", "", -1)
  163. sspanText = strings.Replace(sspanText, " ", "", -1)
  164. sspanText = strings.Trim(sspanText, " ")
  165. sspanText = sspanText[:10]
  166. interviewDate := sspanText
  167. if interviewDate != "" {
  168. interviewDateArr = append(interviewDateArr, interviewDate)
  169. }
  170. }
  171. })
  172. })
  173. })
  174. }
  175. if len(expertContentArr) <= 0 {
  176. doc.Find("span").Each(func(i int, span *goquery.Selection) {
  177. span.Find("strong").Each(func(n int, strong *goquery.Selection) {
  178. spanText := span.Text()
  179. strongText := strong.Text()
  180. if strings.Contains(strongText, "#专家评价") || strings.Contains(strongText, "专家评价") {
  181. expertContent := strong.Parents().Text()
  182. if expertContent != "" {
  183. rightIndex := strings.Index(expertContent, ")")
  184. if rightIndex == 0 {
  185. rightIndex = strings.Index(expertContent, ")")
  186. }
  187. if rightIndex > 0 {
  188. expertNum := expertContent[:rightIndex]
  189. expertNum = strings.Replace(expertNum, "(", "", -1)
  190. expertNum = strings.Replace(expertNum, "(", "", -1)
  191. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  192. expertNum = strings.Replace(expertNum, "#", "", -1)
  193. expertNum = strings.Replace(expertNum, ":", "", -1)
  194. expertNum = strings.Replace(expertNum, "\n", "", -1)
  195. if expertNum != "" {
  196. expertNumArr = append(expertNumArr, expertNum)
  197. rightIndex = rightIndex
  198. expertContentStr := expertContent[rightIndex:]
  199. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  200. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  201. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  202. expertContentArr = append(expertContentArr, expertContentStr)
  203. return
  204. }
  205. }
  206. }
  207. }
  208. if strings.Contains(spanText, "访谈时间") {
  209. spanText = strings.Replace(spanText, "#访谈时间:", "", -1)
  210. spanText = strings.Replace(spanText, "访谈时间:", "", -1)
  211. spanText = strings.Replace(spanText, "\n", "", -1)
  212. spanText = strings.Replace(spanText, " ", "", -1)
  213. spanText = strings.Trim(spanText, " ")
  214. spanText = spanText[:10]
  215. interviewDate := spanText
  216. if interviewDate != "" {
  217. interviewDateArr = append(interviewDateArr, interviewDate)
  218. }
  219. }
  220. })
  221. })
  222. }
  223. var expertNumStr, expertContentStr, interviewDateStr string
  224. if len(expertNumArr) > 0 {
  225. expertNumStr = expertNumArr[0]
  226. }
  227. if len(expertContentArr) > 0 {
  228. expertContentStr = expertContentArr[0]
  229. }
  230. if len(interviewDateArr) > 0 {
  231. interviewDateStr = interviewDateArr[0]
  232. }
  233. expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
  234. err = models.ModifyArticleExpert(articleId, expertNumStr, expertContentStr, interviewDateStr, bodyText)
  235. if err != nil {
  236. fmt.Println("ModifyArticleExpert Err:" + err.Error())
  237. return
  238. }
  239. }
  240. func FixArticleImgUrl(body string) (contentSub string, err error) {
  241. r := strings.NewReader(string(body))
  242. doc, err := goquery.NewDocumentFromReader(r)
  243. if err != nil {
  244. fmt.Println(err)
  245. }
  246. doc.Find("img").Each(func(i int, s *goquery.Selection) {
  247. src, _ := s.Attr("src")
  248. if i == 0 && src != "" {
  249. contentSub = src
  250. }
  251. })
  252. return
  253. }
  254. //获取标签里的第一个内容
  255. func FixArticleFirstCount(body string) (contentSub string, err error) {
  256. doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
  257. if err != nil {
  258. fmt.Println("create doc err:", err.Error())
  259. return
  260. }
  261. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  262. contentTxt := s.Text()
  263. fmt.Println(contentTxt)
  264. })
  265. return
  266. }
  267. func GetArticleListByApi(cont context.Context) (err error) {
  268. defer func() {
  269. if err != nil {
  270. fmt.Println("GetArticleListByApi Err:" + err.Error())
  271. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  272. }
  273. }()
  274. url := "https://vmp.hzinsights.com/v2api/articles/mp?take=100&skip=0&publish_status=1"
  275. method := "GET"
  276. client := &nhttp.Client{}
  277. req, err := nhttp.NewRequest(method, url, nil)
  278. if err != nil {
  279. fmt.Println("GetListApi Err:", err.Error())
  280. return err
  281. }
  282. req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
  283. res, err := client.Do(req)
  284. if err != nil {
  285. fmt.Println(err)
  286. return err
  287. }
  288. defer res.Body.Close()
  289. body, err := ioutil.ReadAll(res.Body)
  290. if err != nil {
  291. fmt.Println("Getres.Body Err:", err.Error())
  292. return err
  293. }
  294. var pdfResult models.ArticleResultApi
  295. err = json.Unmarshal(body, &pdfResult)
  296. if err != nil {
  297. fmt.Println("Getres.pdfResult Err:", err.Error())
  298. return err
  299. }
  300. exitMap := make(map[int]int)
  301. classMap := make(map[int]int)
  302. reportMap := make(map[int]int)
  303. summaryMap := make(map[int]int)
  304. listMap, err := models.GetArticleApiMap()
  305. if err != nil {
  306. fmt.Println("GetlistMap Err:", err.Error())
  307. return err
  308. }
  309. //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
  310. for _, v := range listMap {
  311. exitMap[v.Id] = v.OldId
  312. if v.IsClass == 1 {
  313. classMap[v.OldId] = 1
  314. }
  315. if v.IsReport == 1 {
  316. reportMap[v.OldId] = 1
  317. }
  318. if v.IsSummary == 1 {
  319. summaryMap[v.OldId] = 1
  320. }
  321. }
  322. listData := pdfResult.Data
  323. var list []*models.Tactics2
  324. var listAuthor []*models.CygxArticleAuthor
  325. for _, v := range listData {
  326. if exitMap[v.SeriesId] > 0 {
  327. item := new(models.Tactics2)
  328. itemAuthor := new(models.CygxArticleAuthor)
  329. item.ArticleId = v.ArticleId
  330. item.Title = v.Title
  331. item.TitleEn = v.TitleEn
  332. if v.Frequency == "日度" {
  333. item.UpdateFrequency = "daily"
  334. } else if v.Frequency == "周度" {
  335. item.UpdateFrequency = "weekly"
  336. } else if v.Frequency == "月度" {
  337. item.UpdateFrequency = "monthly"
  338. } else if v.Frequency == "季度" {
  339. item.UpdateFrequency = "quarterly"
  340. } else if v.Frequency == "年度" {
  341. item.UpdateFrequency = "yearly"
  342. } else {
  343. item.UpdateFrequency = "unknow"
  344. }
  345. item.CreateDate = v.CreateDate
  346. item.PublishDate = v.PublishDate
  347. item.PublishStatus = v.PublishStatus
  348. item.Body = v.Content.Body
  349. item.Abstract = v.Content.Abstract
  350. item.CategoryName = v.Industry.Name
  351. item.CategoryId = exitMap[v.SeriesId]
  352. item.SubCategoryName = v.Series.Name
  353. list = append(list, item)
  354. itemAuthor.ArticleId = v.ArticleId
  355. itemAuthor.Name = v.Author.Name
  356. itemAuthor.Mobile = v.Author.PhoneNumber
  357. listAuthor = append(listAuthor, itemAuthor)
  358. }
  359. }
  360. //同步作者
  361. for _, v := range listAuthor {
  362. var count int
  363. count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  364. if err != nil {
  365. fmt.Println("GetCount Err:", err.Error())
  366. return err
  367. }
  368. if count == 0 {
  369. _, err = models.AddCygxActivityAuthor(v)
  370. if err != nil {
  371. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  372. return err
  373. }
  374. }
  375. }
  376. fmt.Println("同步文章条数:", len(list))
  377. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  378. if err != nil {
  379. fmt.Println("GetTacticsList Err:", err.Error())
  380. return err
  381. }
  382. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  383. if errMatch != nil {
  384. fmt.Println("GetTacticsList Err:", errMatch.Error())
  385. return err
  386. }
  387. fmt.Println("list len:", len(list))
  388. 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
  389. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  390. for k, v := range list {
  391. //同步匹配类型
  392. matchTypeName := ""
  393. for _, vMatch := range listGetMatchTypeName {
  394. if v.CategoryId == vMatch.CategoryId {
  395. matchTypeName = vMatch.MatchTypeName
  396. }
  397. }
  398. //是否属于纪要库的数据
  399. if _, has := summaryMap[v.CategoryId]; has {
  400. v.IsSummary = 1
  401. }
  402. //排除不属于纪要库类型的文章
  403. for _, vArt := range listNoSummaryArticleIds {
  404. vArtInt, _ := strconv.Atoi(vArt)
  405. if v.ArticleId == vArtInt {
  406. v.IsSummary = 0
  407. }
  408. }
  409. if _, has := reportMap[v.CategoryId]; has {
  410. v.IsReport = 1
  411. if _, ok := classMap[v.CategoryId]; ok {
  412. v.IsClass = 1
  413. v.ReportType = 1 //是否属于行业报告
  414. } else {
  415. v.ReportType = 2 //是否属于产业报告
  416. }
  417. }
  418. v.Department = "弘则权益研究"
  419. //判断是否已经存在
  420. if v.ArticleId < 0 {
  421. fmt.Println("AddCygxArticle Err:")
  422. return err
  423. }
  424. var count int
  425. count, err = models.GetArticleCountById(v.ArticleId)
  426. if err != nil && err.Error() != utils.ErrNoRow() {
  427. fmt.Println("AddCygxArticle Err:", err.Error())
  428. return err
  429. }
  430. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  431. expertNumStr, expertContentStr, interviewDateStr, fileLink, bodyReturn := BodyAnalysis2(v.Body)
  432. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  433. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  434. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  435. v.Body = strings.Replace(v.Body, "):", "", -1)
  436. }
  437. var titleNew string
  438. titleNew = v.Title
  439. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  440. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  441. if v.UpdateFrequency == "daily" {
  442. var daystr string
  443. daystr = strconv.Itoa(v.PublishDate.Day())
  444. if len(daystr) == 1 {
  445. daystr = "0" + daystr
  446. }
  447. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  448. } else if v.UpdateFrequency == "weekly" {
  449. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  450. }
  451. }
  452. if v.CategoryId == 80 {
  453. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  454. }
  455. if count > 0 {
  456. fmt.Println(k, v.ArticleId, "edit")
  457. var isCustom bool
  458. bodyText, _ := GetReportContentTextSub(v.Body)
  459. updateParams := make(map[string]interface{})
  460. //updateParams["Title"] = v.Title
  461. updateParams["Title"] = titleNew
  462. updateParams["TitleEn"] = v.TitleEn
  463. updateParams["UpdateFrequency"] = v.UpdateFrequency
  464. updateParams["CreateDate"] = v.CreateDate
  465. updateParams["PublishDate"] = v.PublishDate
  466. //updateParams["Body"] = html.EscapeString(v.Body)
  467. updateParams["Body"] = html.EscapeString(bodyReturn)
  468. updateParams["BodyText"] = bodyText
  469. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  470. updateParams["CategoryName"] = v.CategoryName
  471. for _, vCustom := range listCustomArticle {
  472. if v.ArticleId == vCustom.ArticleId {
  473. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  474. isCustom = true
  475. }
  476. }
  477. if isCustom == false {
  478. updateParams["CategoryId"] = v.CategoryId
  479. updateParams["MatchTypeName"] = matchTypeName
  480. updateParams["IsSummary"] = v.IsSummary
  481. updateParams["IsReport"] = v.IsReport
  482. updateParams["ReportType"] = v.ReportType
  483. updateParams["SubCategoryName"] = v.SubCategoryName
  484. }
  485. //updateParams["CategoryId"] = v.CategoryId
  486. updateParams["PublishStatus"] = v.PublishStatus
  487. updateParams["ExpertBackground"] = expertContentStr
  488. updateParams["ExpertNumber"] = expertNumStr
  489. updateParams["InterviewDate"] = interviewDateStr
  490. //updateParams["IsClass"] = v.IsClass
  491. v.Department = "弘则权益研究"
  492. updateParams["Department"] = v.Department
  493. updateParams["FileLink"] = fileLink
  494. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  495. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  496. if err != nil {
  497. fmt.Println("UpdateByExpr Err:" + err.Error())
  498. return err
  499. }
  500. } else {
  501. fmt.Println(k, v.ArticleId, "add")
  502. item := new(models.CygxArticle)
  503. articleIdInt := v.ArticleId
  504. item.ArticleId = articleIdInt
  505. //item.Title = v.Title
  506. item.Title = titleNew
  507. item.TitleEn = v.TitleEn
  508. item.UpdateFrequency = v.UpdateFrequency
  509. item.CreateDate = v.CreateDate
  510. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  511. //item.Body = html.EscapeString(v.Body)
  512. item.Body = html.EscapeString(bodyReturn)
  513. item.Abstract = html.EscapeString(v.Abstract)
  514. item.CategoryName = v.CategoryName
  515. item.SubCategoryName = v.SubCategoryName
  516. item.CategoryId = v.CategoryId
  517. item.PublishStatus = v.PublishStatus
  518. item.ExpertBackground = expertContentStr
  519. item.ExpertNumber = expertNumStr
  520. item.InterviewDate = interviewDateStr
  521. item.Department = v.Department
  522. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  523. item.IsClass = v.IsClass
  524. item.IsSummary = v.IsSummary
  525. item.IsReport = v.IsReport
  526. item.ReportType = v.ReportType
  527. item.FileLink = fileLink
  528. item.MatchTypeName = matchTypeName
  529. _, err = models.AddCygxArticles(item)
  530. if err != nil {
  531. fmt.Println("AddCygxArticle Err:", err.Error())
  532. return err
  533. }
  534. }
  535. }
  536. return
  537. }
  538. func SynchronizationArtclehistory() {
  539. fmt.Println("同步开始")
  540. list, err := models.GetArticleHistoryList()
  541. if err != nil {
  542. fmt.Println("获取列表失败", err)
  543. }
  544. for _, v := range list {
  545. endDate := v.ModifyTime.Add(+time.Minute * 10).Format(utils.FormatDateTime)
  546. detail, err := models.GetNewArticleHistoryRecordNewpv(v.UserId, v.ArticleId, endDate)
  547. if err != nil && err.Error() != utils.ErrNoRow() {
  548. fmt.Println("获取信息失败", err)
  549. }
  550. fmt.Println(v.Id)
  551. if detail == nil {
  552. _, err = models.AddCygxArticleViewRecordNewpv(v)
  553. if err != nil {
  554. fmt.Println("新增失败", err)
  555. }
  556. } else {
  557. err = models.UpdateCygxArticleViewRecordNewpvList(v, v.StopTime)
  558. if err != nil {
  559. fmt.Println("修改失败", err)
  560. }
  561. }
  562. }
  563. fmt.Println(len(list))
  564. fmt.Println("同步结束")
  565. }