article.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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. v.PublishDate = time.Date(v.PublishDate.Year(), v.PublishDate.Month(), v.PublishDate.Day(), v.PublishDate.Hour(), v.PublishDate.Minute(), v.PublishDate.Second(), v.PublishDate.Nanosecond(), time.Local)
  328. item := new(models.Tactics2)
  329. itemAuthor := new(models.CygxArticleAuthor)
  330. item.ArticleId = v.ArticleId
  331. item.Title = v.Title
  332. item.TitleEn = v.TitleEn
  333. if v.Frequency == "日度" {
  334. item.UpdateFrequency = "daily"
  335. } else if v.Frequency == "周度" {
  336. item.UpdateFrequency = "weekly"
  337. } else if v.Frequency == "月度" {
  338. item.UpdateFrequency = "monthly"
  339. } else if v.Frequency == "季度" {
  340. item.UpdateFrequency = "quarterly"
  341. } else if v.Frequency == "年度" {
  342. item.UpdateFrequency = "yearly"
  343. } else {
  344. item.UpdateFrequency = "unknow"
  345. }
  346. item.CreateDate = v.CreateDate
  347. item.PublishDate = v.PublishDate
  348. item.PublishStatus = v.PublishStatus
  349. item.Body = v.Content.Body
  350. item.Abstract = v.Content.Abstract
  351. item.CategoryName = v.Industry.Name
  352. item.CategoryId = exitMap[v.SeriesId]
  353. item.SubCategoryName = v.Series.Name
  354. list = append(list, item)
  355. itemAuthor.ArticleId = v.ArticleId
  356. itemAuthor.Name = v.Author.Name
  357. itemAuthor.Mobile = v.Author.PhoneNumber
  358. listAuthor = append(listAuthor, itemAuthor)
  359. }
  360. }
  361. //同步作者
  362. for _, v := range listAuthor {
  363. var count int
  364. count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  365. if err != nil {
  366. fmt.Println("GetCount Err:", err.Error())
  367. return err
  368. }
  369. if count == 0 {
  370. _, err = models.AddCygxActivityAuthor(v)
  371. if err != nil {
  372. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  373. return err
  374. }
  375. }
  376. }
  377. fmt.Println("同步文章条数:", len(list))
  378. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  379. if err != nil {
  380. fmt.Println("GetTacticsList Err:", err.Error())
  381. return err
  382. }
  383. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  384. if errMatch != nil {
  385. fmt.Println("GetTacticsList Err:", errMatch.Error())
  386. return err
  387. }
  388. fmt.Println("list len:", len(list))
  389. 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
  390. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  391. for k, v := range list {
  392. //同步匹配类型
  393. matchTypeName := ""
  394. for _, vMatch := range listGetMatchTypeName {
  395. if v.CategoryId == vMatch.CategoryId {
  396. matchTypeName = vMatch.MatchTypeName
  397. }
  398. }
  399. //是否属于纪要库的数据
  400. if _, has := summaryMap[v.CategoryId]; has {
  401. v.IsSummary = 1
  402. }
  403. //排除不属于纪要库类型的文章
  404. for _, vArt := range listNoSummaryArticleIds {
  405. vArtInt, _ := strconv.Atoi(vArt)
  406. if v.ArticleId == vArtInt {
  407. v.IsSummary = 0
  408. }
  409. }
  410. if _, has := reportMap[v.CategoryId]; has {
  411. v.IsReport = 1
  412. if _, ok := classMap[v.CategoryId]; ok {
  413. v.IsClass = 1
  414. v.ReportType = 1 //是否属于行业报告
  415. } else {
  416. v.ReportType = 2 //是否属于产业报告
  417. }
  418. }
  419. v.Department = "弘则权益研究"
  420. //判断是否已经存在
  421. if v.ArticleId < 0 {
  422. fmt.Println("AddCygxArticle Err:")
  423. return err
  424. }
  425. var count int
  426. count, err = models.GetArticleCountById(v.ArticleId)
  427. if err != nil && err.Error() != utils.ErrNoRow() {
  428. fmt.Println("AddCygxArticle Err:", err.Error())
  429. return err
  430. }
  431. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  432. expertNumStr, expertContentStr, interviewDateStr, fileLink, bodyReturn := BodyAnalysis2(v.Body)
  433. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  434. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  435. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  436. v.Body = strings.Replace(v.Body, "):", "", -1)
  437. }
  438. var titleNew string
  439. titleNew = v.Title
  440. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  441. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  442. if v.UpdateFrequency == "daily" {
  443. var daystr string
  444. daystr = strconv.Itoa(v.PublishDate.Day())
  445. if len(daystr) == 1 {
  446. daystr = "0" + daystr
  447. }
  448. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  449. } else if v.UpdateFrequency == "weekly" {
  450. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  451. }
  452. }
  453. if v.CategoryId == 80 {
  454. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  455. }
  456. if count > 0 {
  457. fmt.Println(k, v.ArticleId, "edit")
  458. var isCustom bool
  459. bodyText, _ := GetReportContentTextSub(v.Body)
  460. updateParams := make(map[string]interface{})
  461. //updateParams["Title"] = v.Title
  462. updateParams["Title"] = titleNew
  463. updateParams["TitleEn"] = v.TitleEn
  464. updateParams["UpdateFrequency"] = v.UpdateFrequency
  465. updateParams["CreateDate"] = v.CreateDate
  466. updateParams["PublishDate"] = v.PublishDate
  467. //updateParams["Body"] = html.EscapeString(v.Body)
  468. updateParams["Body"] = html.EscapeString(bodyReturn)
  469. updateParams["BodyText"] = bodyText
  470. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  471. updateParams["CategoryName"] = v.CategoryName
  472. for _, vCustom := range listCustomArticle {
  473. if v.ArticleId == vCustom.ArticleId {
  474. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  475. isCustom = true
  476. }
  477. }
  478. if isCustom == false {
  479. updateParams["CategoryId"] = v.CategoryId
  480. updateParams["MatchTypeName"] = matchTypeName
  481. updateParams["IsSummary"] = v.IsSummary
  482. updateParams["IsReport"] = v.IsReport
  483. updateParams["ReportType"] = v.ReportType
  484. updateParams["SubCategoryName"] = v.SubCategoryName
  485. }
  486. //updateParams["CategoryId"] = v.CategoryId
  487. updateParams["PublishStatus"] = v.PublishStatus
  488. updateParams["ExpertBackground"] = expertContentStr
  489. updateParams["ExpertNumber"] = expertNumStr
  490. updateParams["InterviewDate"] = interviewDateStr
  491. //updateParams["IsClass"] = v.IsClass
  492. v.Department = "弘则权益研究"
  493. updateParams["Department"] = v.Department
  494. updateParams["FileLink"] = fileLink
  495. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  496. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  497. if err != nil {
  498. fmt.Println("UpdateByExpr Err:" + err.Error())
  499. return err
  500. }
  501. } else {
  502. fmt.Println(k, v.ArticleId, "add")
  503. item := new(models.CygxArticle)
  504. articleIdInt := v.ArticleId
  505. item.ArticleId = articleIdInt
  506. //item.Title = v.Title
  507. item.Title = titleNew
  508. item.TitleEn = v.TitleEn
  509. item.UpdateFrequency = v.UpdateFrequency
  510. item.CreateDate = v.CreateDate
  511. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  512. //item.Body = html.EscapeString(v.Body)
  513. item.Body = html.EscapeString(bodyReturn)
  514. item.Abstract = html.EscapeString(v.Abstract)
  515. item.CategoryName = v.CategoryName
  516. item.SubCategoryName = v.SubCategoryName
  517. item.CategoryId = v.CategoryId
  518. item.PublishStatus = v.PublishStatus
  519. item.ExpertBackground = expertContentStr
  520. item.ExpertNumber = expertNumStr
  521. item.InterviewDate = interviewDateStr
  522. item.Department = v.Department
  523. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  524. item.IsClass = v.IsClass
  525. item.IsSummary = v.IsSummary
  526. item.IsReport = v.IsReport
  527. item.ReportType = v.ReportType
  528. item.FileLink = fileLink
  529. item.MatchTypeName = matchTypeName
  530. _, err = models.AddCygxArticles(item)
  531. if err != nil {
  532. fmt.Println("AddCygxArticle Err:", err.Error())
  533. return err
  534. }
  535. }
  536. }
  537. return
  538. }
  539. func SynchronizationArtclehistory() {
  540. fmt.Println("同步开始")
  541. list, err := models.GetArticleHistoryList()
  542. if err != nil {
  543. fmt.Println("获取列表失败", err)
  544. }
  545. fmt.Println(len(list))
  546. for _, v := range list {
  547. //endDate := v.ModifyTime.Add(+time.Minute * 10).Format(utils.FormatDateTime)
  548. //detail, err := models.GetNewArticleHistoryRecordNewpv(v.UserId, v.ArticleId, endDate)
  549. //if err != nil && err.Error() != utils.ErrNoRow() {
  550. // fmt.Println("获取信息失败", err)
  551. //}
  552. v.OutType = 1
  553. //fmt.Println(v.Id)
  554. //if detail == nil {
  555. // _, err = models.AddCygxArticleViewRecordNewpv(v)
  556. // if err != nil {
  557. // fmt.Println("新增失败", err)
  558. // }
  559. //} else {
  560. // err = models.UpdateCygxArticleViewRecordNewpvList(v, v.StopTime)
  561. // if err != nil {
  562. // fmt.Println("修改失败", err)
  563. // }
  564. //}
  565. newId, err := models.AddCygxArticleViewRecordNewpv(v)
  566. fmt.Println("新增", newId)
  567. if err != nil {
  568. fmt.Println("新增失败", err)
  569. }
  570. }
  571. fmt.Println("同步结束")
  572. }