article.go 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287
  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. UserId int `json:"user_id" description:"用户id"`
  487. ReportId int `json:"report_id" description:"报告id"`
  488. StopTime int `json:"stop_time" description:"停留时间"`
  489. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  490. OutId int `json:"out_id" description:"记录ID"`
  491. }
  492. type ReportViewRecord struct {
  493. Id int `orm:"column(id);pk"`
  494. //UserId int `json:"user_id" description:"用户ID"`
  495. //ReportId int `description:"报告id"`
  496. //Mobile string `description:"手机号"`
  497. //Email string `description:"邮箱"`
  498. //RealName string `description:"用户实际姓名"`
  499. //CompanyName string `description:"公司名称"`
  500. //CreateTime time.Time `description:"创建时间"`
  501. //StopTime int `json:"stop_time" description:"停留时间"`
  502. //ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  503. //OutId int `json:"out_id" description:"记录ID"`
  504. Mobile string `json:"mobile"`
  505. Email string `json:"email"`
  506. RealName string `json:"real_name"`
  507. CompanyName string `json:"company_name"`
  508. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  509. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  510. CompanyId int `json:"company_id" description:"客户id"`
  511. UserId int `json:"user_id" description:"用户id"`
  512. ReportId int `json:"report_id" description:"报告id"`
  513. StopTime int `json:"stop_time" description:"停留时间"`
  514. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  515. OutId int `json:"out_id" description:"章节ID"`
  516. }
  517. // PushViewRecordNewRedisData 阅读数据加入到redis
  518. func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
  519. data := &UserViewRedisData{
  520. Mobile: reportViewRecord.Mobile,
  521. UserId: reportViewRecord.UserId,
  522. Email: reportViewRecord.Email,
  523. RealName: reportViewRecord.RealName,
  524. CompanyName: reportViewRecord.CompanyName,
  525. ViewTime: reportViewRecord.ViewTime,
  526. ProductId: 2,
  527. CompanyId: companyId,
  528. ReportId: reportViewRecord.ReportId,
  529. StopTime: reportViewRecord.StopTime,
  530. ReportChapterId: reportViewRecord.ReportChapterId,
  531. OutId: reportViewRecord.OutId,
  532. }
  533. if utils.Re == nil {
  534. err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
  535. if err != nil {
  536. fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
  537. }
  538. return true
  539. }
  540. return false
  541. }
  542. //func GetCeLueArticlePv() {
  543. // sum := 0
  544. // for i := 0; i <= 450; i++ {
  545. // if i >= 102 {
  546. // //GetCeLueArticlePvs(strconv.Itoa(i * 1000))
  547. // }
  548. // }
  549. // fmt.Println(sum)
  550. //}
  551. // 获取策略平台报告阅读数据
  552. func GetCeLueArticlePv(cont context.Context) (err error) {
  553. defer func() {
  554. if err != nil {
  555. go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
  556. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  557. }
  558. }()
  559. startTime := time.Now().Add(-time.Minute * 12).Format("2006-01-02 15:04:05")
  560. endTime := time.Now().Format("2006-01-02 15:04:05")
  561. requestUrl := utils.ApiUrl + "backend/statistics_access?take=1000&skip=0&sort=ASC&mode=all&"
  562. encodeData := url.Values{}
  563. encodeData.Add("start_dt", startTime)
  564. encodeData.Add("end_dt", endTime)
  565. encodeStr := encodeData.Encode()
  566. requestUrl += encodeStr
  567. authorization := utils.ApiAuthorization
  568. body, err := PublicGetDate(requestUrl, authorization)
  569. if err != nil {
  570. return
  571. }
  572. var chartResult models.CeLueArticleResultApi
  573. err = json.Unmarshal(body, &chartResult)
  574. if err != nil {
  575. fmt.Println(err)
  576. return err
  577. }
  578. mapMobileArticleId := make(map[string]int)
  579. //获取当天阅读记录
  580. listPv, err := models.GetArticleHistoryRecordAllList()
  581. if err != nil && err.Error() != utils.ErrNoRow() {
  582. fmt.Println("获取当天阅读记录失败", err)
  583. return err
  584. }
  585. if len(listPv) > 0 {
  586. for _, v := range listPv {
  587. mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
  588. }
  589. }
  590. for _, v := range chartResult.Data {
  591. //fmt.Println(v.ArticleId)
  592. item := new(models.CygxCelueArticleHistoryRecord)
  593. item.CelueHistoryId = v.CelueHistoryId
  594. item.Mobile = v.Mobile
  595. item.ArticleId = v.ArticleId
  596. if v.CrmUser != nil {
  597. item.RealName = v.CrmUser.RealName
  598. }
  599. if v.CompanyName != nil {
  600. item.CompanyName = v.CompanyName.RealName
  601. }
  602. item.CreateDateApi = time.Now()
  603. t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
  604. item.CreateTime = t1.Add(+time.Hour * 8).Format(utils.FormatDateTime)
  605. count, err := models.GetCeLueArticleCountById(v.CelueHistoryId)
  606. if err != nil && err.Error() != utils.ErrNoRow() {
  607. return err
  608. }
  609. if count == 0 {
  610. _, err := models.AddCeLueArticle(item, mapMobileArticleId)
  611. if err != nil {
  612. fmt.Println(err)
  613. return err
  614. }
  615. }
  616. }
  617. //处理同步过来的阅读记录所属用户
  618. var condition string
  619. condition = ` AND create_time > ` + "'" + startTime + "'"
  620. listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
  621. if err != nil {
  622. fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
  623. }
  624. for _, v := range listArticlePv {
  625. if v.Mobile != "" {
  626. user, err := models.GetWxUserItemByMobile(v.Mobile)
  627. if err != nil && err.Error() != utils.ErrNoRow() {
  628. fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  629. }
  630. if user != nil {
  631. err = models.UpdateCygxArticleHistoryRecordAll(user)
  632. if err != nil {
  633. fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
  634. }
  635. }
  636. }
  637. }
  638. return
  639. }
  640. func GetArticleListByApi(cont context.Context) (err error) {
  641. defer func() {
  642. if err != nil {
  643. //fmt.Println("GetArticleListByApi Err:" + err.Error())
  644. go utils.SendAlarmMsg("同步策略平台数据失败", 2)
  645. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  646. }
  647. }()
  648. listUpdateArticle, err := models.GetArticleCeluePushList()
  649. if err != nil && err.Error() != utils.ErrNoRow() {
  650. return err
  651. }
  652. //如果长度为零就不处理
  653. if len(listUpdateArticle) == 0 {
  654. return err
  655. }
  656. for _, v := range listUpdateArticle {
  657. // 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
  658. err = HandleArticleListByApi(v.ArticleId)
  659. if err != nil {
  660. utils.FileLog.Info("HandleArticleListByApi", err.Error())
  661. }
  662. }
  663. return
  664. }
  665. // 获取策略平台推送过来的文章并更新
  666. func UpdateArticleByRedis() (err error) {
  667. for {
  668. utils.Rc.Brpop(utils.CYGX_ARTICLE_UPDATE_KEY, func(b []byte) {
  669. var log models.CygxArticleCeluePushRedis
  670. if err := json.Unmarshal(b, &log); err != nil {
  671. fmt.Println("json unmarshal wrong!")
  672. go utils.SendAlarmMsg("获取策略平台推送过来的文章并更新处理Redis队列消息失败:"+err.Error()+string(b), 2)
  673. }
  674. // 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
  675. err = HandleArticleListByApi(log.ArticleId)
  676. if err != nil {
  677. utils.FileLog.Info("HandleArticleListByApi", err.Error())
  678. }
  679. })
  680. }
  681. }
  682. //func init() {
  683. // // allList, err := models.GetArticleAll()
  684. // //
  685. // // fmt.Println(err)
  686. // //
  687. // // for _, v := range allList {
  688. // // HandleArticleListByApi(v.ArticleId)
  689. // // }
  690. //
  691. // //for i := 8648; i < 9004; i++ {
  692. // // HandleArticleListByApi(9552)
  693. // //}
  694. // HandleArticleListByApi(9551)
  695. // //UpdateArticleResourceData(9551)
  696. //}
  697. // 处理同步过来的文章
  698. func HandleArticleListByApi(artcleId int) (err error) {
  699. defer func() {
  700. if err != nil {
  701. go utils.SendAlarmMsg("处理同步策略平台数据失败"+"GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), 2)
  702. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), utils.EmailSendToUsers)
  703. }
  704. }()
  705. var clueApiUrl string
  706. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
  707. fmt.Println(clueApiUrl)
  708. authorization := utils.ApiAuthorization
  709. body, err := PublicGetDate(clueApiUrl, authorization)
  710. if err != nil {
  711. fmt.Println(err)
  712. return
  713. }
  714. var articleResultDate models.ArticleDetailResultApi
  715. err = json.Unmarshal(body, &articleResultDate)
  716. if err != nil {
  717. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  718. return err
  719. }
  720. item := new(models.CygxShanghaiCompanyLog)
  721. item.CreateTime = time.Now()
  722. item.Url = clueApiUrl
  723. item.Body = ""
  724. item.Result = string(body)
  725. go models.AddCygxShanghaiCompanyLog(item)
  726. go models.UpdateCygxArticleCeluePush(artcleId)
  727. articleResult := articleResultDate.Data
  728. exitMap := make(map[int]int)
  729. categoryIdMap := make(map[int]int)
  730. classMap := make(map[int]int)
  731. reportMap := make(map[int]int)
  732. summaryMap := make(map[int]int)
  733. listMap, err := models.GetArticleApiMap()
  734. if err != nil {
  735. fmt.Println("GetlistMap Err:", err.Error())
  736. return err
  737. }
  738. openIdList, err := models.GetUserRecordListByMobile(4, utils.ArticleTaskClassMobile)
  739. if err != nil {
  740. fmt.Println(err)
  741. return err
  742. }
  743. fmt.Println(openIdList)
  744. //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
  745. for _, v := range listMap {
  746. exitMap[v.SeriesId] = v.OldId
  747. categoryIdMap[v.SeriesId] = v.OldIdMap
  748. if v.IsClass == 1 {
  749. classMap[v.OldId] = 1
  750. }
  751. if v.IsReport == 1 {
  752. reportMap[v.OldId] = 1
  753. }
  754. if v.IsSummary == 1 {
  755. summaryMap[v.OldId] = 1
  756. }
  757. }
  758. var list []*models.Tactics2
  759. var listArticleData []*models.CygxArticleData
  760. var listAuthor []*models.CygxArticleAuthor
  761. //如果是英文报告 ,或者香港类型那么则不同步 publish_area :all 全部 ;hk 香港
  762. if articleResult.TypeId == 9 || articleResult.PublishArea != "all" {
  763. // 如果是英文报告,或者是香港报告就进行删除处理
  764. err = models.UpdateArticlePublish(artcleId, 0)
  765. if err != nil {
  766. fmt.Println("UpdateArticlePublish Err:", err.Error())
  767. return err
  768. }
  769. UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  770. return
  771. }
  772. var cover string
  773. if articleResult.Series.Name == "图解市场" {
  774. cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
  775. } else if articleResult.Series.Name == "行业深度" {
  776. cover = articleResult.Cover
  777. }
  778. fmt.Println(cover)
  779. //return
  780. //状态等于 2 跟 4 的进行同步 IsActive 为false 软删除的也不同步
  781. if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
  782. 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)
  783. item := new(models.Tactics2)
  784. itemArticleData := new(models.CygxArticleData)
  785. itemArticleData.ArticleId = articleResult.ArticleId
  786. itemArticleData.Cover = articleResult.Cover
  787. itemArticleData.CreateTime = time.Now()
  788. listArticleData = append(listArticleData, itemArticleData)
  789. itemAuthor := new(models.CygxArticleAuthor)
  790. item.ArticleId = articleResult.ArticleId
  791. item.Title = articleResult.Title
  792. item.TitleEn = articleResult.TitleEn
  793. item.File = articleResult.File
  794. if articleResult.Frequency == "日度" {
  795. item.UpdateFrequency = "daily"
  796. } else if articleResult.Frequency == "周度" {
  797. item.UpdateFrequency = "weekly"
  798. } else if articleResult.Frequency == "月度" {
  799. item.UpdateFrequency = "monthly"
  800. } else if articleResult.Frequency == "季度" {
  801. item.UpdateFrequency = "quarterly"
  802. } else if articleResult.Frequency == "年度" {
  803. item.UpdateFrequency = "yearly"
  804. } else {
  805. item.UpdateFrequency = "unknow"
  806. }
  807. item.CreateDate = articleResult.CreateDate
  808. item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
  809. item.PublishStatus = 1
  810. item.Body = articleResult.Content.Body
  811. item.Abstract = articleResult.Content.Abstract
  812. item.Annotation = articleResult.Content.Annotation
  813. item.CategoryName = articleResult.Industry.Name
  814. item.CategoryId = categoryIdMap[articleResult.SeriesId]
  815. item.CategoryIdTwo = exitMap[articleResult.SeriesId]
  816. item.SubCategoryName = articleResult.Series.Name
  817. item.Cover = cover
  818. if len(articleResult.Stock) > 0 {
  819. var stock string
  820. for _, vS := range articleResult.Stock {
  821. stock += vS + "/"
  822. }
  823. stock = strings.TrimRight(stock, "/")
  824. item.Stock = stock
  825. }
  826. item.FieldName = articleResult.Field.Name
  827. item.TypeName = articleResult.Type.Name
  828. item.UpdateDate = articleResult.UpdateDate
  829. item.CeLueFieldId = articleResult.Field.Id
  830. list = append(list, item)
  831. itemAuthor.ArticleId = articleResult.ArticleId
  832. itemAuthor.Name = articleResult.Author.Name
  833. itemAuthor.Mobile = articleResult.Author.PhoneNumber
  834. fmt.Println(articleResult.Cover)
  835. listAuthor = append(listAuthor, itemAuthor)
  836. } else {
  837. // 如果这篇文章没有发布,那么就不作处理。
  838. err = models.UpdateArticlePublish(artcleId, 0)
  839. if err != nil {
  840. fmt.Println("UpdateArticlePublish Err:", err.Error())
  841. return err
  842. }
  843. UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  844. //go UpdateResourceData(artcleId, "article", "delete", time.Now().Format(utils.FormatDateTime))
  845. return
  846. }
  847. //同步作者
  848. for _, v := range listAuthor {
  849. var count int
  850. count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  851. if err != nil {
  852. fmt.Println("GetActivityAuthorCount Err:", err.Error())
  853. return err
  854. }
  855. if count == 0 {
  856. _, err = models.AddCygxActivityAuthor(v)
  857. if err != nil {
  858. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  859. return err
  860. }
  861. }
  862. }
  863. fmt.Println("同步文章条数:", len(list))
  864. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  865. if err != nil {
  866. fmt.Println("GetTacticsList Err:", err.Error())
  867. return err
  868. }
  869. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  870. if errMatch != nil {
  871. fmt.Println("GetTacticsList Err:", errMatch.Error())
  872. return err
  873. }
  874. //mapCategoryIdSet := make(map[int]int)
  875. //for _, vMatch := range listGetMatchTypeName {
  876. // mapCategoryIdSet[vMatch.CategoryId] = vMatch.CategoryIdSet
  877. //}
  878. fmt.Println("list len:", len(list))
  879. 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
  880. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  881. for k, v := range list {
  882. //同步匹配类型
  883. matchTypeName := ""
  884. for _, vMatch := range listGetMatchTypeName {
  885. if v.CategoryId == vMatch.CategoryId {
  886. matchTypeName = vMatch.MatchTypeName
  887. }
  888. }
  889. //是否属于纪要库的数据
  890. //if _, has := summaryMap[v.CategoryId]; has {
  891. // v.IsSummary = 1
  892. //}
  893. if v.TypeName == "纪要" {
  894. v.IsSummary = 1
  895. }
  896. //排除不属于纪要库类型的文章
  897. for _, vArt := range listNoSummaryArticleIds {
  898. vArtInt, _ := strconv.Atoi(vArt)
  899. if v.ArticleId == vArtInt {
  900. v.IsSummary = 0
  901. }
  902. }
  903. if _, has := reportMap[v.CategoryIdTwo]; has {
  904. v.IsReport = 1
  905. if _, ok := classMap[v.CategoryIdTwo]; ok {
  906. v.IsClass = 1
  907. v.ReportType = 1 //是否属于行业报告
  908. } else {
  909. v.ReportType = 2 //是否属于产业报告
  910. }
  911. }
  912. v.Department = "弘则权益研究"
  913. //判断是否已经存在
  914. if v.ArticleId < 0 {
  915. fmt.Println("AddCygxArticle Err:")
  916. return err
  917. }
  918. var count int
  919. count, err = models.GetArticleCountById(v.ArticleId)
  920. if err != nil && err.Error() != utils.ErrNoRow() {
  921. fmt.Println("AddCygxArticle Err:", err.Error())
  922. return err
  923. }
  924. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  925. expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
  926. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  927. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  928. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  929. v.Body = strings.Replace(v.Body, "):", "", -1)
  930. }
  931. var titleNew string
  932. titleNew = v.Title
  933. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  934. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  935. if v.UpdateFrequency == "daily" {
  936. var daystr string
  937. daystr = strconv.Itoa(v.PublishDate.Day())
  938. if len(daystr) == 1 {
  939. daystr = "0" + daystr
  940. }
  941. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  942. } else if v.UpdateFrequency == "weekly" {
  943. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  944. }
  945. }
  946. if v.CategoryId == 80 {
  947. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  948. }
  949. //类型是综述报告的,不区分是什么系列,统一归类到对应产业的路演精华
  950. if articleResult.Type.Name == "综述报告" {
  951. detailCategory, err := models.GetdetailByCategoryIdLyjh(v.CategoryIdTwo)
  952. if err != nil && err.Error() != utils.ErrNoRow() {
  953. return err
  954. }
  955. v.CategoryId = detailCategory.CategoryId
  956. v.IsSummary = 0
  957. }
  958. if count > 0 {
  959. fmt.Println(k, v.ArticleId, "edit")
  960. articleIfoOld, e := models.GetArticleDetailTestById(v.ArticleId)
  961. if e != nil {
  962. err = e
  963. return
  964. }
  965. bodyTextOld, _ := GetReportContentTextSubNew(articleIfoOld.Body)
  966. bodyText, _ := GetReportContentTextSubNew(v.Body)
  967. if len(bodyText)-len(bodyTextOld) > 100 {
  968. //fmt.Println("触发推送规则")
  969. //更新字数大于一百字触发推送规则
  970. go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  971. go UpdateArticleResourceData(v.ArticleId) //把数据写入 cygx_resource_data 表
  972. //go UpdateResourceData(v.ArticleId, "article", "update", time.Now().Format(utils.FormatDateTime))
  973. }
  974. var isCustom bool
  975. updateParams := make(map[string]interface{})
  976. //updateParams["Title"] = v.Title
  977. updateParams["Title"] = titleNew
  978. updateParams["TitleEn"] = v.TitleEn
  979. updateParams["UpdateFrequency"] = v.UpdateFrequency
  980. updateParams["CreateDate"] = v.CreateDate
  981. updateParams["PublishDate"] = v.PublishDate
  982. //updateParams["Body"] = html.EscapeString(v.Body)
  983. updateParams["Body"] = html.EscapeString(bodyReturn)
  984. updateParams["BodyText"] = bodyText
  985. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  986. updateParams["CategoryName"] = v.CategoryName
  987. for _, vCustom := range listCustomArticle {
  988. if v.ArticleId == vCustom.ArticleId {
  989. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  990. isCustom = true
  991. }
  992. }
  993. if isCustom == false {
  994. updateParams["CategoryId"] = v.CategoryId
  995. updateParams["MatchTypeName"] = matchTypeName
  996. updateParams["IsSummary"] = v.IsSummary
  997. updateParams["IsReport"] = v.IsReport
  998. updateParams["ReportType"] = v.ReportType
  999. updateParams["SubCategoryName"] = v.SubCategoryName
  1000. }
  1001. //updateParams["CategoryId"] = v.CategoryId
  1002. updateParams["PublishStatus"] = 1
  1003. updateParams["ExpertBackground"] = expertContentStr
  1004. updateParams["ExpertNumber"] = expertNumStr
  1005. updateParams["InterviewDate"] = interviewDateStr
  1006. //updateParams["IsClass"] = v.IsClass
  1007. v.Department = "弘则权益研究"
  1008. updateParams["Department"] = v.Department
  1009. updateParams["FileLink"] = v.File
  1010. updateParams["Stock"] = v.Stock
  1011. updateParams["FieldName"] = v.FieldName
  1012. updateParams["Annotation"] = v.Annotation
  1013. updateParams["TypeName"] = v.TypeName
  1014. updateParams["ModifyTimeByCl"] = v.UpdateDate
  1015. updateParams["CeLueFieldId"] = v.CeLueFieldId
  1016. updateParams["Cover"] = v.Cover
  1017. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  1018. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  1019. if err != nil {
  1020. fmt.Println("UpdateByExpr Err:" + err.Error())
  1021. return err
  1022. }
  1023. } else {
  1024. fmt.Println(k, v.ArticleId, "add")
  1025. item := new(models.CygxArticle)
  1026. articleIdInt := v.ArticleId
  1027. item.ArticleId = articleIdInt
  1028. //item.Title = v.Title
  1029. item.Title = titleNew
  1030. item.TitleEn = v.TitleEn
  1031. item.UpdateFrequency = v.UpdateFrequency
  1032. item.CreateDate = v.CreateDate
  1033. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  1034. //item.Body = html.EscapeString(v.Body)
  1035. item.Body = html.EscapeString(bodyReturn)
  1036. item.Abstract = html.EscapeString(v.Abstract)
  1037. item.CategoryName = v.CategoryName
  1038. item.SubCategoryName = v.SubCategoryName
  1039. item.CategoryId = v.CategoryId
  1040. item.CategoryIdTwo = v.CategoryIdTwo
  1041. item.PublishStatus = 1
  1042. item.ExpertBackground = expertContentStr
  1043. item.ExpertNumber = expertNumStr
  1044. item.InterviewDate = interviewDateStr
  1045. item.Department = v.Department
  1046. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  1047. item.IsClass = v.IsClass
  1048. item.IsSummary = v.IsSummary
  1049. item.IsReport = v.IsReport
  1050. item.ReportType = v.ReportType
  1051. item.FileLink = v.File
  1052. item.MatchTypeName = matchTypeName
  1053. item.Stock = v.Stock
  1054. item.FieldName = v.FieldName
  1055. item.Annotation = v.Annotation
  1056. item.TypeName = v.TypeName
  1057. item.ModifyTimeByCl = v.UpdateDate
  1058. item.CeLueFieldId = v.CeLueFieldId
  1059. item.Cover = v.Cover
  1060. newId, err := models.AddCygxArticles(item)
  1061. if err != nil {
  1062. fmt.Println("AddCygxArticle Err:", err.Error())
  1063. return err
  1064. }
  1065. //go UpdateResourceData(v.ArticleId, "article", "add", time.Now().Format(utils.FormatDateTime))
  1066. go UpdateArticleResourceData(v.ArticleId) //把数据写入 cygx_resource_data 表
  1067. //fmt.Println(newId)
  1068. //报告自动归类,以及推送相关模板消息
  1069. if v.ReportType == 2 {
  1070. var subjectStr string
  1071. var industrialManagementIdStr string
  1072. var industrialSubjectIdStr string
  1073. var keyword1 string
  1074. var keyword2 string
  1075. var keyword3 string
  1076. var keyword4 string
  1077. sliceSubjects := strings.Split(v.Stock, "/")
  1078. mapManagementForSubject := make(map[string]string)
  1079. mapIndustrialId := make(map[int]int)
  1080. if len(sliceSubjects) > 0 {
  1081. for _, vSubject := range sliceSubjects {
  1082. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  1083. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  1084. subject := sliceXiahuaxian[0]
  1085. subjectStr += "'" + subject + "',"
  1086. }
  1087. //获取该产业下所对应的行业图片
  1088. detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
  1089. if errCategory != nil {
  1090. fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
  1091. return err
  1092. }
  1093. subjectStr = strings.TrimRight(subjectStr, ",")
  1094. if subjectStr != "" {
  1095. listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
  1096. if err != nil {
  1097. fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
  1098. return err
  1099. }
  1100. subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
  1101. subjectStr = strings.Replace(subjectStr, "'", "", -1)
  1102. subjectStr = "【" + subjectStr + "】"
  1103. if len(listIndustrial) > 0 {
  1104. for _, vIndustrial := range listIndustrial {
  1105. if _, ok := mapIndustrialId[vIndustrial.IndustrialManagementId]; !ok {
  1106. industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
  1107. }
  1108. mapIndustrialId[vIndustrial.IndustrialManagementId] = vIndustrial.IndustrialManagementId
  1109. industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
  1110. mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
  1111. if vIndustrial.LayoutTime == "0000-00-00 00:00:00" {
  1112. go models.UpdateIndustrialManagementLayoutTime(v.PublishDate.AddDate(0, 0, -10).Format(utils.FormatDateTime), vIndustrial.IndustrialManagementId)
  1113. }
  1114. }
  1115. industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
  1116. industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
  1117. if industrialManagementIdStr != "" {
  1118. err = models.ReportArticleClassificationEditNew(int(newId), industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
  1119. if err != nil {
  1120. fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
  1121. return err
  1122. }
  1123. }
  1124. var peoductName string
  1125. for mk, mv := range mapManagementForSubject {
  1126. peoductName += "【" + mk + "--" + strings.TrimRight(mv, "/") + "】"
  1127. }
  1128. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  1129. keyword2 = "已自动关联至以下产业和标的:" + peoductName
  1130. keyword3 = v.Title
  1131. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  1132. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  1133. } else {
  1134. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  1135. keyword2 = "未归类"
  1136. keyword3 = v.Title
  1137. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  1138. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  1139. go models.UpdateIsClassFail(artcleId)
  1140. }
  1141. }
  1142. }
  1143. }
  1144. go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  1145. }
  1146. //【公司调研】系列纪要发布/更新后 end
  1147. //查研观向6.9模板消息推送规则
  1148. //但是如果报告的发布时间是在10天以前的,公众号就不推送了
  1149. //if time.Now().AddDate(0, 0, -10).Before(articleResult.PublishDate.Add(time.Hour * 8)) {
  1150. // go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  1151. //}
  1152. }
  1153. go models.UpdateCygxArticleCeluePush(artcleId)
  1154. AddComprehensiveArticle(artcleId) // 同步到综合页面的搜索引擎
  1155. AddComprehensiveIndustrialSource("Hz", artcleId) // 同步到综合页面的搜索引擎(添加产业资源包)
  1156. GetSummarytoEs(artcleId) // 同步到ES搜索引擎
  1157. GetIndustrialManagementArticleNewPublishData()
  1158. if len(listArticleData) > 0 {
  1159. for _, v := range listArticleData {
  1160. count, err := models.GetCygxArticleDataCount(v.ArticleId)
  1161. if err != nil {
  1162. fmt.Println("GetCygxArticleDataCount Err:", err.Error())
  1163. return err
  1164. }
  1165. if count == 0 {
  1166. _, err := models.AddCygxArticleData(v)
  1167. if err != nil {
  1168. fmt.Println("AddCygxArticleData Err:", err.Error())
  1169. return err
  1170. }
  1171. }
  1172. //} else {
  1173. // updateParams := make(map[string]interface{})
  1174. // updateParams["Cover"] = v.Cover
  1175. // whereParam := map[string]interface{}{"article_id": v.ArticleId}
  1176. // err = models.UpdateByExpr(models.CygxArticleData{}, whereParam, updateParams)
  1177. // if err != nil {
  1178. // fmt.Println("UpdateByExpr CygxArticleData Err:" + err.Error())
  1179. // return err
  1180. // }
  1181. //}
  1182. }
  1183. }
  1184. AddCygxReportMappingCategoryGroupByArticleId(artcleId)
  1185. return err
  1186. }
  1187. //func init() {
  1188. // DoArticleOnenIdWxTemplateMsg(8112)
  1189. //}
  1190. // 过滤策略平台报告,研选报告重复推送,以及权限勾选的推送
  1191. func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
  1192. //策略平台同步过来的文章ID,做微信模板消息推送,同一篇报告12小时只推送一次
  1193. cacheKey := fmt.Sprint(utils.CACHE_KEY_ARTICLE_ID_TEMPLATE, ":ArticleId", articleId)
  1194. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  1195. if ttlTime > 0 {
  1196. fmt.Println(ttlTime)
  1197. return err
  1198. }
  1199. var msg string
  1200. defer func() {
  1201. if err != nil {
  1202. go utils.SendAlarmMsg("处理同步策略平台数据失败"+"GetArticleListByApi ErrMsg:"+err.Error(), 2)
  1203. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  1204. fmt.Println(err)
  1205. }
  1206. if msg != "" {
  1207. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1208. }
  1209. }()
  1210. //获取文章详情
  1211. articleInfo, err := models.GetArticleDetailById(articleId)
  1212. if err != nil {
  1213. return
  1214. }
  1215. articleInfo.Abstract, _ = GetReportContentTextSub(articleInfo.Abstract)
  1216. var chartPermissionId int
  1217. //固收的权限,暂时当策略的逻辑一样处理
  1218. var chartPermissionName string
  1219. reportMapDetail, err := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  1220. if err != nil {
  1221. return err
  1222. }
  1223. if reportMapDetail.ChartPermissionId == utils.CE_LUE_ID {
  1224. chartPermissionId = utils.CE_LUE_ID
  1225. } else if reportMapDetail.ChartPermissionId == utils.GU_SHOU_ID_CHART {
  1226. chartPermissionId = utils.GU_SHOU_ID_CHART
  1227. } else {
  1228. if reportMapDetail.PermissionType == 1 {
  1229. chartPermissionName = reportMapDetail.ChartPermissionName + "(主观)"
  1230. } else {
  1231. chartPermissionName = reportMapDetail.ChartPermissionName + "(客观)"
  1232. }
  1233. chartPermissionDetail, err := models.GetChartPermissionByRemark(chartPermissionName)
  1234. if err != nil {
  1235. return err
  1236. }
  1237. chartPermissionId = chartPermissionDetail.ChartPermissionId
  1238. }
  1239. //文章关联的产业
  1240. var industryName string
  1241. var industrialManagementId string
  1242. if chartPermissionId == utils.CE_LUE_ID || chartPermissionId == utils.GU_SHOU_ID_CHART {
  1243. industryName = reportMapDetail.SubCategoryName
  1244. } else {
  1245. if articleInfo.ReportType == 2 {
  1246. detailIndustryNameList, err := models.GetIndustrialManagemenDetailByAaticleID(articleId)
  1247. if err != nil && err.Error() != utils.ErrNoRow() {
  1248. return err
  1249. }
  1250. //如果不存在关联的产业则不推送
  1251. if len(detailIndustryNameList) == 0 {
  1252. return err
  1253. }
  1254. for _, v := range detailIndustryNameList {
  1255. industryName += v.IndustryName + ","
  1256. industrialManagementId += strconv.Itoa(v.IndustrialManagementId) + ","
  1257. }
  1258. industryName = strings.TrimRight(industryName, ",")
  1259. industrialManagementId = strings.TrimRight(industrialManagementId, ",")
  1260. //处理勾选了全部行业赛道的用户
  1261. var allIn string
  1262. allIn = DoXzsChooseSend(reportMapDetail.ChartPermissionName)
  1263. if allIn != "" {
  1264. allInList, err := models.GetCygxXzsChooseSendByAllIn(allIn)
  1265. if err != nil && err.Error() != utils.ErrNoRow() {
  1266. return err
  1267. }
  1268. if len(allInList) > 0 {
  1269. var allInUserId string
  1270. for _, v := range allInList {
  1271. allInUserId += strconv.Itoa(v.UserId) + ","
  1272. }
  1273. allInUserId = strings.TrimRight(allInUserId, ",")
  1274. userFllowIndustrialList, err := models.GetUserFllowIndustrialListByUserIdAndIndustrial(allInUserId, industrialManagementId)
  1275. if err != nil && err.Error() != utils.ErrNoRow() {
  1276. return err
  1277. }
  1278. mapUserFllowed := make(map[string]int)
  1279. for _, v := range userFllowIndustrialList {
  1280. //用户ID与其关注的产业组成唯一索引,判断是否存在,如果不存在就进行自动关注
  1281. mapUserFllowed[fmt.Sprint("uid:", v.UserId, "_Industrial:", v.IndustrialManagementId)] = v.UserId
  1282. }
  1283. //获取这些allIN用户的的信息进行遍历生成需要插入的数据
  1284. userList, err := models.GetWxUserListByUserIds(allInUserId)
  1285. if err != nil && err.Error() != utils.ErrNoRow() {
  1286. return err
  1287. }
  1288. var industryFllowItems []*models.CygxIndustryFllow
  1289. for _, v := range detailIndustryNameList {
  1290. for _, vUser := range userList {
  1291. //如果用户这个用户没有关注这个产业就进行自动关注
  1292. if mapUserFllowed[fmt.Sprint("uid:", vUser.UserId, "_Industrial:", v.IndustrialManagementId)] == 0 {
  1293. item := new(models.CygxIndustryFllow)
  1294. item.IndustrialManagementId = v.IndustrialManagementId
  1295. item.UserId = vUser.UserId
  1296. item.Email = vUser.Email
  1297. item.Mobile = vUser.Mobile
  1298. item.RealName = vUser.RealName
  1299. item.CompanyId = vUser.CompanyId
  1300. item.CompanyName = vUser.CompanyName
  1301. item.Source = 3
  1302. item.Type = 1
  1303. item.CreateTime = time.Now()
  1304. item.ModifyTime = time.Now()
  1305. industryFllowItems = append(industryFllowItems, item)
  1306. }
  1307. }
  1308. }
  1309. err = models.AddCygxIndustryFllowMulti(industryFllowItems)
  1310. if err != nil {
  1311. go utils.SendAlarmMsg("用户关注全部赛道,出现新赛道批量添加失败 ,AddCygxIndustryFllowMulti ErrMsg:"+err.Error(), 2)
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }
  1317. // 获取所有有权的用户的 openid
  1318. mapOpenidPower := make(map[int]string)
  1319. permissionIdList := make([]string, 0)
  1320. var condition string
  1321. var pars []interface{}
  1322. slicepermissionId := strings.Split(strconv.Itoa(chartPermissionId), ",")
  1323. if len(slicepermissionId) > 0 {
  1324. for _, v := range slicepermissionId {
  1325. if v == strconv.Itoa(utils.GU_SHOU_ID_CHART) {
  1326. v = strconv.Itoa(utils.CE_LUE_ID)
  1327. }
  1328. permissionIdList = append(permissionIdList, v)
  1329. }
  1330. condition += ` AND p.chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) `
  1331. pars = append(pars, permissionIdList)
  1332. }
  1333. openidPowerListMobile, err := models.GetCygxUserRecordPower(condition, pars)
  1334. if err != nil {
  1335. return err
  1336. }
  1337. var mobileArr []string
  1338. for _, v := range openidPowerListMobile {
  1339. mobileArr = append(mobileArr, v.Mobile)
  1340. }
  1341. openidPowerList, err := models.GetWxOpenIdByMobileSliceList(mobileArr)
  1342. if err != nil {
  1343. return err
  1344. }
  1345. //四大行业的行业综述报告,对所有开通了对应行业权限的客户都推送。
  1346. if articleInfo.ReportType == 1 && chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID_CHART {
  1347. for _, item := range openidPowerList {
  1348. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1349. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1350. openIditem := new(models.OpenIdList)
  1351. openIditem.OpenId = item.OpenId
  1352. openIditem.UserId = item.UserId
  1353. SendWxMsgWithArticleUpdate(first, keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIditem, articleId)
  1354. }
  1355. return err
  1356. }
  1357. for _, v := range openidPowerList {
  1358. mapOpenidPower[v.UserId] = v.OpenId
  1359. }
  1360. //获取关注这个文章对应产业的用户的 openid
  1361. mapOpenidFllow := make(map[int]string)
  1362. if chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID_CHART {
  1363. openidFllowListMobile, err := models.GetCygxUserFllowOpenid(articleId)
  1364. if err != nil {
  1365. return err
  1366. }
  1367. var mobileArrFllow []string
  1368. for _, v := range openidFllowListMobile {
  1369. mobileArrFllow = append(mobileArrFllow, v.Mobile)
  1370. }
  1371. openidFllowList, err := models.GetWxOpenIdByMobileSliceList(mobileArrFllow)
  1372. if err != nil {
  1373. return err
  1374. }
  1375. for _, v := range openidFllowList {
  1376. mapOpenidFllow[v.UserId] = v.OpenId
  1377. }
  1378. }
  1379. //获取拒绝接收推送的的用户的 openid
  1380. mapOpenidRefuset := make(map[int]string)
  1381. openidRefusetList, err := models.GetCygxUserRefusetOpenid()
  1382. if err != nil {
  1383. return err
  1384. }
  1385. for _, v := range openidRefusetList {
  1386. mapOpenidRefuset[v.UserId] = v.OpenId
  1387. }
  1388. //获取提交过推送规则的用户的 openid
  1389. mapUserIdChooseSend := make(map[int]int)
  1390. mapUserIdChooseSendTypeNoPermission := make(map[int]int)
  1391. chooseSendtList, err := models.GetCygxXzsChooseSend()
  1392. for _, v := range chooseSendtList {
  1393. mapUserIdChooseSend[v.UserId] = v.UserId
  1394. if v.IsRefuse == 1 {
  1395. continue
  1396. }
  1397. //获取选择主客观赛道的用户
  1398. if reportMapDetail.PermissionType == 1 {
  1399. if v.IsSubjective == 1 {
  1400. mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1401. }
  1402. } else {
  1403. if v.IsObjective == 1 {
  1404. mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1405. }
  1406. }
  1407. }
  1408. //已经推送了的openid
  1409. mapOpenidPushed := make(map[int]string)
  1410. keyword2 := articleInfo.Title
  1411. keyword3 := time.Now().Format(utils.FormatDateTime)
  1412. keyword4 := articleInfo.Abstract
  1413. mapAlreadySend := make(map[int]int)
  1414. //如果是策略就按照策略的推送方式来写
  1415. if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME || reportMapDetail.ChartPermissionName == utils.GU_SHOU_NAME {
  1416. //获取提交过推送规则的用户的 openid
  1417. mapUserFllowCeLue := make(map[int]string)
  1418. userFllowCeLueList, err := models.GetCygxUserFllowCeLueOpenid(articleInfo.CategoryId)
  1419. if err != nil {
  1420. return err
  1421. }
  1422. for _, v := range userFllowCeLueList {
  1423. mapUserFllowCeLue[v.UserId] = v.OpenId
  1424. }
  1425. for k, v := range mapOpenidPower {
  1426. if mapOpenidPushed[k] != "" {
  1427. continue
  1428. }
  1429. openIditem := new(models.OpenIdList)
  1430. openIditem.UserId = k
  1431. openIditem.OpenId = v
  1432. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1433. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1434. mapActivityUserId := make(map[int]string)
  1435. if articleInfo.ReportType == 2 {
  1436. sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1437. if sliceSubjectId != "" {
  1438. appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1439. if err != nil {
  1440. fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
  1441. return err
  1442. }
  1443. var userIds []string
  1444. if len(appointmentList) > 0 {
  1445. for _, v := range appointmentList {
  1446. //fmt.Println("mapActivityUserId:", v.UserId)
  1447. userIds = append(userIds, strconv.Itoa(v.UserId))
  1448. mapActivityUserId[v.UserId] += v.ActivityName + ","
  1449. }
  1450. userIdstr := strings.Join(userIds, ",")
  1451. openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
  1452. if err != nil {
  1453. fmt.Println("GetOpenIdByUserIds Err:", err.Error())
  1454. return err
  1455. }
  1456. for _, item := range openIdLists {
  1457. first := "您预约的调研,有关联的纪要发布/更新了"
  1458. keyword1 := industryName
  1459. openIditem := new(models.OpenIdList)
  1460. openIditem.OpenId = item.OpenId
  1461. openIditem.UserId = item.UserId
  1462. if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1463. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1464. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1465. fmt.Println("AlreadySend:", openIditem.UserId)
  1466. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1467. }
  1468. }
  1469. }
  1470. }
  1471. //fmt.Println("openIditem.UserId:", openIditem.UserId)
  1472. //if _,ok := mapActivityUserId[openIditem.UserId]; ok{
  1473. // first = "您预约的调研,有关联的纪要发布/更新了"
  1474. // keyword1 = industryName
  1475. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1476. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1477. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1478. //}
  1479. }
  1480. _, ok := mapAlreadySend[openIditem.UserId]
  1481. //如果有权限而且小助手没有提交过信息的 就做正常推送
  1482. if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1483. fmt.Println("1:", articleId)
  1484. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1485. }
  1486. //如果小助手勾选了对应的权限信息 就做正常推送
  1487. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != "" && !ok {
  1488. fmt.Println("2:", articleId)
  1489. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1490. }
  1491. }
  1492. } else {
  1493. for k, v := range mapOpenidPower {
  1494. if mapOpenidPushed[k] != "" {
  1495. continue
  1496. }
  1497. mapUserIdChooseSendType := make(map[int]int)
  1498. for _, vS := range chooseSendtList {
  1499. if vS.IsRefuse == 1 {
  1500. continue
  1501. }
  1502. //获取选择主客观赛道的用户
  1503. if reportMapDetail.PermissionType == 1 {
  1504. if vS.IsSubjective == 1 {
  1505. mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1506. }
  1507. } else if reportMapDetail.PermissionType == 2 {
  1508. if vS.IsObjective == 1 {
  1509. mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1510. }
  1511. } else {
  1512. if vS.IsSubjective == 1 || vS.IsObjective == 1 {
  1513. mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1514. }
  1515. }
  1516. }
  1517. openIditem := new(models.OpenIdList)
  1518. openIditem.UserId = k
  1519. openIditem.OpenId = v
  1520. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1521. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1522. mapActivityUserId := make(map[int]string)
  1523. if articleInfo.ReportType == 2 {
  1524. keyword1 = fmt.Sprint("【", industryName, "】有报告发布/更新")
  1525. sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1526. if sliceSubjectId != "" {
  1527. appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1528. if err != nil {
  1529. fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
  1530. return err
  1531. }
  1532. var userIds []string
  1533. if len(appointmentList) > 0 {
  1534. for _, v := range appointmentList {
  1535. //fmt.Println("mapActivityUserId:", v.UserId)
  1536. userIds = append(userIds, strconv.Itoa(v.UserId))
  1537. mapActivityUserId[v.UserId] += v.ActivityName + ","
  1538. }
  1539. userIdstr := strings.Join(userIds, ",")
  1540. openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
  1541. if err != nil {
  1542. fmt.Println("GetOpenIdByUserIds Err:", err.Error())
  1543. return err
  1544. }
  1545. for _, item := range openIdLists {
  1546. //first := "您预约的调研,有关联的纪要发布/更新了"
  1547. //keyword1 := industryName
  1548. openIditem := new(models.OpenIdList)
  1549. openIditem.OpenId = item.OpenId
  1550. openIditem.UserId = item.UserId
  1551. if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1552. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1553. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1554. fmt.Println("AlreadySend:", openIditem.UserId)
  1555. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1556. }
  1557. }
  1558. }
  1559. }
  1560. }
  1561. //如果有权限而且小助手没有提交过信息的 就做正常推送
  1562. _, ok := mapAlreadySend[openIditem.UserId]
  1563. if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1564. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1565. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1566. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1567. }
  1568. //如果小助手勾选了对应的权限信息 就做正常推送
  1569. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" && mapUserIdChooseSendType[openIditem.UserId] > 0 && !ok {
  1570. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1571. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1572. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1573. }
  1574. }
  1575. }
  1576. utils.Rc.Put(cacheKey, articleId, time.Hour*12)
  1577. return
  1578. }
  1579. // GetSpecialArticleDetailUserPower 处理用户查看专项调研文章详情的权限
  1580. func GetSpecialArticleDetailUserPower(user *models.WxUserItem, articleInfo *models.ArticleDetail) (havePower bool, err error) {
  1581. userType, _, e := GetUserType(user.CompanyId)
  1582. if e != nil {
  1583. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  1584. return
  1585. }
  1586. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  1587. if userType == 1 || userType == 2 {
  1588. havePower = true
  1589. return
  1590. }
  1591. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  1592. if e != nil {
  1593. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  1594. return
  1595. }
  1596. reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  1597. if e != nil {
  1598. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  1599. return
  1600. }
  1601. if reportMapDetail == nil {
  1602. err = errors.New("GetdetailByCategoryIdP,获取详情失败, ")
  1603. return
  1604. }
  1605. fmt.Println(permissionStr)
  1606. //如果没有对应的升级权限,则返回
  1607. if !strings.Contains(permissionStr, reportMapDetail.ChartPermissionName) {
  1608. return
  1609. } else {
  1610. havePower = true
  1611. }
  1612. return
  1613. }
  1614. //func init() {
  1615. // GetArticNewLabelWhithActivity3Month()
  1616. //}
  1617. // 弘则报告发布日期在三个月以内的
  1618. func GetArticNewLabelWhithActivity3Month() (labelMap map[int]bool, err error) {
  1619. var condition string
  1620. var pars []interface{}
  1621. condition += ` AND publish_date <= ? AND article_id < ? `
  1622. pars = append(pars, time.Now().AddDate(0, -3, 0), utils.SummaryArticleId)
  1623. articleList, e := models.GetArticleList(condition, pars)
  1624. if e != nil {
  1625. err = errors.New("GetArticleList, Err: " + e.Error())
  1626. return
  1627. }
  1628. var articleIds []int
  1629. for _, v := range articleList {
  1630. articleIds = append(articleIds, v.ArticleId)
  1631. }
  1632. if len(articleIds) == 0 {
  1633. return
  1634. }
  1635. pars = make([]interface{}, 0)
  1636. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1637. pars = append(pars, articleIds)
  1638. industrialList, e := models.GetIndustrialArticleGroupManagementList(condition, pars)
  1639. if e != nil {
  1640. err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error())
  1641. return
  1642. }
  1643. labelMap = make(map[int]bool, 0)
  1644. var industrialIds []int
  1645. for _, v := range industrialList {
  1646. industrialIds = append(industrialIds, v.IndustrialManagementId)
  1647. }
  1648. // 获取活动关联的产业
  1649. var groupCond string
  1650. var groupPars []interface{}
  1651. groupCond += ` AND b.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIds)) + `) AND b.source = 1 `
  1652. groupPars = append(groupPars, industrialIds)
  1653. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  1654. if e != nil {
  1655. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  1656. return
  1657. }
  1658. for _, v := range groups {
  1659. labelMap[v.ActivityId] = true
  1660. }
  1661. return
  1662. }
  1663. // HandleArticleCategoryImg 预处理文章的封面图片
  1664. func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeArticle, err error) {
  1665. //研选的五张图片
  1666. detailResearch, e := models.GetConfigByCode("category_research_img_url")
  1667. if e != nil {
  1668. err = errors.New("获取研选的五张图片失败" + e.Error())
  1669. return
  1670. }
  1671. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  1672. //对应分类的所图片
  1673. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  1674. if err != nil {
  1675. err = errors.New("获取对应分类的所图片失败" + err.Error())
  1676. return
  1677. }
  1678. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  1679. mapCategoryUrl := make(map[string]string)
  1680. var categoryId string
  1681. var imgUrlChart string
  1682. for _, v := range categoryUrlList {
  1683. vslice := strings.Split(v, "_")
  1684. categoryId = vslice[0]
  1685. imgUrlChart = vslice[len(vslice)-1]
  1686. mapCategoryUrl[categoryId] = imgUrlChart
  1687. }
  1688. mapChartPerssion := make(map[string]string)
  1689. reportMappingList, err := models.GetReportMappingStrategyAll()
  1690. if err != nil {
  1691. err = errors.New("GetReportMappingStrategyAll err" + err.Error())
  1692. return
  1693. }
  1694. for _, v := range reportMappingList {
  1695. mapChartPerssion[strconv.Itoa(v.CategoryId)] = v.ChartPermissionName
  1696. }
  1697. for k, v := range list {
  1698. list[k].Abstract, _ = GetReportContentTextSub(v.Abstract)
  1699. item := list[k]
  1700. //如果文章一开始的内容是图片,优先展示第一张图片
  1701. if list[k].Annotation == "" {
  1702. imgurl, _ := FixArticleImgUrl(html.UnescapeString(list[k].Body))
  1703. if imgurl != "" {
  1704. list[k].BodyHtml = imgurl
  1705. }
  1706. }
  1707. //newBody, _ := GetReportContentTextSubByarticle(item.Body, item.Annotation, item.ArticleId)
  1708. list[k].Annotation = ArticleAnnotation(item)
  1709. list[k].Body = ""
  1710. list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  1711. if item.Pv > 999 {
  1712. list[k].Pv = 999
  1713. }
  1714. list[k].ChartPermissionName = mapChartPerssion[v.CategoryId]
  1715. //如果是研选系列的任意取五张图片的中的一张
  1716. if v.CategoryId == "0" || v.ArticleId > utils.SummaryArticleId {
  1717. knum := v.ArticleId % 5
  1718. list[k].ImgUrlPc = researchList[knum]
  1719. } else {
  1720. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  1721. }
  1722. list[k].ArticleResponse = 4 // 默认展示核心观点
  1723. //ArticleResponse int `description:"报告类型 0:啥也不是,1研选报告,2:研选纪要,3:研选沙龙,4;核心观点"`
  1724. if list[k].ArticleId >= utils.SummaryArticleId {
  1725. list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
  1726. list[k].IsNeedJump = true
  1727. list[k].ArticleResponse = 1
  1728. //if v.IsReport == 1 {
  1729. // list[k].ArticleResponse = 1
  1730. //} else if v.ArticleTypeName == "纪要" {
  1731. // list[k].ArticleResponse = 2
  1732. //} else if v.ArticleTypeName == "观点" {
  1733. // list[k].ArticleResponse = 3
  1734. //} else if v.ArticleTypeName == "沙龙" {
  1735. // list[k].ArticleResponse = 3
  1736. //} else if v.ArticleTypeName == "路演精华" {
  1737. // list[k].ArticleResponse = 1
  1738. //}
  1739. }
  1740. list[k].Source = 1
  1741. //添加行业默认图片
  1742. if v.ImgUrlPc == "" {
  1743. if v.ChartPermissionName == utils.YI_YAO_NAME {
  1744. list[k].ImgUrlPc = utils.YI_YAO_OTHER_IMG
  1745. } else if v.ChartPermissionName == utils.XIAO_FEI_NAME {
  1746. list[k].ImgUrlPc = utils.XIAO_FEI_OTHER_IMG
  1747. } else if v.ChartPermissionName == utils.KE_JI_NAME {
  1748. list[k].ImgUrlPc = utils.KE_JI_OTHER_IMG
  1749. } else if v.ChartPermissionName == utils.ZHI_ZAO_NAME {
  1750. list[k].ImgUrlPc = utils.ZHI_ZAO_OTHER_IMG
  1751. }
  1752. }
  1753. //是不是研选报告
  1754. if v.ArticleTypeId > 0 {
  1755. list[k].IsResearch = true
  1756. }
  1757. }
  1758. articleIds := make([]int, 0)
  1759. for i := range list {
  1760. articleIds = append(articleIds, list[i].ArticleId)
  1761. }
  1762. // 报告关联产业信息
  1763. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  1764. if len(articleIds) > 0 {
  1765. var industryCond string
  1766. var industryPars []interface{}
  1767. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1768. industryPars = append(industryPars, articleIds)
  1769. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  1770. if e != nil {
  1771. err = errors.New("GetIndustrialListByarticleId" + e.Error())
  1772. return
  1773. }
  1774. for i := range industryList {
  1775. v := industryList[i]
  1776. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  1777. ArticleId: v.ArticleId,
  1778. IndustrialManagementId: v.IndustrialManagementId,
  1779. IndustryName: v.IndustryName,
  1780. ChartPermissionId: v.ChartPermissionId,
  1781. })
  1782. }
  1783. }
  1784. for k, v := range list {
  1785. if len(industryMap[v.ArticleId]) > 0 {
  1786. list[k].List = industryMap[v.ArticleId]
  1787. } else {
  1788. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  1789. }
  1790. }
  1791. if len(list) == 0 {
  1792. list = make([]*models.HomeArticle, 0)
  1793. }
  1794. items = list
  1795. return
  1796. }
  1797. // 处理核心观点的展示规则
  1798. func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
  1799. if item.ArticleId >= utils.SummaryArticleId {
  1800. item.Annotation = YxArticleAnnotation(item)
  1801. }
  1802. if item.Annotation != "" {
  1803. annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  1804. annotation = strings.Replace(item.Annotation, "&nbsp;", "", -1)
  1805. } else {
  1806. return
  1807. }
  1808. bodyText, _ := GetReportContentTextSubNew(annotation)
  1809. if bodyText == "" {
  1810. return
  1811. }
  1812. if annotation != "" {
  1813. annotation = html.UnescapeString(annotation)
  1814. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1815. docText := doc.Text()
  1816. mapDoc := make(map[int]string)
  1817. var mapSort []int
  1818. p := doc.Find("p")
  1819. p.Each(func(tk int, pd *goquery.Selection) {
  1820. pdText := pd.Text()
  1821. pdText = strings.Replace(pdText, " ", "", -1)
  1822. if pdText != "" {
  1823. textLen := strings.Index(docText, pdText)
  1824. mapDoc[(strings.Index(docText, pdText))] = pdText
  1825. mapSort = append(mapSort, textLen)
  1826. }
  1827. })
  1828. li := doc.Find("li")
  1829. li.Each(func(tk int, li *goquery.Selection) {
  1830. liText := li.Text()
  1831. liText = strings.Replace(liText, " ", "", -1)
  1832. if liText != "" {
  1833. textLen := strings.Index(docText, liText)
  1834. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1835. mapSort = append(mapSort, textLen)
  1836. }
  1837. })
  1838. ul := doc.Find("ul")
  1839. ul.Each(func(tk int, ul *goquery.Selection) {
  1840. ulText := ul.Text()
  1841. ulText = strings.Replace(ulText, " ", "", -1)
  1842. if ulText != "" {
  1843. textLen := strings.Index(docText, ulText)
  1844. mapDoc[(strings.Index(docText, ulText))] = ulText
  1845. mapSort = append(mapSort, textLen)
  1846. }
  1847. })
  1848. if len(mapSort) == 0 {
  1849. return
  1850. } else {
  1851. //排序
  1852. sort.Ints(mapSort)
  1853. var annotationHtml string
  1854. for _, vSort := range mapSort {
  1855. for k, v := range mapDoc {
  1856. if k == vSort && v != "" {
  1857. annotationHtml += v + "<br>"
  1858. }
  1859. }
  1860. }
  1861. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1862. annotationHtml = "<p>" + annotationHtml + "</p>"
  1863. annotation = annotationHtml
  1864. }
  1865. }
  1866. return
  1867. }
  1868. //func init() {
  1869. // strss := AnnotationHtml("")
  1870. //
  1871. // fmt.Println(strss)
  1872. //}
  1873. // 处理核心观点的展示规则
  1874. func AnnotationHtml(bodyText string) (annotation string) {
  1875. if bodyText == "" {
  1876. return
  1877. }
  1878. annotation = bodyText
  1879. annotation = html.UnescapeString(annotation)
  1880. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1881. docText := doc.Text()
  1882. mapDoc := make(map[int]string)
  1883. var mapSort []int
  1884. p := doc.Find("p")
  1885. p.Each(func(tk int, pd *goquery.Selection) {
  1886. pdText := pd.Text()
  1887. //pdText = strings.Replace(pdText, " ", "", -1)
  1888. if pdText != "" {
  1889. textLen := strings.Index(docText, pdText)
  1890. mapDoc[(strings.Index(docText, pdText))] = pdText
  1891. mapSort = append(mapSort, textLen)
  1892. }
  1893. })
  1894. li := doc.Find("li")
  1895. li.Each(func(tk int, li *goquery.Selection) {
  1896. liText := li.Text()
  1897. liText = strings.Replace(liText, " ", "", -1)
  1898. if liText != "" {
  1899. textLen := strings.Index(docText, liText)
  1900. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1901. mapSort = append(mapSort, textLen)
  1902. }
  1903. })
  1904. ul := doc.Find("ul")
  1905. ul.Each(func(tk int, ul *goquery.Selection) {
  1906. ulText := ul.Text()
  1907. ulText = strings.Replace(ulText, " ", "", -1)
  1908. if ulText != "" {
  1909. textLen := strings.Index(docText, ulText)
  1910. mapDoc[(strings.Index(docText, ulText))] = ulText
  1911. mapSort = append(mapSort, textLen)
  1912. }
  1913. })
  1914. section := doc.Find("section")
  1915. section.Each(func(tk int, section *goquery.Selection) {
  1916. sectionText := section.Text()
  1917. sectionText = strings.Replace(sectionText, " ", "", -1)
  1918. if sectionText != "" {
  1919. textLen := strings.Index(docText, sectionText)
  1920. mapDoc[(strings.Index(docText, sectionText))] = sectionText
  1921. mapSort = append(mapSort, textLen)
  1922. }
  1923. })
  1924. if len(mapSort) == 0 {
  1925. return
  1926. } else {
  1927. //排序
  1928. sort.Ints(mapSort)
  1929. var annotationHtml string
  1930. for _, vSort := range mapSort {
  1931. for k, v := range mapDoc {
  1932. if k == vSort && v != "" {
  1933. annotationHtml += v + "<br>"
  1934. }
  1935. }
  1936. }
  1937. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1938. annotationHtml = "<p>" + annotationHtml + "</p>"
  1939. annotation = annotationHtml
  1940. }
  1941. return
  1942. }
  1943. // 处理产品内测展示规则
  1944. func ProductInteriorHtml(bodyText string) (annotation string) {
  1945. if bodyText == "" {
  1946. return
  1947. }
  1948. sliceBody := strings.Split(bodyText, "</p>")
  1949. annotation, _ = GetReportContentTextSub(sliceBody[0])
  1950. return
  1951. }
  1952. // 解析研选内容中的核心观点
  1953. func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
  1954. //如果不规范,就获取内容主体
  1955. if strings.Count(article.Body, "<hr") == 0 {
  1956. //如果内容不规范而且,还有图片,就把核心观点置空
  1957. if article.BodyHtml != "" {
  1958. return
  1959. }
  1960. annotation, _ = GetReportContentTextSub(article.Body)
  1961. return
  1962. }
  1963. body := strings.ReplaceAll(article.Body, "<strong>", "")
  1964. body = strings.ReplaceAll(body, "</strong>", "")
  1965. body = strings.ReplaceAll(body, "</ol>", "</div>")
  1966. body = strings.ReplaceAll(body, "<ol>", "<div>")
  1967. body = strings.ReplaceAll(body, "</li>", "</p>")
  1968. body = strings.ReplaceAll(body, "<li>", "<p>")
  1969. re, _ := regexp.Compile("<strong.*?>")
  1970. body = re.ReplaceAllString(body, "")
  1971. reLi, _ := regexp.Compile("<li.*?>")
  1972. body = reLi.ReplaceAllString(body, "")
  1973. var plus int
  1974. coreIndex := strings.Index(body, "核心观点:")
  1975. plus = 15
  1976. if coreIndex == -1 {
  1977. coreIndex = strings.Index(body, "核心观点:")
  1978. plus = 13
  1979. }
  1980. if coreIndex == -1 {
  1981. coreIndex = strings.Index(body, "核心观点")
  1982. plus = 12
  1983. }
  1984. if coreIndex == -1 {
  1985. coreIndex = strings.Index(body, "核心结论:")
  1986. plus = 15
  1987. }
  1988. if coreIndex == -1 {
  1989. coreIndex = strings.Index(body, "核心结论:")
  1990. plus = 13
  1991. }
  1992. if coreIndex == -1 {
  1993. coreIndex = strings.Index(body, "核心结论")
  1994. plus = 12
  1995. }
  1996. endIndex := strings.Index(body, "<hr")
  1997. if coreIndex != -1 && endIndex != -1 {
  1998. body = body[coreIndex+plus : endIndex]
  1999. }
  2000. annotation = body
  2001. return
  2002. }
  2003. // 通过接解析带有Md5的文章链接获取文章ID
  2004. func GetReportLinkToArticleid(reportLink string) (articleId int, err error) {
  2005. defer func() {
  2006. if err != nil {
  2007. go utils.SendAlarmMsg("通过接解析带有Md5的文章链接获取文章ID失败"+err.Error(), 2)
  2008. }
  2009. }()
  2010. var artMd5 string
  2011. //处理Md5的
  2012. strnum1 := strings.Index(reportLink, "id=")
  2013. if strnum1 > 0 {
  2014. sliceId := strings.Split(reportLink, "id=")
  2015. if len(sliceId) > 1 {
  2016. reportLink = sliceId[1]
  2017. sliceMd5Id := strings.Split(reportLink, "&")
  2018. artMd5 = sliceMd5Id[0]
  2019. }
  2020. if artMd5 != "" {
  2021. detail, errArt := models.GetArticleDetailByIdMd5(artMd5)
  2022. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  2023. err = errArt
  2024. return
  2025. }
  2026. if detail != nil {
  2027. articleId = detail.ArticleId
  2028. }
  2029. }
  2030. } else {
  2031. //处理活动的
  2032. linkList := strings.Split(reportLink, "/")
  2033. if linkList[len(linkList)-1] != "" {
  2034. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  2035. if linkArticleId > 0 {
  2036. articleInfo, errArt := models.GetArticleDetailById(linkArticleId)
  2037. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  2038. err = errArt
  2039. return
  2040. }
  2041. if articleInfo != nil {
  2042. articleId = articleInfo.ArticleId
  2043. }
  2044. }
  2045. }
  2046. }
  2047. return
  2048. }
  2049. // GetArticleStockMap 获取个股标签所对应的文章ID
  2050. func GetArticleStockMap() (mapResp map[string]int, err error) {
  2051. defer func() {
  2052. if err != nil {
  2053. go utils.SendAlarmMsg("获取个股标签所对应的文章ID失败"+err.Error(), 2)
  2054. }
  2055. }()
  2056. list, err := models.GetArticleStock()
  2057. if err != nil && err.Error() != utils.ErrNoRow() {
  2058. return
  2059. }
  2060. mapResp = make(map[string]int, 0)
  2061. if len(list) > 0 {
  2062. //一对一精准匹配
  2063. for _, v := range list {
  2064. sliceSubjects := strings.Split(v.Stock, "/")
  2065. if len(sliceSubjects) > 0 {
  2066. for _, vSubject := range sliceSubjects {
  2067. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  2068. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  2069. subject := sliceXiahuaxian[0]
  2070. mapResp[subject] = v.ArticleId
  2071. }
  2072. }
  2073. }
  2074. }
  2075. return
  2076. }
  2077. // GetAiQianYanArtilceList 获取AI前沿几篇文章
  2078. func GetAiQianYanArtilceList(startSize, pageSize int) (items []*models.ReportArticle, total int, err error) {
  2079. defer func() {
  2080. if err != nil {
  2081. go utils.SendAlarmMsg("获取AI前沿几篇文章失败"+err.Error(), 2)
  2082. }
  2083. }()
  2084. var condition string
  2085. var pars []interface{}
  2086. condition += ` AND title LIKE '%AI前沿%' AND publish_status = 1 ORDER BY publish_date DESC `
  2087. articleList, e := models.GetCygxCygxArticleList(condition, pars, startSize, pageSize)
  2088. if e != nil {
  2089. err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
  2090. return
  2091. }
  2092. total, e = models.GetCygxArticleCount(condition, pars)
  2093. if e != nil {
  2094. err = errors.New("GetCygxArticleCount, Err: " + e.Error())
  2095. return
  2096. }
  2097. for _, v := range articleList {
  2098. item := new(models.ReportArticle)
  2099. item.ArticleId = v.ArticleId
  2100. item.Title = v.Title
  2101. item.Abstract = v.Abstract
  2102. item.Annotation = v.Annotation
  2103. item.PublishDate = v.PublishDate
  2104. item.Resource = 1
  2105. item.CategoryId = strconv.Itoa(v.CategoryId)
  2106. item.Body = v.Body
  2107. items = append(items, item)
  2108. }
  2109. return
  2110. }
  2111. // 获取文章内部图表的第一张封面图
  2112. func GetArticleCoverByChartFirst(body string) (cover string) {
  2113. var err error
  2114. defer func() {
  2115. if err != nil {
  2116. fmt.Println(err)
  2117. go utils.SendAlarmMsg("获取文章内部图表的第一张封面图失败,Err:"+err.Error()+body, 3)
  2118. }
  2119. }()
  2120. var chartUrl string
  2121. var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
  2122. match := hrefRegexp.FindAllString(body, -1)
  2123. if match != nil {
  2124. for _, v := range match {
  2125. if strings.Contains(v, "charts/display") {
  2126. chartUrl = v
  2127. break
  2128. }
  2129. }
  2130. }
  2131. if chartUrl != "" {
  2132. urlSlice := strings.Split(chartUrl, "/")
  2133. lenurlSlice := len(urlSlice)
  2134. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  2135. if sourceId == 0 {
  2136. sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
  2137. }
  2138. if sourceId == 0 {
  2139. err = errors.New("新的图标链接无法解析" + chartUrl)
  2140. return
  2141. }
  2142. chartUrlApi := utils.ApiUrl + "charts/" + strconv.Itoa(sourceId)
  2143. authorization := utils.ApiAuthorization
  2144. body, e := PublicGetDate(chartUrlApi, authorization)
  2145. if e != nil {
  2146. err = errors.New("PublicGetDate" + err.Error())
  2147. return
  2148. }
  2149. var resultDate models.ChartResultDetailApi
  2150. e = json.Unmarshal(body, &resultDate)
  2151. if e != nil {
  2152. err = errors.New(" json.Unmarshal" + err.Error())
  2153. }
  2154. cover = resultDate.Data.Cover
  2155. }
  2156. return
  2157. }
  2158. // GetYxArticleIdMap 获取研选文章ID
  2159. func GetYxArticleIdMap(articleIds []int) (mapResp map[int]bool) {
  2160. var err error
  2161. defer func() {
  2162. if err != nil {
  2163. go utils.SendAlarmMsg("获取研选文章ID失败,GetYxArticleIdMap"+err.Error(), 2)
  2164. }
  2165. }()
  2166. var condition string
  2167. var pars []interface{}
  2168. condition = ` AND article_type_id > 0 `
  2169. if len(articleIds) > 0 {
  2170. condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  2171. pars = append(pars, articleIds)
  2172. }
  2173. articleList, e := models.GetArticleList(condition, pars)
  2174. if e != nil {
  2175. err = errors.New("GetArticleList, Err: " + e.Error())
  2176. return
  2177. }
  2178. mapResp = make(map[int]bool, 0)
  2179. for _, v := range articleList {
  2180. mapResp[v.ArticleId] = true
  2181. }
  2182. return
  2183. }