article.go 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  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. // 处理核心观点的展示规则
  1842. func AnnotationHtml(bodyText string) (annotation string) {
  1843. if bodyText == "" {
  1844. return
  1845. }
  1846. annotation = bodyText
  1847. annotation = html.UnescapeString(annotation)
  1848. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1849. docText := doc.Text()
  1850. mapDoc := make(map[int]string)
  1851. var mapSort []int
  1852. p := doc.Find("p")
  1853. p.Each(func(tk int, pd *goquery.Selection) {
  1854. pdText := pd.Text()
  1855. pdText = strings.Replace(pdText, " ", "", -1)
  1856. if pdText != "" {
  1857. textLen := strings.Index(docText, pdText)
  1858. mapDoc[(strings.Index(docText, pdText))] = pdText
  1859. mapSort = append(mapSort, textLen)
  1860. }
  1861. })
  1862. li := doc.Find("li")
  1863. li.Each(func(tk int, li *goquery.Selection) {
  1864. liText := li.Text()
  1865. liText = strings.Replace(liText, " ", "", -1)
  1866. if liText != "" {
  1867. textLen := strings.Index(docText, liText)
  1868. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1869. mapSort = append(mapSort, textLen)
  1870. }
  1871. })
  1872. ul := doc.Find("ul")
  1873. ul.Each(func(tk int, ul *goquery.Selection) {
  1874. ulText := ul.Text()
  1875. ulText = strings.Replace(ulText, " ", "", -1)
  1876. if ulText != "" {
  1877. textLen := strings.Index(docText, ulText)
  1878. mapDoc[(strings.Index(docText, ulText))] = ulText
  1879. mapSort = append(mapSort, textLen)
  1880. }
  1881. })
  1882. if len(mapSort) == 0 {
  1883. return
  1884. } else {
  1885. //排序
  1886. sort.Ints(mapSort)
  1887. var annotationHtml string
  1888. for _, vSort := range mapSort {
  1889. for k, v := range mapDoc {
  1890. if k == vSort && v != "" {
  1891. annotationHtml += v + "<br>"
  1892. }
  1893. }
  1894. }
  1895. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1896. annotationHtml = "<p>" + annotationHtml + "</p>"
  1897. annotation = annotationHtml
  1898. }
  1899. return
  1900. }
  1901. // 处理产品内测展示规则
  1902. func ProductInteriorHtml(bodyText string) (annotation string) {
  1903. if bodyText == "" {
  1904. return
  1905. }
  1906. sliceBody := strings.Split(bodyText, "</p>")
  1907. annotation, _ = GetReportContentTextSub(sliceBody[0])
  1908. return
  1909. }
  1910. // 解析研选内容中的核心观点
  1911. func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
  1912. //如果不规范,就获取内容主体
  1913. if strings.Count(article.Body, "<hr") == 0 {
  1914. //如果内容不规范而且,还有图片,就把核心观点置空
  1915. if article.BodyHtml != "" {
  1916. return
  1917. }
  1918. annotation, _ = GetReportContentTextSub(article.Body)
  1919. return
  1920. }
  1921. body := strings.ReplaceAll(article.Body, "<strong>", "")
  1922. body = strings.ReplaceAll(body, "</strong>", "")
  1923. body = strings.ReplaceAll(body, "</ol>", "</div>")
  1924. body = strings.ReplaceAll(body, "<ol>", "<div>")
  1925. body = strings.ReplaceAll(body, "</li>", "</p>")
  1926. body = strings.ReplaceAll(body, "<li>", "<p>")
  1927. re, _ := regexp.Compile("<strong.*?>")
  1928. body = re.ReplaceAllString(body, "")
  1929. reLi, _ := regexp.Compile("<li.*?>")
  1930. body = reLi.ReplaceAllString(body, "")
  1931. var plus int
  1932. coreIndex := strings.Index(body, "核心观点:")
  1933. plus = 15
  1934. if coreIndex == -1 {
  1935. coreIndex = strings.Index(body, "核心观点:")
  1936. plus = 13
  1937. }
  1938. if coreIndex == -1 {
  1939. coreIndex = strings.Index(body, "核心观点")
  1940. plus = 12
  1941. }
  1942. if coreIndex == -1 {
  1943. coreIndex = strings.Index(body, "核心结论:")
  1944. plus = 15
  1945. }
  1946. if coreIndex == -1 {
  1947. coreIndex = strings.Index(body, "核心结论:")
  1948. plus = 13
  1949. }
  1950. if coreIndex == -1 {
  1951. coreIndex = strings.Index(body, "核心结论")
  1952. plus = 12
  1953. }
  1954. endIndex := strings.Index(body, "<hr")
  1955. if coreIndex != -1 && endIndex != -1 {
  1956. body = body[coreIndex+plus : endIndex]
  1957. }
  1958. annotation = body
  1959. return
  1960. }
  1961. // 通过接解析带有Md5的文章链接获取文章ID
  1962. func GetReportLinkToArticleid(reportLink string) (articleId int, err error) {
  1963. defer func() {
  1964. if err != nil {
  1965. go utils.SendAlarmMsg("通过接解析带有Md5的文章链接获取文章ID失败"+err.Error(), 2)
  1966. }
  1967. }()
  1968. var artMd5 string
  1969. //处理Md5的
  1970. strnum1 := strings.Index(reportLink, "id=")
  1971. if strnum1 > 0 {
  1972. sliceId := strings.Split(reportLink, "id=")
  1973. if len(sliceId) > 1 {
  1974. reportLink = sliceId[1]
  1975. sliceMd5Id := strings.Split(reportLink, "&")
  1976. artMd5 = sliceMd5Id[0]
  1977. }
  1978. if artMd5 != "" {
  1979. detail, errArt := models.GetArticleDetailByIdMd5(artMd5)
  1980. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  1981. err = errArt
  1982. return
  1983. }
  1984. if detail != nil {
  1985. articleId = detail.ArticleId
  1986. }
  1987. }
  1988. } else {
  1989. //处理活动的
  1990. linkList := strings.Split(reportLink, "/")
  1991. if linkList[len(linkList)-1] != "" {
  1992. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  1993. if linkArticleId > 0 {
  1994. articleInfo, errArt := models.GetArticleDetailById(linkArticleId)
  1995. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  1996. err = errArt
  1997. return
  1998. }
  1999. if articleInfo != nil {
  2000. articleId = articleInfo.ArticleId
  2001. }
  2002. }
  2003. }
  2004. }
  2005. return
  2006. }
  2007. // GetArticleStockMap 获取个股标签所对应的文章ID
  2008. func GetArticleStockMap() (mapResp map[string]int, err error) {
  2009. defer func() {
  2010. if err != nil {
  2011. go utils.SendAlarmMsg("获取个股标签所对应的文章ID失败"+err.Error(), 2)
  2012. }
  2013. }()
  2014. list, err := models.GetArticleStock()
  2015. if err != nil && err.Error() != utils.ErrNoRow() {
  2016. return
  2017. }
  2018. mapResp = make(map[string]int, 0)
  2019. if len(list) > 0 {
  2020. //一对一精准匹配
  2021. for _, v := range list {
  2022. sliceSubjects := strings.Split(v.Stock, "/")
  2023. if len(sliceSubjects) > 0 {
  2024. for _, vSubject := range sliceSubjects {
  2025. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  2026. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  2027. subject := sliceXiahuaxian[0]
  2028. mapResp[subject] = v.ArticleId
  2029. }
  2030. }
  2031. }
  2032. }
  2033. return
  2034. }
  2035. // GetAiQianYanArtilceList 获取AI前沿几篇文章
  2036. func GetAiQianYanArtilceList(startSize, pageSize int) (items []*models.ReportArticle, total int, err error) {
  2037. defer func() {
  2038. if err != nil {
  2039. go utils.SendAlarmMsg("获取AI前沿几篇文章失败"+err.Error(), 2)
  2040. }
  2041. }()
  2042. var condition string
  2043. var pars []interface{}
  2044. condition += ` AND title LIKE '%AI前沿%' AND publish_status = 1 ORDER BY publish_date DESC `
  2045. articleList, e := models.GetCygxCygxArticleList(condition, pars, startSize, pageSize)
  2046. if e != nil {
  2047. err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
  2048. return
  2049. }
  2050. total, e = models.GetCygxArticleCount(condition, pars)
  2051. if e != nil {
  2052. err = errors.New("GetCygxArticleCount, Err: " + e.Error())
  2053. return
  2054. }
  2055. for _, v := range articleList {
  2056. item := new(models.ReportArticle)
  2057. item.ArticleId = v.ArticleId
  2058. item.Title = v.Title
  2059. item.Abstract = v.Abstract
  2060. item.Annotation = v.Annotation
  2061. item.PublishDate = v.PublishDate
  2062. item.Resource = 1
  2063. item.CategoryId = strconv.Itoa(v.CategoryId)
  2064. item.Body = v.Body
  2065. items = append(items, item)
  2066. }
  2067. return
  2068. }
  2069. // 获取文章内部图表的第一张封面图
  2070. func GetArticleCoverByChartFirst(body string) (cover string) {
  2071. var err error
  2072. defer func() {
  2073. if err != nil {
  2074. fmt.Println(err)
  2075. go utils.SendAlarmMsg("获取文章内部图表的第一张封面图失败,Err:"+err.Error()+body, 3)
  2076. }
  2077. }()
  2078. var chartUrl string
  2079. var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
  2080. match := hrefRegexp.FindAllString(body, -1)
  2081. if match != nil {
  2082. for _, v := range match {
  2083. if strings.Contains(v, "charts/display") {
  2084. chartUrl = v
  2085. break
  2086. }
  2087. }
  2088. }
  2089. if chartUrl != "" {
  2090. urlSlice := strings.Split(chartUrl, "/")
  2091. lenurlSlice := len(urlSlice)
  2092. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  2093. if sourceId == 0 {
  2094. sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
  2095. }
  2096. if sourceId == 0 {
  2097. err = errors.New("新的图标链接无法解析" + chartUrl)
  2098. return
  2099. }
  2100. chartUrlApi := utils.ApiUrl + "charts/" + strconv.Itoa(sourceId)
  2101. authorization := utils.ApiAuthorization
  2102. body, e := PublicGetDate(chartUrlApi, authorization)
  2103. if e != nil {
  2104. err = errors.New("PublicGetDate" + err.Error())
  2105. return
  2106. }
  2107. var resultDate models.ChartResultDetailApi
  2108. e = json.Unmarshal(body, &resultDate)
  2109. if e != nil {
  2110. err = errors.New(" json.Unmarshal" + err.Error())
  2111. }
  2112. cover = resultDate.Data.Cover
  2113. }
  2114. return
  2115. }
  2116. // GetYxArticleIdMap 获取研选文章ID
  2117. func GetYxArticleIdMap(articleIds []int) (mapResp map[int]bool) {
  2118. var err error
  2119. defer func() {
  2120. if err != nil {
  2121. go utils.SendAlarmMsg("获取研选文章ID失败,GetYxArticleIdMap"+err.Error(), 2)
  2122. }
  2123. }()
  2124. var condition string
  2125. var pars []interface{}
  2126. condition = ` AND article_type_id > 0 `
  2127. if len(articleIds) > 0 {
  2128. condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  2129. pars = append(pars, articleIds)
  2130. }
  2131. articleList, e := models.GetArticleList(condition, pars)
  2132. if e != nil {
  2133. err = errors.New("GetArticleList, Err: " + e.Error())
  2134. return
  2135. }
  2136. mapResp = make(map[int]bool, 0)
  2137. for _, v := range articleList {
  2138. mapResp[v.ArticleId] = true
  2139. }
  2140. return
  2141. }