article.go 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "github.com/PuerkitoBio/goquery"
  8. "github.com/beego/beego/v2/client/orm"
  9. "hongze/hongze_cygx/models"
  10. "hongze/hongze_cygx/utils"
  11. "html"
  12. "net/url"
  13. "regexp"
  14. "sort"
  15. "strconv"
  16. "strings"
  17. "time"
  18. "unicode/utf8"
  19. )
  20. func GetReportContentSub(content string) (contentSub string, err error) {
  21. content = html.UnescapeString(content)
  22. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  23. if err != nil {
  24. fmt.Println("create doc err:", err.Error())
  25. return
  26. }
  27. n := 0
  28. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  29. if n > 3 {
  30. return
  31. }
  32. n++
  33. phtml, err := s.Html()
  34. if err != nil {
  35. fmt.Println("get html err", err.Error())
  36. return
  37. }
  38. if s.Text() != "" || strings.Contains(phtml, "src") {
  39. contentSub = contentSub + "<p>" + phtml + "</p>"
  40. }
  41. })
  42. return
  43. }
  44. func GetReportContentTextSub(content string) (contentSub string, err error) {
  45. content = html.UnescapeString(content)
  46. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  47. docText := doc.Text()
  48. bodyRune := []rune(docText)
  49. bodyRuneLen := len(bodyRune)
  50. if bodyRuneLen > 200 {
  51. bodyRuneLen = 200
  52. }
  53. body := string(bodyRune[:bodyRuneLen])
  54. contentSub = body
  55. contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
  56. return
  57. }
  58. func GetAnnotationTextSub(content string) (contentSub string) {
  59. contentSub = strings.Replace(content, "<p class=\"ql-align-justify\">", "&nbsp;", -1)
  60. contentSub = strings.Replace(contentSub, "</p>", "", -1)
  61. return
  62. }
  63. func GetReportContentTextSubNew(content string) (contentSub string, err error) {
  64. content = html.UnescapeString(content)
  65. doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(content))
  66. if errdoc != nil {
  67. err = errdoc
  68. return
  69. }
  70. docText := doc.Text()
  71. bodyRune := []rune(docText)
  72. bodyRuneLen := len(bodyRune)
  73. body := string(bodyRune[:bodyRuneLen])
  74. contentSub = body
  75. contentSub = strings.Replace(contentSub, "Powered by Froala Editor", "", -1)
  76. contentSub = strings.Replace(contentSub, " ", "", -1)
  77. contentSub = strings.Replace(contentSub, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sanered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  78. return
  79. }
  80. // GetReportContentTextSubByarticle 解析文章内容
  81. func GetReportContentTextSubByarticle(content, abstract string, articleId int) (contentSub string, err error) {
  82. var lenabstract int
  83. //如果不是研选就这么展示
  84. if articleId < utils.SummaryArticleId {
  85. abstract = html.UnescapeString(abstract)
  86. doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(abstract))
  87. if errdoc != nil {
  88. err = errdoc
  89. return
  90. }
  91. docabstract := doc.Text()
  92. lenabstract = utf8.RuneCountInString(docabstract)
  93. if lenabstract >= 20 {
  94. contentSub = docabstract
  95. return
  96. } else {
  97. contentSub, err = GetReportContentTextSubNew(content)
  98. }
  99. } else {
  100. contentSub, err = GetReportContentTextSubNew(content)
  101. }
  102. return
  103. }
  104. // 解析文章内容
  105. func GetArticleAll() {
  106. var err error
  107. defer func() {
  108. if err != nil {
  109. fmt.Println("err:", err.Error())
  110. return
  111. }
  112. }()
  113. list, err := models.GetArticleAll()
  114. if err != nil {
  115. return
  116. }
  117. for _, v := range list {
  118. fmt.Println(v.ArticleId, v.Title)
  119. FixArticleContent(v.ArticleId)
  120. }
  121. }
  122. // 解析报告
  123. func FixArticleContent(articleId int) {
  124. item, err := models.GetArticleDetailById(articleId)
  125. if err != nil {
  126. fmt.Println("GetArticleDetailById Err:" + err.Error())
  127. return
  128. }
  129. content := item.Body
  130. bodyText, _ := GetReportContentTextSub(content)
  131. content = html.UnescapeString(content)
  132. content = strings.Replace(content, "http", "https", -1)
  133. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  134. if err != nil {
  135. fmt.Println("create doc err:", err.Error())
  136. return
  137. }
  138. var expertNumArr []string
  139. var expertContentArr []string
  140. var interviewDateArr []string
  141. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  142. contentTxt := s.Text()
  143. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  144. interviewDate := s.Next().Text()
  145. interviewDateArr = append(interviewDateArr, interviewDate)
  146. }
  147. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  148. expertContent := s.Next().Text()
  149. if expertContent == "" {
  150. expertContent = contentTxt
  151. }
  152. if expertContent != "" {
  153. rightIndex := strings.Index(expertContent, ")")
  154. if rightIndex == 0 {
  155. rightIndex = strings.Index(expertContent, ")")
  156. }
  157. if rightIndex > 0 {
  158. expertNum := expertContent[:rightIndex]
  159. expertNum = strings.Replace(expertNum, "(", "", -1)
  160. expertNum = strings.Replace(expertNum, "(", "", -1)
  161. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  162. if expertNum != "" {
  163. expertNumArr = append(expertNumArr, expertNum)
  164. rightIndex = rightIndex
  165. expertContentStr := expertContent[rightIndex:]
  166. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  167. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  168. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  169. expertContentArr = append(expertContentArr, expertContentStr)
  170. }
  171. }
  172. }
  173. }
  174. })
  175. if len(expertContentArr) <= 0 {
  176. doc.Find("pre").Each(func(i int, pre *goquery.Selection) {
  177. pre.Find("span").Each(func(n int, span *goquery.Selection) {
  178. contentTxt := span.Text()
  179. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  180. span.Find("span").Each(func(m int, subspan *goquery.Selection) {
  181. subspanText := subspan.Text()
  182. if strings.Contains(subspanText, "专家评价") {
  183. expertContent := subspan.Next().Text()
  184. if expertContent != "" {
  185. rightIndex := strings.Index(expertContent, ")")
  186. if rightIndex == 0 {
  187. rightIndex = strings.Index(expertContent, ")")
  188. }
  189. if rightIndex > 0 {
  190. expertNum := expertContent[:rightIndex]
  191. expertNum = strings.Replace(expertNum, "(", "", -1)
  192. expertNum = strings.Replace(expertNum, "(", "", -1)
  193. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  194. if expertNum != "" {
  195. expertNumArr = append(expertNumArr, expertNum)
  196. rightIndex = rightIndex
  197. expertContentStr := expertContent[rightIndex:]
  198. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  199. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  200. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  201. expertContentArr = append(expertContentArr, expertContentStr)
  202. }
  203. }
  204. }
  205. }
  206. })
  207. }
  208. span.Find("span").Each(func(k int, sspan *goquery.Selection) {
  209. sspanText := sspan.Text()
  210. if strings.Contains(sspanText, "访谈时间") {
  211. sspanText = strings.Replace(sspanText, "#访谈时间:", "", -1)
  212. sspanText = strings.Replace(sspanText, "访谈时间:", "", -1)
  213. sspanText = strings.Replace(sspanText, "\n", "", -1)
  214. sspanText = strings.Replace(sspanText, " ", "", -1)
  215. sspanText = strings.Trim(sspanText, " ")
  216. sspanText = sspanText[:10]
  217. interviewDate := sspanText
  218. if interviewDate != "" {
  219. interviewDateArr = append(interviewDateArr, interviewDate)
  220. }
  221. }
  222. })
  223. })
  224. })
  225. }
  226. if len(expertContentArr) <= 0 {
  227. doc.Find("span").Each(func(i int, span *goquery.Selection) {
  228. span.Find("strong").Each(func(n int, strong *goquery.Selection) {
  229. spanText := span.Text()
  230. strongText := strong.Text()
  231. if strings.Contains(strongText, "#专家评价") || strings.Contains(strongText, "专家评价") {
  232. expertContent := strong.Parents().Text()
  233. if expertContent != "" {
  234. rightIndex := strings.Index(expertContent, ")")
  235. if rightIndex == 0 {
  236. rightIndex = strings.Index(expertContent, ")")
  237. }
  238. if rightIndex > 0 {
  239. expertNum := expertContent[:rightIndex]
  240. expertNum = strings.Replace(expertNum, "(", "", -1)
  241. expertNum = strings.Replace(expertNum, "(", "", -1)
  242. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  243. expertNum = strings.Replace(expertNum, "#", "", -1)
  244. expertNum = strings.Replace(expertNum, ":", "", -1)
  245. expertNum = strings.Replace(expertNum, "\n", "", -1)
  246. if expertNum != "" {
  247. expertNumArr = append(expertNumArr, expertNum)
  248. rightIndex = rightIndex
  249. expertContentStr := expertContent[rightIndex:]
  250. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  251. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  252. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  253. expertContentArr = append(expertContentArr, expertContentStr)
  254. return
  255. }
  256. }
  257. }
  258. }
  259. if strings.Contains(spanText, "访谈时间") {
  260. spanText = strings.Replace(spanText, "#访谈时间:", "", -1)
  261. spanText = strings.Replace(spanText, "访谈时间:", "", -1)
  262. spanText = strings.Replace(spanText, "\n", "", -1)
  263. spanText = strings.Replace(spanText, " ", "", -1)
  264. spanText = strings.Trim(spanText, " ")
  265. spanText = spanText[:10]
  266. interviewDate := spanText
  267. if interviewDate != "" {
  268. interviewDateArr = append(interviewDateArr, interviewDate)
  269. }
  270. }
  271. })
  272. })
  273. }
  274. var expertNumStr, expertContentStr, interviewDateStr string
  275. if len(expertNumArr) > 0 {
  276. expertNumStr = expertNumArr[0]
  277. }
  278. if len(expertContentArr) > 0 {
  279. expertContentStr = expertContentArr[0]
  280. }
  281. if len(interviewDateArr) > 0 {
  282. interviewDateStr = interviewDateArr[0]
  283. }
  284. expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
  285. err = models.ModifyArticleExpert(articleId, expertNumStr, expertContentStr, interviewDateStr, bodyText)
  286. if err != nil {
  287. fmt.Println("ModifyArticleExpert Err:" + err.Error())
  288. return
  289. }
  290. }
  291. func FixArticleImgUrl(body string) (contentSub string, err error) {
  292. r := strings.NewReader(string(body))
  293. doc, err := goquery.NewDocumentFromReader(r)
  294. if err != nil {
  295. fmt.Println(err)
  296. }
  297. doc.Find("img").Each(func(i int, s *goquery.Selection) {
  298. src, _ := s.Attr("src")
  299. if i == 0 && src != "" {
  300. contentSub = src
  301. }
  302. })
  303. return
  304. }
  305. // 获取标签里的第一个内容
  306. func FixArticleFirstCount(body string) (contentSub string, err error) {
  307. doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
  308. if err != nil {
  309. fmt.Println("create doc err:", err.Error())
  310. return
  311. }
  312. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  313. contentTxt := s.Text()
  314. fmt.Println(contentTxt)
  315. })
  316. return
  317. }
  318. func SynchronizationArtclehistory() {
  319. fmt.Println("同步开始")
  320. list, err := models.GetArticleHistoryList()
  321. if err != nil {
  322. fmt.Println("获取列表失败", err)
  323. }
  324. fmt.Println(len(list))
  325. for _, v := range list {
  326. //endDate := v.ModifyTime.Add(+time.Minute * 10).Format(utils.FormatDateTime)
  327. //detail, err := models.GetNewArticleHistoryRecordNewpv(v.UserId, v.ArticleId, endDate)
  328. //if err != nil && err.Error() != utils.ErrNoRow() {
  329. // fmt.Println("获取信息失败", err)
  330. //}
  331. v.OutType = 1
  332. //fmt.Println(v.Id)
  333. //if detail == nil {
  334. // _, err = models.AddCygxArticleViewRecordNewpv(v)
  335. // if err != nil {
  336. // fmt.Println("新增失败", err)
  337. // }
  338. //} else {
  339. // err = models.UpdateCygxArticleViewRecordNewpvList(v, v.StopTime)
  340. // if err != nil {
  341. // fmt.Println("修改失败", err)
  342. // }
  343. //}
  344. newId, err := models.AddCygxArticleViewRecordNewpv(v)
  345. fmt.Println("新增", newId)
  346. if err != nil {
  347. fmt.Println("新增失败", err)
  348. }
  349. }
  350. fmt.Println("同步结束")
  351. }
  352. // 统计报表
  353. func StatisticalReport() {
  354. var isSummaryNumAll, isClassNum, pvNumAll, uvNumAll int
  355. list, err := models.GetChartPermissionActivity()
  356. if err != nil {
  357. fmt.Println("获取列表失败", err)
  358. }
  359. for _, v := range list {
  360. var listPv []*models.ReportMappingStatistical
  361. if v.PermissionName == "研选" {
  362. listPv, err = models.GetStatisticalReportArtilceExpert()
  363. if err != nil {
  364. fmt.Println("获取Pv列表失败", err)
  365. }
  366. } else {
  367. listPv, err = models.GetStatisticalReportArtilce(v.ChartPermissionId)
  368. if err != nil {
  369. fmt.Println("获取Pv列表失败", err)
  370. }
  371. }
  372. var pvNum, uvNum, isSummaryNum int
  373. for _, v2 := range listPv {
  374. pvNum += v2.Pv
  375. uvNum += v2.Uv
  376. if v2.IsSummary == "1" {
  377. isSummaryNum += 1
  378. }
  379. if v2.IsClass == "1" && v.ChartPermissionId <= 22 {
  380. isClassNum += 1
  381. }
  382. if v2.IsSummary == "1" && v.ChartPermissionId <= 22 {
  383. isSummaryNumAll += 1
  384. }
  385. }
  386. if v.ChartPermissionId <= 22 {
  387. pvNumAll += pvNum
  388. uvNumAll += uvNum
  389. }
  390. fmt.Println(v.PermissionName+"行业", len(listPv), "篇,其中主观类报告", isSummaryNum, "篇,客观类报告", len(listPv)-isSummaryNum, "篇。共产生阅读量pv-,", pvNum, ",uv-", uvNum)
  391. }
  392. fmt.Println("目前同步四大行业的总报告(已归类)数量", isClassNum, "篇,其中主观类报告", isSummaryNumAll, "篇,客观类报告", isClassNum-isSummaryNumAll, "篇。共产生阅读量pv-", pvNumAll, ",uv-", uvNumAll)
  393. var totalOnline int //线上
  394. var totalOffline int //线下
  395. var totalPeople int //共累计预约外呼人数
  396. var totalSignUpOff int //线下报名人数
  397. var totalSignUpOffTime int //线下报名人数
  398. var totalPeopleMeet int //线下参会人数
  399. o := orm.NewOrm()
  400. sql := `SELECT COUNT(1) FROM cygx_activity WHERE activity_type_id IN (1,2,3) AND publish_status = 1 AND is_submit_meeting = 1 AND activity_time <= NOW();`
  401. err = o.Raw(sql).QueryRow(&totalOnline)
  402. if err != nil {
  403. fmt.Println("获取线上", err)
  404. }
  405. sql = `SELECT COUNT(1) FROM cygx_activity WHERE activity_type_id IN (4,5,6) AND publish_status = 1 AND is_submit_meeting = 1 AND activity_time <= NOW();`
  406. err = o.Raw(sql).QueryRow(&totalOffline)
  407. if err != nil {
  408. fmt.Println("获取线下", err)
  409. }
  410. sql = `SELECT COUNT( 1 ) FROM
  411. cygx_activity_signup as s
  412. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  413. WHERE
  414. s.do_fail_type = 0
  415. AND a.is_submit_meeting = 1
  416. AND a.activity_time <= NOW()
  417. AND a.publish_status = 1`
  418. err = o.Raw(sql).QueryRow(&totalPeople)
  419. if err != nil {
  420. fmt.Println("共累计预约外呼人数", err)
  421. }
  422. sql = `SELECT COUNT( 1 ) FROM
  423. cygx_activity_signup as s
  424. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  425. WHERE
  426. s.do_fail_type = 0
  427. AND a.is_submit_meeting = 1
  428. AND a.activity_time <= NOW()
  429. AND a.activity_type_id IN (4,5,6)
  430. AND a.publish_status = 1`
  431. err = o.Raw(sql).QueryRow(&totalSignUpOff)
  432. if err != nil {
  433. fmt.Println("共累计预约外呼人数", err)
  434. }
  435. sql = `SELECT COUNT( 1 ) FROM
  436. cygx_activity_signup as s
  437. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  438. WHERE
  439. s.do_fail_type = 0
  440. AND a.publish_status = 1
  441. AND a.is_submit_meeting = 1
  442. AND a.activity_time <= NOW()
  443. AND a.is_submit_meeting = 1
  444. AND a.activity_type_id IN (4,5,6);`
  445. err = o.Raw(sql).QueryRow(&totalSignUpOffTime)
  446. if err != nil {
  447. fmt.Println("线下报名参会人数", err)
  448. }
  449. sql = `SELECT COUNT( 1 ) FROM
  450. cygx_activity_signup as s
  451. INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
  452. WHERE
  453. s.do_fail_type = 0
  454. AND a.is_submit_meeting = 1
  455. AND a.activity_time <= NOW()
  456. AND a.publish_status = 1
  457. AND s.is_meeting = 1
  458. AND a.activity_type_id IN (4,5,6);`
  459. err = o.Raw(sql).QueryRow(&totalPeopleMeet)
  460. if err != nil {
  461. fmt.Println("线下参会人数", err)
  462. }
  463. fmt.Println("共上线活动", totalOnline+totalOffline, "个,其中线上", totalOnline, "个,线下", totalOffline, "个")
  464. fmt.Println("共累计预约外呼人数", totalPeople, "人")
  465. fmt.Println("报名线下参会", totalSignUpOff, "人,实际到会人数", totalPeopleMeet, "人,线下到会率约", totalPeopleMeet*100/totalSignUpOff, "%")
  466. num := totalPeopleMeet / totalSignUpOffTime
  467. fmt.Println(num)
  468. fmt.Println(totalOnline)
  469. fmt.Println(totalOffline)
  470. fmt.Println(totalPeople)
  471. fmt.Println(totalSignUpOff)
  472. fmt.Println(totalPeopleMeet)
  473. fmt.Println(totalSignUpOffTime)
  474. fmt.Println(totalPeopleMeet / totalSignUpOffTime)
  475. return
  476. }
  477. // UserViewRedisData 阅读数据
  478. type UserViewRedisData struct {
  479. Mobile string `json:"mobile"`
  480. Email string `json:"email"`
  481. RealName string `json:"real_name"`
  482. CompanyName string `json:"company_name"`
  483. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  484. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  485. CompanyId int `json:"company_id" description:"客户id"`
  486. UserId int `json:"user_id" description:"用户id"`
  487. ReportId int `json:"report_id" description:"报告id"`
  488. StopTime int `json:"stop_time" description:"停留时间"`
  489. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  490. OutId int `json:"out_id" description:"记录ID"`
  491. }
  492. type ReportViewRecord struct {
  493. Id int `orm:"column(id);pk"`
  494. //UserId int `json:"user_id" description:"用户ID"`
  495. //ReportId int `description:"报告id"`
  496. //Mobile string `description:"手机号"`
  497. //Email string `description:"邮箱"`
  498. //RealName string `description:"用户实际姓名"`
  499. //CompanyName string `description:"公司名称"`
  500. //CreateTime time.Time `description:"创建时间"`
  501. //StopTime int `json:"stop_time" description:"停留时间"`
  502. //ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  503. //OutId int `json:"out_id" description:"记录ID"`
  504. Mobile string `json:"mobile"`
  505. Email string `json:"email"`
  506. RealName string `json:"real_name"`
  507. CompanyName string `json:"company_name"`
  508. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  509. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  510. CompanyId int `json:"company_id" description:"客户id"`
  511. UserId int `json:"user_id" description:"用户id"`
  512. ReportId int `json:"report_id" description:"报告id"`
  513. StopTime int `json:"stop_time" description:"停留时间"`
  514. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  515. OutId int `json:"out_id" description:"章节ID"`
  516. }
  517. // PushViewRecordNewRedisData 阅读数据加入到redis
  518. func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
  519. data := &UserViewRedisData{
  520. Mobile: reportViewRecord.Mobile,
  521. UserId: reportViewRecord.UserId,
  522. Email: reportViewRecord.Email,
  523. RealName: reportViewRecord.RealName,
  524. CompanyName: reportViewRecord.CompanyName,
  525. ViewTime: reportViewRecord.ViewTime,
  526. ProductId: 2,
  527. CompanyId: companyId,
  528. ReportId: reportViewRecord.ReportId,
  529. StopTime: reportViewRecord.StopTime,
  530. ReportChapterId: reportViewRecord.ReportChapterId,
  531. OutId: reportViewRecord.OutId,
  532. }
  533. if utils.Re == nil {
  534. err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
  535. if err != nil {
  536. fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
  537. }
  538. return true
  539. }
  540. return false
  541. }
  542. //func GetCeLueArticlePv() {
  543. // sum := 0
  544. // for i := 0; i <= 450; i++ {
  545. // if i >= 102 {
  546. // //GetCeLueArticlePvs(strconv.Itoa(i * 1000))
  547. // }
  548. // }
  549. // fmt.Println(sum)
  550. //}
  551. // 获取策略平台报告阅读数据
  552. func GetCeLueArticlePv(cont context.Context) (err error) {
  553. defer func() {
  554. if err != nil {
  555. go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
  556. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  557. }
  558. }()
  559. startTime := time.Now().Add(-time.Minute * 12).Format("2006-01-02 15:04:05")
  560. endTime := time.Now().Format("2006-01-02 15:04:05")
  561. requestUrl := utils.ApiUrl + "backend/statistics_access?take=1000&skip=0&sort=ASC&mode=all&"
  562. encodeData := url.Values{}
  563. encodeData.Add("start_dt", startTime)
  564. encodeData.Add("end_dt", endTime)
  565. encodeStr := encodeData.Encode()
  566. requestUrl += encodeStr
  567. authorization := utils.ApiAuthorization
  568. body, err := PublicGetDate(requestUrl, authorization)
  569. if err != nil {
  570. return
  571. }
  572. var chartResult models.CeLueArticleResultApi
  573. err = json.Unmarshal(body, &chartResult)
  574. if err != nil {
  575. fmt.Println(err)
  576. return err
  577. }
  578. mapMobileArticleId := make(map[string]int)
  579. //获取当天阅读记录
  580. listPv, err := models.GetArticleHistoryRecordAllList()
  581. if err != nil && err.Error() != utils.ErrNoRow() {
  582. fmt.Println("获取当天阅读记录失败", err)
  583. return err
  584. }
  585. if len(listPv) > 0 {
  586. for _, v := range listPv {
  587. mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
  588. }
  589. }
  590. for _, v := range chartResult.Data {
  591. //fmt.Println(v.ArticleId)
  592. item := new(models.CygxCelueArticleHistoryRecord)
  593. item.CelueHistoryId = v.CelueHistoryId
  594. item.Mobile = v.Mobile
  595. item.ArticleId = v.ArticleId
  596. if v.CrmUser != nil {
  597. item.RealName = v.CrmUser.RealName
  598. }
  599. if v.CompanyName != nil {
  600. item.CompanyName = v.CompanyName.RealName
  601. }
  602. item.CreateDateApi = time.Now()
  603. t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
  604. item.CreateTime = t1.Add(+time.Hour * 8).Format(utils.FormatDateTime)
  605. count, err := models.GetCeLueArticleCountById(v.CelueHistoryId)
  606. if err != nil && err.Error() != utils.ErrNoRow() {
  607. return err
  608. }
  609. if count == 0 {
  610. _, err := models.AddCeLueArticle(item, mapMobileArticleId)
  611. if err != nil {
  612. fmt.Println(err)
  613. return err
  614. }
  615. }
  616. }
  617. //处理同步过来的阅读记录所属用户
  618. var condition string
  619. condition = ` AND create_time > ` + "'" + startTime + "'"
  620. listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
  621. if err != nil {
  622. fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
  623. }
  624. for _, v := range listArticlePv {
  625. if v.Mobile != "" {
  626. user, err := models.GetWxUserItemByMobile(v.Mobile)
  627. if err != nil && err.Error() != utils.ErrNoRow() {
  628. fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
  629. }
  630. if user != nil {
  631. err = models.UpdateCygxArticleHistoryRecordAll(user)
  632. if err != nil {
  633. fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
  634. }
  635. }
  636. }
  637. }
  638. return
  639. }
  640. func GetArticleListByApi(cont context.Context) (err error) {
  641. defer func() {
  642. if err != nil {
  643. //fmt.Println("GetArticleListByApi Err:" + err.Error())
  644. go utils.SendAlarmMsg("同步策略平台数据失败", 2)
  645. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  646. }
  647. }()
  648. listUpdateArticle, err := models.GetArticleCeluePushList()
  649. if err != nil && err.Error() != utils.ErrNoRow() {
  650. return err
  651. }
  652. //如果长度为零就不处理
  653. if len(listUpdateArticle) == 0 {
  654. return err
  655. }
  656. for _, v := range listUpdateArticle {
  657. // 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
  658. err = HandleArticleListByApi(v.ArticleId)
  659. if err != nil {
  660. utils.FileLog.Info("HandleArticleListByApi", err.Error())
  661. }
  662. }
  663. return
  664. }
  665. // 获取策略平台推送过来的文章并更新
  666. func UpdateArticleByRedis() (err error) {
  667. for {
  668. utils.Rc.Brpop(utils.CYGX_ARTICLE_UPDATE_KEY, func(b []byte) {
  669. var log models.CygxArticleCeluePushRedis
  670. if err := json.Unmarshal(b, &log); err != nil {
  671. fmt.Println("json unmarshal wrong!")
  672. go utils.SendAlarmMsg("获取策略平台推送过来的文章并更新处理Redis队列消息失败:"+err.Error()+string(b), 2)
  673. }
  674. // 这里直接go出去会出现并发,导致文章md5ID唯一索引限制报错
  675. err = HandleArticleListByApi(log.ArticleId)
  676. if err != nil {
  677. utils.FileLog.Info("HandleArticleListByApi", err.Error())
  678. }
  679. })
  680. }
  681. }
  682. //func init() {
  683. // // allList, err := models.GetArticleAll()
  684. // //
  685. // // fmt.Println(err)
  686. // //
  687. // // for _, v := range allList {
  688. // // HandleArticleListByApi(v.ArticleId)
  689. // // }
  690. //
  691. // //for i := 8648; i < 9004; i++ {
  692. // // HandleArticleListByApi(9552)
  693. // //}
  694. // HandleArticleListByApi(10914)
  695. // //UpdateArticleResourceData(9551)
  696. //}
  697. // 处理同步过来的文章
  698. func HandleArticleListByApi(artcleId int) (err error) {
  699. defer func() {
  700. if err != nil {
  701. go utils.SendAlarmMsg("处理同步过来的文章失败"+"HandleArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), 2)
  702. }
  703. }()
  704. var clueApiUrl string
  705. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
  706. fmt.Println(clueApiUrl)
  707. authorization := utils.ApiAuthorization
  708. body, err := PublicGetDate(clueApiUrl, authorization)
  709. if err != nil {
  710. fmt.Println(err)
  711. return
  712. }
  713. var articleResultDate models.ArticleDetailResultApi
  714. err = json.Unmarshal(body, &articleResultDate)
  715. if err != nil {
  716. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  717. return err
  718. }
  719. item := new(models.CygxShanghaiCompanyLog)
  720. item.CreateTime = time.Now()
  721. item.Url = clueApiUrl
  722. item.Body = ""
  723. item.Result = string(body)
  724. go models.AddCygxShanghaiCompanyLog(item)
  725. go models.UpdateCygxArticleCeluePush(artcleId)
  726. articleResult := articleResultDate.Data
  727. exitMap := make(map[int]int)
  728. categoryIdMap := make(map[int]int)
  729. classMap := make(map[int]int)
  730. reportMap := make(map[int]int)
  731. summaryMap := make(map[int]int)
  732. listMap, err := models.GetArticleApiMap()
  733. if err != nil {
  734. fmt.Println("GetlistMap Err:", err.Error())
  735. return err
  736. }
  737. openIdList, err := models.GetUserRecordListByMobile(4, utils.ArticleTaskClassMobile)
  738. if err != nil {
  739. fmt.Println(err)
  740. return err
  741. }
  742. fmt.Println(openIdList)
  743. //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
  744. for _, v := range listMap {
  745. exitMap[v.SeriesId] = v.OldId
  746. categoryIdMap[v.SeriesId] = v.OldIdMap
  747. if v.IsClass == 1 {
  748. classMap[v.OldId] = 1
  749. }
  750. if v.IsReport == 1 {
  751. reportMap[v.OldId] = 1
  752. }
  753. if v.IsSummary == 1 {
  754. summaryMap[v.OldId] = 1
  755. }
  756. }
  757. var list []*models.Tactics2
  758. var listArticleData []*models.CygxArticleData
  759. var listAuthor []*models.CygxArticleAuthor
  760. //如果是英文报告 ,或者香港类型那么则不同步 publish_area :all 全部 ;hk 香港
  761. if articleResult.TypeId == 9 || articleResult.PublishArea != "all" {
  762. // 如果是英文报告,或者是香港报告就进行删除处理
  763. err = models.UpdateArticlePublish(artcleId, 0)
  764. if err != nil {
  765. fmt.Println("UpdateArticlePublish Err:", err.Error())
  766. return err
  767. }
  768. UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  769. return
  770. }
  771. var cover string
  772. if articleResult.Series.Name == "图解市场" {
  773. cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
  774. } else if articleResult.Series.Name == "行业深度" {
  775. cover = articleResult.Cover
  776. }
  777. fmt.Println(cover)
  778. //return
  779. //状态等于 2 跟 4 的进行同步 IsActive 为false 软删除的也不同步
  780. if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
  781. 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)
  782. item := new(models.Tactics2)
  783. itemArticleData := new(models.CygxArticleData)
  784. itemArticleData.ArticleId = articleResult.ArticleId
  785. itemArticleData.Cover = articleResult.Cover
  786. itemArticleData.CreateTime = time.Now()
  787. listArticleData = append(listArticleData, itemArticleData)
  788. itemAuthor := new(models.CygxArticleAuthor)
  789. item.ArticleId = articleResult.ArticleId
  790. item.Title = articleResult.Title
  791. item.TitleEn = articleResult.TitleEn
  792. item.File = articleResult.File
  793. if articleResult.Frequency == "日度" {
  794. item.UpdateFrequency = "daily"
  795. } else if articleResult.Frequency == "周度" {
  796. item.UpdateFrequency = "weekly"
  797. } else if articleResult.Frequency == "月度" {
  798. item.UpdateFrequency = "monthly"
  799. } else if articleResult.Frequency == "季度" {
  800. item.UpdateFrequency = "quarterly"
  801. } else if articleResult.Frequency == "年度" {
  802. item.UpdateFrequency = "yearly"
  803. } else {
  804. item.UpdateFrequency = "unknow"
  805. }
  806. item.CreateDate = articleResult.CreateDate
  807. item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
  808. item.PublishStatus = 1
  809. item.Body = articleResult.Content.Body
  810. item.Abstract = articleResult.Content.Abstract
  811. item.Annotation = articleResult.Content.Annotation
  812. item.CategoryName = articleResult.Industry.Name
  813. item.CategoryId = categoryIdMap[articleResult.SeriesId]
  814. item.CategoryIdTwo = exitMap[articleResult.SeriesId]
  815. item.SubCategoryName = articleResult.Series.Name
  816. item.Cover = cover
  817. {
  818. //这两种情况特殊处理
  819. if articleResult.Field.Name == "宏观利率" {
  820. item.CategoryId = 10070
  821. item.CategoryIdTwo = item.CategoryId
  822. }
  823. if articleResult.Field.Name == "信用" {
  824. item.CategoryId = 10082
  825. item.CategoryIdTwo = item.CategoryId
  826. }
  827. }
  828. if len(articleResult.Stock) > 0 {
  829. var stock string
  830. for _, vS := range articleResult.Stock {
  831. stock += vS + "/"
  832. }
  833. stock = strings.TrimRight(stock, "/")
  834. item.Stock = stock
  835. }
  836. item.FieldName = articleResult.Field.Name
  837. item.TypeName = articleResult.Type.Name
  838. item.UpdateDate = articleResult.UpdateDate
  839. item.CeLueFieldId = articleResult.Field.Id
  840. list = append(list, item)
  841. itemAuthor.ArticleId = articleResult.ArticleId
  842. itemAuthor.Name = articleResult.Author.Name
  843. itemAuthor.Mobile = articleResult.Author.PhoneNumber
  844. fmt.Println(articleResult.Cover)
  845. listAuthor = append(listAuthor, itemAuthor)
  846. } else {
  847. // 如果这篇文章没有发布,那么就不作处理。
  848. err = models.UpdateArticlePublish(artcleId, 0)
  849. if err != nil {
  850. fmt.Println("UpdateArticlePublish Err:", err.Error())
  851. return err
  852. }
  853. UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  854. //go UpdateResourceData(artcleId, "article", "delete", time.Now().Format(utils.FormatDateTime))
  855. return
  856. }
  857. //同步作者
  858. for _, v := range listAuthor {
  859. var count int
  860. count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  861. if err != nil {
  862. fmt.Println("GetActivityAuthorCount Err:", err.Error())
  863. return err
  864. }
  865. if count == 0 {
  866. _, err = models.AddCygxActivityAuthor(v)
  867. if err != nil {
  868. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  869. return err
  870. }
  871. }
  872. }
  873. fmt.Println("同步文章条数:", len(list))
  874. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  875. if err != nil {
  876. fmt.Println("GetTacticsList Err:", err.Error())
  877. return err
  878. }
  879. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  880. if errMatch != nil {
  881. fmt.Println("GetTacticsList Err:", errMatch.Error())
  882. return err
  883. }
  884. //mapCategoryIdSet := make(map[int]int)
  885. //for _, vMatch := range listGetMatchTypeName {
  886. // mapCategoryIdSet[vMatch.CategoryId] = vMatch.CategoryIdSet
  887. //}
  888. fmt.Println("list len:", len(list))
  889. 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
  890. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  891. for k, v := range list {
  892. //同步匹配类型
  893. matchTypeName := ""
  894. for _, vMatch := range listGetMatchTypeName {
  895. if v.CategoryId == vMatch.CategoryId {
  896. matchTypeName = vMatch.MatchTypeName
  897. }
  898. }
  899. //是否属于纪要库的数据
  900. //if _, has := summaryMap[v.CategoryId]; has {
  901. // v.IsSummary = 1
  902. //}
  903. if v.TypeName == "纪要" {
  904. v.IsSummary = 1
  905. }
  906. //排除不属于纪要库类型的文章
  907. for _, vArt := range listNoSummaryArticleIds {
  908. vArtInt, _ := strconv.Atoi(vArt)
  909. if v.ArticleId == vArtInt {
  910. v.IsSummary = 0
  911. }
  912. }
  913. if _, has := reportMap[v.CategoryIdTwo]; has {
  914. v.IsReport = 1
  915. if _, ok := classMap[v.CategoryIdTwo]; ok {
  916. v.IsClass = 1
  917. v.ReportType = 1 //是否属于行业报告
  918. } else {
  919. v.ReportType = 2 //是否属于产业报告
  920. }
  921. }
  922. v.Department = "弘则权益研究"
  923. //判断是否已经存在
  924. if v.ArticleId < 0 {
  925. fmt.Println("AddCygxArticle Err:")
  926. return err
  927. }
  928. var count int
  929. count, err = models.GetArticleCountById(v.ArticleId)
  930. if err != nil && err.Error() != utils.ErrNoRow() {
  931. fmt.Println("AddCygxArticle Err:", err.Error())
  932. return err
  933. }
  934. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  935. expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
  936. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  937. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  938. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  939. v.Body = strings.Replace(v.Body, "):", "", -1)
  940. }
  941. var titleNew string
  942. titleNew = v.Title
  943. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  944. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  945. if v.UpdateFrequency == "daily" {
  946. var daystr string
  947. daystr = strconv.Itoa(v.PublishDate.Day())
  948. if len(daystr) == 1 {
  949. daystr = "0" + daystr
  950. }
  951. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  952. } else if v.UpdateFrequency == "weekly" {
  953. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  954. }
  955. }
  956. //策略周度思考,医药周报,消费周报,消费周度思考,科技前言(周报)、智造精粹、智造本周荟 标题处理
  957. if v.CategoryId == 80 || v.CategoryId == 52 || v.CategoryId == 10074 || v.CategoryId == 1008 || v.CategoryId == 10071 || v.CategoryId == 10073 || v.CategoryId == 50 {
  958. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  959. }
  960. //类型是综述报告的,不区分是什么系列,统一归类到对应产业的路演精华
  961. if articleResult.Type.Name == "综述报告" {
  962. detailCategory, err := models.GetdetailByCategoryIdLyjh(v.CategoryIdTwo)
  963. if err != nil && err.Error() != utils.ErrNoRow() {
  964. return err
  965. }
  966. v.CategoryId = detailCategory.CategoryId
  967. v.IsSummary = 0
  968. }
  969. if count > 0 {
  970. fmt.Println(k, v.ArticleId, "edit")
  971. articleIfoOld, e := models.GetArticleDetailTestById(v.ArticleId)
  972. if e != nil {
  973. err = e
  974. return
  975. }
  976. bodyTextOld, _ := GetReportContentTextSubNew(articleIfoOld.Body)
  977. bodyText, _ := GetReportContentTextSubNew(v.Body)
  978. if len(bodyText)-len(bodyTextOld) > 100 {
  979. //fmt.Println("触发推送规则")
  980. //更新字数大于一百字触发推送规则
  981. go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  982. go UpdateArticleResourceData(v.ArticleId) //把数据写入 cygx_resource_data 表
  983. //go UpdateResourceData(v.ArticleId, "article", "update", time.Now().Format(utils.FormatDateTime))
  984. }
  985. var isCustom bool
  986. updateParams := make(map[string]interface{})
  987. //updateParams["Title"] = v.Title
  988. updateParams["Title"] = titleNew
  989. updateParams["TitleEn"] = v.TitleEn
  990. updateParams["UpdateFrequency"] = v.UpdateFrequency
  991. updateParams["CreateDate"] = v.CreateDate
  992. updateParams["PublishDate"] = v.PublishDate
  993. //updateParams["Body"] = html.EscapeString(v.Body)
  994. updateParams["Body"] = html.EscapeString(bodyReturn)
  995. updateParams["BodyText"] = bodyText
  996. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  997. updateParams["CategoryName"] = v.CategoryName
  998. for _, vCustom := range listCustomArticle {
  999. if v.ArticleId == vCustom.ArticleId {
  1000. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  1001. isCustom = true
  1002. }
  1003. }
  1004. if isCustom == false {
  1005. updateParams["CategoryId"] = v.CategoryId
  1006. updateParams["MatchTypeName"] = matchTypeName
  1007. updateParams["IsSummary"] = v.IsSummary
  1008. updateParams["IsReport"] = v.IsReport
  1009. updateParams["ReportType"] = v.ReportType
  1010. updateParams["SubCategoryName"] = v.SubCategoryName
  1011. }
  1012. //updateParams["CategoryId"] = v.CategoryId
  1013. updateParams["PublishStatus"] = 1
  1014. updateParams["ExpertBackground"] = expertContentStr
  1015. updateParams["ExpertNumber"] = expertNumStr
  1016. updateParams["InterviewDate"] = interviewDateStr
  1017. //updateParams["IsClass"] = v.IsClass
  1018. v.Department = "弘则权益研究"
  1019. updateParams["Department"] = v.Department
  1020. updateParams["FileLink"] = v.File
  1021. updateParams["Stock"] = v.Stock
  1022. updateParams["FieldName"] = v.FieldName
  1023. updateParams["Annotation"] = v.Annotation
  1024. updateParams["TypeName"] = v.TypeName
  1025. updateParams["ModifyTimeByCl"] = v.UpdateDate
  1026. updateParams["CeLueFieldId"] = v.CeLueFieldId
  1027. updateParams["Cover"] = v.Cover
  1028. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  1029. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  1030. if err != nil {
  1031. fmt.Println("UpdateByExpr Err:" + err.Error())
  1032. return err
  1033. }
  1034. } else {
  1035. fmt.Println(k, v.ArticleId, "add")
  1036. item := new(models.CygxArticle)
  1037. articleIdInt := v.ArticleId
  1038. item.ArticleId = articleIdInt
  1039. //item.Title = v.Title
  1040. item.Title = titleNew
  1041. item.TitleEn = v.TitleEn
  1042. item.UpdateFrequency = v.UpdateFrequency
  1043. item.CreateDate = v.CreateDate
  1044. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  1045. //item.Body = html.EscapeString(v.Body)
  1046. item.Body = html.EscapeString(bodyReturn)
  1047. item.Abstract = html.EscapeString(v.Abstract)
  1048. item.CategoryName = v.CategoryName
  1049. item.SubCategoryName = v.SubCategoryName
  1050. item.CategoryId = v.CategoryId
  1051. item.CategoryIdTwo = v.CategoryIdTwo
  1052. item.PublishStatus = 1
  1053. item.ExpertBackground = expertContentStr
  1054. item.ExpertNumber = expertNumStr
  1055. item.InterviewDate = interviewDateStr
  1056. item.Department = v.Department
  1057. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  1058. item.IsClass = v.IsClass
  1059. item.IsSummary = v.IsSummary
  1060. item.IsReport = v.IsReport
  1061. item.ReportType = v.ReportType
  1062. item.FileLink = v.File
  1063. item.MatchTypeName = matchTypeName
  1064. item.Stock = v.Stock
  1065. item.FieldName = v.FieldName
  1066. item.Annotation = v.Annotation
  1067. item.TypeName = v.TypeName
  1068. item.ModifyTimeByCl = v.UpdateDate
  1069. item.CeLueFieldId = v.CeLueFieldId
  1070. item.Cover = v.Cover
  1071. newId, err := models.AddCygxArticles(item)
  1072. if err != nil {
  1073. fmt.Println("AddCygxArticle Err:", err.Error())
  1074. return err
  1075. }
  1076. //go UpdateResourceData(v.ArticleId, "article", "add", time.Now().Format(utils.FormatDateTime))
  1077. go UpdateArticleResourceData(v.ArticleId) //把数据写入 cygx_resource_data 表
  1078. //fmt.Println(newId)
  1079. //报告自动归类,以及推送相关模板消息
  1080. if v.ReportType == 2 {
  1081. var subjectStr string
  1082. var industrialManagementIdStr string
  1083. var industrialSubjectIdStr string
  1084. var keyword1 string
  1085. var keyword2 string
  1086. var keyword3 string
  1087. var keyword4 string
  1088. sliceSubjects := strings.Split(v.Stock, "/")
  1089. mapManagementForSubject := make(map[string]string)
  1090. mapIndustrialId := make(map[int]int)
  1091. if len(sliceSubjects) > 0 {
  1092. for _, vSubject := range sliceSubjects {
  1093. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  1094. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  1095. subject := sliceXiahuaxian[0]
  1096. subjectStr += "'" + subject + "',"
  1097. }
  1098. //获取该产业下所对应的行业图片
  1099. detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
  1100. if errCategory != nil {
  1101. fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
  1102. return err
  1103. }
  1104. subjectStr = strings.TrimRight(subjectStr, ",")
  1105. if subjectStr != "" {
  1106. listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
  1107. if err != nil {
  1108. fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
  1109. return err
  1110. }
  1111. subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
  1112. subjectStr = strings.Replace(subjectStr, "'", "", -1)
  1113. subjectStr = "【" + subjectStr + "】"
  1114. if len(listIndustrial) > 0 {
  1115. for _, vIndustrial := range listIndustrial {
  1116. if _, ok := mapIndustrialId[vIndustrial.IndustrialManagementId]; !ok {
  1117. industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
  1118. }
  1119. mapIndustrialId[vIndustrial.IndustrialManagementId] = vIndustrial.IndustrialManagementId
  1120. industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
  1121. mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
  1122. if vIndustrial.LayoutTime == "0000-00-00 00:00:00" {
  1123. go models.UpdateIndustrialManagementLayoutTime(v.PublishDate.AddDate(0, 0, -10).Format(utils.FormatDateTime), vIndustrial.IndustrialManagementId)
  1124. }
  1125. }
  1126. industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
  1127. industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
  1128. if industrialManagementIdStr != "" {
  1129. err = models.ReportArticleClassificationEditNew(int(newId), industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
  1130. if err != nil {
  1131. fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
  1132. return err
  1133. }
  1134. }
  1135. var peoductName string
  1136. for mk, mv := range mapManagementForSubject {
  1137. peoductName += "【" + mk + "--" + strings.TrimRight(mv, "/") + "】"
  1138. }
  1139. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  1140. keyword2 = "已自动关联至以下产业和标的:" + peoductName
  1141. keyword3 = v.Title
  1142. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  1143. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  1144. } else {
  1145. keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
  1146. keyword2 = "未归类"
  1147. keyword3 = v.Title
  1148. keyword4 = v.PublishDate.Format(utils.FormatDateTime)
  1149. SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
  1150. go models.UpdateIsClassFail(artcleId)
  1151. }
  1152. }
  1153. }
  1154. }
  1155. go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  1156. }
  1157. //【公司调研】系列纪要发布/更新后 end
  1158. //查研观向6.9模板消息推送规则
  1159. //但是如果报告的发布时间是在10天以前的,公众号就不推送了
  1160. //if time.Now().AddDate(0, 0, -10).Before(articleResult.PublishDate.Add(time.Hour * 8)) {
  1161. // go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
  1162. //}
  1163. }
  1164. go models.UpdateCygxArticleCeluePush(artcleId)
  1165. AddComprehensiveArticle(artcleId) // 同步到综合页面的搜索引擎
  1166. AddComprehensiveIndustrialSource("Hz", artcleId) // 同步到综合页面的搜索引擎(添加产业资源包)
  1167. GetSummarytoEs(artcleId) // 同步到ES搜索引擎
  1168. GetIndustrialManagementArticleNewPublishData()
  1169. if len(listArticleData) > 0 {
  1170. for _, v := range listArticleData {
  1171. count, err := models.GetCygxArticleDataCount(v.ArticleId)
  1172. if err != nil {
  1173. fmt.Println("GetCygxArticleDataCount Err:", err.Error())
  1174. return err
  1175. }
  1176. if count == 0 {
  1177. _, err := models.AddCygxArticleData(v)
  1178. if err != nil {
  1179. fmt.Println("AddCygxArticleData Err:", err.Error())
  1180. return err
  1181. }
  1182. }
  1183. //} else {
  1184. // updateParams := make(map[string]interface{})
  1185. // updateParams["Cover"] = v.Cover
  1186. // whereParam := map[string]interface{}{"article_id": v.ArticleId}
  1187. // err = models.UpdateByExpr(models.CygxArticleData{}, whereParam, updateParams)
  1188. // if err != nil {
  1189. // fmt.Println("UpdateByExpr CygxArticleData Err:" + err.Error())
  1190. // return err
  1191. // }
  1192. //}
  1193. }
  1194. }
  1195. AddCygxReportMappingCategoryGroupByArticleId(artcleId)
  1196. return err
  1197. }
  1198. //func init() {
  1199. // DoArticleOnenIdWxTemplateMsg(8112)
  1200. //}
  1201. // 过滤策略平台报告,研选报告重复推送,以及权限勾选的推送
  1202. func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
  1203. //策略平台同步过来的文章ID,做微信模板消息推送,同一篇报告12小时只推送一次
  1204. cacheKey := fmt.Sprint(utils.CACHE_KEY_ARTICLE_ID_TEMPLATE, ":ArticleId", articleId)
  1205. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  1206. if ttlTime > 0 {
  1207. fmt.Println(ttlTime)
  1208. return err
  1209. }
  1210. var msg string
  1211. defer func() {
  1212. if err != nil {
  1213. go utils.SendAlarmMsg("过滤策略平台报告,研选报告重复推送,以及权限勾选的推送失败 DoArticleOnenIdWxTemplateMsg ErrMsg:"+err.Error(), 2)
  1214. fmt.Println(err)
  1215. }
  1216. if msg != "" {
  1217. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1218. }
  1219. }()
  1220. //获取文章详情
  1221. articleInfo, err := models.GetArticleDetailById(articleId)
  1222. if err != nil {
  1223. return
  1224. }
  1225. articleInfo.Abstract, _ = GetReportContentTextSub(articleInfo.Abstract)
  1226. var chartPermissionId int
  1227. //固收的权限,暂时当策略的逻辑一样处理
  1228. var chartPermissionName string
  1229. reportMapDetail, err := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  1230. if err != nil {
  1231. return err
  1232. }
  1233. if reportMapDetail.ChartPermissionId == utils.CE_LUE_ID {
  1234. chartPermissionId = utils.CE_LUE_ID
  1235. } else if reportMapDetail.ChartPermissionId == utils.GU_SHOU_ID_CHART {
  1236. chartPermissionId = utils.GU_SHOU_ID_CHART
  1237. } else {
  1238. if reportMapDetail.PermissionType == 1 {
  1239. chartPermissionName = reportMapDetail.ChartPermissionName + "(主观)"
  1240. } else {
  1241. chartPermissionName = reportMapDetail.ChartPermissionName + "(客观)"
  1242. }
  1243. chartPermissionDetail, err := models.GetChartPermissionByRemark(chartPermissionName)
  1244. if err != nil {
  1245. return err
  1246. }
  1247. chartPermissionId = chartPermissionDetail.ChartPermissionId
  1248. }
  1249. //文章关联的产业
  1250. var industryName string
  1251. var industrialManagementId string
  1252. if chartPermissionId == utils.CE_LUE_ID || chartPermissionId == utils.GU_SHOU_ID_CHART {
  1253. industryName = reportMapDetail.SubCategoryName
  1254. } else {
  1255. if articleInfo.ReportType == 2 {
  1256. detailIndustryNameList, err := models.GetIndustrialManagemenDetailByAaticleID(articleId)
  1257. if err != nil && err.Error() != utils.ErrNoRow() {
  1258. return err
  1259. }
  1260. //如果不存在关联的产业则不推送
  1261. if len(detailIndustryNameList) == 0 {
  1262. return err
  1263. }
  1264. for _, v := range detailIndustryNameList {
  1265. industryName += v.IndustryName + ","
  1266. industrialManagementId += strconv.Itoa(v.IndustrialManagementId) + ","
  1267. }
  1268. industryName = strings.TrimRight(industryName, ",")
  1269. industrialManagementId = strings.TrimRight(industrialManagementId, ",")
  1270. //处理勾选了全部行业赛道的用户
  1271. var allIn string
  1272. allIn = DoXzsChooseSend(reportMapDetail.ChartPermissionName)
  1273. if allIn != "" {
  1274. allInList, err := models.GetCygxXzsChooseSendByAllIn(allIn)
  1275. if err != nil && err.Error() != utils.ErrNoRow() {
  1276. return err
  1277. }
  1278. if len(allInList) > 0 {
  1279. var allInUserId string
  1280. for _, v := range allInList {
  1281. allInUserId += strconv.Itoa(v.UserId) + ","
  1282. }
  1283. allInUserId = strings.TrimRight(allInUserId, ",")
  1284. userFllowIndustrialList, err := models.GetUserFllowIndustrialListByUserIdAndIndustrial(allInUserId, industrialManagementId)
  1285. if err != nil && err.Error() != utils.ErrNoRow() {
  1286. return err
  1287. }
  1288. mapUserFllowed := make(map[string]int)
  1289. for _, v := range userFllowIndustrialList {
  1290. //用户ID与其关注的产业组成唯一索引,判断是否存在,如果不存在就进行自动关注
  1291. mapUserFllowed[fmt.Sprint("uid:", v.UserId, "_Industrial:", v.IndustrialManagementId)] = v.UserId
  1292. }
  1293. //获取这些allIN用户的的信息进行遍历生成需要插入的数据
  1294. userList, err := models.GetWxUserListByUserIds(allInUserId)
  1295. if err != nil && err.Error() != utils.ErrNoRow() {
  1296. return err
  1297. }
  1298. var industryFllowItems []*models.CygxIndustryFllow
  1299. for _, v := range detailIndustryNameList {
  1300. for _, vUser := range userList {
  1301. //如果用户这个用户没有关注这个产业就进行自动关注
  1302. if mapUserFllowed[fmt.Sprint("uid:", vUser.UserId, "_Industrial:", v.IndustrialManagementId)] == 0 {
  1303. item := new(models.CygxIndustryFllow)
  1304. item.IndustrialManagementId = v.IndustrialManagementId
  1305. item.UserId = vUser.UserId
  1306. item.Email = vUser.Email
  1307. item.Mobile = vUser.Mobile
  1308. item.RealName = vUser.RealName
  1309. item.CompanyId = vUser.CompanyId
  1310. item.CompanyName = vUser.CompanyName
  1311. item.Source = 3
  1312. item.Type = 1
  1313. item.CreateTime = time.Now()
  1314. item.ModifyTime = time.Now()
  1315. industryFllowItems = append(industryFllowItems, item)
  1316. }
  1317. }
  1318. }
  1319. err = models.AddCygxIndustryFllowMulti(industryFllowItems)
  1320. if err != nil {
  1321. go utils.SendAlarmMsg("用户关注全部赛道,出现新赛道批量添加失败 ,AddCygxIndustryFllowMulti ErrMsg:"+err.Error(), 2)
  1322. }
  1323. }
  1324. }
  1325. }
  1326. }
  1327. // 获取所有有权的用户的 openid
  1328. mapOpenidPower := make(map[int]string)
  1329. permissionIdList := make([]string, 0)
  1330. var condition string
  1331. var pars []interface{}
  1332. slicepermissionId := strings.Split(strconv.Itoa(chartPermissionId), ",")
  1333. if len(slicepermissionId) > 0 {
  1334. for _, v := range slicepermissionId {
  1335. if v == strconv.Itoa(utils.GU_SHOU_ID_CHART) {
  1336. v = strconv.Itoa(utils.CE_LUE_ID)
  1337. }
  1338. permissionIdList = append(permissionIdList, v)
  1339. }
  1340. condition += ` AND p.chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) `
  1341. pars = append(pars, permissionIdList)
  1342. }
  1343. openidPowerListMobile, err := models.GetCygxUserRecordPower(condition, pars)
  1344. if err != nil {
  1345. return err
  1346. }
  1347. var mobileArr []string
  1348. for _, v := range openidPowerListMobile {
  1349. mobileArr = append(mobileArr, v.Mobile)
  1350. }
  1351. openidPowerList, err := models.GetWxOpenIdByMobileSliceList(mobileArr)
  1352. if err != nil {
  1353. return err
  1354. }
  1355. //四大行业的行业综述报告,对所有开通了对应行业权限的客户都推送。
  1356. if articleInfo.ReportType == 1 && chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID_CHART {
  1357. for _, item := range openidPowerList {
  1358. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1359. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1360. openIditem := new(models.OpenIdList)
  1361. openIditem.OpenId = item.OpenId
  1362. openIditem.UserId = item.UserId
  1363. SendWxMsgWithArticleUpdate(first, keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIditem, articleId)
  1364. }
  1365. return err
  1366. }
  1367. for _, v := range openidPowerList {
  1368. mapOpenidPower[v.UserId] = v.OpenId
  1369. }
  1370. //获取关注这个文章对应产业的用户的 openid
  1371. mapOpenidFllow := make(map[int]string)
  1372. if chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID_CHART {
  1373. openidFllowListMobile, err := models.GetCygxUserFllowOpenid(articleId)
  1374. if err != nil {
  1375. return err
  1376. }
  1377. var mobileArrFllow []string
  1378. for _, v := range openidFllowListMobile {
  1379. mobileArrFllow = append(mobileArrFllow, v.Mobile)
  1380. }
  1381. openidFllowList, err := models.GetWxOpenIdByMobileSliceList(mobileArrFllow)
  1382. if err != nil {
  1383. return err
  1384. }
  1385. for _, v := range openidFllowList {
  1386. mapOpenidFllow[v.UserId] = v.OpenId
  1387. }
  1388. }
  1389. //获取拒绝接收推送的的用户的 openid
  1390. mapOpenidRefuset := make(map[int]string)
  1391. openidRefusetList, err := models.GetCygxUserRefusetOpenid()
  1392. if err != nil {
  1393. return err
  1394. }
  1395. for _, v := range openidRefusetList {
  1396. mapOpenidRefuset[v.UserId] = v.OpenId
  1397. }
  1398. //获取提交过推送规则的用户的 openid
  1399. mapUserIdChooseSend := make(map[int]int)
  1400. mapUserIdChooseSendTypeNoPermission := make(map[int]int)
  1401. chooseSendtList, err := models.GetCygxXzsChooseSend()
  1402. for _, v := range chooseSendtList {
  1403. mapUserIdChooseSend[v.UserId] = v.UserId
  1404. if v.IsRefuse == 1 {
  1405. continue
  1406. }
  1407. //获取选择主客观赛道的用户
  1408. if reportMapDetail.PermissionType == 1 {
  1409. if v.IsSubjective == 1 {
  1410. mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1411. }
  1412. } else {
  1413. if v.IsObjective == 1 {
  1414. mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
  1415. }
  1416. }
  1417. }
  1418. //已经推送了的openid
  1419. mapOpenidPushed := make(map[int]string)
  1420. keyword2 := articleInfo.Title
  1421. keyword3 := time.Now().Format(utils.FormatDateTime)
  1422. keyword4 := articleInfo.Abstract
  1423. mapAlreadySend := make(map[int]int)
  1424. //如果是策略就按照策略的推送方式来写
  1425. if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME || reportMapDetail.ChartPermissionName == utils.GU_SHOU_NAME {
  1426. //获取提交过推送规则的用户的 openid
  1427. mapUserFllowCeLue := make(map[int]string)
  1428. userFllowCeLueList, err := models.GetCygxUserFllowCeLueOpenid(articleInfo.CategoryId)
  1429. if err != nil {
  1430. return err
  1431. }
  1432. for _, v := range userFllowCeLueList {
  1433. mapUserFllowCeLue[v.UserId] = v.OpenId
  1434. }
  1435. for k, v := range mapOpenidPower {
  1436. if mapOpenidPushed[k] != "" {
  1437. continue
  1438. }
  1439. openIditem := new(models.OpenIdList)
  1440. openIditem.UserId = k
  1441. openIditem.OpenId = v
  1442. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1443. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1444. mapActivityUserId := make(map[int]string)
  1445. if articleInfo.ReportType == 2 {
  1446. sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1447. if sliceSubjectId != "" {
  1448. appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1449. if err != nil {
  1450. fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
  1451. return err
  1452. }
  1453. var userIds []string
  1454. if len(appointmentList) > 0 {
  1455. for _, v := range appointmentList {
  1456. //fmt.Println("mapActivityUserId:", v.UserId)
  1457. userIds = append(userIds, strconv.Itoa(v.UserId))
  1458. mapActivityUserId[v.UserId] += v.ActivityName + ","
  1459. }
  1460. userIdstr := strings.Join(userIds, ",")
  1461. openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
  1462. if err != nil {
  1463. fmt.Println("GetOpenIdByUserIds Err:", err.Error())
  1464. return err
  1465. }
  1466. for _, item := range openIdLists {
  1467. first := "您预约的调研,有关联的纪要发布/更新了"
  1468. keyword1 := industryName
  1469. openIditem := new(models.OpenIdList)
  1470. openIditem.OpenId = item.OpenId
  1471. openIditem.UserId = item.UserId
  1472. if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1473. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1474. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1475. fmt.Println("AlreadySend:", openIditem.UserId)
  1476. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1477. }
  1478. }
  1479. }
  1480. }
  1481. //fmt.Println("openIditem.UserId:", openIditem.UserId)
  1482. //if _,ok := mapActivityUserId[openIditem.UserId]; ok{
  1483. // first = "您预约的调研,有关联的纪要发布/更新了"
  1484. // keyword1 = industryName
  1485. // SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1486. // delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1487. // mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1488. //}
  1489. }
  1490. _, ok := mapAlreadySend[openIditem.UserId]
  1491. //如果有权限而且小助手没有提交过信息的 就做正常推送
  1492. if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1493. fmt.Println("1:", articleId)
  1494. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1495. }
  1496. //如果小助手勾选了对应的权限信息 就做正常推送
  1497. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != "" && !ok {
  1498. fmt.Println("2:", articleId)
  1499. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1500. }
  1501. }
  1502. } else {
  1503. for k, v := range mapOpenidPower {
  1504. if mapOpenidPushed[k] != "" {
  1505. continue
  1506. }
  1507. mapUserIdChooseSendType := make(map[int]int)
  1508. for _, vS := range chooseSendtList {
  1509. if vS.IsRefuse == 1 {
  1510. continue
  1511. }
  1512. //获取选择主客观赛道的用户
  1513. if reportMapDetail.PermissionType == 1 {
  1514. if vS.IsSubjective == 1 {
  1515. mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1516. }
  1517. } else if reportMapDetail.PermissionType == 2 {
  1518. if vS.IsObjective == 1 {
  1519. mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1520. }
  1521. } else {
  1522. if vS.IsSubjective == 1 || vS.IsObjective == 1 {
  1523. mapUserIdChooseSendType[vS.UserId] = vS.UserId
  1524. }
  1525. }
  1526. }
  1527. openIditem := new(models.OpenIdList)
  1528. openIditem.UserId = k
  1529. openIditem.OpenId = v
  1530. first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
  1531. keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
  1532. mapActivityUserId := make(map[int]string)
  1533. if articleInfo.ReportType == 2 {
  1534. keyword1 = fmt.Sprint("【", industryName, "】有报告发布/更新")
  1535. sliceSubjectId, _ := models.GetSubjectIds(articleId)
  1536. if sliceSubjectId != "" {
  1537. appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
  1538. if err != nil {
  1539. fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
  1540. return err
  1541. }
  1542. var userIds []string
  1543. if len(appointmentList) > 0 {
  1544. for _, v := range appointmentList {
  1545. //fmt.Println("mapActivityUserId:", v.UserId)
  1546. userIds = append(userIds, strconv.Itoa(v.UserId))
  1547. mapActivityUserId[v.UserId] += v.ActivityName + ","
  1548. }
  1549. userIdstr := strings.Join(userIds, ",")
  1550. openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
  1551. if err != nil {
  1552. fmt.Println("GetOpenIdByUserIds Err:", err.Error())
  1553. return err
  1554. }
  1555. for _, item := range openIdLists {
  1556. //first := "您预约的调研,有关联的纪要发布/更新了"
  1557. //keyword1 := industryName
  1558. openIditem := new(models.OpenIdList)
  1559. openIditem.OpenId = item.OpenId
  1560. openIditem.UserId = item.UserId
  1561. if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
  1562. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1563. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1564. fmt.Println("AlreadySend:", openIditem.UserId)
  1565. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. //如果有权限而且小助手没有提交过信息的 就做正常推送
  1572. _, ok := mapAlreadySend[openIditem.UserId]
  1573. if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
  1574. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1575. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1576. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1577. }
  1578. //如果小助手勾选了对应的权限信息 就做正常推送
  1579. if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" && mapUserIdChooseSendType[openIditem.UserId] > 0 && !ok {
  1580. SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
  1581. delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
  1582. mapAlreadySend[openIditem.UserId] = openIditem.UserId
  1583. }
  1584. }
  1585. }
  1586. utils.Rc.Put(cacheKey, articleId, time.Hour*12)
  1587. return
  1588. }
  1589. // GetSpecialArticleDetailUserPower 处理用户查看专项调研文章详情的权限
  1590. func GetSpecialArticleDetailUserPower(user *models.WxUserItem, articleInfo *models.ArticleDetail) (havePower bool, err error) {
  1591. userType, _, e := GetUserType(user.CompanyId)
  1592. if e != nil {
  1593. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  1594. return
  1595. }
  1596. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  1597. if userType == 1 || userType == 2 {
  1598. havePower = true
  1599. return
  1600. }
  1601. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  1602. if e != nil {
  1603. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  1604. return
  1605. }
  1606. reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  1607. if e != nil {
  1608. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  1609. return
  1610. }
  1611. if reportMapDetail == nil {
  1612. err = errors.New("GetdetailByCategoryIdP,获取详情失败, ")
  1613. return
  1614. }
  1615. fmt.Println(permissionStr)
  1616. //如果没有对应的升级权限,则返回
  1617. if !strings.Contains(permissionStr, reportMapDetail.ChartPermissionName) {
  1618. return
  1619. } else {
  1620. havePower = true
  1621. }
  1622. return
  1623. }
  1624. //func init() {
  1625. // GetArticNewLabelWhithActivity3Month()
  1626. //}
  1627. // 弘则报告发布日期在三个月以内的
  1628. func GetArticNewLabelWhithActivity3Month() (labelMap map[int]bool, err error) {
  1629. var condition string
  1630. var pars []interface{}
  1631. condition += ` AND publish_date <= ? AND article_id < ? `
  1632. pars = append(pars, time.Now().AddDate(0, -3, 0), utils.SummaryArticleId)
  1633. articleList, e := models.GetArticleList(condition, pars)
  1634. if e != nil {
  1635. err = errors.New("GetArticleList, Err: " + e.Error())
  1636. return
  1637. }
  1638. var articleIds []int
  1639. for _, v := range articleList {
  1640. articleIds = append(articleIds, v.ArticleId)
  1641. }
  1642. if len(articleIds) == 0 {
  1643. return
  1644. }
  1645. pars = make([]interface{}, 0)
  1646. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1647. pars = append(pars, articleIds)
  1648. industrialList, e := models.GetIndustrialArticleGroupManagementList(condition, pars)
  1649. if e != nil {
  1650. err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error())
  1651. return
  1652. }
  1653. labelMap = make(map[int]bool, 0)
  1654. var industrialIds []int
  1655. for _, v := range industrialList {
  1656. industrialIds = append(industrialIds, v.IndustrialManagementId)
  1657. }
  1658. // 获取活动关联的产业
  1659. var groupCond string
  1660. var groupPars []interface{}
  1661. groupCond += ` AND b.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIds)) + `) AND b.source = 1 `
  1662. groupPars = append(groupPars, industrialIds)
  1663. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  1664. if e != nil {
  1665. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  1666. return
  1667. }
  1668. for _, v := range groups {
  1669. labelMap[v.ActivityId] = true
  1670. }
  1671. return
  1672. }
  1673. // HandleArticleCategoryImg 预处理文章的封面图片
  1674. func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeArticle, err error) {
  1675. //研选的五张图片
  1676. detailResearch, e := models.GetConfigByCode("category_research_img_url")
  1677. if e != nil {
  1678. err = errors.New("获取研选的五张图片失败" + e.Error())
  1679. return
  1680. }
  1681. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  1682. //对应分类的所图片
  1683. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  1684. if err != nil {
  1685. err = errors.New("获取对应分类的所图片失败" + err.Error())
  1686. return
  1687. }
  1688. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  1689. mapCategoryUrl := make(map[string]string)
  1690. var categoryId string
  1691. var imgUrlChart string
  1692. for _, v := range categoryUrlList {
  1693. vslice := strings.Split(v, "_")
  1694. categoryId = vslice[0]
  1695. imgUrlChart = vslice[len(vslice)-1]
  1696. mapCategoryUrl[categoryId] = imgUrlChart
  1697. }
  1698. mapChartPerssion := make(map[string]string)
  1699. reportMappingList, err := models.GetReportMappingStrategyAll()
  1700. if err != nil {
  1701. err = errors.New("GetReportMappingStrategyAll err" + err.Error())
  1702. return
  1703. }
  1704. for _, v := range reportMappingList {
  1705. mapChartPerssion[strconv.Itoa(v.CategoryId)] = v.ChartPermissionName
  1706. }
  1707. for k, v := range list {
  1708. list[k].Abstract, _ = GetReportContentTextSub(v.Abstract)
  1709. item := list[k]
  1710. //如果文章一开始的内容是图片,优先展示第一张图片
  1711. if list[k].Annotation == "" {
  1712. imgurl, _ := FixArticleImgUrl(html.UnescapeString(list[k].Body))
  1713. if imgurl != "" {
  1714. list[k].BodyHtml = imgurl
  1715. }
  1716. }
  1717. //newBody, _ := GetReportContentTextSubByarticle(item.Body, item.Annotation, item.ArticleId)
  1718. list[k].Annotation = ArticleAnnotation(item)
  1719. list[k].Body = ""
  1720. list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  1721. list[k].ChartPermissionName = mapChartPerssion[v.CategoryId]
  1722. //如果是研选系列的任意取五张图片的中的一张
  1723. if v.CategoryId == "0" || v.ArticleId > utils.SummaryArticleId {
  1724. knum := v.ArticleId % 5
  1725. list[k].ImgUrlPc = researchList[knum]
  1726. } else {
  1727. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  1728. }
  1729. list[k].ArticleResponse = 4 // 默认展示核心观点
  1730. //ArticleResponse int `description:"报告类型 0:啥也不是,1研选报告,2:研选纪要,3:研选沙龙,4;核心观点"`
  1731. if list[k].ArticleId >= utils.SummaryArticleId {
  1732. list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
  1733. list[k].IsNeedJump = true
  1734. list[k].ArticleResponse = 1
  1735. //if v.IsReport == 1 {
  1736. // list[k].ArticleResponse = 1
  1737. //} else if v.ArticleTypeName == "纪要" {
  1738. // list[k].ArticleResponse = 2
  1739. //} else if v.ArticleTypeName == "观点" {
  1740. // list[k].ArticleResponse = 3
  1741. //} else if v.ArticleTypeName == "沙龙" {
  1742. // list[k].ArticleResponse = 3
  1743. //} else if v.ArticleTypeName == "路演精华" {
  1744. // list[k].ArticleResponse = 1
  1745. //}
  1746. }
  1747. list[k].Source = 1
  1748. //添加行业默认图片
  1749. if v.ImgUrlPc == "" {
  1750. if v.ChartPermissionName == utils.YI_YAO_NAME {
  1751. list[k].ImgUrlPc = utils.YI_YAO_OTHER_IMG
  1752. } else if v.ChartPermissionName == utils.XIAO_FEI_NAME {
  1753. list[k].ImgUrlPc = utils.XIAO_FEI_OTHER_IMG
  1754. } else if v.ChartPermissionName == utils.KE_JI_NAME {
  1755. list[k].ImgUrlPc = utils.KE_JI_OTHER_IMG
  1756. } else if v.ChartPermissionName == utils.ZHI_ZAO_NAME {
  1757. list[k].ImgUrlPc = utils.ZHI_ZAO_OTHER_IMG
  1758. }
  1759. }
  1760. //是不是研选报告
  1761. if v.ArticleTypeId > 0 {
  1762. list[k].IsResearch = true
  1763. }
  1764. }
  1765. articleIds := make([]int, 0)
  1766. for i := range list {
  1767. articleIds = append(articleIds, list[i].ArticleId)
  1768. }
  1769. articleMapPv := GetArticleHistoryByArticleId(articleIds) //文章Pv
  1770. // 报告关联产业信息
  1771. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  1772. if len(articleIds) > 0 {
  1773. var industryCond string
  1774. var industryPars []interface{}
  1775. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1776. industryPars = append(industryPars, articleIds)
  1777. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  1778. if e != nil {
  1779. err = errors.New("GetIndustrialListByarticleId" + e.Error())
  1780. return
  1781. }
  1782. for i := range industryList {
  1783. v := industryList[i]
  1784. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  1785. ArticleId: v.ArticleId,
  1786. IndustrialManagementId: v.IndustrialManagementId,
  1787. IndustryName: v.IndustryName,
  1788. ChartPermissionId: v.ChartPermissionId,
  1789. })
  1790. }
  1791. }
  1792. for k, v := range list {
  1793. if len(industryMap[v.ArticleId]) > 0 {
  1794. list[k].List = industryMap[v.ArticleId]
  1795. } else {
  1796. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  1797. }
  1798. v.Pv = articleMapPv[v.ArticleId]
  1799. if v.Pv > 999 {
  1800. list[k].Pv = 999
  1801. }
  1802. }
  1803. if len(list) == 0 {
  1804. list = make([]*models.HomeArticle, 0)
  1805. }
  1806. items = list
  1807. return
  1808. }
  1809. // 处理核心观点的展示规则
  1810. func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
  1811. if item.ArticleId >= utils.SummaryArticleId {
  1812. item.Annotation = YxArticleAnnotation(item)
  1813. }
  1814. if item.Annotation != "" {
  1815. annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  1816. annotation = strings.Replace(item.Annotation, "&nbsp;", "", -1)
  1817. } else {
  1818. return
  1819. }
  1820. bodyText, _ := GetReportContentTextSubNew(annotation)
  1821. if bodyText == "" {
  1822. return
  1823. }
  1824. if annotation != "" {
  1825. annotation = html.UnescapeString(annotation)
  1826. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1827. docText := doc.Text()
  1828. mapDoc := make(map[int]string)
  1829. var mapSort []int
  1830. p := doc.Find("p")
  1831. p.Each(func(tk int, pd *goquery.Selection) {
  1832. pdText := pd.Text()
  1833. pdText = strings.Replace(pdText, " ", "", -1)
  1834. if pdText != "" {
  1835. textLen := strings.Index(docText, pdText)
  1836. mapDoc[(strings.Index(docText, pdText))] = pdText
  1837. mapSort = append(mapSort, textLen)
  1838. }
  1839. })
  1840. li := doc.Find("li")
  1841. li.Each(func(tk int, li *goquery.Selection) {
  1842. liText := li.Text()
  1843. liText = strings.Replace(liText, " ", "", -1)
  1844. if liText != "" {
  1845. textLen := strings.Index(docText, liText)
  1846. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1847. mapSort = append(mapSort, textLen)
  1848. }
  1849. })
  1850. ul := doc.Find("ul")
  1851. ul.Each(func(tk int, ul *goquery.Selection) {
  1852. ulText := ul.Text()
  1853. ulText = strings.Replace(ulText, " ", "", -1)
  1854. if ulText != "" {
  1855. textLen := strings.Index(docText, ulText)
  1856. mapDoc[(strings.Index(docText, ulText))] = ulText
  1857. mapSort = append(mapSort, textLen)
  1858. }
  1859. })
  1860. if len(mapSort) == 0 {
  1861. return
  1862. } else {
  1863. //排序
  1864. sort.Ints(mapSort)
  1865. var annotationHtml string
  1866. for _, vSort := range mapSort {
  1867. for k, v := range mapDoc {
  1868. if k == vSort && v != "" {
  1869. annotationHtml += v + "<br>"
  1870. }
  1871. }
  1872. }
  1873. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1874. annotationHtml = "<p>" + annotationHtml + "</p>"
  1875. annotation = annotationHtml
  1876. }
  1877. }
  1878. return
  1879. }
  1880. //func init() {
  1881. // strss := AnnotationHtml("")
  1882. //
  1883. // fmt.Println(strss)
  1884. //}
  1885. // 处理核心观点的展示规则
  1886. func AnnotationHtml(bodyText string) (annotation string) {
  1887. if bodyText == "" {
  1888. return
  1889. }
  1890. annotation = bodyText
  1891. annotation = html.UnescapeString(annotation)
  1892. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  1893. docText := doc.Text()
  1894. mapDoc := make(map[int]string)
  1895. var mapSort []int
  1896. p := doc.Find("p")
  1897. p.Each(func(tk int, pd *goquery.Selection) {
  1898. pdText := pd.Text()
  1899. //pdText = strings.Replace(pdText, " ", "", -1)
  1900. if pdText != "" {
  1901. textLen := strings.Index(docText, pdText)
  1902. mapDoc[(strings.Index(docText, pdText))] = pdText
  1903. mapSort = append(mapSort, textLen)
  1904. }
  1905. })
  1906. li := doc.Find("li")
  1907. li.Each(func(tk int, li *goquery.Selection) {
  1908. liText := li.Text()
  1909. liText = strings.Replace(liText, " ", "", -1)
  1910. if liText != "" {
  1911. textLen := strings.Index(docText, liText)
  1912. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  1913. mapSort = append(mapSort, textLen)
  1914. }
  1915. })
  1916. ul := doc.Find("ul")
  1917. ul.Each(func(tk int, ul *goquery.Selection) {
  1918. ulText := ul.Text()
  1919. ulText = strings.Replace(ulText, " ", "", -1)
  1920. if ulText != "" {
  1921. textLen := strings.Index(docText, ulText)
  1922. mapDoc[(strings.Index(docText, ulText))] = ulText
  1923. mapSort = append(mapSort, textLen)
  1924. }
  1925. })
  1926. section := doc.Find("section")
  1927. section.Each(func(tk int, section *goquery.Selection) {
  1928. sectionText := section.Text()
  1929. sectionText = strings.Replace(sectionText, " ", "", -1)
  1930. if sectionText != "" {
  1931. textLen := strings.Index(docText, sectionText)
  1932. mapDoc[(strings.Index(docText, sectionText))] = sectionText
  1933. mapSort = append(mapSort, textLen)
  1934. }
  1935. })
  1936. if len(mapSort) == 0 {
  1937. return
  1938. } else {
  1939. //排序
  1940. sort.Ints(mapSort)
  1941. var annotationHtml string
  1942. for _, vSort := range mapSort {
  1943. for k, v := range mapDoc {
  1944. if k == vSort && v != "" {
  1945. annotationHtml += v + "<br>"
  1946. }
  1947. }
  1948. }
  1949. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  1950. annotationHtml = "<p>" + annotationHtml + "</p>"
  1951. annotation = annotationHtml
  1952. }
  1953. return
  1954. }
  1955. // 处理产品内测展示规则
  1956. func ProductInteriorHtml(bodyText string) (annotation string) {
  1957. if bodyText == "" {
  1958. return
  1959. }
  1960. sliceBody := strings.Split(bodyText, "</p>")
  1961. annotation, _ = GetReportContentTextSub(sliceBody[0])
  1962. return
  1963. }
  1964. // 解析研选内容中的核心观点
  1965. func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
  1966. //如果不规范,就获取内容主体
  1967. if strings.Count(article.Body, "<hr") == 0 {
  1968. //如果内容不规范而且,还有图片,就把核心观点置空
  1969. if article.BodyHtml != "" {
  1970. return
  1971. }
  1972. annotation, _ = GetReportContentTextSub(article.Body)
  1973. return
  1974. }
  1975. body := strings.ReplaceAll(article.Body, "<strong>", "")
  1976. body = strings.ReplaceAll(body, "</strong>", "")
  1977. body = strings.ReplaceAll(body, "</ol>", "</div>")
  1978. body = strings.ReplaceAll(body, "<ol>", "<div>")
  1979. body = strings.ReplaceAll(body, "</li>", "</p>")
  1980. body = strings.ReplaceAll(body, "<li>", "<p>")
  1981. re, _ := regexp.Compile("<strong.*?>")
  1982. body = re.ReplaceAllString(body, "")
  1983. reLi, _ := regexp.Compile("<li.*?>")
  1984. body = reLi.ReplaceAllString(body, "")
  1985. var plus int
  1986. coreIndex := strings.Index(body, "核心观点:")
  1987. plus = 15
  1988. if coreIndex == -1 {
  1989. coreIndex = strings.Index(body, "核心观点:")
  1990. plus = 13
  1991. }
  1992. if coreIndex == -1 {
  1993. coreIndex = strings.Index(body, "核心观点")
  1994. plus = 12
  1995. }
  1996. if coreIndex == -1 {
  1997. coreIndex = strings.Index(body, "核心结论:")
  1998. plus = 15
  1999. }
  2000. if coreIndex == -1 {
  2001. coreIndex = strings.Index(body, "核心结论:")
  2002. plus = 13
  2003. }
  2004. if coreIndex == -1 {
  2005. coreIndex = strings.Index(body, "核心结论")
  2006. plus = 12
  2007. }
  2008. endIndex := strings.Index(body, "<hr")
  2009. if coreIndex != -1 && endIndex != -1 {
  2010. body = body[coreIndex+plus : endIndex]
  2011. }
  2012. annotation = body
  2013. return
  2014. }
  2015. // 通过接解析带有Md5的文章链接获取文章ID
  2016. func GetReportLinkToArticleid(reportLink string) (articleId int, err error) {
  2017. defer func() {
  2018. if err != nil {
  2019. go utils.SendAlarmMsg("通过接解析带有Md5的文章链接获取文章ID失败"+err.Error(), 2)
  2020. }
  2021. }()
  2022. var artMd5 string
  2023. //处理Md5的
  2024. strnum1 := strings.Index(reportLink, "id=")
  2025. if strnum1 > 0 {
  2026. sliceId := strings.Split(reportLink, "id=")
  2027. if len(sliceId) > 1 {
  2028. reportLink = sliceId[1]
  2029. sliceMd5Id := strings.Split(reportLink, "&")
  2030. artMd5 = sliceMd5Id[0]
  2031. }
  2032. if artMd5 != "" {
  2033. detail, errArt := models.GetArticleDetailByIdMd5(artMd5)
  2034. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  2035. err = errArt
  2036. return
  2037. }
  2038. if detail != nil {
  2039. articleId = detail.ArticleId
  2040. }
  2041. }
  2042. } else {
  2043. //处理活动的
  2044. linkList := strings.Split(reportLink, "/")
  2045. if linkList[len(linkList)-1] != "" {
  2046. linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
  2047. if linkArticleId > 0 {
  2048. articleInfo, errArt := models.GetArticleDetailById(linkArticleId)
  2049. if errArt != nil && errArt.Error() != utils.ErrNoRow() {
  2050. err = errArt
  2051. return
  2052. }
  2053. if articleInfo != nil {
  2054. articleId = articleInfo.ArticleId
  2055. }
  2056. }
  2057. }
  2058. }
  2059. return
  2060. }
  2061. // GetArticleStockMap 获取个股标签所对应的文章ID
  2062. func GetArticleStockMap() (mapResp map[string]int, err error) {
  2063. defer func() {
  2064. if err != nil {
  2065. go utils.SendAlarmMsg("获取个股标签所对应的文章ID失败"+err.Error(), 2)
  2066. }
  2067. }()
  2068. list, err := models.GetArticleStock()
  2069. if err != nil && err.Error() != utils.ErrNoRow() {
  2070. return
  2071. }
  2072. mapResp = make(map[string]int, 0)
  2073. if len(list) > 0 {
  2074. //一对一精准匹配
  2075. for _, v := range list {
  2076. sliceSubjects := strings.Split(v.Stock, "/")
  2077. if len(sliceSubjects) > 0 {
  2078. for _, vSubject := range sliceSubjects {
  2079. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  2080. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  2081. subject := sliceXiahuaxian[0]
  2082. mapResp[subject] = v.ArticleId
  2083. }
  2084. }
  2085. }
  2086. }
  2087. return
  2088. }
  2089. // GetAiQianYanArtilceList 获取AI前沿几篇文章
  2090. func GetAiQianYanArtilceList(startSize, pageSize int) (items []*models.ReportArticle, total int, err error) {
  2091. defer func() {
  2092. if err != nil {
  2093. go utils.SendAlarmMsg("获取AI前沿几篇文章失败"+err.Error(), 2)
  2094. }
  2095. }()
  2096. var condition string
  2097. var pars []interface{}
  2098. condition += ` AND title LIKE '%AI前沿%' AND publish_status = 1 ORDER BY publish_date DESC `
  2099. articleList, e := models.GetCygxCygxArticleList(condition, pars, startSize, pageSize)
  2100. if e != nil {
  2101. err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
  2102. return
  2103. }
  2104. total, e = models.GetCygxArticleCount(condition, pars)
  2105. if e != nil {
  2106. err = errors.New("GetCygxArticleCount, Err: " + e.Error())
  2107. return
  2108. }
  2109. for _, v := range articleList {
  2110. item := new(models.ReportArticle)
  2111. item.ArticleId = v.ArticleId
  2112. item.Title = v.Title
  2113. item.Abstract = v.Abstract
  2114. item.Annotation = v.Annotation
  2115. item.PublishDate = v.PublishDate
  2116. item.Resource = 1
  2117. item.CategoryId = strconv.Itoa(v.CategoryId)
  2118. item.Body = v.Body
  2119. items = append(items, item)
  2120. }
  2121. return
  2122. }
  2123. // 获取文章内部图表的第一张封面图
  2124. func GetArticleCoverByChartFirst(body string) (cover string) {
  2125. var err error
  2126. defer func() {
  2127. if err != nil {
  2128. fmt.Println(err)
  2129. go utils.SendAlarmMsg("获取文章内部图表的第一张封面图失败,Err:"+err.Error()+body, 3)
  2130. }
  2131. }()
  2132. var chartUrl string
  2133. var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
  2134. match := hrefRegexp.FindAllString(body, -1)
  2135. if match != nil {
  2136. for _, v := range match {
  2137. if strings.Contains(v, "charts/display") {
  2138. chartUrl = v
  2139. break
  2140. }
  2141. }
  2142. }
  2143. if chartUrl != "" {
  2144. urlSlice := strings.Split(chartUrl, "/")
  2145. lenurlSlice := len(urlSlice)
  2146. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  2147. if sourceId == 0 {
  2148. sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
  2149. }
  2150. if sourceId == 0 {
  2151. err = errors.New("新的图标链接无法解析" + chartUrl)
  2152. return
  2153. }
  2154. chartUrlApi := utils.ApiUrl + "charts/" + strconv.Itoa(sourceId)
  2155. authorization := utils.ApiAuthorization
  2156. body, e := PublicGetDate(chartUrlApi, authorization)
  2157. if e != nil {
  2158. err = errors.New("PublicGetDate" + err.Error())
  2159. return
  2160. }
  2161. var resultDate models.ChartResultDetailApi
  2162. e = json.Unmarshal(body, &resultDate)
  2163. if e != nil {
  2164. err = errors.New(" json.Unmarshal" + err.Error())
  2165. }
  2166. cover = resultDate.Data.Cover
  2167. }
  2168. return
  2169. }
  2170. // GetYxArticleIdMap 获取研选文章ID
  2171. func GetYxArticleIdMap(articleIds []int) (mapResp map[int]bool) {
  2172. var err error
  2173. defer func() {
  2174. if err != nil {
  2175. go utils.SendAlarmMsg("获取研选文章ID失败,GetYxArticleIdMap"+err.Error(), 2)
  2176. }
  2177. }()
  2178. var condition string
  2179. var pars []interface{}
  2180. condition = ` AND article_type_id > 0 `
  2181. if len(articleIds) > 0 {
  2182. condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  2183. pars = append(pars, articleIds)
  2184. }
  2185. articleList, e := models.GetArticleList(condition, pars)
  2186. if e != nil {
  2187. err = errors.New("GetArticleList, Err: " + e.Error())
  2188. return
  2189. }
  2190. mapResp = make(map[int]bool, 0)
  2191. for _, v := range articleList {
  2192. mapResp[v.ArticleId] = true
  2193. }
  2194. return
  2195. }
  2196. //func init() {
  2197. //
  2198. // //listarticle, err := models.GetArticleInit13_5()
  2199. // //fmt.Println(err)
  2200. // //fmt.Println("listarticle", len(listarticle))
  2201. // //
  2202. // //for _, v := range listarticle {
  2203. // // HandleArticleListByApiInit13_5(v.ArticleId)
  2204. // //}
  2205. // //HandleArticleListByApiInit13_5(10825)
  2206. //
  2207. // listarticle, err := models.GetArticleInit13_5GuSHou()
  2208. // fmt.Println(err)
  2209. // fmt.Println("listarticle", len(listarticle))
  2210. //
  2211. // for _, v := range listarticle {
  2212. // HandleArticleListByApiInit13_5GuShou(v.ArticleId)
  2213. // }
  2214. //
  2215. //}
  2216. // 处理同步过来的文章
  2217. func HandleArticleListByApiInit13_5(artcleId int) (err error) {
  2218. defer func() {
  2219. if err != nil {
  2220. go utils.SendAlarmMsg("处理同步策略平台数据失败"+"GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), 2)
  2221. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), utils.EmailSendToUsers)
  2222. }
  2223. }()
  2224. var clueApiUrl string
  2225. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
  2226. fmt.Println(clueApiUrl)
  2227. authorization := utils.ApiAuthorization
  2228. body, err := PublicGetDate(clueApiUrl, authorization)
  2229. if err != nil {
  2230. fmt.Println(err)
  2231. return
  2232. }
  2233. var articleResultDate models.ArticleDetailResultApi
  2234. err = json.Unmarshal(body, &articleResultDate)
  2235. if err != nil {
  2236. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  2237. return err
  2238. }
  2239. item := new(models.CygxShanghaiCompanyLog)
  2240. item.CreateTime = time.Now()
  2241. item.Url = clueApiUrl
  2242. item.Body = ""
  2243. item.Result = string(body)
  2244. articleResult := articleResultDate.Data
  2245. exitMap := make(map[int]int)
  2246. categoryIdMap := make(map[int]int)
  2247. classMap := make(map[int]int)
  2248. reportMap := make(map[int]int)
  2249. summaryMap := make(map[int]int)
  2250. listMap, err := models.GetArticleApiMap()
  2251. if err != nil {
  2252. fmt.Println("GetlistMap Err:", err.Error())
  2253. return err
  2254. }
  2255. //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
  2256. for _, v := range listMap {
  2257. exitMap[v.SeriesId] = v.OldId
  2258. categoryIdMap[v.SeriesId] = v.OldIdMap
  2259. if v.IsClass == 1 {
  2260. classMap[v.OldId] = 1
  2261. }
  2262. if v.IsReport == 1 {
  2263. reportMap[v.OldId] = 1
  2264. }
  2265. if v.IsSummary == 1 {
  2266. summaryMap[v.OldId] = 1
  2267. }
  2268. }
  2269. var list []*models.Tactics2
  2270. var listArticleData []*models.CygxArticleData
  2271. var listAuthor []*models.CygxArticleAuthor
  2272. //如果是英文报告 ,或者香港类型那么则不同步 publish_area :all 全部 ;hk 香港
  2273. if articleResult.TypeId == 9 || articleResult.PublishArea != "all" {
  2274. // 如果是英文报告,或者是香港报告就进行删除处理
  2275. err = models.UpdateArticlePublish(artcleId, 0)
  2276. if err != nil {
  2277. fmt.Println("UpdateArticlePublish Err:", err.Error())
  2278. return err
  2279. }
  2280. UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  2281. return
  2282. }
  2283. var cover string
  2284. if articleResult.Series.Name == "图解市场" {
  2285. cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
  2286. } else if articleResult.Series.Name == "行业深度" {
  2287. cover = articleResult.Cover
  2288. }
  2289. fmt.Println(cover)
  2290. //return
  2291. //状态等于 2 跟 4 的进行同步 IsActive 为false 软删除的也不同步
  2292. if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
  2293. 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)
  2294. item := new(models.Tactics2)
  2295. itemArticleData := new(models.CygxArticleData)
  2296. itemArticleData.ArticleId = articleResult.ArticleId
  2297. itemArticleData.Cover = articleResult.Cover
  2298. itemArticleData.CreateTime = time.Now()
  2299. listArticleData = append(listArticleData, itemArticleData)
  2300. itemAuthor := new(models.CygxArticleAuthor)
  2301. item.ArticleId = articleResult.ArticleId
  2302. item.Title = articleResult.Title
  2303. item.TitleEn = articleResult.TitleEn
  2304. item.File = articleResult.File
  2305. if articleResult.Frequency == "日度" {
  2306. item.UpdateFrequency = "daily"
  2307. } else if articleResult.Frequency == "周度" {
  2308. item.UpdateFrequency = "weekly"
  2309. } else if articleResult.Frequency == "月度" {
  2310. item.UpdateFrequency = "monthly"
  2311. } else if articleResult.Frequency == "季度" {
  2312. item.UpdateFrequency = "quarterly"
  2313. } else if articleResult.Frequency == "年度" {
  2314. item.UpdateFrequency = "yearly"
  2315. } else {
  2316. item.UpdateFrequency = "unknow"
  2317. }
  2318. item.CreateDate = articleResult.CreateDate
  2319. item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
  2320. item.PublishStatus = 1
  2321. item.Body = articleResult.Content.Body
  2322. item.Abstract = articleResult.Content.Abstract
  2323. item.Annotation = articleResult.Content.Annotation
  2324. item.CategoryName = articleResult.Industry.Name
  2325. item.CategoryId = categoryIdMap[articleResult.SeriesId]
  2326. item.CategoryIdTwo = exitMap[articleResult.SeriesId]
  2327. item.SubCategoryName = articleResult.Series.Name
  2328. item.Cover = cover
  2329. fmt.Println("item.CategoryIdTwo", item.CategoryIdTwo)
  2330. fmt.Println("item.CategoryId", item.CategoryId)
  2331. {
  2332. //这两种情况特殊处理
  2333. if articleResult.Field.Name == "宏观利率" {
  2334. item.CategoryId = 10070
  2335. item.CategoryIdTwo = item.CategoryId
  2336. }
  2337. if articleResult.Field.Name == "信用" {
  2338. item.CategoryId = 10082
  2339. item.CategoryIdTwo = item.CategoryId
  2340. }
  2341. }
  2342. if len(articleResult.Stock) > 0 {
  2343. var stock string
  2344. for _, vS := range articleResult.Stock {
  2345. stock += vS + "/"
  2346. }
  2347. stock = strings.TrimRight(stock, "/")
  2348. item.Stock = stock
  2349. }
  2350. item.FieldName = articleResult.Field.Name
  2351. item.TypeName = articleResult.Type.Name
  2352. item.UpdateDate = articleResult.UpdateDate
  2353. item.CeLueFieldId = articleResult.Field.Id
  2354. list = append(list, item)
  2355. itemAuthor.ArticleId = articleResult.ArticleId
  2356. itemAuthor.Name = articleResult.Author.Name
  2357. itemAuthor.Mobile = articleResult.Author.PhoneNumber
  2358. fmt.Println(articleResult.Cover)
  2359. listAuthor = append(listAuthor, itemAuthor)
  2360. } else {
  2361. // 如果这篇文章没有发布,那么就不作处理。
  2362. err = models.UpdateArticlePublish(artcleId, 0)
  2363. if err != nil {
  2364. fmt.Println("UpdateArticlePublish Err:", err.Error())
  2365. return err
  2366. }
  2367. UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  2368. //go UpdateResourceData(artcleId, "article", "delete", time.Now().Format(utils.FormatDateTime))
  2369. return
  2370. }
  2371. fmt.Println("同步文章条数:", len(list))
  2372. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  2373. if err != nil {
  2374. fmt.Println("GetTacticsList Err:", err.Error())
  2375. return err
  2376. }
  2377. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  2378. if errMatch != nil {
  2379. fmt.Println("GetTacticsList Err:", errMatch.Error())
  2380. return err
  2381. }
  2382. //mapCategoryIdSet := make(map[int]int)
  2383. //for _, vMatch := range listGetMatchTypeName {
  2384. // mapCategoryIdSet[vMatch.CategoryId] = vMatch.CategoryIdSet
  2385. //}
  2386. fmt.Println("list len:", len(list))
  2387. noSummaryArticleIds := "" //非纪要库类型的文章ID
  2388. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  2389. for k, v := range list {
  2390. //同步匹配类型
  2391. matchTypeName := ""
  2392. for _, vMatch := range listGetMatchTypeName {
  2393. if v.CategoryId == vMatch.CategoryId {
  2394. matchTypeName = vMatch.MatchTypeName
  2395. }
  2396. }
  2397. //是否属于纪要库的数据
  2398. //if _, has := summaryMap[v.CategoryId]; has {
  2399. // v.IsSummary = 1
  2400. //}
  2401. if v.TypeName == "纪要" {
  2402. v.IsSummary = 1
  2403. }
  2404. //排除不属于纪要库类型的文章
  2405. for _, vArt := range listNoSummaryArticleIds {
  2406. vArtInt, _ := strconv.Atoi(vArt)
  2407. if v.ArticleId == vArtInt {
  2408. v.IsSummary = 0
  2409. }
  2410. }
  2411. if _, has := reportMap[v.CategoryIdTwo]; has {
  2412. v.IsReport = 1
  2413. if _, ok := classMap[v.CategoryIdTwo]; ok {
  2414. v.IsClass = 1
  2415. v.ReportType = 1 //是否属于行业报告
  2416. } else {
  2417. v.ReportType = 2 //是否属于产业报告
  2418. }
  2419. }
  2420. v.Department = "弘则权益研究"
  2421. //判断是否已经存在
  2422. if v.ArticleId < 0 {
  2423. fmt.Println("AddCygxArticle Err:")
  2424. return err
  2425. }
  2426. var count int
  2427. count, err = models.GetArticleCountById(v.ArticleId)
  2428. if err != nil && err.Error() != utils.ErrNoRow() {
  2429. fmt.Println("AddCygxArticle Err:", err.Error())
  2430. return err
  2431. }
  2432. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  2433. expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
  2434. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  2435. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  2436. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  2437. v.Body = strings.Replace(v.Body, "):", "", -1)
  2438. }
  2439. var titleNew string
  2440. titleNew = v.Title
  2441. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  2442. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  2443. if v.UpdateFrequency == "daily" {
  2444. var daystr string
  2445. daystr = strconv.Itoa(v.PublishDate.Day())
  2446. if len(daystr) == 1 {
  2447. daystr = "0" + daystr
  2448. }
  2449. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  2450. } else if v.UpdateFrequency == "weekly" {
  2451. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  2452. }
  2453. }
  2454. if v.CategoryId == 80 {
  2455. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  2456. }
  2457. //类型是综述报告的,不区分是什么系列,统一归类到对应产业的路演精华
  2458. if articleResult.Type.Name == "综述报告" {
  2459. detailCategory, err := models.GetdetailByCategoryIdLyjh(v.CategoryIdTwo)
  2460. if err != nil && err.Error() != utils.ErrNoRow() {
  2461. return err
  2462. }
  2463. v.CategoryId = detailCategory.CategoryId
  2464. v.IsSummary = 0
  2465. }
  2466. if count > 0 {
  2467. fmt.Println(k, v.ArticleId, "edit")
  2468. bodyText, _ := GetReportContentTextSubNew(v.Body)
  2469. var isCustom bool
  2470. updateParams := make(map[string]interface{})
  2471. //updateParams["Title"] = v.Title
  2472. updateParams["Title"] = titleNew
  2473. updateParams["TitleEn"] = v.TitleEn
  2474. updateParams["UpdateFrequency"] = v.UpdateFrequency
  2475. updateParams["CreateDate"] = v.CreateDate
  2476. updateParams["PublishDate"] = v.PublishDate
  2477. //updateParams["Body"] = html.EscapeString(v.Body)
  2478. updateParams["Body"] = html.EscapeString(bodyReturn)
  2479. updateParams["BodyText"] = bodyText
  2480. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  2481. updateParams["CategoryName"] = v.CategoryName
  2482. for _, vCustom := range listCustomArticle {
  2483. if v.ArticleId == vCustom.ArticleId {
  2484. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  2485. isCustom = true
  2486. }
  2487. }
  2488. if isCustom == false {
  2489. updateParams["CategoryId"] = v.CategoryId
  2490. updateParams["MatchTypeName"] = matchTypeName
  2491. updateParams["IsSummary"] = v.IsSummary
  2492. updateParams["IsReport"] = v.IsReport
  2493. updateParams["ReportType"] = v.ReportType
  2494. updateParams["SubCategoryName"] = v.SubCategoryName
  2495. }
  2496. //updateParams["CategoryId"] = v.CategoryId
  2497. updateParams["PublishStatus"] = 1
  2498. updateParams["ExpertBackground"] = expertContentStr
  2499. updateParams["ExpertNumber"] = expertNumStr
  2500. updateParams["InterviewDate"] = interviewDateStr
  2501. //updateParams["IsClass"] = v.IsClass
  2502. v.Department = "弘则权益研究"
  2503. updateParams["Department"] = v.Department
  2504. updateParams["FileLink"] = v.File
  2505. updateParams["Stock"] = v.Stock
  2506. updateParams["FieldName"] = v.FieldName
  2507. updateParams["Annotation"] = v.Annotation
  2508. updateParams["TypeName"] = v.TypeName
  2509. updateParams["ModifyTimeByCl"] = v.UpdateDate
  2510. updateParams["CeLueFieldId"] = v.CeLueFieldId
  2511. updateParams["Cover"] = v.Cover
  2512. //whereParam := map[string]interface{}{"article_id": v.ArticleId}
  2513. //err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  2514. //if err != nil {
  2515. // fmt.Println("UpdateByExpr Err:" + err.Error())
  2516. // return err
  2517. //}
  2518. fmt.Println("v.ReportType", v.ReportType)
  2519. //if v.ReportType == 2 {
  2520. var subjectStr string
  2521. var industrialManagementIdStr string
  2522. var industrialSubjectIdStr string
  2523. sliceSubjects := strings.Split(v.Stock, "/")
  2524. mapManagementForSubject := make(map[string]string)
  2525. mapIndustrialId := make(map[int]int)
  2526. if len(sliceSubjects) > 0 {
  2527. for _, vSubject := range sliceSubjects {
  2528. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  2529. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  2530. subject := sliceXiahuaxian[0]
  2531. subjectStr += "'" + subject + "',"
  2532. }
  2533. //获取该产业下所对应的行业图片
  2534. detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
  2535. if errCategory != nil {
  2536. fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
  2537. return err
  2538. }
  2539. subjectStr = strings.TrimRight(subjectStr, ",")
  2540. if subjectStr != "" {
  2541. listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
  2542. if err != nil {
  2543. fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
  2544. return err
  2545. }
  2546. subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
  2547. subjectStr = strings.Replace(subjectStr, "'", "", -1)
  2548. subjectStr = "【" + subjectStr + "】"
  2549. if len(listIndustrial) > 0 {
  2550. for _, vIndustrial := range listIndustrial {
  2551. if _, ok := mapIndustrialId[vIndustrial.IndustrialManagementId]; !ok {
  2552. industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
  2553. }
  2554. mapIndustrialId[vIndustrial.IndustrialManagementId] = vIndustrial.IndustrialManagementId
  2555. industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
  2556. mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
  2557. if vIndustrial.LayoutTime == "0000-00-00 00:00:00" {
  2558. go models.UpdateIndustrialManagementLayoutTime(v.PublishDate.AddDate(0, 0, -10).Format(utils.FormatDateTime), vIndustrial.IndustrialManagementId)
  2559. }
  2560. }
  2561. industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
  2562. industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
  2563. if industrialManagementIdStr != "" {
  2564. err = models.ReportArticleClassificationEditNew(artcleId, industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
  2565. if err != nil {
  2566. fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
  2567. return err
  2568. }
  2569. }
  2570. }
  2571. //}
  2572. }
  2573. }
  2574. }
  2575. }
  2576. AddComprehensiveIndustrialSource("Hz", artcleId) // 同步到综合页面的搜索引擎(添加产业资源包)
  2577. AddCygxReportMappingCategoryGroupByArticleId(artcleId)
  2578. return err
  2579. }
  2580. func HandleArticleListByApiInit13_5GuShou(artcleId int) (err error) {
  2581. defer func() {
  2582. if err != nil {
  2583. go utils.SendAlarmMsg("处理同步策略平台数据失败"+"GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), 2)
  2584. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), utils.EmailSendToUsers)
  2585. }
  2586. }()
  2587. var clueApiUrl string
  2588. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
  2589. fmt.Println(clueApiUrl)
  2590. authorization := utils.ApiAuthorization
  2591. body, err := PublicGetDate(clueApiUrl, authorization)
  2592. if err != nil {
  2593. fmt.Println(err)
  2594. return
  2595. }
  2596. var articleResultDate models.ArticleDetailResultApi
  2597. err = json.Unmarshal(body, &articleResultDate)
  2598. if err != nil {
  2599. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  2600. return err
  2601. }
  2602. item := new(models.CygxShanghaiCompanyLog)
  2603. item.CreateTime = time.Now()
  2604. item.Url = clueApiUrl
  2605. item.Body = ""
  2606. item.Result = string(body)
  2607. articleResult := articleResultDate.Data
  2608. exitMap := make(map[int]int)
  2609. categoryIdMap := make(map[int]int)
  2610. classMap := make(map[int]int)
  2611. reportMap := make(map[int]int)
  2612. summaryMap := make(map[int]int)
  2613. listMap, err := models.GetArticleApiMap()
  2614. if err != nil {
  2615. fmt.Println("GetlistMap Err:", err.Error())
  2616. return err
  2617. }
  2618. //新旧分类 反向隐射,是否归类,是否是报告,是否是纪要库
  2619. for _, v := range listMap {
  2620. exitMap[v.SeriesId] = v.OldId
  2621. categoryIdMap[v.SeriesId] = v.OldIdMap
  2622. if v.IsClass == 1 {
  2623. classMap[v.OldId] = 1
  2624. }
  2625. if v.IsReport == 1 {
  2626. reportMap[v.OldId] = 1
  2627. }
  2628. if v.IsSummary == 1 {
  2629. summaryMap[v.OldId] = 1
  2630. }
  2631. }
  2632. var list []*models.Tactics2
  2633. var listArticleData []*models.CygxArticleData
  2634. var listAuthor []*models.CygxArticleAuthor
  2635. //如果是英文报告 ,或者香港类型那么则不同步 publish_area :all 全部 ;hk 香港
  2636. if articleResult.TypeId == 9 || articleResult.PublishArea != "all" {
  2637. // 如果是英文报告,或者是香港报告就进行删除处理
  2638. err = models.UpdateArticlePublish(artcleId, 0)
  2639. if err != nil {
  2640. fmt.Println("UpdateArticlePublish Err:", err.Error())
  2641. return err
  2642. }
  2643. UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  2644. return
  2645. }
  2646. var cover string
  2647. if articleResult.Series.Name == "图解市场" {
  2648. cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
  2649. } else if articleResult.Series.Name == "行业深度" {
  2650. cover = articleResult.Cover
  2651. }
  2652. fmt.Println(cover)
  2653. //return
  2654. //状态等于 2 跟 4 的进行同步 IsActive 为false 软删除的也不同步
  2655. if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
  2656. 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)
  2657. item := new(models.Tactics2)
  2658. itemArticleData := new(models.CygxArticleData)
  2659. itemArticleData.ArticleId = articleResult.ArticleId
  2660. itemArticleData.Cover = articleResult.Cover
  2661. itemArticleData.CreateTime = time.Now()
  2662. listArticleData = append(listArticleData, itemArticleData)
  2663. itemAuthor := new(models.CygxArticleAuthor)
  2664. item.ArticleId = articleResult.ArticleId
  2665. item.Title = articleResult.Title
  2666. item.TitleEn = articleResult.TitleEn
  2667. item.File = articleResult.File
  2668. if articleResult.Frequency == "日度" {
  2669. item.UpdateFrequency = "daily"
  2670. } else if articleResult.Frequency == "周度" {
  2671. item.UpdateFrequency = "weekly"
  2672. } else if articleResult.Frequency == "月度" {
  2673. item.UpdateFrequency = "monthly"
  2674. } else if articleResult.Frequency == "季度" {
  2675. item.UpdateFrequency = "quarterly"
  2676. } else if articleResult.Frequency == "年度" {
  2677. item.UpdateFrequency = "yearly"
  2678. } else {
  2679. item.UpdateFrequency = "unknow"
  2680. }
  2681. item.CreateDate = articleResult.CreateDate
  2682. item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
  2683. item.PublishStatus = 1
  2684. item.Body = articleResult.Content.Body
  2685. item.Abstract = articleResult.Content.Abstract
  2686. item.Annotation = articleResult.Content.Annotation
  2687. item.CategoryName = articleResult.Industry.Name
  2688. item.CategoryId = categoryIdMap[articleResult.SeriesId]
  2689. item.CategoryIdTwo = exitMap[articleResult.SeriesId]
  2690. item.SubCategoryName = articleResult.Series.Name
  2691. item.Cover = cover
  2692. fmt.Println("item.CategoryIdTwo", item.CategoryIdTwo)
  2693. fmt.Println("item.CategoryId", item.CategoryId)
  2694. {
  2695. //这两种情况特殊处理
  2696. if articleResult.Field.Name == "宏观利率" {
  2697. item.CategoryId = 10070
  2698. item.CategoryIdTwo = item.CategoryId
  2699. }
  2700. if articleResult.Field.Name == "信用" {
  2701. item.CategoryId = 10082
  2702. item.CategoryIdTwo = item.CategoryId
  2703. }
  2704. }
  2705. if len(articleResult.Stock) > 0 {
  2706. var stock string
  2707. for _, vS := range articleResult.Stock {
  2708. stock += vS + "/"
  2709. }
  2710. stock = strings.TrimRight(stock, "/")
  2711. item.Stock = stock
  2712. }
  2713. item.FieldName = articleResult.Field.Name
  2714. item.TypeName = articleResult.Type.Name
  2715. item.UpdateDate = articleResult.UpdateDate
  2716. item.CeLueFieldId = articleResult.Field.Id
  2717. list = append(list, item)
  2718. itemAuthor.ArticleId = articleResult.ArticleId
  2719. itemAuthor.Name = articleResult.Author.Name
  2720. itemAuthor.Mobile = articleResult.Author.PhoneNumber
  2721. fmt.Println(articleResult.Cover)
  2722. listAuthor = append(listAuthor, itemAuthor)
  2723. } else {
  2724. // 如果这篇文章没有发布,那么就不作处理。
  2725. //err = models.UpdateArticlePublish(artcleId, 0)
  2726. //if err != nil {
  2727. // fmt.Println("UpdateArticlePublish Err:", err.Error())
  2728. // return err
  2729. //}
  2730. //UpdateArticleResourceData(artcleId) //把数据写入 cygx_resource_data 表
  2731. //go UpdateResourceData(artcleId, "article", "delete", time.Now().Format(utils.FormatDateTime))
  2732. return
  2733. }
  2734. fmt.Println("同步文章条数:", len(list))
  2735. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  2736. if err != nil {
  2737. fmt.Println("GetTacticsList Err:", err.Error())
  2738. return err
  2739. }
  2740. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  2741. if errMatch != nil {
  2742. fmt.Println("GetTacticsList Err:", errMatch.Error())
  2743. return err
  2744. }
  2745. //mapCategoryIdSet := make(map[int]int)
  2746. //for _, vMatch := range listGetMatchTypeName {
  2747. // mapCategoryIdSet[vMatch.CategoryId] = vMatch.CategoryIdSet
  2748. //}
  2749. fmt.Println("list len:", len(list))
  2750. noSummaryArticleIds := "" //非纪要库类型的文章ID
  2751. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  2752. for k, v := range list {
  2753. //同步匹配类型
  2754. matchTypeName := ""
  2755. for _, vMatch := range listGetMatchTypeName {
  2756. if v.CategoryId == vMatch.CategoryId {
  2757. matchTypeName = vMatch.MatchTypeName
  2758. }
  2759. }
  2760. //是否属于纪要库的数据
  2761. //if _, has := summaryMap[v.CategoryId]; has {
  2762. // v.IsSummary = 1
  2763. //}
  2764. if v.TypeName == "纪要" {
  2765. v.IsSummary = 1
  2766. }
  2767. //排除不属于纪要库类型的文章
  2768. for _, vArt := range listNoSummaryArticleIds {
  2769. vArtInt, _ := strconv.Atoi(vArt)
  2770. if v.ArticleId == vArtInt {
  2771. v.IsSummary = 0
  2772. }
  2773. }
  2774. if _, has := reportMap[v.CategoryIdTwo]; has {
  2775. v.IsReport = 1
  2776. if _, ok := classMap[v.CategoryIdTwo]; ok {
  2777. v.IsClass = 1
  2778. v.ReportType = 1 //是否属于行业报告
  2779. } else {
  2780. v.ReportType = 2 //是否属于产业报告
  2781. }
  2782. }
  2783. v.Department = "弘则权益研究"
  2784. //判断是否已经存在
  2785. if v.ArticleId < 0 {
  2786. fmt.Println("AddCygxArticle Err:")
  2787. return err
  2788. }
  2789. var count int
  2790. count, err = models.GetArticleCountById(v.ArticleId)
  2791. if err != nil && err.Error() != utils.ErrNoRow() {
  2792. fmt.Println("AddCygxArticle Err:", err.Error())
  2793. return err
  2794. }
  2795. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  2796. expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
  2797. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  2798. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  2799. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  2800. v.Body = strings.Replace(v.Body, "):", "", -1)
  2801. }
  2802. var titleNew string
  2803. titleNew = v.Title
  2804. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  2805. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  2806. if v.UpdateFrequency == "daily" {
  2807. var daystr string
  2808. daystr = strconv.Itoa(v.PublishDate.Day())
  2809. if len(daystr) == 1 {
  2810. daystr = "0" + daystr
  2811. }
  2812. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  2813. } else if v.UpdateFrequency == "weekly" {
  2814. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  2815. }
  2816. }
  2817. if v.CategoryId == 80 {
  2818. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  2819. }
  2820. //类型是综述报告的,不区分是什么系列,统一归类到对应产业的路演精华
  2821. if articleResult.Type.Name == "综述报告" {
  2822. detailCategory, err := models.GetdetailByCategoryIdLyjh(v.CategoryIdTwo)
  2823. if err != nil && err.Error() != utils.ErrNoRow() {
  2824. return err
  2825. }
  2826. v.CategoryId = detailCategory.CategoryId
  2827. v.IsSummary = 0
  2828. }
  2829. if count > 0 {
  2830. fmt.Println(k, v.ArticleId, "edit")
  2831. bodyText, _ := GetReportContentTextSubNew(v.Body)
  2832. var isCustom bool
  2833. updateParams := make(map[string]interface{})
  2834. //updateParams["Title"] = v.Title
  2835. updateParams["Title"] = titleNew
  2836. updateParams["TitleEn"] = v.TitleEn
  2837. updateParams["UpdateFrequency"] = v.UpdateFrequency
  2838. updateParams["CreateDate"] = v.CreateDate
  2839. updateParams["PublishDate"] = v.PublishDate
  2840. //updateParams["Body"] = html.EscapeString(v.Body)
  2841. updateParams["Body"] = html.EscapeString(bodyReturn)
  2842. updateParams["BodyText"] = bodyText
  2843. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  2844. updateParams["CategoryName"] = v.CategoryName
  2845. for _, vCustom := range listCustomArticle {
  2846. if v.ArticleId == vCustom.ArticleId {
  2847. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  2848. isCustom = true
  2849. }
  2850. }
  2851. if isCustom == false {
  2852. updateParams["CategoryId"] = v.CategoryId
  2853. updateParams["MatchTypeName"] = matchTypeName
  2854. updateParams["IsSummary"] = v.IsSummary
  2855. updateParams["IsReport"] = v.IsReport
  2856. updateParams["ReportType"] = v.ReportType
  2857. updateParams["SubCategoryName"] = v.SubCategoryName
  2858. }
  2859. //updateParams["CategoryId"] = v.CategoryId
  2860. updateParams["PublishStatus"] = 1
  2861. updateParams["ExpertBackground"] = expertContentStr
  2862. updateParams["ExpertNumber"] = expertNumStr
  2863. updateParams["InterviewDate"] = interviewDateStr
  2864. //updateParams["IsClass"] = v.IsClass
  2865. v.Department = "弘则权益研究"
  2866. updateParams["Department"] = v.Department
  2867. updateParams["FileLink"] = v.File
  2868. updateParams["Stock"] = v.Stock
  2869. updateParams["FieldName"] = v.FieldName
  2870. updateParams["Annotation"] = v.Annotation
  2871. updateParams["TypeName"] = v.TypeName
  2872. updateParams["ModifyTimeByCl"] = v.UpdateDate
  2873. updateParams["CeLueFieldId"] = v.CeLueFieldId
  2874. updateParams["Cover"] = v.Cover
  2875. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  2876. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  2877. if err != nil {
  2878. fmt.Println("UpdateByExpr Err:" + err.Error())
  2879. return err
  2880. }
  2881. fmt.Println("v.ReportType", v.ReportType)
  2882. if v.ReportType == 2 {
  2883. var subjectStr string
  2884. var industrialManagementIdStr string
  2885. var industrialSubjectIdStr string
  2886. sliceSubjects := strings.Split(v.Stock, "/")
  2887. mapManagementForSubject := make(map[string]string)
  2888. mapIndustrialId := make(map[int]int)
  2889. if len(sliceSubjects) > 0 {
  2890. for _, vSubject := range sliceSubjects {
  2891. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  2892. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  2893. subject := sliceXiahuaxian[0]
  2894. subjectStr += "'" + subject + "',"
  2895. }
  2896. //获取该产业下所对应的行业图片
  2897. detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
  2898. if errCategory != nil {
  2899. fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
  2900. return err
  2901. }
  2902. subjectStr = strings.TrimRight(subjectStr, ",")
  2903. if subjectStr != "" {
  2904. listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
  2905. if err != nil {
  2906. fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
  2907. return err
  2908. }
  2909. subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
  2910. subjectStr = strings.Replace(subjectStr, "'", "", -1)
  2911. subjectStr = "【" + subjectStr + "】"
  2912. if len(listIndustrial) > 0 {
  2913. for _, vIndustrial := range listIndustrial {
  2914. if _, ok := mapIndustrialId[vIndustrial.IndustrialManagementId]; !ok {
  2915. industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
  2916. }
  2917. mapIndustrialId[vIndustrial.IndustrialManagementId] = vIndustrial.IndustrialManagementId
  2918. industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
  2919. mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
  2920. if vIndustrial.LayoutTime == "0000-00-00 00:00:00" {
  2921. go models.UpdateIndustrialManagementLayoutTime(v.PublishDate.AddDate(0, 0, -10).Format(utils.FormatDateTime), vIndustrial.IndustrialManagementId)
  2922. }
  2923. }
  2924. industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
  2925. industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
  2926. if industrialManagementIdStr != "" {
  2927. err = models.ReportArticleClassificationEditNew(artcleId, industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
  2928. if err != nil {
  2929. fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
  2930. return err
  2931. }
  2932. }
  2933. }
  2934. //}
  2935. }
  2936. }
  2937. }
  2938. }
  2939. }
  2940. AddComprehensiveIndustrialSource("Hz", artcleId) // 同步到综合页面的搜索引擎(添加产业资源包)
  2941. AddCygxReportMappingCategoryGroupByArticleId(artcleId)
  2942. return err
  2943. }
  2944. // 需求池972 修改部分报告类型title
  2945. func initweek() {
  2946. var category_id int
  2947. //category_id = 52
  2948. //category_id = 10074
  2949. //category_id = 1008
  2950. //category_id = 10071
  2951. //category_id = 10073
  2952. //category_id = 50
  2953. var condition string
  2954. var pars []interface{}
  2955. condition += ` AND category_id = ? AND publish_date > '2023-12-31' `
  2956. pars = append(pars, category_id)
  2957. articleList, e := models.GetCygxCygxArticleList(condition, pars, 0, 1000)
  2958. if e != nil {
  2959. fmt.Println(e)
  2960. return
  2961. }
  2962. var clueApiUrl string
  2963. for _, v := range articleList {
  2964. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", v.ArticleId)
  2965. fmt.Println(clueApiUrl)
  2966. authorization := utils.ApiAuthorization
  2967. body, err := PublicGetDate(clueApiUrl, authorization)
  2968. if err != nil {
  2969. fmt.Println(err)
  2970. return
  2971. }
  2972. var articleResultDate models.ArticleDetailResultApi
  2973. err = json.Unmarshal(body, &articleResultDate)
  2974. if err != nil {
  2975. fmt.Println(err)
  2976. return
  2977. }
  2978. articleResult := articleResultDate.Data
  2979. titleWeek := articleResult.Title + utils.WeekByDate(articleResult.PublishDate)
  2980. fmt.Println(titleWeek)
  2981. e = models.ModifyArticleTitleByarticleId(v.ArticleId, titleWeek)
  2982. if e != nil {
  2983. fmt.Println(e)
  2984. return
  2985. }
  2986. }
  2987. }