edb_info.go 151 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/company"
  7. "eta/eta_api/models/data_manage"
  8. "eta/eta_api/models/data_manage/request"
  9. "eta/eta_api/models/data_manage/response"
  10. "eta/eta_api/models/system"
  11. "eta/eta_api/services/alarm_msg"
  12. "eta/eta_api/services/data"
  13. "eta/eta_api/services/data_stat"
  14. "eta/eta_api/services/elastic"
  15. etaTrialService "eta/eta_api/services/eta_trial"
  16. "eta/eta_api/utils"
  17. "fmt"
  18. "github.com/rdlucklib/rdluck_tools/paging"
  19. "strconv"
  20. "strings"
  21. "sync"
  22. "time"
  23. )
  24. // EdbInfoController 数据管理
  25. type EdbInfoController struct {
  26. controllers.BaseAuthController
  27. }
  28. // EdbInfoSearch
  29. // @Title 新增指标-查询指标信息接口
  30. // @Description 新增指标-查询指标信息接口
  31. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  32. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  33. // @Param EdbCode query string false "指标编码/指标代码"
  34. // @Param StockCode query string false "证券代码"
  35. // @Success 200 {object} data_manage.EdbInfoSearchResp
  36. // @router /edb_info/search [get]
  37. func (this *EdbInfoController) EdbInfoSearch() {
  38. br := new(models.BaseResponse).Init()
  39. defer func() {
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. source, _ := this.GetInt("Source")
  44. edbCode := this.GetString("EdbCode")
  45. edbCode = strings.Trim(edbCode, "\t")
  46. edbCode = strings.Trim(edbCode, " ")
  47. edbCode = strings.Replace(edbCode, "\t", "", -1)
  48. subSource, _ := this.GetInt("SubSource")
  49. stockCode := this.GetString("StockCode")
  50. if source <= 0 {
  51. br.Msg = "无效的数据来源"
  52. return
  53. }
  54. if edbCode == "" {
  55. br.Msg = "请输入指标ID"
  56. return
  57. }
  58. //如果是彭博财务指标,那么需要传入客户code
  59. if source == utils.DATA_SOURCE_PB_FINANCE {
  60. companyCode := this.GetString("CompanyCode")
  61. companyCode = strings.Trim(companyCode, "\t")
  62. companyCode = strings.Trim(companyCode, " ")
  63. companyCode = strings.Replace(companyCode, "\t", "", -1)
  64. // 如果财务数据,那么需要拼接上客户code
  65. edbCode = companyCode + "&&" + edbCode
  66. }
  67. resp := new(data_manage.EdbInfoSearchResp)
  68. //判断指标是否存在
  69. var item *data_manage.EdbInfo
  70. var err error
  71. if source == utils.DATA_SOURCE_GL {
  72. // 如果是钢联的话,那么就先判断是不是存在钢联化工
  73. item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, edbCode)
  74. if err != nil {
  75. if err.Error() != utils.ErrNoRow() {
  76. br.Msg = "获取失败"
  77. br.ErrMsg = "获取失败,Err:" + err.Error()
  78. return
  79. }
  80. }
  81. err = nil
  82. if item != nil {
  83. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  84. } else {
  85. // 判断是不是已经在钢联这边已经存在了
  86. item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_GL, edbCode)
  87. if err != nil {
  88. if err.Error() != utils.ErrNoRow() {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "获取失败,Err:" + err.Error()
  91. return
  92. }
  93. }
  94. err = nil
  95. // 如果在钢联来源也没找到,那么就需要再判断下是否处于 《钢联化工》 数据源里面
  96. if item == nil {
  97. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
  98. if err != nil {
  99. if err.Error() != utils.ErrNoRow() {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取失败,Err:" + err.Error()
  102. return
  103. }
  104. }
  105. err = nil
  106. if tmpInfo != nil {
  107. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  108. }
  109. }
  110. }
  111. }
  112. if item == nil {
  113. item, err = data_manage.GetEdbInfoByEdbCode(source, edbCode)
  114. }
  115. if err != nil {
  116. if err.Error() != utils.ErrNoRow() {
  117. br.Msg = "获取失败"
  118. br.ErrMsg = "获取失败,Err:" + err.Error()
  119. return
  120. }
  121. }
  122. var isAdd bool
  123. var isInEdb bool //是否在指标库中
  124. if item != nil && item.EdbInfoId > 0 {
  125. isInEdb = true //在指标库中
  126. resp.Status = 1
  127. searchItem := new(data_manage.EdbInfoSearch)
  128. searchItem.EdbCode = item.EdbCode
  129. searchItem.StartDate = item.StartDate
  130. searchItem.EndDate = item.EndDate
  131. searchItem.EdbName = item.EdbName
  132. resp.SearchItem = searchItem
  133. //查询目录
  134. resultList, _ := data_manage.GetClassifyAllByClassifyId(item.ClassifyId)
  135. resp.ClassifyList = resultList
  136. // 查询该指标是否有权限
  137. obj := data_manage.EdbInfoNoPermissionAdmin{}
  138. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, item.EdbInfoId)
  139. if err != nil && err.Error() != utils.ErrNoRow() {
  140. br.Msg = "获取失败"
  141. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  142. return
  143. }
  144. if conf != nil {
  145. resp.Status = 3
  146. }
  147. } else {
  148. //dateNow := time.Now()
  149. //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDate)
  150. searchItem := new(data_manage.EdbInfoSearch)
  151. if source == utils.DATA_SOURCE_THS {
  152. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, utils.EDB_DATA_LIMIT)
  153. if err != nil && err.Error() != utils.ErrNoRow() {
  154. br.Msg = "获取失败"
  155. br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
  156. return
  157. }
  158. fmt.Println("ths len:", len(dataItems))
  159. if len(dataItems) > 0 {
  160. fmt.Println("ths data exist")
  161. searchItem.EdbCode = edbCode
  162. minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
  163. if err != nil {
  164. br.Msg = "获取失败"
  165. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  166. return
  167. }
  168. searchItem.DataList = dataItems
  169. searchItem.StartDate = minDate
  170. searchItem.EndDate = maxDate
  171. } else {
  172. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  173. //searchItem, err = data.GetEdbDataByThs(edbCode, startDate, endDate)
  174. //if err != nil {
  175. // br.Msg = "获取失败"
  176. // br.ErrMsg = "获取失败,Err:" + err.Error()
  177. // return
  178. //}
  179. respItem, err := data.AddEdbData(source, edbCode)
  180. if err != nil {
  181. br.Msg = "获取失败"
  182. br.ErrMsg = "获取失败,Err:" + err.Error()
  183. return
  184. }
  185. if respItem.Ret != 200 {
  186. br.Msg = "未搜索到该指标"
  187. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  188. return
  189. }
  190. isAdd = true
  191. }
  192. } else if source == utils.DATA_SOURCE_WIND {
  193. fmt.Println("subSource:", subSource)
  194. if subSource == utils.DATA_SUB_SOURCE_EDB {
  195. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_WIND, utils.EDB_DATA_LIMIT)
  196. if err != nil && err.Error() != utils.ErrNoRow() {
  197. br.Msg = "获取失败"
  198. br.ErrMsg = "获取Wind已存在信息失败,Err:" + err.Error()
  199. return
  200. }
  201. fmt.Println("wind dataItems:", len(dataItems))
  202. if len(dataItems) > 0 {
  203. searchItem.EdbCode = edbCode
  204. minDate, maxDate, err := data_manage.GetEdbDataWindMaxOrMinDate(edbCode)
  205. if err != nil {
  206. br.Msg = "获取失败"
  207. br.ErrMsg = "获取wind日期信息失败,Err:" + err.Error()
  208. return
  209. }
  210. searchItem.DataList = dataItems
  211. searchItem.StartDate = minDate
  212. searchItem.EndDate = maxDate
  213. } else {
  214. //endDate := dateNow.Format(utils.FormatDate)
  215. //searchItem, err = data.GetEdbDataByWind(edbCode, startDate, endDate)
  216. //if err != nil {
  217. // br.Msg = "获取失败"
  218. // br.ErrMsg = "wind 获取失败,Err:" + err.Error()
  219. // return
  220. //}
  221. respItem, err := data.AddEdbData(source, edbCode)
  222. if err != nil {
  223. br.Msg = "获取失败"
  224. br.ErrMsg = "获取失败,Err:" + err.Error()
  225. return
  226. }
  227. if respItem.Ret != 200 {
  228. if respItem.Ret == 421 {
  229. br.Msg = "该渠道已超过添加上限"
  230. } else if respItem.Ret == 4052 {
  231. br.Msg = "该指标已下架"
  232. } else {
  233. br.Msg = "未搜索到该指标"
  234. }
  235. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  236. return
  237. }
  238. isAdd = true
  239. }
  240. } else if subSource == utils.DATA_SUB_SOURCE_DATE {
  241. if stockCode == "" {
  242. br.Msg = "请输入证券代码"
  243. return
  244. }
  245. if edbCode == "" {
  246. br.Msg = "请输入指标代码"
  247. return
  248. }
  249. respItem, err := data.AddEdbDataWindWsd(source, stockCode, edbCode)
  250. if err != nil {
  251. br.Msg = "获取失败"
  252. br.ErrMsg = "获取失败,Err:" + err.Error()
  253. return
  254. }
  255. if respItem.Ret != 200 {
  256. if respItem.Ret == 421 {
  257. br.Msg = "该渠道已超过添加上限"
  258. } else if respItem.Ret == 4052 {
  259. br.Msg = "该指标已下架"
  260. } else {
  261. br.Msg = "未搜索到该指标"
  262. }
  263. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  264. return
  265. }
  266. isAdd = true
  267. } else {
  268. br.Msg = "无效的渠道来源"
  269. return
  270. }
  271. } else if source == utils.DATA_SOURCE_PB || source == utils.DATA_SOURCE_PB_FINANCE {
  272. fmt.Println("pb data exist")
  273. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  274. if err != nil && err.Error() != utils.ErrNoRow() {
  275. br.Msg = "获取失败"
  276. br.ErrMsg = "获取Pb已存在信息失败,Err:" + err.Error()
  277. return
  278. }
  279. fmt.Println("pb dataItems:", len(dataItems))
  280. if len(dataItems) > 0 {
  281. searchItem.EdbCode = edbCode
  282. minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(edbCode)
  283. if err != nil {
  284. br.Msg = "获取失败"
  285. br.ErrMsg = "获取Pb日期信息失败,Err:" + err.Error()
  286. return
  287. }
  288. searchItem.DataList = dataItems
  289. searchItem.StartDate = minDate
  290. searchItem.EndDate = maxDate
  291. } else {
  292. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  293. //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDateUnSpace)
  294. //searchItem, err = data.GetEdbDataByPb(edbCode, startDate, endDate)
  295. //if err != nil {
  296. // br.Msg = "获取失败"
  297. // br.ErrMsg = "彭博数据获取失败,Err:" + err.Error()
  298. // return
  299. //}
  300. respItem, err := data.AddEdbData(source, edbCode)
  301. if err != nil {
  302. br.Msg = "获取失败"
  303. br.ErrMsg = "获取失败,Err:" + err.Error()
  304. return
  305. }
  306. if respItem.Ret != 200 {
  307. br.Msg = "未搜索到该指标"
  308. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  309. return
  310. }
  311. isAdd = true
  312. }
  313. } else if source == utils.DATA_SOURCE_MANUAL { //手工数据指标
  314. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_MANUAL, utils.EDB_DATA_LIMIT)
  315. if err != nil && err.Error() != utils.ErrNoRow() {
  316. br.Msg = "获取失败"
  317. br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
  318. return
  319. }
  320. fmt.Println("ths len:", len(dataItems))
  321. if len(dataItems) > 0 {
  322. fmt.Println("ths data exist")
  323. searchItem.EdbCode = edbCode
  324. minDate, maxDate, err := data_manage.GetEdbDataManualMaxOrMinDate(edbCode)
  325. if err != nil {
  326. br.Msg = "获取失败"
  327. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  328. return
  329. }
  330. searchItem.DataList = dataItems
  331. searchItem.StartDate = minDate
  332. searchItem.EndDate = maxDate
  333. } else {
  334. //searchItem, err = data_manage.GetEdbDataByManual(edbCode, startDate, endDate)
  335. //if err != nil {
  336. // br.Msg = "获取失败"
  337. // br.ErrMsg = "获取失败,Err:" + err.Error()
  338. // return
  339. //}
  340. respItem, err := data.AddEdbData(source, edbCode)
  341. if err != nil {
  342. br.Msg = "获取失败"
  343. br.ErrMsg = "获取失败,Err:" + err.Error()
  344. return
  345. }
  346. if respItem.Ret != 200 {
  347. br.Msg = "未搜索到该指标"
  348. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  349. return
  350. }
  351. isAdd = true
  352. }
  353. //获取指标信息
  354. manualInfo, err := models.GetEdbinfoByTradeCode(edbCode)
  355. if err != nil && err.Error() != utils.ErrNoRow() {
  356. br.Msg = "获取失败"
  357. br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
  358. return
  359. }
  360. if manualInfo != nil {
  361. searchItem.Frequency = manualInfo.Frequency
  362. searchItem.Unit = manualInfo.Unit
  363. searchItem.EdbName = manualInfo.SecName
  364. }
  365. } else if source == utils.DATA_SOURCE_LZ {
  366. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LZ, utils.EDB_DATA_LIMIT)
  367. if err != nil && err.Error() != utils.ErrNoRow() {
  368. br.Msg = "获取失败"
  369. br.ErrMsg = "获取隆众已存在信息失败,Err:" + err.Error()
  370. return
  371. }
  372. fmt.Println("ths len:", len(dataItems))
  373. if len(dataItems) > 0 {
  374. fmt.Println("ths data exist")
  375. searchItem.EdbCode = edbCode
  376. minDate, maxDate, err := data_manage.GetEdbDataLzMaxOrMinDate(edbCode)
  377. if err != nil {
  378. br.Msg = "获取失败"
  379. br.ErrMsg = "获取隆众日期信息失败,Err:" + err.Error()
  380. return
  381. }
  382. searchItem.DataList = dataItems
  383. searchItem.StartDate = minDate
  384. searchItem.EndDate = maxDate
  385. } else {
  386. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  387. //searchItem, err = data_manage.GetEdbDataByLz(edbCode, startDate, endDate)
  388. //if err != nil {
  389. // br.Msg = "获取失败"
  390. // br.ErrMsg = "获取隆众数据失败,Err:" + err.Error()
  391. // return
  392. //}
  393. respItem, err := data.AddEdbData(source, edbCode)
  394. if err != nil {
  395. br.Msg = "获取失败"
  396. br.ErrMsg = "获取失败,Err:" + err.Error()
  397. return
  398. }
  399. if respItem.Ret != 200 {
  400. br.Msg = "未搜索到该指标"
  401. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  402. return
  403. }
  404. isAdd = true
  405. }
  406. //获取指标信息
  407. lzInfo, err := data_manage.GetLongzhongSurveyProductByCode(edbCode)
  408. if err != nil && err.Error() != utils.ErrNoRow() {
  409. br.Msg = "获取失败"
  410. br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
  411. return
  412. }
  413. if lzInfo != nil {
  414. frequency := lzInfo.Frequency
  415. var frequencyStr string
  416. if frequency == 1 {
  417. frequencyStr = "日度"
  418. } else if frequency == 2 {
  419. frequencyStr = "周度"
  420. } else if frequency == 3 {
  421. frequencyStr = "月度"
  422. } else if frequency == 4 {
  423. frequencyStr = "季度"
  424. } else if frequency == 5 {
  425. frequencyStr = "年度"
  426. } else if frequency == 99 {
  427. frequencyStr = "无固定频率"
  428. }
  429. searchItem.Frequency = frequencyStr
  430. searchItem.Unit = lzInfo.UnitName
  431. searchItem.EdbName = lzInfo.SampleName + lzInfo.BreedName + lzInfo.QuotaName
  432. }
  433. } else if source == utils.DATA_SOURCE_YS { //有色网
  434. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.EDB_DATA_LIMIT)
  435. if err != nil && err.Error() != utils.ErrNoRow() {
  436. br.Msg = "获取失败"
  437. br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
  438. return
  439. }
  440. fmt.Println("dataItems:", len(dataItems))
  441. if len(dataItems) > 0 {
  442. searchItem.EdbCode = edbCode
  443. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  444. if err != nil {
  445. br.Msg = "获取失败"
  446. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  447. return
  448. }
  449. searchItem.DataList = dataItems
  450. searchItem.StartDate = minDate
  451. searchItem.EndDate = maxDate
  452. } else {
  453. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  454. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  455. //if err != nil {
  456. // br.Msg = "获取失败"
  457. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  458. // return
  459. //}
  460. //if searchItem.StartDate == "" {
  461. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  462. // searchItem.StartDate = minDate
  463. // searchItem.EndDate = maxDate
  464. //}
  465. respItem, err := data.AddEdbData(source, edbCode)
  466. if err != nil {
  467. br.Msg = "获取失败"
  468. br.ErrMsg = "获取失败,Err:" + err.Error()
  469. return
  470. }
  471. if respItem.Ret != 200 {
  472. br.Msg = "未搜索到该指标"
  473. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  474. return
  475. }
  476. isAdd = true
  477. }
  478. //获取指标信息
  479. smmInfo, err := data_manage.GetBaseFromSmmIndexByIndexCode(edbCode)
  480. if err != nil && err.Error() != utils.ErrNoRow() {
  481. br.Msg = "获取失败"
  482. br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
  483. return
  484. }
  485. if smmInfo != nil {
  486. searchItem.Frequency = smmInfo.Frequency
  487. searchItem.Unit = smmInfo.Unit
  488. searchItem.EdbName = smmInfo.IndexName
  489. }
  490. } else if source == utils.DATA_SOURCE_GL { //钢联
  491. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  492. if err != nil && err.Error() != utils.ErrNoRow() {
  493. br.Msg = "获取失败"
  494. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  495. return
  496. }
  497. if len(dataItems) > 0 {
  498. searchItem.EdbCode = edbCode
  499. minDate, maxDate, err := data_manage.GetEdbDataGlMaxOrMinDate(edbCode)
  500. if err != nil {
  501. br.Msg = "获取失败"
  502. br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
  503. return
  504. }
  505. searchItem.DataList = dataItems
  506. searchItem.StartDate = minDate
  507. searchItem.EndDate = maxDate
  508. } else {
  509. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  510. //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
  511. //if err != nil {
  512. // br.Msg = "获取失败"
  513. // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
  514. // return
  515. //}
  516. respItem, err := data.AddEdbData(source, edbCode)
  517. if err != nil {
  518. br.Msg = "获取失败"
  519. br.ErrMsg = "获取失败,Err:" + err.Error()
  520. return
  521. }
  522. if respItem.Ret != 200 {
  523. br.Msg = "未搜索到该指标"
  524. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  525. return
  526. }
  527. isAdd = true
  528. }
  529. //获取指标信息
  530. glInfo, err := data_manage.GetGlIndexByCode(edbCode)
  531. if err != nil && err.Error() != utils.ErrNoRow() {
  532. br.Msg = "获取失败"
  533. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  534. return
  535. }
  536. if glInfo != nil {
  537. searchItem.Frequency = glInfo.FrequencyName
  538. searchItem.Unit = glInfo.UnitName
  539. searchItem.EdbName = glInfo.IndexName
  540. }
  541. } else if source == utils.DATA_SOURCE_ZZ { //郑商所
  542. var suffix string
  543. if strings.Contains(edbCode, "deal") {
  544. suffix = "deal"
  545. } else if strings.Contains(edbCode, "buy") {
  546. suffix = "buy"
  547. } else if strings.Contains(edbCode, "sold") {
  548. suffix = "sold"
  549. } else {
  550. br.Msg = "未搜索到该指标"
  551. br.ErrMsg = "指标code异常"
  552. return
  553. }
  554. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  555. if err != nil && err.Error() != utils.ErrNoRow() {
  556. br.Msg = "获取失败"
  557. br.ErrMsg = "获取郑商所已存在信息失败,Err:" + err.Error()
  558. return
  559. }
  560. if len(dataItems) > 0 {
  561. searchItem.EdbCode = edbCode
  562. minDate, maxDate, err := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
  563. if err != nil {
  564. br.Msg = "获取失败"
  565. br.ErrMsg = "获取郑商所日期信息失败,Err:" + err.Error()
  566. return
  567. }
  568. searchItem.DataList = dataItems
  569. searchItem.StartDate = minDate
  570. searchItem.EndDate = maxDate
  571. } else {
  572. //searchItem, err = data_manage.GetEdbDataByZz(edbCode, suffix, startDate, "")
  573. //if err != nil {
  574. // br.Msg = "获取失败"
  575. // br.ErrMsg = "获取失败,GetEdbDataByZz Err:" + err.Error()
  576. // return
  577. //}
  578. //if searchItem.StartDate == "" {
  579. // minDate, maxDate, _ := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
  580. // searchItem.StartDate = minDate
  581. // searchItem.EndDate = maxDate
  582. //}
  583. respItem, err := data.AddEdbData(source, edbCode)
  584. if err != nil {
  585. br.Msg = "获取失败"
  586. br.ErrMsg = "获取失败,Err:" + err.Error()
  587. return
  588. }
  589. if respItem.Ret != 200 {
  590. br.Msg = "未搜索到该指标"
  591. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  592. return
  593. }
  594. isAdd = true
  595. }
  596. //获取指标信息
  597. allInfo, err := data_manage.GetBaseInfoFromZhengzhouByIndexCode(edbCode, suffix)
  598. if err != nil && err.Error() != utils.ErrNoRow() {
  599. br.Msg = "获取失败"
  600. br.ErrMsg = "获取郑商所指标详情失败,Err:" + err.Error()
  601. return
  602. }
  603. var zzInfo *data_manage.BaseInfoFromZz
  604. if allInfo != nil {
  605. zzInfo = allInfo[0]
  606. }
  607. if zzInfo != nil {
  608. searchItem.Frequency = "日度"
  609. searchItem.Unit = "手"
  610. if suffix == "deal" {
  611. searchItem.EdbName = zzInfo.DealName
  612. } else if suffix == "buy" {
  613. searchItem.EdbName = zzInfo.BuyName
  614. } else {
  615. searchItem.EdbName = zzInfo.SoldName
  616. }
  617. }
  618. } else if source == utils.DATA_SOURCE_DL { //大商所
  619. var suffix string
  620. if strings.Contains(edbCode, "deal") {
  621. suffix = "deal"
  622. } else if strings.Contains(edbCode, "buy") {
  623. suffix = "buy"
  624. } else if strings.Contains(edbCode, "sold") {
  625. suffix = "sold"
  626. } else {
  627. br.Msg = "未搜索到该指标"
  628. br.ErrMsg = "指标code异常"
  629. return
  630. }
  631. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  632. if err != nil && err.Error() != utils.ErrNoRow() {
  633. br.Msg = "获取失败"
  634. br.ErrMsg = "获取大商所已存在信息失败,Err:" + err.Error()
  635. return
  636. }
  637. if len(dataItems) > 0 {
  638. searchItem.EdbCode = edbCode
  639. minDate, maxDate, err := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
  640. if err != nil {
  641. br.Msg = "获取失败"
  642. br.ErrMsg = "获取大商所日期信息失败,Err:" + err.Error()
  643. return
  644. }
  645. searchItem.DataList = dataItems
  646. searchItem.StartDate = minDate
  647. searchItem.EndDate = maxDate
  648. } else {
  649. //searchItem, err = data_manage.GetEdbDataByDl(edbCode, suffix, startDate, "")
  650. //if err != nil {
  651. // br.Msg = "获取失败"
  652. // br.ErrMsg = "获取失败,GetEdbDataByDl Err:" + err.Error()
  653. // return
  654. //}
  655. //if searchItem.StartDate == "" {
  656. // minDate, maxDate, _ := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
  657. // searchItem.StartDate = minDate
  658. // searchItem.EndDate = maxDate
  659. //}
  660. respItem, err := data.AddEdbData(source, edbCode)
  661. if err != nil {
  662. br.Msg = "获取失败"
  663. br.ErrMsg = "获取失败,Err:" + err.Error()
  664. return
  665. }
  666. if respItem.Ret != 200 {
  667. br.Msg = "未搜索到该指标"
  668. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  669. return
  670. }
  671. isAdd = true
  672. }
  673. //获取指标信息
  674. allInfo, err := data_manage.GetBaseInfoFromDalianByIndexCode(edbCode, suffix)
  675. if err != nil && err.Error() != utils.ErrNoRow() {
  676. br.Msg = "获取失败"
  677. br.ErrMsg = "获取大商所指标详情失败,Err:" + err.Error()
  678. return
  679. }
  680. var dlInfo *data_manage.BaseInfoFromDl
  681. if allInfo != nil {
  682. dlInfo = allInfo[0]
  683. }
  684. if dlInfo != nil {
  685. searchItem.Frequency = "日度"
  686. searchItem.Unit = "手"
  687. if suffix == "deal" {
  688. searchItem.EdbName = dlInfo.DealName
  689. } else if suffix == "buy" {
  690. searchItem.EdbName = dlInfo.BuyName
  691. } else {
  692. searchItem.EdbName = dlInfo.SoldName
  693. }
  694. }
  695. } else if source == utils.DATA_SOURCE_SH { //上期所
  696. var suffix string
  697. if strings.Contains(edbCode, "deal") {
  698. suffix = "deal"
  699. } else if strings.Contains(edbCode, "buy") {
  700. suffix = "buy"
  701. } else if strings.Contains(edbCode, "sold") {
  702. suffix = "sold"
  703. } else {
  704. br.Msg = "未搜索到该指标"
  705. br.ErrMsg = "指标code异常"
  706. return
  707. }
  708. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  709. if err != nil && err.Error() != utils.ErrNoRow() {
  710. br.Msg = "获取失败"
  711. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  712. return
  713. }
  714. if len(dataItems) > 0 {
  715. searchItem.EdbCode = edbCode
  716. minDate, maxDate, err := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
  717. if err != nil {
  718. br.Msg = "获取失败"
  719. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  720. return
  721. }
  722. searchItem.DataList = dataItems
  723. searchItem.StartDate = minDate
  724. searchItem.EndDate = maxDate
  725. } else {
  726. //searchItem, err = data_manage.GetEdbDataBySh(edbCode, suffix, startDate, "")
  727. //if err != nil {
  728. // br.Msg = "获取失败"
  729. // br.ErrMsg = "获取失败,GetEdbDataBySh Err:" + err.Error()
  730. // return
  731. //}
  732. //if searchItem.StartDate == "" {
  733. // minDate, maxDate, _ := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
  734. // searchItem.StartDate = minDate
  735. // searchItem.EndDate = maxDate
  736. //}
  737. respItem, err := data.AddEdbData(source, edbCode)
  738. if err != nil {
  739. br.Msg = "获取失败"
  740. br.ErrMsg = "获取失败,Err:" + err.Error()
  741. return
  742. }
  743. if respItem.Ret != 200 {
  744. br.Msg = "未搜索到该指标"
  745. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  746. return
  747. }
  748. isAdd = true
  749. }
  750. //获取指标信息
  751. allInfo, err := data_manage.GetBaseInfoFromShByIndexCode(edbCode, suffix)
  752. if err != nil && err.Error() != utils.ErrNoRow() {
  753. br.Msg = "获取失败"
  754. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  755. return
  756. }
  757. var shInfo *data_manage.BaseInfoFromSh
  758. if allInfo != nil {
  759. shInfo = allInfo[0]
  760. }
  761. if shInfo != nil {
  762. searchItem.Frequency = "日度"
  763. searchItem.Unit = "手"
  764. if suffix == "deal" {
  765. searchItem.EdbName = shInfo.DealName
  766. } else if suffix == "buy" {
  767. searchItem.EdbName = shInfo.BuyName
  768. } else {
  769. searchItem.EdbName = shInfo.SoldName
  770. }
  771. }
  772. } else if source == utils.DATA_SOURCE_CFFEX { //中金所
  773. var suffix string
  774. if strings.Contains(edbCode, "deal") {
  775. suffix = "deal"
  776. } else if strings.Contains(edbCode, "buy") {
  777. suffix = "buy"
  778. } else if strings.Contains(edbCode, "sold") {
  779. suffix = "sold"
  780. } else {
  781. br.Msg = "未搜索到该指标"
  782. br.ErrMsg = "指标code异常"
  783. return
  784. }
  785. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  786. if err != nil && err.Error() != utils.ErrNoRow() {
  787. br.Msg = "获取失败"
  788. br.ErrMsg = "获取中金所已存在信息失败,Err:" + err.Error()
  789. return
  790. }
  791. if len(dataItems) > 0 {
  792. searchItem.EdbCode = edbCode
  793. minDate, maxDate, err := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  794. if err != nil {
  795. br.Msg = "获取失败"
  796. br.ErrMsg = "获取中金所日期信息失败,Err:" + err.Error()
  797. return
  798. }
  799. searchItem.DataList = dataItems
  800. searchItem.StartDate = minDate
  801. searchItem.EndDate = maxDate
  802. } else {
  803. //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
  804. //if err != nil {
  805. // br.Msg = "获取失败"
  806. // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
  807. // return
  808. //}
  809. //if searchItem.StartDate == "" {
  810. // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  811. // searchItem.StartDate = minDate
  812. // searchItem.EndDate = maxDate
  813. //}
  814. respItem, err := data.AddEdbData(source, edbCode)
  815. if err != nil {
  816. br.Msg = "获取失败"
  817. br.ErrMsg = "获取失败,Err:" + err.Error()
  818. return
  819. }
  820. if respItem.Ret != 200 {
  821. br.Msg = "未搜索到该指标"
  822. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  823. return
  824. }
  825. isAdd = true
  826. }
  827. //获取指标信息
  828. allInfo, err := data_manage.GetBaseInfoFromCffexByIndexCode(edbCode, suffix)
  829. if err != nil && err.Error() != utils.ErrNoRow() {
  830. br.Msg = "获取失败"
  831. br.ErrMsg = "获取中金所指标详情失败,Err:" + err.Error()
  832. return
  833. }
  834. var cffexInfo *data_manage.BaseInfoFromCffex
  835. if allInfo != nil {
  836. cffexInfo = allInfo[0]
  837. }
  838. if cffexInfo != nil {
  839. searchItem.Frequency = "日度"
  840. searchItem.Unit = "手"
  841. if suffix == "deal" {
  842. searchItem.EdbName = cffexInfo.DealName
  843. } else if suffix == "buy" {
  844. searchItem.EdbName = cffexInfo.BuyName
  845. } else {
  846. searchItem.EdbName = cffexInfo.SoldName
  847. }
  848. }
  849. } else if source == utils.DATA_SOURCE_SHFE { //上期能源
  850. var suffix string
  851. if strings.Contains(edbCode, "deal") {
  852. suffix = "deal"
  853. } else if strings.Contains(edbCode, "buy") {
  854. suffix = "buy"
  855. } else if strings.Contains(edbCode, "sold") {
  856. suffix = "sold"
  857. } else {
  858. br.Msg = "未搜索到该指标"
  859. br.ErrMsg = "指标code异常"
  860. return
  861. }
  862. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  863. if err != nil && err.Error() != utils.ErrNoRow() {
  864. br.Msg = "获取失败"
  865. br.ErrMsg = "获取上期能源已存在信息失败,Err:" + err.Error()
  866. return
  867. }
  868. if len(dataItems) > 0 {
  869. searchItem.EdbCode = edbCode
  870. minDate, maxDate, err := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
  871. if err != nil {
  872. br.Msg = "获取失败"
  873. br.ErrMsg = "获取上期能源日期信息失败,Err:" + err.Error()
  874. return
  875. }
  876. searchItem.DataList = dataItems
  877. searchItem.StartDate = minDate
  878. searchItem.EndDate = maxDate
  879. } else {
  880. //searchItem, err = data_manage.GetEdbDataByShfe(edbCode, suffix, startDate, "")
  881. //if err != nil {
  882. // br.Msg = "获取失败"
  883. // br.ErrMsg = "获取失败,GetEdbDataByShfe Err:" + err.Error()
  884. // return
  885. //}
  886. //if searchItem.StartDate == "" {
  887. // minDate, maxDate, _ := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
  888. // searchItem.StartDate = minDate
  889. // searchItem.EndDate = maxDate
  890. //}
  891. respItem, err := data.AddEdbData(source, edbCode)
  892. if err != nil {
  893. br.Msg = "获取失败"
  894. br.ErrMsg = "获取失败,Err:" + err.Error()
  895. return
  896. }
  897. if respItem.Ret != 200 {
  898. br.Msg = "未搜索到该指标"
  899. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  900. return
  901. }
  902. isAdd = true
  903. }
  904. //获取指标信息
  905. allInfo, err := data_manage.GetBaseInfoFromShfeByIndexCode(edbCode, suffix)
  906. if err != nil && err.Error() != utils.ErrNoRow() {
  907. br.Msg = "获取失败"
  908. br.ErrMsg = "获取上期能源指标详情失败,Err:" + err.Error()
  909. return
  910. }
  911. var shfeInfo *data_manage.BaseInfoFromShfe
  912. if allInfo != nil {
  913. shfeInfo = allInfo[0]
  914. }
  915. if shfeInfo != nil {
  916. searchItem.Frequency = "日度"
  917. searchItem.Unit = "手"
  918. if suffix == "deal" {
  919. searchItem.EdbName = shfeInfo.DealName
  920. } else if suffix == "buy" {
  921. searchItem.EdbName = shfeInfo.BuyName
  922. } else {
  923. searchItem.EdbName = shfeInfo.SoldName
  924. }
  925. }
  926. } else if source == utils.DATA_SOURCE_GIE { //欧洲天然气
  927. var suffix string
  928. l := len(edbCode)
  929. if strings.Contains(edbCode[l-2:], "GS") {
  930. suffix = "GS"
  931. } else if strings.Contains(edbCode[l-2:], "CF") {
  932. suffix = "CF"
  933. } else if strings.Contains(edbCode[l-1:], "T") {
  934. suffix = "T"
  935. } else if strings.Contains(edbCode[l-2:], "In") {
  936. suffix = "In"
  937. } else if strings.Contains(edbCode[l-3:], "Out") {
  938. suffix = "Out"
  939. } else if strings.Contains(edbCode[l-3:], "WGV") {
  940. suffix = "WGV"
  941. } else if strings.Contains(edbCode[l-2:], "IC") {
  942. suffix = "IC"
  943. } else if strings.Contains(edbCode[l-2:], "WC") {
  944. suffix = "WC"
  945. } else if strings.Contains(edbCode[l-1:], "F") {
  946. suffix = "F"
  947. } else if strings.Contains(edbCode[l-1:], "C") {
  948. suffix = "C"
  949. } else {
  950. br.Msg = "未搜索到该指标"
  951. br.ErrMsg = "指标code异常"
  952. return
  953. }
  954. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  955. if err != nil && err.Error() != utils.ErrNoRow() {
  956. br.Msg = "获取失败"
  957. br.ErrMsg = "获取欧洲天然气已存在信息失败,Err:" + err.Error()
  958. return
  959. }
  960. if len(dataItems) > 0 {
  961. searchItem.EdbCode = edbCode
  962. minDate, maxDate, err := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
  963. if err != nil {
  964. br.Msg = "获取失败"
  965. br.ErrMsg = "获取欧洲天然气日期信息失败,Err:" + err.Error()
  966. return
  967. }
  968. searchItem.DataList = dataItems
  969. searchItem.StartDate = minDate
  970. searchItem.EndDate = maxDate
  971. } else {
  972. //searchItem, err = data_manage.GetEdbDataByGie(edbCode, suffix, startDate, "")
  973. //if err != nil {
  974. // br.Msg = "获取失败"
  975. // br.ErrMsg = "获取失败,GetEdbDataByGie Err:" + err.Error()
  976. // return
  977. //}
  978. //if searchItem.StartDate == "" {
  979. // minDate, maxDate, _ := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
  980. // searchItem.StartDate = minDate
  981. // searchItem.EndDate = maxDate
  982. //}
  983. respItem, err := data.AddEdbData(source, edbCode)
  984. if err != nil {
  985. br.Msg = "获取失败"
  986. br.ErrMsg = "获取失败,Err:" + err.Error()
  987. return
  988. }
  989. if respItem.Ret != 200 {
  990. br.Msg = "未搜索到该指标"
  991. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  992. return
  993. }
  994. isAdd = true
  995. }
  996. //获取指标信息
  997. allInfo, err := data_manage.GetBaseFromEicDataAllByIndexCodeV2(edbCode, suffix)
  998. if err != nil && err.Error() != utils.ErrNoRow() {
  999. br.Msg = "获取失败"
  1000. br.ErrMsg = "获取欧洲天然气指标详情失败,Err:" + err.Error()
  1001. return
  1002. }
  1003. var eicInfo *data_manage.BaseFromTradeEicIndexV2
  1004. if allInfo != nil {
  1005. eicInfo = allInfo[0]
  1006. }
  1007. var name string
  1008. if eicInfo != nil {
  1009. searchItem.Frequency = "日度"
  1010. if suffix == "GS" {
  1011. name = eicInfo.Name + "_gas_in_storage"
  1012. searchItem.EdbName = name
  1013. searchItem.Unit = "TWh"
  1014. } else if suffix == "C" {
  1015. name = eicInfo.Name + "_consumption"
  1016. searchItem.EdbName = name
  1017. searchItem.Unit = "TWh"
  1018. } else if suffix == "CF" {
  1019. name = eicInfo.Name + "_consumption_full"
  1020. searchItem.EdbName = name
  1021. searchItem.Unit = "百分比"
  1022. } else if suffix == "F" {
  1023. name = eicInfo.Name + "_full"
  1024. searchItem.EdbName = name
  1025. searchItem.Unit = "百分比"
  1026. } else if suffix == "T" {
  1027. name = eicInfo.Name + "_trend"
  1028. searchItem.EdbName = name
  1029. searchItem.Unit = "百分比"
  1030. } else if suffix == "In" {
  1031. name = eicInfo.Name + "_injection"
  1032. searchItem.EdbName = name
  1033. searchItem.Unit = "GWH/d"
  1034. } else if suffix == "Out" {
  1035. name = eicInfo.Name + "_withdrawal"
  1036. searchItem.EdbName = name
  1037. searchItem.Unit = "GWH/d"
  1038. } else if suffix == "WGV" {
  1039. name = eicInfo.Name + "_working_gas_volume"
  1040. searchItem.EdbName = name
  1041. searchItem.Unit = "TWh"
  1042. } else if suffix == "IC" {
  1043. name = eicInfo.Name + "_injection_capacity"
  1044. searchItem.EdbName = name
  1045. searchItem.Unit = "GWh/d"
  1046. } else if suffix == "WC" {
  1047. name = eicInfo.Name + "_withdrawal_capacity"
  1048. searchItem.EdbName = name
  1049. searchItem.Unit = "GWh/d"
  1050. }
  1051. }
  1052. } else if source == utils.DATA_SOURCE_LT {
  1053. fmt.Println("lt data exist")
  1054. if strings.Contains(edbCode, "=") {
  1055. br.Msg = "暂不支持编码中含有=的指标"
  1056. br.ErrMsg = "暂不支持编码中含有=的指标"
  1057. return
  1058. }
  1059. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LT, utils.EDB_DATA_LIMIT)
  1060. if err != nil && err.Error() != utils.ErrNoRow() {
  1061. br.Msg = "获取失败"
  1062. br.ErrMsg = "获取 lt 已存在信息失败,Err:" + err.Error()
  1063. return
  1064. }
  1065. fmt.Println("lt dataItems:", len(dataItems))
  1066. if len(dataItems) > 0 {
  1067. searchItem.EdbCode = edbCode
  1068. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1069. if err != nil {
  1070. br.Msg = "获取失败"
  1071. br.ErrMsg = "获取lt日期信息失败,Err:" + err.Error()
  1072. return
  1073. }
  1074. searchItem.DataList = dataItems
  1075. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1076. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1077. } else {
  1078. //endDate := dateNow.Format(utils.FormatDate)
  1079. //searchItem, err = data.GetEdbDataByLt(edbCode, startDate, endDate)
  1080. //if err != nil {
  1081. // br.Msg = "获取失败"
  1082. // br.ErrMsg = "lt 获取失败,Err:" + err.Error()
  1083. // return
  1084. //}
  1085. respItem, err := data.AddEdbData(source, edbCode)
  1086. if err != nil {
  1087. br.Msg = "获取失败"
  1088. br.ErrMsg = "获取失败,Err:" + err.Error()
  1089. return
  1090. }
  1091. if respItem.Ret != 200 {
  1092. br.Msg = respItem.Msg
  1093. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1094. return
  1095. }
  1096. isAdd = true
  1097. }
  1098. } else if source == utils.DATA_SOURCE_COAL { //中国煤炭网
  1099. var suffix string
  1100. if strings.Contains(edbCode, "jsm") {
  1101. suffix = "jsm_index"
  1102. } else if strings.Contains(edbCode, "company") {
  1103. suffix = "company_index"
  1104. } else if strings.Contains(edbCode, "firm") {
  1105. suffix = "firm_index"
  1106. } else if strings.Contains(edbCode, "coastal") {
  1107. suffix = "coastal_index"
  1108. } else if strings.Contains(edbCode, "inland") {
  1109. suffix = "inland_index"
  1110. } else {
  1111. br.Msg = "未搜索到该指标"
  1112. br.ErrMsg = "指标code异常"
  1113. return
  1114. }
  1115. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1116. if err != nil && err.Error() != utils.ErrNoRow() {
  1117. br.Msg = "获取失败"
  1118. br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
  1119. return
  1120. }
  1121. if len(dataItems) > 0 {
  1122. searchItem.EdbCode = edbCode
  1123. minDate, maxDate, err := data_manage.GetEdbDataCoalMaxOrMinDate(edbCode)
  1124. if err != nil {
  1125. br.Msg = "获取失败"
  1126. br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
  1127. return
  1128. }
  1129. searchItem.DataList = dataItems
  1130. searchItem.StartDate = minDate
  1131. searchItem.EndDate = maxDate
  1132. } else {
  1133. //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
  1134. //if err != nil {
  1135. // br.Msg = "获取失败"
  1136. // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
  1137. // return
  1138. //}
  1139. //if searchItem.StartDate == "" {
  1140. // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  1141. // searchItem.StartDate = minDate
  1142. // searchItem.EndDate = maxDate
  1143. //}
  1144. respItem, err := data.AddEdbData(source, edbCode)
  1145. if err != nil {
  1146. br.Msg = "获取失败"
  1147. br.ErrMsg = "获取失败,Err:" + err.Error()
  1148. return
  1149. }
  1150. if respItem.Ret != 200 {
  1151. br.Msg = "未搜索到该指标"
  1152. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1153. return
  1154. }
  1155. isAdd = true
  1156. }
  1157. //获取指标信息
  1158. allInfo, err := data_manage.GetBaseInfoFromCoalByIndexCode(edbCode, suffix)
  1159. if err != nil && err.Error() != utils.ErrNoRow() {
  1160. br.Msg = "获取失败"
  1161. br.ErrMsg = "获取煤炭网指标详情失败,Err:" + err.Error()
  1162. return
  1163. }
  1164. var coalInfo *data_manage.BaseInfoFromCoal
  1165. if allInfo != nil {
  1166. coalInfo = allInfo[0]
  1167. }
  1168. if coalInfo != nil {
  1169. searchItem.Frequency = coalInfo.Frequency
  1170. searchItem.Unit = coalInfo.Unit
  1171. searchItem.EdbName = coalInfo.IndexName
  1172. }
  1173. } else if source == utils.DATA_SOURCE_GOOGLE_TRAVEL { //谷歌出行数据
  1174. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1175. if err != nil && err.Error() != utils.ErrNoRow() {
  1176. br.Msg = "获取失败"
  1177. br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
  1178. return
  1179. }
  1180. if len(dataItems) > 0 {
  1181. searchItem.EdbCode = edbCode
  1182. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1183. if err != nil {
  1184. br.Msg = "获取失败"
  1185. br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
  1186. return
  1187. }
  1188. if item != nil {
  1189. searchItem.DataList = dataItems
  1190. searchItem.StartDate = item.MinDate
  1191. searchItem.EndDate = item.MaxDate
  1192. }
  1193. } else {
  1194. respItem, err := data.AddEdbData(source, edbCode)
  1195. if err != nil {
  1196. br.Msg = "获取失败"
  1197. br.ErrMsg = "获取失败,Err:" + err.Error()
  1198. return
  1199. }
  1200. if respItem.Ret != 200 {
  1201. br.Msg = "未搜索到该指标"
  1202. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1203. return
  1204. }
  1205. isAdd = true
  1206. }
  1207. } else if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL { //钢联化工
  1208. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1209. if err != nil && err.Error() != utils.ErrNoRow() {
  1210. br.Msg = "获取失败"
  1211. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1212. return
  1213. }
  1214. if len(dataItems) > 0 {
  1215. searchItem.EdbCode = edbCode
  1216. minDate, maxDate, err := data_manage.GetEdbDataMysteelChemicalMaxOrMinDate(edbCode)
  1217. if err != nil {
  1218. br.Msg = "获取失败"
  1219. br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
  1220. return
  1221. }
  1222. searchItem.DataList = dataItems
  1223. searchItem.StartDate = minDate
  1224. searchItem.EndDate = maxDate
  1225. } else {
  1226. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1227. //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
  1228. //if err != nil {
  1229. // br.Msg = "获取失败"
  1230. // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
  1231. // return
  1232. //}
  1233. respItem, err := data.AddEdbData(source, edbCode)
  1234. if err != nil {
  1235. br.Msg = "获取失败"
  1236. br.ErrMsg = "获取失败,Err:" + err.Error()
  1237. return
  1238. }
  1239. if respItem.Ret != 200 {
  1240. br.Msg = "未搜索到该指标"
  1241. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1242. return
  1243. }
  1244. isAdd = true
  1245. }
  1246. //获取指标信息
  1247. glInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
  1248. if err != nil && err.Error() != utils.ErrNoRow() {
  1249. br.Msg = "获取失败"
  1250. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1251. return
  1252. }
  1253. if glInfo != nil {
  1254. searchItem.Frequency = glInfo.Frequency
  1255. searchItem.Unit = glInfo.Unit
  1256. searchItem.EdbName = glInfo.IndexName
  1257. }
  1258. } else if source == utils.DATA_SOURCE_EIA_STEO { //eia steo报告
  1259. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1260. if err != nil && err.Error() != utils.ErrNoRow() {
  1261. br.Msg = "获取失败"
  1262. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1263. return
  1264. }
  1265. if len(dataItems) > 0 {
  1266. searchItem.EdbCode = edbCode
  1267. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1268. if err != nil {
  1269. br.Msg = "获取失败"
  1270. br.ErrMsg = "获取eia steo日期信息失败,Err:" + err.Error()
  1271. return
  1272. }
  1273. searchItem.DataList = dataItems
  1274. searchItem.StartDate = item.MinDate
  1275. searchItem.EndDate = item.MaxDate
  1276. } else {
  1277. respItem, err := data.AddEdbData(source, edbCode)
  1278. if err != nil {
  1279. br.Msg = "获取失败"
  1280. br.ErrMsg = "获取失败,Err:" + err.Error()
  1281. return
  1282. }
  1283. if respItem.Ret != 200 {
  1284. br.Msg = "未搜索到该指标"
  1285. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1286. return
  1287. }
  1288. isAdd = true
  1289. }
  1290. //获取指标信息
  1291. eiasteoInfo, err := data_manage.GetBaseFromEiaSteoIndexByCode(edbCode)
  1292. if err != nil && err.Error() != utils.ErrNoRow() {
  1293. br.Msg = "获取失败"
  1294. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1295. return
  1296. }
  1297. if eiasteoInfo != nil {
  1298. searchItem.Frequency = eiasteoInfo.Frequency
  1299. searchItem.Unit = eiasteoInfo.Unit
  1300. searchItem.EdbName = eiasteoInfo.IndexName
  1301. }
  1302. } else if source == utils.DATA_SOURCE_COM_TRADE { // un数据源
  1303. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1304. if err != nil && err.Error() != utils.ErrNoRow() {
  1305. br.Msg = "获取失败"
  1306. br.ErrMsg = "获取联合国商品贸易数据已存在信息失败,Err:" + err.Error()
  1307. return
  1308. }
  1309. if len(dataItems) > 0 {
  1310. searchItem.EdbCode = edbCode
  1311. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1312. if err != nil {
  1313. br.Msg = "获取失败"
  1314. br.ErrMsg = "获取联合国商品贸易数据日期信息失败,Err:" + err.Error()
  1315. return
  1316. }
  1317. searchItem.DataList = dataItems
  1318. searchItem.StartDate = item.MinDate
  1319. searchItem.EndDate = item.MaxDate
  1320. } else {
  1321. respItem, err := data.AddEdbData(source, edbCode)
  1322. if err != nil {
  1323. br.Msg = "获取失败"
  1324. br.ErrMsg = "获取失败,Err:" + err.Error()
  1325. return
  1326. }
  1327. if respItem.Ret != 200 {
  1328. br.Msg = "未搜索到该指标"
  1329. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1330. return
  1331. }
  1332. isAdd = true
  1333. }
  1334. //获取指标信息
  1335. eiasteoInfo, err := data_manage.GetComTradeIndex(edbCode)
  1336. if err != nil && err.Error() != utils.ErrNoRow() {
  1337. br.Msg = "获取失败"
  1338. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1339. return
  1340. }
  1341. if eiasteoInfo != nil {
  1342. //eiasteoInfo.
  1343. if eiasteoInfo.Type <= 2 {
  1344. searchItem.Frequency = `年度`
  1345. } else {
  1346. searchItem.Frequency = `月度`
  1347. }
  1348. if eiasteoInfo.Type == 1 || eiasteoInfo.Type == 3 {
  1349. searchItem.Unit = "美元"
  1350. } else {
  1351. searchItem.Unit = "千克"
  1352. }
  1353. searchItem.EdbName = eiasteoInfo.Name
  1354. }
  1355. } else if source == utils.DATA_SOURCE_SCI { //卓创数据(红桃三)
  1356. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1357. if err != nil && err.Error() != utils.ErrNoRow() {
  1358. br.Msg = "获取失败"
  1359. br.ErrMsg = "获取SCI已存在信息失败,Err:" + err.Error()
  1360. return
  1361. }
  1362. fmt.Println("dataItems:", len(dataItems))
  1363. if len(dataItems) > 0 {
  1364. searchItem.EdbCode = edbCode
  1365. minDate, maxDate, err := data_manage.GetEdbDataSciMaxAndMinDate(edbCode)
  1366. if err != nil {
  1367. br.Msg = "获取失败"
  1368. br.ErrMsg = "获取SCI日期信息失败,Err:" + err.Error()
  1369. return
  1370. }
  1371. searchItem.DataList = dataItems
  1372. searchItem.StartDate = minDate
  1373. searchItem.EndDate = maxDate
  1374. } else {
  1375. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1376. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  1377. //if err != nil {
  1378. // br.Msg = "获取失败"
  1379. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  1380. // return
  1381. //}
  1382. //if searchItem.StartDate == "" {
  1383. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  1384. // searchItem.StartDate = minDate
  1385. // searchItem.EndDate = maxDate
  1386. //}
  1387. respItem, err := data.AddEdbData(source, edbCode)
  1388. if err != nil {
  1389. br.Msg = "获取失败"
  1390. br.ErrMsg = "获取失败,Err:" + err.Error()
  1391. return
  1392. }
  1393. if respItem.Ret != 200 {
  1394. br.Msg = "未搜索到该指标"
  1395. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1396. return
  1397. }
  1398. isAdd = true
  1399. }
  1400. //获取指标信息
  1401. smmInfo, err := data_manage.GetBaseFromSciIndexByIndexCode(edbCode)
  1402. if err != nil && err.Error() != utils.ErrNoRow() {
  1403. br.Msg = "获取失败"
  1404. br.ErrMsg = "获取Sci指标详情失败,Err:" + err.Error()
  1405. return
  1406. }
  1407. if smmInfo != nil {
  1408. searchItem.Frequency = smmInfo.Frequency
  1409. searchItem.Unit = smmInfo.Unit
  1410. searchItem.EdbName = smmInfo.IndexName
  1411. }
  1412. } else if source == utils.DATA_SOURCE_BAIINFO { //百川盈孚
  1413. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1414. if err != nil && err.Error() != utils.ErrNoRow() {
  1415. br.Msg = "获取失败"
  1416. br.ErrMsg = "获取BAIINFO已存在信息失败,Err:" + err.Error()
  1417. return
  1418. }
  1419. fmt.Println("dataItems:", len(dataItems))
  1420. if len(dataItems) > 0 {
  1421. searchItem.EdbCode = edbCode
  1422. minDate, maxDate, err := data_manage.GetEdbDataBaiinfoMaxAndMinDate(edbCode)
  1423. if err != nil {
  1424. br.Msg = "获取失败"
  1425. br.ErrMsg = "获取BAIINFO日期信息失败,Err:" + err.Error()
  1426. return
  1427. }
  1428. searchItem.DataList = dataItems
  1429. searchItem.StartDate = minDate
  1430. searchItem.EndDate = maxDate
  1431. } else {
  1432. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1433. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  1434. //if err != nil {
  1435. // br.Msg = "获取失败"
  1436. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  1437. // return
  1438. //}
  1439. //if searchItem.StartDate == "" {
  1440. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  1441. // searchItem.StartDate = minDate
  1442. // searchItem.EndDate = maxDate
  1443. //}
  1444. respItem, err := data.AddEdbData(source, edbCode)
  1445. if err != nil {
  1446. br.Msg = "获取失败"
  1447. br.ErrMsg = "获取失败,Err:" + err.Error()
  1448. return
  1449. }
  1450. if respItem.Ret != 200 {
  1451. br.Msg = "未搜索到该指标"
  1452. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1453. return
  1454. }
  1455. isAdd = true
  1456. }
  1457. //获取指标信息
  1458. baiInfo, err := data_manage.GetBaseFromBaiinfoIndexByIndexCode(edbCode)
  1459. if err != nil && err.Error() != utils.ErrNoRow() {
  1460. br.Msg = "获取失败"
  1461. br.ErrMsg = "获取Baiinfo指标详情失败,Err:" + err.Error()
  1462. return
  1463. }
  1464. if baiInfo != nil {
  1465. searchItem.Frequency = baiInfo.Frequency
  1466. searchItem.Unit = baiInfo.Unit
  1467. searchItem.EdbName = baiInfo.IndexName
  1468. }
  1469. } else if source == utils.DATA_SOURCE_NATIONAL_STATISTICS { // 国家统计局
  1470. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1471. if err != nil && err.Error() != utils.ErrNoRow() {
  1472. br.Msg = "获取失败"
  1473. br.ErrMsg = "获取国家统计局已存在信息失败,Err:" + err.Error()
  1474. return
  1475. }
  1476. if len(dataItems) > 0 {
  1477. searchItem.EdbCode = edbCode
  1478. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1479. if err != nil {
  1480. br.Msg = "获取失败"
  1481. br.ErrMsg = "获取国家统计局日期信息失败,Err:" + err.Error()
  1482. return
  1483. }
  1484. searchItem.DataList = dataItems
  1485. searchItem.StartDate = item.MinDate
  1486. searchItem.EndDate = item.MaxDate
  1487. } else {
  1488. respItem, err := data.AddEdbData(source, edbCode)
  1489. if err != nil {
  1490. br.Msg = "获取失败"
  1491. br.ErrMsg = "获取失败,Err:" + err.Error()
  1492. return
  1493. }
  1494. if respItem.Ret != 200 {
  1495. br.Msg = "未搜索到该指标"
  1496. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1497. return
  1498. }
  1499. isAdd = true
  1500. }
  1501. //获取指标信息
  1502. nationalInfo, err := data_manage.GetBaseFromNationalStatisticsIndexByIndexCode(edbCode)
  1503. if err != nil && err.Error() != utils.ErrNoRow() {
  1504. br.Msg = "获取失败"
  1505. br.ErrMsg = "获取国家统计局详情失败,Err:" + err.Error()
  1506. return
  1507. }
  1508. if nationalInfo != nil {
  1509. searchItem.Frequency = nationalInfo.Frequency
  1510. searchItem.Unit = nationalInfo.Unit
  1511. searchItem.EdbName = fmt.Sprintf("%s%s", nationalInfo.Reg, nationalInfo.IndexName)
  1512. }
  1513. } else if source == utils.DATA_SOURCE_FUBAO { //数宝
  1514. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_FUBAO, utils.EDB_DATA_LIMIT)
  1515. if err != nil && err.Error() != utils.ErrNoRow() {
  1516. br.Msg = "获取失败"
  1517. br.ErrMsg = "获取Fubao已存在信息失败,Err:" + err.Error()
  1518. return
  1519. }
  1520. fmt.Println("fubao len:", len(dataItems))
  1521. if len(dataItems) > 0 {
  1522. fmt.Println("fubao data exist")
  1523. searchItem.EdbCode = edbCode
  1524. minDate, maxDate, err := data_manage.GetEdbDataFubaoMaxOrMinDate(edbCode)
  1525. if err != nil {
  1526. br.Msg = "获取失败"
  1527. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  1528. return
  1529. }
  1530. searchItem.DataList = dataItems
  1531. searchItem.StartDate = minDate
  1532. searchItem.EndDate = maxDate
  1533. } else {
  1534. respItem, err := data.AddEdbData(source, edbCode)
  1535. if err != nil {
  1536. br.Msg = "获取失败," + respItem.Msg
  1537. br.ErrMsg = "获取失败,Err:" + err.Error()
  1538. return
  1539. }
  1540. if respItem.Ret != 200 {
  1541. br.Msg = "未搜索到该指标," + respItem.Msg
  1542. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1543. return
  1544. }
  1545. isAdd = true
  1546. }
  1547. } else {
  1548. // 代码中没有的来源那么从edb_source中找是否有对应的
  1549. sourceItem := data_manage.EdbSourceIdMap[source]
  1550. if sourceItem == nil {
  1551. br.Msg = "无效指标来源"
  1552. return
  1553. }
  1554. // 获取指标数据
  1555. dataList, e := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1556. if e != nil {
  1557. br.Msg = "获取失败"
  1558. br.ErrMsg = "获取指标数据失败, Err: " + e.Error()
  1559. return
  1560. }
  1561. if len(dataList) > 0 {
  1562. searchItem.EdbCode = edbCode
  1563. searchItem.DataList = dataList
  1564. // 获取最大最小值
  1565. edbInfoMaxAndMinInfo, e := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1566. if e != nil && e.Error() != utils.ErrNoRow() {
  1567. br.Msg = "获取失败"
  1568. br.ErrMsg = "获取数据失败, GetEdbInfoMaxAndMinInfo Err:" + e.Error()
  1569. return
  1570. }
  1571. if edbInfoMaxAndMinInfo != nil {
  1572. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1573. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1574. }
  1575. } else {
  1576. // 新增指标数据
  1577. addRes, e := data.AddEdbData(source, edbCode)
  1578. if e != nil {
  1579. br.Msg = "获取失败"
  1580. br.ErrMsg = "获取失败,Err:" + e.Error()
  1581. return
  1582. }
  1583. if addRes == nil {
  1584. br.Msg = "获取失败"
  1585. br.ErrMsg = "新增指标数据失败, addRes nil"
  1586. return
  1587. }
  1588. if addRes.Ret != 200 {
  1589. br.Msg = "未搜索到该指标, " + addRes.Msg
  1590. //br.ErrMsg = addRes.ErrMsg + ";EdbCode:" + edbCode
  1591. br.Success = true
  1592. return
  1593. }
  1594. isAdd = true
  1595. }
  1596. // 指标来源于桥接服务: 桥接服务获取指标取频度信息等
  1597. if sourceItem.BridgeFlag != "" {
  1598. bridgeOb := data.InitBridgeOB(sourceItem.BridgeFlag)
  1599. if bridgeOb != nil {
  1600. var r data.GetIndexFromBridgeReq
  1601. r.IndexCode = edbCode
  1602. r.Source = sourceItem.EdbSourceId
  1603. r.SourceExtend = sourceItem.SourceExtend
  1604. r.IndexCodeRequired = sourceItem.EdbCodeRequired
  1605. bridgeIndex, e := bridgeOb.GetIndex(r)
  1606. if e != nil {
  1607. br.Msg = "获取失败"
  1608. br.ErrMsg = "桥接服务获取指标信息失败, Err: " + e.Error()
  1609. return
  1610. }
  1611. searchItem.EdbName = bridgeIndex.IndexName
  1612. searchItem.Frequency = bridgeIndex.Frequency
  1613. searchItem.Unit = bridgeIndex.Unit
  1614. }
  1615. }
  1616. }
  1617. if isAdd {
  1618. if subSource == utils.DATA_SUB_SOURCE_DATE {
  1619. //wsdData := windWsdRespItem.Data
  1620. //var buf bytes.Buffer
  1621. //// 创建一个encoder并指定目标为buf
  1622. //enc := gob.NewEncoder(&buf)
  1623. //
  1624. //// 将data编码到buf中
  1625. //err = enc.Encode(wsdData)
  1626. //if err != nil {
  1627. // br.Msg = "获取失败"
  1628. // br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error()
  1629. // return
  1630. //}
  1631. //
  1632. //wsdDataMap := make(map[string]map[string]interface{})
  1633. //err = json.Unmarshal(buf.Bytes(), &wsdDataMap)
  1634. //if err != nil {
  1635. // br.Msg = "获取失败"
  1636. // br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error()
  1637. // return
  1638. //}
  1639. //
  1640. //stockList := make([]*data_manage.StockInfo, 0)
  1641. //
  1642. //dataList := make([]*data_manage.EdbInfoSearchData, 0)
  1643. //for wk, wv := range wsdDataMap {
  1644. // for vk, vv := range wv {
  1645. // wkInt, err := strconv.ParseInt(wk, 10, 64)
  1646. // if err != nil {
  1647. // br.Msg = "获取失败"
  1648. // br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error()
  1649. // return
  1650. // }
  1651. //
  1652. // vk = strings.ToLower(vk)
  1653. // wkInt = wkInt / 1000
  1654. // t := time.Unix(wkInt, 0)
  1655. // dateTime := t.Format(utils.FormatDate)
  1656. // //saveVal := utils.SubFloatToString(val, 20)
  1657. // if vv == nil {
  1658. // continue
  1659. // }
  1660. // var saveVal string
  1661. // switch vt := vv.(type) {
  1662. // case int:
  1663. // saveVal = strconv.Itoa(vt)
  1664. // case float64:
  1665. // saveVal = utils.SubFloatToFloatStr(vt, 20)
  1666. // case string:
  1667. // saveVal = vt
  1668. // }
  1669. //
  1670. // dataItem := new(data_manage.EdbInfoSearchData)
  1671. // dataItem.Value = saveVal
  1672. // dataItem.DataTime = dateTime
  1673. // dataList = append(dataList, dataItem)
  1674. // if len(dataList) >= 10 {
  1675. // break
  1676. // }
  1677. // }
  1678. //}
  1679. //searchItem.StockList = stockList
  1680. stockList := make([]*data_manage.StockInfo, 0)
  1681. edbCodeArr := strings.Split(edbCode, ",")
  1682. for _, v := range edbCodeArr {
  1683. indexCode := utils.WindDbWsd + stockCode + v
  1684. dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
  1685. if err != nil && err.Error() != utils.ErrNoRow() {
  1686. br.Msg = "获取失败"
  1687. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  1688. return
  1689. }
  1690. stockInfo := new(data_manage.StockInfo)
  1691. stockInfo.StockCode = stockCode
  1692. stockInfo.EdbCode = v
  1693. stockInfo.DataList = dataList
  1694. stockList = append(stockList, stockInfo)
  1695. }
  1696. searchItem.StockList = stockList
  1697. } else {
  1698. dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1699. if err != nil && err.Error() != utils.ErrNoRow() {
  1700. br.Msg = "获取失败"
  1701. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  1702. return
  1703. }
  1704. searchItem.DataList = dataList
  1705. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1706. if err != nil && err.Error() != utils.ErrNoRow() {
  1707. br.Msg = "获取失败"
  1708. br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
  1709. return
  1710. }
  1711. searchItem.EdbCode = edbCode
  1712. searchItem.DataList = dataList
  1713. if edbInfoMaxAndMinInfo != nil {
  1714. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1715. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1716. }
  1717. //edb指标信息
  1718. edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode)
  1719. if edbInfoItem != nil {
  1720. searchItem.EdbName = edbInfoItem.EdbName
  1721. }
  1722. }
  1723. }
  1724. resp.Status = 2
  1725. resp.SearchItem = searchItem
  1726. }
  1727. //如果不在指标库中,且不是新增
  1728. if !isInEdb && !isAdd {
  1729. if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 {
  1730. br.Msg = "目标指标无有效值,请重新搜索"
  1731. br.Data = resp
  1732. return
  1733. }
  1734. }
  1735. br.Ret = 200
  1736. br.Success = true
  1737. br.Msg = "获取成功"
  1738. br.Data = resp
  1739. }
  1740. // EdbInfoList
  1741. // @Title 指标列表接口
  1742. // @Description 指标列表接口
  1743. // @Param PageSize query int true "每页数据条数"
  1744. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1745. // @Param EdbInfoId query int true "指标id"
  1746. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  1747. // @Success 200 {object} data_manage.EdbInfoListResp
  1748. // @router /edb_info/list [get]
  1749. func (this *EdbInfoController) EdbInfoList() {
  1750. br := new(models.BaseResponse).Init()
  1751. defer func() {
  1752. this.Data["json"] = br
  1753. this.ServeJSON()
  1754. }()
  1755. edbInfoId, _ := this.GetInt("EdbInfoId")
  1756. keyWord := this.GetString("KeyWord")
  1757. pageSize, _ := this.GetInt("PageSize")
  1758. currentIndex, _ := this.GetInt("CurrentIndex")
  1759. var total int
  1760. page := paging.GetPaging(currentIndex, pageSize, total)
  1761. var startSize int
  1762. if pageSize <= 0 {
  1763. pageSize = utils.PageSize20
  1764. }
  1765. if currentIndex <= 0 {
  1766. currentIndex = 1
  1767. }
  1768. startSize = paging.StartIndex(currentIndex, pageSize)
  1769. var condition string
  1770. var pars []interface{}
  1771. //if edbInfoId <= 0 && keyWord == "" {
  1772. // br.Msg = "参数错误"
  1773. // return
  1774. //}
  1775. // 指标类型,0:普通指标,1:预测指标
  1776. condition += " AND edb_info_type=? "
  1777. pars = append(pars, 0)
  1778. if edbInfoId > 0 {
  1779. condition += " AND edb_info_id=? "
  1780. pars = append(pars, edbInfoId)
  1781. // 获取当前账号的不可见指标配置
  1782. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1783. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId)
  1784. if err != nil && err.Error() != utils.ErrNoRow() {
  1785. br.Msg = "获取失败"
  1786. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  1787. return
  1788. }
  1789. if conf != nil {
  1790. br.Msg = "无权限,请联系管理员"
  1791. br.IsSendEmail = false
  1792. return
  1793. }
  1794. }
  1795. if keyWord != "" {
  1796. condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  1797. //pars = append(pars, keyWord)
  1798. //pars = append(pars, keyWord)
  1799. }
  1800. resp := new(data_manage.EdbInfoListResp)
  1801. if condition == "" {
  1802. item := new(data_manage.EdbInfoList)
  1803. resp.Paging = page
  1804. resp.Item = item
  1805. br.Ret = 200
  1806. br.Success = true
  1807. br.Msg = "获取成功"
  1808. return
  1809. }
  1810. //获取指标信息
  1811. edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
  1812. if err != nil && err.Error() != utils.ErrNoRow() {
  1813. br.Success = true
  1814. br.Msg = "获取指标信息失败"
  1815. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  1816. return
  1817. }
  1818. if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1819. item := new(data_manage.EdbInfoList)
  1820. resp.Paging = page
  1821. resp.Item = item
  1822. br.Ret = 200
  1823. br.Success = true
  1824. br.Msg = "获取成功"
  1825. return
  1826. }
  1827. //获取英文频度
  1828. edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
  1829. //获取指标数据
  1830. var dataCondition string
  1831. var dataPars []interface{}
  1832. dataCondition += ` AND edb_info_id=? `
  1833. dataPars = append(dataPars, edbInfoItem.EdbInfoId)
  1834. dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
  1835. if err != nil && err.Error() != utils.ErrNoRow() {
  1836. br.Msg = "获取指标信息失败"
  1837. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  1838. return
  1839. }
  1840. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  1841. dataList, err := data_manage.GetEdbDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
  1842. if err != nil {
  1843. br.Msg = "获取指标信息失败"
  1844. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  1845. return
  1846. }
  1847. edbInfoItem.DataList = dataList
  1848. // 获取指标插入配置
  1849. {
  1850. edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId)
  1851. if err != nil && err.Error() != utils.ErrNoRow() {
  1852. br.Msg = "获取指标信息失败"
  1853. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  1854. return
  1855. }
  1856. if edbDataInsertConfig != nil {
  1857. edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate)
  1858. edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate)
  1859. edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value
  1860. }
  1861. }
  1862. // 按钮校验
  1863. button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType)
  1864. button.AddButton = false
  1865. edbInfoItem.Button = button
  1866. //是否展示英文标识
  1867. edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn)
  1868. //查询目录
  1869. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId)
  1870. if err != nil {
  1871. br.Msg = err.Error()
  1872. br.ErrMsg = errMsg
  1873. return
  1874. }
  1875. resp.Paging = page
  1876. resp.Item = edbInfoItem
  1877. resp.ClassifyList = classifyList
  1878. br.Ret = 200
  1879. br.Success = true
  1880. br.Msg = "获取成功"
  1881. br.Data = resp
  1882. }
  1883. // EdbInfoAdd
  1884. // @Title 新增指标接口
  1885. // @Description 新增指标接口
  1886. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1887. // @Success Ret=200 保存成功
  1888. // @router /edb_info/add [post]
  1889. func (this *EdbInfoController) EdbInfoAdd() {
  1890. br := new(models.BaseResponse).Init()
  1891. defer func() {
  1892. this.Data["json"] = br
  1893. this.ServeJSON()
  1894. }()
  1895. sysUser := this.SysUser
  1896. if sysUser == nil {
  1897. br.Msg = "请登录"
  1898. br.ErrMsg = "请登录,SysUser Is Empty"
  1899. br.Ret = 408
  1900. return
  1901. }
  1902. deleteCache := true
  1903. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  1904. defer func() {
  1905. if deleteCache {
  1906. utils.Rc.Delete(cacheKey)
  1907. }
  1908. }()
  1909. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1910. deleteCache = false
  1911. br.Msg = "系统处理中,请稍后重试!"
  1912. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1913. return
  1914. }
  1915. var req data_manage.AddEdbInfoReq
  1916. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1917. if err != nil {
  1918. br.Msg = "参数解析异常!"
  1919. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1920. return
  1921. }
  1922. source := req.Source
  1923. if source <= 0 {
  1924. br.Msg = "无效的数据来源"
  1925. return
  1926. }
  1927. req.EdbName = strings.Trim(req.EdbName, " ")
  1928. req.EdbCode = strings.Trim(req.EdbCode, " ")
  1929. if req.EdbCode == "" {
  1930. br.Msg = "指标ID不能为空"
  1931. return
  1932. }
  1933. if req.EdbName == "" {
  1934. br.Msg = "指标名称不能为空"
  1935. return
  1936. }
  1937. if req.Frequency == "" {
  1938. br.Msg = "频率不能为空"
  1939. return
  1940. }
  1941. if req.Unit == "" {
  1942. br.Msg = "单位不能为空"
  1943. return
  1944. }
  1945. if req.ClassifyId <= 0 {
  1946. br.Msg = "请选择分类"
  1947. return
  1948. }
  1949. //if req.StartDate == "" || req.EndDate == "" {
  1950. // br.Msg = "日期不能为空"
  1951. // return
  1952. //}
  1953. // 兼容钢联与钢联化工数据
  1954. if source == utils.DATA_SOURCE_GL {
  1955. // 如果是钢联的话,那么就先判断是不是存在钢联化工
  1956. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
  1957. if err != nil {
  1958. if err.Error() != utils.ErrNoRow() {
  1959. br.Msg = "获取失败"
  1960. br.ErrMsg = "获取失败,Err:" + err.Error()
  1961. return
  1962. }
  1963. }
  1964. if tmpInfo != nil {
  1965. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  1966. req.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  1967. }
  1968. }
  1969. // 指标入库
  1970. edbInfo, err, errMsg, isSendEmail := data.EdbInfoAdd(source, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, req.StartDate, req.EndDate, sysUser.AdminId, sysUser.RealName)
  1971. if err != nil {
  1972. br.Msg = "保存失败"
  1973. if errMsg != `` {
  1974. br.Msg = errMsg
  1975. }
  1976. br.ErrMsg = err.Error()
  1977. br.IsSendEmail = isSendEmail
  1978. return
  1979. }
  1980. // 试用平台更新用户累计新增指标数
  1981. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  1982. if e != nil {
  1983. br.Msg = "操作失败"
  1984. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  1985. return
  1986. }
  1987. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  1988. go func() {
  1989. var r etaTrialService.EtaTrialUserReq
  1990. r.Mobile = adminItem.Mobile
  1991. _, _ = etaTrialService.UpdateUserIndexNum(r)
  1992. }()
  1993. }
  1994. //新增操作日志
  1995. {
  1996. edbLog := new(data_manage.EdbInfoLog)
  1997. edbLog.EdbInfoId = edbInfo.EdbInfoId
  1998. edbLog.SourceName = edbInfo.SourceName
  1999. edbLog.Source = edbInfo.Source
  2000. edbLog.EdbCode = edbInfo.EdbCode
  2001. edbLog.EdbName = edbInfo.EdbName
  2002. edbLog.ClassifyId = edbInfo.ClassifyId
  2003. edbLog.SysUserId = sysUser.AdminId
  2004. edbLog.SysUserRealName = sysUser.RealName
  2005. edbLog.CreateTime = time.Now()
  2006. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2007. edbLog.Status = "新增指标"
  2008. edbLog.Method = this.Ctx.Input.URI()
  2009. go data_manage.AddEdbInfoLog(edbLog)
  2010. }
  2011. resp := new(data_manage.AddEdbInfoResp)
  2012. resp.EdbInfoId = edbInfo.EdbInfoId
  2013. resp.UniqueCode = edbInfo.UniqueCode
  2014. br.Ret = 200
  2015. br.Success = true
  2016. br.Msg = "保存成功"
  2017. br.Data = resp
  2018. br.IsAddLog = true
  2019. }
  2020. // EdbInfoEdit
  2021. // @Title 编辑指标接口
  2022. // @Description 编辑指标接口
  2023. // @Success 200 {object} data_manage.EditEdbInfoReq
  2024. // @router /edb_info/edit [post]
  2025. func (this *EdbInfoController) EdbInfoEdit() {
  2026. br := new(models.BaseResponse).Init()
  2027. defer func() {
  2028. this.Data["json"] = br
  2029. this.ServeJSON()
  2030. }()
  2031. sysUser := this.SysUser
  2032. if sysUser == nil {
  2033. br.Msg = "请登录"
  2034. br.ErrMsg = "请登录,SysUser Is Empty"
  2035. br.Ret = 408
  2036. return
  2037. }
  2038. var req data_manage.EditEdbInfoReq
  2039. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2040. if err != nil {
  2041. br.Msg = "参数解析异常!"
  2042. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2043. return
  2044. }
  2045. req.EdbName = strings.Trim(req.EdbName, " ")
  2046. if req.EdbInfoId <= 0 {
  2047. br.Msg = "参数错误"
  2048. br.ErrMsg = "指标id小于等于0"
  2049. return
  2050. }
  2051. if req.EdbName == "" {
  2052. br.Msg = "指标名称不能为空"
  2053. return
  2054. }
  2055. if req.Frequency == "" {
  2056. br.Msg = "频率不能为空"
  2057. return
  2058. }
  2059. if req.Unit == "" {
  2060. br.Msg = "单位不能为空"
  2061. return
  2062. }
  2063. if req.ClassifyId <= 0 {
  2064. br.Msg = "请选择分类"
  2065. return
  2066. }
  2067. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2068. if err != nil {
  2069. br.Msg = "修改失败"
  2070. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2071. return
  2072. }
  2073. // 编辑权限校验
  2074. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType)
  2075. if !button.OpButton {
  2076. br.Msg = "无权限操作"
  2077. br.IsSendEmail = false
  2078. return
  2079. }
  2080. //判断指标名称是否存在
  2081. var condition string
  2082. var pars []interface{}
  2083. condition += " AND edb_info_id<>? "
  2084. pars = append(pars, req.EdbInfoId)
  2085. //condition += " AND source=? "
  2086. //pars = append(pars, edbInfo.Source)
  2087. condition += " AND edb_name=? "
  2088. pars = append(pars, req.EdbName)
  2089. count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
  2090. if err != nil {
  2091. br.Msg = "判断指标名称是否存在失败"
  2092. br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error()
  2093. return
  2094. }
  2095. if count > 0 {
  2096. br.Msg = "指标名称已存在,请重新填写"
  2097. br.ErrMsg = "指标名称已存在,请重新填写"
  2098. br.IsSendEmail = false
  2099. return
  2100. }
  2101. err = data_manage.ModifyEdbInfo(&req)
  2102. if err != nil {
  2103. br.Msg = "保存失败"
  2104. br.ErrMsg = "修改失败,Err:" + err.Error()
  2105. return
  2106. }
  2107. //处理同名指标
  2108. //{
  2109. // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName)
  2110. // if err != nil {
  2111. // br.Msg = "保存失败"
  2112. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2113. // return
  2114. // }
  2115. // if len(edbNameList) >= 2 {
  2116. // for _, v := range edbNameList {
  2117. // edbName := v.EdbName + "(" + v.SourceName + ")"
  2118. // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
  2119. // if err != nil {
  2120. // br.Msg = "保存失败"
  2121. // br.ErrMsg = "修改指标名称失败,Err:" + err.Error()
  2122. // return
  2123. // }
  2124. // }
  2125. // }
  2126. //}
  2127. //新增操作日志
  2128. {
  2129. edbLog := new(data_manage.EdbInfoLog)
  2130. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2131. edbLog.SourceName = edbInfo.SourceName
  2132. edbLog.Source = edbInfo.Source
  2133. edbLog.EdbCode = edbInfo.EdbCode
  2134. edbLog.EdbName = edbInfo.EdbName
  2135. edbLog.ClassifyId = edbInfo.ClassifyId
  2136. edbLog.SysUserId = sysUser.AdminId
  2137. edbLog.SysUserRealName = sysUser.RealName
  2138. edbLog.CreateTime = time.Now()
  2139. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2140. edbLog.Status = "编辑指标"
  2141. edbLog.Method = this.Ctx.Input.URI()
  2142. go data_manage.AddEdbInfoLog(edbLog)
  2143. }
  2144. //添加es
  2145. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2146. // 修改关联的预测指标基础信息
  2147. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo)
  2148. // 添加钢联指标更新日志
  2149. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2150. go data_stat.AddEdbInfoUpdateLog(req.EdbInfoId, 1, "", sysUser)
  2151. }
  2152. br.Ret = 200
  2153. br.Success = true
  2154. br.Msg = "保存成功"
  2155. br.IsAddLog = true
  2156. }
  2157. // EdbEnInfoEdit
  2158. // @Title 编辑指标英文信息接口
  2159. // @Description 编辑指标英文信息接口
  2160. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  2161. // @router /edb_info/en/edit [post]
  2162. func (this *EdbInfoController) EdbEnInfoEdit() {
  2163. br := new(models.BaseResponse).Init()
  2164. defer func() {
  2165. this.Data["json"] = br
  2166. this.ServeJSON()
  2167. }()
  2168. sysUser := this.SysUser
  2169. if sysUser == nil {
  2170. br.Msg = "请登录"
  2171. br.ErrMsg = "请登录,SysUser Is Empty"
  2172. br.Ret = 408
  2173. return
  2174. }
  2175. var req data_manage.EditEdbEnInfoReq
  2176. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2177. if err != nil {
  2178. br.Msg = "参数解析异常!"
  2179. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2180. return
  2181. }
  2182. req.EdbNameEn = strings.Trim(req.EdbNameEn, " ")
  2183. req.UnitEn = strings.Trim(req.UnitEn, " ")
  2184. if req.EdbInfoId <= 0 {
  2185. br.Msg = "参数错误"
  2186. br.ErrMsg = "指标id小于等于0"
  2187. return
  2188. }
  2189. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2190. if err != nil {
  2191. br.Msg = "获取指标信息失败"
  2192. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2193. return
  2194. }
  2195. if req.EdbNameEn != "" {
  2196. //判断指标名称是否存在
  2197. var condition string
  2198. var pars []interface{}
  2199. condition += " AND edb_info_id<>? "
  2200. pars = append(pars, req.EdbInfoId)
  2201. /*condition += " AND source=? "
  2202. pars = append(pars, edbInfo.Source)*/
  2203. condition += " AND edb_name_en=? "
  2204. pars = append(pars, req.EdbNameEn)
  2205. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2206. if err != nil {
  2207. if err.Error() != utils.ErrNoRow() {
  2208. br.Msg = "判断英文指标名称是否存在失败"
  2209. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2210. return
  2211. }
  2212. }
  2213. if err == nil && edbExist.EdbInfoId > 0 {
  2214. br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在"
  2215. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2216. br.IsSendEmail = false
  2217. return
  2218. }
  2219. }
  2220. err = data_manage.ModifyEdbEnInfo(&req)
  2221. if err != nil {
  2222. br.Msg = "保存失败"
  2223. br.ErrMsg = "修改失败,Err:" + err.Error()
  2224. return
  2225. }
  2226. //新增操作日志
  2227. {
  2228. edbLog := new(data_manage.EdbInfoLog)
  2229. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2230. edbLog.SourceName = edbInfo.SourceName
  2231. edbLog.Source = edbInfo.Source
  2232. edbLog.EdbCode = edbInfo.EdbCode
  2233. edbLog.EdbName = edbInfo.EdbName
  2234. edbLog.ClassifyId = edbInfo.ClassifyId
  2235. edbLog.SysUserId = sysUser.AdminId
  2236. edbLog.SysUserRealName = sysUser.RealName
  2237. edbLog.CreateTime = time.Now()
  2238. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2239. edbLog.Status = "编辑指标英文信息"
  2240. edbLog.Method = this.Ctx.Input.URI()
  2241. go data_manage.AddEdbInfoLog(edbLog)
  2242. }
  2243. //添加es
  2244. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2245. // 修改关联的预测指标基础信息
  2246. if edbInfo.EdbInfoType == 0 {
  2247. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo)
  2248. }
  2249. br.Ret = 200
  2250. br.Success = true
  2251. br.Msg = "保存成功"
  2252. br.IsAddLog = true
  2253. }
  2254. // EdbInfoNewest
  2255. // @Title 获取最新指标接口
  2256. // @Description 获取最新指标接口
  2257. // @Success 200 {object} data_manage.EdbInfoList
  2258. // @router /edb_info/newest [get]
  2259. func (this *EdbInfoController) EdbInfoNewest() {
  2260. br := new(models.BaseResponse).Init()
  2261. defer func() {
  2262. this.Data["json"] = br
  2263. this.ServeJSON()
  2264. }()
  2265. item, err := data_manage.GetEdbInfoByNewest()
  2266. if err != nil && err.Error() != utils.ErrNoRow() {
  2267. br.Msg = "获取最新指标失败"
  2268. br.ErrMsg = "获取最新指标失败,Err:" + err.Error()
  2269. return
  2270. }
  2271. br.Ret = 200
  2272. br.Success = true
  2273. br.Msg = "获取成功"
  2274. br.Data = item
  2275. }
  2276. // EdbInfoRefresh
  2277. // @Title 指标刷新接口
  2278. // @Description 指标刷新接口
  2279. // @Param EdbInfoId query int true "指标id"
  2280. // @Success Ret=200 刷新成功
  2281. // @router /edb_info/refresh [get]
  2282. func (this *EdbInfoController) EdbInfoRefresh() {
  2283. br := new(models.BaseResponse).Init()
  2284. defer func() {
  2285. this.Data["json"] = br
  2286. this.ServeJSON()
  2287. }()
  2288. sysUser := this.SysUser
  2289. if sysUser == nil {
  2290. br.Msg = "请登录"
  2291. br.ErrMsg = "请登录,SysUser Is Empty"
  2292. br.Ret = 408
  2293. return
  2294. }
  2295. edbInfoId, _ := this.GetInt("EdbInfoId")
  2296. if edbInfoId <= 0 {
  2297. br.Msg = "参数错误"
  2298. br.ErrMsg = "参数错误"
  2299. return
  2300. }
  2301. _, err := data_manage.GetEdbInfoById(edbInfoId)
  2302. if err != nil {
  2303. if err.Error() == utils.ErrNoRow() {
  2304. br.Msg = "数据已被删除,请刷新页面"
  2305. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2306. return
  2307. }
  2308. br.Msg = "刷新失败"
  2309. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2310. return
  2311. }
  2312. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false)
  2313. if err != nil {
  2314. br.Msg = "刷新失败"
  2315. br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error()
  2316. return
  2317. }
  2318. br.Ret = 200
  2319. br.Msg = "刷新成功"
  2320. if isAsync {
  2321. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  2322. }
  2323. br.Success = true
  2324. br.IsAddLog = true
  2325. }
  2326. // EdbInfoMove
  2327. // @Title 移动指标接口
  2328. // @Description 移动指标接口
  2329. // @Success 200 {object} data_manage.MoveEdbInfoReq
  2330. // @router /edb_info/move [post]
  2331. func (this *EdbInfoController) EdbInfoMove() {
  2332. br := new(models.BaseResponse).Init()
  2333. defer func() {
  2334. this.Data["json"] = br
  2335. this.ServeJSON()
  2336. }()
  2337. sysUser := this.SysUser
  2338. if sysUser == nil {
  2339. br.Msg = "请登录"
  2340. br.ErrMsg = "请登录,SysUser Is Empty"
  2341. br.Ret = 408
  2342. return
  2343. }
  2344. var req data_manage.MoveEdbInfoReq
  2345. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2346. if err != nil {
  2347. br.Msg = "参数解析异常!"
  2348. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2349. return
  2350. }
  2351. if req.EdbInfoId <= 0 {
  2352. br.Msg = "参数错误"
  2353. br.ErrMsg = "指标id小于等于0"
  2354. return
  2355. }
  2356. if req.ClassifyId <= 0 {
  2357. br.Msg = "请选择分类"
  2358. return
  2359. }
  2360. //判断分类是否存在
  2361. count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId)
  2362. if count <= 0 {
  2363. br.Msg = "分类已被删除,不可移动,请刷新页面"
  2364. return
  2365. }
  2366. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2367. if err != nil {
  2368. br.Msg = "移动失败"
  2369. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2370. return
  2371. }
  2372. // 移动权限校验
  2373. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType)
  2374. if !button.MoveButton {
  2375. br.Msg = "无权限操作"
  2376. br.IsSendEmail = false
  2377. return
  2378. }
  2379. //如果改变了分类,那么移动该指标数据
  2380. if edbInfo.ClassifyId != req.ClassifyId {
  2381. err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId)
  2382. if err != nil {
  2383. br.Msg = "移动失败"
  2384. br.ErrMsg = "移动指标失败,Err:" + err.Error()
  2385. return
  2386. }
  2387. }
  2388. updateCol := make([]string, 0)
  2389. //如果有传入 上一个兄弟节点分类id
  2390. if req.PrevEdbInfoId > 0 {
  2391. prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId)
  2392. if err != nil {
  2393. br.Msg = "移动失败"
  2394. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  2395. return
  2396. }
  2397. //如果是移动在两个兄弟节点之间
  2398. if req.NextEdbInfoId > 0 {
  2399. //下一个兄弟节点
  2400. nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId)
  2401. if err != nil {
  2402. br.Msg = "移动失败"
  2403. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  2404. return
  2405. }
  2406. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  2407. if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort {
  2408. //变更兄弟节点的排序
  2409. updateSortStr := `sort + 2`
  2410. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2411. } else {
  2412. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  2413. if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 {
  2414. //变更兄弟节点的排序
  2415. updateSortStr := `sort + 1`
  2416. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2417. }
  2418. }
  2419. }
  2420. edbInfo.Sort = prevEdbInfo.Sort + 1
  2421. edbInfo.ModifyTime = time.Now()
  2422. updateCol = append(updateCol, "Sort", "ModifyTime")
  2423. } else {
  2424. firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId)
  2425. if err != nil && err.Error() != utils.ErrNoRow() {
  2426. br.Msg = "移动失败"
  2427. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2428. return
  2429. }
  2430. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2431. if firstClassify != nil && firstClassify.Sort == 0 {
  2432. updateSortStr := ` sort + 1 `
  2433. _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr)
  2434. }
  2435. edbInfo.Sort = 0 //那就是排在第一位
  2436. edbInfo.ModifyTime = time.Now()
  2437. updateCol = append(updateCol, "Sort", "ModifyTime")
  2438. }
  2439. //更新
  2440. if len(updateCol) > 0 {
  2441. err = edbInfo.Update(updateCol)
  2442. if err != nil {
  2443. br.Msg = "移动失败"
  2444. br.ErrMsg = "修改失败,Err:" + err.Error()
  2445. return
  2446. }
  2447. }
  2448. if err != nil {
  2449. br.Msg = "移动失败"
  2450. br.ErrMsg = "修改失败,Err:" + err.Error()
  2451. return
  2452. }
  2453. //新增操作日志
  2454. {
  2455. edbLog := new(data_manage.EdbInfoLog)
  2456. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2457. edbLog.SourceName = edbInfo.SourceName
  2458. edbLog.Source = edbInfo.Source
  2459. edbLog.EdbCode = edbInfo.EdbCode
  2460. edbLog.EdbName = edbInfo.EdbName
  2461. edbLog.ClassifyId = edbInfo.ClassifyId
  2462. edbLog.SysUserId = sysUser.AdminId
  2463. edbLog.SysUserRealName = sysUser.RealName
  2464. edbLog.CreateTime = time.Now()
  2465. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2466. edbLog.Status = "移动指标"
  2467. edbLog.Method = this.Ctx.Input.URI()
  2468. go data_manage.AddEdbInfoLog(edbLog)
  2469. }
  2470. br.Ret = 200
  2471. br.Success = true
  2472. br.Msg = "移动成功"
  2473. }
  2474. // EdbInfoDetail
  2475. // @Title 获取指标详情
  2476. // @Description 获取指标详情接口
  2477. // @Param EdbInfoId query int true "指标id"
  2478. // @Success 200 {object} data_manage.EdbInfo
  2479. // @router /edb_info/detail [get]
  2480. func (this *EdbInfoController) EdbInfoDetail() {
  2481. br := new(models.BaseResponse).Init()
  2482. defer func() {
  2483. this.Data["json"] = br
  2484. this.ServeJSON()
  2485. }()
  2486. sysUser := this.SysUser
  2487. if sysUser == nil {
  2488. br.Msg = "请登录"
  2489. br.ErrMsg = "请登录,SysUser Is Empty"
  2490. br.Ret = 408
  2491. return
  2492. }
  2493. edbInfoId, _ := this.GetInt("EdbInfoId")
  2494. if edbInfoId <= 0 {
  2495. br.Msg = "参数错误"
  2496. br.ErrMsg = "参数错误"
  2497. return
  2498. }
  2499. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  2500. if err != nil {
  2501. br.Msg = "获取失败"
  2502. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2503. return
  2504. }
  2505. var resp data_manage.EdbInfoFullClassify
  2506. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  2507. if err != nil {
  2508. br.Msg = err.Error()
  2509. br.ErrMsg = errMsg
  2510. return
  2511. }
  2512. resp.EdbInfo = edbInfo
  2513. resp.ClassifyList = classifyList
  2514. br.Ret = 200
  2515. br.Success = true
  2516. br.Msg = "获取成功"
  2517. br.Data = resp
  2518. }
  2519. // EdbInfoFilter
  2520. // @Title 指标筛选接口
  2521. // @Description 指标筛选接口
  2522. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  2523. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标"
  2524. // @Param PageSize query int true "每页数据条数"
  2525. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2526. // @Success 200 {object} data_manage.EdbInfoList
  2527. // @router /edb_info/filter [get]
  2528. func (this *EdbInfoController) EdbInfoFilter() {
  2529. br := new(models.BaseResponse).Init()
  2530. defer func() {
  2531. this.Data["json"] = br
  2532. this.ServeJSON()
  2533. }()
  2534. keyWord := this.GetString("KeyWord")
  2535. filterSource, _ := this.GetInt("FilterSource")
  2536. if filterSource <= 0 {
  2537. filterSource = 1
  2538. }
  2539. var pars []interface{}
  2540. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  2541. // 获取当前账号的不可见指标
  2542. {
  2543. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2544. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  2545. if err != nil && err.Error() != utils.ErrNoRow() {
  2546. br.Msg = "获取失败"
  2547. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  2548. return
  2549. }
  2550. for _, v := range confList {
  2551. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  2552. }
  2553. }
  2554. var keyWordArr []string
  2555. keyWordArr = append(keyWordArr, keyWord)
  2556. if keyWord != "" {
  2557. newKeyWord := strings.Split(keyWord, " ")
  2558. keyWordArr = append(keyWordArr, newKeyWord...)
  2559. }
  2560. //var err error
  2561. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  2562. //if keyWord == "" {
  2563. // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars)
  2564. // if err != nil && err.Error() != utils.ErrNoRow() {
  2565. // br.Success = true
  2566. // br.Msg = "获取指标信息失败"
  2567. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2568. // return
  2569. // }
  2570. //} else {
  2571. // //获取指标信息
  2572. // indexName := utils.DATA_INDEX_NAME
  2573. // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource)
  2574. // if err != nil && err.Error() != utils.ErrNoRow() {
  2575. // br.Success = true
  2576. // br.Msg = "获取指标信息失败"
  2577. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2578. // return
  2579. // }
  2580. //}
  2581. var baseCondition string
  2582. // 无权限指标id
  2583. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  2584. if lenNoPermissionEdbInfoIdList > 0 {
  2585. baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  2586. pars = append(pars, noPermissionEdbInfoIdList)
  2587. }
  2588. existMap := make(map[int]string)
  2589. for _, v := range keyWordArr {
  2590. v = strings.Replace(v, " ", "%", -1)
  2591. var condition string
  2592. if filterSource == 2 {
  2593. condition += ` AND frequency='月度' `
  2594. }
  2595. if filterSource == 3 {
  2596. condition += ` AND frequency <> '日度' `
  2597. }
  2598. if filterSource == 4 {
  2599. condition += ` AND edb_type = 1 `
  2600. }
  2601. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  2602. condition += conditionWhere + baseCondition
  2603. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  2604. if err != nil && err.Error() != utils.ErrNoRow() {
  2605. br.Success = true
  2606. br.Msg = "获取指标信息失败"
  2607. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2608. return
  2609. }
  2610. for _, nv := range newEdbInfoList {
  2611. if _, ok := existMap[nv.EdbInfoId]; !ok {
  2612. edbInfoList = append(edbInfoList, nv)
  2613. }
  2614. existMap[nv.EdbInfoId] = nv.EdbCode
  2615. }
  2616. }
  2617. if edbInfoList == nil {
  2618. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  2619. }
  2620. edbInfoListLen := len(edbInfoList)
  2621. for i := 0; i < edbInfoListLen; i++ {
  2622. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  2623. }
  2624. for i := 0; i < edbInfoListLen; i++ {
  2625. for j := 0; j < edbInfoListLen; j++ {
  2626. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  2627. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  2628. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  2629. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  2630. }
  2631. }
  2632. }
  2633. //新增搜索词记录
  2634. {
  2635. searchKeyword := new(data_manage.SearchKeyword)
  2636. searchKeyword.KeyWord = keyWord
  2637. searchKeyword.CreateTime = time.Now()
  2638. go data_manage.AddSearchKeyword(searchKeyword)
  2639. }
  2640. br.Ret = 200
  2641. br.Success = true
  2642. br.Msg = "获取成功"
  2643. br.Data = edbInfoList
  2644. }
  2645. // EdbInfoFilterByEs
  2646. // @Title 指标筛选接口
  2647. // @Description 指标筛选接口
  2648. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  2649. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  2650. // @Param Frequency query string false "频度"
  2651. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  2652. // @Param PageSize query int true "每页数据条数"
  2653. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2654. // @Success 200 {object} data_manage.EdbInfoList
  2655. // @router /edb_info/filter_by_es [get]
  2656. func (this *EdbInfoController) EdbInfoFilterByEs() {
  2657. br := new(models.BaseResponse).Init()
  2658. defer func() {
  2659. this.Data["json"] = br
  2660. this.ServeJSON()
  2661. }()
  2662. pageSize, _ := this.GetInt("PageSize")
  2663. currentIndex, _ := this.GetInt("CurrentIndex")
  2664. var total int64
  2665. var startSize int
  2666. if pageSize <= 0 {
  2667. pageSize = utils.PageSize20
  2668. }
  2669. if currentIndex <= 0 {
  2670. currentIndex = 1
  2671. }
  2672. startSize = paging.StartIndex(currentIndex, pageSize)
  2673. keyWord := this.GetString("KeyWord")
  2674. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  2675. filterSource, _ := this.GetInt("FilterSource")
  2676. if filterSource <= 0 {
  2677. filterSource = 1
  2678. }
  2679. //指标来源
  2680. source, _ := this.GetInt("Source")
  2681. frequency := this.GetString("Frequency") //频度
  2682. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  2683. var edbInfoList []*data_manage.EdbInfoList
  2684. var err error
  2685. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  2686. // 获取当前账号的不可见指标
  2687. {
  2688. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2689. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  2690. if err != nil && err.Error() != utils.ErrNoRow() {
  2691. br.Msg = "获取失败"
  2692. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  2693. return
  2694. }
  2695. for _, v := range confList {
  2696. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  2697. }
  2698. }
  2699. if keyWord != "" {
  2700. var keyWordArr []string
  2701. keyWordArr = append(keyWordArr, keyWord)
  2702. newKeyWord := strings.Split(keyWord, " ")
  2703. keyWordArr = append(keyWordArr, newKeyWord...)
  2704. // 普通的搜索
  2705. if !isAddPredictEdb {
  2706. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
  2707. } else {
  2708. // 允许添加预测指标的搜索
  2709. total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize)
  2710. }
  2711. } else {
  2712. var condition string
  2713. var pars []interface{}
  2714. // 普通指标
  2715. condition += ` AND edb_info_type = ? `
  2716. pars = append(pars, 0)
  2717. // 无权限指标id
  2718. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  2719. if lenNoPermissionEdbInfoIdList > 0 {
  2720. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  2721. pars = append(pars, noPermissionEdbInfoIdList)
  2722. }
  2723. switch filterSource {
  2724. case 2:
  2725. condition += ` AND frequency='月度' `
  2726. case 3:
  2727. condition += ` AND frequency <> '日度' `
  2728. case 4:
  2729. condition += ` AND edb_type = 1 `
  2730. case 5:
  2731. condition += ` AND source = 6 ` //来源(同比值)
  2732. case 6:
  2733. condition += ` AND frequency != ? `
  2734. pars = append(pars, "年度")
  2735. }
  2736. //频度
  2737. if frequency != "" {
  2738. condition += ` AND frequency = ? `
  2739. pars = append(pars, frequency)
  2740. }
  2741. // 查询只允许添加预测指标的搜索
  2742. if isAddPredictEdb {
  2743. condition += ` AND frequency in ("日度","周度","月度") `
  2744. }
  2745. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  2746. }
  2747. if err != nil {
  2748. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  2749. }
  2750. page := paging.GetPaging(currentIndex, pageSize, int(total))
  2751. edbInfoListLen := len(edbInfoList)
  2752. for i := 0; i < edbInfoListLen; i++ {
  2753. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  2754. }
  2755. for i := 0; i < edbInfoListLen; i++ {
  2756. for j := 0; j < edbInfoListLen; j++ {
  2757. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  2758. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  2759. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  2760. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  2761. }
  2762. }
  2763. }
  2764. //新增搜索词记录
  2765. {
  2766. searchKeyword := new(data_manage.SearchKeyword)
  2767. searchKeyword.KeyWord = keyWord
  2768. searchKeyword.CreateTime = time.Now()
  2769. go data_manage.AddSearchKeyword(searchKeyword)
  2770. }
  2771. resp := data_manage.EdbInfoFilterDataResp{
  2772. Paging: page,
  2773. List: edbInfoList,
  2774. }
  2775. br.Ret = 200
  2776. br.Success = true
  2777. br.Msg = "获取成功"
  2778. br.Data = resp
  2779. }
  2780. func (this *EdbInfoController) EdbInfoFilter2() {
  2781. br := new(models.BaseResponse).Init()
  2782. defer func() {
  2783. this.Data["json"] = br
  2784. this.ServeJSON()
  2785. }()
  2786. keyWord := this.GetString("KeyWord")
  2787. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  2788. filterSource, _ := this.GetInt("FilterSource")
  2789. if filterSource <= 0 {
  2790. filterSource = 1
  2791. }
  2792. var pars []interface{}
  2793. //if keyWord != "" {
  2794. // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  2795. //}
  2796. var keyWordArr []string
  2797. keyWordArr = append(keyWordArr, keyWord)
  2798. if keyWord != "" {
  2799. newKeyWord := strings.Split(keyWord, " ")
  2800. keyWordArr = append(keyWordArr, newKeyWord...)
  2801. }
  2802. keywordLen := len(keyWordArr)
  2803. ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen)
  2804. searchWait := sync.WaitGroup{}
  2805. searchWait.Add(keywordLen)
  2806. for index, v := range keyWordArr {
  2807. v = strings.Replace(v, " ", "%", -1)
  2808. var condition string
  2809. if filterSource == 2 {
  2810. condition += ` AND frequency='月度' `
  2811. }
  2812. if filterSource == 3 {
  2813. condition += ` AND frequency <> '日度' `
  2814. }
  2815. if filterSource == 4 {
  2816. condition += ` AND edb_type = 1 `
  2817. }
  2818. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  2819. condition += conditionWhere
  2820. go searchEdbInfoFilter(condition, pars, index, ch, &searchWait)
  2821. }
  2822. searchWait.Wait()
  2823. newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList)
  2824. i := 0
  2825. for tmpEdbInfoList := range ch {
  2826. i++
  2827. for k, v := range tmpEdbInfoList {
  2828. newEdbInfoListMap[k] = v
  2829. }
  2830. if i == keywordLen {
  2831. break
  2832. }
  2833. }
  2834. close(ch)
  2835. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  2836. existMap := make(map[int]string)
  2837. for i := 0; i < keywordLen; i++ {
  2838. if newEdbInfoList, ok := newEdbInfoListMap[i]; ok {
  2839. for _, nv := range newEdbInfoList {
  2840. if _, ok := existMap[nv.EdbInfoId]; !ok {
  2841. edbInfoList = append(edbInfoList, nv)
  2842. }
  2843. existMap[nv.EdbInfoId] = nv.EdbCode
  2844. }
  2845. }
  2846. }
  2847. if edbInfoList == nil {
  2848. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  2849. }
  2850. edbInfoListLen := len(edbInfoList)
  2851. for i := 0; i < edbInfoListLen; i++ {
  2852. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  2853. }
  2854. for i := 0; i < edbInfoListLen; i++ {
  2855. for j := 0; j < edbInfoListLen; j++ {
  2856. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  2857. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  2858. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  2859. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  2860. }
  2861. }
  2862. }
  2863. //新增搜索词记录
  2864. {
  2865. searchKeyword := new(data_manage.SearchKeyword)
  2866. searchKeyword.KeyWord = keyWord
  2867. searchKeyword.CreateTime = time.Now()
  2868. go data_manage.AddSearchKeyword(searchKeyword)
  2869. }
  2870. br.Ret = 200
  2871. br.Success = true
  2872. br.Msg = "获取成功"
  2873. br.Data = edbInfoList
  2874. }
  2875. func searchEdbInfoFilter(condition string, pars []interface{}, i int, ch chan map[int][]*data_manage.EdbInfoList, searchWait *sync.WaitGroup) (newEdbInfoListMap map[int][]*data_manage.EdbInfoList, err error) {
  2876. newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList)
  2877. defer func() {
  2878. if err != nil {
  2879. go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3)
  2880. //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  2881. }
  2882. ch <- newEdbInfoListMap
  2883. searchWait.Done()
  2884. }()
  2885. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  2886. newEdbInfoListMap[i] = newEdbInfoList
  2887. return
  2888. }
  2889. // EdbInfoAllRefresh
  2890. // @Title 指标全部刷新接口
  2891. // @Description 指标全部刷新接口
  2892. // @Param EdbInfoId query int true "指标id"
  2893. // @Success Ret=200 全部刷新成功
  2894. // @router /edb_info/refresh/all [get]
  2895. func (this *EdbInfoController) EdbInfoAllRefresh() {
  2896. br := new(models.BaseResponse).Init()
  2897. defer func() {
  2898. this.Data["json"] = br
  2899. this.ServeJSON()
  2900. }()
  2901. sysUser := this.SysUser
  2902. if sysUser == nil {
  2903. br.Msg = "请登录"
  2904. br.ErrMsg = "请登录,SysUser Is Empty"
  2905. br.Ret = 408
  2906. return
  2907. }
  2908. edbInfoId, _ := this.GetInt("EdbInfoId")
  2909. if edbInfoId <= 0 {
  2910. br.Msg = "参数错误"
  2911. br.ErrMsg = "参数错误"
  2912. return
  2913. }
  2914. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  2915. if err != nil {
  2916. if err.Error() == utils.ErrNoRow() {
  2917. br.Msg = "数据已被删除,请刷新页面"
  2918. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2919. return
  2920. }
  2921. br.Msg = "刷新失败"
  2922. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2923. return
  2924. }
  2925. if edbInfo == nil {
  2926. br.Msg = "数据已被删除,请刷新页面"
  2927. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2928. return
  2929. }
  2930. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true)
  2931. if err != nil {
  2932. br.Msg = "刷新失败"
  2933. br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error()
  2934. return
  2935. }
  2936. br.Ret = 200
  2937. br.Success = true
  2938. br.Msg = "刷新成功"
  2939. if isAsync {
  2940. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  2941. }
  2942. }
  2943. // EdbInfoData
  2944. // @Title 获取指标数据
  2945. // @Description 获取指标数据
  2946. // @Param EdbInfoId query int true "指标ID"
  2947. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  2948. // @Param StartDate query string true "自定义开始日期"
  2949. // @Param EndDate query string true "自定义结束日期"
  2950. // @Success 200 {object} data_manage.EdbInfoDataResp
  2951. // @router /edb_info/data [get]
  2952. func (this *ChartInfoController) EdbInfoData() {
  2953. br := new(models.BaseResponse).Init()
  2954. defer func() {
  2955. this.Data["json"] = br
  2956. this.ServeJSON()
  2957. }()
  2958. sysUser := this.SysUser
  2959. if sysUser == nil {
  2960. br.Msg = "请登录"
  2961. br.ErrMsg = "请登录,SysUser Is Empty"
  2962. br.Ret = 408
  2963. return
  2964. }
  2965. edbInfoId, _ := this.GetInt("EdbInfoId")
  2966. if edbInfoId <= 0 {
  2967. br.Msg = "参数错误"
  2968. return
  2969. }
  2970. dateType, _ := this.GetInt("DateType")
  2971. if dateType <= 0 {
  2972. dateType = 3
  2973. }
  2974. edbInfoType, _ := this.GetInt("EdbInfoType")
  2975. if edbInfoType < 0 {
  2976. edbInfoType = 1
  2977. }
  2978. startDate := this.GetString("StartDate")
  2979. endDate := this.GetString("EndDate")
  2980. startYear, _ := this.GetInt("StartYear")
  2981. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  2982. if err != nil {
  2983. if err.Error() == utils.ErrNoRow() {
  2984. br.Ret = 200
  2985. return
  2986. }
  2987. br.Msg = "获取失败"
  2988. br.ErrMsg = "获取失败,Err:" + err.Error()
  2989. return
  2990. }
  2991. maxYear := 0
  2992. if edbInfo.LatestDate != "" {
  2993. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  2994. maxYear = latestDateT.Year()
  2995. }
  2996. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  2997. dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfoId, startDate, endDate)
  2998. if err != nil {
  2999. br.Msg = "获取失败"
  3000. br.ErrMsg = "获取失败,Err:" + err.Error()
  3001. return
  3002. }
  3003. fullEdb := new(data_manage.EdbInfoFullClassify)
  3004. resp := new(data_manage.EdbInfoDataFullClassifyResp)
  3005. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  3006. if err != nil {
  3007. br.Msg = err.Error()
  3008. br.ErrMsg = errMsg
  3009. return
  3010. }
  3011. fullEdb.EdbInfo = edbInfo
  3012. fullEdb.ClassifyList = classifyList
  3013. resp.EdbInfo = fullEdb
  3014. resp.DataList = dataList
  3015. br.Ret = 200
  3016. br.Success = true
  3017. br.Msg = "获取成功"
  3018. br.Data = resp
  3019. }
  3020. // EdbInfoReplaceCheck
  3021. // @Title 指标一键刷新接口
  3022. // @Description 指标一键刷新接口
  3023. // @Success Ret=200 更新成功
  3024. // @router /edb_info/replace/check [post]
  3025. func (this *EdbInfoController) EdbInfoReplaceCheck() {
  3026. br := new(models.BaseResponse).Init()
  3027. setNxKey := "EDB_INFO_REPLACE"
  3028. defer func() {
  3029. this.Data["json"] = br
  3030. this.ServeJSON()
  3031. }()
  3032. status := 0
  3033. if utils.Rc.IsExist(setNxKey) {
  3034. status = 1
  3035. } else {
  3036. status = 2
  3037. }
  3038. br.Ret = 200
  3039. br.Success = true
  3040. br.Msg = "检测成功"
  3041. br.Data = status
  3042. }
  3043. // EdbInfoReplace
  3044. // @Title 替换指标
  3045. // @Description 替换指标
  3046. // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
  3047. // @Success 200 {object} data_manage.EdbInfoDataResp
  3048. // @router /edb_info/replace [post]
  3049. func (this *ChartInfoController) EdbInfoReplace() {
  3050. br := new(models.BaseResponse).Init()
  3051. setNxKey := "EDB_INFO_REPLACE"
  3052. deleteCache := true
  3053. defer func() {
  3054. if deleteCache {
  3055. utils.Rc.Delete(setNxKey)
  3056. }
  3057. this.Data["json"] = br
  3058. this.ServeJSON()
  3059. }()
  3060. sysUser := this.SysUser
  3061. if sysUser == nil {
  3062. br.Msg = "请登录"
  3063. br.ErrMsg = "请登录,SysUser Is Empty"
  3064. br.Ret = 408
  3065. return
  3066. }
  3067. if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
  3068. deleteCache = false
  3069. br.Msg = "当前正在替换中,请耐心等待!"
  3070. br.IsSendEmail = false
  3071. return
  3072. }
  3073. var req data_manage.EdbInfoReplaceReq
  3074. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3075. if err != nil {
  3076. br.Msg = "参数解析异常!"
  3077. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3078. return
  3079. }
  3080. if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
  3081. br.Msg = "参数错误!"
  3082. br.ErrMsg = "参数错误,指标id为0"
  3083. return
  3084. }
  3085. oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
  3086. if err != nil {
  3087. br.Msg = "替换失败!"
  3088. br.ErrMsg = "获取原指标失败,Err:" + err.Error()
  3089. return
  3090. }
  3091. newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
  3092. if err != nil {
  3093. br.Msg = "替换失败!"
  3094. br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
  3095. return
  3096. }
  3097. //if oldEdbInfo.EdbType != 1 {
  3098. // br.Msg = "原指标为计算指标,不可替换!"
  3099. // br.ErrMsg = "原指标为计算指标,不可替换!"
  3100. // return
  3101. //}
  3102. //
  3103. //if newEdbInfo.EdbType != 1 {
  3104. // br.Msg = "替换指标为计算指标,不可替换!"
  3105. // br.ErrMsg = "替换指标为计算指标,不可替换!"
  3106. // return
  3107. //}
  3108. if oldEdbInfo.Frequency != newEdbInfo.Frequency {
  3109. br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3110. br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3111. return
  3112. }
  3113. sysAdminId := sysUser.AdminId
  3114. //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3115. _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3116. //msgContent := ``
  3117. isFail := false
  3118. var errmsg string
  3119. if err != nil {
  3120. //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换失败,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n " + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
  3121. isFail = true
  3122. errmsg = "replace err:" + err.Error()
  3123. } else {
  3124. //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换成功,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n" + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
  3125. isFail = false
  3126. }
  3127. // 添加站内信息
  3128. //{
  3129. // msgItem := new(company.CompanyApprovalMessage)
  3130. // msgItem.CreateUserId = sysAdminId
  3131. // msgItem.ReceiveUserId = sysAdminId
  3132. // msgItem.MessageStatus = 0
  3133. // msgItem.Remark = "指标替换"
  3134. // msgItem.OperationStatus = 1
  3135. // msgItem.Content = msgContent
  3136. // msgItem.CreateTime = time.Now()
  3137. // msgItem.ModifyTime = time.Now()
  3138. // msgItem.MessageType = 3 //1:申请消息,2:审批结果,3:文字消息
  3139. // msgItem.SourceType = 4 //消息来源
  3140. // err = company.AddCompanyApprovalMessage(msgItem)
  3141. //}
  3142. if isFail {
  3143. br.Msg = "替换失败"
  3144. br.ErrMsg = "替换失败 err:" + errmsg
  3145. } else {
  3146. br.Msg = "替换成功"
  3147. br.ErrMsg = "替换成功"
  3148. br.Ret = 200
  3149. }
  3150. br.IsAddLog = true
  3151. return
  3152. }
  3153. // RelationChartList
  3154. // @Title 获取ETA指标关联的图表列表接口
  3155. // @Description 获取ETA指标关联的图表列表接口
  3156. // @Param PageSize query int true "每页数据条数"
  3157. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3158. // @Param EdbInfoId query int true "指标id"
  3159. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3160. // @Success 200 {object} data_manage.ChartListResp
  3161. // @router /edb_info/relation/chart_list [get]
  3162. func (this *EdbInfoController) RelationChartList() {
  3163. br := new(models.BaseResponse).Init()
  3164. defer func() {
  3165. this.Data["json"] = br
  3166. this.ServeJSON()
  3167. }()
  3168. sysUser := this.SysUser
  3169. if sysUser == nil {
  3170. br.Msg = "请登录"
  3171. br.ErrMsg = "请登录,SysUser Is Empty"
  3172. br.Ret = 408
  3173. return
  3174. }
  3175. edbInfoId, _ := this.GetInt("EdbInfoId")
  3176. pageSize, _ := this.GetInt("PageSize")
  3177. currentIndex, _ := this.GetInt("CurrentIndex")
  3178. resp := data_manage.ChartListResp{}
  3179. var total int
  3180. page := paging.GetPaging(currentIndex, pageSize, total)
  3181. var startSize int
  3182. if pageSize <= 0 {
  3183. pageSize = utils.PageSize20
  3184. }
  3185. if currentIndex <= 0 {
  3186. currentIndex = 1
  3187. }
  3188. startSize = paging.StartIndex(currentIndex, pageSize)
  3189. var condition string
  3190. var pars []interface{}
  3191. if edbInfoId <= 0 {
  3192. br.Msg = "请选择指标"
  3193. br.ErrMsg = "请选择指标"
  3194. br.IsSendEmail = false
  3195. return
  3196. }
  3197. // 关联指标
  3198. condition += ` AND b.edb_info_id = ? `
  3199. pars = append(pars, edbInfoId)
  3200. //只看我的
  3201. isShowMe, _ := this.GetBool("IsShowMe")
  3202. if isShowMe {
  3203. condition += ` AND a.sys_user_id = ? `
  3204. pars = append(pars, sysUser.AdminId)
  3205. }
  3206. // 获取当前账号的不可见图表
  3207. noPermissionChartIdList := make([]int, 0)
  3208. {
  3209. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3210. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  3211. if err != nil && err.Error() != utils.ErrNoRow() {
  3212. br.Msg = "获取失败"
  3213. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3214. return
  3215. }
  3216. for _, v := range confList {
  3217. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  3218. }
  3219. }
  3220. noPermissionChartIdNum := len(noPermissionChartIdList)
  3221. if noPermissionChartIdNum > 0 {
  3222. condition += ` AND a.chart_info_id not in (` + utils.GetOrmInReplace(noPermissionChartIdNum) + `) `
  3223. pars = append(pars, noPermissionChartIdList)
  3224. }
  3225. //获取关联图表列表
  3226. list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
  3227. if err != nil && err.Error() != utils.ErrNoRow() {
  3228. br.Success = true
  3229. br.Msg = "获取图表信息失败"
  3230. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3231. return
  3232. }
  3233. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3234. items := make([]*data_manage.ChartInfoView, 0)
  3235. resp.Paging = page
  3236. resp.List = items
  3237. br.Ret = 200
  3238. br.Success = true
  3239. br.Msg = "获取成功"
  3240. return
  3241. }
  3242. // 获取关联图表总数
  3243. dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
  3244. if err != nil && err.Error() != utils.ErrNoRow() {
  3245. br.Msg = "获取指标信息失败"
  3246. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3247. return
  3248. }
  3249. // 获取MY ETA 图表,用来判断是否加入我的图库
  3250. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  3251. if err != nil && err.Error() != utils.ErrNoRow() {
  3252. br.Msg = "获取图表信息失败"
  3253. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  3254. return
  3255. }
  3256. myChartMap := make(map[int]*data_manage.MyChartView)
  3257. for _, v := range myChartList {
  3258. myChartMap[v.ChartInfoId] = v
  3259. }
  3260. listLen := len(list)
  3261. for i := 0; i < listLen; i++ {
  3262. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  3263. list[i].IsAdd = true
  3264. list[i].MyChartId = existItem.MyChartId
  3265. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  3266. }
  3267. }
  3268. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  3269. resp.Paging = page
  3270. resp.List = list
  3271. br.Ret = 200
  3272. br.Success = true
  3273. br.Msg = "获取成功"
  3274. br.Data = resp
  3275. }
  3276. // RelationEdbList
  3277. // @Title 获取ETA指标关联的指标列表接口
  3278. // @Description 获取ETA指标关联的指标列表接口
  3279. // @Param PageSize query int true "每页数据条数"
  3280. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3281. // @Param EdbInfoId query int true "指标id"
  3282. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3283. // @Success 200 {object} data_manage.ChartListResp
  3284. // @router /edb_info/relation/edbinfo_list [get]
  3285. func (this *EdbInfoController) RelationEdbList() {
  3286. br := new(models.BaseResponse).Init()
  3287. defer func() {
  3288. this.Data["json"] = br
  3289. this.ServeJSON()
  3290. }()
  3291. sysUser := this.SysUser
  3292. if sysUser == nil {
  3293. br.Msg = "请登录"
  3294. br.ErrMsg = "请登录,SysUser Is Empty"
  3295. br.Ret = 408
  3296. return
  3297. }
  3298. edbInfoId, _ := this.GetInt("EdbInfoId")
  3299. pageSize, _ := this.GetInt("PageSize")
  3300. currentIndex, _ := this.GetInt("CurrentIndex")
  3301. resp := data_manage.RelationEdbInfoListResp{}
  3302. var total int
  3303. page := paging.GetPaging(currentIndex, pageSize, total)
  3304. var startSize int
  3305. if pageSize <= 0 {
  3306. pageSize = utils.PageSize20
  3307. }
  3308. if currentIndex <= 0 {
  3309. currentIndex = 1
  3310. }
  3311. startSize = paging.StartIndex(currentIndex, pageSize)
  3312. var condition string
  3313. var pars []interface{}
  3314. if edbInfoId <= 0 {
  3315. br.Msg = "请选择指标"
  3316. br.ErrMsg = "请选择指标"
  3317. br.IsSendEmail = false
  3318. return
  3319. }
  3320. // 关联指标
  3321. condition += ` AND b.from_edb_info_id = ? `
  3322. pars = append(pars, edbInfoId)
  3323. //只看我的
  3324. isShowMe, _ := this.GetBool("IsShowMe")
  3325. if isShowMe {
  3326. condition += ` AND a.sys_user_id = ? `
  3327. pars = append(pars, sysUser.AdminId)
  3328. }
  3329. // 获取当前账号的不可见图表
  3330. noPermissionEdbIdList := make([]int, 0)
  3331. {
  3332. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3333. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3334. if err != nil && err.Error() != utils.ErrNoRow() {
  3335. br.Msg = "获取失败"
  3336. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3337. return
  3338. }
  3339. for _, v := range confList {
  3340. noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
  3341. }
  3342. }
  3343. noPermissionEdbIdNum := len(noPermissionEdbIdList)
  3344. if noPermissionEdbIdNum > 0 {
  3345. condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
  3346. pars = append(pars, noPermissionEdbIdList)
  3347. }
  3348. //获取关联图表列表
  3349. list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
  3350. if err != nil && err.Error() != utils.ErrNoRow() {
  3351. br.Success = true
  3352. br.Msg = "获取图表信息失败"
  3353. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3354. return
  3355. }
  3356. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3357. items := make([]*data_manage.ChartEdbInfoMapping, 0)
  3358. resp.Paging = page
  3359. resp.List = items
  3360. br.Ret = 200
  3361. br.Success = true
  3362. br.Msg = "获取成功"
  3363. return
  3364. }
  3365. // 获取关联图表总数
  3366. dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
  3367. if err != nil && err.Error() != utils.ErrNoRow() {
  3368. br.Msg = "获取指标信息失败"
  3369. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3370. return
  3371. }
  3372. if err != nil {
  3373. br.Msg = "获取失败"
  3374. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3375. return
  3376. }
  3377. edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
  3378. for _, v := range list {
  3379. item := new(data_manage.ChartEdbInfoMapping)
  3380. item.EdbInfoId = v.EdbInfoId
  3381. item.SourceName = v.SourceName
  3382. item.Source = v.Source
  3383. item.EdbCode = v.EdbCode
  3384. item.EdbName = v.EdbName
  3385. item.EdbNameEn = v.EdbNameEn
  3386. item.Frequency = v.Frequency
  3387. item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
  3388. if v.Unit != `无` {
  3389. item.Unit = v.Unit
  3390. }
  3391. item.UnitEn = v.UnitEn
  3392. item.StartDate = v.StartDate
  3393. item.EndDate = v.EndDate
  3394. item.ModifyTime = v.ModifyTime
  3395. item.IsAxis = 1
  3396. item.LeadValue = 0
  3397. item.LeadUnit = ""
  3398. item.ChartEdbMappingId = 0
  3399. item.ChartInfoId = 0
  3400. item.IsOrder = false
  3401. item.EdbInfoType = v.EdbInfoType
  3402. item.EdbInfoCategoryType = v.EdbInfoType
  3403. item.ChartStyle = ""
  3404. item.ChartColor = ""
  3405. item.ChartWidth = 0
  3406. item.MaxData = v.MaxValue
  3407. item.MinData = v.MinValue
  3408. item.LatestValue = v.LatestValue
  3409. item.LatestDate = v.LatestDate
  3410. item.UniqueCode = v.UniqueCode
  3411. item.ClassifyId = v.ClassifyId
  3412. dataList := make([]*data_manage.EdbDataList, 0)
  3413. if v.EdbInfoType == 0 {
  3414. dataList, err = data_manage.GetEdbDataList(v.Source, v.EdbInfoId, "", "")
  3415. } else {
  3416. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
  3417. }
  3418. if err != nil {
  3419. br.Msg = "获取失败"
  3420. br.Msg = "获取失败,Err:" + err.Error()
  3421. return
  3422. }
  3423. item.DataList = dataList
  3424. edbList = append(edbList, item)
  3425. }
  3426. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  3427. resp.Paging = page
  3428. resp.List = edbList
  3429. br.Ret = 200
  3430. br.Success = true
  3431. br.Msg = "获取成功"
  3432. br.Data = resp
  3433. }
  3434. // MoveEdbChartList
  3435. // @Title 获取指标/图表创建人列表数据接口
  3436. // @Description 获取指标/图表创建人列表数据接口
  3437. // @Param PageSize query int true "每页数据条数"
  3438. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3439. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  3440. // @Param Keyword query string false "关键字,code或者名称"
  3441. // @Param Classify query string false "分类id"
  3442. // @Param UserId query int false "创建人id"
  3443. // @Success 200 {object} data_manage.ChartListResp
  3444. // @router /edb_chart/list [get]
  3445. func (this *EdbInfoController) MoveEdbChartList() {
  3446. br := new(models.BaseResponse).Init()
  3447. defer func() {
  3448. this.Data["json"] = br
  3449. this.ServeJSON()
  3450. }()
  3451. sysUser := this.SysUser
  3452. if sysUser == nil {
  3453. br.Msg = "请登录"
  3454. br.ErrMsg = "请登录,SysUser Is Empty"
  3455. br.Ret = 408
  3456. return
  3457. }
  3458. source, _ := this.GetInt("Source")
  3459. if source <= 0 || source > 5 {
  3460. br.Msg = "错误的来源"
  3461. br.IsSendEmail = false
  3462. return
  3463. }
  3464. userId, _ := this.GetInt("UserId")
  3465. keyword := this.GetString("Keyword")
  3466. classify := this.GetString("Classify")
  3467. pageSize, _ := this.GetInt("PageSize")
  3468. currentIndex, _ := this.GetInt("CurrentIndex")
  3469. var startSize int
  3470. if pageSize <= 0 {
  3471. pageSize = utils.PageSize20
  3472. }
  3473. if currentIndex <= 0 {
  3474. currentIndex = 1
  3475. }
  3476. startSize = paging.StartIndex(currentIndex, pageSize)
  3477. resp := data_manage.MoveEdbChartListResp{}
  3478. var total int
  3479. page := paging.GetPaging(currentIndex, pageSize, total)
  3480. defaultList := make([]data_manage.MoveEdbChartList, 0)
  3481. resp.List = defaultList
  3482. resp.Paging = page
  3483. // 没有传入条件,那就默认自动返回
  3484. if userId <= 0 && keyword == `` && classify == `` {
  3485. br.Ret = 200
  3486. br.Success = true
  3487. br.Msg = "获取成功"
  3488. br.Data = resp
  3489. return
  3490. }
  3491. list, total, err := data.GetMoveEdbChartList(source, userId, keyword, classify, startSize, pageSize)
  3492. if err != nil {
  3493. //br.Success = true
  3494. br.Msg = "获取失败"
  3495. br.ErrMsg = "获取失败,Err:" + err.Error()
  3496. return
  3497. }
  3498. if list == nil {
  3499. list = defaultList
  3500. }
  3501. page = paging.GetPaging(currentIndex, pageSize, total)
  3502. resp.Paging = page
  3503. resp.List = list
  3504. br.Ret = 200
  3505. br.Success = true
  3506. br.Msg = "获取成功"
  3507. br.Data = resp
  3508. }
  3509. // MoveEdbChartUser
  3510. // @Title 指标/图表创建人变更接口
  3511. // @Description 指标/图表创建人变更接口
  3512. // @Param PageSize query int true "每页数据条数"
  3513. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3514. // @Param EdbInfoId query int true "指标id"
  3515. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3516. // @Success 200 {object} data_manage.ChartListResp
  3517. // @router /edb_chart/change_user [post]
  3518. func (this *EdbInfoController) MoveEdbChartUser() {
  3519. br := new(models.BaseResponse).Init()
  3520. defer func() {
  3521. this.Data["json"] = br
  3522. this.ServeJSON()
  3523. }()
  3524. sysUser := this.SysUser
  3525. if sysUser == nil {
  3526. br.Msg = "请登录"
  3527. br.ErrMsg = "请登录,SysUser Is Empty"
  3528. br.Ret = 408
  3529. return
  3530. }
  3531. var req data_manage.MoveEdbChartReq
  3532. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3533. if err != nil {
  3534. br.Msg = "参数解析异常!"
  3535. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3536. return
  3537. }
  3538. if req.Source <= 0 || req.Source > 5 {
  3539. br.Msg = "错误的来源"
  3540. br.IsSendEmail = false
  3541. return
  3542. }
  3543. if len(req.DataIdList) <= 0 {
  3544. br.Msg = "请勾选数据项"
  3545. br.IsSendEmail = false
  3546. return
  3547. }
  3548. if req.NewUserId <= 0 {
  3549. br.Msg = "请选择新的创建人"
  3550. br.IsSendEmail = false
  3551. return
  3552. }
  3553. err, errMsg := data.MoveEdbChart(req.Source, req.NewUserId, req.DataIdList)
  3554. if err != nil {
  3555. //br.Success = true
  3556. br.Msg = "获取失败"
  3557. if errMsg != `` {
  3558. br.Msg = errMsg
  3559. }
  3560. br.ErrMsg = "获取失败,Err:" + err.Error()
  3561. return
  3562. }
  3563. br.Ret = 200
  3564. br.IsAddLog = true
  3565. br.Success = true
  3566. br.Msg = "修改成功"
  3567. }
  3568. // EdbChartClassifyList
  3569. // @Title 获取指标/图表分类列表数据接口
  3570. // @Description 获取指标/图表分类列表数据接口
  3571. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  3572. // @Success 200 {object} data_manage.ChartListResp
  3573. // @router /edb_chart/classify [get]
  3574. func (this *EdbInfoController) EdbChartClassifyList() {
  3575. br := new(models.BaseResponse).Init()
  3576. defer func() {
  3577. this.Data["json"] = br
  3578. this.ServeJSON()
  3579. }()
  3580. sysUser := this.SysUser
  3581. if sysUser == nil {
  3582. br.Msg = "请登录"
  3583. br.ErrMsg = "请登录,SysUser Is Empty"
  3584. br.Ret = 408
  3585. return
  3586. }
  3587. source, _ := this.GetInt("Source")
  3588. if source <= 0 || source > 5 {
  3589. br.Msg = "错误的来源"
  3590. br.IsSendEmail = false
  3591. return
  3592. }
  3593. list, err := data.GetEdbChartClassifyList(source)
  3594. if err != nil {
  3595. //br.Success = true
  3596. br.Msg = "获取失败"
  3597. br.ErrMsg = "获取失败,Err:" + err.Error()
  3598. return
  3599. }
  3600. br.Ret = 200
  3601. br.Success = true
  3602. br.Msg = "获取成功"
  3603. br.Data = list
  3604. }
  3605. // EdbInfoDataTb
  3606. // @Title 获取指标数据同比值
  3607. // @Description 获取指标数据
  3608. // @Param EdbInfoId query int true "指标ID"
  3609. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  3610. // @Param StartDate query string true "自定义开始日期"
  3611. // @Param EndDate query string true "自定义结束日期"
  3612. // @Success 200 {object} data_manage.EdbInfoDataResp
  3613. // @router /edb_info/data/tb [get]
  3614. func (this *ChartInfoController) EdbInfoDataTb() {
  3615. br := new(models.BaseResponse).Init()
  3616. defer func() {
  3617. this.Data["json"] = br
  3618. this.ServeJSON()
  3619. }()
  3620. sysUser := this.SysUser
  3621. if sysUser == nil {
  3622. br.Msg = "请登录"
  3623. br.ErrMsg = "请登录,SysUser Is Empty"
  3624. br.Ret = 408
  3625. return
  3626. }
  3627. edbInfoId, _ := this.GetInt("EdbInfoId")
  3628. if edbInfoId <= 0 {
  3629. br.Msg = "参数错误"
  3630. return
  3631. }
  3632. dateType, _ := this.GetInt("DateType")
  3633. if dateType <= 0 {
  3634. dateType = 3
  3635. }
  3636. edbInfoType, _ := this.GetInt("EdbInfoType")
  3637. if edbInfoType < 0 {
  3638. edbInfoType = 1
  3639. }
  3640. startDate := this.GetString("StartDate")
  3641. endDate := this.GetString("EndDate")
  3642. startYear, _ := this.GetInt("StartYear")
  3643. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3644. if err != nil {
  3645. br.Msg = "获取失败"
  3646. br.Msg = "获取失败,Err:" + err.Error()
  3647. return
  3648. }
  3649. maxYear := 0
  3650. if edbInfo.LatestDate != "" {
  3651. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3652. maxYear = latestDateT.Year()
  3653. }
  3654. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  3655. var startDateTime time.Time
  3656. if startDate != `` {
  3657. startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  3658. if err != nil {
  3659. br.Msg = "开始日期异常"
  3660. br.Msg = "开始日期异常,Err:" + err.Error()
  3661. return
  3662. }
  3663. //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
  3664. startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
  3665. }
  3666. tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfoId, startDate, endDate)
  3667. if err != nil {
  3668. br.Msg = "获取失败"
  3669. br.Msg = "获取失败,Err:" + err.Error()
  3670. return
  3671. }
  3672. // 计算同比值
  3673. dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
  3674. if err != nil {
  3675. br.Msg = "获取失败"
  3676. br.Msg = "计算同比值失败,Err:" + err.Error()
  3677. return
  3678. }
  3679. edbInfo.MaxValue = maxValue
  3680. edbInfo.MinValue = minValue
  3681. resp := new(data_manage.EdbInfoDataResp)
  3682. resp.EdbInfo = edbInfo
  3683. resp.DataList = dataList
  3684. br.Ret = 200
  3685. br.Success = true
  3686. br.Msg = "获取成功"
  3687. br.Data = resp
  3688. }
  3689. // EdbInfoDataSeasonal
  3690. // @Title 获取指标数据(季节性)
  3691. // @Description 获取指标数据
  3692. // @Param EdbInfoId query int true "指标ID"
  3693. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  3694. // @Param StartDate query string true "自定义开始日期"
  3695. // @Param EndDate query string true "自定义结束日期"
  3696. // @Param Calendar query string true "公历/农历"
  3697. // @Success 200 {object} data_manage.EdbInfoDataResp
  3698. // @router /edb_info/data/seasonal [get]
  3699. func (this *ChartInfoController) EdbInfoDataSeasonal() {
  3700. br := new(models.BaseResponse).Init()
  3701. defer func() {
  3702. this.Data["json"] = br
  3703. this.ServeJSON()
  3704. }()
  3705. sysUser := this.SysUser
  3706. if sysUser == nil {
  3707. br.Msg = "请登录"
  3708. br.ErrMsg = "请登录,SysUser Is Empty"
  3709. br.Ret = 408
  3710. return
  3711. }
  3712. dateType, _ := this.GetInt("DateType")
  3713. startDate := this.GetString("StartDate")
  3714. endDate := this.GetString("EndDate")
  3715. startYear, _ := this.GetInt("StartYear")
  3716. edbInfoIdStr := this.GetString("EdbInfoId")
  3717. edbInfoId, err := strconv.Atoi(edbInfoIdStr)
  3718. if err != nil {
  3719. br.Msg = "指标id异常"
  3720. br.Msg = "指标id转换异常,Err:" + err.Error()
  3721. return
  3722. }
  3723. fmt.Println("startDate:", startDate)
  3724. fmt.Println("endDate:", endDate)
  3725. calendar := this.GetString("Calendar")
  3726. if calendar == "" {
  3727. calendar = "公历"
  3728. }
  3729. if dateType == 0 {
  3730. if startDate == "" {
  3731. dateType = utils.DateTypeNYears
  3732. } else {
  3733. dateType = 5
  3734. }
  3735. }
  3736. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3737. if err != nil {
  3738. br.Msg = "获取失败"
  3739. br.Msg = "获取失败,Err:" + err.Error()
  3740. return
  3741. }
  3742. maxYear := 0
  3743. if edbInfo.LatestDate != "" {
  3744. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3745. maxYear = latestDateT.Year()
  3746. }
  3747. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  3748. dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
  3749. if err != nil {
  3750. br.Msg = "获取失败"
  3751. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3752. return
  3753. }
  3754. resp := new(data_manage.EdbInfoDataSeasonalResp)
  3755. resp.EdbInfo = edbInfo
  3756. resp.DataList = dataList
  3757. br.Ret = 200
  3758. br.Success = true
  3759. br.Msg = "获取成功"
  3760. br.Data = resp
  3761. }
  3762. // SetEdbDataInsertConfig 设置插入值
  3763. // @Title 设置插入值接口
  3764. // @Description 设置插入值接口
  3765. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  3766. // @router /edb_info/insert_config/set [post]
  3767. func (this *EdbInfoController) SetEdbDataInsertConfig() {
  3768. br := new(models.BaseResponse).Init()
  3769. defer func() {
  3770. this.Data["json"] = br
  3771. this.ServeJSON()
  3772. }()
  3773. sysUser := this.SysUser
  3774. if sysUser == nil {
  3775. br.Msg = "请登录"
  3776. br.ErrMsg = "请登录,SysUser Is Empty"
  3777. br.Ret = 408
  3778. return
  3779. }
  3780. var req data_manage.SetEdbDataInsertConfigReq
  3781. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3782. if err != nil {
  3783. br.Msg = "参数解析异常!"
  3784. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3785. return
  3786. }
  3787. dateStr := req.Date
  3788. if dateStr == `` {
  3789. br.Msg = "请选择日期"
  3790. br.IsSendEmail = false
  3791. return
  3792. }
  3793. date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
  3794. if err != nil {
  3795. br.Msg = "日期异常"
  3796. br.ErrMsg = "日期异常,err:" + err.Error()
  3797. br.IsSendEmail = false
  3798. return
  3799. }
  3800. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  3801. if err != nil {
  3802. br.Msg = "获取指标信息失败"
  3803. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3804. return
  3805. }
  3806. err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
  3807. if err != nil {
  3808. br.Msg = "设置失败"
  3809. if errMsg != `` {
  3810. br.Msg = errMsg
  3811. }
  3812. br.ErrMsg = "修改失败,Err:" + err.Error()
  3813. br.IsSendEmail = isSendEmail
  3814. return
  3815. }
  3816. //新增操作日志
  3817. {
  3818. edbLog := new(data_manage.EdbInfoLog)
  3819. edbLog.EdbInfoId = edbInfo.EdbInfoId
  3820. edbLog.SourceName = edbInfo.SourceName
  3821. edbLog.Source = edbInfo.Source
  3822. edbLog.EdbCode = edbInfo.EdbCode
  3823. edbLog.EdbName = edbInfo.EdbName
  3824. edbLog.ClassifyId = edbInfo.ClassifyId
  3825. edbLog.SysUserId = sysUser.AdminId
  3826. edbLog.SysUserRealName = sysUser.RealName
  3827. edbLog.CreateTime = time.Now()
  3828. edbLog.Content = string(this.Ctx.Input.RequestBody)
  3829. edbLog.Status = "设置插入值"
  3830. edbLog.Method = this.Ctx.Input.URI()
  3831. go data_manage.AddEdbInfoLog(edbLog)
  3832. }
  3833. br.Ret = 200
  3834. br.Success = true
  3835. br.Msg = "保存成功"
  3836. br.IsAddLog = true
  3837. }
  3838. // TraceEdbInfo
  3839. // @Title 指标溯源接口
  3840. // @Description 指标溯源接口
  3841. // @Param EdbInfoId query int true "指标id"
  3842. // @Success 200 {object} data_manage.ChartListResp
  3843. // @router /edb_info/trace [get]
  3844. func (this *EdbInfoController) TraceEdbInfo() {
  3845. br := new(models.BaseResponse).Init()
  3846. defer func() {
  3847. this.Data["json"] = br
  3848. this.ServeJSON()
  3849. }()
  3850. sysUser := this.SysUser
  3851. if sysUser == nil {
  3852. br.Msg = "请登录"
  3853. br.ErrMsg = "请登录,SysUser Is Empty"
  3854. br.Ret = 408
  3855. return
  3856. }
  3857. edbInfoId, _ := this.GetInt("EdbInfoId")
  3858. if edbInfoId <= 0 {
  3859. br.Msg = "参数错误"
  3860. br.ErrMsg = "参数错误"
  3861. return
  3862. }
  3863. resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId)
  3864. if err != nil {
  3865. br.Msg = "获取失败"
  3866. br.Msg = "获取失败,Err:" + err.Error()
  3867. return
  3868. }
  3869. br.Ret = 200
  3870. br.Data = resp
  3871. br.Success = true
  3872. br.Msg = "刷新成功"
  3873. }
  3874. // AllEdbInfoByEs
  3875. // @Title 所有指标筛选接口
  3876. // @Description 所有指标筛选接口
  3877. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  3878. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  3879. // @Param Frequency query string false "频度"
  3880. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  3881. // @Param PageSize query int true "每页数据条数"
  3882. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3883. // @Success 200 {object} data_manage.EdbInfoList
  3884. // @router /edb_info/filter_by_es/all [get]
  3885. func (this *EdbInfoController) AllEdbInfoByEs() {
  3886. br := new(models.BaseResponse).Init()
  3887. defer func() {
  3888. this.Data["json"] = br
  3889. this.ServeJSON()
  3890. }()
  3891. pageSize, _ := this.GetInt("PageSize")
  3892. currentIndex, _ := this.GetInt("CurrentIndex")
  3893. var total int64
  3894. var startSize int
  3895. if pageSize <= 0 {
  3896. pageSize = utils.PageSize20
  3897. }
  3898. if currentIndex <= 0 {
  3899. currentIndex = 1
  3900. }
  3901. startSize = paging.StartIndex(currentIndex, pageSize)
  3902. keyWord := this.GetString("KeyWord")
  3903. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3904. filterSource, _ := this.GetInt("FilterSource")
  3905. if filterSource <= 0 {
  3906. filterSource = 1
  3907. }
  3908. //指标来源
  3909. source, _ := this.GetInt("Source")
  3910. frequency := this.GetString("Frequency") //频度
  3911. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  3912. var edbInfoList []*data_manage.EdbInfoList
  3913. var err error
  3914. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  3915. // 获取当前账号的不可见指标
  3916. {
  3917. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3918. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3919. if err != nil && err.Error() != utils.ErrNoRow() {
  3920. br.Msg = "获取失败"
  3921. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3922. return
  3923. }
  3924. for _, v := range confList {
  3925. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3926. }
  3927. }
  3928. if keyWord != "" {
  3929. var keyWordArr []string
  3930. keyWordArr = append(keyWordArr, keyWord)
  3931. newKeyWord := strings.Split(keyWord, " ")
  3932. keyWordArr = append(keyWordArr, newKeyWord...)
  3933. // 普通的搜索
  3934. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, ``, noPermissionEdbInfoIdList)
  3935. } else {
  3936. var condition string
  3937. var pars []interface{}
  3938. // 普通指标
  3939. condition += ` AND edb_info_type = ? `
  3940. pars = append(pars, 0)
  3941. // 无权限指标id
  3942. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3943. if lenNoPermissionEdbInfoIdList > 0 {
  3944. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3945. pars = append(pars, noPermissionEdbInfoIdList)
  3946. }
  3947. switch filterSource {
  3948. case 2:
  3949. condition += ` AND frequency='月度' `
  3950. case 3:
  3951. condition += ` AND frequency <> '日度' `
  3952. case 4:
  3953. condition += ` AND edb_type = 1 `
  3954. case 5:
  3955. condition += ` AND source = 6 ` //来源(同比值)
  3956. case 6:
  3957. condition += ` AND frequency != ? `
  3958. pars = append(pars, "年度")
  3959. }
  3960. //频度
  3961. if frequency != "" {
  3962. condition += ` AND frequency = ? `
  3963. pars = append(pars, frequency)
  3964. }
  3965. // 查询只允许添加预测指标的搜索
  3966. if isAddPredictEdb {
  3967. condition += ` AND frequency in ("日度","周度","月度") `
  3968. }
  3969. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  3970. }
  3971. if err != nil {
  3972. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3973. }
  3974. page := paging.GetPaging(currentIndex, pageSize, int(total))
  3975. edbInfoListLen := len(edbInfoList)
  3976. for i := 0; i < edbInfoListLen; i++ {
  3977. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3978. }
  3979. for i := 0; i < edbInfoListLen; i++ {
  3980. for j := 0; j < edbInfoListLen; j++ {
  3981. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3982. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3983. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3984. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3985. }
  3986. }
  3987. }
  3988. //新增搜索词记录
  3989. {
  3990. searchKeyword := new(data_manage.SearchKeyword)
  3991. searchKeyword.KeyWord = keyWord
  3992. searchKeyword.CreateTime = time.Now()
  3993. go data_manage.AddSearchKeyword(searchKeyword)
  3994. }
  3995. resp := data_manage.EdbInfoFilterDataResp{
  3996. Paging: page,
  3997. List: edbInfoList,
  3998. }
  3999. br.Ret = 200
  4000. br.Success = true
  4001. br.Msg = "获取成功"
  4002. br.Data = resp
  4003. }
  4004. // GetEdbDateData
  4005. // @Title 根据指标ID和具体日期获取对应日期的数据值
  4006. // @Description 根据指标ID和具体日期获取对应日期的数据值
  4007. // @Param EdbInfoId query int false "指标id"
  4008. // @Param Date query string false "日期"
  4009. // @Success 200 {object} data_manage.EdbInfoList
  4010. // @router /edb_info/date_data [get]
  4011. func (this *EdbInfoController) GetEdbDateData() {
  4012. br := new(models.BaseResponse).Init()
  4013. defer func() {
  4014. this.Data["json"] = br
  4015. this.ServeJSON()
  4016. }()
  4017. edbInfoId, _ := this.GetInt("EdbInfoId")
  4018. date := this.GetString("Date")
  4019. if edbInfoId <= 0 {
  4020. br.Msg = "请选择指标"
  4021. br.IsSendEmail = false
  4022. return
  4023. }
  4024. if date == `` {
  4025. br.Msg = "请选择日期"
  4026. br.IsSendEmail = false
  4027. return
  4028. }
  4029. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4030. if err != nil {
  4031. br.Msg = "获取失败"
  4032. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4033. return
  4034. }
  4035. startDate := date
  4036. endDate := date
  4037. dateType := "day"
  4038. //如果填写的是月度日期
  4039. if strings.Count(date, "-") == 1 {
  4040. startDate = date + "-01"
  4041. endDate = ``
  4042. dateType = "month"
  4043. }
  4044. dataItem, err := data.GetDateData(edbInfo, startDate, endDate)
  4045. if err != nil {
  4046. br.Msg = "获取失败"
  4047. br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
  4048. return
  4049. }
  4050. val := ``
  4051. if dataItem != nil {
  4052. switch dateType {
  4053. case "month":
  4054. dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local)
  4055. dateTimeStr := dateTime.Format(utils.FormatYearMonthDate)
  4056. if dateTimeStr != date {
  4057. val = ``
  4058. }
  4059. }
  4060. val = fmt.Sprint(dataItem.Value)
  4061. }
  4062. br.Ret = 200
  4063. br.Success = true
  4064. br.Msg = "获取成功"
  4065. br.Data = val
  4066. }
  4067. // GetEdbBeforeAndAfterDateData
  4068. // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4069. // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4070. // @Param EdbInfoId query int false "指标id"
  4071. // @Param Date query string false "日期"
  4072. // @Param Num query int false "前后几期数据"
  4073. // @Success 200 {object} data_manage.EdbInfoList
  4074. // @router /edb_info/date_data/before_after [get]
  4075. func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
  4076. br := new(models.BaseResponse).Init()
  4077. defer func() {
  4078. this.Data["json"] = br
  4079. this.ServeJSON()
  4080. }()
  4081. edbInfoId, _ := this.GetInt("EdbInfoId")
  4082. date := this.GetString("Date")
  4083. num, _ := this.GetInt("Num")
  4084. // 默认2期数据
  4085. if num <= 0 {
  4086. num = 2
  4087. }
  4088. if edbInfoId <= 0 {
  4089. br.Msg = "请选择指标"
  4090. br.IsSendEmail = false
  4091. return
  4092. }
  4093. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4094. if err != nil {
  4095. br.Msg = "获取失败"
  4096. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4097. return
  4098. }
  4099. // 当前日期
  4100. var currDate string
  4101. // 是否查找之后的数据
  4102. isFindAfter := true
  4103. if date == `` {
  4104. currDate = edbInfo.EndDate
  4105. isFindAfter = false
  4106. if num <= 0 {
  4107. num = 4 //默认获取前面的几期数据
  4108. }
  4109. }
  4110. dataList := make([]*data_manage.EdbDataList, 0)
  4111. startDate := date
  4112. // 指定日期的类型
  4113. dateType := "day"
  4114. //如果填写的是月度日期
  4115. if strings.Count(date, "-") == 1 {
  4116. startDate = date + "-01"
  4117. dateType = "month"
  4118. }
  4119. resp := data_manage.BeforeAndAfterDateDataResp{
  4120. List: dataList,
  4121. Date: "",
  4122. }
  4123. // 后面的数据
  4124. afterList := make([]*data_manage.EdbDataList, 0)
  4125. if isFindAfter {
  4126. afterList, err = data.GetEdbBeforeAndAfterDateData(edbInfo, startDate, "", 2, num)
  4127. if err != nil {
  4128. br.Msg = "获取失败"
  4129. br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
  4130. return
  4131. }
  4132. lenBeforeList := len(afterList)
  4133. if lenBeforeList <= 0 {
  4134. br.Ret = 200
  4135. br.Success = true
  4136. br.Msg = "所选指标所选日期无值"
  4137. br.Data = resp
  4138. return
  4139. } else {
  4140. var dateTimeStr string
  4141. switch dateType {
  4142. case "month":
  4143. dateTime, _ := time.ParseInLocation(utils.FormatDate, afterList[0].DataTime, time.Local)
  4144. dateTimeStr = dateTime.Format(utils.FormatYearMonthDate)
  4145. case "day":
  4146. dateTimeStr = afterList[0].DataTime
  4147. }
  4148. currDate = afterList[0].DataTime
  4149. // 如果对应日期找不到,那么就直接返回吧
  4150. if dateTimeStr != date {
  4151. br.Ret = 200
  4152. br.Success = true
  4153. br.Msg = "所选指标所选日期无值"
  4154. br.Data = resp
  4155. return
  4156. }
  4157. }
  4158. }
  4159. // 前面的数据
  4160. beforeList, err := data.GetEdbBeforeAndAfterDateData(edbInfo, "", currDate, 1, num)
  4161. if err != nil {
  4162. br.Msg = "获取失败"
  4163. br.ErrMsg = fmt.Sprint("获取前面的指数据失败,Err:", err.Error())
  4164. return
  4165. }
  4166. dataList = append(dataList, beforeList...)
  4167. // 后面的数据
  4168. if len(afterList) > 0 {
  4169. if len(beforeList) > 0 {
  4170. dataList = append(dataList, afterList[1:]...)
  4171. } else {
  4172. dataList = append(dataList, afterList...)
  4173. }
  4174. }
  4175. // 数据翻转
  4176. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  4177. dataList[i], dataList[j] = dataList[j], dataList[i]
  4178. }
  4179. resp.List = dataList
  4180. // 前端不传入日期的时候,这个J皮不让返回这个字段,要不然他会颜色标记
  4181. if date != `` {
  4182. resp.Date = currDate
  4183. }
  4184. br.Ret = 200
  4185. br.Success = true
  4186. br.Msg = "获取成功"
  4187. br.Data = resp
  4188. }
  4189. // EdbChartAdminList
  4190. // @Title 获取创建人员分组
  4191. // @Description 获取创建人员分组
  4192. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  4193. // @Success 200 {object} company.DepartmentGroupSellersResp
  4194. // @router /edb_chart/adminList [get]
  4195. func (this *EdbInfoController) EdbChartAdminList() {
  4196. br := new(models.BaseResponse).Init()
  4197. defer func() {
  4198. this.Data["json"] = br
  4199. this.ServeJSON()
  4200. }()
  4201. sysUser := this.SysUser
  4202. if sysUser == nil {
  4203. br.Msg = "请登录"
  4204. br.ErrMsg = "请登录,SysUser Is Empty"
  4205. br.Ret = 408
  4206. return
  4207. }
  4208. source, _ := this.GetInt("Source", 0)
  4209. if source <= 0 || source > 5 {
  4210. br.Msg = "错误的来源"
  4211. br.IsSendEmail = false
  4212. return
  4213. }
  4214. idList, err := data.GetEdbChartAdminList(source)
  4215. if err != nil {
  4216. //br.Success = true
  4217. br.Msg = "获取失败"
  4218. br.ErrMsg = "获取失败,Err:" + err.Error()
  4219. return
  4220. }
  4221. fmt.Println("idlist:", idList)
  4222. systemAdminMap := make(map[int]*system.Admin)
  4223. departmentMap := make(map[string]string)
  4224. departmentAdminMap := make(map[int]string)
  4225. groupMap := make(map[string]string)
  4226. systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList)
  4227. if err != nil {
  4228. br.Msg = "获取用户列表失败"
  4229. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  4230. return
  4231. }
  4232. for _, v := range systemAdminList {
  4233. systemAdminMap[v.AdminId] = v
  4234. departmentMap[v.DepartmentName] = v.DepartmentName
  4235. departmentAdminMap[v.AdminId] = v.DepartmentName
  4236. groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName
  4237. }
  4238. depList := make([]company.DepartmentGroupAdmins, 0)
  4239. i := 1
  4240. for _, v := range departmentMap {
  4241. item := company.DepartmentGroupAdmins{
  4242. AdminId: "dep_" + strconv.Itoa(i),
  4243. RealName: v,
  4244. }
  4245. i++
  4246. depList = append(depList, item)
  4247. }
  4248. for k := 0; k < len(depList); k++ {
  4249. for k1, v1 := range groupMap {
  4250. if v1 == depList[k].RealName && v1 != "" {
  4251. item := &company.DepartmentGroupAdmins{
  4252. AdminId: "group_" + strconv.Itoa(k),
  4253. RealName: strings.Replace(k1, v1, "", -1),
  4254. }
  4255. depList[k].ChildrenList = append(depList[k].ChildrenList, item)
  4256. }
  4257. }
  4258. }
  4259. for _, admin := range systemAdminList {
  4260. for i, v := range depList {
  4261. for k, group := range v.ChildrenList {
  4262. if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName {
  4263. item := &company.DepartmentGroupAdmins{
  4264. AdminId: strconv.Itoa(admin.AdminId),
  4265. RealName: admin.RealName,
  4266. RoleTypeCode: admin.RoleTypeCode,
  4267. Authority: admin.Authority,
  4268. }
  4269. if group.RealName != "" {
  4270. depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item)
  4271. } else {
  4272. depList[i].ChildrenList = append(depList[i].ChildrenList, item)
  4273. }
  4274. }
  4275. }
  4276. }
  4277. }
  4278. for i, groupList := range depList {
  4279. for k, v := range groupList.ChildrenList {
  4280. if v.RealName == "" {
  4281. newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...)
  4282. depList[i].ChildrenList = newChildrenList
  4283. }
  4284. }
  4285. }
  4286. br.Ret = 200
  4287. br.Success = true
  4288. br.Msg = "获取成功"
  4289. br.Data = depList
  4290. }
  4291. // EdbSourceList
  4292. // @Title 指标来源列表
  4293. // @Description 指标来源列表
  4294. // @Param IsBase query int false "是否为基础指标: 1-是"
  4295. // @Success 200 {object} data_manage.EdbInfoListResp
  4296. // @router /edb_source/list [get]
  4297. func (this *EdbInfoController) EdbSourceList() {
  4298. br := new(models.BaseResponse).Init()
  4299. defer func() {
  4300. if br.ErrMsg == "" {
  4301. br.IsSendEmail = false
  4302. }
  4303. this.Data["json"] = br
  4304. this.ServeJSON()
  4305. }()
  4306. isBase, _ := this.GetInt("IsBase", 0)
  4307. cond := ``
  4308. if isBase > 0 {
  4309. cond = ` AND is_base = 1`
  4310. }
  4311. pars := make([]interface{}, 0)
  4312. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4313. if e != nil {
  4314. br.Msg = "获取失败"
  4315. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4316. return
  4317. }
  4318. br.Data = list
  4319. br.Ret = 200
  4320. br.Success = true
  4321. br.Msg = "获取成功"
  4322. }
  4323. // EdbSourceListByPython
  4324. // @Title 指标来源列表
  4325. // @Description 指标来源列表
  4326. // @Param IsBase query int false "是否为基础指标: 1-是"
  4327. // @Success 200 {object} data_manage.EdbInfoListResp
  4328. // @router /edb_source/list/python [get]
  4329. func (this *EdbInfoController) EdbSourceListByPython() {
  4330. br := new(models.BaseResponse).Init()
  4331. defer func() {
  4332. if br.ErrMsg == "" {
  4333. br.IsSendEmail = false
  4334. }
  4335. this.Data["json"] = br
  4336. this.ServeJSON()
  4337. }()
  4338. isBase, _ := this.GetInt("IsBase", 0)
  4339. cond := ``
  4340. if isBase > 0 {
  4341. cond = ` AND is_base = 1`
  4342. }
  4343. pars := make([]interface{}, 0)
  4344. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4345. if e != nil {
  4346. br.Msg = "获取失败"
  4347. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4348. return
  4349. }
  4350. baseEdbList := make([]data_manage.EdbSourceChild, 0)
  4351. calEdbList := make([]data_manage.EdbSourceChild, 0)
  4352. for _, v := range list {
  4353. switch v.IsBase {
  4354. case 1:
  4355. baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{
  4356. EdbSourceId: v.EdbSourceId,
  4357. SourceName: v.SourceName,
  4358. IsBase: v.IsBase,
  4359. TableName: v.TableName,
  4360. Child: []data_manage.EdbSourceChild{},
  4361. })
  4362. case 2:
  4363. calEdbList = append(calEdbList, data_manage.EdbSourceChild{
  4364. EdbSourceId: v.EdbSourceId,
  4365. SourceName: v.SourceName,
  4366. IsBase: v.IsBase,
  4367. TableName: v.TableName,
  4368. Child: []data_manage.EdbSourceChild{},
  4369. })
  4370. }
  4371. }
  4372. resp := []data_manage.EdbSourceChild{
  4373. {
  4374. EdbSourceId: 0,
  4375. SourceName: "基础指标",
  4376. IsBase: 1,
  4377. Child: baseEdbList,
  4378. },
  4379. {
  4380. EdbSourceId: 0,
  4381. SourceName: "计算指标",
  4382. IsBase: 1,
  4383. Child: calEdbList,
  4384. },
  4385. }
  4386. br.Data = resp
  4387. br.Ret = 200
  4388. br.Success = true
  4389. br.Msg = "获取成功"
  4390. }
  4391. // EdbChartList
  4392. // @Title 指标缩略图列表接口
  4393. // @Description 指标缩略图列表接口
  4394. // @Param PageSize query int true "每页数据条数"
  4395. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4396. // @Param ClassifyId query int true "分类id"
  4397. // @Param AdminId query int false "创建人id"
  4398. // @Param IsOnlyMe query bool false "是否只看我的"
  4399. // @Success 200 {object} response.EdbInfoChartListResp
  4400. // @router /edb_info/chart/list [get]
  4401. func (this *EdbInfoController) EdbChartList() {
  4402. br := new(models.BaseResponse).Init()
  4403. defer func() {
  4404. if br.ErrMsg == "" {
  4405. br.IsSendEmail = false
  4406. }
  4407. this.Data["json"] = br
  4408. this.ServeJSON()
  4409. }()
  4410. sysUser := this.SysUser
  4411. if sysUser == nil {
  4412. br.Msg = "请登录"
  4413. br.ErrMsg = "请登录,SysUser Is Empty"
  4414. br.Ret = 408
  4415. return
  4416. }
  4417. // 分页
  4418. pageSize, _ := this.GetInt("PageSize")
  4419. currentIndex, _ := this.GetInt("CurrentIndex")
  4420. var total int
  4421. page := paging.GetPaging(currentIndex, pageSize, total)
  4422. var startSize int
  4423. if pageSize <= 0 {
  4424. pageSize = utils.PageSize20
  4425. }
  4426. if currentIndex <= 0 {
  4427. currentIndex = 1
  4428. }
  4429. startSize = paging.StartIndex(currentIndex, pageSize)
  4430. // 基础指标
  4431. var condition string
  4432. var pars []interface{}
  4433. condition += ` AND edb_info_type = ? `
  4434. pars = append(pars, 0)
  4435. // 分类筛选
  4436. classifyId, _ := this.GetInt("ClassifyId")
  4437. if classifyId > 0 {
  4438. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  4439. if e != nil && e.Error() != utils.ErrNoRow() {
  4440. br.Msg = "获取失败"
  4441. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  4442. return
  4443. }
  4444. var classifyIds []int
  4445. for _, v := range childClassify {
  4446. classifyIds = append(classifyIds, v.ClassifyId)
  4447. }
  4448. condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  4449. pars = append(pars, classifyIds)
  4450. }
  4451. // 创建人
  4452. adminId, _ := this.GetInt("AdminId")
  4453. if adminId > 0 {
  4454. condition += ` AND sys_user_id = ? `
  4455. pars = append(pars, adminId)
  4456. }
  4457. // 只看我的
  4458. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  4459. if isOnlyMe {
  4460. condition += ` AND sys_user_id = ? `
  4461. pars = append(pars, sysUser.AdminId)
  4462. }
  4463. // 获取当前账号的不可见指标
  4464. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4465. confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4466. if e != nil {
  4467. br.Msg = "获取失败"
  4468. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
  4469. return
  4470. }
  4471. noPermissionEdbInfoIdList := make([]int, 0)
  4472. for _, v := range confList {
  4473. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  4474. }
  4475. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  4476. if noPermissionEdbInfoIdNum > 0 {
  4477. condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  4478. pars = append(pars, noPermissionEdbInfoIdList)
  4479. }
  4480. // 获取指标信息
  4481. dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  4482. if e != nil {
  4483. br.Msg = "获取失败"
  4484. br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
  4485. return
  4486. }
  4487. if len(list) == 0 {
  4488. list = make([]*data_manage.EdbInfoList, 0)
  4489. } else {
  4490. for _, v := range list {
  4491. v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType)
  4492. }
  4493. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  4494. }
  4495. resp := response.EdbInfoChartListResp{
  4496. Paging: page,
  4497. List: list,
  4498. }
  4499. br.Ret = 200
  4500. br.Success = true
  4501. br.Msg = "获取成功"
  4502. br.Data = resp
  4503. }
  4504. // Modify
  4505. // @Title 修改指标信息接口
  4506. // @Description 编辑指标接口
  4507. // @Success 200 string "操作成功"
  4508. // @router /edb_info/modify [post]
  4509. func (this *EdbInfoController) Modify() {
  4510. br := new(models.BaseResponse).Init()
  4511. defer func() {
  4512. if br.ErrMsg == "" {
  4513. br.IsSendEmail = false
  4514. }
  4515. this.Data["json"] = br
  4516. this.ServeJSON()
  4517. }()
  4518. sysUser := this.SysUser
  4519. if sysUser == nil {
  4520. br.Msg = "请登录"
  4521. br.ErrMsg = "请登录,SysUser Is Empty"
  4522. br.Ret = 408
  4523. return
  4524. }
  4525. var req request.ModifyEdbInfoReq
  4526. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4527. if err != nil {
  4528. br.Msg = "参数解析异常!"
  4529. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4530. return
  4531. }
  4532. edbInfoId := req.EdbInfoId
  4533. if edbInfoId <= 0 {
  4534. br.Msg = "请选择指标"
  4535. br.IsSendEmail = false
  4536. return
  4537. }
  4538. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  4539. if e != nil {
  4540. br.Msg = "操作失败"
  4541. br.ErrMsg = "获取指标信息失败, Err:" + err.Error()
  4542. return
  4543. }
  4544. // 编辑权限校验
  4545. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType)
  4546. if !button.OpButton {
  4547. br.Msg = "无权限操作"
  4548. return
  4549. }
  4550. edbInfo.MaxValue = req.MaxValue
  4551. edbInfo.MinValue = req.MinValue
  4552. edbInfo.ManualSave = 1
  4553. edbInfo.ModifyTime = time.Now()
  4554. err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"})
  4555. if err != nil {
  4556. br.Msg = "获取失败"
  4557. br.ErrMsg = "获取失败,Err:" + err.Error()
  4558. return
  4559. }
  4560. //修改es
  4561. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  4562. br.Ret = 200
  4563. br.Success = true
  4564. br.Msg = "修改成功"
  4565. br.IsAddLog = true
  4566. }
  4567. // ChartImageSet
  4568. // @Title 设置指标的图表图片
  4569. // @Description 设置指标的图表图片接口
  4570. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  4571. // @Success Ret=200 保存成功
  4572. // @router /edb_info/image/set [post]
  4573. func (this *EdbInfoController) ChartImageSet() {
  4574. br := new(models.BaseResponse).Init()
  4575. defer func() {
  4576. if br.ErrMsg == "" {
  4577. br.IsSendEmail = false
  4578. }
  4579. this.Data["json"] = br
  4580. this.ServeJSON()
  4581. }()
  4582. sysUser := this.SysUser
  4583. if sysUser == nil {
  4584. br.Msg = "请登录"
  4585. br.ErrMsg = "请登录,SysUser Is Empty"
  4586. br.Ret = 408
  4587. return
  4588. }
  4589. var req data_manage.SetEdbInfoImageReq
  4590. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  4591. br.Msg = "参数解析异常!"
  4592. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  4593. return
  4594. }
  4595. if req.EdbInfoId <= 0 || req.ImageUrl == "" {
  4596. br.Ret = 200
  4597. br.Success = true
  4598. br.Msg = "保存成功"
  4599. return
  4600. }
  4601. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  4602. if e != nil {
  4603. if e.Error() == utils.ErrNoRow() {
  4604. br.Msg = "找不到该指标"
  4605. return
  4606. }
  4607. br.Msg = "保存失败"
  4608. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  4609. return
  4610. }
  4611. edbInfo.ChartImage = req.ImageUrl
  4612. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  4613. br.Msg = "保存失败"
  4614. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  4615. return
  4616. }
  4617. // 修改es数据
  4618. go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  4619. br.Ret = 200
  4620. br.Success = true
  4621. br.Msg = "保存成功"
  4622. }
  4623. // EdbInfoExistCheck
  4624. // @Title 新增指标-检验指标是否存在接口
  4625. // @Description 新增指标-检验指标是否存在接口
  4626. // @Param Source query int true "来源:1:同花顺,2:wind"
  4627. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  4628. // @Param EdbCode query string false "指标编码/指标代码"
  4629. // @Param StockCode query string false "证券代码"
  4630. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  4631. // @router /edb_info/exist/check [get]
  4632. func (this *EdbInfoController) EdbInfoExistCheck() {
  4633. br := new(models.BaseResponse).Init()
  4634. defer func() {
  4635. this.Data["json"] = br
  4636. this.ServeJSON()
  4637. }()
  4638. source, _ := this.GetInt("Source")
  4639. edbCode := this.GetString("EdbCode")
  4640. edbCode = strings.Trim(edbCode, "\t")
  4641. edbCode = strings.Trim(edbCode, " ")
  4642. edbCode = strings.Replace(edbCode, "\t", "", -1)
  4643. subSource, _ := this.GetInt("SubSource")
  4644. stockCode := this.GetString("StockCode")
  4645. if source <= 0 {
  4646. br.Msg = "无效的数据来源"
  4647. return
  4648. }
  4649. if edbCode == "" {
  4650. br.Msg = "请输入指标ID"
  4651. return
  4652. }
  4653. if source != utils.DATA_SOURCE_WIND {
  4654. br.Msg = "无效的数据来源"
  4655. return
  4656. }
  4657. if subSource != utils.DATA_SUB_SOURCE_DATE {
  4658. br.Msg = "无效的数据库来源"
  4659. return
  4660. }
  4661. var indexCodeArr []string
  4662. edbCodeArr := strings.Split(edbCode, ",")
  4663. stockCodeArr := strings.Split(stockCode, ",")
  4664. for _, sv := range stockCodeArr {
  4665. for _, ev := range edbCodeArr {
  4666. indexCode := utils.WindDbWsd + sv + ev
  4667. indexCodeArr = append(indexCodeArr, indexCode)
  4668. }
  4669. }
  4670. indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr)
  4671. if err != nil && err.Error() != utils.ErrNoRow() {
  4672. br.Msg = "校验指标是否存在失败"
  4673. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  4674. return
  4675. }
  4676. var existStockCodeArr []string
  4677. var existEdbCodeArr []string
  4678. for _, indexItem := range indexList {
  4679. for _, sv := range stockCodeArr {
  4680. for _, ev := range edbCodeArr {
  4681. if strings.Contains(indexItem.EdbCode, sv) {
  4682. existStockCodeArr = append(existStockCodeArr, sv)
  4683. }
  4684. if strings.Contains(indexItem.EdbCode, ev) {
  4685. existEdbCodeArr = append(existEdbCodeArr, ev)
  4686. }
  4687. }
  4688. }
  4689. }
  4690. resp := new(data_manage.EdbInfoExistCheckResp)
  4691. if len(indexList) > 0 {
  4692. resp.IndexExist = true
  4693. }
  4694. resp.ExistEdbCodeArr = existEdbCodeArr
  4695. resp.ExistStockCodeArr = existStockCodeArr
  4696. br.Ret = 200
  4697. br.Success = true
  4698. br.Msg = "获取成功"
  4699. br.Data = resp
  4700. }
  4701. // EdbInfoAdd
  4702. // @Title 指标批量保存接口
  4703. // @Description 指标批量保存接口
  4704. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  4705. // @Success Ret=200 保存成功
  4706. // @router /edb_info/batch/add [post]
  4707. func (this *EdbInfoController) EdbInfoBatchAdd() {
  4708. br := new(models.BaseResponse).Init()
  4709. defer func() {
  4710. this.Data["json"] = br
  4711. this.ServeJSON()
  4712. }()
  4713. sysUser := this.SysUser
  4714. if sysUser == nil {
  4715. br.Msg = "请登录"
  4716. br.ErrMsg = "请登录,SysUser Is Empty"
  4717. br.Ret = 408
  4718. return
  4719. }
  4720. deleteCache := true
  4721. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  4722. defer func() {
  4723. if deleteCache {
  4724. utils.Rc.Delete(cacheKey)
  4725. }
  4726. }()
  4727. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  4728. deleteCache = false
  4729. br.Msg = "系统处理中,请稍后重试!"
  4730. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  4731. return
  4732. }
  4733. var req data_manage.BatchAddEdbInfoReq
  4734. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4735. if err != nil {
  4736. br.Msg = "参数解析异常!"
  4737. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4738. return
  4739. }
  4740. source := utils.DATA_SOURCE_WIND
  4741. if source <= 0 {
  4742. br.Msg = "无效的数据来源"
  4743. return
  4744. }
  4745. resp := new(data_manage.AddEdbInfoResp)
  4746. for k, v := range req.BatchList {
  4747. v.EdbName = strings.Trim(v.EdbName, " ")
  4748. v.EdbCode = strings.Trim(v.EdbCode, " ")
  4749. v.StockCode = strings.Trim(v.StockCode, " ")
  4750. if v.EdbCode == "" {
  4751. br.Msg = "指标ID不能为空"
  4752. return
  4753. }
  4754. if v.StockCode == "" {
  4755. br.Msg = "证券代码不能为空"
  4756. return
  4757. }
  4758. if v.EdbName == "" {
  4759. br.Msg = "指标名称不能为空"
  4760. return
  4761. }
  4762. if v.Frequency == "" {
  4763. br.Msg = "频率不能为空"
  4764. return
  4765. }
  4766. if v.ClassifyId <= 0 {
  4767. br.Msg = "请选择分类"
  4768. return
  4769. }
  4770. edbInfoItem := new(data_manage.EdbInfo)
  4771. edbInfoItem.Source = source
  4772. switch source {
  4773. case utils.DATA_SOURCE_WIND:
  4774. edbInfoItem.SourceName = "wind"
  4775. }
  4776. edbInfoItem.SubSource = 1
  4777. edbInfoItem.SubSourceName = "日期序列"
  4778. edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
  4779. edbInfoItem.EdbName = v.EdbName
  4780. edbInfoItem.Frequency = v.Frequency
  4781. edbInfoItem.Unit = v.Unit
  4782. edbInfoItem.ClassifyId = v.ClassifyId
  4783. edbInfoItem.SysUserId = sysUser.AdminId
  4784. edbInfoItem.SysUserRealName = sysUser.RealName
  4785. edbInfoItem.IndicatorCode = v.EdbCode
  4786. edbInfoItem.StockCode = v.StockCode
  4787. // 指标入库
  4788. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  4789. if err != nil {
  4790. br.Msg = "保存失败"
  4791. if errMsg != `` {
  4792. br.Msg = errMsg
  4793. }
  4794. br.ErrMsg = err.Error()
  4795. br.IsSendEmail = isSendEmail
  4796. return
  4797. }
  4798. //新增操作日志
  4799. {
  4800. edbLog := new(data_manage.EdbInfoLog)
  4801. edbLog.EdbInfoId = edbInfo.EdbInfoId
  4802. edbLog.SourceName = edbInfo.SourceName
  4803. edbLog.Source = edbInfo.Source
  4804. edbLog.EdbCode = edbInfo.EdbCode
  4805. edbLog.EdbName = edbInfo.EdbName
  4806. edbLog.ClassifyId = edbInfo.ClassifyId
  4807. edbLog.SysUserId = sysUser.AdminId
  4808. edbLog.SysUserRealName = sysUser.RealName
  4809. edbLog.CreateTime = time.Now()
  4810. edbLog.Content = string(this.Ctx.Input.RequestBody)
  4811. edbLog.Status = "新增指标"
  4812. edbLog.Method = this.Ctx.Input.URI()
  4813. go data_manage.AddEdbInfoLog(edbLog)
  4814. }
  4815. if k <= 0 {
  4816. resp.EdbInfoId = edbInfo.EdbInfoId
  4817. resp.UniqueCode = edbInfo.UniqueCode
  4818. }
  4819. }
  4820. // 试用平台更新用户累计新增指标数
  4821. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  4822. if e != nil {
  4823. br.Msg = "操作失败"
  4824. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  4825. return
  4826. }
  4827. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  4828. go func() {
  4829. var r etaTrialService.EtaTrialUserReq
  4830. r.Mobile = adminItem.Mobile
  4831. _, _ = etaTrialService.UpdateUserIndexNum(r)
  4832. }()
  4833. }
  4834. br.Ret = 200
  4835. br.Success = true
  4836. br.Msg = "保存成功"
  4837. br.Data = resp
  4838. br.IsAddLog = true
  4839. }