12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083 |
- package services
- import (
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/PuerkitoBio/goquery"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- "html"
- "net/url"
- "regexp"
- "sort"
- "strconv"
- "strings"
- "time"
- "unicode/utf8"
- )
- func GetReportContentSub(content string) (contentSub string, err error) {
- content = html.UnescapeString(content)
- doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
- if err != nil {
- fmt.Println("create doc err:", err.Error())
- return
- }
- n := 0
- doc.Find("p").Each(func(i int, s *goquery.Selection) {
- if n > 3 {
- return
- }
- n++
- phtml, err := s.Html()
- if err != nil {
- fmt.Println("get html err", err.Error())
- return
- }
- if s.Text() != "" || strings.Contains(phtml, "src") {
- contentSub = contentSub + "<p>" + phtml + "</p>"
- }
- })
- return
- }
- func GetReportContentTextSub(content string) (contentSub string, err error) {
- content = html.UnescapeString(content)
- doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
- docText := doc.Text()
- bodyRune := []rune(docText)
- bodyRuneLen := len(bodyRune)
- if bodyRuneLen > 200 {
- bodyRuneLen = 200
- }
- body := string(bodyRune[:bodyRuneLen])
- contentSub = body
- contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
- return
- }
- func GetReportContentTextSubNew(content string) (contentSub string, err error) {
- content = html.UnescapeString(content)
- doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(content))
- if errdoc != nil {
- err = errdoc
- return
- }
- docText := doc.Text()
- bodyRune := []rune(docText)
- bodyRuneLen := len(bodyRune)
- body := string(bodyRune[:bodyRuneLen])
- contentSub = body
- contentSub = strings.Replace(contentSub, "Powered by Froala Editor", "", -1)
- contentSub = strings.Replace(contentSub, " ", "", -1)
- 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)
- return
- }
- func GetReportContentTextSubByarticle(content, abstract string, articleId int) (contentSub string, err error) {
- var lenabstract int
-
- if articleId < utils.SummaryArticleId {
- abstract = html.UnescapeString(abstract)
- doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(abstract))
- if errdoc != nil {
- err = errdoc
- return
- }
- docabstract := doc.Text()
- lenabstract = utf8.RuneCountInString(docabstract)
- if lenabstract >= 20 {
- contentSub = docabstract
- return
- } else {
- contentSub, err = GetReportContentTextSubNew(content)
- }
- } else {
- contentSub, err = GetReportContentTextSubNew(content)
- }
- return
- }
- func GetArticleAll() {
- var err error
- defer func() {
- if err != nil {
- fmt.Println("err:", err.Error())
- return
- }
- }()
- list, err := models.GetArticleAll()
- if err != nil {
- return
- }
- for _, v := range list {
- fmt.Println(v.ArticleId, v.Title)
- FixArticleContent(v.ArticleId)
- }
- }
- func FixArticleContent(articleId int) {
- item, err := models.GetArticleDetailById(articleId)
- if err != nil {
- fmt.Println("GetArticleDetailById Err:" + err.Error())
- return
- }
- content := item.Body
- bodyText, _ := GetReportContentTextSub(content)
- content = html.UnescapeString(content)
- content = strings.Replace(content, "http", "https", -1)
- doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
- if err != nil {
- fmt.Println("create doc err:", err.Error())
- return
- }
- var expertNumArr []string
- var expertContentArr []string
- var interviewDateArr []string
- doc.Find("p").Each(func(i int, s *goquery.Selection) {
- contentTxt := s.Text()
- if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
- interviewDate := s.Next().Text()
- interviewDateArr = append(interviewDateArr, interviewDate)
- }
- if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
- expertContent := s.Next().Text()
- if expertContent == "" {
- expertContent = contentTxt
- }
- if expertContent != "" {
- rightIndex := strings.Index(expertContent, ")")
- if rightIndex == 0 {
- rightIndex = strings.Index(expertContent, ")")
- }
- if rightIndex > 0 {
- expertNum := expertContent[:rightIndex]
- expertNum = strings.Replace(expertNum, "(", "", -1)
- expertNum = strings.Replace(expertNum, "(", "", -1)
- expertNum = strings.Replace(expertNum, "专家评价", "", -1)
- if expertNum != "" {
- expertNumArr = append(expertNumArr, expertNum)
- rightIndex = rightIndex
- expertContentStr := expertContent[rightIndex:]
- expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
- expertContentStr = strings.TrimLeft(expertContentStr, ":")
- expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
- expertContentArr = append(expertContentArr, expertContentStr)
- }
- }
- }
- }
- })
- if len(expertContentArr) <= 0 {
- doc.Find("pre").Each(func(i int, pre *goquery.Selection) {
- pre.Find("span").Each(func(n int, span *goquery.Selection) {
- contentTxt := span.Text()
- if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
- span.Find("span").Each(func(m int, subspan *goquery.Selection) {
- subspanText := subspan.Text()
- if strings.Contains(subspanText, "专家评价") {
- expertContent := subspan.Next().Text()
- if expertContent != "" {
- rightIndex := strings.Index(expertContent, ")")
- if rightIndex == 0 {
- rightIndex = strings.Index(expertContent, ")")
- }
- if rightIndex > 0 {
- expertNum := expertContent[:rightIndex]
- expertNum = strings.Replace(expertNum, "(", "", -1)
- expertNum = strings.Replace(expertNum, "(", "", -1)
- expertNum = strings.Replace(expertNum, "专家评价", "", -1)
- if expertNum != "" {
- expertNumArr = append(expertNumArr, expertNum)
- rightIndex = rightIndex
- expertContentStr := expertContent[rightIndex:]
- expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
- expertContentStr = strings.TrimLeft(expertContentStr, ":")
- expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
- expertContentArr = append(expertContentArr, expertContentStr)
- }
- }
- }
- }
- })
- }
- span.Find("span").Each(func(k int, sspan *goquery.Selection) {
- sspanText := sspan.Text()
- if strings.Contains(sspanText, "访谈时间") {
- sspanText = strings.Replace(sspanText, "#访谈时间:", "", -1)
- sspanText = strings.Replace(sspanText, "访谈时间:", "", -1)
- sspanText = strings.Replace(sspanText, "\n", "", -1)
- sspanText = strings.Replace(sspanText, " ", "", -1)
- sspanText = strings.Trim(sspanText, " ")
- sspanText = sspanText[:10]
- interviewDate := sspanText
- if interviewDate != "" {
- interviewDateArr = append(interviewDateArr, interviewDate)
- }
- }
- })
- })
- })
- }
- if len(expertContentArr) <= 0 {
- doc.Find("span").Each(func(i int, span *goquery.Selection) {
- span.Find("strong").Each(func(n int, strong *goquery.Selection) {
- spanText := span.Text()
- strongText := strong.Text()
- if strings.Contains(strongText, "#专家评价") || strings.Contains(strongText, "专家评价") {
- expertContent := strong.Parents().Text()
- if expertContent != "" {
- rightIndex := strings.Index(expertContent, ")")
- if rightIndex == 0 {
- rightIndex = strings.Index(expertContent, ")")
- }
- if rightIndex > 0 {
- expertNum := expertContent[:rightIndex]
- expertNum = strings.Replace(expertNum, "(", "", -1)
- expertNum = strings.Replace(expertNum, "(", "", -1)
- expertNum = strings.Replace(expertNum, "专家评价", "", -1)
- expertNum = strings.Replace(expertNum, "#", "", -1)
- expertNum = strings.Replace(expertNum, ":", "", -1)
- expertNum = strings.Replace(expertNum, "\n", "", -1)
- if expertNum != "" {
- expertNumArr = append(expertNumArr, expertNum)
- rightIndex = rightIndex
- expertContentStr := expertContent[rightIndex:]
- expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
- expertContentStr = strings.TrimLeft(expertContentStr, ":")
- expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
- expertContentArr = append(expertContentArr, expertContentStr)
- return
- }
- }
- }
- }
- if strings.Contains(spanText, "访谈时间") {
- spanText = strings.Replace(spanText, "#访谈时间:", "", -1)
- spanText = strings.Replace(spanText, "访谈时间:", "", -1)
- spanText = strings.Replace(spanText, "\n", "", -1)
- spanText = strings.Replace(spanText, " ", "", -1)
- spanText = strings.Trim(spanText, " ")
- spanText = spanText[:10]
- interviewDate := spanText
- if interviewDate != "" {
- interviewDateArr = append(interviewDateArr, interviewDate)
- }
- }
- })
- })
- }
- var expertNumStr, expertContentStr, interviewDateStr string
- if len(expertNumArr) > 0 {
- expertNumStr = expertNumArr[0]
- }
- if len(expertContentArr) > 0 {
- expertContentStr = expertContentArr[0]
- }
- if len(interviewDateArr) > 0 {
- interviewDateStr = interviewDateArr[0]
- }
- expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
- err = models.ModifyArticleExpert(articleId, expertNumStr, expertContentStr, interviewDateStr, bodyText)
- if err != nil {
- fmt.Println("ModifyArticleExpert Err:" + err.Error())
- return
- }
- }
- func FixArticleImgUrl(body string) (contentSub string, err error) {
- r := strings.NewReader(string(body))
- doc, err := goquery.NewDocumentFromReader(r)
- if err != nil {
- fmt.Println(err)
- }
- doc.Find("img").Each(func(i int, s *goquery.Selection) {
- src, _ := s.Attr("src")
- if i == 0 && src != "" {
- contentSub = src
- }
- })
- return
- }
- func FixArticleFirstCount(body string) (contentSub string, err error) {
- doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
- if err != nil {
- fmt.Println("create doc err:", err.Error())
- return
- }
- doc.Find("p").Each(func(i int, s *goquery.Selection) {
- contentTxt := s.Text()
- fmt.Println(contentTxt)
- })
- return
- }
- func SynchronizationArtclehistory() {
- fmt.Println("同步开始")
- list, err := models.GetArticleHistoryList()
- if err != nil {
- fmt.Println("获取列表失败", err)
- }
- fmt.Println(len(list))
- for _, v := range list {
-
-
-
-
-
- v.OutType = 1
-
-
-
-
-
-
-
-
-
-
-
-
- newId, err := models.AddCygxArticleViewRecordNewpv(v)
- fmt.Println("新增", newId)
- if err != nil {
- fmt.Println("新增失败", err)
- }
- }
- fmt.Println("同步结束")
- }
- func StatisticalReport() {
- var isSummaryNumAll, isClassNum, pvNumAll, uvNumAll int
- list, err := models.GetChartPermissionActivity()
- if err != nil {
- fmt.Println("获取列表失败", err)
- }
- for _, v := range list {
- var listPv []*models.ReportMappingStatistical
- if v.PermissionName == "研选" {
- listPv, err = models.GetStatisticalReportArtilceExpert()
- if err != nil {
- fmt.Println("获取Pv列表失败", err)
- }
- } else {
- listPv, err = models.GetStatisticalReportArtilce(v.ChartPermissionId)
- if err != nil {
- fmt.Println("获取Pv列表失败", err)
- }
- }
- var pvNum, uvNum, isSummaryNum int
- for _, v2 := range listPv {
- pvNum += v2.Pv
- uvNum += v2.Uv
- if v2.IsSummary == "1" {
- isSummaryNum += 1
- }
- if v2.IsClass == "1" && v.ChartPermissionId <= 22 {
- isClassNum += 1
- }
- if v2.IsSummary == "1" && v.ChartPermissionId <= 22 {
- isSummaryNumAll += 1
- }
- }
- if v.ChartPermissionId <= 22 {
- pvNumAll += pvNum
- uvNumAll += uvNum
- }
- fmt.Println(v.PermissionName+"行业", len(listPv), "篇,其中主观类报告", isSummaryNum, "篇,客观类报告", len(listPv)-isSummaryNum, "篇。共产生阅读量pv-,", pvNum, ",uv-", uvNum)
- }
- fmt.Println("目前同步四大行业的总报告(已归类)数量", isClassNum, "篇,其中主观类报告", isSummaryNumAll, "篇,客观类报告", isClassNum-isSummaryNumAll, "篇。共产生阅读量pv-", pvNumAll, ",uv-", uvNumAll)
- var totalOnline int
- var totalOffline int
- var totalPeople int
- var totalSignUpOff int
- var totalSignUpOffTime int
- var totalPeopleMeet int
- o := orm.NewOrm()
- 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();`
- err = o.Raw(sql).QueryRow(&totalOnline)
- if err != nil {
- fmt.Println("获取线上", err)
- }
- 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();`
- err = o.Raw(sql).QueryRow(&totalOffline)
- if err != nil {
- fmt.Println("获取线下", err)
- }
- sql = `SELECT COUNT( 1 ) FROM
- cygx_activity_signup as s
- INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
- WHERE
- s.do_fail_type = 0
- AND a.is_submit_meeting = 1
- AND a.activity_time <= NOW()
- AND a.publish_status = 1`
- err = o.Raw(sql).QueryRow(&totalPeople)
- if err != nil {
- fmt.Println("共累计预约外呼人数", err)
- }
- sql = `SELECT COUNT( 1 ) FROM
- cygx_activity_signup as s
- INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
- WHERE
- s.do_fail_type = 0
- AND a.is_submit_meeting = 1
- AND a.activity_time <= NOW()
- AND a.activity_type_id IN (4,5,6)
- AND a.publish_status = 1`
- err = o.Raw(sql).QueryRow(&totalSignUpOff)
- if err != nil {
- fmt.Println("共累计预约外呼人数", err)
- }
- sql = `SELECT COUNT( 1 ) FROM
- cygx_activity_signup as s
- INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
- WHERE
- s.do_fail_type = 0
- AND a.publish_status = 1
- AND a.is_submit_meeting = 1
- AND a.activity_time <= NOW()
- AND a.is_submit_meeting = 1
- AND a.activity_type_id IN (4,5,6);`
- err = o.Raw(sql).QueryRow(&totalSignUpOffTime)
- if err != nil {
- fmt.Println("线下报名参会人数", err)
- }
- sql = `SELECT COUNT( 1 ) FROM
- cygx_activity_signup as s
- INNER JOIN cygx_activity as a ON a.activity_id = s.activity_id
- WHERE
- s.do_fail_type = 0
- AND a.is_submit_meeting = 1
- AND a.activity_time <= NOW()
- AND a.publish_status = 1
- AND s.is_meeting = 1
- AND a.activity_type_id IN (4,5,6);`
- err = o.Raw(sql).QueryRow(&totalPeopleMeet)
- if err != nil {
- fmt.Println("线下参会人数", err)
- }
- fmt.Println("共上线活动", totalOnline+totalOffline, "个,其中线上", totalOnline, "个,线下", totalOffline, "个")
- fmt.Println("共累计预约外呼人数", totalPeople, "人")
- fmt.Println("报名线下参会", totalSignUpOff, "人,实际到会人数", totalPeopleMeet, "人,线下到会率约", totalPeopleMeet*100/totalSignUpOff, "%")
- num := totalPeopleMeet / totalSignUpOffTime
- fmt.Println(num)
- fmt.Println(totalOnline)
- fmt.Println(totalOffline)
- fmt.Println(totalPeople)
- fmt.Println(totalSignUpOff)
- fmt.Println(totalPeopleMeet)
- fmt.Println(totalSignUpOffTime)
- fmt.Println(totalPeopleMeet / totalSignUpOffTime)
- return
- }
- type UserViewRedisData struct {
- Mobile string `json:"mobile"`
- Email string `json:"email"`
- RealName string `json:"real_name"`
- CompanyName string `json:"company_name"`
- ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
- ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
- CompanyId int `json:"company_id" description:"客户id"`
- UserId int `json:"user_id" description:"用户id"`
- ReportId int `json:"report_id" description:"报告id"`
- StopTime int `json:"stop_time" description:"停留时间"`
- ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
- OutId int `json:"out_id" description:"记录ID"`
- }
- type ReportViewRecord struct {
- Id int `orm:"column(id);pk"`
-
-
-
-
-
-
-
-
-
-
- Mobile string `json:"mobile"`
- Email string `json:"email"`
- RealName string `json:"real_name"`
- CompanyName string `json:"company_name"`
- ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
- ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
- CompanyId int `json:"company_id" description:"客户id"`
- UserId int `json:"user_id" description:"用户id"`
- ReportId int `json:"report_id" description:"报告id"`
- StopTime int `json:"stop_time" description:"停留时间"`
- ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
- OutId int `json:"out_id" description:"章节ID"`
- }
- func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
- data := &UserViewRedisData{
- Mobile: reportViewRecord.Mobile,
- UserId: reportViewRecord.UserId,
- Email: reportViewRecord.Email,
- RealName: reportViewRecord.RealName,
- CompanyName: reportViewRecord.CompanyName,
- ViewTime: reportViewRecord.ViewTime,
- ProductId: 2,
- CompanyId: companyId,
- ReportId: reportViewRecord.ReportId,
- StopTime: reportViewRecord.StopTime,
- ReportChapterId: reportViewRecord.ReportChapterId,
- OutId: reportViewRecord.OutId,
- }
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
- if err != nil {
- fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
- }
- return true
- }
- return false
- }
- func GetCeLueArticlePv(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
- go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- startTime := time.Now().Add(-time.Minute * 12).Format("2006-01-02 15:04:05")
- endTime := time.Now().Format("2006-01-02 15:04:05")
- requestUrl := utils.ApiUrl + "backend/statistics_access?take=1000&skip=0&sort=ASC&mode=all&"
- encodeData := url.Values{}
- encodeData.Add("start_dt", startTime)
- encodeData.Add("end_dt", endTime)
- encodeStr := encodeData.Encode()
- requestUrl += encodeStr
- authorization := utils.ApiAuthorization
- body, err := PublicGetDate(requestUrl, authorization)
- if err != nil {
- return
- }
- var chartResult models.CeLueArticleResultApi
- err = json.Unmarshal(body, &chartResult)
- if err != nil {
- fmt.Println(err)
- return err
- }
- mapMobileArticleId := make(map[string]int)
-
- listPv, err := models.GetArticleHistoryRecordAllList()
- if err != nil && err.Error() != utils.ErrNoRow() {
- fmt.Println("获取当天阅读记录失败", err)
- return err
- }
- if len(listPv) > 0 {
- for _, v := range listPv {
- mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
- }
- }
- for _, v := range chartResult.Data {
-
- item := new(models.CygxCelueArticleHistoryRecord)
- item.CelueHistoryId = v.CelueHistoryId
- item.Mobile = v.Mobile
- item.ArticleId = v.ArticleId
- if v.CrmUser != nil {
- item.RealName = v.CrmUser.RealName
- }
- if v.CompanyName != nil {
- item.CompanyName = v.CompanyName.RealName
- }
- item.CreateDateApi = time.Now()
- t1, _ := time.Parse("2006-01-02T15:04:05Z", v.CreateDate)
- item.CreateTime = t1.Add(+time.Hour * 8).Format(utils.FormatDateTime)
- count, err := models.GetCeLueArticleCountById(v.CelueHistoryId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- if count == 0 {
- _, err := models.AddCeLueArticle(item, mapMobileArticleId)
- if err != nil {
- fmt.Println(err)
- return err
- }
- }
- }
-
- var condition string
- condition = ` AND create_time > ` + "'" + startTime + "'"
- listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
- if err != nil {
- fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
- }
- for _, v := range listArticlePv {
- if v.Mobile != "" {
- user, err := models.GetWxUserItemByMobile(v.Mobile)
- if err != nil && err.Error() != utils.ErrNoRow() {
- fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
- }
- if user != nil {
- err = models.UpdateCygxArticleHistoryRecordAll(user)
- if err != nil {
- fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
- }
- }
- }
- }
- return
- }
- func GetArticleListByApi(cont context.Context) (err error) {
- defer func() {
- if err != nil {
-
- go utils.SendAlarmMsg("同步策略平台数据失败", 2)
- go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- listUpdateArticle, err := models.GetArticleCeluePushList()
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
-
- if len(listUpdateArticle) == 0 {
- return err
- }
- for _, v := range listUpdateArticle {
-
- err = HandleArticleListByApi(v.ArticleId)
- if err != nil {
- utils.FileLog.Info("HandleArticleListByApi", err.Error())
- }
- }
- return
- }
- func UpdateArticleByRedis() (err error) {
- for {
- utils.Rc.Brpop(utils.CYGX_ARTICLE_UPDATE_KEY, func(b []byte) {
- var log models.CygxArticleCeluePushRedis
- if err := json.Unmarshal(b, &log); err != nil {
- fmt.Println("json unmarshal wrong!")
- go utils.SendAlarmMsg("获取策略平台推送过来的文章并更新处理Redis队列消息失败:"+err.Error()+string(b), 2)
- }
-
- err = HandleArticleListByApi(log.ArticleId)
- if err != nil {
- utils.FileLog.Info("HandleArticleListByApi", err.Error())
- }
- })
- }
- }
- func HandleArticleListByApi(artcleId int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("处理同步过来的文章失败"+"HandleArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), 2)
- }
- }()
- var clueApiUrl string
- clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
- fmt.Println(clueApiUrl)
- authorization := utils.ApiAuthorization
- body, err := PublicGetDate(clueApiUrl, authorization)
- if err != nil {
- fmt.Println(err)
- return
- }
- var articleResultDate models.ArticleDetailResultApi
- err = json.Unmarshal(body, &articleResultDate)
- if err != nil {
- fmt.Println("Getres.PublicGetDate Err:", err.Error())
- return err
- }
- item := new(models.CygxShanghaiCompanyLog)
- item.CreateTime = time.Now()
- item.Url = clueApiUrl
- item.Body = ""
- item.Result = string(body)
- go models.AddCygxShanghaiCompanyLog(item)
- go models.UpdateCygxArticleCeluePush(artcleId)
- articleResult := articleResultDate.Data
- exitMap := make(map[int]int)
- categoryIdMap := make(map[int]int)
- classMap := make(map[int]int)
- reportMap := make(map[int]int)
- summaryMap := make(map[int]int)
- listMap, err := models.GetArticleApiMap()
- if err != nil {
- fmt.Println("GetlistMap Err:", err.Error())
- return err
- }
- openIdList, err := models.GetUserRecordListByMobile(4, utils.ArticleTaskClassMobile)
- if err != nil {
- fmt.Println(err)
- return err
- }
- fmt.Println(openIdList)
-
- for _, v := range listMap {
- exitMap[v.SeriesId] = v.OldId
- categoryIdMap[v.SeriesId] = v.OldIdMap
- if v.IsClass == 1 {
- classMap[v.OldId] = 1
- }
- if v.IsReport == 1 {
- reportMap[v.OldId] = 1
- }
- if v.IsSummary == 1 {
- summaryMap[v.OldId] = 1
- }
- }
- var list []*models.Tactics2
- var listArticleData []*models.CygxArticleData
- var listAuthor []*models.CygxArticleAuthor
-
- if articleResult.TypeId == 9 || articleResult.PublishArea != "all" {
-
- err = models.UpdateArticlePublish(artcleId, 0)
- if err != nil {
- fmt.Println("UpdateArticlePublish Err:", err.Error())
- return err
- }
- UpdateArticleResourceData(artcleId)
- return
- }
- var cover string
- if articleResult.Series.Name == "图解市场" {
- cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
- } else if articleResult.Series.Name == "行业深度" {
- cover = articleResult.Cover
- }
- fmt.Println(cover)
-
-
- if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
- 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)
- item := new(models.Tactics2)
- itemArticleData := new(models.CygxArticleData)
- itemArticleData.ArticleId = articleResult.ArticleId
- itemArticleData.Cover = articleResult.Cover
- itemArticleData.CreateTime = time.Now()
- listArticleData = append(listArticleData, itemArticleData)
- itemAuthor := new(models.CygxArticleAuthor)
- item.ArticleId = articleResult.ArticleId
- item.Title = articleResult.Title
- item.TitleEn = articleResult.TitleEn
- item.File = articleResult.File
- if articleResult.Frequency == "日度" {
- item.UpdateFrequency = "daily"
- } else if articleResult.Frequency == "周度" {
- item.UpdateFrequency = "weekly"
- } else if articleResult.Frequency == "月度" {
- item.UpdateFrequency = "monthly"
- } else if articleResult.Frequency == "季度" {
- item.UpdateFrequency = "quarterly"
- } else if articleResult.Frequency == "年度" {
- item.UpdateFrequency = "yearly"
- } else {
- item.UpdateFrequency = "unknow"
- }
- item.CreateDate = articleResult.CreateDate
- item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
- item.PublishStatus = 1
- item.Body = articleResult.Content.Body
- item.Abstract = articleResult.Content.Abstract
- item.Annotation = articleResult.Content.Annotation
- item.CategoryName = articleResult.Industry.Name
- item.CategoryId = categoryIdMap[articleResult.SeriesId]
- item.CategoryIdTwo = exitMap[articleResult.SeriesId]
- item.SubCategoryName = articleResult.Series.Name
- item.Cover = cover
- {
-
- if articleResult.Field.Name == "宏观利率" {
- item.CategoryId = 10070
- item.CategoryIdTwo = item.CategoryId
- }
- if articleResult.Field.Name == "信用" {
- item.CategoryId = 10082
- item.CategoryIdTwo = item.CategoryId
- }
- }
- if len(articleResult.Stock) > 0 {
- var stock string
- for _, vS := range articleResult.Stock {
- stock += vS + "/"
- }
- stock = strings.TrimRight(stock, "/")
- item.Stock = stock
- }
- item.FieldName = articleResult.Field.Name
- item.TypeName = articleResult.Type.Name
- item.UpdateDate = articleResult.UpdateDate
- item.CeLueFieldId = articleResult.Field.Id
- list = append(list, item)
- itemAuthor.ArticleId = articleResult.ArticleId
- itemAuthor.Name = articleResult.Author.Name
- itemAuthor.Mobile = articleResult.Author.PhoneNumber
- fmt.Println(articleResult.Cover)
- listAuthor = append(listAuthor, itemAuthor)
- } else {
-
- err = models.UpdateArticlePublish(artcleId, 0)
- if err != nil {
- fmt.Println("UpdateArticlePublish Err:", err.Error())
- return err
- }
- UpdateArticleResourceData(artcleId)
-
- return
- }
-
- for _, v := range listAuthor {
- var count int
- count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
- if err != nil {
- fmt.Println("GetActivityAuthorCount Err:", err.Error())
- return err
- }
- if count == 0 {
- _, err = models.AddCygxActivityAuthor(v)
- if err != nil {
- fmt.Println("AddCygxActivityAuthor Err:", err.Error())
- return err
- }
- }
- }
- fmt.Println("同步文章条数:", len(list))
- listCustomArticle, err := models.GetCustomArticleId()
- if err != nil {
- fmt.Println("GetTacticsList Err:", err.Error())
- return err
- }
- listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull()
- if errMatch != nil {
- fmt.Println("GetTacticsList Err:", errMatch.Error())
- return err
- }
-
-
-
-
- fmt.Println("list len:", len(list))
- 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"
- listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
- for k, v := range list {
-
- matchTypeName := ""
- for _, vMatch := range listGetMatchTypeName {
- if v.CategoryId == vMatch.CategoryId {
- matchTypeName = vMatch.MatchTypeName
- }
- }
-
-
-
-
- if v.TypeName == "纪要" {
- v.IsSummary = 1
- }
-
- for _, vArt := range listNoSummaryArticleIds {
- vArtInt, _ := strconv.Atoi(vArt)
- if v.ArticleId == vArtInt {
- v.IsSummary = 0
- }
- }
- if _, has := reportMap[v.CategoryIdTwo]; has {
- v.IsReport = 1
- if _, ok := classMap[v.CategoryIdTwo]; ok {
- v.IsClass = 1
- v.ReportType = 1
- } else {
- v.ReportType = 2
- }
- }
- v.Department = "弘则权益研究"
-
- if v.ArticleId < 0 {
- fmt.Println("AddCygxArticle Err:")
- return err
- }
- var count int
- count, err = models.GetArticleCountById(v.ArticleId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- fmt.Println("AddCygxArticle Err:", err.Error())
- return err
- }
- v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
- expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
- if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
- v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
- v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
- v.Body = strings.Replace(v.Body, "):", "", -1)
- }
- var titleNew string
- titleNew = v.Title
-
- if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
- if v.UpdateFrequency == "daily" {
- var daystr string
- daystr = strconv.Itoa(v.PublishDate.Day())
- if len(daystr) == 1 {
- daystr = "0" + daystr
- }
- titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
- } else if v.UpdateFrequency == "weekly" {
- titleNew = v.Title + utils.WeekByDate(v.PublishDate)
- }
- }
- if v.CategoryId == 80 {
- titleNew = v.Title + utils.WeekByDate(v.PublishDate)
- }
-
- if articleResult.Type.Name == "综述报告" {
- detailCategory, err := models.GetdetailByCategoryIdLyjh(v.CategoryIdTwo)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- v.CategoryId = detailCategory.CategoryId
- v.IsSummary = 0
- }
- if count > 0 {
- fmt.Println(k, v.ArticleId, "edit")
- articleIfoOld, e := models.GetArticleDetailTestById(v.ArticleId)
- if e != nil {
- err = e
- return
- }
- bodyTextOld, _ := GetReportContentTextSubNew(articleIfoOld.Body)
- bodyText, _ := GetReportContentTextSubNew(v.Body)
- if len(bodyText)-len(bodyTextOld) > 100 {
-
-
- go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
- go UpdateArticleResourceData(v.ArticleId)
-
- }
- var isCustom bool
- updateParams := make(map[string]interface{})
-
- updateParams["Title"] = titleNew
- updateParams["TitleEn"] = v.TitleEn
- updateParams["UpdateFrequency"] = v.UpdateFrequency
- updateParams["CreateDate"] = v.CreateDate
- updateParams["PublishDate"] = v.PublishDate
-
- updateParams["Body"] = html.EscapeString(bodyReturn)
- updateParams["BodyText"] = bodyText
- updateParams["Abstract"] = html.EscapeString(v.Abstract)
- updateParams["CategoryName"] = v.CategoryName
- for _, vCustom := range listCustomArticle {
- if v.ArticleId == vCustom.ArticleId {
- fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
- isCustom = true
- }
- }
- if isCustom == false {
- updateParams["CategoryId"] = v.CategoryId
- updateParams["MatchTypeName"] = matchTypeName
- updateParams["IsSummary"] = v.IsSummary
- updateParams["IsReport"] = v.IsReport
- updateParams["ReportType"] = v.ReportType
- updateParams["SubCategoryName"] = v.SubCategoryName
- }
-
- updateParams["PublishStatus"] = 1
- updateParams["ExpertBackground"] = expertContentStr
- updateParams["ExpertNumber"] = expertNumStr
- updateParams["InterviewDate"] = interviewDateStr
-
- v.Department = "弘则权益研究"
- updateParams["Department"] = v.Department
- updateParams["FileLink"] = v.File
- updateParams["Stock"] = v.Stock
- updateParams["FieldName"] = v.FieldName
- updateParams["Annotation"] = v.Annotation
- updateParams["TypeName"] = v.TypeName
- updateParams["ModifyTimeByCl"] = v.UpdateDate
- updateParams["CeLueFieldId"] = v.CeLueFieldId
- updateParams["Cover"] = v.Cover
- whereParam := map[string]interface{}{"article_id": v.ArticleId}
- err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
- if err != nil {
- fmt.Println("UpdateByExpr Err:" + err.Error())
- return err
- }
- } else {
- fmt.Println(k, v.ArticleId, "add")
- item := new(models.CygxArticle)
- articleIdInt := v.ArticleId
- item.ArticleId = articleIdInt
-
- item.Title = titleNew
- item.TitleEn = v.TitleEn
- item.UpdateFrequency = v.UpdateFrequency
- item.CreateDate = v.CreateDate
- item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
-
- item.Body = html.EscapeString(bodyReturn)
- item.Abstract = html.EscapeString(v.Abstract)
- item.CategoryName = v.CategoryName
- item.SubCategoryName = v.SubCategoryName
- item.CategoryId = v.CategoryId
- item.CategoryIdTwo = v.CategoryIdTwo
- item.PublishStatus = 1
- item.ExpertBackground = expertContentStr
- item.ExpertNumber = expertNumStr
- item.InterviewDate = interviewDateStr
- item.Department = v.Department
- item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
- item.IsClass = v.IsClass
- item.IsSummary = v.IsSummary
- item.IsReport = v.IsReport
- item.ReportType = v.ReportType
- item.FileLink = v.File
- item.MatchTypeName = matchTypeName
- item.Stock = v.Stock
- item.FieldName = v.FieldName
- item.Annotation = v.Annotation
- item.TypeName = v.TypeName
- item.ModifyTimeByCl = v.UpdateDate
- item.CeLueFieldId = v.CeLueFieldId
- item.Cover = v.Cover
- newId, err := models.AddCygxArticles(item)
- if err != nil {
- fmt.Println("AddCygxArticle Err:", err.Error())
- return err
- }
-
- go UpdateArticleResourceData(v.ArticleId)
-
-
- if v.ReportType == 2 {
- var subjectStr string
- var industrialManagementIdStr string
- var industrialSubjectIdStr string
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- sliceSubjects := strings.Split(v.Stock, "/")
- mapManagementForSubject := make(map[string]string)
- mapIndustrialId := make(map[int]int)
- if len(sliceSubjects) > 0 {
- for _, vSubject := range sliceSubjects {
- sliceKuohao := strings.Split(vSubject, "(")
- sliceXiahuaxian := strings.Split(sliceKuohao[0], "-")
- subject := sliceXiahuaxian[0]
- subjectStr += "'" + subject + "',"
- }
-
- detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
- if errCategory != nil {
- fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
- return err
- }
- subjectStr = strings.TrimRight(subjectStr, ",")
- if subjectStr != "" {
- listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
- if err != nil {
- fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
- return err
- }
- subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
- subjectStr = strings.Replace(subjectStr, "'", "", -1)
- subjectStr = "【" + subjectStr + "】"
- if len(listIndustrial) > 0 {
- for _, vIndustrial := range listIndustrial {
- if _, ok := mapIndustrialId[vIndustrial.IndustrialManagementId]; !ok {
- industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
- }
- mapIndustrialId[vIndustrial.IndustrialManagementId] = vIndustrial.IndustrialManagementId
- industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
- mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
- if vIndustrial.LayoutTime == "0000-00-00 00:00:00" {
- go models.UpdateIndustrialManagementLayoutTime(v.PublishDate.AddDate(0, 0, -10).Format(utils.FormatDateTime), vIndustrial.IndustrialManagementId)
- }
- }
- industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
- industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
- if industrialManagementIdStr != "" {
- err = models.ReportArticleClassificationEditNew(int(newId), industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
- if err != nil {
- fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
- return err
- }
- }
- var peoductName string
- for mk, mv := range mapManagementForSubject {
- peoductName += "【" + mk + "--" + strings.TrimRight(mv, "/") + "】"
- }
- keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
- keyword2 = "已自动关联至以下产业和标的:" + peoductName
- keyword3 = v.Title
- keyword4 = v.PublishDate.Format(utils.FormatDateTime)
- SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
- } else {
- keyword1 = "新报告产业标签:【" + v.FieldName + "】,个股标签:" + subjectStr
- keyword2 = "未归类"
- keyword3 = v.Title
- keyword4 = v.PublishDate.Format(utils.FormatDateTime)
- SendWxMsgWithArticleClassToAdmin(keyword1, keyword2, keyword3, keyword4, openIdList, articleIdInt)
- go models.UpdateIsClassFail(artcleId)
- }
- }
- }
- }
- go DoArticleOnenIdWxTemplateMsg(v.ArticleId)
- }
-
-
-
-
-
-
- }
- go models.UpdateCygxArticleCeluePush(artcleId)
- AddComprehensiveArticle(artcleId)
- AddComprehensiveIndustrialSource("Hz", artcleId)
- GetSummarytoEs(artcleId)
- GetIndustrialManagementArticleNewPublishData()
- if len(listArticleData) > 0 {
- for _, v := range listArticleData {
- count, err := models.GetCygxArticleDataCount(v.ArticleId)
- if err != nil {
- fmt.Println("GetCygxArticleDataCount Err:", err.Error())
- return err
- }
- if count == 0 {
- _, err := models.AddCygxArticleData(v)
- if err != nil {
- fmt.Println("AddCygxArticleData Err:", err.Error())
- return err
- }
- }
-
-
-
-
-
-
-
-
-
-
- }
- }
- AddCygxReportMappingCategoryGroupByArticleId(artcleId)
- return err
- }
- func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
-
- cacheKey := fmt.Sprint(utils.CACHE_KEY_ARTICLE_ID_TEMPLATE, ":ArticleId", articleId)
- ttlTime := utils.Rc.GetRedisTTL(cacheKey)
- if ttlTime > 0 {
- fmt.Println(ttlTime)
- return err
- }
- var msg string
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("过滤策略平台报告,研选报告重复推送,以及权限勾选的推送失败 DoArticleOnenIdWxTemplateMsg ErrMsg:"+err.Error(), 2)
- fmt.Println(err)
- }
- if msg != "" {
- utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
- }
- }()
-
- articleInfo, err := models.GetArticleDetailById(articleId)
- if err != nil {
- return
- }
- articleInfo.Abstract, _ = GetReportContentTextSub(articleInfo.Abstract)
- var chartPermissionId int
-
- var chartPermissionName string
- reportMapDetail, err := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
- if err != nil {
- return err
- }
- if reportMapDetail.ChartPermissionId == utils.CE_LUE_ID {
- chartPermissionId = utils.CE_LUE_ID
- } else if reportMapDetail.ChartPermissionId == utils.GU_SHOU_ID_CHART {
- chartPermissionId = utils.GU_SHOU_ID_CHART
- } else {
- if reportMapDetail.PermissionType == 1 {
- chartPermissionName = reportMapDetail.ChartPermissionName + "(主观)"
- } else {
- chartPermissionName = reportMapDetail.ChartPermissionName + "(客观)"
- }
- chartPermissionDetail, err := models.GetChartPermissionByRemark(chartPermissionName)
- if err != nil {
- return err
- }
- chartPermissionId = chartPermissionDetail.ChartPermissionId
- }
-
- var industryName string
- var industrialManagementId string
- if chartPermissionId == utils.CE_LUE_ID || chartPermissionId == utils.GU_SHOU_ID_CHART {
- industryName = reportMapDetail.SubCategoryName
- } else {
- if articleInfo.ReportType == 2 {
- detailIndustryNameList, err := models.GetIndustrialManagemenDetailByAaticleID(articleId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
-
- if len(detailIndustryNameList) == 0 {
- return err
- }
- for _, v := range detailIndustryNameList {
- industryName += v.IndustryName + ","
- industrialManagementId += strconv.Itoa(v.IndustrialManagementId) + ","
- }
- industryName = strings.TrimRight(industryName, ",")
- industrialManagementId = strings.TrimRight(industrialManagementId, ",")
-
- var allIn string
- allIn = DoXzsChooseSend(reportMapDetail.ChartPermissionName)
- if allIn != "" {
- allInList, err := models.GetCygxXzsChooseSendByAllIn(allIn)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- if len(allInList) > 0 {
- var allInUserId string
- for _, v := range allInList {
- allInUserId += strconv.Itoa(v.UserId) + ","
- }
- allInUserId = strings.TrimRight(allInUserId, ",")
- userFllowIndustrialList, err := models.GetUserFllowIndustrialListByUserIdAndIndustrial(allInUserId, industrialManagementId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- mapUserFllowed := make(map[string]int)
- for _, v := range userFllowIndustrialList {
-
- mapUserFllowed[fmt.Sprint("uid:", v.UserId, "_Industrial:", v.IndustrialManagementId)] = v.UserId
- }
-
- userList, err := models.GetWxUserListByUserIds(allInUserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- var industryFllowItems []*models.CygxIndustryFllow
- for _, v := range detailIndustryNameList {
- for _, vUser := range userList {
-
- if mapUserFllowed[fmt.Sprint("uid:", vUser.UserId, "_Industrial:", v.IndustrialManagementId)] == 0 {
- item := new(models.CygxIndustryFllow)
- item.IndustrialManagementId = v.IndustrialManagementId
- item.UserId = vUser.UserId
- item.Email = vUser.Email
- item.Mobile = vUser.Mobile
- item.RealName = vUser.RealName
- item.CompanyId = vUser.CompanyId
- item.CompanyName = vUser.CompanyName
- item.Source = 3
- item.Type = 1
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- industryFllowItems = append(industryFllowItems, item)
- }
- }
- }
- err = models.AddCygxIndustryFllowMulti(industryFllowItems)
- if err != nil {
- go utils.SendAlarmMsg("用户关注全部赛道,出现新赛道批量添加失败 ,AddCygxIndustryFllowMulti ErrMsg:"+err.Error(), 2)
- }
- }
- }
- }
- }
-
- mapOpenidPower := make(map[int]string)
- permissionIdList := make([]string, 0)
- var condition string
- var pars []interface{}
- slicepermissionId := strings.Split(strconv.Itoa(chartPermissionId), ",")
- if len(slicepermissionId) > 0 {
- for _, v := range slicepermissionId {
- if v == strconv.Itoa(utils.GU_SHOU_ID_CHART) {
- v = strconv.Itoa(utils.CE_LUE_ID)
- }
- permissionIdList = append(permissionIdList, v)
- }
- condition += ` AND p.chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) `
- pars = append(pars, permissionIdList)
- }
- openidPowerListMobile, err := models.GetCygxUserRecordPower(condition, pars)
- if err != nil {
- return err
- }
- var mobileArr []string
- for _, v := range openidPowerListMobile {
- mobileArr = append(mobileArr, v.Mobile)
- }
- openidPowerList, err := models.GetWxOpenIdByMobileSliceList(mobileArr)
- if err != nil {
- return err
- }
-
- if articleInfo.ReportType == 1 && chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID_CHART {
- for _, item := range openidPowerList {
- first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
- keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
- openIditem := new(models.OpenIdList)
- openIditem.OpenId = item.OpenId
- openIditem.UserId = item.UserId
- SendWxMsgWithArticleUpdate(first, keyword1, articleInfo.Title, articleInfo.PublishDate, articleInfo.Abstract, openIditem, articleId)
- }
- return err
- }
- for _, v := range openidPowerList {
- mapOpenidPower[v.UserId] = v.OpenId
- }
-
- mapOpenidFllow := make(map[int]string)
- if chartPermissionId != utils.CE_LUE_ID && chartPermissionId != utils.GU_SHOU_ID_CHART {
- openidFllowListMobile, err := models.GetCygxUserFllowOpenid(articleId)
- if err != nil {
- return err
- }
- var mobileArrFllow []string
- for _, v := range openidFllowListMobile {
- mobileArrFllow = append(mobileArrFllow, v.Mobile)
- }
- openidFllowList, err := models.GetWxOpenIdByMobileSliceList(mobileArrFllow)
- if err != nil {
- return err
- }
- for _, v := range openidFllowList {
- mapOpenidFllow[v.UserId] = v.OpenId
- }
- }
-
- mapOpenidRefuset := make(map[int]string)
- openidRefusetList, err := models.GetCygxUserRefusetOpenid()
- if err != nil {
- return err
- }
- for _, v := range openidRefusetList {
- mapOpenidRefuset[v.UserId] = v.OpenId
- }
-
- mapUserIdChooseSend := make(map[int]int)
- mapUserIdChooseSendTypeNoPermission := make(map[int]int)
- chooseSendtList, err := models.GetCygxXzsChooseSend()
- for _, v := range chooseSendtList {
- mapUserIdChooseSend[v.UserId] = v.UserId
- if v.IsRefuse == 1 {
- continue
- }
-
- if reportMapDetail.PermissionType == 1 {
- if v.IsSubjective == 1 {
- mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
- }
- } else {
- if v.IsObjective == 1 {
- mapUserIdChooseSendTypeNoPermission[v.UserId] = v.UserId
- }
- }
- }
-
- mapOpenidPushed := make(map[int]string)
- keyword2 := articleInfo.Title
- keyword3 := time.Now().Format(utils.FormatDateTime)
- keyword4 := articleInfo.Abstract
- mapAlreadySend := make(map[int]int)
-
- if reportMapDetail.ChartPermissionName == utils.CE_LUE_NAME || reportMapDetail.ChartPermissionName == utils.GU_SHOU_NAME {
-
- mapUserFllowCeLue := make(map[int]string)
- userFllowCeLueList, err := models.GetCygxUserFllowCeLueOpenid(articleInfo.CategoryId)
- if err != nil {
- return err
- }
- for _, v := range userFllowCeLueList {
- mapUserFllowCeLue[v.UserId] = v.OpenId
- }
- for k, v := range mapOpenidPower {
- if mapOpenidPushed[k] != "" {
- continue
- }
- openIditem := new(models.OpenIdList)
- openIditem.UserId = k
- openIditem.OpenId = v
- first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
- keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
- mapActivityUserId := make(map[int]string)
- if articleInfo.ReportType == 2 {
- sliceSubjectId, _ := models.GetSubjectIds(articleId)
- if sliceSubjectId != "" {
- appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
- if err != nil {
- fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
- return err
- }
- var userIds []string
- if len(appointmentList) > 0 {
- for _, v := range appointmentList {
-
- userIds = append(userIds, strconv.Itoa(v.UserId))
- mapActivityUserId[v.UserId] += v.ActivityName + ","
- }
- userIdstr := strings.Join(userIds, ",")
- openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
- if err != nil {
- fmt.Println("GetOpenIdByUserIds Err:", err.Error())
- return err
- }
- for _, item := range openIdLists {
- first := "您预约的调研,有关联的纪要发布/更新了"
- keyword1 := industryName
- openIditem := new(models.OpenIdList)
- openIditem.OpenId = item.OpenId
- openIditem.UserId = item.UserId
- if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
- SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
- delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
- fmt.Println("AlreadySend:", openIditem.UserId)
- mapAlreadySend[openIditem.UserId] = openIditem.UserId
- }
- }
- }
- }
-
-
-
-
-
-
-
-
- }
- _, ok := mapAlreadySend[openIditem.UserId]
-
- if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
- fmt.Println("1:", articleId)
- SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
- }
-
- if mapUserIdChooseSend[openIditem.UserId] != 0 && mapUserFllowCeLue[openIditem.UserId] != "" && !ok {
- fmt.Println("2:", articleId)
- SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
- }
- }
- } else {
- for k, v := range mapOpenidPower {
- if mapOpenidPushed[k] != "" {
- continue
- }
- mapUserIdChooseSendType := make(map[int]int)
- for _, vS := range chooseSendtList {
- if vS.IsRefuse == 1 {
- continue
- }
-
- if reportMapDetail.PermissionType == 1 {
- if vS.IsSubjective == 1 {
- mapUserIdChooseSendType[vS.UserId] = vS.UserId
- }
- } else if reportMapDetail.PermissionType == 2 {
- if vS.IsObjective == 1 {
- mapUserIdChooseSendType[vS.UserId] = vS.UserId
- }
- } else {
- if vS.IsSubjective == 1 || vS.IsObjective == 1 {
- mapUserIdChooseSendType[vS.UserId] = vS.UserId
- }
- }
- }
- openIditem := new(models.OpenIdList)
- openIditem.UserId = k
- openIditem.OpenId = v
- first := "您关注的赛道,有新的报告发布/更新,欢迎查看"
- keyword1 := "【" + articleInfo.SubCategoryName + "】有报告发布/更新"
- mapActivityUserId := make(map[int]string)
- if articleInfo.ReportType == 2 {
- keyword1 = fmt.Sprint("【", industryName, "】有报告发布/更新")
- sliceSubjectId, _ := models.GetSubjectIds(articleId)
- if sliceSubjectId != "" {
- appointmentList, err := models.GetCygxAppointmentSummaryBySubjectId(sliceSubjectId)
- if err != nil {
- fmt.Println("GetCygxAppointmentSummaryListBySubjectId Err:", err.Error())
- return err
- }
- var userIds []string
- if len(appointmentList) > 0 {
- for _, v := range appointmentList {
-
- userIds = append(userIds, strconv.Itoa(v.UserId))
- mapActivityUserId[v.UserId] += v.ActivityName + ","
- }
- userIdstr := strings.Join(userIds, ",")
- openIdLists, err := models.GetOpenIdByUserIds(userIdstr)
- if err != nil {
- fmt.Println("GetOpenIdByUserIds Err:", err.Error())
- return err
- }
- for _, item := range openIdLists {
-
-
- openIditem := new(models.OpenIdList)
- openIditem.OpenId = item.OpenId
- openIditem.UserId = item.UserId
- if _, ok := mapAlreadySend[openIditem.UserId]; !ok {
- SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
- delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
- fmt.Println("AlreadySend:", openIditem.UserId)
- mapAlreadySend[openIditem.UserId] = openIditem.UserId
- }
- }
- }
- }
- }
-
- _, ok := mapAlreadySend[openIditem.UserId]
- if mapUserIdChooseSend[openIditem.UserId] == 0 && !ok {
- SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
- delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
- mapAlreadySend[openIditem.UserId] = openIditem.UserId
- }
-
- if mapUserIdChooseSend[openIditem.UserId] != 0 && mapOpenidFllow[openIditem.UserId] != "" && mapUserIdChooseSendType[openIditem.UserId] > 0 && !ok {
- SendWxMsgWithArticleUpdate(first, keyword1, keyword2, keyword3, keyword4, openIditem, articleId)
- delete(mapUserIdChooseSendTypeNoPermission, openIditem.UserId)
- mapAlreadySend[openIditem.UserId] = openIditem.UserId
- }
- }
- }
- utils.Rc.Put(cacheKey, articleId, time.Hour*12)
- return
- }
- func GetSpecialArticleDetailUserPower(user *models.WxUserItem, articleInfo *models.ArticleDetail) (havePower bool, err error) {
- userType, _, e := GetUserType(user.CompanyId)
- if e != nil {
- err = errors.New("GetSpecialUserType, Err: " + e.Error())
- return
- }
-
- if userType == 1 || userType == 2 {
- havePower = true
- return
- }
- permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
- return
- }
- reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
- if e != nil {
- err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
- return
- }
- if reportMapDetail == nil {
- err = errors.New("GetdetailByCategoryIdP,获取详情失败, ")
- return
- }
- fmt.Println(permissionStr)
-
- if !strings.Contains(permissionStr, reportMapDetail.ChartPermissionName) {
- return
- } else {
- havePower = true
- }
- return
- }
- func GetArticNewLabelWhithActivity3Month() (labelMap map[int]bool, err error) {
- var condition string
- var pars []interface{}
- condition += ` AND publish_date <= ? AND article_id < ? `
- pars = append(pars, time.Now().AddDate(0, -3, 0), utils.SummaryArticleId)
- articleList, e := models.GetArticleList(condition, pars)
- if e != nil {
- err = errors.New("GetArticleList, Err: " + e.Error())
- return
- }
- var articleIds []int
- for _, v := range articleList {
- articleIds = append(articleIds, v.ArticleId)
- }
- if len(articleIds) == 0 {
- return
- }
- pars = make([]interface{}, 0)
- condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
- pars = append(pars, articleIds)
- industrialList, e := models.GetIndustrialArticleGroupManagementList(condition, pars)
- if e != nil {
- err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error())
- return
- }
- labelMap = make(map[int]bool, 0)
- var industrialIds []int
- for _, v := range industrialList {
- industrialIds = append(industrialIds, v.IndustrialManagementId)
- }
-
- var groupCond string
- var groupPars []interface{}
- groupCond += ` AND b.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIds)) + `) AND b.source = 1 `
- groupPars = append(groupPars, industrialIds)
- groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
- if e != nil {
- err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
- return
- }
- for _, v := range groups {
- labelMap[v.ActivityId] = true
- }
- return
- }
- func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeArticle, err error) {
-
- detailResearch, e := models.GetConfigByCode("category_research_img_url")
- if e != nil {
- err = errors.New("获取研选的五张图片失败" + e.Error())
- return
- }
- researchList := strings.Split(detailResearch.ConfigValue, "{|}")
-
- detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
- if err != nil {
- err = errors.New("获取对应分类的所图片失败" + err.Error())
- return
- }
- categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
- mapCategoryUrl := make(map[string]string)
- var categoryId string
- var imgUrlChart string
- for _, v := range categoryUrlList {
- vslice := strings.Split(v, "_")
- categoryId = vslice[0]
- imgUrlChart = vslice[len(vslice)-1]
- mapCategoryUrl[categoryId] = imgUrlChart
- }
- mapChartPerssion := make(map[string]string)
- reportMappingList, err := models.GetReportMappingStrategyAll()
- if err != nil {
- err = errors.New("GetReportMappingStrategyAll err" + err.Error())
- return
- }
- for _, v := range reportMappingList {
- mapChartPerssion[strconv.Itoa(v.CategoryId)] = v.ChartPermissionName
- }
- for k, v := range list {
- list[k].Abstract, _ = GetReportContentTextSub(v.Abstract)
- item := list[k]
-
- if list[k].Annotation == "" {
- imgurl, _ := FixArticleImgUrl(html.UnescapeString(list[k].Body))
- if imgurl != "" {
- list[k].BodyHtml = imgurl
- }
- }
-
- list[k].Annotation = ArticleAnnotation(item)
- list[k].Body = ""
- list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate)
- list[k].ChartPermissionName = mapChartPerssion[v.CategoryId]
-
- if v.CategoryId == "0" || v.ArticleId > utils.SummaryArticleId {
- knum := v.ArticleId % 5
- list[k].ImgUrlPc = researchList[knum]
- } else {
- list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
- }
- list[k].ArticleResponse = 4
-
- if list[k].ArticleId >= utils.SummaryArticleId {
- list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
- list[k].IsNeedJump = true
- list[k].ArticleResponse = 1
-
-
-
-
-
-
-
-
-
-
-
- }
- list[k].Source = 1
-
- if v.ImgUrlPc == "" {
- if v.ChartPermissionName == utils.YI_YAO_NAME {
- list[k].ImgUrlPc = utils.YI_YAO_OTHER_IMG
- } else if v.ChartPermissionName == utils.XIAO_FEI_NAME {
- list[k].ImgUrlPc = utils.XIAO_FEI_OTHER_IMG
- } else if v.ChartPermissionName == utils.KE_JI_NAME {
- list[k].ImgUrlPc = utils.KE_JI_OTHER_IMG
- } else if v.ChartPermissionName == utils.ZHI_ZAO_NAME {
- list[k].ImgUrlPc = utils.ZHI_ZAO_OTHER_IMG
- }
- }
-
- if v.ArticleTypeId > 0 {
- list[k].IsResearch = true
- }
- }
- articleIds := make([]int, 0)
- for i := range list {
- articleIds = append(articleIds, list[i].ArticleId)
- }
- articleMapPv := GetArticleHistoryByArticleId(articleIds)
-
- industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
- if len(articleIds) > 0 {
- var industryCond string
- var industryPars []interface{}
- industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
- industryPars = append(industryPars, articleIds)
- industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
- if e != nil {
- err = errors.New("GetIndustrialListByarticleId" + e.Error())
- return
- }
- for i := range industryList {
- v := industryList[i]
- industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
- ArticleId: v.ArticleId,
- IndustrialManagementId: v.IndustrialManagementId,
- IndustryName: v.IndustryName,
- ChartPermissionId: v.ChartPermissionId,
- })
- }
- }
- for k, v := range list {
- if len(industryMap[v.ArticleId]) > 0 {
- list[k].List = industryMap[v.ArticleId]
- } else {
- list[k].List = make([]*models.IndustrialManagementIdInt, 0)
- }
- v.Pv = articleMapPv[v.ArticleId]
- if v.Pv > 999 {
- list[k].Pv = 999
- }
- }
- if len(list) == 0 {
- list = make([]*models.HomeArticle, 0)
- }
- items = list
- return
- }
- func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
- if item.ArticleId >= utils.SummaryArticleId {
- item.Annotation = YxArticleAnnotation(item)
- }
- if item.Annotation != "" {
- annotation = strings.Replace(item.Annotation, "<br>", "", -1)
- annotation = strings.Replace(item.Annotation, " ", "", -1)
- } else {
- return
- }
- bodyText, _ := GetReportContentTextSubNew(annotation)
- if bodyText == "" {
- return
- }
- if annotation != "" {
- annotation = html.UnescapeString(annotation)
- doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
- docText := doc.Text()
- mapDoc := make(map[int]string)
- var mapSort []int
- p := doc.Find("p")
- p.Each(func(tk int, pd *goquery.Selection) {
- pdText := pd.Text()
- pdText = strings.Replace(pdText, " ", "", -1)
- if pdText != "" {
- textLen := strings.Index(docText, pdText)
- mapDoc[(strings.Index(docText, pdText))] = pdText
- mapSort = append(mapSort, textLen)
- }
- })
- li := doc.Find("li")
- li.Each(func(tk int, li *goquery.Selection) {
- liText := li.Text()
- liText = strings.Replace(liText, " ", "", -1)
- if liText != "" {
- textLen := strings.Index(docText, liText)
- mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
- mapSort = append(mapSort, textLen)
- }
- })
- ul := doc.Find("ul")
- ul.Each(func(tk int, ul *goquery.Selection) {
- ulText := ul.Text()
- ulText = strings.Replace(ulText, " ", "", -1)
- if ulText != "" {
- textLen := strings.Index(docText, ulText)
- mapDoc[(strings.Index(docText, ulText))] = ulText
- mapSort = append(mapSort, textLen)
- }
- })
- if len(mapSort) == 0 {
- return
- } else {
-
- sort.Ints(mapSort)
- var annotationHtml string
- for _, vSort := range mapSort {
- for k, v := range mapDoc {
- if k == vSort && v != "" {
- annotationHtml += v + "<br>"
- }
- }
- }
- annotationHtml = strings.TrimRight(annotationHtml, "<br>")
- annotationHtml = "<p>" + annotationHtml + "</p>"
- annotation = annotationHtml
- }
- }
- return
- }
- func AnnotationHtml(bodyText string) (annotation string) {
- if bodyText == "" {
- return
- }
- annotation = bodyText
- annotation = html.UnescapeString(annotation)
- doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
- docText := doc.Text()
- mapDoc := make(map[int]string)
- var mapSort []int
- p := doc.Find("p")
- p.Each(func(tk int, pd *goquery.Selection) {
- pdText := pd.Text()
-
- if pdText != "" {
- textLen := strings.Index(docText, pdText)
- mapDoc[(strings.Index(docText, pdText))] = pdText
- mapSort = append(mapSort, textLen)
- }
- })
- li := doc.Find("li")
- li.Each(func(tk int, li *goquery.Selection) {
- liText := li.Text()
- liText = strings.Replace(liText, " ", "", -1)
- if liText != "" {
- textLen := strings.Index(docText, liText)
- mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
- mapSort = append(mapSort, textLen)
- }
- })
- ul := doc.Find("ul")
- ul.Each(func(tk int, ul *goquery.Selection) {
- ulText := ul.Text()
- ulText = strings.Replace(ulText, " ", "", -1)
- if ulText != "" {
- textLen := strings.Index(docText, ulText)
- mapDoc[(strings.Index(docText, ulText))] = ulText
- mapSort = append(mapSort, textLen)
- }
- })
- section := doc.Find("section")
- section.Each(func(tk int, section *goquery.Selection) {
- sectionText := section.Text()
- sectionText = strings.Replace(sectionText, " ", "", -1)
- if sectionText != "" {
- textLen := strings.Index(docText, sectionText)
- mapDoc[(strings.Index(docText, sectionText))] = sectionText
- mapSort = append(mapSort, textLen)
- }
- })
- if len(mapSort) == 0 {
- return
- } else {
-
- sort.Ints(mapSort)
- var annotationHtml string
- for _, vSort := range mapSort {
- for k, v := range mapDoc {
- if k == vSort && v != "" {
- annotationHtml += v + "<br>"
- }
- }
- }
- annotationHtml = strings.TrimRight(annotationHtml, "<br>")
- annotationHtml = "<p>" + annotationHtml + "</p>"
- annotation = annotationHtml
- }
- return
- }
- func ProductInteriorHtml(bodyText string) (annotation string) {
- if bodyText == "" {
- return
- }
- sliceBody := strings.Split(bodyText, "</p>")
- annotation, _ = GetReportContentTextSub(sliceBody[0])
- return
- }
- func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
-
- if strings.Count(article.Body, "<hr") == 0 {
-
- if article.BodyHtml != "" {
- return
- }
- annotation, _ = GetReportContentTextSub(article.Body)
- return
- }
- body := strings.ReplaceAll(article.Body, "<strong>", "")
- body = strings.ReplaceAll(body, "</strong>", "")
- body = strings.ReplaceAll(body, "</ol>", "</div>")
- body = strings.ReplaceAll(body, "<ol>", "<div>")
- body = strings.ReplaceAll(body, "</li>", "</p>")
- body = strings.ReplaceAll(body, "<li>", "<p>")
- re, _ := regexp.Compile("<strong.*?>")
- body = re.ReplaceAllString(body, "")
- reLi, _ := regexp.Compile("<li.*?>")
- body = reLi.ReplaceAllString(body, "")
- var plus int
- coreIndex := strings.Index(body, "核心观点:")
- plus = 15
- if coreIndex == -1 {
- coreIndex = strings.Index(body, "核心观点:")
- plus = 13
- }
- if coreIndex == -1 {
- coreIndex = strings.Index(body, "核心观点")
- plus = 12
- }
- if coreIndex == -1 {
- coreIndex = strings.Index(body, "核心结论:")
- plus = 15
- }
- if coreIndex == -1 {
- coreIndex = strings.Index(body, "核心结论:")
- plus = 13
- }
- if coreIndex == -1 {
- coreIndex = strings.Index(body, "核心结论")
- plus = 12
- }
- endIndex := strings.Index(body, "<hr")
- if coreIndex != -1 && endIndex != -1 {
- body = body[coreIndex+plus : endIndex]
- }
- annotation = body
- return
- }
- func GetReportLinkToArticleid(reportLink string) (articleId int, err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("通过接解析带有Md5的文章链接获取文章ID失败"+err.Error(), 2)
- }
- }()
- var artMd5 string
-
- strnum1 := strings.Index(reportLink, "id=")
- if strnum1 > 0 {
- sliceId := strings.Split(reportLink, "id=")
- if len(sliceId) > 1 {
- reportLink = sliceId[1]
- sliceMd5Id := strings.Split(reportLink, "&")
- artMd5 = sliceMd5Id[0]
- }
- if artMd5 != "" {
- detail, errArt := models.GetArticleDetailByIdMd5(artMd5)
- if errArt != nil && errArt.Error() != utils.ErrNoRow() {
- err = errArt
- return
- }
- if detail != nil {
- articleId = detail.ArticleId
- }
- }
- } else {
-
- linkList := strings.Split(reportLink, "/")
- if linkList[len(linkList)-1] != "" {
- linkArticleId, _ := strconv.Atoi(linkList[len(linkList)-1])
- if linkArticleId > 0 {
- articleInfo, errArt := models.GetArticleDetailById(linkArticleId)
- if errArt != nil && errArt.Error() != utils.ErrNoRow() {
- err = errArt
- return
- }
- if articleInfo != nil {
- articleId = articleInfo.ArticleId
- }
- }
- }
- }
- return
- }
- func GetArticleStockMap() (mapResp map[string]int, err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("获取个股标签所对应的文章ID失败"+err.Error(), 2)
- }
- }()
- list, err := models.GetArticleStock()
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- mapResp = make(map[string]int, 0)
- if len(list) > 0 {
-
- for _, v := range list {
- sliceSubjects := strings.Split(v.Stock, "/")
- if len(sliceSubjects) > 0 {
- for _, vSubject := range sliceSubjects {
- sliceKuohao := strings.Split(vSubject, "(")
- sliceXiahuaxian := strings.Split(sliceKuohao[0], "-")
- subject := sliceXiahuaxian[0]
- mapResp[subject] = v.ArticleId
- }
- }
- }
- }
- return
- }
- func GetAiQianYanArtilceList(startSize, pageSize int) (items []*models.ReportArticle, total int, err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("获取AI前沿几篇文章失败"+err.Error(), 2)
- }
- }()
- var condition string
- var pars []interface{}
- condition += ` AND title LIKE '%AI前沿%' AND publish_status = 1 ORDER BY publish_date DESC `
- articleList, e := models.GetCygxCygxArticleList(condition, pars, startSize, pageSize)
- if e != nil {
- err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
- return
- }
- total, e = models.GetCygxArticleCount(condition, pars)
- if e != nil {
- err = errors.New("GetCygxArticleCount, Err: " + e.Error())
- return
- }
- for _, v := range articleList {
- item := new(models.ReportArticle)
- item.ArticleId = v.ArticleId
- item.Title = v.Title
- item.Abstract = v.Abstract
- item.Annotation = v.Annotation
- item.PublishDate = v.PublishDate
- item.Resource = 1
- item.CategoryId = strconv.Itoa(v.CategoryId)
- item.Body = v.Body
- items = append(items, item)
- }
- return
- }
- func GetArticleCoverByChartFirst(body string) (cover string) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("获取文章内部图表的第一张封面图失败,Err:"+err.Error()+body, 3)
- }
- }()
- var chartUrl string
- var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
- match := hrefRegexp.FindAllString(body, -1)
- if match != nil {
- for _, v := range match {
- if strings.Contains(v, "charts/display") {
- chartUrl = v
- break
- }
- }
- }
- if chartUrl != "" {
- urlSlice := strings.Split(chartUrl, "/")
- lenurlSlice := len(urlSlice)
- sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
- if sourceId == 0 {
- sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
- }
- if sourceId == 0 {
- err = errors.New("新的图标链接无法解析" + chartUrl)
- return
- }
- chartUrlApi := utils.ApiUrl + "charts/" + strconv.Itoa(sourceId)
- authorization := utils.ApiAuthorization
- body, e := PublicGetDate(chartUrlApi, authorization)
- if e != nil {
- err = errors.New("PublicGetDate" + err.Error())
- return
- }
- var resultDate models.ChartResultDetailApi
- e = json.Unmarshal(body, &resultDate)
- if e != nil {
- err = errors.New(" json.Unmarshal" + err.Error())
- }
- cover = resultDate.Data.Cover
- }
- return
- }
- func GetYxArticleIdMap(articleIds []int) (mapResp map[int]bool) {
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("获取研选文章ID失败,GetYxArticleIdMap"+err.Error(), 2)
- }
- }()
- var condition string
- var pars []interface{}
- condition = ` AND article_type_id > 0 `
- if len(articleIds) > 0 {
- condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
- pars = append(pars, articleIds)
- }
- articleList, e := models.GetArticleList(condition, pars)
- if e != nil {
- err = errors.New("GetArticleList, Err: " + e.Error())
- return
- }
- mapResp = make(map[int]bool, 0)
- for _, v := range articleList {
- mapResp[v.ArticleId] = true
- }
- return
- }
- func HandleArticleListByApiInit13_5(artcleId int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("处理同步策略平台数据失败"+"GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), 2)
- go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), utils.EmailSendToUsers)
- }
- }()
- var clueApiUrl string
- clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
- fmt.Println(clueApiUrl)
- authorization := utils.ApiAuthorization
- body, err := PublicGetDate(clueApiUrl, authorization)
- if err != nil {
- fmt.Println(err)
- return
- }
- var articleResultDate models.ArticleDetailResultApi
- err = json.Unmarshal(body, &articleResultDate)
- if err != nil {
- fmt.Println("Getres.PublicGetDate Err:", err.Error())
- return err
- }
- item := new(models.CygxShanghaiCompanyLog)
- item.CreateTime = time.Now()
- item.Url = clueApiUrl
- item.Body = ""
- item.Result = string(body)
- articleResult := articleResultDate.Data
- exitMap := make(map[int]int)
- categoryIdMap := make(map[int]int)
- classMap := make(map[int]int)
- reportMap := make(map[int]int)
- summaryMap := make(map[int]int)
- listMap, err := models.GetArticleApiMap()
- if err != nil {
- fmt.Println("GetlistMap Err:", err.Error())
- return err
- }
-
- for _, v := range listMap {
- exitMap[v.SeriesId] = v.OldId
- categoryIdMap[v.SeriesId] = v.OldIdMap
- if v.IsClass == 1 {
- classMap[v.OldId] = 1
- }
- if v.IsReport == 1 {
- reportMap[v.OldId] = 1
- }
- if v.IsSummary == 1 {
- summaryMap[v.OldId] = 1
- }
- }
- var list []*models.Tactics2
- var listArticleData []*models.CygxArticleData
- var listAuthor []*models.CygxArticleAuthor
-
- if articleResult.TypeId == 9 || articleResult.PublishArea != "all" {
-
- err = models.UpdateArticlePublish(artcleId, 0)
- if err != nil {
- fmt.Println("UpdateArticlePublish Err:", err.Error())
- return err
- }
- UpdateArticleResourceData(artcleId)
- return
- }
- var cover string
- if articleResult.Series.Name == "图解市场" {
- cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
- } else if articleResult.Series.Name == "行业深度" {
- cover = articleResult.Cover
- }
- fmt.Println(cover)
-
-
- if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
- 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)
- item := new(models.Tactics2)
- itemArticleData := new(models.CygxArticleData)
- itemArticleData.ArticleId = articleResult.ArticleId
- itemArticleData.Cover = articleResult.Cover
- itemArticleData.CreateTime = time.Now()
- listArticleData = append(listArticleData, itemArticleData)
- itemAuthor := new(models.CygxArticleAuthor)
- item.ArticleId = articleResult.ArticleId
- item.Title = articleResult.Title
- item.TitleEn = articleResult.TitleEn
- item.File = articleResult.File
- if articleResult.Frequency == "日度" {
- item.UpdateFrequency = "daily"
- } else if articleResult.Frequency == "周度" {
- item.UpdateFrequency = "weekly"
- } else if articleResult.Frequency == "月度" {
- item.UpdateFrequency = "monthly"
- } else if articleResult.Frequency == "季度" {
- item.UpdateFrequency = "quarterly"
- } else if articleResult.Frequency == "年度" {
- item.UpdateFrequency = "yearly"
- } else {
- item.UpdateFrequency = "unknow"
- }
- item.CreateDate = articleResult.CreateDate
- item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
- item.PublishStatus = 1
- item.Body = articleResult.Content.Body
- item.Abstract = articleResult.Content.Abstract
- item.Annotation = articleResult.Content.Annotation
- item.CategoryName = articleResult.Industry.Name
- item.CategoryId = categoryIdMap[articleResult.SeriesId]
- item.CategoryIdTwo = exitMap[articleResult.SeriesId]
- item.SubCategoryName = articleResult.Series.Name
- item.Cover = cover
- fmt.Println("item.CategoryIdTwo", item.CategoryIdTwo)
- fmt.Println("item.CategoryId", item.CategoryId)
- {
-
- if articleResult.Field.Name == "宏观利率" {
- item.CategoryId = 10070
- item.CategoryIdTwo = item.CategoryId
- }
- if articleResult.Field.Name == "信用" {
- item.CategoryId = 10082
- item.CategoryIdTwo = item.CategoryId
- }
- }
- if len(articleResult.Stock) > 0 {
- var stock string
- for _, vS := range articleResult.Stock {
- stock += vS + "/"
- }
- stock = strings.TrimRight(stock, "/")
- item.Stock = stock
- }
- item.FieldName = articleResult.Field.Name
- item.TypeName = articleResult.Type.Name
- item.UpdateDate = articleResult.UpdateDate
- item.CeLueFieldId = articleResult.Field.Id
- list = append(list, item)
- itemAuthor.ArticleId = articleResult.ArticleId
- itemAuthor.Name = articleResult.Author.Name
- itemAuthor.Mobile = articleResult.Author.PhoneNumber
- fmt.Println(articleResult.Cover)
- listAuthor = append(listAuthor, itemAuthor)
- } else {
-
- err = models.UpdateArticlePublish(artcleId, 0)
- if err != nil {
- fmt.Println("UpdateArticlePublish Err:", err.Error())
- return err
- }
- UpdateArticleResourceData(artcleId)
-
- return
- }
- fmt.Println("同步文章条数:", len(list))
- listCustomArticle, err := models.GetCustomArticleId()
- if err != nil {
- fmt.Println("GetTacticsList Err:", err.Error())
- return err
- }
- listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull()
- if errMatch != nil {
- fmt.Println("GetTacticsList Err:", errMatch.Error())
- return err
- }
-
-
-
-
- fmt.Println("list len:", len(list))
- noSummaryArticleIds := ""
- listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
- for k, v := range list {
-
- matchTypeName := ""
- for _, vMatch := range listGetMatchTypeName {
- if v.CategoryId == vMatch.CategoryId {
- matchTypeName = vMatch.MatchTypeName
- }
- }
-
-
-
-
- if v.TypeName == "纪要" {
- v.IsSummary = 1
- }
-
- for _, vArt := range listNoSummaryArticleIds {
- vArtInt, _ := strconv.Atoi(vArt)
- if v.ArticleId == vArtInt {
- v.IsSummary = 0
- }
- }
- if _, has := reportMap[v.CategoryIdTwo]; has {
- v.IsReport = 1
- if _, ok := classMap[v.CategoryIdTwo]; ok {
- v.IsClass = 1
- v.ReportType = 1
- } else {
- v.ReportType = 2
- }
- }
- v.Department = "弘则权益研究"
-
- if v.ArticleId < 0 {
- fmt.Println("AddCygxArticle Err:")
- return err
- }
- var count int
- count, err = models.GetArticleCountById(v.ArticleId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- fmt.Println("AddCygxArticle Err:", err.Error())
- return err
- }
- v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
- expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
- if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
- v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
- v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
- v.Body = strings.Replace(v.Body, "):", "", -1)
- }
- var titleNew string
- titleNew = v.Title
-
- if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
- if v.UpdateFrequency == "daily" {
- var daystr string
- daystr = strconv.Itoa(v.PublishDate.Day())
- if len(daystr) == 1 {
- daystr = "0" + daystr
- }
- titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
- } else if v.UpdateFrequency == "weekly" {
- titleNew = v.Title + utils.WeekByDate(v.PublishDate)
- }
- }
- if v.CategoryId == 80 {
- titleNew = v.Title + utils.WeekByDate(v.PublishDate)
- }
-
- if articleResult.Type.Name == "综述报告" {
- detailCategory, err := models.GetdetailByCategoryIdLyjh(v.CategoryIdTwo)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- v.CategoryId = detailCategory.CategoryId
- v.IsSummary = 0
- }
- if count > 0 {
- fmt.Println(k, v.ArticleId, "edit")
- bodyText, _ := GetReportContentTextSubNew(v.Body)
- var isCustom bool
- updateParams := make(map[string]interface{})
-
- updateParams["Title"] = titleNew
- updateParams["TitleEn"] = v.TitleEn
- updateParams["UpdateFrequency"] = v.UpdateFrequency
- updateParams["CreateDate"] = v.CreateDate
- updateParams["PublishDate"] = v.PublishDate
-
- updateParams["Body"] = html.EscapeString(bodyReturn)
- updateParams["BodyText"] = bodyText
- updateParams["Abstract"] = html.EscapeString(v.Abstract)
- updateParams["CategoryName"] = v.CategoryName
- for _, vCustom := range listCustomArticle {
- if v.ArticleId == vCustom.ArticleId {
- fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
- isCustom = true
- }
- }
- if isCustom == false {
- updateParams["CategoryId"] = v.CategoryId
- updateParams["MatchTypeName"] = matchTypeName
- updateParams["IsSummary"] = v.IsSummary
- updateParams["IsReport"] = v.IsReport
- updateParams["ReportType"] = v.ReportType
- updateParams["SubCategoryName"] = v.SubCategoryName
- }
-
- updateParams["PublishStatus"] = 1
- updateParams["ExpertBackground"] = expertContentStr
- updateParams["ExpertNumber"] = expertNumStr
- updateParams["InterviewDate"] = interviewDateStr
-
- v.Department = "弘则权益研究"
- updateParams["Department"] = v.Department
- updateParams["FileLink"] = v.File
- updateParams["Stock"] = v.Stock
- updateParams["FieldName"] = v.FieldName
- updateParams["Annotation"] = v.Annotation
- updateParams["TypeName"] = v.TypeName
- updateParams["ModifyTimeByCl"] = v.UpdateDate
- updateParams["CeLueFieldId"] = v.CeLueFieldId
- updateParams["Cover"] = v.Cover
-
-
-
-
-
-
- fmt.Println("v.ReportType", v.ReportType)
-
- var subjectStr string
- var industrialManagementIdStr string
- var industrialSubjectIdStr string
- sliceSubjects := strings.Split(v.Stock, "/")
- mapManagementForSubject := make(map[string]string)
- mapIndustrialId := make(map[int]int)
- if len(sliceSubjects) > 0 {
- for _, vSubject := range sliceSubjects {
- sliceKuohao := strings.Split(vSubject, "(")
- sliceXiahuaxian := strings.Split(sliceKuohao[0], "-")
- subject := sliceXiahuaxian[0]
- subjectStr += "'" + subject + "',"
- }
-
- detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
- if errCategory != nil {
- fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
- return err
- }
- subjectStr = strings.TrimRight(subjectStr, ",")
- if subjectStr != "" {
- listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
- if err != nil {
- fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
- return err
- }
- subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
- subjectStr = strings.Replace(subjectStr, "'", "", -1)
- subjectStr = "【" + subjectStr + "】"
- if len(listIndustrial) > 0 {
- for _, vIndustrial := range listIndustrial {
- if _, ok := mapIndustrialId[vIndustrial.IndustrialManagementId]; !ok {
- industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
- }
- mapIndustrialId[vIndustrial.IndustrialManagementId] = vIndustrial.IndustrialManagementId
- industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
- mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
- if vIndustrial.LayoutTime == "0000-00-00 00:00:00" {
- go models.UpdateIndustrialManagementLayoutTime(v.PublishDate.AddDate(0, 0, -10).Format(utils.FormatDateTime), vIndustrial.IndustrialManagementId)
- }
- }
- industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
- industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
- if industrialManagementIdStr != "" {
- err = models.ReportArticleClassificationEditNew(artcleId, industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
- if err != nil {
- fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
- return err
- }
- }
- }
-
- }
- }
- }
- }
- AddComprehensiveIndustrialSource("Hz", artcleId)
- AddCygxReportMappingCategoryGroupByArticleId(artcleId)
- return err
- }
- func HandleArticleListByApiInit13_5GuShou(artcleId int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("处理同步策略平台数据失败"+"GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), 2)
- go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error()+"artcleId:"+strconv.Itoa(artcleId), utils.EmailSendToUsers)
- }
- }()
- var clueApiUrl string
- clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", artcleId)
- fmt.Println(clueApiUrl)
- authorization := utils.ApiAuthorization
- body, err := PublicGetDate(clueApiUrl, authorization)
- if err != nil {
- fmt.Println(err)
- return
- }
- var articleResultDate models.ArticleDetailResultApi
- err = json.Unmarshal(body, &articleResultDate)
- if err != nil {
- fmt.Println("Getres.PublicGetDate Err:", err.Error())
- return err
- }
- item := new(models.CygxShanghaiCompanyLog)
- item.CreateTime = time.Now()
- item.Url = clueApiUrl
- item.Body = ""
- item.Result = string(body)
- articleResult := articleResultDate.Data
- exitMap := make(map[int]int)
- categoryIdMap := make(map[int]int)
- classMap := make(map[int]int)
- reportMap := make(map[int]int)
- summaryMap := make(map[int]int)
- listMap, err := models.GetArticleApiMap()
- if err != nil {
- fmt.Println("GetlistMap Err:", err.Error())
- return err
- }
-
- for _, v := range listMap {
- exitMap[v.SeriesId] = v.OldId
- categoryIdMap[v.SeriesId] = v.OldIdMap
- if v.IsClass == 1 {
- classMap[v.OldId] = 1
- }
- if v.IsReport == 1 {
- reportMap[v.OldId] = 1
- }
- if v.IsSummary == 1 {
- summaryMap[v.OldId] = 1
- }
- }
- var list []*models.Tactics2
- var listArticleData []*models.CygxArticleData
- var listAuthor []*models.CygxArticleAuthor
-
- if articleResult.TypeId == 9 || articleResult.PublishArea != "all" {
-
- err = models.UpdateArticlePublish(artcleId, 0)
- if err != nil {
- fmt.Println("UpdateArticlePublish Err:", err.Error())
- return err
- }
- UpdateArticleResourceData(artcleId)
- return
- }
- var cover string
- if articleResult.Series.Name == "图解市场" {
- cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
- } else if articleResult.Series.Name == "行业深度" {
- cover = articleResult.Cover
- }
- fmt.Println(cover)
-
-
- if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
- 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)
- item := new(models.Tactics2)
- itemArticleData := new(models.CygxArticleData)
- itemArticleData.ArticleId = articleResult.ArticleId
- itemArticleData.Cover = articleResult.Cover
- itemArticleData.CreateTime = time.Now()
- listArticleData = append(listArticleData, itemArticleData)
- itemAuthor := new(models.CygxArticleAuthor)
- item.ArticleId = articleResult.ArticleId
- item.Title = articleResult.Title
- item.TitleEn = articleResult.TitleEn
- item.File = articleResult.File
- if articleResult.Frequency == "日度" {
- item.UpdateFrequency = "daily"
- } else if articleResult.Frequency == "周度" {
- item.UpdateFrequency = "weekly"
- } else if articleResult.Frequency == "月度" {
- item.UpdateFrequency = "monthly"
- } else if articleResult.Frequency == "季度" {
- item.UpdateFrequency = "quarterly"
- } else if articleResult.Frequency == "年度" {
- item.UpdateFrequency = "yearly"
- } else {
- item.UpdateFrequency = "unknow"
- }
- item.CreateDate = articleResult.CreateDate
- item.PublishDate = articleResult.PublishDate.Add(time.Hour * 8)
- item.PublishStatus = 1
- item.Body = articleResult.Content.Body
- item.Abstract = articleResult.Content.Abstract
- item.Annotation = articleResult.Content.Annotation
- item.CategoryName = articleResult.Industry.Name
- item.CategoryId = categoryIdMap[articleResult.SeriesId]
- item.CategoryIdTwo = exitMap[articleResult.SeriesId]
- item.SubCategoryName = articleResult.Series.Name
- item.Cover = cover
- fmt.Println("item.CategoryIdTwo", item.CategoryIdTwo)
- fmt.Println("item.CategoryId", item.CategoryId)
- {
-
- if articleResult.Field.Name == "宏观利率" {
- item.CategoryId = 10070
- item.CategoryIdTwo = item.CategoryId
- }
- if articleResult.Field.Name == "信用" {
- item.CategoryId = 10082
- item.CategoryIdTwo = item.CategoryId
- }
- }
- if len(articleResult.Stock) > 0 {
- var stock string
- for _, vS := range articleResult.Stock {
- stock += vS + "/"
- }
- stock = strings.TrimRight(stock, "/")
- item.Stock = stock
- }
- item.FieldName = articleResult.Field.Name
- item.TypeName = articleResult.Type.Name
- item.UpdateDate = articleResult.UpdateDate
- item.CeLueFieldId = articleResult.Field.Id
- list = append(list, item)
- itemAuthor.ArticleId = articleResult.ArticleId
- itemAuthor.Name = articleResult.Author.Name
- itemAuthor.Mobile = articleResult.Author.PhoneNumber
- fmt.Println(articleResult.Cover)
- listAuthor = append(listAuthor, itemAuthor)
- } else {
-
-
-
-
-
-
-
-
- return
- }
- fmt.Println("同步文章条数:", len(list))
- listCustomArticle, err := models.GetCustomArticleId()
- if err != nil {
- fmt.Println("GetTacticsList Err:", err.Error())
- return err
- }
- listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull()
- if errMatch != nil {
- fmt.Println("GetTacticsList Err:", errMatch.Error())
- return err
- }
-
-
-
-
- fmt.Println("list len:", len(list))
- noSummaryArticleIds := ""
- listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
- for k, v := range list {
-
- matchTypeName := ""
- for _, vMatch := range listGetMatchTypeName {
- if v.CategoryId == vMatch.CategoryId {
- matchTypeName = vMatch.MatchTypeName
- }
- }
-
-
-
-
- if v.TypeName == "纪要" {
- v.IsSummary = 1
- }
-
- for _, vArt := range listNoSummaryArticleIds {
- vArtInt, _ := strconv.Atoi(vArt)
- if v.ArticleId == vArtInt {
- v.IsSummary = 0
- }
- }
- if _, has := reportMap[v.CategoryIdTwo]; has {
- v.IsReport = 1
- if _, ok := classMap[v.CategoryIdTwo]; ok {
- v.IsClass = 1
- v.ReportType = 1
- } else {
- v.ReportType = 2
- }
- }
- v.Department = "弘则权益研究"
-
- if v.ArticleId < 0 {
- fmt.Println("AddCygxArticle Err:")
- return err
- }
- var count int
- count, err = models.GetArticleCountById(v.ArticleId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- fmt.Println("AddCygxArticle Err:", err.Error())
- return err
- }
- v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
- expertNumStr, expertContentStr, interviewDateStr, _, bodyReturn := BodyAnalysis2(v.Body)
- if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
- v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
- v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
- v.Body = strings.Replace(v.Body, "):", "", -1)
- }
- var titleNew string
- titleNew = v.Title
-
- if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
- if v.UpdateFrequency == "daily" {
- var daystr string
- daystr = strconv.Itoa(v.PublishDate.Day())
- if len(daystr) == 1 {
- daystr = "0" + daystr
- }
- titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
- } else if v.UpdateFrequency == "weekly" {
- titleNew = v.Title + utils.WeekByDate(v.PublishDate)
- }
- }
- if v.CategoryId == 80 {
- titleNew = v.Title + utils.WeekByDate(v.PublishDate)
- }
-
- if articleResult.Type.Name == "综述报告" {
- detailCategory, err := models.GetdetailByCategoryIdLyjh(v.CategoryIdTwo)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- v.CategoryId = detailCategory.CategoryId
- v.IsSummary = 0
- }
- if count > 0 {
- fmt.Println(k, v.ArticleId, "edit")
- bodyText, _ := GetReportContentTextSubNew(v.Body)
- var isCustom bool
- updateParams := make(map[string]interface{})
-
- updateParams["Title"] = titleNew
- updateParams["TitleEn"] = v.TitleEn
- updateParams["UpdateFrequency"] = v.UpdateFrequency
- updateParams["CreateDate"] = v.CreateDate
- updateParams["PublishDate"] = v.PublishDate
-
- updateParams["Body"] = html.EscapeString(bodyReturn)
- updateParams["BodyText"] = bodyText
- updateParams["Abstract"] = html.EscapeString(v.Abstract)
- updateParams["CategoryName"] = v.CategoryName
- for _, vCustom := range listCustomArticle {
- if v.ArticleId == vCustom.ArticleId {
- fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
- isCustom = true
- }
- }
- if isCustom == false {
- updateParams["CategoryId"] = v.CategoryId
- updateParams["MatchTypeName"] = matchTypeName
- updateParams["IsSummary"] = v.IsSummary
- updateParams["IsReport"] = v.IsReport
- updateParams["ReportType"] = v.ReportType
- updateParams["SubCategoryName"] = v.SubCategoryName
- }
-
- updateParams["PublishStatus"] = 1
- updateParams["ExpertBackground"] = expertContentStr
- updateParams["ExpertNumber"] = expertNumStr
- updateParams["InterviewDate"] = interviewDateStr
-
- v.Department = "弘则权益研究"
- updateParams["Department"] = v.Department
- updateParams["FileLink"] = v.File
- updateParams["Stock"] = v.Stock
- updateParams["FieldName"] = v.FieldName
- updateParams["Annotation"] = v.Annotation
- updateParams["TypeName"] = v.TypeName
- updateParams["ModifyTimeByCl"] = v.UpdateDate
- updateParams["CeLueFieldId"] = v.CeLueFieldId
- updateParams["Cover"] = v.Cover
- whereParam := map[string]interface{}{"article_id": v.ArticleId}
- err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
- if err != nil {
- fmt.Println("UpdateByExpr Err:" + err.Error())
- return err
- }
- fmt.Println("v.ReportType", v.ReportType)
- if v.ReportType == 2 {
- var subjectStr string
- var industrialManagementIdStr string
- var industrialSubjectIdStr string
- sliceSubjects := strings.Split(v.Stock, "/")
- mapManagementForSubject := make(map[string]string)
- mapIndustrialId := make(map[int]int)
- if len(sliceSubjects) > 0 {
- for _, vSubject := range sliceSubjects {
- sliceKuohao := strings.Split(vSubject, "(")
- sliceXiahuaxian := strings.Split(sliceKuohao[0], "-")
- subject := sliceXiahuaxian[0]
- subjectStr += "'" + subject + "',"
- }
-
- detailCategory, errCategory := models.GetdetailByCategoryIdOne(v.CategoryId)
- if errCategory != nil {
- fmt.Println("GetdetailByCategoryIdOne Err:", err.Error())
- return err
- }
- subjectStr = strings.TrimRight(subjectStr, ",")
- if subjectStr != "" {
- listIndustrial, err := models.GetIndustrialManagementForSubjecName(subjectStr, detailCategory.ChartPermissionId)
- if err != nil {
- fmt.Println("GetIndustrialManagementForSubjecName Err:", err.Error())
- return err
- }
- subjectStr = strings.Replace(subjectStr, "','", "】【", -1)
- subjectStr = strings.Replace(subjectStr, "'", "", -1)
- subjectStr = "【" + subjectStr + "】"
- if len(listIndustrial) > 0 {
- for _, vIndustrial := range listIndustrial {
- if _, ok := mapIndustrialId[vIndustrial.IndustrialManagementId]; !ok {
- industrialManagementIdStr += strconv.Itoa(vIndustrial.IndustrialManagementId) + ","
- }
- mapIndustrialId[vIndustrial.IndustrialManagementId] = vIndustrial.IndustrialManagementId
- industrialSubjectIdStr += strconv.Itoa(vIndustrial.IndustrialSubjectId) + ","
- mapManagementForSubject[vIndustrial.IndustryName] += vIndustrial.SubjectName + "/"
- if vIndustrial.LayoutTime == "0000-00-00 00:00:00" {
- go models.UpdateIndustrialManagementLayoutTime(v.PublishDate.AddDate(0, 0, -10).Format(utils.FormatDateTime), vIndustrial.IndustrialManagementId)
- }
- }
- industrialManagementIdStr = strings.TrimRight(industrialManagementIdStr, ",")
- industrialSubjectIdStr = strings.TrimRight(industrialSubjectIdStr, ",")
- if industrialManagementIdStr != "" {
- err = models.ReportArticleClassificationEditNew(artcleId, industrialManagementIdStr, v.ArticleId, industrialSubjectIdStr)
- if err != nil {
- fmt.Println("ReportArticleClassificationEditNew Err:", err.Error())
- return err
- }
- }
- }
-
- }
- }
- }
- }
- }
- AddComprehensiveIndustrialSource("Hz", artcleId)
- AddCygxReportMappingCategoryGroupByArticleId(artcleId)
- return err
- }
|