article.go 74 KB

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