article.go 76 KB

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