article.go 69 KB

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