article.go 68 KB

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