article.go 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "github.com/PuerkitoBio/goquery"
  8. "github.com/beego/beego/v2/client/orm"
  9. "hongze/hongze_cygx/models"
  10. "hongze/hongze_cygx/utils"
  11. "html"
  12. "net/url"
  13. "regexp"
  14. "sort"
  15. "strconv"
  16. "strings"
  17. "time"
  18. "unicode/utf8"
  19. )
  20. func GetReportContentSub(content string) (contentSub string, err error) {
  21. content = html.UnescapeString(content)
  22. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  23. if err != nil {
  24. fmt.Println("create doc err:", err.Error())
  25. return
  26. }
  27. n := 0
  28. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  29. if n > 3 {
  30. return
  31. }
  32. n++
  33. phtml, err := s.Html()
  34. if err != nil {
  35. fmt.Println("get html err", err.Error())
  36. return
  37. }
  38. if s.Text() != "" || strings.Contains(phtml, "src") {
  39. contentSub = contentSub + "<p>" + phtml + "</p>"
  40. }
  41. })
  42. return
  43. }
  44. func GetReportContentTextSub(content string) (contentSub string, err error) {
  45. content = html.UnescapeString(content)
  46. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  47. docText := doc.Text()
  48. bodyRune := []rune(docText)
  49. bodyRuneLen := len(bodyRune)
  50. if bodyRuneLen > 200 {
  51. bodyRuneLen = 200
  52. }
  53. body := string(bodyRune[:bodyRuneLen])
  54. contentSub = body
  55. contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
  56. return
  57. }
  58. func GetAnnotationTextSub(content string) (contentSub string) {
  59. contentSub = strings.Replace(content, "<p class=\"ql-align-justify\">", "&nbsp;", -1)
  60. contentSub = strings.Replace(contentSub, "</p>", "", -1)
  61. return
  62. }
  63. func GetReportContentTextSubNew(content string) (contentSub string, err error) {
  64. content = html.UnescapeString(content)
  65. doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(content))
  66. if errdoc != nil {
  67. err = errdoc
  68. return
  69. }
  70. docText := doc.Text()
  71. bodyRune := []rune(docText)
  72. bodyRuneLen := len(bodyRune)
  73. body := string(bodyRune[:bodyRuneLen])
  74. contentSub = body
  75. contentSub = strings.Replace(contentSub, "Powered by Froala Editor", "", -1)
  76. contentSub = strings.Replace(contentSub, " ", "", -1)
  77. contentSub = strings.Replace(contentSub, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sanered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  78. return
  79. }
  80. // GetReportContentTextSubByarticle 解析文章内容
  81. func GetReportContentTextSubByarticle(content, abstract string, articleId int) (contentSub string, err error) {
  82. var lenabstract int
  83. //如果不是研选就这么展示
  84. if articleId < utils.SummaryArticleId {
  85. abstract = html.UnescapeString(abstract)
  86. doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(abstract))
  87. if errdoc != nil {
  88. err = errdoc
  89. return
  90. }
  91. docabstract := doc.Text()
  92. lenabstract = utf8.RuneCountInString(docabstract)
  93. if lenabstract >= 20 {
  94. contentSub = docabstract
  95. return
  96. } else {
  97. contentSub, err = GetReportContentTextSubNew(content)
  98. }
  99. } else {
  100. contentSub, err = GetReportContentTextSubNew(content)
  101. }
  102. return
  103. }
  104. // 解析文章内容
  105. func GetArticleAll() {
  106. var err error
  107. defer func() {
  108. if err != nil {
  109. fmt.Println("err:", err.Error())
  110. return
  111. }
  112. }()
  113. list, err := models.GetArticleAll()
  114. if err != nil {
  115. return
  116. }
  117. for _, v := range list {
  118. fmt.Println(v.ArticleId, v.Title)
  119. FixArticleContent(v.ArticleId)
  120. }
  121. }
  122. // 解析报告
  123. func FixArticleContent(articleId int) {
  124. item, err := models.GetArticleDetailById(articleId)
  125. if err != nil {
  126. fmt.Println("GetArticleDetailById Err:" + err.Error())
  127. return
  128. }
  129. content := item.Body
  130. bodyText, _ := GetReportContentTextSub(content)
  131. content = html.UnescapeString(content)
  132. content = strings.Replace(content, "http", "https", -1)
  133. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  134. if err != nil {
  135. fmt.Println("create doc err:", err.Error())
  136. return
  137. }
  138. var expertNumArr []string
  139. var expertContentArr []string
  140. var interviewDateArr []string
  141. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  142. contentTxt := s.Text()
  143. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  144. interviewDate := s.Next().Text()
  145. interviewDateArr = append(interviewDateArr, interviewDate)
  146. }
  147. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  148. expertContent := s.Next().Text()
  149. if expertContent == "" {
  150. expertContent = contentTxt
  151. }
  152. if expertContent != "" {
  153. rightIndex := strings.Index(expertContent, ")")
  154. if rightIndex == 0 {
  155. rightIndex = strings.Index(expertContent, ")")
  156. }
  157. if rightIndex > 0 {
  158. expertNum := expertContent[:rightIndex]
  159. expertNum = strings.Replace(expertNum, "(", "", -1)
  160. expertNum = strings.Replace(expertNum, "(", "", -1)
  161. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  162. if expertNum != "" {
  163. expertNumArr = append(expertNumArr, expertNum)
  164. rightIndex = rightIndex
  165. expertContentStr := expertContent[rightIndex:]
  166. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  167. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  168. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  169. expertContentArr = append(expertContentArr, expertContentStr)
  170. }
  171. }
  172. }
  173. }
  174. })
  175. if len(expertContentArr) <= 0 {
  176. doc.Find("pre").Each(func(i int, pre *goquery.Selection) {
  177. pre.Find("span").Each(func(n int, span *goquery.Selection) {
  178. contentTxt := span.Text()
  179. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  180. span.Find("span").Each(func(m int, subspan *goquery.Selection) {
  181. subspanText := subspan.Text()
  182. if strings.Contains(subspanText, "专家评价") {
  183. expertContent := subspan.Next().Text()
  184. if expertContent != "" {
  185. rightIndex := strings.Index(expertContent, ")")
  186. if rightIndex == 0 {
  187. rightIndex = strings.Index(expertContent, ")")
  188. }
  189. if rightIndex > 0 {
  190. expertNum := expertContent[:rightIndex]
  191. expertNum = strings.Replace(expertNum, "(", "", -1)
  192. expertNum = strings.Replace(expertNum, "(", "", -1)
  193. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  194. if expertNum != "" {
  195. expertNumArr = append(expertNumArr, expertNum)
  196. rightIndex = rightIndex
  197. expertContentStr := expertContent[rightIndex:]
  198. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  199. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  200. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  201. expertContentArr = append(expertContentArr, expertContentStr)
  202. }
  203. }
  204. }
  205. }
  206. })
  207. }
  208. span.Find("span").Each(func(k int, sspan *goquery.Selection) {
  209. sspanText := sspan.Text()
  210. if strings.Contains(sspanText, "访谈时间") {
  211. sspanText = strings.Replace(sspanText, "#访谈时间:", "", -1)
  212. sspanText = strings.Replace(sspanText, "访谈时间:", "", -1)
  213. sspanText = strings.Replace(sspanText, "\n", "", -1)
  214. sspanText = strings.Replace(sspanText, " ", "", -1)
  215. sspanText = strings.Trim(sspanText, " ")
  216. sspanText = sspanText[:10]
  217. interviewDate := sspanText
  218. if interviewDate != "" {
  219. interviewDateArr = append(interviewDateArr, interviewDate)
  220. }
  221. }
  222. })
  223. })
  224. })
  225. }
  226. if len(expertContentArr) <= 0 {
  227. doc.Find("span").Each(func(i int, span *goquery.Selection) {
  228. span.Find("strong").Each(func(n int, strong *goquery.Selection) {
  229. spanText := span.Text()
  230. strongText := strong.Text()
  231. if strings.Contains(strongText, "#专家评价") || strings.Contains(strongText, "专家评价") {
  232. expertContent := strong.Parents().Text()
  233. if expertContent != "" {
  234. rightIndex := strings.Index(expertContent, ")")
  235. if rightIndex == 0 {
  236. rightIndex = strings.Index(expertContent, ")")
  237. }
  238. if rightIndex > 0 {
  239. expertNum := expertContent[:rightIndex]
  240. expertNum = strings.Replace(expertNum, "(", "", -1)
  241. expertNum = strings.Replace(expertNum, "(", "", -1)
  242. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  243. expertNum = strings.Replace(expertNum, "#", "", -1)
  244. expertNum = strings.Replace(expertNum, ":", "", -1)
  245. expertNum = strings.Replace(expertNum, "\n", "", -1)
  246. if expertNum != "" {
  247. expertNumArr = append(expertNumArr, expertNum)
  248. rightIndex = rightIndex
  249. expertContentStr := expertContent[rightIndex:]
  250. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  251. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  252. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  253. expertContentArr = append(expertContentArr, expertContentStr)
  254. return
  255. }
  256. }
  257. }
  258. }
  259. if strings.Contains(spanText, "访谈时间") {
  260. spanText = strings.Replace(spanText, "#访谈时间:", "", -1)
  261. spanText = strings.Replace(spanText, "访谈时间:", "", -1)
  262. spanText = strings.Replace(spanText, "\n", "", -1)
  263. spanText = strings.Replace(spanText, " ", "", -1)
  264. spanText = strings.Trim(spanText, " ")
  265. spanText = spanText[:10]
  266. interviewDate := spanText
  267. if interviewDate != "" {
  268. interviewDateArr = append(interviewDateArr, interviewDate)
  269. }
  270. }
  271. })
  272. })
  273. }
  274. var expertNumStr, expertContentStr, interviewDateStr string
  275. if len(expertNumArr) > 0 {
  276. expertNumStr = expertNumArr[0]
  277. }
  278. if len(expertContentArr) > 0 {
  279. expertContentStr = expertContentArr[0]
  280. }
  281. if len(interviewDateArr) > 0 {
  282. interviewDateStr = interviewDateArr[0]
  283. }
  284. expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
  285. err = models.ModifyArticleExpert(articleId, expertNumStr, expertContentStr, interviewDateStr, bodyText)
  286. if err != nil {
  287. fmt.Println("ModifyArticleExpert Err:" + err.Error())
  288. return
  289. }
  290. }
  291. func FixArticleImgUrl(body string) (contentSub string, err error) {
  292. r := strings.NewReader(string(body))
  293. doc, err := goquery.NewDocumentFromReader(r)
  294. if err != nil {
  295. fmt.Println(err)
  296. }
  297. doc.Find("img").Each(func(i int, s *goquery.Selection) {
  298. src, _ := s.Attr("src")
  299. if i == 0 && src != "" {
  300. contentSub = src
  301. }
  302. })
  303. return
  304. }
  305. // 获取标签里的第一个内容
  306. func FixArticleFirstCount(body string) (contentSub string, err error) {
  307. doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
  308. if err != nil {
  309. fmt.Println("create doc err:", err.Error())
  310. return
  311. }
  312. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  313. contentTxt := s.Text()
  314. fmt.Println(contentTxt)
  315. })
  316. return
  317. }
  318. func SynchronizationArtclehistory() {
  319. fmt.Println("同步开始")
  320. list, err := models.GetArticleHistoryList()
  321. if err != nil {
  322. fmt.Println("获取列表失败", err)
  323. }
  324. fmt.Println(len(list))
  325. for _, v := range list {
  326. //endDate := v.ModifyTime.Add(+time.Minute * 10).Format(utils.FormatDateTime)
  327. //detail, err := models.GetNewArticleHistoryRecordNewpv(v.UserId, v.ArticleId, endDate)
  328. //if err != nil && err.Error() != utils.ErrNoRow() {
  329. // fmt.Println("获取信息失败", err)
  330. //}
  331. v.OutType = 1
  332. //fmt.Println(v.Id)
  333. //if detail == nil {
  334. // _, err = models.AddCygxArticleViewRecordNewpv(v)
  335. // if err != nil {
  336. // fmt.Println("新增失败", err)
  337. // }
  338. //} else {
  339. // err = models.UpdateCygxArticleViewRecordNewpvList(v, v.StopTime)
  340. // if err != nil {
  341. // fmt.Println("修改失败", err)
  342. // }
  343. //}
  344. newId, err := models.AddCygxArticleViewRecordNewpv(v)
  345. fmt.Println("新增", newId)
  346. if err != nil {
  347. fmt.Println("新增失败", err)
  348. }
  349. }
  350. fmt.Println("同步结束")
  351. }
  352. // 统计报表
  353. func StatisticalReport() {
  354. var isSummaryNumAll, isClassNum, pvNumAll, uvNumAll int
  355. list, err := models.GetChartPermissionActivity()
  356. if err != nil {
  357. fmt.Println("获取列表失败", err)
  358. }
  359. for _, v := range list {
  360. var listPv []*models.ReportMappingStatistical
  361. if v.PermissionName == "研选" {
  362. listPv, err = models.GetStatisticalReportArtilceExpert()
  363. if err != nil {
  364. fmt.Println("获取Pv列表失败", err)
  365. }
  366. } else {
  367. listPv, err = models.GetStatisticalReportArtilce(v.ChartPermissionId)
  368. if err != nil {
  369. fmt.Println("获取Pv列表失败", err)
  370. }
  371. }
  372. var pvNum, uvNum, isSummaryNum int
  373. for _, v2 := range listPv {
  374. pvNum += v2.Pv
  375. uvNum += v2.Uv
  376. if v2.IsSummary == "1" {
  377. isSummaryNum += 1
  378. }
  379. if v2.IsClass == "1" && v.ChartPermissionId <= 22 {
  380. isClassNum += 1
  381. }
  382. if v2.IsSummary == "1" && v.ChartPermissionId <= 22 {
  383. isSummaryNumAll += 1
  384. }
  385. }
  386. if v.ChartPermissionId <= 22 {
  387. pvNumAll += pvNum
  388. uvNumAll += uvNum
  389. }
  390. fmt.Println(v.PermissionName+"行业", len(listPv), "篇,其中主观类报告", isSummaryNum, "篇,客观类报告", len(listPv)-isSummaryNum, "篇。共产生阅读量pv-,", pvNum, ",uv-", uvNum)
  391. }
  392. fmt.Println("目前同步四大行业的总报告(已归类)数量", isClassNum, "篇,其中主观类报告", isSummaryNumAll, "篇,客观类报告", isClassNum-isSummaryNumAll, "篇。共产生阅读量pv-", pvNumAll, ",uv-", uvNumAll)
  393. var totalOnline int //线上
  394. var totalOffline int //线下
  395. var totalPeople int //共累计预约外呼人数
  396. var totalSignUpOff int //线下报名人数
  397. var totalSignUpOffTime int //线下报名人数
  398. var totalPeopleMeet int //线下参会人数
  399. o := orm.NewOrm()
  400. 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();`
  401. err = o.Raw(sql).QueryRow(&totalOnline)
  402. if err != nil {
  403. fmt.Println("获取线上", err)
  404. }
  405. 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();`
  406. err = o.Raw(sql).QueryRow(&totalOffline)
  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. err = o.Raw(sql).QueryRow(&totalPeople)
  419. if err != nil {
  420. fmt.Println("共累计预约外呼人数", err)
  421. }
  422. sql = `SELECT COUNT( 1 ) FROM
  423. cygx_activity_signup as s
  424. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  425. WHERE
  426. s.do_fail_type = 0
  427. AND a.is_submit_meeting = 1
  428. AND a.activity_time <= NOW()
  429. AND a.activity_type_id IN (4,5,6)
  430. AND a.publish_status = 1`
  431. err = o.Raw(sql).QueryRow(&totalSignUpOff)
  432. if err != nil {
  433. fmt.Println("共累计预约外呼人数", err)
  434. }
  435. sql = `SELECT COUNT( 1 ) FROM
  436. cygx_activity_signup as s
  437. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  438. WHERE
  439. s.do_fail_type = 0
  440. AND a.publish_status = 1
  441. AND a.is_submit_meeting = 1
  442. AND a.activity_time <= NOW()
  443. AND a.is_submit_meeting = 1
  444. AND a.activity_type_id IN (4,5,6);`
  445. err = o.Raw(sql).QueryRow(&totalSignUpOffTime)
  446. if err != nil {
  447. fmt.Println("线下报名参会人数", err)
  448. }
  449. sql = `SELECT COUNT( 1 ) FROM
  450. cygx_activity_signup as s
  451. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  452. WHERE
  453. s.do_fail_type = 0
  454. AND a.is_submit_meeting = 1
  455. AND a.activity_time <= NOW()
  456. AND a.publish_status = 1
  457. AND s.is_meeting = 1
  458. AND a.activity_type_id IN (4,5,6);`
  459. err = o.Raw(sql).QueryRow(&totalPeopleMeet)
  460. if err != nil {
  461. fmt.Println("线下参会人数", err)
  462. }
  463. fmt.Println("共上线活动", totalOnline+totalOffline, "个,其中线上", totalOnline, "个,线下", totalOffline, "个")
  464. fmt.Println("共累计预约外呼人数", totalPeople, "人")
  465. fmt.Println("报名线下参会", totalSignUpOff, "人,实际到会人数", totalPeopleMeet, "人,线下到会率约", totalPeopleMeet*100/totalSignUpOff, "%")
  466. num := totalPeopleMeet / totalSignUpOffTime
  467. fmt.Println(num)
  468. fmt.Println(totalOnline)
  469. fmt.Println(totalOffline)
  470. fmt.Println(totalPeople)
  471. fmt.Println(totalSignUpOff)
  472. fmt.Println(totalPeopleMeet)
  473. fmt.Println(totalSignUpOffTime)
  474. fmt.Println(totalPeopleMeet / totalSignUpOffTime)
  475. return
  476. }
  477. // UserViewRedisData 阅读数据
  478. type UserViewRedisData struct {
  479. Mobile string `json:"mobile"`
  480. Email string `json:"email"`
  481. RealName string `json:"real_name"`
  482. CompanyName string `json:"company_name"`
  483. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  484. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  485. CompanyId int `json:"company_id" description:"客户id"`
  486. }
  487. type ReportViewRecord struct {
  488. Id int `orm:"column(id);pk"`
  489. UserId int `description:"用户id"`
  490. ReportId int `description:"报告id"`
  491. Mobile string `description:"手机号"`
  492. Email string `description:"邮箱"`
  493. RealName string `description:"用户实际姓名"`
  494. CompanyName string `description:"公司名称"`
  495. CreateTime time.Time `description:"创建时间"`
  496. }
  497. // PushViewRecordNewRedisData 阅读数据加入到redis
  498. func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
  499. data := &UserViewRedisData{
  500. Mobile: reportViewRecord.Mobile,
  501. Email: reportViewRecord.Email,
  502. RealName: reportViewRecord.RealName,
  503. CompanyName: reportViewRecord.CompanyName,
  504. ViewTime: reportViewRecord.CreateTime.Format(utils.FormatDateTime),
  505. ProductId: 2,
  506. CompanyId: companyId,
  507. }
  508. if utils.Re == nil {
  509. err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
  510. if err != nil {
  511. fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
  512. }
  513. return true
  514. }
  515. return false
  516. }
  517. //func GetCeLueArticlePv() {
  518. // sum := 0
  519. // for i := 0; i <= 450; i++ {
  520. // if i >= 102 {
  521. // //GetCeLueArticlePvs(strconv.Itoa(i * 1000))
  522. // }
  523. // }
  524. // fmt.Println(sum)
  525. //}
  526. // 获取策略平台报告阅读数据
  527. func GetCeLueArticlePv(cont context.Context) (err error) {
  528. defer func() {
  529. if err != nil {
  530. go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
  531. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  532. }
  533. }()
  534. startTime := time.Now().Add(-time.Minute * 12).Format("2006-01-02 15:04:05")
  535. endTime := time.Now().Format("2006-01-02 15:04:05")
  536. requestUrl := utils.ApiUrl + "backend/statistics_access?take=1000&skip=0&sort=ASC&mode=all&"
  537. encodeData := url.Values{}
  538. encodeData.Add("start_dt", startTime)
  539. encodeData.Add("end_dt", endTime)
  540. encodeStr := encodeData.Encode()
  541. requestUrl += encodeStr
  542. authorization := utils.ApiAuthorization
  543. body, err := PublicGetDate(requestUrl, authorization)
  544. if err != nil {
  545. return
  546. }
  547. var chartResult models.CeLueArticleResultApi
  548. err = json.Unmarshal(body, &chartResult)
  549. if err != nil {
  550. fmt.Println(err)
  551. return err
  552. }
  553. mapMobileArticleId := make(map[string]int)
  554. //获取当天阅读记录
  555. listPv, err := models.GetArticleHistoryRecordAllList()
  556. if err != nil && err.Error() != utils.ErrNoRow() {
  557. fmt.Println("获取当天阅读记录失败", err)
  558. return err
  559. }
  560. if len(listPv) > 0 {
  561. for _, v := range listPv {
  562. mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
  563. }
  564. }
  565. for _, v := range chartResult.Data {
  566. //fmt.Println(v.ArticleId)
  567. item := new(models.CygxCelueArticleHistoryRecord)
  568. item.CelueHistoryId = v.CelueHistoryId
  569. item.Mobile = v.Mobile
  570. item.ArticleId = v.ArticleId
  571. if v.CrmUser != nil {
  572. item.RealName = v.CrmUser.RealName
  573. }
  574. if v.CompanyName != nil {
  575. item.CompanyName = v.CompanyName.RealName
  576. }
  577. item.CreateDateApi = time.Now()
  578. t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
  579. item.CreateTime = t1.Add(+time.Hour * 8).Format(utils.FormatDateTime)
  580. count, err := models.GetCeLueArticleCountById(v.CelueHistoryId)
  581. if err != nil && err.Error() != utils.ErrNoRow() {
  582. return err
  583. }
  584. if count == 0 {
  585. _, err := models.AddCeLueArticle(item, mapMobileArticleId)
  586. if err != nil {
  587. fmt.Println(err)
  588. return err
  589. }
  590. }
  591. }
  592. //处理同步过来的阅读记录所属用户
  593. var condition string
  594. condition = ` AND create_time > ` + "'" + startTime + "'"
  595. listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
  596. if err != nil {
  597. fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
  598. }
  599. for _, v := range listArticlePv {
  600. if v.Mobile != "" {
  601. user, err := models.GetWxUserItemByMobile(v.Mobile)
  602. if err != nil && err.Error() != utils.ErrNoRow() {
  603. fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  604. }
  605. if user != nil {
  606. err = models.UpdateCygxArticleHistoryRecordAll(user)
  607. if err != nil {
  608. fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
  609. }
  610. }
  611. }
  612. }
  613. return
  614. }
  615. func GetArticleListByApi(cont context.Context) (err error) {
  616. defer func() {
  617. if err != nil {
  618. //fmt.Println("GetArticleListByApi Err:" + err.Error())
  619. go utils.SendAlarmMsg("同步策略平台数据失败", 2)
  620. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  621. }
  622. }()
  623. listUpdateArticle, err := models.GetArticleCeluePushList()
  624. if err != nil && err.Error() != utils.ErrNoRow() {
  625. return err
  626. }
  627. //如果长度为零就不处理
  628. if len(listUpdateArticle) == 0 {
  629. return err
  630. }
  631. for _, v := range listUpdateArticle {
  632. // 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
  633. err = HandleArticleListByApi(v.ArticleId)
  634. if err != nil {
  635. utils.FileLog.Info("HandleArticleListByApi", err.Error())
  636. }
  637. }
  638. return
  639. }
  640. //func init() {
  641. // // allList, err := models.GetArticleAll()
  642. // //
  643. // // fmt.Println(err)
  644. // //
  645. // // for _, v := range allList {
  646. // // HandleArticleListByApi(v.ArticleId)
  647. // // }
  648. // HandleArticleListByApi(8785)
  649. //
  650. //}
  651. // 处理同步过来的文章
  652. func HandleArticleListByApi(artcleId int) (err error) {
  653. defer func() {
  654. if err != nil {
  655. go utils.SendAlarmMsg("处理同步策略平台数据失败"+"GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), 2)
  656. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), utils.EmailSendToUsers)
  657. }
  658. }()
  659. var clueApiUrl string
  660. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
  661. fmt.Println(clueApiUrl)
  662. authorization := utils.ApiAuthorization
  663. body, err := PublicGetDate(clueApiUrl, authorization)
  664. if err != nil {
  665. fmt.Println(err)
  666. return
  667. }
  668. var articleResultDate models.ArticleDetailResultApi
  669. err = json.Unmarshal(body, &articleResultDate)
  670. if err != nil {
  671. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  672. return err
  673. }
  674. //item := new(models.CygxShanghaiCompanyLog)
  675. //item.CreateTime = time.Now()
  676. //item.Url = clueApiUrl
  677. //item.Body = ""
  678. //item.Result = string(body)
  679. //go models.AddCygxShanghaiCompanyLog(item)
  680. go models.UpdateCygxArticleCeluePush(artcleId)
  681. articleResult := articleResultDate.Data
  682. exitMap := make(map[int]int)
  683. classMap := make(map[int]int)
  684. reportMap := make(map[int]int)
  685. summaryMap := make(map[int]int)
  686. listMap, err := models.GetArticleApiMap()
  687. if err != nil {
  688. fmt.Println("GetlistMap Err:", err.Error())
  689. return err
  690. }
  691. openIdList, err := models.GetUserRecordListByMobile(4, utils.ArticleTaskClassMobile)
  692. if err != nil {
  693. fmt.Println(err)
  694. return err
  695. }
  696. fmt.Println(openIdList)
  697. //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
  698. for _, v := range listMap {
  699. exitMap[v.Id] = v.OldId
  700. if v.IsClass == 1 {
  701. classMap[v.OldId] = 1
  702. }
  703. if v.IsReport == 1 {
  704. reportMap[v.OldId] = 1
  705. }
  706. if v.IsSummary == 1 {
  707. summaryMap[v.OldId] = 1
  708. }
  709. }
  710. var list []*models.Tactics2
  711. var listArticleData []*models.CygxArticleData
  712. var listAuthor []*models.CygxArticleAuthor
  713. //如果是英文报告那么则不同步
  714. if articleResult.TypeId == 9 {
  715. return
  716. }
  717. var cover string
  718. if articleResult.Series.Name == "图解市场" {
  719. cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
  720. } else if articleResult.Series.Name == "行业深度" {
  721. cover = articleResult.Cover
  722. }
  723. fmt.Println(cover)
  724. //return
  725. //状态等于 2 跟 4 的进行同步 IsActive 为false 软删除的也不同步
  726. if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
  727. 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)
  728. item := new(models.Tactics2)
  729. itemArticleData := new(models.CygxArticleData)
  730. itemArticleData.ArticleId = articleResult.ArticleId
  731. itemArticleData.Cover = articleResult.Cover
  732. itemArticleData.CreateTime = time.Now()
  733. listArticleData = append(listArticleData, itemArticleData)
  734. itemAuthor := new(models.CygxArticleAuthor)
  735. item.ArticleId = articleResult.ArticleId
  736. item.Title = articleResult.Title
  737. item.TitleEn = articleResult.TitleEn
  738. item.File = articleResult.File
  739. if articleResult.Frequency == "日度" {
  740. item.UpdateFrequency = "daily"
  741. } else if articleResult.Frequency == "周度" {
  742. item.UpdateFrequency = "weekly"
  743. } else if articleResult.Frequency == "月度" {
  744. item.UpdateFrequency = "monthly"
  745. } else if articleResult.Frequency == "季度" {
  746. item.UpdateFrequency = "quarterly"
  747. } else if articleResult.Frequency == "年度" {
  748. item.UpdateFrequency = "yearly"
  749. } else {
  750. item.UpdateFrequency = "unknow"
  751. }
  752. item.CreateDate = articleResult.CreateDate
  753. item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
  754. item.PublishStatus = 1
  755. item.Body = articleResult.Content.Body
  756. item.Abstract = articleResult.Content.Abstract
  757. item.Annotation = articleResult.Content.Annotation
  758. item.CategoryName = articleResult.Industry.Name
  759. item.CategoryId = exitMap[articleResult.SeriesId]
  760. item.CategoryIdTwo = exitMap[articleResult.SeriesId]
  761. item.SubCategoryName = articleResult.Series.Name
  762. item.Cover = cover
  763. if len(articleResult.Stock) > 0 {
  764. var stock string
  765. for _, vS := range articleResult.Stock {
  766. stock += vS + "/"
  767. }
  768. stock = strings.TrimRight(stock, "/")
  769. item.Stock = stock
  770. }
  771. item.FieldName = articleResult.Field.Name
  772. item.TypeName = articleResult.Type.Name
  773. item.UpdateDate = articleResult.UpdateDate
  774. item.CeLueFieldId = articleResult.Field.Id
  775. list = append(list, item)
  776. itemAuthor.ArticleId = articleResult.ArticleId
  777. itemAuthor.Name = articleResult.Author.Name
  778. itemAuthor.Mobile = articleResult.Author.PhoneNumber
  779. fmt.Println(articleResult.Cover)
  780. listAuthor = append(listAuthor, itemAuthor)
  781. } else {
  782. // 如果这篇文章没有发布,那么就不作处理。
  783. err = models.UpdateArticlePublish(artcleId, 0)
  784. if err != nil {
  785. fmt.Println("UpdateArticlePublish Err:", err.Error())
  786. return err
  787. }
  788. go UpdateResourceData(artcleId, "article", "delete", time.Now().Format(utils.FormatDateTime))
  789. return err
  790. }
  791. //同步作者
  792. for _, v := range listAuthor {
  793. var count int
  794. count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  795. if err != nil {
  796. fmt.Println("GetActivityAuthorCount Err:", err.Error())
  797. return err
  798. }
  799. if count == 0 {
  800. _, err = models.AddCygxActivityAuthor(v)
  801. if err != nil {
  802. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  803. return err
  804. }
  805. }
  806. }
  807. fmt.Println("同步文章条数:", len(list))
  808. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  809. if err != nil {
  810. fmt.Println("GetTacticsList Err:", err.Error())
  811. return err
  812. }
  813. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  814. if errMatch != nil {
  815. fmt.Println("GetTacticsList Err:", errMatch.Error())
  816. return err
  817. }
  818. //mapCategoryIdSet := make(map[int]int)
  819. //for _, vMatch := range listGetMatchTypeName {
  820. // mapCategoryIdSet[vMatch.CategoryId] = vMatch.CategoryIdSet
  821. //}
  822. fmt.Println("list len:", len(list))
  823. 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
  824. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  825. for k, v := range list {
  826. //同步匹配类型
  827. matchTypeName := ""
  828. for _, vMatch := range listGetMatchTypeName {
  829. if v.CategoryId == vMatch.CategoryId {
  830. matchTypeName = vMatch.MatchTypeName
  831. }
  832. }
  833. //是否属于纪要库的数据
  834. //if _, has := summaryMap[v.CategoryId]; has {
  835. // v.IsSummary = 1
  836. //}
  837. if v.TypeName == "纪要" {
  838. v.IsSummary = 1
  839. }
  840. //排除不属于纪要库类型的文章
  841. for _, vArt := range listNoSummaryArticleIds {
  842. vArtInt, _ := strconv.Atoi(vArt)
  843. if v.ArticleId == vArtInt {
  844. v.IsSummary = 0
  845. }
  846. }
  847. if _, has := reportMap[v.CategoryId]; has {
  848. v.IsReport = 1
  849. if _, ok := classMap[v.CategoryId]; ok {
  850. v.IsClass = 1
  851. v.ReportType = 1 //是否属于行业报告
  852. } else {
  853. v.ReportType = 2 //是否属于产业报告
  854. }
  855. }
  856. v.Department = "弘则权益研究"
  857. //判断是否已经存在
  858. if v.ArticleId < 0 {
  859. fmt.Println("AddCygxArticle Err:")
  860. return err
  861. }
  862. var count int
  863. count, err = models.GetArticleCountById(v.ArticleId)
  864. if err != nil && err.Error() != utils.ErrNoRow() {
  865. fmt.Println("AddCygxArticle Err:", err.Error())
  866. return err
  867. }
  868. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  869. expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
  870. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  871. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  872. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  873. v.Body = strings.Replace(v.Body, "):", "", -1)
  874. }
  875. var titleNew string
  876. titleNew = v.Title
  877. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  878. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  879. if v.UpdateFrequency == "daily" {
  880. var daystr string
  881. daystr = strconv.Itoa(v.PublishDate.Day())
  882. if len(daystr) == 1 {
  883. daystr = "0" + daystr
  884. }
  885. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  886. } else if v.UpdateFrequency == "weekly" {
  887. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  888. }
  889. }
  890. if v.CategoryId == 80 {
  891. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  892. }
  893. //类型是综述报告的,不区分是什么系列,统一归类到对应产业的路演精华
  894. if articleResult.Type.Name == "综述报告" {
  895. detailCategory, err := models.GetdetailByCategoryIdLyjh(v.CategoryIdTwo)
  896. if err != nil && err.Error() != utils.ErrNoRow() {
  897. return err
  898. }
  899. v.CategoryId = detailCategory.CategoryId
  900. v.IsSummary = 0
  901. }
  902. if count > 0 {
  903. fmt.Println(k, v.ArticleId, "edit")
  904. articleIfoOld, e := models.GetArticleDetailTestById(v.ArticleId)
  905. if e != nil {
  906. err = e
  907. return
  908. }
  909. bodyTextOld, _ := GetReportContentTextSubNew(articleIfoOld.Body)
  910. bodyText, _ := GetReportContentTextSubNew(v.Body)
  911. if len(bodyText)-len(bodyTextOld) > 100 {
  912. //fmt.Println("触发推送规则")
  913. //更新字数大于一百字触发推送规则
  914. go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  915. go UpdateResourceData(v.ArticleId, "article", "update", time.Now().Format(utils.FormatDateTime))
  916. }
  917. var isCustom bool
  918. updateParams := make(map[string]interface{})
  919. //updateParams["Title"] = v.Title
  920. updateParams["Title"] = titleNew
  921. updateParams["TitleEn"] = v.TitleEn
  922. updateParams["UpdateFrequency"] = v.UpdateFrequency
  923. updateParams["CreateDate"] = v.CreateDate
  924. updateParams["PublishDate"] = v.PublishDate
  925. //updateParams["Body"] = html.EscapeString(v.Body)
  926. updateParams["Body"] = html.EscapeString(bodyReturn)
  927. updateParams["BodyText"] = bodyText
  928. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  929. updateParams["CategoryName"] = v.CategoryName
  930. for _, vCustom := range listCustomArticle {
  931. if v.ArticleId == vCustom.ArticleId {
  932. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  933. isCustom = true
  934. }
  935. }
  936. if isCustom == false {
  937. updateParams["CategoryId"] = v.CategoryId
  938. updateParams["MatchTypeName"] = matchTypeName
  939. updateParams["IsSummary"] = v.IsSummary
  940. updateParams["IsReport"] = v.IsReport
  941. updateParams["ReportType"] = v.ReportType
  942. updateParams["SubCategoryName"] = v.SubCategoryName
  943. }
  944. //updateParams["CategoryId"] = v.CategoryId
  945. updateParams["PublishStatus"] = 1
  946. updateParams["ExpertBackground"] = expertContentStr
  947. updateParams["ExpertNumber"] = expertNumStr
  948. updateParams["InterviewDate"] = interviewDateStr
  949. //updateParams["IsClass"] = v.IsClass
  950. v.Department = "弘则权益研究"
  951. updateParams["Department"] = v.Department
  952. updateParams["FileLink"] = v.File
  953. updateParams["Stock"] = v.Stock
  954. updateParams["FieldName"] = v.FieldName
  955. updateParams["Annotation"] = v.Annotation
  956. updateParams["TypeName"] = v.TypeName
  957. updateParams["ModifyTimeByCl"] = v.UpdateDate
  958. updateParams["CeLueFieldId"] = v.CeLueFieldId
  959. updateParams["Cover"] = v.Cover
  960. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  961. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  962. if err != nil {
  963. fmt.Println("UpdateByExpr Err:" + err.Error())
  964. return err
  965. }
  966. } else {
  967. fmt.Println(k, v.ArticleId, "add")
  968. item := new(models.CygxArticle)
  969. articleIdInt := v.ArticleId
  970. item.ArticleId = articleIdInt
  971. //item.Title = v.Title
  972. item.Title = titleNew
  973. item.TitleEn = v.TitleEn
  974. item.UpdateFrequency = v.UpdateFrequency
  975. item.CreateDate = v.CreateDate
  976. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  977. //item.Body = html.EscapeString(v.Body)
  978. item.Body = html.EscapeString(bodyReturn)
  979. item.Abstract = html.EscapeString(v.Abstract)
  980. item.CategoryName = v.CategoryName
  981. item.SubCategoryName = v.SubCategoryName
  982. item.CategoryId = v.CategoryId
  983. item.CategoryIdTwo = v.CategoryIdTwo
  984. item.PublishStatus = 1
  985. item.ExpertBackground = expertContentStr
  986. item.ExpertNumber = expertNumStr
  987. item.InterviewDate = interviewDateStr
  988. item.Department = v.Department
  989. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  990. item.IsClass = v.IsClass
  991. item.IsSummary = v.IsSummary
  992. item.IsReport = v.IsReport
  993. item.ReportType = v.ReportType
  994. item.FileLink = v.File
  995. item.MatchTypeName = matchTypeName
  996. item.Stock = v.Stock
  997. item.FieldName = v.FieldName
  998. item.Annotation = v.Annotation
  999. item.TypeName = v.TypeName
  1000. item.ModifyTimeByCl = v.UpdateDate
  1001. item.CeLueFieldId = v.CeLueFieldId
  1002. item.Cover = v.Cover
  1003. newId, err := models.AddCygxArticles(item)
  1004. if err != nil {
  1005. fmt.Println("AddCygxArticle Err:", err.Error())
  1006. return err
  1007. }
  1008. go UpdateResourceData(v.ArticleId, "article", "add", time.Now().Format(utils.FormatDateTime))
  1009. //fmt.Println(newId)
  1010. //报告自动归类,以及推送相关模板消息
  1011. if v.ReportType == 2 {
  1012. var subjectStr string
  1013. var industrialManagementIdStr string
  1014. var industrialSubjectIdStr string
  1015. var keyword1 string
  1016. var keyword2 string
  1017. var keyword3 string
  1018. var keyword4 string
  1019. sliceSubjects := strings.Split(v.Stock, "/")
  1020. mapManagementForSubject := make(map[string]string)
  1021. mapIndustrialId := make(map[int]int)
  1022. if len(sliceSubjects) > 0 {
  1023. for _, vSubject := range sliceSubjects {
  1024. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  1025. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  1026. subject := sliceXiahuaxian[0]
  1027. subjectStr += "'" + subject + "',"
  1028. }
  1029. //获取该产业下所对应的行业图片
  1030. detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
  1031. if errCategory != nil {
  1032. fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
  1033. return err
  1034. }
  1035. subjectStr = strings.TrimRight(subjectStr, ",")
  1036. if subjectStr != "" {
  1037. listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
  1038. if err != nil {
  1039. fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
  1040. return err
  1041. }
  1042. subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
  1043. subjectStr = strings.Replace(subjectStr, "'", "", -1)
  1044. subjectStr = "【" + subjectStr + "】"
  1045. if len(listIndustrial) > 0 {
  1046. for _, vIndustrial := range listIndustrial {
  1047. if _, ok := mapIndustrialId[vIndustrial.IndustrialManagementId]; !ok {
  1048. industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
  1049. }
  1050. mapIndustrialId[vIndustrial.IndustrialManagementId] = vIndustrial.IndustrialManagementId
  1051. industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
  1052. mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
  1053. if vIndustrial.LayoutTime == "0000-00-00 00:00:00" {
  1054. go models.UpdateIndustrialManagementLayoutTime(v.PublishDate.AddDate(0, 0, -10).Format(utils.FormatDateTime), vIndustrial.IndustrialManagementId)
  1055. }
  1056. }
  1057. industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
  1058. industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
  1059. if industrialManagementIdStr != "" {
  1060. err = models.ReportArticleClassificationEditNew(int(newId), industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
  1061. if err != nil {
  1062. fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
  1063. return err
  1064. }
  1065. }
  1066. var peoductName string
  1067. for mk, mv := range mapManagementForSubject {
  1068. peoductName += "【" + mk + "--" + strings.TrimRight(mv, "/") + "】"
  1069. }
  1070. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  1071. keyword2 = "已自动关联至以下产业和标的:" + peoductName
  1072. keyword3 = v.Title
  1073. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  1074. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  1075. } else {
  1076. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  1077. keyword2 = "未归类"
  1078. keyword3 = v.Title
  1079. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  1080. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  1081. go models.UpdateIsClassFail(artcleId)
  1082. }
  1083. }
  1084. }
  1085. }
  1086. go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  1087. }
  1088. //【公司调研】系列纪要发布/更新后 end
  1089. //查研观向6.9模板消息推送规则
  1090. //但是如果报告的发布时间是在10天以前的,公众号就不推送了
  1091. //if time.Now().AddDate(0, 0, -10).Before(articleResult.PublishDate.Add(time.Hour * 8)) {
  1092. // go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  1093. //}
  1094. }
  1095. go models.UpdateCygxArticleCeluePush(artcleId)
  1096. GetSummarytoEs(artcleId)
  1097. GetIndustrialManagementArticleNewPublishData()
  1098. if len(listArticleData) > 0 {
  1099. for _, v := range listArticleData {
  1100. count, err := models.GetCygxArticleDataCount(v.ArticleId)
  1101. if err != nil {
  1102. fmt.Println("GetCygxArticleDataCount Err:", err.Error())
  1103. return err
  1104. }
  1105. if count == 0 {
  1106. _, err := models.AddCygxArticleData(v)
  1107. if err != nil {
  1108. fmt.Println("AddCygxArticleData Err:", err.Error())
  1109. return err
  1110. }
  1111. }
  1112. //} else {
  1113. // updateParams := make(map[string]interface{})
  1114. // updateParams["Cover"] = v.Cover
  1115. // whereParam := map[string]interface{}{"article_id": v.ArticleId}
  1116. // err = models.UpdateByExpr(models.CygxArticleData{}, whereParam, updateParams)
  1117. // if err != nil {
  1118. // fmt.Println("UpdateByExpr CygxArticleData Err:" + err.Error())
  1119. // return err
  1120. // }
  1121. //}
  1122. }
  1123. }
  1124. return err
  1125. }
  1126. //func init() {
  1127. // DoArticleOnenIdWxTemplateMsg(8112)
  1128. //}
  1129. // 过滤策略平台报告,研选报告重复推送,以及权限勾选的推送
  1130. func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
  1131. //策略平台同步过来的文章ID,做微信模板消息推送,同一篇报告12小时只推送一次
  1132. cacheKey := fmt.Sprint(utils.CACHE_KEY_ARTICLE_ID_TEMPLATE, ":ArticleId", articleId)
  1133. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  1134. if ttlTime > 0 {
  1135. fmt.Println(ttlTime)
  1136. return err
  1137. }
  1138. var msg string
  1139. defer func() {
  1140. if err != nil {
  1141. go utils.SendAlarmMsg("处理同步策略平台数据失败"+"GetArticleListByApi ErrMsg:"+err.Error(), 2)
  1142. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1143. fmt.Println(err)
  1144. }
  1145. if msg != "" {
  1146. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1147. }
  1148. }()
  1149. //获取文章详情
  1150. articleInfo, err := models.GetArticleDetailById(articleId)
  1151. if err != nil {
  1152. return
  1153. }
  1154. articleInfo.Abstract, _ = GetReportContentTextSub(articleInfo.Abstract)
  1155. var chartPermissionId int
  1156. //固收的权限,暂时当策略的逻辑一样处理
  1157. var chartPermissionName string
  1158. reportMapDetail, err := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  1159. if err != nil {
  1160. return err
  1161. }
  1162. if reportMapDetail.ChartPermissionId == utils.CE_LUE_ID {
  1163. chartPermissionId = utils.CE_LUE_ID
  1164. } else if reportMapDetail.ChartPermissionId == utils.GU_SHOU_ID {
  1165. chartPermissionId = utils.GU_SHOU_ID
  1166. } else {
  1167. if reportMapDetail.PermissionType == 1 {
  1168. chartPermissionName = reportMapDetail.ChartPermissionName + "(主观)"
  1169. } else {
  1170. chartPermissionName = reportMapDetail.ChartPermissionName + "(客观)"
  1171. }
  1172. chartPermissionDetail, err := models.GetChartPermissionByRemark(chartPermissionName)
  1173. if err != nil {
  1174. return err
  1175. }
  1176. chartPermissionId = chartPermissionDetail.ChartPermissionId
  1177. }
  1178. //文章关联的产业
  1179. var industryName string
  1180. var industrialManagementId string
  1181. if chartPermissionId == utils.CE_LUE_ID || chartPermissionId == utils.GU_SHOU_ID {
  1182. industryName = reportMapDetail.SubCategoryName
  1183. } else {
  1184. if articleInfo.ReportType == 2 {
  1185. detailIndustryNameList, err := models.GetIndustrialManagemenDetailByAaticleID(articleId)
  1186. if err != nil && err.Error() != utils.ErrNoRow() {
  1187. return err
  1188. }
  1189. //如果不存在关联的产业则不推送
  1190. if len(detailIndustryNameList) == 0 {
  1191. return err
  1192. }
  1193. for _, v := range detailIndustryNameList {
  1194. industryName += v.IndustryName + ","
  1195. industrialManagementId += strconv.Itoa(v.IndustrialManagementId) + ","
  1196. }
  1197. industryName = strings.TrimRight(industryName, ",")
  1198. industrialManagementId = strings.TrimRight(industrialManagementId, ",")
  1199. //处理勾选了全部行业赛道的用户
  1200. var allIn string
  1201. allIn = DoXzsChooseSend(reportMapDetail.ChartPermissionName)
  1202. if allIn != "" {
  1203. allInList, err := models.GetCygxXzsChooseSendByAllIn(allIn)
  1204. if err != nil && err.Error() != utils.ErrNoRow() {
  1205. return err
  1206. }
  1207. if len(allInList) > 0 {
  1208. var allInUserId string
  1209. for _, v := range allInList {
  1210. allInUserId += strconv.Itoa(v.UserId) + ","
  1211. }
  1212. allInUserId = strings.TrimRight(allInUserId, ",")
  1213. userFllowIndustrialList, err := models.GetUserFllowIndustrialListByUserIdAndIndustrial(allInUserId, industrialManagementId)
  1214. if err != nil && err.Error() != utils.ErrNoRow() {
  1215. return err
  1216. }
  1217. mapUserFllowed := make(map[string]int)
  1218. for _, v := range userFllowIndustrialList {
  1219. //用户ID与其关注的产业组成唯一索引,判断是否存在,如果不存在就进行自动关注
  1220. mapUserFllowed[fmt.Sprint("uid:", v.UserId, "_Industrial:", v.IndustrialManagementId)] = v.UserId
  1221. }
  1222. //获取这些allIN用户的的信息进行遍历生成需要插入的数据
  1223. userList, err := models.GetWxUserListByUserIds(allInUserId)
  1224. if err != nil && err.Error() != utils.ErrNoRow() {
  1225. return err
  1226. }
  1227. var industryFllowItems []*models.CygxIndustryFllow
  1228. for _, v := range detailIndustryNameList {
  1229. for _, vUser := range userList {
  1230. //如果用户这个用户没有关注这个产业就进行自动关注
  1231. if mapUserFllowed[fmt.Sprint("uid:", vUser.UserId, "_Industrial:", v.IndustrialManagementId)] == 0 {
  1232. item := new(models.CygxIndustryFllow)
  1233. item.IndustrialManagementId = v.IndustrialManagementId
  1234. item.UserId = vUser.UserId
  1235. item.Email = vUser.Email
  1236. item.Mobile = vUser.Mobile
  1237. item.RealName = vUser.RealName
  1238. item.CompanyId = vUser.CompanyId
  1239. item.CompanyName = vUser.CompanyName
  1240. item.Source = 3
  1241. item.Type = 1
  1242. item.CreateTime = time.Now()
  1243. item.ModifyTime = time.Now()
  1244. industryFllowItems = append(industryFllowItems, item)
  1245. }
  1246. }
  1247. }
  1248. err = models.AddCygxIndustryFllowMulti(industryFllowItems)
  1249. if err != nil {
  1250. go utils.SendAlarmMsg("用户关注全部赛道,出现新赛道批量添加失败 ,AddCygxIndustryFllowMulti ErrMsg:"+err.Error(), 2)
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. // 获取所有有权的用户的 openid
  1257. mapOpenidPower := make(map[int]string)
  1258. permissionIdList := make([]string, 0)
  1259. var condition string
  1260. var pars []interface{}
  1261. slicepermissionId := strings.Split(strconv.Itoa(chartPermissionId), ",")
  1262. if len(slicepermissionId) > 0 {
  1263. for _, v := range slicepermissionId {
  1264. if v == strconv.Itoa(utils.GU_SHOU_ID) {
  1265. v = strconv.Itoa(utils.CE_LUE_ID)
  1266. }
  1267. permissionIdList = append(permissionIdList, v)
  1268. }
  1269. condition += ` AND p.chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) `
  1270. pars = append(pars, permissionIdList)
  1271. }
  1272. openidPowerList, err := models.GetCygxUserRecordPower(condition, pars)
  1273. if err != nil {
  1274. return err
  1275. }
  1276. //四大行业的行业综述报告,对所有开通了对应行业权限的客户都推送。
  1277. if articleInfo.ReportType == 1 && chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID {
  1278. for _, item := range openidPowerList {
  1279. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1280. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1281. openIditem := new(models.OpenIdList)
  1282. openIditem.OpenId = item.OpenId
  1283. openIditem.UserId = item.UserId
  1284. SendWxMsgWithArticleUpdate(first, keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIditem, articleId)
  1285. }
  1286. return err
  1287. }
  1288. for _, v := range openidPowerList {
  1289. mapOpenidPower[v.UserId] = v.OpenId
  1290. }
  1291. //获取关注这个文章对应产业的用户的 openid
  1292. mapOpenidFllow := make(map[int]string)
  1293. if chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID {
  1294. openidFllowList, err := models.GetCygxUserFllowOpenid(articleId)
  1295. if err != nil {
  1296. return err
  1297. }
  1298. for _, v := range openidFllowList {
  1299. mapOpenidFllow[v.UserId] = v.OpenId
  1300. }
  1301. }
  1302. //获取拒绝接收推送的的用户的 openid
  1303. mapOpenidRefuset := make(map[int]string)
  1304. openidRefusetList, err := models.GetCygxUserRefusetOpenid()
  1305. if err != nil {
  1306. return err
  1307. }
  1308. for _, v := range openidRefusetList {
  1309. mapOpenidRefuset[v.UserId] = v.OpenId
  1310. }
  1311. //获取提交过推送规则的用户的 openid
  1312. mapUserIdChooseSend := make(map[int]int)
  1313. mapUserIdChooseSendTypeNoPermission := make(map[int]int)
  1314. chooseSendtList, err := models.GetCygxXzsChooseSend()
  1315. for _, v := range chooseSendtList {
  1316. mapUserIdChooseSend[v.UserId] = v.UserId
  1317. if v.IsRefuse == 1 {
  1318. continue
  1319. }
  1320. //获取选择主客观赛道的用户
  1321. if reportMapDetail.PermissionType == 1 {
  1322. if v.IsSubjective == 1 {
  1323. mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1324. }
  1325. } else {
  1326. if v.IsObjective == 1 {
  1327. mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1328. }
  1329. }
  1330. }
  1331. //已经推送了的openid
  1332. mapOpenidPushed := make(map[int]string)
  1333. keyword2 := articleInfo.Title
  1334. keyword3 := time.Now().Format(utils.FormatDateTime)
  1335. keyword4 := articleInfo.Abstract
  1336. mapAlreadySend := make(map[int]int)
  1337. //如果是策略就按照策略的推送方式来写
  1338. if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME || reportMapDetail.ChartPermissionName == utils.GU_SHOU_NAME {
  1339. //获取提交过推送规则的用户的 openid
  1340. mapUserFllowCeLue := make(map[int]string)
  1341. userFllowCeLueList, err := models.GetCygxUserFllowCeLueOpenid(articleInfo.CategoryId)
  1342. if err != nil {
  1343. return err
  1344. }
  1345. for _, v := range userFllowCeLueList {
  1346. mapUserFllowCeLue[v.UserId] = v.OpenId
  1347. }
  1348. for k, v := range mapOpenidPower {
  1349. if mapOpenidPushed[k] != "" {
  1350. continue
  1351. }
  1352. openIditem := new(models.OpenIdList)
  1353. openIditem.UserId = k
  1354. openIditem.OpenId = v
  1355. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1356. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1357. mapActivityUserId := make(map[int]string)
  1358. if articleInfo.ReportType == 2 {
  1359. sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1360. if sliceSubjectId != "" {
  1361. appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1362. if err != nil {
  1363. fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
  1364. return err
  1365. }
  1366. var userIds []string
  1367. if len(appointmentList) > 0 {
  1368. for _, v := range appointmentList {
  1369. //fmt.Println("mapActivityUserId:", v.UserId)
  1370. userIds = append(userIds, strconv.Itoa(v.UserId))
  1371. mapActivityUserId[v.UserId] += v.ActivityName + ","
  1372. }
  1373. userIdstr := strings.Join(userIds, ",")
  1374. openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
  1375. if err != nil {
  1376. fmt.Println("GetOpenIdByUserIds Err:", err.Error())
  1377. return err
  1378. }
  1379. for _, item := range openIdLists {
  1380. first := "您预约的调研,有关联的纪要发布/更新了"
  1381. keyword1 := industryName
  1382. openIditem := new(models.OpenIdList)
  1383. openIditem.OpenId = item.OpenId
  1384. openIditem.UserId = item.UserId
  1385. if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1386. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1387. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1388. fmt.Println("AlreadySend:", openIditem.UserId)
  1389. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1390. }
  1391. }
  1392. }
  1393. }
  1394. //fmt.Println("openIditem.UserId:", openIditem.UserId)
  1395. //if _,ok := mapActivityUserId[openIditem.UserId]; ok{
  1396. // first = "您预约的调研,有关联的纪要发布/更新了"
  1397. // keyword1 = industryName
  1398. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1399. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1400. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1401. //}
  1402. }
  1403. _, ok := mapAlreadySend[openIditem.UserId]
  1404. //如果有权限而且小助手没有提交过信息的 就做正常推送
  1405. if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1406. fmt.Println("1:", articleId)
  1407. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1408. }
  1409. //如果小助手勾选了对应的权限信息 就做正常推送
  1410. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != "" && !ok {
  1411. fmt.Println("2:", articleId)
  1412. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1413. }
  1414. }
  1415. } else {
  1416. for k, v := range mapOpenidPower {
  1417. if mapOpenidPushed[k] != "" {
  1418. continue
  1419. }
  1420. mapUserIdChooseSendType := make(map[int]int)
  1421. for _, vS := range chooseSendtList {
  1422. if vS.IsRefuse == 1 {
  1423. continue
  1424. }
  1425. //获取选择主客观赛道的用户
  1426. if reportMapDetail.PermissionType == 1 {
  1427. if vS.IsSubjective == 1 {
  1428. mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1429. }
  1430. } else if reportMapDetail.PermissionType == 2 {
  1431. if vS.IsObjective == 1 {
  1432. mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1433. }
  1434. } else {
  1435. if vS.IsSubjective == 1 || vS.IsObjective == 1 {
  1436. mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1437. }
  1438. }
  1439. }
  1440. openIditem := new(models.OpenIdList)
  1441. openIditem.UserId = k
  1442. openIditem.OpenId = v
  1443. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1444. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1445. mapActivityUserId := make(map[int]string)
  1446. if articleInfo.ReportType == 2 {
  1447. keyword1 = fmt.Sprint("【", industryName, "】赛道有报告发布/更新")
  1448. sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1449. if sliceSubjectId != "" {
  1450. appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1451. if err != nil {
  1452. fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
  1453. return err
  1454. }
  1455. var userIds []string
  1456. if len(appointmentList) > 0 {
  1457. for _, v := range appointmentList {
  1458. //fmt.Println("mapActivityUserId:", v.UserId)
  1459. userIds = append(userIds, strconv.Itoa(v.UserId))
  1460. mapActivityUserId[v.UserId] += v.ActivityName + ","
  1461. }
  1462. userIdstr := strings.Join(userIds, ",")
  1463. openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
  1464. if err != nil {
  1465. fmt.Println("GetOpenIdByUserIds Err:", err.Error())
  1466. return err
  1467. }
  1468. for _, item := range openIdLists {
  1469. //first := "您预约的调研,有关联的纪要发布/更新了"
  1470. //keyword1 := industryName
  1471. openIditem := new(models.OpenIdList)
  1472. openIditem.OpenId = item.OpenId
  1473. openIditem.UserId = item.UserId
  1474. if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1475. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1476. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1477. fmt.Println("AlreadySend:", openIditem.UserId)
  1478. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. //如果有权限而且小助手没有提交过信息的 就做正常推送
  1485. _, ok := mapAlreadySend[openIditem.UserId]
  1486. if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1487. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1488. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1489. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1490. }
  1491. //如果小助手勾选了对应的权限信息 就做正常推送
  1492. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" && mapUserIdChooseSendType[openIditem.UserId] > 0 && !ok {
  1493. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1494. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1495. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1496. }
  1497. }
  1498. }
  1499. utils.Rc.Put(cacheKey, articleId, time.Hour*12)
  1500. return
  1501. }
  1502. // GetSpecialArticleDetailUserPower 处理用户查看专项调研文章详情的权限
  1503. func GetSpecialArticleDetailUserPower(user *models.WxUserItem, articleInfo *models.ArticleDetail) (havePower bool, err error) {
  1504. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  1505. if e != nil {
  1506. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  1507. return
  1508. }
  1509. reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  1510. if e != nil {
  1511. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  1512. return
  1513. }
  1514. if reportMapDetail == nil {
  1515. err = errors.New("GetdetailByCategoryIdP,获取详情失败, ")
  1516. return
  1517. }
  1518. fmt.Println(permissionStr)
  1519. //如果没有对应的升级权限,则返回
  1520. if !strings.Contains(permissionStr, reportMapDetail.ChartPermissionName) {
  1521. return
  1522. } else {
  1523. havePower = true
  1524. }
  1525. return
  1526. }
  1527. //func init() {
  1528. // GetArticNewLabelWhithActivity3Month()
  1529. //}
  1530. // 弘则报告发布日期在三个月以内的
  1531. func GetArticNewLabelWhithActivity3Month() (labelMap map[int]bool, err error) {
  1532. var condition string
  1533. var pars []interface{}
  1534. condition += ` AND publish_date <= ? AND article_id < ? `
  1535. pars = append(pars, time.Now().AddDate(0, -3, 0), utils.SummaryArticleId)
  1536. articleList, e := models.GetArticleList(condition, pars)
  1537. if e != nil {
  1538. err = errors.New("GetArticleList, Err: " + e.Error())
  1539. return
  1540. }
  1541. var articleIds []int
  1542. for _, v := range articleList {
  1543. articleIds = append(articleIds, v.ArticleId)
  1544. }
  1545. if len(articleIds) == 0 {
  1546. return
  1547. }
  1548. pars = make([]interface{}, 0)
  1549. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1550. pars = append(pars, articleIds)
  1551. industrialList, e := models.GetIndustrialArticleGroupManagementList(condition, pars)
  1552. if e != nil {
  1553. err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error())
  1554. return
  1555. }
  1556. labelMap = make(map[int]bool, 0)
  1557. var industrialIds []int
  1558. for _, v := range industrialList {
  1559. industrialIds = append(industrialIds, v.IndustrialManagementId)
  1560. }
  1561. // 获取活动关联的产业
  1562. var groupCond string
  1563. var groupPars []interface{}
  1564. groupCond += ` AND b.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIds)) + `) AND b.source = 1 `
  1565. groupPars = append(groupPars, industrialIds)
  1566. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  1567. if e != nil {
  1568. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  1569. return
  1570. }
  1571. for _, v := range groups {
  1572. labelMap[v.ActivityId] = true
  1573. }
  1574. return
  1575. }
  1576. // HandleArticleCategoryImg 预处理文章的封面图片
  1577. func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeArticle, err error) {
  1578. //研选的五张图片
  1579. detailResearch, e := models.GetConfigByCode("category_research_img_url")
  1580. if e != nil {
  1581. err = errors.New("获取研选的五张图片失败" + e.Error())
  1582. return
  1583. }
  1584. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  1585. //对应分类的所图片
  1586. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  1587. if err != nil {
  1588. err = errors.New("获取对应分类的所图片失败" + err.Error())
  1589. return
  1590. }
  1591. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  1592. mapCategoryUrl := make(map[string]string)
  1593. var categoryId string
  1594. var imgUrlChart string
  1595. for _, v := range categoryUrlList {
  1596. vslice := strings.Split(v, "_")
  1597. categoryId = vslice[0]
  1598. imgUrlChart = vslice[len(vslice)-1]
  1599. mapCategoryUrl[categoryId] = imgUrlChart
  1600. }
  1601. mapChartPerssion := make(map[string]string)
  1602. reportMappingList, err := models.GetReportMappingStrategyAll()
  1603. if err != nil {
  1604. err = errors.New("GetReportMappingStrategyAll err" + err.Error())
  1605. return
  1606. }
  1607. for _, v := range reportMappingList {
  1608. mapChartPerssion[strconv.Itoa(v.CategoryId)] = v.ChartPermissionName
  1609. }
  1610. for k, v := range list {
  1611. list[k].Abstract, _ = GetReportContentTextSub(v.Abstract)
  1612. item := list[k]
  1613. //如果文章一开始的内容是图片,优先展示第一张图片
  1614. if list[k].Annotation == "" {
  1615. imgurl, _ := FixArticleImgUrl(html.UnescapeString(list[k].Body))
  1616. if imgurl != "" {
  1617. list[k].BodyHtml = imgurl
  1618. }
  1619. }
  1620. //newBody, _ := GetReportContentTextSubByarticle(item.Body, item.Annotation, item.ArticleId)
  1621. list[k].Annotation = ArticleAnnotation(item)
  1622. list[k].Body = ""
  1623. list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  1624. if item.Pv > 999 {
  1625. list[k].Pv = 999
  1626. }
  1627. list[k].ChartPermissionName = mapChartPerssion[v.CategoryId]
  1628. //如果是研选系列的任意取五张图片的中的一张
  1629. if v.CategoryId == "0" || v.ArticleId > utils.SummaryArticleId {
  1630. knum := v.ArticleId % 5
  1631. list[k].ImgUrlPc = researchList[knum]
  1632. } else {
  1633. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  1634. }
  1635. list[k].ArticleResponse = 4 // 默认展示核心观点
  1636. //ArticleResponse int `description:"报告类型 0:啥也不是,1研选报告,2:研选纪要,3:研选沙龙,4;核心观点"`
  1637. if list[k].ArticleId >= utils.SummaryArticleId {
  1638. list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
  1639. list[k].IsNeedJump = true
  1640. list[k].ArticleResponse = 1
  1641. //if v.IsReport == 1 {
  1642. // list[k].ArticleResponse = 1
  1643. //} else if v.ArticleTypeName == "纪要" {
  1644. // list[k].ArticleResponse = 2
  1645. //} else if v.ArticleTypeName == "观点" {
  1646. // list[k].ArticleResponse = 3
  1647. //} else if v.ArticleTypeName == "沙龙" {
  1648. // list[k].ArticleResponse = 3
  1649. //} else if v.ArticleTypeName == "路演精华" {
  1650. // list[k].ArticleResponse = 1
  1651. //}
  1652. }
  1653. list[k].Source = 1
  1654. //添加行业默认图片
  1655. if v.ImgUrlPc == "" {
  1656. if v.ChartPermissionName == utils.YI_YAO_NAME {
  1657. list[k].ImgUrlPc = utils.YI_YAO_OTHER_IMG
  1658. } else if v.ChartPermissionName == utils.XIAO_FEI_NAME {
  1659. list[k].ImgUrlPc = utils.XIAO_FEI_OTHER_IMG
  1660. } else if v.ChartPermissionName == utils.KE_JI_NAME {
  1661. list[k].ImgUrlPc = utils.KE_JI_OTHER_IMG
  1662. } else if v.ChartPermissionName == utils.ZHI_ZAO_NAME {
  1663. list[k].ImgUrlPc = utils.ZHI_ZAO_OTHER_IMG
  1664. }
  1665. }
  1666. }
  1667. articleIds := make([]int, 0)
  1668. for i := range list {
  1669. articleIds = append(articleIds, list[i].ArticleId)
  1670. }
  1671. // 报告关联产业信息
  1672. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  1673. if len(articleIds) > 0 {
  1674. var industryCond string
  1675. var industryPars []interface{}
  1676. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1677. industryPars = append(industryPars, articleIds)
  1678. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  1679. if e != nil {
  1680. err = errors.New("GetIndustrialListByarticleId" + e.Error())
  1681. return
  1682. }
  1683. for i := range industryList {
  1684. v := industryList[i]
  1685. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  1686. ArticleId: v.ArticleId,
  1687. IndustrialManagementId: v.IndustrialManagementId,
  1688. IndustryName: v.IndustryName,
  1689. ChartPermissionId: v.ChartPermissionId,
  1690. })
  1691. }
  1692. }
  1693. for k, v := range list {
  1694. if len(industryMap[v.ArticleId]) > 0 {
  1695. list[k].List = industryMap[v.ArticleId]
  1696. } else {
  1697. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  1698. }
  1699. }
  1700. if len(list) == 0 {
  1701. list = make([]*models.HomeArticle, 0)
  1702. }
  1703. items = list
  1704. return
  1705. }
  1706. // 处理核心观点的展示规则
  1707. func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
  1708. if item.ArticleId >= utils.SummaryArticleId {
  1709. item.Annotation = YxArticleAnnotation(item)
  1710. }
  1711. if item.Annotation != "" {
  1712. annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  1713. annotation = strings.Replace(item.Annotation, "&nbsp;", "", -1)
  1714. } else {
  1715. return
  1716. }
  1717. bodyText, _ := GetReportContentTextSubNew(annotation)
  1718. if bodyText == "" {
  1719. return
  1720. }
  1721. if annotation != "" {
  1722. annotation = html.UnescapeString(annotation)
  1723. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1724. docText := doc.Text()
  1725. mapDoc := make(map[int]string)
  1726. var mapSort []int
  1727. p := doc.Find("p")
  1728. p.Each(func(tk int, pd *goquery.Selection) {
  1729. pdText := pd.Text()
  1730. pdText = strings.Replace(pdText, " ", "", -1)
  1731. if pdText != "" {
  1732. textLen := strings.Index(docText, pdText)
  1733. mapDoc[(strings.Index(docText, pdText))] = pdText
  1734. mapSort = append(mapSort, textLen)
  1735. }
  1736. })
  1737. li := doc.Find("li")
  1738. li.Each(func(tk int, li *goquery.Selection) {
  1739. liText := li.Text()
  1740. liText = strings.Replace(liText, " ", "", -1)
  1741. if liText != "" {
  1742. textLen := strings.Index(docText, liText)
  1743. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1744. mapSort = append(mapSort, textLen)
  1745. }
  1746. })
  1747. ul := doc.Find("ul")
  1748. ul.Each(func(tk int, ul *goquery.Selection) {
  1749. ulText := ul.Text()
  1750. ulText = strings.Replace(ulText, " ", "", -1)
  1751. if ulText != "" {
  1752. textLen := strings.Index(docText, ulText)
  1753. mapDoc[(strings.Index(docText, ulText))] = ulText
  1754. mapSort = append(mapSort, textLen)
  1755. }
  1756. })
  1757. if len(mapSort) == 0 {
  1758. return
  1759. } else {
  1760. //排序
  1761. sort.Ints(mapSort)
  1762. var annotationHtml string
  1763. for _, vSort := range mapSort {
  1764. for k, v := range mapDoc {
  1765. if k == vSort && v != "" {
  1766. annotationHtml += v + "<br>"
  1767. }
  1768. }
  1769. }
  1770. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1771. annotationHtml = "<p>" + annotationHtml + "</p>"
  1772. annotation = annotationHtml
  1773. }
  1774. }
  1775. return
  1776. }
  1777. // 处理核心观点的展示规则
  1778. func AnnotationHtml(bodyText string) (annotation string) {
  1779. if bodyText == "" {
  1780. return
  1781. }
  1782. annotation = bodyText
  1783. annotation = html.UnescapeString(annotation)
  1784. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1785. docText := doc.Text()
  1786. mapDoc := make(map[int]string)
  1787. var mapSort []int
  1788. p := doc.Find("p")
  1789. p.Each(func(tk int, pd *goquery.Selection) {
  1790. pdText := pd.Text()
  1791. pdText = strings.Replace(pdText, " ", "", -1)
  1792. if pdText != "" {
  1793. textLen := strings.Index(docText, pdText)
  1794. mapDoc[(strings.Index(docText, pdText))] = pdText
  1795. mapSort = append(mapSort, textLen)
  1796. }
  1797. })
  1798. li := doc.Find("li")
  1799. li.Each(func(tk int, li *goquery.Selection) {
  1800. liText := li.Text()
  1801. liText = strings.Replace(liText, " ", "", -1)
  1802. if liText != "" {
  1803. textLen := strings.Index(docText, liText)
  1804. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1805. mapSort = append(mapSort, textLen)
  1806. }
  1807. })
  1808. ul := doc.Find("ul")
  1809. ul.Each(func(tk int, ul *goquery.Selection) {
  1810. ulText := ul.Text()
  1811. ulText = strings.Replace(ulText, " ", "", -1)
  1812. if ulText != "" {
  1813. textLen := strings.Index(docText, ulText)
  1814. mapDoc[(strings.Index(docText, ulText))] = ulText
  1815. mapSort = append(mapSort, textLen)
  1816. }
  1817. })
  1818. if len(mapSort) == 0 {
  1819. return
  1820. } else {
  1821. //排序
  1822. sort.Ints(mapSort)
  1823. var annotationHtml string
  1824. for _, vSort := range mapSort {
  1825. for k, v := range mapDoc {
  1826. if k == vSort && v != "" {
  1827. annotationHtml += v + "<br>"
  1828. }
  1829. }
  1830. }
  1831. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1832. annotationHtml = "<p>" + annotationHtml + "</p>"
  1833. annotation = annotationHtml
  1834. }
  1835. return
  1836. }
  1837. // 处理产品内测展示规则
  1838. func ProductInteriorHtml(bodyText string) (annotation string) {
  1839. if bodyText == "" {
  1840. return
  1841. }
  1842. sliceBody := strings.Split(bodyText, "</p>")
  1843. annotation, _ = GetReportContentTextSub(sliceBody[0])
  1844. return
  1845. }
  1846. // 解析研选内容中的核心观点
  1847. func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
  1848. //如果不规范,就获取内容主体
  1849. if strings.Count(article.Body, "<hr") == 0 {
  1850. //如果内容不规范而且,还有图片,就把核心观点置空
  1851. if article.BodyHtml != "" {
  1852. return
  1853. }
  1854. annotation, _ = GetReportContentTextSub(article.Body)
  1855. return
  1856. }
  1857. body := strings.ReplaceAll(article.Body, "<strong>", "")
  1858. body = strings.ReplaceAll(body, "</strong>", "")
  1859. body = strings.ReplaceAll(body, "</ol>", "</div>")
  1860. body = strings.ReplaceAll(body, "<ol>", "<div>")
  1861. body = strings.ReplaceAll(body, "</li>", "</p>")
  1862. body = strings.ReplaceAll(body, "<li>", "<p>")
  1863. re, _ := regexp.Compile("<strong.*?>")
  1864. body = re.ReplaceAllString(body, "")
  1865. reLi, _ := regexp.Compile("<li.*?>")
  1866. body = reLi.ReplaceAllString(body, "")
  1867. var plus int
  1868. coreIndex := strings.Index(body, "核心观点:")
  1869. plus = 15
  1870. if coreIndex == -1 {
  1871. coreIndex = strings.Index(body, "核心观点:")
  1872. plus = 13
  1873. }
  1874. if coreIndex == -1 {
  1875. coreIndex = strings.Index(body, "核心观点")
  1876. plus = 12
  1877. }
  1878. if coreIndex == -1 {
  1879. coreIndex = strings.Index(body, "核心结论:")
  1880. plus = 15
  1881. }
  1882. if coreIndex == -1 {
  1883. coreIndex = strings.Index(body, "核心结论:")
  1884. plus = 13
  1885. }
  1886. if coreIndex == -1 {
  1887. coreIndex = strings.Index(body, "核心结论")
  1888. plus = 12
  1889. }
  1890. endIndex := strings.Index(body, "<hr")
  1891. if coreIndex != -1 && endIndex != -1 {
  1892. body = body[coreIndex+plus : endIndex]
  1893. }
  1894. annotation = body
  1895. return
  1896. }
  1897. // 通过接解析带有Md5的文章链接获取文章ID
  1898. func GetReportLinkToArticleid(reportLink string) (articleId int, err error) {
  1899. defer func() {
  1900. if err != nil {
  1901. go utils.SendAlarmMsg("通过接解析带有Md5的文章链接获取文章ID失败"+err.Error(), 2)
  1902. }
  1903. }()
  1904. var artMd5 string
  1905. //处理Md5的
  1906. strnum1 := strings.Index(reportLink, "id=")
  1907. if strnum1 > 0 {
  1908. sliceId := strings.Split(reportLink, "id=")
  1909. if len(sliceId) > 1 {
  1910. reportLink = sliceId[1]
  1911. sliceMd5Id := strings.Split(reportLink, "&")
  1912. artMd5 = sliceMd5Id[0]
  1913. }
  1914. if artMd5 != "" {
  1915. detail, errArt := models.GetArticleDetailByIdMd5(artMd5)
  1916. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  1917. err = errArt
  1918. return
  1919. }
  1920. if detail != nil {
  1921. articleId = detail.ArticleId
  1922. }
  1923. }
  1924. } else {
  1925. //处理活动的
  1926. linkList := strings.Split(reportLink, "/")
  1927. if linkList[len(linkList)-1] != "" {
  1928. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  1929. if linkArticleId > 0 {
  1930. articleInfo, errArt := models.GetArticleDetailById(linkArticleId)
  1931. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  1932. err = errArt
  1933. return
  1934. }
  1935. if articleInfo != nil {
  1936. articleId = articleInfo.ArticleId
  1937. }
  1938. }
  1939. }
  1940. }
  1941. return
  1942. }
  1943. // GetArticleStockMap 获取个股标签所对应的文章ID
  1944. func GetArticleStockMap() (mapResp map[string]int, err error) {
  1945. defer func() {
  1946. if err != nil {
  1947. go utils.SendAlarmMsg("获取个股标签所对应的文章ID失败"+err.Error(), 2)
  1948. }
  1949. }()
  1950. list, err := models.GetArticleStock()
  1951. if err != nil && err.Error() != utils.ErrNoRow() {
  1952. return
  1953. }
  1954. mapResp = make(map[string]int, 0)
  1955. if len(list) > 0 {
  1956. //一对一精准匹配
  1957. for _, v := range list {
  1958. sliceSubjects := strings.Split(v.Stock, "/")
  1959. if len(sliceSubjects) > 0 {
  1960. for _, vSubject := range sliceSubjects {
  1961. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  1962. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  1963. subject := sliceXiahuaxian[0]
  1964. mapResp[subject] = v.ArticleId
  1965. }
  1966. }
  1967. }
  1968. }
  1969. return
  1970. }
  1971. // GetAiQianYanArtilceList 获取AI前沿几篇文章
  1972. func GetAiQianYanArtilceList(startSize, pageSize int) (items []*models.ReportArticle, total int, err error) {
  1973. defer func() {
  1974. if err != nil {
  1975. go utils.SendAlarmMsg("获取AI前沿几篇文章失败"+err.Error(), 2)
  1976. }
  1977. }()
  1978. var condition string
  1979. var pars []interface{}
  1980. condition += ` AND title LIKE '%AI前沿%' AND publish_status = 1 ORDER BY publish_date DESC `
  1981. articleList, e := models.GetCygxCygxArticleList(condition, pars, startSize, pageSize)
  1982. if e != nil {
  1983. err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
  1984. return
  1985. }
  1986. total, e = models.GetCygxArticleCount(condition, pars)
  1987. if e != nil {
  1988. err = errors.New("GetCygxArticleCount, Err: " + e.Error())
  1989. return
  1990. }
  1991. for _, v := range articleList {
  1992. item := new(models.ReportArticle)
  1993. item.ArticleId = v.ArticleId
  1994. item.Title = v.Title
  1995. item.Abstract = v.Abstract
  1996. item.Annotation = v.Annotation
  1997. item.PublishDate = v.PublishDate
  1998. item.Resource = 1
  1999. item.CategoryId = strconv.Itoa(v.CategoryId)
  2000. item.Body = v.Body
  2001. items = append(items, item)
  2002. }
  2003. return
  2004. }
  2005. // 获取文章内部图表的第一张封面图
  2006. func GetArticleCoverByChartFirst(body string) (cover string) {
  2007. var err error
  2008. defer func() {
  2009. if err != nil {
  2010. fmt.Println(err)
  2011. go utils.SendAlarmMsg("获取文章内部图表的第一张封面图失败,Err:"+err.Error()+body, 3)
  2012. }
  2013. }()
  2014. var chartUrl string
  2015. var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
  2016. match := hrefRegexp.FindAllString(body, -1)
  2017. if match != nil {
  2018. for _, v := range match {
  2019. if strings.Contains(v, "charts/display") {
  2020. chartUrl = v
  2021. break
  2022. }
  2023. }
  2024. }
  2025. if chartUrl != "" {
  2026. urlSlice := strings.Split(chartUrl, "/")
  2027. lenurlSlice := len(urlSlice)
  2028. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  2029. if sourceId == 0 {
  2030. sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
  2031. }
  2032. if sourceId == 0 {
  2033. err = errors.New("新的图标链接无法解析" + chartUrl)
  2034. return
  2035. }
  2036. chartUrlApi := utils.ApiUrl + "charts/" + strconv.Itoa(sourceId)
  2037. authorization := utils.ApiAuthorization
  2038. body, e := PublicGetDate(chartUrlApi, authorization)
  2039. if e != nil {
  2040. err = errors.New("PublicGetDate" + err.Error())
  2041. return
  2042. }
  2043. var resultDate models.ChartResultDetailApi
  2044. e = json.Unmarshal(body, &resultDate)
  2045. if e != nil {
  2046. err = errors.New(" json.Unmarshal" + err.Error())
  2047. }
  2048. cover = resultDate.Data.Cover
  2049. }
  2050. return
  2051. }