article.go 110 KB

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