edb_info.go 204 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966
  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/cross_variety"
  9. request2 "eta/eta_api/models/data_manage/excel/request"
  10. "eta/eta_api/models/data_manage/request"
  11. "eta/eta_api/models/data_manage/response"
  12. "eta/eta_api/models/system"
  13. "eta/eta_api/services"
  14. "eta/eta_api/services/alarm_msg"
  15. "eta/eta_api/services/data"
  16. "eta/eta_api/services/data/data_manage_permission"
  17. excel2 "eta/eta_api/services/data/excel"
  18. "eta/eta_api/services/data_stat"
  19. "eta/eta_api/services/elastic"
  20. etaTrialService "eta/eta_api/services/eta_trial"
  21. "eta/eta_api/utils"
  22. "fmt"
  23. "sort"
  24. "strconv"
  25. "strings"
  26. "sync"
  27. "time"
  28. "github.com/rdlucklib/rdluck_tools/paging"
  29. )
  30. // EdbInfoController 数据管理
  31. type EdbInfoController struct {
  32. controllers.BaseAuthController
  33. }
  34. // EdbInfoSearch
  35. // @Title 新增指标-查询指标信息接口
  36. // @Description 新增指标-查询指标信息接口
  37. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  38. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  39. // @Param EdbCode query string false "指标编码/指标代码"
  40. // @Param StockCode query string false "证券代码"
  41. // @Param Frequency query string false "频度"
  42. // @Success 200 {object} data_manage.EdbInfoSearchResp
  43. // @router /edb_info/search [get]
  44. func (this *EdbInfoController) EdbInfoSearch() {
  45. br := new(models.BaseResponse).Init()
  46. defer func() {
  47. this.Data["json"] = br
  48. this.ServeJSON()
  49. }()
  50. source, _ := this.GetInt("Source")
  51. edbCode := this.GetString("EdbCode")
  52. edbCode = strings.Trim(edbCode, "\t")
  53. edbCode = strings.Trim(edbCode, " ")
  54. edbCode = strings.Replace(edbCode, "\t", "", -1)
  55. subSource, _ := this.GetInt("SubSource")
  56. stockCode := this.GetString("StockCode")
  57. frequency := this.GetString("Frequency")
  58. extraPars := this.GetString("ExtraPars")
  59. extraPars = strings.TrimSpace(extraPars)
  60. if source <= 0 {
  61. br.Msg = "无效的数据来源"
  62. return
  63. }
  64. if edbCode == "" {
  65. br.Msg = "请输入指标ID"
  66. return
  67. }
  68. //如果是彭博财务指标,那么需要传入客户code
  69. if source == utils.DATA_SOURCE_PB_FINANCE {
  70. companyCode := this.GetString("CompanyCode")
  71. companyCode = strings.Trim(companyCode, "\t")
  72. companyCode = strings.Trim(companyCode, " ")
  73. companyCode = strings.Replace(companyCode, "\t", "", -1)
  74. // 如果财务数据,那么需要拼接上客户code
  75. edbCode = companyCode + "&&" + edbCode
  76. }
  77. resp := new(data_manage.EdbInfoSearchResp)
  78. //判断指标是否存在
  79. var item *data_manage.EdbInfo
  80. var err error
  81. if utils.InArrayByInt([]int{utils.DATA_SOURCE_GL, utils.DATA_SOURCE_MYSTEEL_CHEMICAL}, source) {
  82. //source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  83. source, item, err = data.GetMySteelSourceByEdbCode(edbCode)
  84. if err != nil {
  85. br.Msg = "获取失败"
  86. br.ErrMsg = "获取失败,Err:" + err.Error()
  87. return
  88. }
  89. }
  90. if item == nil {
  91. item, err = data_manage.GetEdbInfoByEdbCode(source, edbCode)
  92. if err != nil {
  93. if err.Error() != utils.ErrNoRow() {
  94. br.Msg = "获取失败"
  95. br.ErrMsg = "获取失败,Err:" + err.Error()
  96. return
  97. }
  98. }
  99. }
  100. var isAdd bool
  101. var isInEdb bool //是否在指标库中
  102. if item != nil && item.EdbInfoId > 0 {
  103. isInEdb = true //在指标库中
  104. resp.Status = 1
  105. searchItem := new(data_manage.EdbInfoSearch)
  106. searchItem.EdbCode = item.EdbCode
  107. searchItem.StartDate = item.StartDate
  108. searchItem.EndDate = item.EndDate
  109. searchItem.EdbName = item.EdbName
  110. resp.SearchItem = searchItem
  111. //查询目录
  112. resultList, _ := data_manage.GetClassifyAllByClassifyId(item.ClassifyId)
  113. resp.ClassifyList = resultList
  114. // 查询该指标是否有权限
  115. obj := data_manage.EdbInfoNoPermissionAdmin{}
  116. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, item.EdbInfoId)
  117. if err != nil && err.Error() != utils.ErrNoRow() {
  118. br.Msg = "获取失败"
  119. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  120. return
  121. }
  122. if conf != nil {
  123. resp.Status = 3
  124. }
  125. } else {
  126. //dateNow := time.Now()
  127. //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDate)
  128. searchItem := new(data_manage.EdbInfoSearch)
  129. if source == utils.DATA_SOURCE_THS {
  130. fmt.Println("subSource:", subSource)
  131. if subSource == utils.DATA_SUB_SOURCE_EDB {
  132. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, subSource, utils.EDB_DATA_LIMIT)
  133. if err != nil && err.Error() != utils.ErrNoRow() {
  134. br.Msg = "获取失败"
  135. br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
  136. return
  137. }
  138. fmt.Println("ths len:", len(dataItems))
  139. if len(dataItems) > 0 {
  140. fmt.Println("ths data exist")
  141. searchItem.EdbCode = edbCode
  142. minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
  143. if err != nil {
  144. br.Msg = "获取失败"
  145. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  146. return
  147. }
  148. searchItem.DataList = dataItems
  149. searchItem.StartDate = minDate
  150. searchItem.EndDate = maxDate
  151. } else {
  152. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  153. //searchItem, err = data.GetEdbDataByThs(edbCode, startDate, endDate)
  154. //if err != nil {
  155. // br.Msg = "获取失败"
  156. // br.ErrMsg = "获取失败,Err:" + err.Error()
  157. // return
  158. //}
  159. respItem, err := data.AddEdbData(source, edbCode, frequency)
  160. if err != nil {
  161. br.Msg = "获取失败"
  162. br.ErrMsg = "获取失败,Err:" + err.Error()
  163. return
  164. }
  165. if respItem.Ret != 200 {
  166. br.Msg = "未搜索到该指标"
  167. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  168. return
  169. }
  170. isAdd = true
  171. }
  172. } else if subSource == utils.DATA_SUB_SOURCE_DATE {
  173. if stockCode == "" {
  174. br.Msg = "请输入证券代码"
  175. return
  176. }
  177. if edbCode == "" {
  178. br.Msg = "请输入指标代码"
  179. return
  180. }
  181. respItem, err := data.AddEdbDataThsDs(source, stockCode, edbCode, extraPars)
  182. if err != nil {
  183. br.Msg = "获取失败"
  184. br.ErrMsg = "获取失败,Err:" + err.Error()
  185. return
  186. }
  187. if respItem.Ret != 200 {
  188. if respItem.Ret == 421 {
  189. br.Msg = "该渠道已超过添加上限"
  190. } else if respItem.Ret == 4052 {
  191. br.Msg = "该指标已下架"
  192. } else {
  193. br.Msg = "未搜索到该指标"
  194. }
  195. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  196. return
  197. }
  198. isAdd = true
  199. } else {
  200. br.Msg = "无效的渠道来源"
  201. return
  202. }
  203. } else if source == utils.DATA_SOURCE_WIND {
  204. fmt.Println("subSource:", subSource)
  205. if subSource == utils.DATA_SUB_SOURCE_EDB {
  206. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_WIND, subSource, utils.EDB_DATA_LIMIT)
  207. if err != nil && err.Error() != utils.ErrNoRow() {
  208. br.Msg = "获取失败"
  209. br.ErrMsg = "获取Wind已存在信息失败,Err:" + err.Error()
  210. return
  211. }
  212. fmt.Println("wind dataItems:", len(dataItems))
  213. if len(dataItems) > 0 {
  214. searchItem.EdbCode = edbCode
  215. minDate, maxDate, err := data_manage.GetEdbDataWindMaxOrMinDate(edbCode)
  216. if err != nil {
  217. br.Msg = "获取失败"
  218. br.ErrMsg = "获取wind日期信息失败,Err:" + err.Error()
  219. return
  220. }
  221. searchItem.DataList = dataItems
  222. searchItem.StartDate = minDate
  223. searchItem.EndDate = maxDate
  224. } else {
  225. //endDate := dateNow.Format(utils.FormatDate)
  226. //searchItem, err = data.GetEdbDataByWind(edbCode, startDate, endDate)
  227. //if err != nil {
  228. // br.Msg = "获取失败"
  229. // br.ErrMsg = "wind 获取失败,Err:" + err.Error()
  230. // return
  231. //}
  232. respItem, err := data.AddEdbData(source, edbCode, frequency)
  233. if err != nil {
  234. br.Msg = "获取失败"
  235. br.ErrMsg = "获取失败,Err:" + err.Error()
  236. return
  237. }
  238. if respItem.Ret != 200 {
  239. if respItem.Ret == 421 {
  240. br.Msg = "该渠道已超过添加上限"
  241. } else if respItem.Ret == 4052 {
  242. br.Msg = "该指标已下架"
  243. } else {
  244. br.Msg = "未搜索到该指标"
  245. }
  246. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  247. return
  248. }
  249. isAdd = true
  250. }
  251. } else if subSource == utils.DATA_SUB_SOURCE_DATE {
  252. if stockCode == "" {
  253. br.Msg = "请输入证券代码"
  254. return
  255. }
  256. if edbCode == "" {
  257. br.Msg = "请输入指标代码"
  258. return
  259. }
  260. respItem, err := data.AddEdbDataWindWsd(source, stockCode, edbCode)
  261. if err != nil {
  262. br.Msg = "获取失败"
  263. br.ErrMsg = "获取失败,Err:" + err.Error()
  264. return
  265. }
  266. if respItem.Ret != 200 {
  267. if respItem.Ret == 421 {
  268. br.Msg = "该渠道已超过添加上限"
  269. } else if respItem.Ret == 4052 {
  270. br.Msg = "该指标已下架"
  271. } else {
  272. br.Msg = "未搜索到该指标"
  273. }
  274. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  275. return
  276. }
  277. isAdd = true
  278. } else {
  279. br.Msg = "无效的渠道来源"
  280. return
  281. }
  282. } else if source == utils.DATA_SOURCE_PB || source == utils.DATA_SOURCE_PB_FINANCE {
  283. fmt.Println("pb data exist")
  284. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  285. if err != nil && err.Error() != utils.ErrNoRow() {
  286. br.Msg = "获取失败"
  287. br.ErrMsg = "获取Pb已存在信息失败,Err:" + err.Error()
  288. return
  289. }
  290. fmt.Println("pb dataItems:", len(dataItems))
  291. if len(dataItems) > 0 {
  292. searchItem.EdbCode = edbCode
  293. minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(edbCode)
  294. if err != nil {
  295. br.Msg = "获取失败"
  296. br.ErrMsg = "获取Pb日期信息失败,Err:" + err.Error()
  297. return
  298. }
  299. searchItem.DataList = dataItems
  300. searchItem.StartDate = minDate
  301. searchItem.EndDate = maxDate
  302. } else {
  303. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  304. //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDateUnSpace)
  305. //searchItem, err = data.GetEdbDataByPb(edbCode, startDate, endDate)
  306. //if err != nil {
  307. // br.Msg = "获取失败"
  308. // br.ErrMsg = "彭博数据获取失败,Err:" + err.Error()
  309. // return
  310. //}
  311. respItem, err := data.AddEdbData(source, edbCode, frequency)
  312. if err != nil {
  313. br.Msg = "获取失败"
  314. br.ErrMsg = "获取失败,Err:" + err.Error()
  315. return
  316. }
  317. if respItem.Ret != 200 {
  318. br.Msg = "未搜索到该指标"
  319. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  320. return
  321. }
  322. isAdd = true
  323. }
  324. } else if source == utils.DATA_SOURCE_MANUAL { //手工数据指标
  325. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_MANUAL, subSource, utils.EDB_DATA_LIMIT)
  326. if err != nil && err.Error() != utils.ErrNoRow() {
  327. br.Msg = "获取失败"
  328. br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
  329. return
  330. }
  331. fmt.Println("ths len:", len(dataItems))
  332. if len(dataItems) > 0 {
  333. fmt.Println("ths data exist")
  334. searchItem.EdbCode = edbCode
  335. minDate, maxDate, err := data_manage.GetEdbDataManualMaxOrMinDate(edbCode)
  336. if err != nil {
  337. br.Msg = "获取失败"
  338. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  339. return
  340. }
  341. searchItem.DataList = dataItems
  342. searchItem.StartDate = minDate
  343. searchItem.EndDate = maxDate
  344. } else {
  345. //searchItem, err = data_manage.GetEdbDataByManual(edbCode, startDate, endDate)
  346. //if err != nil {
  347. // br.Msg = "获取失败"
  348. // br.ErrMsg = "获取失败,Err:" + err.Error()
  349. // return
  350. //}
  351. respItem, err := data.AddEdbData(source, edbCode, frequency)
  352. if err != nil {
  353. br.Msg = "获取失败"
  354. br.ErrMsg = "获取失败,Err:" + err.Error()
  355. return
  356. }
  357. if respItem.Ret != 200 {
  358. br.Msg = "未搜索到该指标"
  359. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  360. return
  361. }
  362. isAdd = true
  363. }
  364. //获取指标信息
  365. manualInfo, err := models.GetEdbinfoByTradeCode(edbCode)
  366. if err != nil && err.Error() != utils.ErrNoRow() {
  367. br.Msg = "获取失败"
  368. br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
  369. return
  370. }
  371. if manualInfo != nil {
  372. searchItem.Frequency = manualInfo.Frequency
  373. searchItem.Unit = manualInfo.Unit
  374. searchItem.EdbName = manualInfo.SecName
  375. }
  376. } else if source == utils.DATA_SOURCE_LZ {
  377. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LZ, subSource, utils.EDB_DATA_LIMIT)
  378. if err != nil && err.Error() != utils.ErrNoRow() {
  379. br.Msg = "获取失败"
  380. br.ErrMsg = "获取隆众已存在信息失败,Err:" + err.Error()
  381. return
  382. }
  383. fmt.Println("ths len:", len(dataItems))
  384. if len(dataItems) > 0 {
  385. fmt.Println("ths data exist")
  386. searchItem.EdbCode = edbCode
  387. minDate, maxDate, err := data_manage.GetEdbDataLzMaxOrMinDate(edbCode)
  388. if err != nil {
  389. br.Msg = "获取失败"
  390. br.ErrMsg = "获取隆众日期信息失败,Err:" + err.Error()
  391. return
  392. }
  393. searchItem.DataList = dataItems
  394. searchItem.StartDate = minDate
  395. searchItem.EndDate = maxDate
  396. } else {
  397. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  398. //searchItem, err = data_manage.GetEdbDataByLz(edbCode, startDate, endDate)
  399. //if err != nil {
  400. // br.Msg = "获取失败"
  401. // br.ErrMsg = "获取隆众数据失败,Err:" + err.Error()
  402. // return
  403. //}
  404. respItem, err := data.AddEdbData(source, edbCode, frequency)
  405. if err != nil {
  406. br.Msg = "获取失败"
  407. br.ErrMsg = "获取失败,Err:" + err.Error()
  408. return
  409. }
  410. if respItem.Ret != 200 {
  411. br.Msg = "未搜索到该指标"
  412. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  413. return
  414. }
  415. isAdd = true
  416. }
  417. //获取指标信息
  418. lzInfo, err := data_manage.GetLongzhongSurveyProductByCode(edbCode)
  419. if err != nil && err.Error() != utils.ErrNoRow() {
  420. br.Msg = "获取失败"
  421. br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
  422. return
  423. }
  424. if lzInfo != nil {
  425. frequency := lzInfo.Frequency
  426. var frequencyStr string
  427. if frequency == 1 {
  428. frequencyStr = "日度"
  429. } else if frequency == 2 {
  430. frequencyStr = "周度"
  431. } else if frequency == 3 {
  432. frequencyStr = "月度"
  433. } else if frequency == 4 {
  434. frequencyStr = "季度"
  435. } else if frequency == 5 {
  436. frequencyStr = "年度"
  437. } else if frequency == 99 {
  438. frequencyStr = "无固定频率"
  439. }
  440. searchItem.Frequency = frequencyStr
  441. searchItem.Unit = lzInfo.UnitName
  442. searchItem.EdbName = lzInfo.SampleName + lzInfo.BreedName + lzInfo.QuotaName
  443. }
  444. } else if source == utils.DATA_SOURCE_YS { //有色网
  445. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, subSource, utils.EDB_DATA_LIMIT)
  446. if err != nil && err.Error() != utils.ErrNoRow() {
  447. br.Msg = "获取失败"
  448. br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
  449. return
  450. }
  451. fmt.Println("dataItems:", len(dataItems))
  452. if len(dataItems) > 0 {
  453. searchItem.EdbCode = edbCode
  454. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  455. if err != nil {
  456. br.Msg = "获取失败"
  457. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  458. return
  459. }
  460. searchItem.DataList = dataItems
  461. searchItem.StartDate = minDate
  462. searchItem.EndDate = maxDate
  463. } else {
  464. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  465. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  466. //if err != nil {
  467. // br.Msg = "获取失败"
  468. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  469. // return
  470. //}
  471. //if searchItem.StartDate == "" {
  472. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  473. // searchItem.StartDate = minDate
  474. // searchItem.EndDate = maxDate
  475. //}
  476. respItem, err := data.AddEdbData(source, edbCode, frequency)
  477. if err != nil {
  478. br.Msg = "获取失败"
  479. br.ErrMsg = "获取失败,Err:" + err.Error()
  480. return
  481. }
  482. if respItem.Ret != 200 {
  483. br.Msg = "未搜索到该指标"
  484. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  485. return
  486. }
  487. isAdd = true
  488. }
  489. //获取指标信息
  490. smmInfo, err := data_manage.GetBaseFromSmmIndexByIndexCode(edbCode)
  491. if err != nil && err.Error() != utils.ErrNoRow() {
  492. br.Msg = "获取失败"
  493. br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
  494. return
  495. }
  496. if smmInfo != nil {
  497. searchItem.Frequency = smmInfo.Frequency
  498. searchItem.Unit = smmInfo.Unit
  499. searchItem.EdbName = smmInfo.IndexName
  500. }
  501. } else if source == utils.DATA_SOURCE_GL { //钢联
  502. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  503. if err != nil && err.Error() != utils.ErrNoRow() {
  504. br.Msg = "获取失败"
  505. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  506. return
  507. }
  508. if len(dataItems) > 0 {
  509. searchItem.EdbCode = edbCode
  510. minDate, maxDate, err := data_manage.GetEdbDataGlMaxOrMinDate(edbCode)
  511. if err != nil {
  512. br.Msg = "获取失败"
  513. br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
  514. return
  515. }
  516. searchItem.DataList = dataItems
  517. searchItem.StartDate = minDate
  518. searchItem.EndDate = maxDate
  519. } else {
  520. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  521. //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
  522. //if err != nil {
  523. // br.Msg = "获取失败"
  524. // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
  525. // return
  526. //}
  527. respItem, err := data.AddEdbData(source, edbCode, frequency)
  528. if err != nil {
  529. br.Msg = "获取失败"
  530. br.ErrMsg = "获取失败,Err:" + err.Error()
  531. return
  532. }
  533. if respItem.Ret != 200 {
  534. br.Msg = "未搜索到该指标"
  535. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  536. return
  537. }
  538. isAdd = true
  539. }
  540. //获取指标信息
  541. glInfo, err := data_manage.GetGlIndexByCode(edbCode)
  542. if err != nil && err.Error() != utils.ErrNoRow() {
  543. br.Msg = "获取失败"
  544. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  545. return
  546. }
  547. if glInfo != nil {
  548. searchItem.Frequency = glInfo.FrequencyName
  549. searchItem.Unit = glInfo.UnitName
  550. searchItem.EdbName = glInfo.IndexName
  551. }
  552. } else if source == utils.DATA_SOURCE_ZZ { //郑商所
  553. var suffix string
  554. if strings.Contains(edbCode, "deal") {
  555. suffix = "deal"
  556. } else if strings.Contains(edbCode, "buy") {
  557. suffix = "buy"
  558. } else if strings.Contains(edbCode, "sold") {
  559. suffix = "sold"
  560. } else {
  561. br.Msg = "未搜索到该指标"
  562. br.ErrMsg = "指标code异常"
  563. return
  564. }
  565. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  566. if err != nil && err.Error() != utils.ErrNoRow() {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取郑商所已存在信息失败,Err:" + err.Error()
  569. return
  570. }
  571. if len(dataItems) > 0 {
  572. searchItem.EdbCode = edbCode
  573. minDate, maxDate, err := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
  574. if err != nil {
  575. br.Msg = "获取失败"
  576. br.ErrMsg = "获取郑商所日期信息失败,Err:" + err.Error()
  577. return
  578. }
  579. searchItem.DataList = dataItems
  580. searchItem.StartDate = minDate
  581. searchItem.EndDate = maxDate
  582. } else {
  583. //searchItem, err = data_manage.GetEdbDataByZz(edbCode, suffix, startDate, "")
  584. //if err != nil {
  585. // br.Msg = "获取失败"
  586. // br.ErrMsg = "获取失败,GetEdbDataByZz Err:" + err.Error()
  587. // return
  588. //}
  589. //if searchItem.StartDate == "" {
  590. // minDate, maxDate, _ := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
  591. // searchItem.StartDate = minDate
  592. // searchItem.EndDate = maxDate
  593. //}
  594. respItem, err := data.AddEdbData(source, edbCode, frequency)
  595. if err != nil {
  596. br.Msg = "获取失败"
  597. br.ErrMsg = "获取失败,Err:" + err.Error()
  598. return
  599. }
  600. if respItem.Ret != 200 {
  601. br.Msg = "未搜索到该指标"
  602. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  603. return
  604. }
  605. isAdd = true
  606. }
  607. //获取指标信息
  608. allInfo, err := data_manage.GetBaseInfoFromZhengzhouByIndexCode(edbCode, suffix)
  609. if err != nil && err.Error() != utils.ErrNoRow() {
  610. br.Msg = "获取失败"
  611. br.ErrMsg = "获取郑商所指标详情失败,Err:" + err.Error()
  612. return
  613. }
  614. var zzInfo *data_manage.BaseInfoFromZz
  615. if allInfo != nil {
  616. zzInfo = allInfo[0]
  617. }
  618. if zzInfo != nil {
  619. searchItem.Frequency = "日度"
  620. searchItem.Unit = "手"
  621. if suffix == "deal" {
  622. searchItem.EdbName = zzInfo.DealName
  623. } else if suffix == "buy" {
  624. searchItem.EdbName = zzInfo.BuyName
  625. } else {
  626. searchItem.EdbName = zzInfo.SoldName
  627. }
  628. }
  629. } else if source == utils.DATA_SOURCE_DL { //大商所
  630. var suffix string
  631. if strings.Contains(edbCode, "deal") {
  632. suffix = "deal"
  633. } else if strings.Contains(edbCode, "buy") {
  634. suffix = "buy"
  635. } else if strings.Contains(edbCode, "sold") {
  636. suffix = "sold"
  637. } else {
  638. br.Msg = "未搜索到该指标"
  639. br.ErrMsg = "指标code异常"
  640. return
  641. }
  642. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  643. if err != nil && err.Error() != utils.ErrNoRow() {
  644. br.Msg = "获取失败"
  645. br.ErrMsg = "获取大商所已存在信息失败,Err:" + err.Error()
  646. return
  647. }
  648. if len(dataItems) > 0 {
  649. searchItem.EdbCode = edbCode
  650. minDate, maxDate, err := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
  651. if err != nil {
  652. br.Msg = "获取失败"
  653. br.ErrMsg = "获取大商所日期信息失败,Err:" + err.Error()
  654. return
  655. }
  656. searchItem.DataList = dataItems
  657. searchItem.StartDate = minDate
  658. searchItem.EndDate = maxDate
  659. } else {
  660. //searchItem, err = data_manage.GetEdbDataByDl(edbCode, suffix, startDate, "")
  661. //if err != nil {
  662. // br.Msg = "获取失败"
  663. // br.ErrMsg = "获取失败,GetEdbDataByDl Err:" + err.Error()
  664. // return
  665. //}
  666. //if searchItem.StartDate == "" {
  667. // minDate, maxDate, _ := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
  668. // searchItem.StartDate = minDate
  669. // searchItem.EndDate = maxDate
  670. //}
  671. respItem, err := data.AddEdbData(source, edbCode, frequency)
  672. if err != nil {
  673. br.Msg = "获取失败"
  674. br.ErrMsg = "获取失败,Err:" + err.Error()
  675. return
  676. }
  677. if respItem.Ret != 200 {
  678. br.Msg = "未搜索到该指标"
  679. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  680. return
  681. }
  682. isAdd = true
  683. }
  684. //获取指标信息
  685. allInfo, err := data_manage.GetBaseInfoFromDalianByIndexCode(edbCode, suffix)
  686. if err != nil && err.Error() != utils.ErrNoRow() {
  687. br.Msg = "获取失败"
  688. br.ErrMsg = "获取大商所指标详情失败,Err:" + err.Error()
  689. return
  690. }
  691. var dlInfo *data_manage.BaseInfoFromDl
  692. if allInfo != nil {
  693. dlInfo = allInfo[0]
  694. }
  695. if dlInfo != nil {
  696. searchItem.Frequency = "日度"
  697. searchItem.Unit = "手"
  698. if suffix == "deal" {
  699. searchItem.EdbName = dlInfo.DealName
  700. } else if suffix == "buy" {
  701. searchItem.EdbName = dlInfo.BuyName
  702. } else {
  703. searchItem.EdbName = dlInfo.SoldName
  704. }
  705. }
  706. } else if source == utils.DATA_SOURCE_SH { //上期所
  707. var suffix string
  708. if strings.Contains(edbCode, "deal") {
  709. suffix = "deal"
  710. } else if strings.Contains(edbCode, "buy") {
  711. suffix = "buy"
  712. } else if strings.Contains(edbCode, "sold") {
  713. suffix = "sold"
  714. } else {
  715. br.Msg = "未搜索到该指标"
  716. br.ErrMsg = "指标code异常"
  717. return
  718. }
  719. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  720. if err != nil && err.Error() != utils.ErrNoRow() {
  721. br.Msg = "获取失败"
  722. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  723. return
  724. }
  725. if len(dataItems) > 0 {
  726. searchItem.EdbCode = edbCode
  727. minDate, maxDate, err := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
  728. if err != nil {
  729. br.Msg = "获取失败"
  730. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  731. return
  732. }
  733. searchItem.DataList = dataItems
  734. searchItem.StartDate = minDate
  735. searchItem.EndDate = maxDate
  736. } else {
  737. //searchItem, err = data_manage.GetEdbDataBySh(edbCode, suffix, startDate, "")
  738. //if err != nil {
  739. // br.Msg = "获取失败"
  740. // br.ErrMsg = "获取失败,GetEdbDataBySh Err:" + err.Error()
  741. // return
  742. //}
  743. //if searchItem.StartDate == "" {
  744. // minDate, maxDate, _ := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
  745. // searchItem.StartDate = minDate
  746. // searchItem.EndDate = maxDate
  747. //}
  748. respItem, err := data.AddEdbData(source, edbCode, frequency)
  749. if err != nil {
  750. br.Msg = "获取失败"
  751. br.ErrMsg = "获取失败,Err:" + err.Error()
  752. return
  753. }
  754. if respItem.Ret != 200 {
  755. br.Msg = "未搜索到该指标"
  756. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  757. return
  758. }
  759. isAdd = true
  760. }
  761. //获取指标信息
  762. allInfo, err := data_manage.GetBaseInfoFromShByIndexCode(edbCode, suffix)
  763. if err != nil && err.Error() != utils.ErrNoRow() {
  764. br.Msg = "获取失败"
  765. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  766. return
  767. }
  768. var shInfo *data_manage.BaseInfoFromSh
  769. if allInfo != nil {
  770. shInfo = allInfo[0]
  771. }
  772. if shInfo != nil {
  773. searchItem.Frequency = "日度"
  774. searchItem.Unit = "手"
  775. if suffix == "deal" {
  776. searchItem.EdbName = shInfo.DealName
  777. } else if suffix == "buy" {
  778. searchItem.EdbName = shInfo.BuyName
  779. } else {
  780. searchItem.EdbName = shInfo.SoldName
  781. }
  782. }
  783. } else if source == utils.DATA_SOURCE_CFFEX { //中金所
  784. var suffix string
  785. if strings.Contains(edbCode, "deal") {
  786. suffix = "deal"
  787. } else if strings.Contains(edbCode, "buy") {
  788. suffix = "buy"
  789. } else if strings.Contains(edbCode, "sold") {
  790. suffix = "sold"
  791. } else {
  792. br.Msg = "未搜索到该指标"
  793. br.ErrMsg = "指标code异常"
  794. return
  795. }
  796. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  797. if err != nil && err.Error() != utils.ErrNoRow() {
  798. br.Msg = "获取失败"
  799. br.ErrMsg = "获取中金所已存在信息失败,Err:" + err.Error()
  800. return
  801. }
  802. if len(dataItems) > 0 {
  803. searchItem.EdbCode = edbCode
  804. minDate, maxDate, err := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  805. if err != nil {
  806. br.Msg = "获取失败"
  807. br.ErrMsg = "获取中金所日期信息失败,Err:" + err.Error()
  808. return
  809. }
  810. searchItem.DataList = dataItems
  811. searchItem.StartDate = minDate
  812. searchItem.EndDate = maxDate
  813. } else {
  814. //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
  815. //if err != nil {
  816. // br.Msg = "获取失败"
  817. // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
  818. // return
  819. //}
  820. //if searchItem.StartDate == "" {
  821. // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  822. // searchItem.StartDate = minDate
  823. // searchItem.EndDate = maxDate
  824. //}
  825. respItem, err := data.AddEdbData(source, edbCode, frequency)
  826. if err != nil {
  827. br.Msg = "获取失败"
  828. br.ErrMsg = "获取失败,Err:" + err.Error()
  829. return
  830. }
  831. if respItem.Ret != 200 {
  832. br.Msg = "未搜索到该指标"
  833. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  834. return
  835. }
  836. isAdd = true
  837. }
  838. //获取指标信息
  839. allInfo, err := data_manage.GetBaseInfoFromCffexByIndexCode(edbCode, suffix)
  840. if err != nil && err.Error() != utils.ErrNoRow() {
  841. br.Msg = "获取失败"
  842. br.ErrMsg = "获取中金所指标详情失败,Err:" + err.Error()
  843. return
  844. }
  845. var cffexInfo *data_manage.BaseInfoFromCffex
  846. if allInfo != nil {
  847. cffexInfo = allInfo[0]
  848. }
  849. if cffexInfo != nil {
  850. searchItem.Frequency = "日度"
  851. searchItem.Unit = "手"
  852. if suffix == "deal" {
  853. searchItem.EdbName = cffexInfo.DealName
  854. } else if suffix == "buy" {
  855. searchItem.EdbName = cffexInfo.BuyName
  856. } else {
  857. searchItem.EdbName = cffexInfo.SoldName
  858. }
  859. }
  860. } else if source == utils.DATA_SOURCE_SHFE { //上期能源
  861. var suffix string
  862. if strings.Contains(edbCode, "deal") {
  863. suffix = "deal"
  864. } else if strings.Contains(edbCode, "buy") {
  865. suffix = "buy"
  866. } else if strings.Contains(edbCode, "sold") {
  867. suffix = "sold"
  868. } else {
  869. br.Msg = "未搜索到该指标"
  870. br.ErrMsg = "指标code异常"
  871. return
  872. }
  873. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  874. if err != nil && err.Error() != utils.ErrNoRow() {
  875. br.Msg = "获取失败"
  876. br.ErrMsg = "获取上期能源已存在信息失败,Err:" + err.Error()
  877. return
  878. }
  879. if len(dataItems) > 0 {
  880. searchItem.EdbCode = edbCode
  881. minDate, maxDate, err := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
  882. if err != nil {
  883. br.Msg = "获取失败"
  884. br.ErrMsg = "获取上期能源日期信息失败,Err:" + err.Error()
  885. return
  886. }
  887. searchItem.DataList = dataItems
  888. searchItem.StartDate = minDate
  889. searchItem.EndDate = maxDate
  890. } else {
  891. //searchItem, err = data_manage.GetEdbDataByShfe(edbCode, suffix, startDate, "")
  892. //if err != nil {
  893. // br.Msg = "获取失败"
  894. // br.ErrMsg = "获取失败,GetEdbDataByShfe Err:" + err.Error()
  895. // return
  896. //}
  897. //if searchItem.StartDate == "" {
  898. // minDate, maxDate, _ := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
  899. // searchItem.StartDate = minDate
  900. // searchItem.EndDate = maxDate
  901. //}
  902. respItem, err := data.AddEdbData(source, edbCode, frequency)
  903. if err != nil {
  904. br.Msg = "获取失败"
  905. br.ErrMsg = "获取失败,Err:" + err.Error()
  906. return
  907. }
  908. if respItem.Ret != 200 {
  909. br.Msg = "未搜索到该指标"
  910. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  911. return
  912. }
  913. isAdd = true
  914. }
  915. //获取指标信息
  916. allInfo, err := data_manage.GetBaseInfoFromShfeByIndexCode(edbCode, suffix)
  917. if err != nil && err.Error() != utils.ErrNoRow() {
  918. br.Msg = "获取失败"
  919. br.ErrMsg = "获取上期能源指标详情失败,Err:" + err.Error()
  920. return
  921. }
  922. var shfeInfo *data_manage.BaseInfoFromShfe
  923. if allInfo != nil {
  924. shfeInfo = allInfo[0]
  925. }
  926. if shfeInfo != nil {
  927. searchItem.Frequency = "日度"
  928. searchItem.Unit = "手"
  929. if suffix == "deal" {
  930. searchItem.EdbName = shfeInfo.DealName
  931. } else if suffix == "buy" {
  932. searchItem.EdbName = shfeInfo.BuyName
  933. } else {
  934. searchItem.EdbName = shfeInfo.SoldName
  935. }
  936. }
  937. } else if source == utils.DATA_SOURCE_GIE { //欧洲天然气
  938. var suffix string
  939. l := len(edbCode)
  940. if strings.Contains(edbCode[l-2:], "GS") {
  941. suffix = "GS"
  942. } else if strings.Contains(edbCode[l-2:], "CF") {
  943. suffix = "CF"
  944. } else if strings.Contains(edbCode[l-1:], "T") {
  945. suffix = "T"
  946. } else if strings.Contains(edbCode[l-2:], "In") {
  947. suffix = "In"
  948. } else if strings.Contains(edbCode[l-3:], "Out") {
  949. suffix = "Out"
  950. } else if strings.Contains(edbCode[l-3:], "WGV") {
  951. suffix = "WGV"
  952. } else if strings.Contains(edbCode[l-2:], "IC") {
  953. suffix = "IC"
  954. } else if strings.Contains(edbCode[l-2:], "WC") {
  955. suffix = "WC"
  956. } else if strings.Contains(edbCode[l-1:], "F") {
  957. suffix = "F"
  958. } else if strings.Contains(edbCode[l-1:], "C") {
  959. suffix = "C"
  960. } else {
  961. br.Msg = "未搜索到该指标"
  962. br.ErrMsg = "指标code异常"
  963. return
  964. }
  965. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  966. if err != nil && err.Error() != utils.ErrNoRow() {
  967. br.Msg = "获取失败"
  968. br.ErrMsg = "获取欧洲天然气已存在信息失败,Err:" + err.Error()
  969. return
  970. }
  971. if len(dataItems) > 0 {
  972. searchItem.EdbCode = edbCode
  973. minDate, maxDate, err := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
  974. if err != nil {
  975. br.Msg = "获取失败"
  976. br.ErrMsg = "获取欧洲天然气日期信息失败,Err:" + err.Error()
  977. return
  978. }
  979. searchItem.DataList = dataItems
  980. searchItem.StartDate = minDate
  981. searchItem.EndDate = maxDate
  982. } else {
  983. //searchItem, err = data_manage.GetEdbDataByGie(edbCode, suffix, startDate, "")
  984. //if err != nil {
  985. // br.Msg = "获取失败"
  986. // br.ErrMsg = "获取失败,GetEdbDataByGie Err:" + err.Error()
  987. // return
  988. //}
  989. //if searchItem.StartDate == "" {
  990. // minDate, maxDate, _ := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
  991. // searchItem.StartDate = minDate
  992. // searchItem.EndDate = maxDate
  993. //}
  994. respItem, err := data.AddEdbData(source, edbCode, frequency)
  995. if err != nil {
  996. br.Msg = "获取失败"
  997. br.ErrMsg = "获取失败,Err:" + err.Error()
  998. return
  999. }
  1000. if respItem.Ret != 200 {
  1001. br.Msg = "未搜索到该指标"
  1002. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1003. return
  1004. }
  1005. isAdd = true
  1006. }
  1007. //获取指标信息
  1008. allInfo, err := data_manage.GetBaseFromEicDataAllByIndexCodeV2(edbCode, suffix)
  1009. if err != nil && err.Error() != utils.ErrNoRow() {
  1010. br.Msg = "获取失败"
  1011. br.ErrMsg = "获取欧洲天然气指标详情失败,Err:" + err.Error()
  1012. return
  1013. }
  1014. var eicInfo *data_manage.BaseFromTradeEicIndexV2
  1015. if allInfo != nil {
  1016. eicInfo = allInfo[0]
  1017. }
  1018. var name string
  1019. if eicInfo != nil {
  1020. searchItem.Frequency = "日度"
  1021. if suffix == "GS" {
  1022. name = eicInfo.Name + "_gas_in_storage"
  1023. searchItem.EdbName = name
  1024. searchItem.Unit = "TWh"
  1025. } else if suffix == "C" {
  1026. name = eicInfo.Name + "_consumption"
  1027. searchItem.EdbName = name
  1028. searchItem.Unit = "TWh"
  1029. } else if suffix == "CF" {
  1030. name = eicInfo.Name + "_consumption_full"
  1031. searchItem.EdbName = name
  1032. searchItem.Unit = "百分比"
  1033. } else if suffix == "F" {
  1034. name = eicInfo.Name + "_full"
  1035. searchItem.EdbName = name
  1036. searchItem.Unit = "百分比"
  1037. } else if suffix == "T" {
  1038. name = eicInfo.Name + "_trend"
  1039. searchItem.EdbName = name
  1040. searchItem.Unit = "百分比"
  1041. } else if suffix == "In" {
  1042. name = eicInfo.Name + "_injection"
  1043. searchItem.EdbName = name
  1044. searchItem.Unit = "GWH/d"
  1045. } else if suffix == "Out" {
  1046. name = eicInfo.Name + "_withdrawal"
  1047. searchItem.EdbName = name
  1048. searchItem.Unit = "GWH/d"
  1049. } else if suffix == "WGV" {
  1050. name = eicInfo.Name + "_working_gas_volume"
  1051. searchItem.EdbName = name
  1052. searchItem.Unit = "TWh"
  1053. } else if suffix == "IC" {
  1054. name = eicInfo.Name + "_injection_capacity"
  1055. searchItem.EdbName = name
  1056. searchItem.Unit = "GWh/d"
  1057. } else if suffix == "WC" {
  1058. name = eicInfo.Name + "_withdrawal_capacity"
  1059. searchItem.EdbName = name
  1060. searchItem.Unit = "GWh/d"
  1061. }
  1062. }
  1063. } else if source == utils.DATA_SOURCE_LT {
  1064. fmt.Println("lt data exist")
  1065. if strings.Contains(edbCode, "=") {
  1066. br.Msg = "暂不支持编码中含有=的指标"
  1067. br.ErrMsg = "暂不支持编码中含有=的指标"
  1068. return
  1069. }
  1070. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LT, subSource, utils.EDB_DATA_LIMIT)
  1071. if err != nil && err.Error() != utils.ErrNoRow() {
  1072. br.Msg = "获取失败"
  1073. br.ErrMsg = "获取 lt 已存在信息失败,Err:" + err.Error()
  1074. return
  1075. }
  1076. fmt.Println("lt dataItems:", len(dataItems))
  1077. if len(dataItems) > 0 {
  1078. searchItem.EdbCode = edbCode
  1079. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1080. if err != nil {
  1081. br.Msg = "获取失败"
  1082. br.ErrMsg = "获取lt日期信息失败,Err:" + err.Error()
  1083. return
  1084. }
  1085. searchItem.DataList = dataItems
  1086. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1087. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1088. } else {
  1089. //endDate := dateNow.Format(utils.FormatDate)
  1090. //searchItem, err = data.GetEdbDataByLt(edbCode, startDate, endDate)
  1091. //if err != nil {
  1092. // br.Msg = "获取失败"
  1093. // br.ErrMsg = "lt 获取失败,Err:" + err.Error()
  1094. // return
  1095. //}
  1096. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1097. if err != nil {
  1098. br.Msg = "获取失败"
  1099. br.ErrMsg = "获取失败,Err:" + err.Error()
  1100. return
  1101. }
  1102. if respItem.Ret != 200 {
  1103. br.Msg = respItem.Msg
  1104. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1105. return
  1106. }
  1107. isAdd = true
  1108. }
  1109. } else if source == utils.DATA_SOURCE_COAL { //中国煤炭市场网
  1110. var suffix string
  1111. if strings.Contains(edbCode, "jsm") {
  1112. suffix = "jsm_index"
  1113. } else if strings.Contains(edbCode, "company") {
  1114. suffix = "company_index"
  1115. } else if strings.Contains(edbCode, "firm") {
  1116. suffix = "firm_index"
  1117. } else if strings.Contains(edbCode, "coastal") {
  1118. suffix = "coastal_index"
  1119. } else if strings.Contains(edbCode, "inland") {
  1120. suffix = "inland_index"
  1121. } else {
  1122. br.Msg = "未搜索到该指标"
  1123. br.ErrMsg = "指标code异常"
  1124. return
  1125. }
  1126. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1127. if err != nil && err.Error() != utils.ErrNoRow() {
  1128. br.Msg = "获取失败"
  1129. br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
  1130. return
  1131. }
  1132. if len(dataItems) > 0 {
  1133. searchItem.EdbCode = edbCode
  1134. minDate, maxDate, err := data_manage.GetEdbDataCoalMaxOrMinDate(edbCode)
  1135. if err != nil {
  1136. br.Msg = "获取失败"
  1137. br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
  1138. return
  1139. }
  1140. searchItem.DataList = dataItems
  1141. searchItem.StartDate = minDate
  1142. searchItem.EndDate = maxDate
  1143. } else {
  1144. //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
  1145. //if err != nil {
  1146. // br.Msg = "获取失败"
  1147. // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
  1148. // return
  1149. //}
  1150. //if searchItem.StartDate == "" {
  1151. // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  1152. // searchItem.StartDate = minDate
  1153. // searchItem.EndDate = maxDate
  1154. //}
  1155. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1156. if err != nil {
  1157. br.Msg = "获取失败"
  1158. br.ErrMsg = "获取失败,Err:" + err.Error()
  1159. return
  1160. }
  1161. if respItem.Ret != 200 {
  1162. br.Msg = "未搜索到该指标"
  1163. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1164. return
  1165. }
  1166. isAdd = true
  1167. }
  1168. //获取指标信息
  1169. allInfo, err := data_manage.GetBaseInfoFromCoalByIndexCode(edbCode, suffix)
  1170. if err != nil && err.Error() != utils.ErrNoRow() {
  1171. br.Msg = "获取失败"
  1172. br.ErrMsg = "获取煤炭网指标详情失败,Err:" + err.Error()
  1173. return
  1174. }
  1175. var coalInfo *data_manage.BaseInfoFromCoal
  1176. if allInfo != nil {
  1177. coalInfo = allInfo[0]
  1178. }
  1179. if coalInfo != nil {
  1180. searchItem.Frequency = coalInfo.Frequency
  1181. searchItem.Unit = coalInfo.Unit
  1182. searchItem.EdbName = coalInfo.IndexName
  1183. }
  1184. } else if source == utils.DATA_SOURCE_GOOGLE_TRAVEL { //谷歌出行数据
  1185. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1186. if err != nil && err.Error() != utils.ErrNoRow() {
  1187. br.Msg = "获取失败"
  1188. br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
  1189. return
  1190. }
  1191. if len(dataItems) > 0 {
  1192. searchItem.EdbCode = edbCode
  1193. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1194. if err != nil {
  1195. br.Msg = "获取失败"
  1196. br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
  1197. return
  1198. }
  1199. if item != nil {
  1200. searchItem.DataList = dataItems
  1201. searchItem.StartDate = item.MinDate
  1202. searchItem.EndDate = item.MaxDate
  1203. }
  1204. } else {
  1205. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1206. if err != nil {
  1207. br.Msg = "获取失败"
  1208. br.ErrMsg = "获取失败,Err:" + err.Error()
  1209. return
  1210. }
  1211. if respItem.Ret != 200 {
  1212. br.Msg = "未搜索到该指标"
  1213. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1214. return
  1215. }
  1216. isAdd = true
  1217. }
  1218. } else if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL { //上海钢联
  1219. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1220. if err != nil && err.Error() != utils.ErrNoRow() {
  1221. br.Msg = "获取失败"
  1222. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1223. return
  1224. }
  1225. if len(dataItems) > 0 {
  1226. searchItem.EdbCode = edbCode
  1227. minDate, maxDate, err := data_manage.GetEdbDataMysteelChemicalMaxOrMinDate(edbCode)
  1228. if err != nil {
  1229. br.Msg = "获取失败"
  1230. br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
  1231. return
  1232. }
  1233. searchItem.DataList = dataItems
  1234. searchItem.StartDate = minDate
  1235. searchItem.EndDate = maxDate
  1236. } else {
  1237. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1238. //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
  1239. //if err != nil {
  1240. // br.Msg = "获取失败"
  1241. // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
  1242. // return
  1243. //}
  1244. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1245. if err != nil {
  1246. br.Msg = "获取失败"
  1247. br.ErrMsg = "获取失败,Err:" + err.Error()
  1248. return
  1249. }
  1250. if respItem.Ret != 200 {
  1251. br.Msg = "未搜索到该指标"
  1252. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1253. return
  1254. }
  1255. isAdd = true
  1256. }
  1257. //获取指标信息
  1258. glInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
  1259. if err != nil && err.Error() != utils.ErrNoRow() {
  1260. br.Msg = "获取失败"
  1261. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1262. return
  1263. }
  1264. if glInfo != nil {
  1265. searchItem.Frequency = glInfo.Frequency
  1266. searchItem.Unit = glInfo.Unit
  1267. searchItem.EdbName = glInfo.IndexName
  1268. }
  1269. } else if source == utils.DATA_SOURCE_EIA_STEO { //eia steo报告
  1270. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1271. if err != nil && err.Error() != utils.ErrNoRow() {
  1272. br.Msg = "获取失败"
  1273. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1274. return
  1275. }
  1276. if len(dataItems) > 0 {
  1277. searchItem.EdbCode = edbCode
  1278. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1279. if err != nil {
  1280. br.Msg = "获取失败"
  1281. br.ErrMsg = "获取eia steo日期信息失败,Err:" + err.Error()
  1282. return
  1283. }
  1284. searchItem.DataList = dataItems
  1285. searchItem.StartDate = item.MinDate
  1286. searchItem.EndDate = item.MaxDate
  1287. } else {
  1288. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1289. if err != nil {
  1290. br.Msg = "获取失败"
  1291. br.ErrMsg = "获取失败,Err:" + err.Error()
  1292. return
  1293. }
  1294. if respItem.Ret != 200 {
  1295. br.Msg = "未搜索到该指标"
  1296. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1297. return
  1298. }
  1299. isAdd = true
  1300. }
  1301. //获取指标信息
  1302. eiasteoInfo, err := data_manage.GetBaseFromEiaSteoIndexByCode(edbCode)
  1303. if err != nil && err.Error() != utils.ErrNoRow() {
  1304. br.Msg = "获取失败"
  1305. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1306. return
  1307. }
  1308. if eiasteoInfo != nil {
  1309. searchItem.Frequency = eiasteoInfo.Frequency
  1310. searchItem.Unit = eiasteoInfo.Unit
  1311. searchItem.EdbName = eiasteoInfo.IndexName
  1312. }
  1313. } else if source == utils.DATA_SOURCE_COM_TRADE { // un数据源
  1314. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1315. if err != nil && err.Error() != utils.ErrNoRow() {
  1316. br.Msg = "获取失败"
  1317. br.ErrMsg = "获取联合国商品贸易数据已存在信息失败,Err:" + err.Error()
  1318. return
  1319. }
  1320. if len(dataItems) > 0 {
  1321. searchItem.EdbCode = edbCode
  1322. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1323. if err != nil {
  1324. br.Msg = "获取失败"
  1325. br.ErrMsg = "获取联合国商品贸易数据日期信息失败,Err:" + err.Error()
  1326. return
  1327. }
  1328. searchItem.DataList = dataItems
  1329. searchItem.StartDate = item.MinDate
  1330. searchItem.EndDate = item.MaxDate
  1331. } else {
  1332. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1333. if err != nil {
  1334. br.Msg = "获取失败"
  1335. br.ErrMsg = "获取失败,Err:" + err.Error()
  1336. return
  1337. }
  1338. if respItem.Ret != 200 {
  1339. br.Msg = "未搜索到该指标"
  1340. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1341. return
  1342. }
  1343. isAdd = true
  1344. }
  1345. //获取指标信息
  1346. eiasteoInfo, err := data_manage.GetComTradeIndex(edbCode)
  1347. if err != nil && err.Error() != utils.ErrNoRow() {
  1348. br.Msg = "获取失败"
  1349. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1350. return
  1351. }
  1352. if eiasteoInfo != nil {
  1353. //eiasteoInfo.
  1354. if eiasteoInfo.Type <= 2 {
  1355. searchItem.Frequency = `年度`
  1356. } else {
  1357. searchItem.Frequency = `月度`
  1358. }
  1359. if eiasteoInfo.Type == 1 || eiasteoInfo.Type == 3 {
  1360. searchItem.Unit = "美元"
  1361. } else {
  1362. searchItem.Unit = "千克"
  1363. }
  1364. searchItem.EdbName = eiasteoInfo.Name
  1365. }
  1366. } else if source == utils.DATA_SOURCE_SCI { //卓创数据(红桃三)
  1367. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1368. if err != nil && err.Error() != utils.ErrNoRow() {
  1369. br.Msg = "获取失败"
  1370. br.ErrMsg = "获取SCI已存在信息失败,Err:" + err.Error()
  1371. return
  1372. }
  1373. fmt.Println("dataItems:", len(dataItems))
  1374. if len(dataItems) > 0 {
  1375. searchItem.EdbCode = edbCode
  1376. minDate, maxDate, err := data_manage.GetEdbDataSciMaxAndMinDate(edbCode)
  1377. if err != nil {
  1378. br.Msg = "获取失败"
  1379. br.ErrMsg = "获取SCI日期信息失败,Err:" + err.Error()
  1380. return
  1381. }
  1382. searchItem.DataList = dataItems
  1383. searchItem.StartDate = minDate
  1384. searchItem.EndDate = maxDate
  1385. } else {
  1386. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1387. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  1388. //if err != nil {
  1389. // br.Msg = "获取失败"
  1390. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  1391. // return
  1392. //}
  1393. //if searchItem.StartDate == "" {
  1394. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  1395. // searchItem.StartDate = minDate
  1396. // searchItem.EndDate = maxDate
  1397. //}
  1398. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1399. if err != nil {
  1400. br.Msg = "获取失败"
  1401. br.ErrMsg = "获取失败,Err:" + err.Error()
  1402. return
  1403. }
  1404. if respItem.Ret != 200 {
  1405. br.Msg = "未搜索到该指标"
  1406. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1407. return
  1408. }
  1409. isAdd = true
  1410. }
  1411. //获取指标信息
  1412. smmInfo, err := data_manage.GetBaseFromSciIndexByIndexCode(edbCode)
  1413. if err != nil && err.Error() != utils.ErrNoRow() {
  1414. br.Msg = "获取失败"
  1415. br.ErrMsg = "获取Sci指标详情失败,Err:" + err.Error()
  1416. return
  1417. }
  1418. if smmInfo != nil {
  1419. searchItem.Frequency = smmInfo.Frequency
  1420. searchItem.Unit = smmInfo.Unit
  1421. searchItem.EdbName = smmInfo.IndexName
  1422. }
  1423. } else if source == utils.DATA_SOURCE_BAIINFO { //百川盈孚
  1424. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1425. if err != nil && err.Error() != utils.ErrNoRow() {
  1426. br.Msg = "获取失败"
  1427. br.ErrMsg = "获取BAIINFO已存在信息失败,Err:" + err.Error()
  1428. return
  1429. }
  1430. fmt.Println("dataItems:", len(dataItems))
  1431. if len(dataItems) > 0 {
  1432. searchItem.EdbCode = edbCode
  1433. minDate, maxDate, err := data_manage.GetEdbDataBaiinfoMaxAndMinDate(edbCode)
  1434. if err != nil {
  1435. br.Msg = "获取失败"
  1436. br.ErrMsg = "获取BAIINFO日期信息失败,Err:" + err.Error()
  1437. return
  1438. }
  1439. searchItem.DataList = dataItems
  1440. searchItem.StartDate = minDate
  1441. searchItem.EndDate = maxDate
  1442. } else {
  1443. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1444. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  1445. //if err != nil {
  1446. // br.Msg = "获取失败"
  1447. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  1448. // return
  1449. //}
  1450. //if searchItem.StartDate == "" {
  1451. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  1452. // searchItem.StartDate = minDate
  1453. // searchItem.EndDate = maxDate
  1454. //}
  1455. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1456. if err != nil {
  1457. br.Msg = "获取失败"
  1458. br.ErrMsg = "获取失败,Err:" + err.Error()
  1459. return
  1460. }
  1461. if respItem.Ret != 200 {
  1462. br.Msg = "未搜索到该指标"
  1463. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1464. return
  1465. }
  1466. isAdd = true
  1467. }
  1468. //获取指标信息
  1469. baiInfo, err := data_manage.GetBaseFromBaiinfoIndexByIndexCode(edbCode)
  1470. if err != nil && err.Error() != utils.ErrNoRow() {
  1471. br.Msg = "获取失败"
  1472. br.ErrMsg = "获取Baiinfo指标详情失败,Err:" + err.Error()
  1473. return
  1474. }
  1475. if baiInfo != nil {
  1476. searchItem.Frequency = baiInfo.Frequency
  1477. searchItem.Unit = baiInfo.Unit
  1478. searchItem.EdbName = baiInfo.IndexName
  1479. }
  1480. } else if source == utils.DATA_SOURCE_NATIONAL_STATISTICS { // 国家统计局
  1481. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1482. if err != nil && err.Error() != utils.ErrNoRow() {
  1483. br.Msg = "获取失败"
  1484. br.ErrMsg = "获取国家统计局已存在信息失败,Err:" + err.Error()
  1485. return
  1486. }
  1487. if len(dataItems) > 0 {
  1488. searchItem.EdbCode = edbCode
  1489. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1490. if err != nil {
  1491. br.Msg = "获取失败"
  1492. br.ErrMsg = "获取国家统计局日期信息失败,Err:" + err.Error()
  1493. return
  1494. }
  1495. searchItem.DataList = dataItems
  1496. searchItem.StartDate = item.MinDate
  1497. searchItem.EndDate = item.MaxDate
  1498. } else {
  1499. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1500. if err != nil {
  1501. br.Msg = "获取失败"
  1502. br.ErrMsg = "获取失败,Err:" + err.Error()
  1503. return
  1504. }
  1505. if respItem.Ret != 200 {
  1506. br.Msg = "未搜索到该指标"
  1507. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1508. return
  1509. }
  1510. isAdd = true
  1511. }
  1512. //获取指标信息
  1513. nationalInfo, err := data_manage.GetBaseFromNationalStatisticsIndexByIndexCode(edbCode)
  1514. if err != nil && err.Error() != utils.ErrNoRow() {
  1515. br.Msg = "获取失败"
  1516. br.ErrMsg = "获取国家统计局详情失败,Err:" + err.Error()
  1517. return
  1518. }
  1519. if nationalInfo != nil {
  1520. searchItem.Frequency = nationalInfo.Frequency
  1521. searchItem.Unit = nationalInfo.Unit
  1522. searchItem.EdbName = fmt.Sprintf("%s%s", nationalInfo.Reg, nationalInfo.IndexName)
  1523. }
  1524. } else if source == utils.DATA_SOURCE_FUBAO { //数宝
  1525. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_FUBAO, subSource, utils.EDB_DATA_LIMIT)
  1526. if err != nil && err.Error() != utils.ErrNoRow() {
  1527. br.Msg = "获取失败"
  1528. br.ErrMsg = "获取Fubao已存在信息失败,Err:" + err.Error()
  1529. return
  1530. }
  1531. fmt.Println("fubao len:", len(dataItems))
  1532. if len(dataItems) > 0 {
  1533. fmt.Println("fubao data exist")
  1534. searchItem.EdbCode = edbCode
  1535. minDate, maxDate, err := data_manage.GetEdbDataFubaoMaxOrMinDate(edbCode)
  1536. if err != nil {
  1537. br.Msg = "获取失败"
  1538. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  1539. return
  1540. }
  1541. searchItem.DataList = dataItems
  1542. searchItem.StartDate = minDate
  1543. searchItem.EndDate = maxDate
  1544. } else {
  1545. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1546. if err != nil {
  1547. br.Msg = "获取失败," + respItem.Msg
  1548. br.ErrMsg = "获取失败,Err:" + err.Error()
  1549. return
  1550. }
  1551. if respItem.Ret != 200 {
  1552. br.Msg = "未搜索到该指标," + respItem.Msg
  1553. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1554. return
  1555. }
  1556. isAdd = true
  1557. }
  1558. } else if source == utils.DATA_SOURCE_GFEX { //广州期货交易所
  1559. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1560. if err != nil && err.Error() != utils.ErrNoRow() {
  1561. br.Msg = "获取失败"
  1562. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  1563. return
  1564. }
  1565. if len(dataItems) > 0 {
  1566. searchItem.EdbCode = edbCode
  1567. minDate, maxDate, err := data_manage.GetEdbDataGzMaxOrMinDate(edbCode)
  1568. if err != nil {
  1569. br.Msg = "获取失败"
  1570. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  1571. return
  1572. }
  1573. searchItem.DataList = dataItems
  1574. searchItem.StartDate = minDate
  1575. searchItem.EndDate = maxDate
  1576. } else {
  1577. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1578. if err != nil {
  1579. br.Msg = "获取失败"
  1580. br.ErrMsg = "获取失败,Err:" + err.Error()
  1581. return
  1582. }
  1583. if respItem.Ret != 200 {
  1584. br.Msg = "未搜索到该指标"
  1585. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1586. return
  1587. }
  1588. isAdd = true
  1589. }
  1590. //获取指标信息
  1591. indexInfo, err := data_manage.GetBaseInfoFromGzByIndexCode(edbCode)
  1592. if err != nil && err.Error() != utils.ErrNoRow() {
  1593. br.Msg = "获取失败"
  1594. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  1595. return
  1596. }
  1597. if indexInfo != nil {
  1598. searchItem.Frequency = indexInfo.Frequency
  1599. searchItem.Unit = indexInfo.Unit
  1600. searchItem.EdbName = indexInfo.IndexName
  1601. }
  1602. } else if source == utils.DATA_SOURCE_ICPI { //消费者指数
  1603. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1604. if err != nil && err.Error() != utils.ErrNoRow() {
  1605. br.Msg = "获取失败"
  1606. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  1607. return
  1608. }
  1609. if len(dataItems) > 0 {
  1610. searchItem.EdbCode = edbCode
  1611. minDate, maxDate, err := data_manage.GetEdbDataIcpiMaxOrMinDate(edbCode)
  1612. if err != nil {
  1613. br.Msg = "获取失败"
  1614. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  1615. return
  1616. }
  1617. searchItem.DataList = dataItems
  1618. searchItem.StartDate = minDate
  1619. searchItem.EndDate = maxDate
  1620. } else {
  1621. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1622. if err != nil {
  1623. br.Msg = "获取失败"
  1624. br.ErrMsg = "获取失败,Err:" + err.Error()
  1625. return
  1626. }
  1627. if respItem.Ret != 200 {
  1628. br.Msg = "未搜索到该指标"
  1629. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1630. return
  1631. }
  1632. isAdd = true
  1633. }
  1634. //获取指标信息
  1635. indexInfo, err := data_manage.GetBaseInfoFromIcpiByIndexCode(edbCode)
  1636. if err != nil && err.Error() != utils.ErrNoRow() {
  1637. br.Msg = "获取失败"
  1638. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  1639. return
  1640. }
  1641. if indexInfo != nil {
  1642. searchItem.Frequency = "日度"
  1643. searchItem.Unit = "%"
  1644. searchItem.EdbName = indexInfo.IndexName
  1645. }
  1646. } else if source == utils.DATA_SOURCE_BUSINESS { //自有数据
  1647. indexObj := data_manage.BaseFromBusinessIndex{}
  1648. indexInfo, err := indexObj.GetDetailByEdbCode(edbCode)
  1649. if err != nil && err.Error() != utils.ErrNoRow() {
  1650. br.Msg = "获取失败"
  1651. br.ErrMsg = "获取自有数据指标信息失败,Err:" + err.Error()
  1652. return
  1653. }
  1654. _, tmpDataList, err := data.GetPageBaseBusinessIndexData(edbCode, 1, utils.EDB_DATA_LIMIT)
  1655. if err != nil && err.Error() != utils.ErrNoRow() {
  1656. br.Msg = "获取失败"
  1657. br.ErrMsg = "获取自有数据已存在信息失败,Err:" + err.Error()
  1658. return
  1659. }
  1660. dataItems := make([]*data_manage.EdbInfoSearchData, 0)
  1661. for _, v := range tmpDataList {
  1662. dataItems = append(dataItems, &data_manage.EdbInfoSearchData{
  1663. DataTime: v.DataTime,
  1664. Value: v.Value,
  1665. })
  1666. }
  1667. searchItem.EdbCode = edbCode
  1668. searchItem.DataList = dataItems
  1669. searchItem.StartDate = indexInfo.StartDate.Format(utils.FormatDate)
  1670. searchItem.EndDate = indexInfo.EndDate.Format(utils.FormatDate)
  1671. searchItem.Frequency = indexInfo.Frequency
  1672. searchItem.Unit = indexInfo.Unit
  1673. searchItem.EdbName = indexInfo.IndexName
  1674. } else if source == utils.DATA_SOURCE_SCI99 { //卓创资讯
  1675. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1676. if err != nil && err.Error() != utils.ErrNoRow() {
  1677. br.Msg = "获取失败"
  1678. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  1679. return
  1680. }
  1681. if len(dataItems) > 0 {
  1682. searchItem.EdbCode = edbCode
  1683. minDate, maxDate, err := data_manage.GetEdbDataSci99MaxOrMinDate(edbCode)
  1684. if err != nil {
  1685. br.Msg = "获取失败"
  1686. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  1687. return
  1688. }
  1689. searchItem.DataList = dataItems
  1690. searchItem.StartDate = minDate
  1691. searchItem.EndDate = maxDate
  1692. } else {
  1693. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1694. if err != nil {
  1695. br.Msg = "获取失败"
  1696. br.ErrMsg = "获取失败,Err:" + err.Error()
  1697. return
  1698. }
  1699. if respItem.Ret != 200 {
  1700. br.Msg = "未搜索到该指标"
  1701. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1702. return
  1703. }
  1704. isAdd = true
  1705. }
  1706. //获取指标信息
  1707. indexInfo, err := data_manage.GetBaseInfoFromSci99ByIndexCode(edbCode)
  1708. if err != nil && err.Error() != utils.ErrNoRow() {
  1709. br.Msg = "获取失败"
  1710. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  1711. return
  1712. }
  1713. if indexInfo != nil {
  1714. searchItem.Frequency = "日度"
  1715. searchItem.Unit = "元/吨"
  1716. searchItem.EdbName = indexInfo.IndexName
  1717. }
  1718. } else if source == utils.DATA_SOURCE_SCI_HQ {
  1719. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1720. if err != nil && err.Error() != utils.ErrNoRow() {
  1721. br.Msg = "获取失败"
  1722. br.ErrMsg = "获取SCIHQ已存在信息失败,Err:" + err.Error()
  1723. return
  1724. }
  1725. fmt.Println("dataItems:", len(dataItems))
  1726. if len(dataItems) > 0 {
  1727. searchItem.EdbCode = edbCode
  1728. minDate, maxDate, err := data_manage.GetEdbDataSciHqMaxAndMinDate(edbCode)
  1729. if err != nil {
  1730. br.Msg = "获取失败"
  1731. br.ErrMsg = "获取SCIHQ日期信息失败,Err:" + err.Error()
  1732. return
  1733. }
  1734. searchItem.DataList = dataItems
  1735. searchItem.StartDate = minDate
  1736. searchItem.EndDate = maxDate
  1737. } else {
  1738. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1739. if err != nil {
  1740. br.Msg = "获取失败"
  1741. br.ErrMsg = "获取失败,Err:" + err.Error()
  1742. return
  1743. }
  1744. if respItem.Ret != 200 {
  1745. br.Msg = "未搜索到该指标"
  1746. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1747. return
  1748. }
  1749. isAdd = true
  1750. }
  1751. //获取指标信息
  1752. sciHqInfo, err := data_manage.GetSciHqIndexByIndexCode(edbCode)
  1753. if err != nil && err.Error() != utils.ErrNoRow() {
  1754. br.Msg = "获取失败"
  1755. br.ErrMsg = "获取SciHq指标详情失败,Err:" + err.Error()
  1756. return
  1757. }
  1758. if sciHqInfo != nil {
  1759. searchItem.Frequency = sciHqInfo.Frequency
  1760. searchItem.Unit = sciHqInfo.Unit
  1761. searchItem.EdbName = sciHqInfo.IndexName
  1762. }
  1763. } else if source == utils.DATA_SOURCE_OILCHEM { //隆众资讯
  1764. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1765. if err != nil && err.Error() != utils.ErrNoRow() {
  1766. br.Msg = "获取失败"
  1767. br.ErrMsg = "获取隆众资讯已存在信息失败,Err:" + err.Error()
  1768. return
  1769. }
  1770. if len(dataItems) > 0 {
  1771. searchItem.EdbCode = edbCode
  1772. minDate, maxDate, err := data_manage.GetEdbDataOilchemMaxOrMinDate(edbCode)
  1773. if err != nil {
  1774. br.Msg = "获取失败"
  1775. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  1776. return
  1777. }
  1778. searchItem.DataList = dataItems
  1779. searchItem.StartDate = minDate
  1780. searchItem.EndDate = maxDate
  1781. } else {
  1782. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1783. if err != nil {
  1784. br.Msg = "获取失败"
  1785. br.ErrMsg = "获取失败,Err:" + err.Error()
  1786. return
  1787. }
  1788. if respItem.Ret != 200 {
  1789. br.Msg = "未搜索到该指标"
  1790. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1791. return
  1792. }
  1793. isAdd = true
  1794. }
  1795. //获取指标信息
  1796. indexInfo, err := data_manage.GetBaseInfoFromOilchemByIndexCode(edbCode)
  1797. if err != nil && err.Error() != utils.ErrNoRow() {
  1798. br.Msg = "获取失败"
  1799. br.ErrMsg = "获取隆众资讯指标详情失败,Err:" + err.Error()
  1800. return
  1801. }
  1802. if indexInfo != nil {
  1803. searchItem.Frequency = indexInfo.Frequency
  1804. searchItem.Unit = indexInfo.Unit
  1805. searchItem.EdbName = indexInfo.IndexName
  1806. }
  1807. } else if source == utils.DATA_SOURCE_HISUGAR { //泛糖科技
  1808. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1809. if err != nil && err.Error() != utils.ErrNoRow() {
  1810. br.Msg = "获取失败"
  1811. br.ErrMsg = "获取泛糖科技已存在信息失败,Err:" + err.Error()
  1812. return
  1813. }
  1814. if len(dataItems) > 0 {
  1815. searchItem.EdbCode = edbCode
  1816. minDate, maxDate, err := data_manage.GetEdbDataHisugarMaxOrMinDate(edbCode)
  1817. if err != nil {
  1818. br.Msg = "获取失败"
  1819. br.ErrMsg = "获取泛糖科技日期信息失败,Err:" + err.Error()
  1820. return
  1821. }
  1822. searchItem.DataList = dataItems
  1823. searchItem.StartDate = minDate
  1824. searchItem.EndDate = maxDate
  1825. } else {
  1826. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1827. if err != nil {
  1828. br.Msg = "获取失败"
  1829. br.ErrMsg = "获取失败,Err:" + err.Error()
  1830. return
  1831. }
  1832. if respItem.Ret != 200 {
  1833. br.Msg = "未搜索到该指标"
  1834. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1835. return
  1836. }
  1837. isAdd = true
  1838. }
  1839. //获取指标信息
  1840. indexInfo, err := data_manage.GetBaseInfoFromHisugarByIndexCode(edbCode)
  1841. if err != nil && err.Error() != utils.ErrNoRow() {
  1842. br.Msg = "获取失败"
  1843. br.ErrMsg = "获取泛糖科技指标详情失败,Err:" + err.Error()
  1844. return
  1845. }
  1846. if indexInfo != nil {
  1847. searchItem.Frequency = indexInfo.Frequency
  1848. searchItem.Unit = indexInfo.Unit
  1849. searchItem.EdbName = indexInfo.IndexName
  1850. }
  1851. } else {
  1852. // 代码中没有的来源那么从edb_source中找是否有对应的
  1853. sourceItem := data_manage.EdbSourceIdMap[source]
  1854. if sourceItem == nil {
  1855. br.Msg = "无效指标来源"
  1856. return
  1857. }
  1858. // 获取指标数据
  1859. dataList, e := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1860. if e != nil {
  1861. br.Msg = "获取失败"
  1862. br.ErrMsg = "获取指标数据失败, Err: " + e.Error()
  1863. return
  1864. }
  1865. if len(dataList) > 0 {
  1866. searchItem.EdbCode = edbCode
  1867. searchItem.DataList = dataList
  1868. // 获取最大最小值
  1869. edbInfoMaxAndMinInfo, e := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1870. if e != nil && e.Error() != utils.ErrNoRow() {
  1871. br.Msg = "获取失败"
  1872. br.ErrMsg = "获取数据失败, GetEdbInfoMaxAndMinInfo Err:" + e.Error()
  1873. return
  1874. }
  1875. if edbInfoMaxAndMinInfo != nil {
  1876. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1877. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1878. }
  1879. } else {
  1880. // 新增指标数据
  1881. addRes, e := data.AddEdbData(source, edbCode, frequency)
  1882. if e != nil {
  1883. br.Msg = "获取失败"
  1884. br.ErrMsg = "获取失败,Err:" + e.Error()
  1885. return
  1886. }
  1887. if addRes == nil {
  1888. br.Msg = "获取失败"
  1889. br.ErrMsg = "新增指标数据失败, addRes nil"
  1890. return
  1891. }
  1892. if addRes.Ret != 200 {
  1893. br.Msg = "未搜索到该指标, " + addRes.Msg
  1894. //br.ErrMsg = addRes.ErrMsg + ";EdbCode:" + edbCode
  1895. br.Success = true
  1896. return
  1897. }
  1898. isAdd = true
  1899. }
  1900. // 查询基本信息
  1901. baseIndexInfo, tErr := data_manage.GetBaseIndexInfoByEdbCode(edbCode, source)
  1902. if tErr == nil {
  1903. searchItem.EdbName = baseIndexInfo.IndexName
  1904. searchItem.Frequency = baseIndexInfo.Frequency
  1905. searchItem.Unit = baseIndexInfo.Unit
  1906. }
  1907. // 指标来源于桥接服务: 桥接服务获取指标取频度信息等
  1908. if sourceItem.BridgeFlag != "" {
  1909. bridgeOb := data.InitBridgeOB(sourceItem.BridgeFlag)
  1910. if bridgeOb != nil {
  1911. var r data.GetIndexFromBridgeReq
  1912. r.IndexCode = edbCode
  1913. r.Source = sourceItem.EdbSourceId
  1914. r.SourceExtend = sourceItem.SourceExtend
  1915. r.IndexCodeRequired = sourceItem.EdbCodeRequired
  1916. bridgeIndex, e := bridgeOb.GetIndex(r)
  1917. if e != nil {
  1918. br.Msg = "获取失败"
  1919. br.ErrMsg = "桥接服务获取指标信息失败, Err: " + e.Error()
  1920. return
  1921. }
  1922. searchItem.EdbName = bridgeIndex.IndexName
  1923. searchItem.Frequency = bridgeIndex.Frequency
  1924. searchItem.Unit = bridgeIndex.Unit
  1925. }
  1926. }
  1927. }
  1928. if isAdd {
  1929. if subSource == utils.DATA_SUB_SOURCE_DATE {
  1930. if source == utils.DATA_SOURCE_WIND {
  1931. //wsdData := windWsdRespItem.Data
  1932. //var buf bytes.Buffer
  1933. //// 创建一个encoder并指定目标为buf
  1934. //enc := gob.NewEncoder(&buf)
  1935. //
  1936. //// 将data编码到buf中
  1937. //err = enc.Encode(wsdData)
  1938. //if err != nil {
  1939. // br.Msg = "获取失败"
  1940. // br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error()
  1941. // return
  1942. //}
  1943. //
  1944. //wsdDataMap := make(map[string]map[string]interface{})
  1945. //err = json.Unmarshal(buf.Bytes(), &wsdDataMap)
  1946. //if err != nil {
  1947. // br.Msg = "获取失败"
  1948. // br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error()
  1949. // return
  1950. //}
  1951. //
  1952. //stockList := make([]*data_manage.StockInfo, 0)
  1953. //
  1954. //dataList := make([]*data_manage.EdbInfoSearchData, 0)
  1955. //for wk, wv := range wsdDataMap {
  1956. // for vk, vv := range wv {
  1957. // wkInt, err := strconv.ParseInt(wk, 10, 64)
  1958. // if err != nil {
  1959. // br.Msg = "获取失败"
  1960. // br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error()
  1961. // return
  1962. // }
  1963. //
  1964. // vk = strings.ToLower(vk)
  1965. // wkInt = wkInt / 1000
  1966. // t := time.Unix(wkInt, 0)
  1967. // dateTime := t.Format(utils.FormatDate)
  1968. // //saveVal := utils.SubFloatToString(val, 20)
  1969. // if vv == nil {
  1970. // continue
  1971. // }
  1972. // var saveVal string
  1973. // switch vt := vv.(type) {
  1974. // case int:
  1975. // saveVal = strconv.Itoa(vt)
  1976. // case float64:
  1977. // saveVal = utils.SubFloatToFloatStr(vt, 20)
  1978. // case string:
  1979. // saveVal = vt
  1980. // }
  1981. //
  1982. // dataItem := new(data_manage.EdbInfoSearchData)
  1983. // dataItem.Value = saveVal
  1984. // dataItem.DataTime = dateTime
  1985. // dataList = append(dataList, dataItem)
  1986. // if len(dataList) >= 10 {
  1987. // break
  1988. // }
  1989. // }
  1990. //}
  1991. //searchItem.StockList = stockList
  1992. stockList := make([]*data_manage.StockInfo, 0)
  1993. edbCodeArr := strings.Split(edbCode, ",")
  1994. for _, v := range edbCodeArr {
  1995. indexCode := utils.WindDbWsd + stockCode + v
  1996. dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
  1997. if err != nil && err.Error() != utils.ErrNoRow() {
  1998. br.Msg = "获取失败"
  1999. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  2000. return
  2001. }
  2002. stockInfo := new(data_manage.StockInfo)
  2003. stockInfo.StockCode = stockCode
  2004. stockInfo.EdbCode = v
  2005. stockInfo.DataList = dataList
  2006. stockList = append(stockList, stockInfo)
  2007. }
  2008. searchItem.StockList = stockList
  2009. } else if source == utils.DATA_SOURCE_THS {
  2010. stockList := make([]*data_manage.StockInfo, 0)
  2011. edbCodeArr := strings.Split(edbCode, ",")
  2012. for _, v := range edbCodeArr {
  2013. indexCode := utils.ThsDs + stockCode + v
  2014. dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
  2015. if err != nil && err.Error() != utils.ErrNoRow() {
  2016. br.Msg = "获取失败"
  2017. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  2018. return
  2019. }
  2020. stockInfo := new(data_manage.StockInfo)
  2021. stockInfo.StockCode = stockCode
  2022. stockInfo.EdbCode = v
  2023. stockInfo.DataList = dataList
  2024. stockList = append(stockList, stockInfo)
  2025. }
  2026. searchItem.StockList = stockList
  2027. } else {
  2028. br.Msg = "来源错误"
  2029. br.ErrMsg = "来源错误"
  2030. return
  2031. }
  2032. } else {
  2033. dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  2034. if err != nil && err.Error() != utils.ErrNoRow() {
  2035. br.Msg = "获取失败"
  2036. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  2037. return
  2038. }
  2039. searchItem.DataList = dataList
  2040. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  2041. if err != nil && err.Error() != utils.ErrNoRow() {
  2042. br.Msg = "获取失败"
  2043. br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
  2044. return
  2045. }
  2046. searchItem.EdbCode = edbCode
  2047. searchItem.DataList = dataList
  2048. if edbInfoMaxAndMinInfo != nil {
  2049. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  2050. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  2051. }
  2052. //edb指标信息
  2053. edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode)
  2054. if edbInfoItem != nil {
  2055. searchItem.EdbName = edbInfoItem.EdbName
  2056. }
  2057. }
  2058. }
  2059. resp.Status = 2
  2060. resp.SearchItem = searchItem
  2061. }
  2062. //如果不在指标库中,且不是新增
  2063. if !isInEdb && !isAdd {
  2064. if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 {
  2065. br.Msg = "目标指标无有效值,请重新搜索"
  2066. br.Data = resp
  2067. return
  2068. }
  2069. }
  2070. br.Ret = 200
  2071. br.Success = true
  2072. br.Msg = "获取成功"
  2073. br.Data = resp
  2074. }
  2075. // EdbInfoList
  2076. // @Title 指标列表接口
  2077. // @Description 指标列表接口
  2078. // @Param PageSize query int true "每页数据条数"
  2079. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2080. // @Param EdbInfoId query int true "指标id"
  2081. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  2082. // @Success 200 {object} data_manage.EdbInfoListResp
  2083. // @router /edb_info/list [get]
  2084. func (this *EdbInfoController) EdbInfoList() {
  2085. br := new(models.BaseResponse).Init()
  2086. defer func() {
  2087. this.Data["json"] = br
  2088. this.ServeJSON()
  2089. }()
  2090. edbInfoId, _ := this.GetInt("EdbInfoId")
  2091. keyWord := this.GetString("KeyWord")
  2092. pageSize, _ := this.GetInt("PageSize")
  2093. currentIndex, _ := this.GetInt("CurrentIndex")
  2094. var total int
  2095. page := paging.GetPaging(currentIndex, pageSize, total)
  2096. var startSize int
  2097. if pageSize <= 0 {
  2098. pageSize = utils.PageSize20
  2099. }
  2100. if currentIndex <= 0 {
  2101. currentIndex = 1
  2102. }
  2103. startSize = paging.StartIndex(currentIndex, pageSize)
  2104. var condition string
  2105. var pars []interface{}
  2106. //if edbInfoId <= 0 && keyWord == "" {
  2107. // br.Msg = "参数错误"
  2108. // return
  2109. //}
  2110. // 指标类型,0:普通指标,1:预测指标
  2111. condition += " AND edb_info_type=? "
  2112. pars = append(pars, 0)
  2113. if edbInfoId > 0 {
  2114. condition += " AND edb_info_id=? "
  2115. pars = append(pars, edbInfoId)
  2116. // 获取当前账号的不可见指标配置
  2117. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2118. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId)
  2119. if err != nil && err.Error() != utils.ErrNoRow() {
  2120. br.Msg = "获取失败"
  2121. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  2122. return
  2123. }
  2124. if conf != nil {
  2125. br.Msg = "无权限,请联系管理员"
  2126. br.IsSendEmail = false
  2127. return
  2128. }
  2129. }
  2130. if keyWord != "" {
  2131. condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  2132. //pars = append(pars, keyWord)
  2133. //pars = append(pars, keyWord)
  2134. }
  2135. resp := new(data_manage.EdbInfoListResp)
  2136. if condition == "" {
  2137. item := new(data_manage.EdbInfoList)
  2138. resp.Paging = page
  2139. resp.Item = item
  2140. br.Ret = 200
  2141. br.Success = true
  2142. br.Msg = "获取成功"
  2143. return
  2144. }
  2145. //获取指标信息
  2146. edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2147. if err != nil && err.Error() != utils.ErrNoRow() {
  2148. br.Success = true
  2149. br.Msg = "获取指标信息失败"
  2150. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2151. return
  2152. }
  2153. if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  2154. item := new(data_manage.EdbInfoList)
  2155. resp.Paging = page
  2156. resp.Item = item
  2157. br.Ret = 200
  2158. br.Success = true
  2159. br.Msg = "获取成功"
  2160. return
  2161. }
  2162. //获取英文频度
  2163. edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
  2164. // 获取是否供应商停更
  2165. edbInfoItem.IsSupplierStop = data.GetIsSupplierStop(edbInfoItem.Source, edbInfoItem.EdbCode)
  2166. //查询目录
  2167. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId)
  2168. if err != nil {
  2169. br.Msg = err.Error()
  2170. br.ErrMsg = errMsg
  2171. return
  2172. }
  2173. // 权限校验
  2174. {
  2175. var currClassify *data_manage.EdbClassifyIdItems
  2176. for _, v := range classifyList {
  2177. if edbInfoItem.ClassifyId == v.ClassifyId {
  2178. currClassify = v
  2179. break
  2180. }
  2181. }
  2182. if currClassify != nil {
  2183. edbInfoItem.HaveOperaAuth, err = data_manage_permission.CheckEdbPermission(edbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfoItem.EdbInfoId, edbInfoItem.ClassifyId)
  2184. if err != nil {
  2185. br.Msg = err.Error()
  2186. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2187. return
  2188. }
  2189. }
  2190. }
  2191. // 按钮校验
  2192. button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType, edbInfoItem.HaveOperaAuth)
  2193. button.AddButton = false
  2194. edbInfoItem.Button = button
  2195. edbInfoItem.DataList = make([]*data_manage.EdbData, 0)
  2196. edbInfoItem.EndValue = utils.FormatFloatPoint(edbInfoItem.EndValue, 4)
  2197. edbInfoItem.LatestValue = utils.FormatFloatPoint(edbInfoItem.LatestValue, 4)
  2198. // 如果有数据权限,那么就去获取指标数据
  2199. if edbInfoItem.HaveOperaAuth {
  2200. dataCount, dataList, err := data.GetPageData(edbInfoItem.EdbInfoId, edbInfoItem.Source, edbInfoItem.SubSource, "", startSize, pageSize)
  2201. if err != nil && err.Error() != utils.ErrNoRow() {
  2202. br.Msg = "获取指标信息失败"
  2203. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  2204. return
  2205. }
  2206. for _, v := range dataList {
  2207. v.Value = utils.FormatFloatPoint(v.Value, 4)
  2208. }
  2209. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  2210. edbInfoItem.DataList = dataList
  2211. }
  2212. // 获取指标插入配置
  2213. {
  2214. edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId)
  2215. if err != nil && err.Error() != utils.ErrNoRow() {
  2216. br.Msg = "获取指标信息失败"
  2217. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2218. return
  2219. }
  2220. if edbDataInsertConfig != nil {
  2221. edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate)
  2222. edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate)
  2223. edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value
  2224. }
  2225. }
  2226. //是否展示英文标识
  2227. edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn)
  2228. resp.Paging = page
  2229. resp.Item = edbInfoItem
  2230. resp.ClassifyList = classifyList
  2231. br.Ret = 200
  2232. br.Success = true
  2233. br.Msg = "获取成功"
  2234. br.Data = resp
  2235. }
  2236. // EdbInfoAdd
  2237. // @Title 新增指标接口
  2238. // @Description 新增指标接口
  2239. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  2240. // @Success Ret=200 保存成功
  2241. // @router /edb_info/add [post]
  2242. func (this *EdbInfoController) EdbInfoAdd() {
  2243. br := new(models.BaseResponse).Init()
  2244. defer func() {
  2245. this.Data["json"] = br
  2246. this.ServeJSON()
  2247. }()
  2248. sysUser := this.SysUser
  2249. if sysUser == nil {
  2250. br.Msg = "请登录"
  2251. br.ErrMsg = "请登录,SysUser Is Empty"
  2252. br.Ret = 408
  2253. return
  2254. }
  2255. deleteCache := true
  2256. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  2257. defer func() {
  2258. if deleteCache {
  2259. utils.Rc.Delete(cacheKey)
  2260. }
  2261. }()
  2262. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  2263. deleteCache = false
  2264. br.Msg = "系统处理中,请稍后重试!"
  2265. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  2266. return
  2267. }
  2268. var req data_manage.AddEdbInfoReq
  2269. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2270. if err != nil {
  2271. br.Msg = "参数解析异常!"
  2272. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2273. return
  2274. }
  2275. source := req.Source
  2276. if source <= 0 {
  2277. br.Msg = "无效的数据来源"
  2278. return
  2279. }
  2280. req.EdbName = strings.Trim(req.EdbName, " ")
  2281. req.EdbCode = strings.Trim(req.EdbCode, " ")
  2282. if req.EdbCode == "" {
  2283. br.Msg = "指标ID不能为空"
  2284. return
  2285. }
  2286. if req.EdbName == "" {
  2287. br.Msg = "指标名称不能为空"
  2288. return
  2289. }
  2290. if req.Frequency == "" {
  2291. br.Msg = "频率不能为空"
  2292. return
  2293. }
  2294. if req.Unit == "" {
  2295. br.Msg = "单位不能为空"
  2296. return
  2297. }
  2298. if req.ClassifyId <= 0 {
  2299. br.Msg = "请选择分类"
  2300. return
  2301. }
  2302. //if req.StartDate == "" || req.EndDate == "" {
  2303. // br.Msg = "日期不能为空"
  2304. // return
  2305. //}
  2306. // 兼容钢联与上海钢联数据
  2307. if utils.InArrayByInt([]int{utils.DATA_SOURCE_GL, utils.DATA_SOURCE_MYSTEEL_CHEMICAL}, source) {
  2308. // 如果是钢联的话,那么就先判断是不是存在钢联化工
  2309. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
  2310. if err != nil {
  2311. if err.Error() != utils.ErrNoRow() {
  2312. br.Msg = "获取失败"
  2313. br.ErrMsg = "获取失败,Err:" + err.Error()
  2314. return
  2315. }
  2316. }
  2317. if tmpInfo != nil {
  2318. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  2319. req.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  2320. } else {
  2321. source = utils.DATA_SOURCE_GL
  2322. req.Source = utils.DATA_SOURCE_GL
  2323. }
  2324. }
  2325. // 指标入库
  2326. edbInfo, err, errMsg, isSendEmail := data.EdbInfoAdd(source, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, req.StartDate, req.EndDate, sysUser.AdminId, sysUser.RealName, this.Lang)
  2327. if err != nil {
  2328. br.Msg = "保存失败"
  2329. if errMsg != `` {
  2330. br.Msg = errMsg
  2331. }
  2332. br.ErrMsg = err.Error()
  2333. br.IsSendEmail = isSendEmail
  2334. return
  2335. }
  2336. // 试用平台更新用户累计新增指标数
  2337. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  2338. if e != nil {
  2339. br.Msg = "操作失败"
  2340. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  2341. return
  2342. }
  2343. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  2344. go func() {
  2345. var r etaTrialService.EtaTrialUserReq
  2346. r.Mobile = adminItem.Mobile
  2347. _, _ = etaTrialService.UpdateUserIndexNum(r)
  2348. }()
  2349. }
  2350. //新增操作日志
  2351. {
  2352. // 添加钢联指标更新日志
  2353. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2354. go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
  2355. }
  2356. edbLog := new(data_manage.EdbInfoLog)
  2357. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2358. edbLog.SourceName = edbInfo.SourceName
  2359. edbLog.Source = edbInfo.Source
  2360. edbLog.EdbCode = edbInfo.EdbCode
  2361. edbLog.EdbName = edbInfo.EdbName
  2362. edbLog.ClassifyId = edbInfo.ClassifyId
  2363. edbLog.SysUserId = sysUser.AdminId
  2364. edbLog.SysUserRealName = sysUser.RealName
  2365. edbLog.CreateTime = time.Now()
  2366. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2367. edbLog.Status = "新增指标"
  2368. edbLog.Method = this.Ctx.Input.URI()
  2369. go data_manage.AddEdbInfoLog(edbLog)
  2370. }
  2371. // 更新es
  2372. go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  2373. resp := new(data_manage.AddEdbInfoResp)
  2374. resp.EdbInfoId = edbInfo.EdbInfoId
  2375. resp.UniqueCode = edbInfo.UniqueCode
  2376. br.Ret = 200
  2377. br.Success = true
  2378. br.Msg = "保存成功"
  2379. br.Data = resp
  2380. br.IsAddLog = true
  2381. }
  2382. // EdbInfoEdit
  2383. // @Title 编辑指标接口
  2384. // @Description 编辑指标接口
  2385. // @Success 200 {object} data_manage.EditEdbInfoReq
  2386. // @router /edb_info/edit [post]
  2387. func (this *EdbInfoController) EdbInfoEdit() {
  2388. br := new(models.BaseResponse).Init()
  2389. defer func() {
  2390. this.Data["json"] = br
  2391. this.ServeJSON()
  2392. }()
  2393. sysUser := this.SysUser
  2394. if sysUser == nil {
  2395. br.Msg = "请登录"
  2396. br.ErrMsg = "请登录,SysUser Is Empty"
  2397. br.Ret = 408
  2398. return
  2399. }
  2400. var req data_manage.EditEdbInfoReq
  2401. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2402. if err != nil {
  2403. br.Msg = "参数解析异常!"
  2404. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2405. return
  2406. }
  2407. req.EdbName = strings.Trim(req.EdbName, " ")
  2408. if req.EdbInfoId <= 0 {
  2409. br.Msg = "参数错误"
  2410. br.ErrMsg = "指标id小于等于0"
  2411. return
  2412. }
  2413. if req.EdbName == "" {
  2414. br.Msg = "指标名称不能为空"
  2415. return
  2416. }
  2417. if req.Frequency == "" {
  2418. br.Msg = "频率不能为空"
  2419. return
  2420. }
  2421. if req.Unit == "" {
  2422. br.Msg = "单位不能为空"
  2423. return
  2424. }
  2425. if req.ClassifyId <= 0 {
  2426. br.Msg = "请选择分类"
  2427. return
  2428. }
  2429. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2430. if err != nil {
  2431. br.Msg = "修改失败"
  2432. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2433. return
  2434. }
  2435. // 记录旧的指标基本信息
  2436. oldEdbName := edbInfo.EdbName
  2437. oldFrequency := edbInfo.Frequency
  2438. oldUnit := edbInfo.Unit
  2439. var haveOperaAuth bool
  2440. // 权限校验
  2441. {
  2442. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
  2443. if err != nil {
  2444. br.Msg = err.Error()
  2445. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2446. return
  2447. }
  2448. }
  2449. // 编辑权限校验
  2450. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  2451. if !button.OpButton {
  2452. br.Msg = "无权限操作"
  2453. br.IsSendEmail = false
  2454. return
  2455. }
  2456. //判断指标名称是否存在
  2457. var condition string
  2458. var pars []interface{}
  2459. condition += " AND edb_info_id<>? "
  2460. pars = append(pars, req.EdbInfoId)
  2461. //condition += " AND source=? "
  2462. //pars = append(pars, edbInfo.Source)
  2463. updateCols := make([]string, 0)
  2464. switch this.Lang {
  2465. case utils.EnLangVersion:
  2466. condition += " AND edb_name_en = ? "
  2467. edbInfo.EdbNameEn = req.EdbName
  2468. edbInfo.Frequency = req.Frequency
  2469. edbInfo.UnitEn = req.Unit
  2470. edbInfo.ClassifyId = req.ClassifyId
  2471. updateCols = append(updateCols, "EdbNameEn", "Frequency", "UnitEn", "ClassifyId")
  2472. default:
  2473. condition += " AND edb_name=? "
  2474. edbInfo.EdbName = req.EdbName
  2475. edbInfo.EdbNameSource = req.EdbName
  2476. edbInfo.Frequency = req.Frequency
  2477. edbInfo.Unit = req.Unit
  2478. edbInfo.ClassifyId = req.ClassifyId
  2479. updateCols = append(updateCols, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId")
  2480. }
  2481. pars = append(pars, req.EdbName)
  2482. count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
  2483. if err != nil {
  2484. br.Msg = "判断指标名称是否存在失败"
  2485. br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error()
  2486. return
  2487. }
  2488. if count > 0 {
  2489. br.Msg = "指标名称已存在,请重新填写"
  2490. br.ErrMsg = "指标名称已存在,请重新填写"
  2491. br.IsSendEmail = false
  2492. return
  2493. }
  2494. if len(updateCols) > 0 {
  2495. err = edbInfo.Update(updateCols)
  2496. if err != nil {
  2497. br.Msg = "保存失败"
  2498. br.ErrMsg = "修改失败,Err:" + err.Error()
  2499. return
  2500. }
  2501. }
  2502. //处理同名指标
  2503. //{
  2504. // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName)
  2505. // if err != nil {
  2506. // br.Msg = "保存失败"
  2507. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2508. // return
  2509. // }
  2510. // if len(edbNameList) >= 2 {
  2511. // for _, v := range edbNameList {
  2512. // edbName := v.EdbName + "(" + v.SourceName + ")"
  2513. // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
  2514. // if err != nil {
  2515. // br.Msg = "保存失败"
  2516. // br.ErrMsg = "修改指标名称失败,Err:" + err.Error()
  2517. // return
  2518. // }
  2519. // }
  2520. // }
  2521. //}
  2522. // 新增保存记录日志
  2523. oldEdbInfo := new(data_manage.EdbInfo)
  2524. oldEdbInfo.EdbInfoId = edbInfo.EdbInfoId
  2525. oldEdbInfo.EdbName = oldEdbName
  2526. oldEdbInfo.Frequency = oldFrequency
  2527. oldEdbInfo.Unit = oldUnit
  2528. newEdbInfoRecord := new(data_manage.EdbInfoEditRecord)
  2529. newEdbInfoRecord.EdbName = req.EdbName
  2530. newEdbInfoRecord.Frequency = req.Frequency
  2531. newEdbInfoRecord.Unit = req.Unit
  2532. newEdbInfoRecord.OperateUserId = sysUser.AdminId
  2533. newEdbInfoRecord.OperateUserRealName = sysUser.RealName
  2534. go data.AddEditEdbInfoRcord(oldEdbInfo, newEdbInfoRecord)
  2535. //新增操作日志
  2536. {
  2537. edbLog := new(data_manage.EdbInfoLog)
  2538. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2539. edbLog.SourceName = edbInfo.SourceName
  2540. edbLog.Source = edbInfo.Source
  2541. edbLog.EdbCode = edbInfo.EdbCode
  2542. edbLog.EdbName = edbInfo.EdbName
  2543. edbLog.ClassifyId = edbInfo.ClassifyId
  2544. edbLog.SysUserId = sysUser.AdminId
  2545. edbLog.SysUserRealName = sysUser.RealName
  2546. edbLog.CreateTime = time.Now()
  2547. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2548. edbLog.Status = "编辑指标"
  2549. edbLog.Method = this.Ctx.Input.URI()
  2550. go data_manage.AddEdbInfoLog(edbLog)
  2551. }
  2552. //添加es
  2553. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2554. switch this.Lang {
  2555. case utils.EnLangVersion:
  2556. // 修改关联的预测指标基础信息
  2557. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
  2558. default:
  2559. // 修改关联的预测指标基础信息
  2560. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, req.Frequency, req.Unit)
  2561. }
  2562. // 添加钢联指标更新日志
  2563. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2564. if edbInfo.EdbName != req.EdbName || edbInfo.Frequency != req.Frequency || edbInfo.Unit != req.Unit {
  2565. go data_stat.AddEdbInfoUpdateLog(req.EdbInfoId, 1, "", sysUser, 1)
  2566. }
  2567. }
  2568. br.Ret = 200
  2569. br.Success = true
  2570. br.Msg = "保存成功"
  2571. br.IsAddLog = true
  2572. }
  2573. // EdbEnInfoEdit
  2574. // @Title 编辑指标英文信息接口
  2575. // @Description 编辑指标英文信息接口
  2576. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  2577. // @router /edb_info/en/edit [post]
  2578. func (this *EdbInfoController) EdbEnInfoEdit() {
  2579. br := new(models.BaseResponse).Init()
  2580. defer func() {
  2581. this.Data["json"] = br
  2582. this.ServeJSON()
  2583. }()
  2584. sysUser := this.SysUser
  2585. if sysUser == nil {
  2586. br.Msg = "请登录"
  2587. br.ErrMsg = "请登录,SysUser Is Empty"
  2588. br.Ret = 408
  2589. return
  2590. }
  2591. var req data_manage.EditEdbEnInfoReq
  2592. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2593. if err != nil {
  2594. br.Msg = "参数解析异常!"
  2595. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2596. return
  2597. }
  2598. req.EdbNameEn = strings.Trim(req.EdbNameEn, " ")
  2599. req.UnitEn = strings.Trim(req.UnitEn, " ")
  2600. if req.EdbInfoId <= 0 {
  2601. br.Msg = "参数错误"
  2602. br.ErrMsg = "指标id小于等于0"
  2603. return
  2604. }
  2605. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2606. if err != nil {
  2607. br.Msg = "获取指标信息失败"
  2608. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2609. return
  2610. }
  2611. if req.EdbNameEn != "" {
  2612. //判断指标名称是否存在
  2613. var condition string
  2614. var pars []interface{}
  2615. condition += " AND edb_info_id<>? "
  2616. pars = append(pars, req.EdbInfoId)
  2617. /*condition += " AND source=? "
  2618. pars = append(pars, edbInfo.Source)*/
  2619. condition += " AND edb_name_en=? "
  2620. pars = append(pars, req.EdbNameEn)
  2621. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2622. if err != nil {
  2623. if err.Error() != utils.ErrNoRow() {
  2624. br.Msg = "判断英文指标名称是否存在失败"
  2625. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2626. return
  2627. }
  2628. }
  2629. if err == nil && edbExist.EdbInfoId > 0 {
  2630. br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在"
  2631. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2632. br.IsSendEmail = false
  2633. return
  2634. }
  2635. }
  2636. err = data_manage.ModifyEdbEnInfo(&req)
  2637. if err != nil {
  2638. br.Msg = "保存失败"
  2639. br.ErrMsg = "修改失败,Err:" + err.Error()
  2640. return
  2641. }
  2642. //新增操作日志
  2643. {
  2644. edbLog := new(data_manage.EdbInfoLog)
  2645. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2646. edbLog.SourceName = edbInfo.SourceName
  2647. edbLog.Source = edbInfo.Source
  2648. edbLog.EdbCode = edbInfo.EdbCode
  2649. edbLog.EdbName = edbInfo.EdbName
  2650. edbLog.ClassifyId = edbInfo.ClassifyId
  2651. edbLog.SysUserId = sysUser.AdminId
  2652. edbLog.SysUserRealName = sysUser.RealName
  2653. edbLog.CreateTime = time.Now()
  2654. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2655. edbLog.Status = "编辑指标英文信息"
  2656. edbLog.Method = this.Ctx.Input.URI()
  2657. go data_manage.AddEdbInfoLog(edbLog)
  2658. }
  2659. //添加es
  2660. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2661. // 修改关联的预测指标基础信息
  2662. if edbInfo.EdbInfoType == 0 {
  2663. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.UnitEn)
  2664. }
  2665. br.Ret = 200
  2666. br.Success = true
  2667. br.Msg = "保存成功"
  2668. br.IsAddLog = true
  2669. }
  2670. // EdbInfoBaseEdit
  2671. // @Title 编辑指标基础信息接口
  2672. // @Description 编辑指标基础信息接口
  2673. // @Success 200 {object} data_manage.EditEdbBaseInfoReq
  2674. // @router /edb_info/base/edit [post]
  2675. func (this *EdbInfoController) EdbInfoBaseEdit() {
  2676. br := new(models.BaseResponse).Init()
  2677. defer func() {
  2678. this.Data["json"] = br
  2679. this.ServeJSON()
  2680. }()
  2681. sysUser := this.SysUser
  2682. if sysUser == nil {
  2683. br.Msg = "请登录"
  2684. br.ErrMsg = "请登录,SysUser Is Empty"
  2685. br.Ret = 408
  2686. return
  2687. }
  2688. var req data_manage.EditEdbBaseInfoReq
  2689. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2690. if err != nil {
  2691. br.Msg = "参数解析异常!"
  2692. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2693. return
  2694. }
  2695. req.EdbName = strings.Trim(req.EdbName, " ")
  2696. req.Unit = strings.Trim(req.Unit, " ")
  2697. if req.EdbInfoId <= 0 {
  2698. br.Msg = "参数错误"
  2699. br.ErrMsg = "指标id小于等于0"
  2700. return
  2701. }
  2702. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2703. if err != nil {
  2704. br.Msg = "获取指标信息失败"
  2705. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2706. return
  2707. }
  2708. updateCols := make([]string, 0)
  2709. if req.EdbName != "" {
  2710. //判断指标名称是否存在
  2711. var condition string
  2712. var pars []interface{}
  2713. condition += " AND edb_info_id<>? "
  2714. pars = append(pars, req.EdbInfoId)
  2715. /*condition += " AND source=? "
  2716. pars = append(pars, edbInfo.Source)*/
  2717. switch this.Lang {
  2718. case utils.EnLangVersion:
  2719. condition += " AND edb_name_en = ? "
  2720. edbInfo.EdbNameEn = req.EdbName
  2721. edbInfo.UnitEn = req.Unit
  2722. edbInfo.ModifyTime = time.Now()
  2723. updateCols = append(updateCols, "EdbNameEn", "UnitEn", "ModifyTime")
  2724. default:
  2725. condition += " AND edb_name = ? "
  2726. edbInfo.EdbName = req.EdbName
  2727. edbInfo.EdbNameSource = req.EdbName
  2728. edbInfo.Unit = req.Unit
  2729. edbInfo.ModifyTime = time.Now()
  2730. updateCols = append(updateCols, "EdbName", "EdbNameSource", "Unit", "ModifyTime")
  2731. }
  2732. pars = append(pars, req.EdbName)
  2733. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2734. if err != nil {
  2735. if err.Error() != utils.ErrNoRow() {
  2736. br.Msg = "判断英文指标名称是否存在失败"
  2737. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2738. return
  2739. }
  2740. }
  2741. if err == nil && edbExist.EdbInfoId > 0 {
  2742. br.Msg = edbExist.EdbName + ":" + req.EdbName + "指标名称已存在"
  2743. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2744. br.IsSendEmail = false
  2745. return
  2746. }
  2747. }
  2748. if len(updateCols) > 0 {
  2749. err = edbInfo.Update(updateCols)
  2750. if err != nil {
  2751. br.Msg = "保存失败"
  2752. br.ErrMsg = "修改失败,Err:" + err.Error()
  2753. return
  2754. }
  2755. }
  2756. //新增操作日志
  2757. {
  2758. edbLog := new(data_manage.EdbInfoLog)
  2759. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2760. edbLog.SourceName = edbInfo.SourceName
  2761. edbLog.Source = edbInfo.Source
  2762. edbLog.EdbCode = edbInfo.EdbCode
  2763. edbLog.EdbName = edbInfo.EdbName
  2764. edbLog.ClassifyId = edbInfo.ClassifyId
  2765. edbLog.SysUserId = sysUser.AdminId
  2766. edbLog.SysUserRealName = sysUser.RealName
  2767. edbLog.CreateTime = time.Now()
  2768. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2769. edbLog.Status = "编辑指标英文信息"
  2770. edbLog.Method = this.Ctx.Input.URI()
  2771. go data_manage.AddEdbInfoLog(edbLog)
  2772. }
  2773. //添加es
  2774. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2775. // 修改关联的预测指标基础信息
  2776. if edbInfo.EdbInfoType == 0 {
  2777. switch this.Lang {
  2778. case utils.EnLangVersion:
  2779. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
  2780. default:
  2781. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, edbInfo.Frequency, req.Unit)
  2782. }
  2783. }
  2784. br.Ret = 200
  2785. br.Success = true
  2786. br.Msg = "保存成功"
  2787. br.IsAddLog = true
  2788. }
  2789. // EdbInfoNewest
  2790. // @Title 获取最新指标接口
  2791. // @Description 获取最新指标接口
  2792. // @Success 200 {object} data_manage.EdbInfoList
  2793. // @router /edb_info/newest [get]
  2794. func (this *EdbInfoController) EdbInfoNewest() {
  2795. br := new(models.BaseResponse).Init()
  2796. defer func() {
  2797. this.Data["json"] = br
  2798. this.ServeJSON()
  2799. }()
  2800. item, err := data_manage.GetEdbInfoByNewest()
  2801. if err != nil && err.Error() != utils.ErrNoRow() {
  2802. br.Msg = "获取最新指标失败"
  2803. br.ErrMsg = "获取最新指标失败,Err:" + err.Error()
  2804. return
  2805. }
  2806. br.Ret = 200
  2807. br.Success = true
  2808. br.Msg = "获取成功"
  2809. br.Data = item
  2810. }
  2811. // EdbInfoRefresh
  2812. // @Title 指标刷新接口
  2813. // @Description 指标刷新接口
  2814. // @Param EdbInfoId query int true "指标id"
  2815. // @Success Ret=200 刷新成功
  2816. // @router /edb_info/refresh [get]
  2817. func (this *EdbInfoController) EdbInfoRefresh() {
  2818. br := new(models.BaseResponse).Init()
  2819. defer func() {
  2820. this.Data["json"] = br
  2821. this.ServeJSON()
  2822. }()
  2823. sysUser := this.SysUser
  2824. if sysUser == nil {
  2825. br.Msg = "请登录"
  2826. br.ErrMsg = "请登录,SysUser Is Empty"
  2827. br.Ret = 408
  2828. return
  2829. }
  2830. edbInfoId, _ := this.GetInt("EdbInfoId")
  2831. if edbInfoId <= 0 {
  2832. br.Msg = "参数错误"
  2833. br.ErrMsg = "参数错误"
  2834. return
  2835. }
  2836. _, err := data_manage.GetEdbInfoById(edbInfoId)
  2837. if err != nil {
  2838. if err.Error() == utils.ErrNoRow() {
  2839. br.Msg = "数据已被删除,请刷新页面"
  2840. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2841. return
  2842. }
  2843. br.Msg = "刷新失败"
  2844. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2845. return
  2846. }
  2847. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false, false)
  2848. if err != nil {
  2849. br.Msg = "刷新失败"
  2850. br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error()
  2851. return
  2852. }
  2853. br.Ret = 200
  2854. br.Msg = "刷新成功"
  2855. if isAsync {
  2856. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  2857. }
  2858. br.Success = true
  2859. br.IsAddLog = true
  2860. }
  2861. // EdbInfoMove
  2862. // @Title 移动指标接口
  2863. // @Description 移动指标接口
  2864. // @Success 200 {object} data_manage.MoveEdbInfoReq
  2865. // @router /edb_info/move [post]
  2866. func (this *EdbInfoController) EdbInfoMove() {
  2867. br := new(models.BaseResponse).Init()
  2868. defer func() {
  2869. this.Data["json"] = br
  2870. this.ServeJSON()
  2871. }()
  2872. sysUser := this.SysUser
  2873. if sysUser == nil {
  2874. br.Msg = "请登录"
  2875. br.ErrMsg = "请登录,SysUser Is Empty"
  2876. br.Ret = 408
  2877. return
  2878. }
  2879. var req data_manage.MoveEdbInfoReq
  2880. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2881. if err != nil {
  2882. br.Msg = "参数解析异常!"
  2883. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2884. return
  2885. }
  2886. if req.EdbInfoId <= 0 {
  2887. br.Msg = "参数错误"
  2888. br.ErrMsg = "指标id小于等于0"
  2889. return
  2890. }
  2891. if req.ClassifyId <= 0 {
  2892. br.Msg = "请选择分类"
  2893. return
  2894. }
  2895. //判断分类是否存在
  2896. count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId)
  2897. if count <= 0 {
  2898. br.Msg = "分类已被删除,不可移动,请刷新页面"
  2899. return
  2900. }
  2901. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2902. if err != nil {
  2903. br.Msg = "移动失败"
  2904. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2905. return
  2906. }
  2907. var haveOperaAuth bool
  2908. // 权限校验
  2909. {
  2910. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.IsJoinPermission, edbInfo.EdbInfoId, edbInfo.ClassifyId, this.SysUser.AdminId)
  2911. if err != nil {
  2912. br.Msg = err.Error()
  2913. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2914. return
  2915. }
  2916. }
  2917. // 移动权限校验
  2918. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  2919. if !button.MoveButton {
  2920. br.Msg = "无权限操作"
  2921. br.IsSendEmail = false
  2922. return
  2923. }
  2924. //如果改变了分类,那么移动该指标数据
  2925. if edbInfo.ClassifyId != req.ClassifyId {
  2926. err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId)
  2927. if err != nil {
  2928. br.Msg = "移动失败"
  2929. br.ErrMsg = "移动指标失败,Err:" + err.Error()
  2930. return
  2931. }
  2932. }
  2933. updateCol := make([]string, 0)
  2934. //如果有传入 上一个兄弟节点分类id
  2935. if req.PrevEdbInfoId > 0 {
  2936. prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId)
  2937. if err != nil {
  2938. br.Msg = "移动失败"
  2939. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  2940. return
  2941. }
  2942. //如果是移动在两个兄弟节点之间
  2943. if req.NextEdbInfoId > 0 {
  2944. //下一个兄弟节点
  2945. nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId)
  2946. if err != nil {
  2947. br.Msg = "移动失败"
  2948. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  2949. return
  2950. }
  2951. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  2952. if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort {
  2953. //变更兄弟节点的排序
  2954. updateSortStr := `sort + 2`
  2955. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2956. } else {
  2957. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  2958. if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 {
  2959. //变更兄弟节点的排序
  2960. updateSortStr := `sort + 1`
  2961. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2962. }
  2963. }
  2964. }
  2965. edbInfo.Sort = prevEdbInfo.Sort + 1
  2966. edbInfo.ModifyTime = time.Now()
  2967. updateCol = append(updateCol, "Sort", "ModifyTime")
  2968. } else {
  2969. firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId)
  2970. if err != nil && err.Error() != utils.ErrNoRow() {
  2971. br.Msg = "移动失败"
  2972. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2973. return
  2974. }
  2975. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2976. if firstClassify != nil && firstClassify.Sort == 0 {
  2977. updateSortStr := ` sort + 1 `
  2978. _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr)
  2979. }
  2980. edbInfo.Sort = 0 //那就是排在第一位
  2981. edbInfo.ModifyTime = time.Now()
  2982. updateCol = append(updateCol, "Sort", "ModifyTime")
  2983. }
  2984. //更新
  2985. if len(updateCol) > 0 {
  2986. err = edbInfo.Update(updateCol)
  2987. if err != nil {
  2988. br.Msg = "移动失败"
  2989. br.ErrMsg = "修改失败,Err:" + err.Error()
  2990. return
  2991. }
  2992. //添加es
  2993. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2994. }
  2995. if err != nil {
  2996. br.Msg = "移动失败"
  2997. br.ErrMsg = "修改失败,Err:" + err.Error()
  2998. return
  2999. }
  3000. //新增操作日志
  3001. {
  3002. edbLog := new(data_manage.EdbInfoLog)
  3003. edbLog.EdbInfoId = edbInfo.EdbInfoId
  3004. edbLog.SourceName = edbInfo.SourceName
  3005. edbLog.Source = edbInfo.Source
  3006. edbLog.EdbCode = edbInfo.EdbCode
  3007. edbLog.EdbName = edbInfo.EdbName
  3008. edbLog.ClassifyId = edbInfo.ClassifyId
  3009. edbLog.SysUserId = sysUser.AdminId
  3010. edbLog.SysUserRealName = sysUser.RealName
  3011. edbLog.CreateTime = time.Now()
  3012. edbLog.Content = string(this.Ctx.Input.RequestBody)
  3013. edbLog.Status = "移动指标"
  3014. edbLog.Method = this.Ctx.Input.URI()
  3015. go data_manage.AddEdbInfoLog(edbLog)
  3016. }
  3017. br.Ret = 200
  3018. br.Success = true
  3019. br.Msg = "移动成功"
  3020. }
  3021. // EdbInfoDetail
  3022. // @Title 获取指标详情
  3023. // @Description 获取指标详情接口
  3024. // @Param EdbInfoId query int true "指标id"
  3025. // @Success 200 {object} data_manage.EdbInfo
  3026. // @router /edb_info/detail [get]
  3027. func (this *EdbInfoController) EdbInfoDetail() {
  3028. br := new(models.BaseResponse).Init()
  3029. defer func() {
  3030. this.Data["json"] = br
  3031. this.ServeJSON()
  3032. }()
  3033. sysUser := this.SysUser
  3034. if sysUser == nil {
  3035. br.Msg = "请登录"
  3036. br.ErrMsg = "请登录,SysUser Is Empty"
  3037. br.Ret = 408
  3038. return
  3039. }
  3040. edbInfoId, _ := this.GetInt("EdbInfoId")
  3041. if edbInfoId <= 0 {
  3042. br.Msg = "参数错误"
  3043. br.ErrMsg = "参数错误"
  3044. return
  3045. }
  3046. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3047. if err != nil {
  3048. br.Msg = "获取失败"
  3049. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3050. return
  3051. }
  3052. var resp data_manage.EdbInfoFullClassify
  3053. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  3054. if err != nil {
  3055. br.Msg = err.Error()
  3056. br.ErrMsg = errMsg
  3057. return
  3058. }
  3059. // 权限校验
  3060. {
  3061. classifyMap := make(map[int]*data_manage.EdbClassifyIdItems)
  3062. for _, v := range classifyList {
  3063. classifyMap[v.ClassifyId] = v
  3064. }
  3065. if currClassify, ok := classifyMap[edbInfo.ClassifyId]; ok {
  3066. haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
  3067. if err != nil {
  3068. br.Msg = err.Error()
  3069. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  3070. return
  3071. }
  3072. resp.HaveOperaAuth = haveOperaAuth
  3073. }
  3074. }
  3075. resp.EdbInfo = edbInfo
  3076. resp.ClassifyList = classifyList
  3077. br.Ret = 200
  3078. br.Success = true
  3079. br.Msg = "获取成功"
  3080. br.Data = resp
  3081. }
  3082. // EdbInfoFilter
  3083. // @Title 指标筛选接口
  3084. // @Description 指标筛选接口
  3085. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  3086. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标"
  3087. // @Param PageSize query int true "每页数据条数"
  3088. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3089. // @Success 200 {object} data_manage.EdbInfoList
  3090. // @router /edb_info/filter [get]
  3091. func (this *EdbInfoController) EdbInfoFilter() {
  3092. br := new(models.BaseResponse).Init()
  3093. defer func() {
  3094. this.Data["json"] = br
  3095. this.ServeJSON()
  3096. }()
  3097. keyWord := this.GetString("KeyWord")
  3098. filterSource, _ := this.GetInt("FilterSource")
  3099. if filterSource <= 0 {
  3100. filterSource = 1
  3101. }
  3102. var pars []interface{}
  3103. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  3104. // 获取当前账号的不可见指标
  3105. {
  3106. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3107. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3108. if err != nil && err.Error() != utils.ErrNoRow() {
  3109. br.Msg = "获取失败"
  3110. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3111. return
  3112. }
  3113. for _, v := range confList {
  3114. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3115. }
  3116. }
  3117. var keyWordArr []string
  3118. keyWordArr = append(keyWordArr, keyWord)
  3119. if keyWord != "" {
  3120. newKeyWord := strings.Split(keyWord, " ")
  3121. keyWordArr = append(keyWordArr, newKeyWord...)
  3122. }
  3123. //var err error
  3124. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  3125. //if keyWord == "" {
  3126. // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars)
  3127. // if err != nil && err.Error() != utils.ErrNoRow() {
  3128. // br.Success = true
  3129. // br.Msg = "获取指标信息失败"
  3130. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3131. // return
  3132. // }
  3133. //} else {
  3134. // //获取指标信息
  3135. // indexName := utils.DATA_INDEX_NAME
  3136. // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource)
  3137. // if err != nil && err.Error() != utils.ErrNoRow() {
  3138. // br.Success = true
  3139. // br.Msg = "获取指标信息失败"
  3140. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3141. // return
  3142. // }
  3143. //}
  3144. var baseCondition string
  3145. // 无权限指标id
  3146. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3147. if lenNoPermissionEdbInfoIdList > 0 {
  3148. baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3149. pars = append(pars, noPermissionEdbInfoIdList)
  3150. }
  3151. existMap := make(map[int]string)
  3152. for _, v := range keyWordArr {
  3153. v = strings.Replace(v, " ", "%", -1)
  3154. var condition string
  3155. if filterSource == 2 {
  3156. condition += ` AND frequency='月度' `
  3157. }
  3158. if filterSource == 3 {
  3159. condition += ` AND frequency <> '日度' `
  3160. }
  3161. if filterSource == 4 {
  3162. condition += ` AND edb_type = 1 `
  3163. }
  3164. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  3165. condition += conditionWhere + baseCondition
  3166. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  3167. if err != nil && err.Error() != utils.ErrNoRow() {
  3168. br.Success = true
  3169. br.Msg = "获取指标信息失败"
  3170. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3171. return
  3172. }
  3173. for _, nv := range newEdbInfoList {
  3174. if _, ok := existMap[nv.EdbInfoId]; !ok {
  3175. edbInfoList = append(edbInfoList, nv)
  3176. }
  3177. existMap[nv.EdbInfoId] = nv.EdbCode
  3178. }
  3179. }
  3180. if edbInfoList == nil {
  3181. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3182. }
  3183. edbInfoListLen := len(edbInfoList)
  3184. for i := 0; i < edbInfoListLen; i++ {
  3185. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3186. }
  3187. for i := 0; i < edbInfoListLen; i++ {
  3188. for j := 0; j < edbInfoListLen; j++ {
  3189. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3190. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3191. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3192. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3193. }
  3194. }
  3195. }
  3196. //新增搜索词记录
  3197. {
  3198. searchKeyword := new(data_manage.SearchKeyword)
  3199. searchKeyword.KeyWord = keyWord
  3200. searchKeyword.CreateTime = time.Now()
  3201. go data_manage.AddSearchKeyword(searchKeyword)
  3202. }
  3203. br.Ret = 200
  3204. br.Success = true
  3205. br.Msg = "获取成功"
  3206. br.Data = edbInfoList
  3207. }
  3208. // EdbInfoFilterByEs
  3209. // @Title 指标筛选接口
  3210. // @Description 指标筛选接口
  3211. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  3212. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  3213. // @Param Frequency query string false "频度"
  3214. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  3215. // @Param PageSize query int true "每页数据条数"
  3216. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3217. // @Success 200 {object} data_manage.EdbInfoList
  3218. // @router /edb_info/filter_by_es [get]
  3219. func (this *EdbInfoController) EdbInfoFilterByEs() {
  3220. br := new(models.BaseResponse).Init()
  3221. defer func() {
  3222. this.Data["json"] = br
  3223. this.ServeJSON()
  3224. }()
  3225. pageSize, _ := this.GetInt("PageSize")
  3226. currentIndex, _ := this.GetInt("CurrentIndex")
  3227. var total int64
  3228. var startSize int
  3229. if pageSize <= 0 {
  3230. pageSize = utils.PageSize20
  3231. }
  3232. if currentIndex <= 0 {
  3233. currentIndex = 1
  3234. }
  3235. startSize = paging.StartIndex(currentIndex, pageSize)
  3236. keyWord := this.GetString("KeyWord")
  3237. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3238. filterSource, _ := this.GetInt("FilterSource")
  3239. if filterSource <= 0 {
  3240. filterSource = 1
  3241. }
  3242. //指标来源
  3243. source, _ := this.GetInt("Source")
  3244. frequency := this.GetString("Frequency") //频度
  3245. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  3246. var edbInfoList []*data_manage.EdbInfoList
  3247. var err error
  3248. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  3249. // 获取当前账号的不可见指标
  3250. {
  3251. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3252. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3253. if err != nil && err.Error() != utils.ErrNoRow() {
  3254. br.Msg = "获取失败"
  3255. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3256. return
  3257. }
  3258. for _, v := range confList {
  3259. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3260. }
  3261. }
  3262. // 只看我的
  3263. var sysUserId int
  3264. mine, _ := this.GetBool("IsShowMe")
  3265. if mine {
  3266. sysUserId = this.SysUser.AdminId
  3267. }
  3268. // 是否走ES
  3269. isEs := false
  3270. if keyWord != "" {
  3271. var keyWordArr []string
  3272. keyWordArr = append(keyWordArr, keyWord)
  3273. newKeyWord := strings.Split(keyWord, " ")
  3274. keyWordArr = append(keyWordArr, newKeyWord...)
  3275. // 普通的搜索
  3276. if !isAddPredictEdb {
  3277. if mine {
  3278. total, edbInfoList, err = elastic.SearchEdbInfoDataByAdminId(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, sysUserId)
  3279. } else {
  3280. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
  3281. }
  3282. } else {
  3283. // 允许添加预测指标的搜索
  3284. total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize, sysUserId)
  3285. }
  3286. isEs = true
  3287. } else {
  3288. var condition string
  3289. var pars []interface{}
  3290. // 普通指标
  3291. condition += ` AND edb_info_type = ? `
  3292. pars = append(pars, 0)
  3293. // 无权限指标id
  3294. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3295. if lenNoPermissionEdbInfoIdList > 0 {
  3296. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3297. pars = append(pars, noPermissionEdbInfoIdList)
  3298. }
  3299. switch filterSource {
  3300. case 2:
  3301. condition += ` AND frequency='月度' `
  3302. case 3:
  3303. condition += ` AND frequency <> '日度' `
  3304. case 4:
  3305. condition += ` AND edb_type = 1 `
  3306. case 5:
  3307. condition += ` AND source = 6 ` //来源(同比值)
  3308. case 6:
  3309. condition += ` AND frequency != ? `
  3310. pars = append(pars, "年度")
  3311. }
  3312. //频度
  3313. if frequency != "" {
  3314. condition += ` AND frequency = ? `
  3315. pars = append(pars, frequency)
  3316. }
  3317. if source > 0 && filterSource != 5 {
  3318. condition += ` AND source = ? `
  3319. pars = append(pars, source)
  3320. }
  3321. // 查询只允许添加预测指标的搜索
  3322. if isAddPredictEdb {
  3323. condition += ` AND frequency in ("日度","周度","月度") `
  3324. }
  3325. if mine {
  3326. condition += ` AND sys_user_id = ? `
  3327. pars = append(pars, sysUserId)
  3328. }
  3329. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  3330. }
  3331. if err != nil {
  3332. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3333. }
  3334. page := paging.GetPaging(currentIndex, pageSize, int(total))
  3335. edbInfoListLen := len(edbInfoList)
  3336. classifyIdList := make([]int, 0)
  3337. for i := 0; i < edbInfoListLen; i++ {
  3338. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3339. classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
  3340. // 如果没有关键词,那么搜索结果字段取指标名,前端已统一用该字段显示搜索的列表内容
  3341. if keyWord == "" {
  3342. if this.Lang == utils.ZhLangVersion {
  3343. edbInfoList[i].SearchText = edbInfoList[i].EdbName
  3344. }
  3345. if this.Lang == utils.EnLangVersion {
  3346. edbInfoList[i].SearchText = edbInfoList[i].EdbNameEn
  3347. }
  3348. }
  3349. }
  3350. // 当前列表中的分类map
  3351. classifyMap := make(map[int]*data_manage.EdbClassify)
  3352. if edbInfoListLen > 0 {
  3353. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  3354. if err != nil {
  3355. br.Msg = "获取失败"
  3356. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  3357. return
  3358. }
  3359. for _, v := range classifyList {
  3360. classifyMap[v.ClassifyId] = v
  3361. }
  3362. // 获取所有有权限的指标和分类
  3363. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  3364. if err != nil {
  3365. br.Msg = "获取失败"
  3366. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  3367. return
  3368. }
  3369. // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  3370. if isEs {
  3371. edbInfoIdList := make([]int, 0)
  3372. for i := 0; i < edbInfoListLen; i++ {
  3373. edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
  3374. tmpEdbInfo := edbInfoList[i]
  3375. if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
  3376. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  3377. }
  3378. }
  3379. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  3380. if err != nil {
  3381. br.Msg = "获取失败"
  3382. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  3383. return
  3384. }
  3385. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  3386. for _, v := range tmpEdbList {
  3387. edbInfoMap[v.EdbInfoId] = v
  3388. }
  3389. for i := 0; i < edbInfoListLen; i++ {
  3390. tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
  3391. if !ok {
  3392. continue
  3393. }
  3394. edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
  3395. }
  3396. }
  3397. // 权限校验
  3398. for i := 0; i < edbInfoListLen; i++ {
  3399. tmpEdbInfoItem := edbInfoList[i]
  3400. if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
  3401. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  3402. }
  3403. }
  3404. }
  3405. for i := 0; i < edbInfoListLen; i++ {
  3406. for j := 0; j < edbInfoListLen; j++ {
  3407. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3408. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3409. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3410. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3411. }
  3412. }
  3413. }
  3414. //新增搜索词记录
  3415. {
  3416. searchKeyword := new(data_manage.SearchKeyword)
  3417. searchKeyword.KeyWord = keyWord
  3418. searchKeyword.CreateTime = time.Now()
  3419. go data_manage.AddSearchKeyword(searchKeyword)
  3420. }
  3421. resp := data_manage.EdbInfoFilterDataResp{
  3422. Paging: page,
  3423. List: edbInfoList,
  3424. }
  3425. br.Ret = 200
  3426. br.Success = true
  3427. br.Msg = "获取成功"
  3428. br.Data = resp
  3429. }
  3430. func (this *EdbInfoController) EdbInfoFilter2() {
  3431. br := new(models.BaseResponse).Init()
  3432. defer func() {
  3433. this.Data["json"] = br
  3434. this.ServeJSON()
  3435. }()
  3436. keyWord := this.GetString("KeyWord")
  3437. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3438. filterSource, _ := this.GetInt("FilterSource")
  3439. if filterSource <= 0 {
  3440. filterSource = 1
  3441. }
  3442. var pars []interface{}
  3443. //if keyWord != "" {
  3444. // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  3445. //}
  3446. var keyWordArr []string
  3447. keyWordArr = append(keyWordArr, keyWord)
  3448. if keyWord != "" {
  3449. newKeyWord := strings.Split(keyWord, " ")
  3450. keyWordArr = append(keyWordArr, newKeyWord...)
  3451. }
  3452. keywordLen := len(keyWordArr)
  3453. ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen)
  3454. searchWait := sync.WaitGroup{}
  3455. searchWait.Add(keywordLen)
  3456. for index, v := range keyWordArr {
  3457. v = strings.Replace(v, " ", "%", -1)
  3458. var condition string
  3459. if filterSource == 2 {
  3460. condition += ` AND frequency='月度' `
  3461. }
  3462. if filterSource == 3 {
  3463. condition += ` AND frequency <> '日度' `
  3464. }
  3465. if filterSource == 4 {
  3466. condition += ` AND edb_type = 1 `
  3467. }
  3468. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  3469. condition += conditionWhere
  3470. go searchEdbInfoFilter(condition, pars, index, ch, &searchWait)
  3471. }
  3472. searchWait.Wait()
  3473. newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList)
  3474. i := 0
  3475. for tmpEdbInfoList := range ch {
  3476. i++
  3477. for k, v := range tmpEdbInfoList {
  3478. newEdbInfoListMap[k] = v
  3479. }
  3480. if i == keywordLen {
  3481. break
  3482. }
  3483. }
  3484. close(ch)
  3485. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  3486. existMap := make(map[int]string)
  3487. for i := 0; i < keywordLen; i++ {
  3488. if newEdbInfoList, ok := newEdbInfoListMap[i]; ok {
  3489. for _, nv := range newEdbInfoList {
  3490. if _, ok := existMap[nv.EdbInfoId]; !ok {
  3491. edbInfoList = append(edbInfoList, nv)
  3492. }
  3493. existMap[nv.EdbInfoId] = nv.EdbCode
  3494. }
  3495. }
  3496. }
  3497. if edbInfoList == nil {
  3498. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3499. }
  3500. edbInfoListLen := len(edbInfoList)
  3501. for i := 0; i < edbInfoListLen; i++ {
  3502. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3503. }
  3504. for i := 0; i < edbInfoListLen; i++ {
  3505. for j := 0; j < edbInfoListLen; j++ {
  3506. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3507. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3508. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3509. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3510. }
  3511. }
  3512. }
  3513. //新增搜索词记录
  3514. {
  3515. searchKeyword := new(data_manage.SearchKeyword)
  3516. searchKeyword.KeyWord = keyWord
  3517. searchKeyword.CreateTime = time.Now()
  3518. go data_manage.AddSearchKeyword(searchKeyword)
  3519. }
  3520. br.Ret = 200
  3521. br.Success = true
  3522. br.Msg = "获取成功"
  3523. br.Data = edbInfoList
  3524. }
  3525. 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) {
  3526. newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList)
  3527. defer func() {
  3528. if err != nil {
  3529. go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3)
  3530. //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  3531. }
  3532. ch <- newEdbInfoListMap
  3533. searchWait.Done()
  3534. }()
  3535. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  3536. newEdbInfoListMap[i] = newEdbInfoList
  3537. return
  3538. }
  3539. // EdbInfoAllRefresh
  3540. // @Title 指标全部刷新接口
  3541. // @Description 指标全部刷新接口
  3542. // @Param EdbInfoId query int true "指标id"
  3543. // @Success Ret=200 全部刷新成功
  3544. // @router /edb_info/refresh/all [get]
  3545. func (this *EdbInfoController) EdbInfoAllRefresh() {
  3546. br := new(models.BaseResponse).Init()
  3547. defer func() {
  3548. this.Data["json"] = br
  3549. this.ServeJSON()
  3550. }()
  3551. sysUser := this.SysUser
  3552. if sysUser == nil {
  3553. br.Msg = "请登录"
  3554. br.ErrMsg = "请登录,SysUser Is Empty"
  3555. br.Ret = 408
  3556. return
  3557. }
  3558. edbInfoId, _ := this.GetInt("EdbInfoId")
  3559. if edbInfoId <= 0 {
  3560. br.Msg = "参数错误"
  3561. br.ErrMsg = "参数错误"
  3562. return
  3563. }
  3564. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3565. if err != nil {
  3566. if err.Error() == utils.ErrNoRow() {
  3567. br.Msg = "数据已被删除,请刷新页面"
  3568. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  3569. return
  3570. }
  3571. br.Msg = "刷新失败"
  3572. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3573. return
  3574. }
  3575. if edbInfo == nil {
  3576. br.Msg = "数据已被删除,请刷新页面"
  3577. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  3578. return
  3579. }
  3580. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true, false)
  3581. if err != nil {
  3582. br.Msg = "刷新失败"
  3583. br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error()
  3584. return
  3585. }
  3586. br.Ret = 200
  3587. br.Success = true
  3588. br.Msg = "刷新成功"
  3589. if isAsync {
  3590. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  3591. }
  3592. }
  3593. // EdbInfoData
  3594. // @Title 获取指标数据
  3595. // @Description 获取指标数据
  3596. // @Param EdbInfoId query int true "指标ID"
  3597. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  3598. // @Param StartDate query string true "自定义开始日期"
  3599. // @Param EndDate query string true "自定义结束日期"
  3600. // @Success 200 {object} data_manage.EdbInfoDataResp
  3601. // @router /edb_info/data [get]
  3602. func (this *ChartInfoController) EdbInfoData() {
  3603. br := new(models.BaseResponse).Init()
  3604. defer func() {
  3605. this.Data["json"] = br
  3606. this.ServeJSON()
  3607. }()
  3608. sysUser := this.SysUser
  3609. if sysUser == nil {
  3610. br.Msg = "请登录"
  3611. br.ErrMsg = "请登录,SysUser Is Empty"
  3612. br.Ret = 408
  3613. return
  3614. }
  3615. fullEdb := new(data_manage.EdbInfoFullClassify)
  3616. resp := new(data_manage.EdbInfoDataFullClassifyResp)
  3617. dataList := make([]*data_manage.EdbDataList, 0)
  3618. edbInfoId, _ := this.GetInt("EdbInfoId")
  3619. if edbInfoId <= 0 {
  3620. br.Msg = "参数错误"
  3621. return
  3622. }
  3623. dateType, _ := this.GetInt("DateType")
  3624. if dateType <= 0 {
  3625. dateType = 3
  3626. }
  3627. edbInfoType, _ := this.GetInt("EdbInfoType")
  3628. if edbInfoType < 0 {
  3629. edbInfoType = 1
  3630. }
  3631. startDate := this.GetString("StartDate")
  3632. endDate := this.GetString("EndDate")
  3633. startYear, _ := this.GetInt("StartYear")
  3634. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3635. if err != nil {
  3636. if err.Error() == utils.ErrNoRow() {
  3637. br.Ret = 200
  3638. return
  3639. }
  3640. br.Msg = "获取失败"
  3641. br.ErrMsg = "获取失败,Err:" + err.Error()
  3642. return
  3643. }
  3644. // 分类
  3645. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  3646. if err != nil {
  3647. br.Msg = err.Error()
  3648. br.ErrMsg = errMsg
  3649. return
  3650. }
  3651. fullEdb.EdbInfo = edbInfo
  3652. // 是否供应商停更
  3653. fullEdb.IsSupplierStop = data.GetIsSupplierStop(edbInfo.Source, edbInfo.EdbCode)
  3654. fullEdb.ClassifyList = classifyList
  3655. var currClassifyItem *data_manage.EdbClassifyIdItems
  3656. for _, v := range classifyList {
  3657. if v.ClassifyId == edbInfo.ClassifyId {
  3658. currClassifyItem = v
  3659. }
  3660. }
  3661. if currClassifyItem != nil {
  3662. haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassifyItem.IsJoinPermission, sysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
  3663. if err != nil {
  3664. br.Msg = err.Error()
  3665. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  3666. return
  3667. }
  3668. fullEdb.HaveOperaAuth = haveOperaAuth
  3669. }
  3670. fullEdb.MinValue = utils.FormatFloatPoint(fullEdb.MinValue, 4)
  3671. fullEdb.MaxValue = utils.FormatFloatPoint(fullEdb.MaxValue, 4)
  3672. fullEdb.EndValue = utils.FormatFloatPoint(fullEdb.EndValue, 4)
  3673. fullEdb.LatestValue = utils.FormatFloatPoint(fullEdb.LatestValue, 4)
  3674. resp.EdbInfo = fullEdb
  3675. resp.DataList = make([]*data_manage.EdbDataList, 0)
  3676. // 数据获取
  3677. if fullEdb.HaveOperaAuth { // 有权限才获取数据
  3678. var latestDateT time.Time
  3679. if edbInfo.LatestDate != "" {
  3680. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3681. }
  3682. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  3683. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  3684. if err != nil {
  3685. br.Msg = "获取失败"
  3686. br.ErrMsg = "获取失败,Err:" + err.Error()
  3687. return
  3688. }
  3689. for _, v := range dataList {
  3690. v.Value = utils.FormatFloatPoint(v.Value, 4)
  3691. }
  3692. resp.DataList = dataList
  3693. }
  3694. br.Ret = 200
  3695. br.Success = true
  3696. br.Msg = "获取成功"
  3697. br.Data = resp
  3698. }
  3699. // EdbInfoReplaceCheck
  3700. // @Title 指标一键刷新接口
  3701. // @Description 指标一键刷新接口
  3702. // @Success Ret=200 更新成功
  3703. // @router /edb_info/replace/check [post]
  3704. func (this *EdbInfoController) EdbInfoReplaceCheck() {
  3705. br := new(models.BaseResponse).Init()
  3706. setNxKey := "EDB_INFO_REPLACE"
  3707. defer func() {
  3708. this.Data["json"] = br
  3709. this.ServeJSON()
  3710. }()
  3711. status := 0
  3712. if utils.Rc.IsExist(setNxKey) {
  3713. status = 1
  3714. } else {
  3715. status = 2
  3716. }
  3717. br.Ret = 200
  3718. br.Success = true
  3719. br.Msg = "检测成功"
  3720. br.Data = status
  3721. }
  3722. // EdbInfoReplace
  3723. // @Title 替换指标
  3724. // @Description 替换指标
  3725. // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
  3726. // @Success 200 {object} data_manage.EdbInfoDataResp
  3727. // @router /edb_info/replace [post]
  3728. func (this *ChartInfoController) EdbInfoReplace() {
  3729. br := new(models.BaseResponse).Init()
  3730. setNxKey := "EDB_INFO_REPLACE"
  3731. deleteCache := true
  3732. defer func() {
  3733. if deleteCache {
  3734. utils.Rc.Delete(setNxKey)
  3735. }
  3736. this.Data["json"] = br
  3737. this.ServeJSON()
  3738. }()
  3739. sysUser := this.SysUser
  3740. if sysUser == nil {
  3741. br.Msg = "请登录"
  3742. br.ErrMsg = "请登录,SysUser Is Empty"
  3743. br.Ret = 408
  3744. return
  3745. }
  3746. if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
  3747. deleteCache = false
  3748. br.Msg = "当前正在替换中,请耐心等待!"
  3749. br.IsSendEmail = false
  3750. return
  3751. }
  3752. var req data_manage.EdbInfoReplaceReq
  3753. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3754. if err != nil {
  3755. br.Msg = "参数解析异常!"
  3756. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3757. return
  3758. }
  3759. if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
  3760. br.Msg = "参数错误!"
  3761. br.ErrMsg = "参数错误,指标id为0"
  3762. return
  3763. }
  3764. oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
  3765. if err != nil {
  3766. br.Msg = "替换失败!"
  3767. br.ErrMsg = "获取原指标失败,Err:" + err.Error()
  3768. return
  3769. }
  3770. newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
  3771. if err != nil {
  3772. br.Msg = "替换失败!"
  3773. br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
  3774. return
  3775. }
  3776. //if oldEdbInfo.EdbType != 1 {
  3777. // br.Msg = "原指标为计算指标,不可替换!"
  3778. // br.ErrMsg = "原指标为计算指标,不可替换!"
  3779. // return
  3780. //}
  3781. //
  3782. //if newEdbInfo.EdbType != 1 {
  3783. // br.Msg = "替换指标为计算指标,不可替换!"
  3784. // br.ErrMsg = "替换指标为计算指标,不可替换!"
  3785. // return
  3786. //}
  3787. if oldEdbInfo.Frequency != newEdbInfo.Frequency {
  3788. br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3789. br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3790. return
  3791. }
  3792. if oldEdbInfo.EdbInfoType == 1 || newEdbInfo.EdbInfoType == 1 {
  3793. br.Msg = "预测指标不允许替换"
  3794. br.ErrMsg = "预测指标不允许替换"
  3795. return
  3796. }
  3797. // 判断指标是否循环引用
  3798. if oldEdbInfo.EdbType == 2 {
  3799. // 查询该计算指标的所有相关指标,如果相关指标中包含新指标,则提示
  3800. hasRelation, e := data.CheckTwoEdbInfoRelation(oldEdbInfo, newEdbInfo)
  3801. if e != nil {
  3802. br.Msg = "替换失败!"
  3803. br.ErrMsg = "查询指标引用关系失败,Err:" + e.Error()
  3804. return
  3805. }
  3806. if hasRelation {
  3807. br.Msg = "原指标与替换指标存在引用关系,不允许替换"
  3808. br.ErrMsg = "原指标与替换指标存在引用关系,不允许替换"
  3809. return
  3810. }
  3811. }
  3812. if newEdbInfo.EdbType == 2 {
  3813. // 查询该计算指标的所有相关指标,如果相关指标中包含新指标,则提示
  3814. hasRelation, e := data.CheckTwoEdbInfoRelation(newEdbInfo, oldEdbInfo)
  3815. if e != nil {
  3816. br.Msg = "替换失败!"
  3817. br.ErrMsg = "查询指标引用关系失败,Err:" + e.Error()
  3818. return
  3819. }
  3820. if hasRelation {
  3821. br.Msg = "原指标与替换指标存在引用关系,不允许替换"
  3822. br.ErrMsg = "原指标与替换指标存在引用关系,不允许替换"
  3823. return
  3824. }
  3825. }
  3826. sysAdminId := sysUser.AdminId
  3827. //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3828. _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3829. //msgContent := ``
  3830. if err != nil {
  3831. br.Msg = "替换失败"
  3832. br.ErrMsg = "替换失败 replace err:" + err.Error()
  3833. return
  3834. }
  3835. br.Msg = "替换成功"
  3836. br.ErrMsg = "替换成功"
  3837. br.Ret = 200
  3838. br.IsAddLog = true
  3839. return
  3840. }
  3841. // RelationChartList
  3842. // @Title 获取ETA指标关联的图表列表接口
  3843. // @Description 获取ETA指标关联的图表列表接口
  3844. // @Param PageSize query int true "每页数据条数"
  3845. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3846. // @Param EdbInfoId query int true "指标id"
  3847. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3848. // @Success 200 {object} data_manage.ChartListResp
  3849. // @router /edb_info/relation/chart_list [get]
  3850. func (this *EdbInfoController) RelationChartList() {
  3851. br := new(models.BaseResponse).Init()
  3852. defer func() {
  3853. this.Data["json"] = br
  3854. this.ServeJSON()
  3855. }()
  3856. sysUser := this.SysUser
  3857. if sysUser == nil {
  3858. br.Msg = "请登录"
  3859. br.ErrMsg = "请登录,SysUser Is Empty"
  3860. br.Ret = 408
  3861. return
  3862. }
  3863. edbInfoId, _ := this.GetInt("EdbInfoId")
  3864. pageSize, _ := this.GetInt("PageSize")
  3865. currentIndex, _ := this.GetInt("CurrentIndex")
  3866. resp := data_manage.ChartListResp{}
  3867. var total int
  3868. page := paging.GetPaging(currentIndex, pageSize, total)
  3869. var startSize int
  3870. if pageSize <= 0 {
  3871. pageSize = utils.PageSize20
  3872. }
  3873. if currentIndex <= 0 {
  3874. currentIndex = 1
  3875. }
  3876. startSize = paging.StartIndex(currentIndex, pageSize)
  3877. var condition string
  3878. var pars []interface{}
  3879. if edbInfoId <= 0 {
  3880. br.Msg = "请选择指标"
  3881. br.ErrMsg = "请选择指标"
  3882. br.IsSendEmail = false
  3883. return
  3884. }
  3885. /*// 关联指标
  3886. condition += ` AND b.edb_info_id = ? `
  3887. pars = append(pars, edbInfoId)*/
  3888. //只看我的
  3889. isShowMe, _ := this.GetBool("IsShowMe")
  3890. if isShowMe {
  3891. condition += ` AND a.sys_user_id = ? `
  3892. pars = append(pars, sysUser.AdminId)
  3893. }
  3894. chartIds := make([]int, 0)
  3895. chartIdMap := make(map[int]bool)
  3896. // 查询指标绑定的图表
  3897. edbListTemp, err := data_manage.GetEdbMappingListByEdbInfoId(edbInfoId)
  3898. if err != nil && err.Error() != utils.ErrNoRow() {
  3899. br.Msg = "获取图表信息失败"
  3900. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3901. return
  3902. }
  3903. for _, v := range edbListTemp {
  3904. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  3905. chartIdMap[v.ChartInfoId] = true
  3906. }
  3907. }
  3908. // 查询相关性的图表
  3909. correlationChart := new(data_manage.ChartInfoCorrelation)
  3910. correlationChartId, err := correlationChart.GetChartInfoIdByEdb(edbInfoId)
  3911. if err != nil && err.Error() != utils.ErrNoRow() {
  3912. br.Msg = "获取图表信息失败"
  3913. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3914. return
  3915. }
  3916. if correlationChartId > 0 {
  3917. chartIdMap[correlationChartId] = true
  3918. }
  3919. // 查询跨品种的图表
  3920. tagXList, err := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
  3921. if err != nil && err.Error() != utils.ErrNoRow() {
  3922. br.Msg = "获取图表信息失败"
  3923. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3924. return
  3925. }
  3926. for _, v := range tagXList {
  3927. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  3928. chartIdMap[v.ChartInfoId] = true
  3929. }
  3930. }
  3931. tagYList, err := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
  3932. if err != nil && err.Error() != utils.ErrNoRow() {
  3933. br.Msg = "获取图表信息失败"
  3934. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3935. return
  3936. }
  3937. for _, v := range tagYList {
  3938. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  3939. chartIdMap[v.ChartInfoId] = true
  3940. }
  3941. }
  3942. // 获取当前账号的不可见图表
  3943. {
  3944. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3945. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  3946. if err != nil && err.Error() != utils.ErrNoRow() {
  3947. br.Msg = "获取失败"
  3948. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3949. return
  3950. }
  3951. for _, v := range confList {
  3952. if _, ok := chartIdMap[v.ChartInfoId]; ok {
  3953. delete(chartIdMap, v.ChartInfoId)
  3954. }
  3955. }
  3956. }
  3957. for k, _ := range chartIdMap {
  3958. chartIds = append(chartIds, k)
  3959. }
  3960. // 关联指标
  3961. if len(chartIds) > 0 {
  3962. condition += ` AND a.chart_info_id in (` + utils.GetOrmInReplace(len(chartIds)) + `)`
  3963. pars = append(pars, chartIds)
  3964. } else {
  3965. items := make([]*data_manage.ChartInfoView, 0)
  3966. resp.Paging = page
  3967. resp.List = items
  3968. br.Ret = 200
  3969. br.Success = true
  3970. br.Msg = "获取成功"
  3971. return
  3972. }
  3973. // 得到图表ID
  3974. //获取关联图表列表
  3975. list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
  3976. if err != nil && err.Error() != utils.ErrNoRow() {
  3977. br.Success = true
  3978. br.Msg = "获取图表信息失败"
  3979. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3980. return
  3981. }
  3982. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3983. items := make([]*data_manage.ChartInfoView, 0)
  3984. resp.Paging = page
  3985. resp.List = items
  3986. br.Ret = 200
  3987. br.Success = true
  3988. br.Msg = "获取成功"
  3989. return
  3990. }
  3991. // 获取关联图表总数
  3992. dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
  3993. if err != nil && err.Error() != utils.ErrNoRow() {
  3994. br.Msg = "获取指标信息失败"
  3995. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3996. return
  3997. }
  3998. // 获取MY ETA 图表,用来判断是否加入我的图库
  3999. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  4000. if err != nil && err.Error() != utils.ErrNoRow() {
  4001. br.Msg = "获取图表信息失败"
  4002. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  4003. return
  4004. }
  4005. myChartMap := make(map[int]*data_manage.MyChartView)
  4006. for _, v := range myChartList {
  4007. myChartMap[v.ChartInfoId] = v
  4008. }
  4009. listLen := len(list)
  4010. if listLen > 0 {
  4011. // 分类id
  4012. classifyIdList := make([]int, 0)
  4013. // 当前列表中的分类map
  4014. classifyMap := make(map[int]*data_manage.ChartClassify)
  4015. for _, v := range list {
  4016. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  4017. }
  4018. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  4019. if err != nil {
  4020. br.Msg = "获取失败"
  4021. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4022. return
  4023. }
  4024. for _, v := range classifyList {
  4025. classifyMap[v.ChartClassifyId] = v
  4026. }
  4027. // 已授权分类id
  4028. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4029. if err != nil {
  4030. br.Msg = "获取失败"
  4031. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  4032. return
  4033. }
  4034. for _, v := range list {
  4035. if existItem, ok := myChartMap[v.ChartInfoId]; ok {
  4036. v.IsAdd = true
  4037. v.MyChartId = existItem.MyChartId
  4038. v.MyChartClassifyId = existItem.MyChartClassifyId
  4039. }
  4040. // 权限
  4041. if currClassify, ok := classifyMap[v.ChartClassifyId]; ok {
  4042. v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  4043. }
  4044. }
  4045. }
  4046. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  4047. resp.Paging = page
  4048. resp.List = list
  4049. br.Ret = 200
  4050. br.Success = true
  4051. br.Msg = "获取成功"
  4052. br.Data = resp
  4053. }
  4054. // RelationEdbList
  4055. // @Title 获取ETA指标关联的指标列表接口
  4056. // @Description 获取ETA指标关联的指标列表接口
  4057. // @Param PageSize query int true "每页数据条数"
  4058. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4059. // @Param EdbInfoId query int true "指标id"
  4060. // @Param IsShowMe query bool true "是否只看我的,true、false"
  4061. // @Success 200 {object} data_manage.ChartListResp
  4062. // @router /edb_info/relation/edbinfo_list [get]
  4063. func (this *EdbInfoController) RelationEdbList() {
  4064. br := new(models.BaseResponse).Init()
  4065. defer func() {
  4066. this.Data["json"] = br
  4067. this.ServeJSON()
  4068. }()
  4069. sysUser := this.SysUser
  4070. if sysUser == nil {
  4071. br.Msg = "请登录"
  4072. br.ErrMsg = "请登录,SysUser Is Empty"
  4073. br.Ret = 408
  4074. return
  4075. }
  4076. edbInfoId, _ := this.GetInt("EdbInfoId")
  4077. pageSize, _ := this.GetInt("PageSize")
  4078. currentIndex, _ := this.GetInt("CurrentIndex")
  4079. resp := data_manage.RelationEdbInfoListResp{}
  4080. var total int
  4081. page := paging.GetPaging(currentIndex, pageSize, total)
  4082. var startSize int
  4083. if pageSize <= 0 {
  4084. pageSize = utils.PageSize20
  4085. }
  4086. if currentIndex <= 0 {
  4087. currentIndex = 1
  4088. }
  4089. startSize = paging.StartIndex(currentIndex, pageSize)
  4090. var condition string
  4091. var pars []interface{}
  4092. if edbInfoId <= 0 {
  4093. br.Msg = "请选择指标"
  4094. br.ErrMsg = "请选择指标"
  4095. br.IsSendEmail = false
  4096. return
  4097. }
  4098. // 关联指标
  4099. condition += ` AND b.from_edb_info_id = ? `
  4100. pars = append(pars, edbInfoId)
  4101. //只看我的
  4102. isShowMe, _ := this.GetBool("IsShowMe")
  4103. if isShowMe {
  4104. condition += ` AND a.sys_user_id = ? `
  4105. pars = append(pars, sysUser.AdminId)
  4106. }
  4107. // 获取当前账号的不可见图表
  4108. noPermissionEdbIdList := make([]int, 0)
  4109. {
  4110. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4111. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4112. if err != nil && err.Error() != utils.ErrNoRow() {
  4113. br.Msg = "获取失败"
  4114. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  4115. return
  4116. }
  4117. for _, v := range confList {
  4118. noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
  4119. }
  4120. }
  4121. noPermissionEdbIdNum := len(noPermissionEdbIdList)
  4122. if noPermissionEdbIdNum > 0 {
  4123. condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
  4124. pars = append(pars, noPermissionEdbIdList)
  4125. }
  4126. //获取关联图表列表
  4127. list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
  4128. if err != nil && err.Error() != utils.ErrNoRow() {
  4129. br.Success = true
  4130. br.Msg = "获取图表信息失败"
  4131. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  4132. return
  4133. }
  4134. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  4135. items := make([]*data_manage.ChartEdbInfoMapping, 0)
  4136. resp.Paging = page
  4137. resp.List = items
  4138. br.Ret = 200
  4139. br.Success = true
  4140. br.Msg = "获取成功"
  4141. return
  4142. }
  4143. // 获取关联图表总数
  4144. dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
  4145. if err != nil && err.Error() != utils.ErrNoRow() {
  4146. br.Msg = "获取指标信息失败"
  4147. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  4148. return
  4149. }
  4150. if err != nil {
  4151. br.Msg = "获取失败"
  4152. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  4153. return
  4154. }
  4155. edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
  4156. if len(list) > 0 {
  4157. // 当前的分类
  4158. classifyMap := make(map[int]*data_manage.EdbClassify)
  4159. {
  4160. classifyIdList := make([]int, 0)
  4161. for _, v := range list {
  4162. classifyIdList = append(classifyIdList, v.ClassifyId)
  4163. }
  4164. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4165. if err != nil {
  4166. if err != nil {
  4167. br.Msg = "获取失败"
  4168. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4169. return
  4170. }
  4171. }
  4172. for _, v := range classifyList {
  4173. classifyMap[v.ClassifyId] = v
  4174. }
  4175. }
  4176. // 获取所有有权限的指标和分类
  4177. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4178. if err != nil {
  4179. br.Msg = "获取失败"
  4180. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4181. return
  4182. }
  4183. for _, v := range list {
  4184. item := new(data_manage.ChartEdbInfoMapping)
  4185. item.EdbInfoId = v.EdbInfoId
  4186. item.SourceName = v.SourceName
  4187. item.Source = v.Source
  4188. item.EdbCode = v.EdbCode
  4189. item.EdbName = v.EdbName
  4190. item.EdbNameEn = v.EdbNameEn
  4191. item.Frequency = v.Frequency
  4192. item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
  4193. if v.Unit != `无` {
  4194. item.Unit = v.Unit
  4195. }
  4196. item.UnitEn = v.UnitEn
  4197. item.StartDate = v.StartDate
  4198. item.EndDate = v.EndDate
  4199. item.ModifyTime = v.ModifyTime
  4200. item.IsAxis = 1
  4201. item.LeadValue = 0
  4202. item.LeadUnit = ""
  4203. item.ChartEdbMappingId = 0
  4204. item.ChartInfoId = 0
  4205. item.IsOrder = false
  4206. item.EdbInfoType = v.EdbInfoType
  4207. item.EdbInfoCategoryType = v.EdbInfoType
  4208. item.ChartStyle = ""
  4209. item.ChartColor = ""
  4210. item.ChartWidth = 0
  4211. item.MaxData = v.MaxValue
  4212. item.MinData = v.MinValue
  4213. item.LatestValue = v.LatestValue
  4214. item.LatestDate = v.LatestDate
  4215. item.UniqueCode = v.UniqueCode
  4216. item.ClassifyId = v.ClassifyId
  4217. dataList := make([]*data_manage.EdbDataList, 0)
  4218. // 指标权限
  4219. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  4220. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4221. }
  4222. // 有权限则获取数据
  4223. if item.HaveOperaAuth {
  4224. if v.EdbInfoType == 0 {
  4225. dataList, err = data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, "", "")
  4226. } else {
  4227. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
  4228. }
  4229. if err != nil {
  4230. br.Msg = "获取失败"
  4231. br.Msg = "获取失败,Err:" + err.Error()
  4232. return
  4233. }
  4234. }
  4235. item.DataList = dataList
  4236. edbList = append(edbList, item)
  4237. }
  4238. }
  4239. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  4240. resp.Paging = page
  4241. resp.List = edbList
  4242. br.Ret = 200
  4243. br.Success = true
  4244. br.Msg = "获取成功"
  4245. br.Data = resp
  4246. }
  4247. // EdbInfoDataTb
  4248. // @Title 获取指标数据同比值
  4249. // @Description 获取指标数据
  4250. // @Param EdbInfoId query int true "指标ID"
  4251. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4252. // @Param StartDate query string true "自定义开始日期"
  4253. // @Param EndDate query string true "自定义结束日期"
  4254. // @Success 200 {object} data_manage.EdbInfoDataResp
  4255. // @router /edb_info/data/tb [get]
  4256. func (this *ChartInfoController) EdbInfoDataTb() {
  4257. br := new(models.BaseResponse).Init()
  4258. defer func() {
  4259. this.Data["json"] = br
  4260. this.ServeJSON()
  4261. }()
  4262. sysUser := this.SysUser
  4263. if sysUser == nil {
  4264. br.Msg = "请登录"
  4265. br.ErrMsg = "请登录,SysUser Is Empty"
  4266. br.Ret = 408
  4267. return
  4268. }
  4269. edbInfoId, _ := this.GetInt("EdbInfoId")
  4270. if edbInfoId <= 0 {
  4271. br.Msg = "参数错误"
  4272. return
  4273. }
  4274. dateType, _ := this.GetInt("DateType")
  4275. if dateType <= 0 {
  4276. dateType = 3
  4277. }
  4278. edbInfoType, _ := this.GetInt("EdbInfoType")
  4279. if edbInfoType < 0 {
  4280. edbInfoType = 1
  4281. }
  4282. startDate := this.GetString("StartDate")
  4283. endDate := this.GetString("EndDate")
  4284. startYear, _ := this.GetInt("StartYear")
  4285. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4286. if err != nil {
  4287. br.Msg = "获取失败"
  4288. br.Msg = "获取失败,Err:" + err.Error()
  4289. return
  4290. }
  4291. var latestDateT time.Time
  4292. if edbInfo.LatestDate != "" {
  4293. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4294. }
  4295. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  4296. var startDateTime time.Time
  4297. if startDate != `` {
  4298. startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  4299. if err != nil {
  4300. br.Msg = "开始日期异常"
  4301. br.Msg = "开始日期异常,Err:" + err.Error()
  4302. return
  4303. }
  4304. //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
  4305. startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
  4306. }
  4307. tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  4308. if err != nil {
  4309. br.Msg = "获取失败"
  4310. br.Msg = "获取失败,Err:" + err.Error()
  4311. return
  4312. }
  4313. // 计算同比值
  4314. dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
  4315. if err != nil {
  4316. br.Msg = "获取失败"
  4317. br.Msg = "计算同比值失败,Err:" + err.Error()
  4318. return
  4319. }
  4320. edbInfo.MaxValue = maxValue
  4321. edbInfo.MinValue = minValue
  4322. resp := new(data_manage.EdbInfoDataResp)
  4323. resp.EdbInfo = edbInfo
  4324. resp.DataList = dataList
  4325. br.Ret = 200
  4326. br.Success = true
  4327. br.Msg = "获取成功"
  4328. br.Data = resp
  4329. }
  4330. // EdbInfoDataSeasonal
  4331. // @Title 获取指标数据(季节性)
  4332. // @Description 获取指标数据
  4333. // @Param EdbInfoId query int true "指标ID"
  4334. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4335. // @Param StartDate query string true "自定义开始日期"
  4336. // @Param EndDate query string true "自定义结束日期"
  4337. // @Param Calendar query string true "公历/农历"
  4338. // @Success 200 {object} data_manage.EdbInfoDataResp
  4339. // @router /edb_info/data/seasonal [get]
  4340. func (this *ChartInfoController) EdbInfoDataSeasonal() {
  4341. br := new(models.BaseResponse).Init()
  4342. defer func() {
  4343. this.Data["json"] = br
  4344. this.ServeJSON()
  4345. }()
  4346. sysUser := this.SysUser
  4347. if sysUser == nil {
  4348. br.Msg = "请登录"
  4349. br.ErrMsg = "请登录,SysUser Is Empty"
  4350. br.Ret = 408
  4351. return
  4352. }
  4353. dateType, _ := this.GetInt("DateType")
  4354. startDate := this.GetString("StartDate")
  4355. endDate := this.GetString("EndDate")
  4356. startYear, _ := this.GetInt("StartYear")
  4357. edbInfoIdStr := this.GetString("EdbInfoId")
  4358. edbInfoId, err := strconv.Atoi(edbInfoIdStr)
  4359. if err != nil {
  4360. br.Msg = "指标id异常"
  4361. br.Msg = "指标id转换异常,Err:" + err.Error()
  4362. return
  4363. }
  4364. fmt.Println("startDate:", startDate)
  4365. fmt.Println("endDate:", endDate)
  4366. calendar := this.GetString("Calendar")
  4367. if calendar == "" {
  4368. calendar = "公历"
  4369. }
  4370. if dateType == 0 {
  4371. if startDate == "" {
  4372. dateType = utils.DateTypeNYears
  4373. } else {
  4374. dateType = 5
  4375. }
  4376. }
  4377. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4378. if err != nil {
  4379. br.Msg = "获取失败"
  4380. br.Msg = "获取失败,Err:" + err.Error()
  4381. return
  4382. }
  4383. var latestDateT time.Time
  4384. if edbInfo.LatestDate != "" {
  4385. // 季节性图需要特殊处理最近N年数据
  4386. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4387. latestDateT = time.Date(latestDateT.Year()+1, 1, 1, 0, 0, 0, 0, time.Local)
  4388. }
  4389. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  4390. dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
  4391. if err != nil {
  4392. br.Msg = "获取失败"
  4393. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  4394. return
  4395. }
  4396. resp := new(data_manage.EdbInfoDataSeasonalResp)
  4397. resp.EdbInfo = edbInfo
  4398. resp.DataList = dataList
  4399. br.Ret = 200
  4400. br.Success = true
  4401. br.Msg = "获取成功"
  4402. br.Data = resp
  4403. }
  4404. // SetEdbDataInsertConfig 设置插入值
  4405. // @Title 设置插入值接口
  4406. // @Description 设置插入值接口
  4407. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  4408. // @router /edb_info/insert_config/set [post]
  4409. func (this *EdbInfoController) SetEdbDataInsertConfig() {
  4410. br := new(models.BaseResponse).Init()
  4411. defer func() {
  4412. this.Data["json"] = br
  4413. this.ServeJSON()
  4414. }()
  4415. sysUser := this.SysUser
  4416. if sysUser == nil {
  4417. br.Msg = "请登录"
  4418. br.ErrMsg = "请登录,SysUser Is Empty"
  4419. br.Ret = 408
  4420. return
  4421. }
  4422. var req data_manage.SetEdbDataInsertConfigReq
  4423. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4424. if err != nil {
  4425. br.Msg = "参数解析异常!"
  4426. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4427. return
  4428. }
  4429. dateStr := req.Date
  4430. if dateStr == `` {
  4431. br.Msg = "请选择日期"
  4432. br.IsSendEmail = false
  4433. return
  4434. }
  4435. date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
  4436. if err != nil {
  4437. br.Msg = "日期异常"
  4438. br.ErrMsg = "日期异常,err:" + err.Error()
  4439. br.IsSendEmail = false
  4440. return
  4441. }
  4442. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  4443. if err != nil {
  4444. br.Msg = "获取指标信息失败"
  4445. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  4446. return
  4447. }
  4448. err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
  4449. if err != nil {
  4450. br.Msg = "设置失败"
  4451. if errMsg != `` {
  4452. br.Msg = errMsg
  4453. }
  4454. br.ErrMsg = "修改失败,Err:" + err.Error()
  4455. br.IsSendEmail = isSendEmail
  4456. return
  4457. }
  4458. //新增操作日志
  4459. {
  4460. edbLog := new(data_manage.EdbInfoLog)
  4461. edbLog.EdbInfoId = edbInfo.EdbInfoId
  4462. edbLog.SourceName = edbInfo.SourceName
  4463. edbLog.Source = edbInfo.Source
  4464. edbLog.EdbCode = edbInfo.EdbCode
  4465. edbLog.EdbName = edbInfo.EdbName
  4466. edbLog.ClassifyId = edbInfo.ClassifyId
  4467. edbLog.SysUserId = sysUser.AdminId
  4468. edbLog.SysUserRealName = sysUser.RealName
  4469. edbLog.CreateTime = time.Now()
  4470. edbLog.Content = string(this.Ctx.Input.RequestBody)
  4471. edbLog.Status = "设置插入值"
  4472. edbLog.Method = this.Ctx.Input.URI()
  4473. go data_manage.AddEdbInfoLog(edbLog)
  4474. }
  4475. br.Ret = 200
  4476. br.Success = true
  4477. br.Msg = "保存成功"
  4478. br.IsAddLog = true
  4479. }
  4480. // TraceEdbInfo
  4481. // @Title 指标溯源接口
  4482. // @Description 指标溯源接口
  4483. // @Param UniqueCode query int true "指标唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  4484. // @Success 200 {object} data_manage.ChartListResp
  4485. // @router /edb_info/trace [get]
  4486. func (this *EdbInfoController) TraceEdbInfo() {
  4487. br := new(models.BaseResponse).Init()
  4488. defer func() {
  4489. this.Data["json"] = br
  4490. this.ServeJSON()
  4491. }()
  4492. sysUser := this.SysUser
  4493. if sysUser == nil {
  4494. br.Msg = "请登录"
  4495. br.ErrMsg = "请登录,SysUser Is Empty"
  4496. br.Ret = 408
  4497. return
  4498. }
  4499. //edbInfoId, _ := this.GetInt("EdbInfoId")
  4500. //if edbInfoId <= 0 {
  4501. // br.Msg = "参数错误"
  4502. // br.ErrMsg = "参数错误"
  4503. // return
  4504. //}
  4505. uniqueCode := this.GetString("UniqueCode")
  4506. if uniqueCode == `` {
  4507. br.Msg = "参数错误"
  4508. br.ErrMsg = "参数错误"
  4509. return
  4510. }
  4511. // 根据UniqueCode获取指标信息
  4512. edbInfo, err := data_manage.GetEdbInfoByUniqueCode(uniqueCode)
  4513. if err != nil {
  4514. br.Msg = "获取失败"
  4515. br.Msg = "获取失败,Err:" + err.Error()
  4516. if err.Error() == utils.ErrNoRow() {
  4517. br.Msg = "指标不存在"
  4518. }
  4519. return
  4520. }
  4521. resp, err := data.TraceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, this.SysUser.AdminId)
  4522. if err != nil {
  4523. br.Msg = "获取失败"
  4524. br.Msg = "获取失败,Err:" + err.Error()
  4525. return
  4526. }
  4527. br.Ret = 200
  4528. br.Data = resp
  4529. br.Success = true
  4530. br.Msg = "刷新成功"
  4531. }
  4532. // AllEdbInfoByEs
  4533. // @Title 所有指标筛选接口
  4534. // @Description 所有指标筛选接口
  4535. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  4536. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  4537. // @Param Frequency query string false "频度"
  4538. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  4539. // @Param PageSize query int true "每页数据条数"
  4540. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4541. // @Success 200 {object} data_manage.EdbInfoList
  4542. // @router /edb_info/filter_by_es/all [get]
  4543. func (this *EdbInfoController) AllEdbInfoByEs() {
  4544. br := new(models.BaseResponse).Init()
  4545. defer func() {
  4546. this.Data["json"] = br
  4547. this.ServeJSON()
  4548. }()
  4549. pageSize, _ := this.GetInt("PageSize")
  4550. currentIndex, _ := this.GetInt("CurrentIndex")
  4551. var total int64
  4552. var startSize int
  4553. if pageSize <= 0 {
  4554. pageSize = utils.PageSize20
  4555. }
  4556. if currentIndex <= 0 {
  4557. currentIndex = 1
  4558. }
  4559. startSize = paging.StartIndex(currentIndex, pageSize)
  4560. keyWord := this.GetString("KeyWord")
  4561. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  4562. filterSource, _ := this.GetInt("FilterSource")
  4563. if filterSource <= 0 {
  4564. filterSource = 1
  4565. }
  4566. //指标来源
  4567. source, _ := this.GetInt("Source")
  4568. frequency := this.GetString("Frequency") //频度
  4569. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  4570. var edbInfoList []*data_manage.EdbInfoList
  4571. var err error
  4572. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  4573. // 获取当前账号的不可见指标
  4574. {
  4575. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4576. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4577. if err != nil && err.Error() != utils.ErrNoRow() {
  4578. br.Msg = "获取失败"
  4579. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  4580. return
  4581. }
  4582. for _, v := range confList {
  4583. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  4584. }
  4585. }
  4586. // 只看我的
  4587. mine, _ := this.GetBool("IsShowMe")
  4588. // 是否走ES
  4589. isEs := false
  4590. if keyWord != "" {
  4591. var keyWordArr []string
  4592. keyWordArr = append(keyWordArr, keyWord)
  4593. newKeyWord := strings.Split(keyWord, " ")
  4594. keyWordArr = append(keyWordArr, newKeyWord...)
  4595. // 普通的搜索
  4596. if mine {
  4597. total, edbInfoList, err = elastic.SearchEdbInfoDataByAdminId(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 1, frequency, this.SysUser.AdminId)
  4598. } else {
  4599. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, frequency, noPermissionEdbInfoIdList)
  4600. }
  4601. isEs = true
  4602. } else {
  4603. var condition string
  4604. var pars []interface{}
  4605. // 普通指标
  4606. condition += ` AND edb_info_type = ? `
  4607. pars = append(pars, 0)
  4608. // 无权限指标id
  4609. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  4610. if lenNoPermissionEdbInfoIdList > 0 {
  4611. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  4612. pars = append(pars, noPermissionEdbInfoIdList)
  4613. }
  4614. switch filterSource {
  4615. case 2:
  4616. condition += ` AND frequency='月度' `
  4617. case 3:
  4618. condition += ` AND frequency <> '日度' `
  4619. case 4:
  4620. condition += ` AND edb_type = 1 `
  4621. case 5:
  4622. condition += ` AND source = 6 ` //来源(同比值)
  4623. case 6:
  4624. condition += ` AND frequency != ? `
  4625. pars = append(pars, "年度")
  4626. }
  4627. //频度
  4628. if frequency != "" {
  4629. condition += ` AND frequency = ? `
  4630. pars = append(pars, frequency)
  4631. }
  4632. // 查询只允许添加预测指标的搜索
  4633. if isAddPredictEdb {
  4634. condition += ` AND frequency in ("日度","周度","月度") `
  4635. }
  4636. if mine {
  4637. condition += ` AND sys_user_id = ? `
  4638. pars = append(pars, this.SysUser.AdminId)
  4639. }
  4640. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  4641. }
  4642. if err != nil {
  4643. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  4644. }
  4645. page := paging.GetPaging(currentIndex, pageSize, int(total))
  4646. edbInfoListLen := len(edbInfoList)
  4647. classifyIdList := make([]int, 0)
  4648. for i := 0; i < edbInfoListLen; i++ {
  4649. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  4650. classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
  4651. // 如果没有关键词,那么搜索结果字段取指标名,前端已统一用该字段显示搜索的列表内容
  4652. if keyWord == "" {
  4653. if this.Lang == utils.ZhLangVersion {
  4654. edbInfoList[i].SearchText = edbInfoList[i].EdbName
  4655. }
  4656. if this.Lang == utils.EnLangVersion {
  4657. edbInfoList[i].SearchText = edbInfoList[i].EdbNameEn
  4658. }
  4659. }
  4660. }
  4661. // 当前列表中的分类map
  4662. classifyMap := make(map[int]*data_manage.EdbClassify)
  4663. if edbInfoListLen > 0 {
  4664. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4665. if err != nil {
  4666. br.Msg = "获取失败"
  4667. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4668. return
  4669. }
  4670. for _, v := range classifyList {
  4671. classifyMap[v.ClassifyId] = v
  4672. }
  4673. // 获取所有有权限的指标和分类
  4674. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4675. if err != nil {
  4676. br.Msg = "获取失败"
  4677. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4678. return
  4679. }
  4680. // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  4681. if isEs {
  4682. edbInfoIdList := make([]int, 0)
  4683. for i := 0; i < edbInfoListLen; i++ {
  4684. edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
  4685. tmpEdbInfo := edbInfoList[i]
  4686. if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
  4687. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4688. }
  4689. }
  4690. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  4691. if err != nil {
  4692. br.Msg = "获取失败"
  4693. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4694. return
  4695. }
  4696. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  4697. for _, v := range tmpEdbList {
  4698. edbInfoMap[v.EdbInfoId] = v
  4699. }
  4700. for i := 0; i < edbInfoListLen; i++ {
  4701. tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
  4702. if !ok {
  4703. continue
  4704. }
  4705. edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
  4706. }
  4707. }
  4708. // 权限校验
  4709. for i := 0; i < edbInfoListLen; i++ {
  4710. tmpEdbInfoItem := edbInfoList[i]
  4711. if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
  4712. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4713. }
  4714. }
  4715. }
  4716. for i := 0; i < edbInfoListLen; i++ {
  4717. for j := 0; j < edbInfoListLen; j++ {
  4718. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  4719. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  4720. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  4721. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  4722. }
  4723. }
  4724. }
  4725. //新增搜索词记录
  4726. {
  4727. searchKeyword := new(data_manage.SearchKeyword)
  4728. searchKeyword.KeyWord = keyWord
  4729. searchKeyword.CreateTime = time.Now()
  4730. go data_manage.AddSearchKeyword(searchKeyword)
  4731. }
  4732. resp := data_manage.EdbInfoFilterDataResp{
  4733. Paging: page,
  4734. List: edbInfoList,
  4735. }
  4736. br.Ret = 200
  4737. br.Success = true
  4738. br.Msg = "获取成功"
  4739. br.Data = resp
  4740. }
  4741. // GetEdbDateData
  4742. // @Title 根据指标ID和具体日期获取对应日期的数据值
  4743. // @Description 根据指标ID和具体日期获取对应日期的数据值
  4744. // @Param EdbInfoId query int false "指标id"
  4745. // @Param Date query string false "日期"
  4746. // @Success 200 {object} data_manage.EdbInfoList
  4747. // @router /edb_info/date_data [get]
  4748. func (this *EdbInfoController) GetEdbDateData() {
  4749. br := new(models.BaseResponse).Init()
  4750. defer func() {
  4751. this.Data["json"] = br
  4752. this.ServeJSON()
  4753. }()
  4754. edbInfoId, _ := this.GetInt("EdbInfoId")
  4755. date := this.GetString("Date")
  4756. if edbInfoId <= 0 {
  4757. br.Msg = "请选择指标"
  4758. br.IsSendEmail = false
  4759. return
  4760. }
  4761. if date == `` {
  4762. br.Msg = "请选择日期"
  4763. br.IsSendEmail = false
  4764. return
  4765. }
  4766. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4767. if err != nil {
  4768. br.Msg = "获取失败"
  4769. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4770. return
  4771. }
  4772. startDate := date
  4773. endDate := date
  4774. dateType := "day"
  4775. //如果填写的是月度日期
  4776. if strings.Count(date, "-") == 1 {
  4777. startDate = date + "-01"
  4778. endDate = ``
  4779. dateType = "month"
  4780. }
  4781. dataItem, err := data.GetDateData(edbInfo, startDate, endDate)
  4782. if err != nil {
  4783. br.Msg = "获取失败"
  4784. br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
  4785. return
  4786. }
  4787. val := ``
  4788. if dataItem != nil {
  4789. switch dateType {
  4790. case "month":
  4791. dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local)
  4792. dateTimeStr := dateTime.Format(utils.FormatYearMonthDate)
  4793. if dateTimeStr != date {
  4794. val = ``
  4795. }
  4796. }
  4797. val = fmt.Sprint(dataItem.Value)
  4798. }
  4799. br.Ret = 200
  4800. br.Success = true
  4801. br.Msg = "获取成功"
  4802. br.Data = val
  4803. }
  4804. // GetEdbBeforeAndAfterDateData
  4805. // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4806. // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4807. // @Param EdbInfoId query int false "指标id"
  4808. // @Param Date query string false "日期"
  4809. // @Param Num query int false "前后几期数据"
  4810. // @Success 200 {object} data_manage.EdbInfoList
  4811. // @router /edb_info/date_data/before_after [post]
  4812. func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
  4813. br := new(models.BaseResponse).Init()
  4814. defer func() {
  4815. this.Data["json"] = br
  4816. this.ServeJSON()
  4817. }()
  4818. requestBody := string(this.Ctx.Input.RequestBody)
  4819. var req request2.DateDataBeforeAfterReq
  4820. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4821. if err != nil {
  4822. br.Msg = "参数解析异常!"
  4823. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4824. return
  4825. }
  4826. edbInfoId := req.EdbInfoId
  4827. currDate := req.Date
  4828. num := req.Num
  4829. // 默认2期数据
  4830. if num <= 0 {
  4831. num = 2
  4832. }
  4833. if edbInfoId <= 0 {
  4834. br.Msg = "请选择指标"
  4835. br.IsSendEmail = false
  4836. return
  4837. }
  4838. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4839. if err != nil {
  4840. br.Msg = "获取失败"
  4841. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4842. return
  4843. }
  4844. dataList := make([]*data_manage.EdbDataList, 0)
  4845. switch edbInfo.EdbInfoType {
  4846. case 0:
  4847. dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
  4848. case 1:
  4849. _, dataList, _, _, _, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  4850. default:
  4851. br.Msg = "指标类型异常!"
  4852. br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType)
  4853. return
  4854. }
  4855. if currDate == `` {
  4856. currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList)
  4857. if err != nil {
  4858. br.Msg = "日期前移失败"
  4859. br.ErrMsg = "日期前移失败,Err:" + err.Error()
  4860. return
  4861. }
  4862. } else {
  4863. if strings.Count(currDate, "-") == 1 {
  4864. currDate = currDate + "-01"
  4865. // 查找这个月早的时间作为起始时间
  4866. for _, v := range dataList {
  4867. if v.DataTime >= currDate {
  4868. currDate = v.DataTime
  4869. break
  4870. }
  4871. }
  4872. }
  4873. }
  4874. currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody)
  4875. if err != nil {
  4876. br.Msg = "日期变换失败"
  4877. br.ErrMsg = "日期变换失败,Err:" + err.Error()
  4878. return
  4879. }
  4880. list := make([]*data_manage.EdbDataList, 5)
  4881. list, err = data.GetEdbBeforeAndAfterDateData(currDate, dataList)
  4882. if err != nil {
  4883. br.Msg = "获取失败"
  4884. br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
  4885. return
  4886. }
  4887. // 这个日期不存在的话直接返回空数组
  4888. resp := data_manage.BeforeAndAfterDateDataResp{
  4889. List: list,
  4890. Date: currDate,
  4891. }
  4892. br.Ret = 200
  4893. br.Success = true
  4894. br.Msg = "获取成功"
  4895. br.Data = resp
  4896. }
  4897. // EdbChartAdminList
  4898. // @Title 获取创建人员分组
  4899. // @Description 获取创建人员分组
  4900. // @Param Source query int false "来源 :1:手工数据指标 2:上海钢联数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  4901. // @Success 200 {object} company.DepartmentGroupSellersResp
  4902. // @router /edb_chart/adminList [get]
  4903. func (this *EdbInfoController) EdbChartAdminList() {
  4904. br := new(models.BaseResponse).Init()
  4905. defer func() {
  4906. this.Data["json"] = br
  4907. this.ServeJSON()
  4908. }()
  4909. sysUser := this.SysUser
  4910. if sysUser == nil {
  4911. br.Msg = "请登录"
  4912. br.ErrMsg = "请登录,SysUser Is Empty"
  4913. br.Ret = 408
  4914. return
  4915. }
  4916. source, _ := this.GetInt("Source", 0)
  4917. if source <= 0 || source > 5 {
  4918. br.Msg = "错误的来源"
  4919. br.IsSendEmail = false
  4920. return
  4921. }
  4922. idList, err := data.GetEdbChartAdminList(source)
  4923. if err != nil {
  4924. //br.Success = true
  4925. br.Msg = "获取失败"
  4926. br.ErrMsg = "获取失败,Err:" + err.Error()
  4927. return
  4928. }
  4929. fmt.Println("idlist:", idList)
  4930. systemAdminMap := make(map[int]*system.Admin)
  4931. departmentMap := make(map[string]string)
  4932. departmentAdminMap := make(map[int]string)
  4933. groupMap := make(map[string]string)
  4934. systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList)
  4935. if err != nil {
  4936. br.Msg = "获取用户列表失败"
  4937. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  4938. return
  4939. }
  4940. for _, v := range systemAdminList {
  4941. systemAdminMap[v.AdminId] = v
  4942. departmentMap[v.DepartmentName] = v.DepartmentName
  4943. departmentAdminMap[v.AdminId] = v.DepartmentName
  4944. groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName
  4945. }
  4946. depList := make([]company.DepartmentGroupAdmins, 0)
  4947. i := 1
  4948. for _, v := range departmentMap {
  4949. item := company.DepartmentGroupAdmins{
  4950. AdminId: "dep_" + strconv.Itoa(i),
  4951. RealName: v,
  4952. }
  4953. i++
  4954. depList = append(depList, item)
  4955. }
  4956. for k := 0; k < len(depList); k++ {
  4957. for k1, v1 := range groupMap {
  4958. if v1 == depList[k].RealName && v1 != "" {
  4959. item := &company.DepartmentGroupAdmins{
  4960. AdminId: "group_" + strconv.Itoa(k),
  4961. RealName: strings.Replace(k1, v1, "", -1),
  4962. }
  4963. depList[k].ChildrenList = append(depList[k].ChildrenList, item)
  4964. }
  4965. }
  4966. }
  4967. for _, admin := range systemAdminList {
  4968. for i, v := range depList {
  4969. for k, group := range v.ChildrenList {
  4970. if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName {
  4971. item := &company.DepartmentGroupAdmins{
  4972. AdminId: strconv.Itoa(admin.AdminId),
  4973. RealName: admin.RealName,
  4974. RoleTypeCode: admin.RoleTypeCode,
  4975. Authority: admin.Authority,
  4976. }
  4977. if group.RealName != "" {
  4978. depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item)
  4979. } else {
  4980. depList[i].ChildrenList = append(depList[i].ChildrenList, item)
  4981. }
  4982. }
  4983. }
  4984. }
  4985. }
  4986. for i, groupList := range depList {
  4987. for k, v := range groupList.ChildrenList {
  4988. if v.RealName == "" {
  4989. newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...)
  4990. depList[i].ChildrenList = newChildrenList
  4991. }
  4992. }
  4993. }
  4994. br.Ret = 200
  4995. br.Success = true
  4996. br.Msg = "获取成功"
  4997. br.Data = depList
  4998. }
  4999. // EdbSourceList
  5000. // @Title 指标来源列表
  5001. // @Description 指标来源列表
  5002. // @Param IsBase query int false "是否为基础指标: 1-是"
  5003. // @Success 200 {object} data_manage.EdbInfoListResp
  5004. // @router /edb_source/list [get]
  5005. func (this *EdbInfoController) EdbSourceList() {
  5006. br := new(models.BaseResponse).Init()
  5007. defer func() {
  5008. if br.ErrMsg == "" {
  5009. br.IsSendEmail = false
  5010. }
  5011. this.Data["json"] = br
  5012. this.ServeJSON()
  5013. }()
  5014. isBase, _ := this.GetInt("IsBase", 0)
  5015. cond := ``
  5016. if isBase > 0 {
  5017. cond = ` AND is_base = 1`
  5018. }
  5019. pars := make([]interface{}, 0)
  5020. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  5021. if e != nil {
  5022. br.Msg = "获取失败"
  5023. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  5024. return
  5025. }
  5026. br.Data = list
  5027. br.Ret = 200
  5028. br.Success = true
  5029. br.Msg = "获取成功"
  5030. }
  5031. // EdbSourceListByPython
  5032. // @Title 指标来源列表
  5033. // @Description 指标来源列表
  5034. // @Param IsBase query int false "是否为基础指标: 1-是"
  5035. // @Success 200 {object} data_manage.EdbInfoListResp
  5036. // @router /edb_source/list/python [get]
  5037. func (this *EdbInfoController) EdbSourceListByPython() {
  5038. br := new(models.BaseResponse).Init()
  5039. defer func() {
  5040. if br.ErrMsg == "" {
  5041. br.IsSendEmail = false
  5042. }
  5043. this.Data["json"] = br
  5044. this.ServeJSON()
  5045. }()
  5046. isBase, _ := this.GetInt("IsBase", 0)
  5047. cond := ``
  5048. if isBase > 0 {
  5049. cond = ` AND is_base = 1`
  5050. }
  5051. pars := make([]interface{}, 0)
  5052. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  5053. if e != nil {
  5054. br.Msg = "获取失败"
  5055. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  5056. return
  5057. }
  5058. baseEdbList := make([]data_manage.EdbSourceChild, 0)
  5059. calEdbList := make([]data_manage.EdbSourceChild, 0)
  5060. for _, v := range list {
  5061. switch v.IsBase {
  5062. case 1:
  5063. baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{
  5064. EdbSourceId: v.EdbSourceId,
  5065. SourceName: v.SourceName,
  5066. IsBase: v.IsBase,
  5067. TableName: v.TableName,
  5068. Child: []data_manage.EdbSourceChild{},
  5069. })
  5070. case 2:
  5071. calEdbList = append(calEdbList, data_manage.EdbSourceChild{
  5072. EdbSourceId: v.EdbSourceId,
  5073. SourceName: v.SourceName,
  5074. IsBase: v.IsBase,
  5075. TableName: v.TableName,
  5076. Child: []data_manage.EdbSourceChild{},
  5077. })
  5078. }
  5079. }
  5080. resp := []data_manage.EdbSourceChild{
  5081. {
  5082. EdbSourceId: 0,
  5083. SourceName: "基础指标",
  5084. IsBase: 1,
  5085. Child: baseEdbList,
  5086. },
  5087. {
  5088. EdbSourceId: 0,
  5089. SourceName: "计算指标",
  5090. IsBase: 1,
  5091. Child: calEdbList,
  5092. },
  5093. }
  5094. br.Data = resp
  5095. br.Ret = 200
  5096. br.Success = true
  5097. br.Msg = "获取成功"
  5098. }
  5099. // EdbChartList
  5100. // @Title 指标缩略图列表接口
  5101. // @Description 指标缩略图列表接口
  5102. // @Param PageSize query int true "每页数据条数"
  5103. // @Param CurrentIndex query int true "当前页页码,从1开始"
  5104. // @Param ClassifyId query int true "分类id"
  5105. // @Param AdminId query int false "创建人id"
  5106. // @Param IsOnlyMe query bool false "是否只看我的"
  5107. // @Success 200 {object} response.EdbInfoChartListResp
  5108. // @router /edb_info/chart/list [get]
  5109. func (this *EdbInfoController) EdbChartList() {
  5110. br := new(models.BaseResponse).Init()
  5111. defer func() {
  5112. if br.ErrMsg == "" {
  5113. br.IsSendEmail = false
  5114. }
  5115. this.Data["json"] = br
  5116. this.ServeJSON()
  5117. }()
  5118. sysUser := this.SysUser
  5119. if sysUser == nil {
  5120. br.Msg = "请登录"
  5121. br.ErrMsg = "请登录,SysUser Is Empty"
  5122. br.Ret = 408
  5123. return
  5124. }
  5125. // 分页
  5126. pageSize, _ := this.GetInt("PageSize")
  5127. currentIndex, _ := this.GetInt("CurrentIndex")
  5128. var total int
  5129. page := paging.GetPaging(currentIndex, pageSize, total)
  5130. var startSize int
  5131. if pageSize <= 0 {
  5132. pageSize = utils.PageSize20
  5133. }
  5134. if currentIndex <= 0 {
  5135. currentIndex = 1
  5136. }
  5137. startSize = paging.StartIndex(currentIndex, pageSize)
  5138. // 基础指标
  5139. var condition string
  5140. var pars []interface{}
  5141. condition += ` AND edb_info_type = ? `
  5142. pars = append(pars, 0)
  5143. // 分类筛选
  5144. classifyId, _ := this.GetInt("ClassifyId")
  5145. if classifyId > 0 {
  5146. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  5147. if e != nil && e.Error() != utils.ErrNoRow() {
  5148. br.Msg = "获取失败"
  5149. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  5150. return
  5151. }
  5152. var classifyIds []int
  5153. for _, v := range childClassify {
  5154. classifyIds = append(classifyIds, v.ClassifyId)
  5155. }
  5156. condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  5157. pars = append(pars, classifyIds)
  5158. }
  5159. // 创建人
  5160. adminId, _ := this.GetInt("AdminId")
  5161. if adminId > 0 {
  5162. condition += ` AND sys_user_id = ? `
  5163. pars = append(pars, adminId)
  5164. }
  5165. // 只看我的
  5166. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  5167. if isOnlyMe {
  5168. condition += ` AND sys_user_id = ? `
  5169. pars = append(pars, sysUser.AdminId)
  5170. }
  5171. // 获取当前账号的不可见指标
  5172. obj := data_manage.EdbInfoNoPermissionAdmin{}
  5173. confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
  5174. if e != nil {
  5175. br.Msg = "获取失败"
  5176. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
  5177. return
  5178. }
  5179. noPermissionEdbInfoIdList := make([]int, 0)
  5180. for _, v := range confList {
  5181. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  5182. }
  5183. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  5184. if noPermissionEdbInfoIdNum > 0 {
  5185. condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  5186. pars = append(pars, noPermissionEdbInfoIdList)
  5187. }
  5188. // 获取指标信息
  5189. dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  5190. if e != nil {
  5191. br.Msg = "获取失败"
  5192. br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
  5193. return
  5194. }
  5195. if len(list) == 0 {
  5196. list = make([]*data_manage.EdbInfoList, 0)
  5197. } else {
  5198. classifyIdList := make([]int, 0)
  5199. for _, v := range list {
  5200. classifyIdList = append(classifyIdList, v.ClassifyId)
  5201. }
  5202. // 指标权限
  5203. {
  5204. // 当前的分类
  5205. classifyMap := make(map[int]*data_manage.EdbClassify)
  5206. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  5207. if err != nil {
  5208. if err != nil {
  5209. br.Msg = "获取失败"
  5210. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  5211. return
  5212. }
  5213. }
  5214. for _, v := range classifyList {
  5215. classifyMap[v.ClassifyId] = v
  5216. }
  5217. // 获取所有有权限的指标和分类
  5218. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  5219. if err != nil {
  5220. br.Msg = "获取失败"
  5221. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  5222. return
  5223. }
  5224. issSupplierStopIndexCodeMap := make(map[string]bool)
  5225. {
  5226. tmpEdbCodeList := make([]string, 0)
  5227. for _, v := range list {
  5228. if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  5229. tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode)
  5230. }
  5231. }
  5232. if len(tmpEdbCodeList) > 0 {
  5233. notIsSupplierStopIndexList, e := data_manage.GetNotIsSupplierStopIndexByCodeList(tmpEdbCodeList, 1)
  5234. if e != nil {
  5235. br.Msg = "获取失败"
  5236. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  5237. return
  5238. }
  5239. // 已被供应商暂停的指标编码
  5240. for _, v := range notIsSupplierStopIndexList {
  5241. issSupplierStopIndexCodeMap[v.IndexCode] = true
  5242. }
  5243. }
  5244. }
  5245. for _, v := range list {
  5246. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  5247. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  5248. v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType, v.HaveOperaAuth)
  5249. }
  5250. // 供应商停用
  5251. if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  5252. if _, ok := issSupplierStopIndexCodeMap[v.EdbCode]; ok {
  5253. v.IsSupplierStop = 1
  5254. }
  5255. }
  5256. }
  5257. }
  5258. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  5259. }
  5260. resp := response.EdbInfoChartListResp{
  5261. Paging: page,
  5262. List: list,
  5263. }
  5264. br.Ret = 200
  5265. br.Success = true
  5266. br.Msg = "获取成功"
  5267. br.Data = resp
  5268. }
  5269. // Modify
  5270. // @Title 修改指标信息接口
  5271. // @Description 编辑指标接口
  5272. // @Success 200 string "操作成功"
  5273. // @router /edb_info/modify [post]
  5274. func (this *EdbInfoController) Modify() {
  5275. br := new(models.BaseResponse).Init()
  5276. defer func() {
  5277. if br.ErrMsg == "" {
  5278. br.IsSendEmail = false
  5279. }
  5280. this.Data["json"] = br
  5281. this.ServeJSON()
  5282. }()
  5283. sysUser := this.SysUser
  5284. if sysUser == nil {
  5285. br.Msg = "请登录"
  5286. br.ErrMsg = "请登录,SysUser Is Empty"
  5287. br.Ret = 408
  5288. return
  5289. }
  5290. var req request.ModifyEdbInfoReq
  5291. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5292. if err != nil {
  5293. br.Msg = "参数解析异常!"
  5294. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5295. return
  5296. }
  5297. edbInfoId := req.EdbInfoId
  5298. if edbInfoId <= 0 {
  5299. br.Msg = "请选择指标"
  5300. br.IsSendEmail = false
  5301. return
  5302. }
  5303. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5304. if e != nil {
  5305. br.Msg = "操作失败"
  5306. br.ErrMsg = "获取指标信息失败, Err:" + err.Error()
  5307. return
  5308. }
  5309. var haveOperaAuth bool
  5310. // 权限校验
  5311. {
  5312. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
  5313. if err != nil {
  5314. br.Msg = err.Error()
  5315. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  5316. return
  5317. }
  5318. }
  5319. // 编辑权限校验
  5320. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  5321. if !button.OpButton {
  5322. br.Msg = "无权限操作"
  5323. return
  5324. }
  5325. edbInfo.MaxValue = req.MaxValue
  5326. edbInfo.MinValue = req.MinValue
  5327. edbInfo.ManualSave = 1
  5328. edbInfo.ModifyTime = time.Now()
  5329. err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"})
  5330. if err != nil {
  5331. br.Msg = "获取失败"
  5332. br.ErrMsg = "获取失败,Err:" + err.Error()
  5333. return
  5334. }
  5335. //修改es
  5336. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  5337. br.Ret = 200
  5338. br.Success = true
  5339. br.Msg = "修改成功"
  5340. br.IsAddLog = true
  5341. }
  5342. // ChartImageSet
  5343. // @Title 设置指标的图表图片
  5344. // @Description 设置指标的图表图片接口
  5345. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  5346. // @Success Ret=200 保存成功
  5347. // @router /edb_info/image/set [post]
  5348. func (this *EdbInfoController) ChartImageSet() {
  5349. br := new(models.BaseResponse).Init()
  5350. defer func() {
  5351. if br.ErrMsg == "" {
  5352. br.IsSendEmail = false
  5353. }
  5354. this.Data["json"] = br
  5355. this.ServeJSON()
  5356. }()
  5357. sysUser := this.SysUser
  5358. if sysUser == nil {
  5359. br.Msg = "请登录"
  5360. br.ErrMsg = "请登录,SysUser Is Empty"
  5361. br.Ret = 408
  5362. return
  5363. }
  5364. var req data_manage.SetEdbInfoImageReq
  5365. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  5366. br.Msg = "参数解析异常!"
  5367. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  5368. return
  5369. }
  5370. if req.EdbInfoId <= 0 || req.ImageUrl == "" {
  5371. br.Ret = 200
  5372. br.Success = true
  5373. br.Msg = "保存成功"
  5374. return
  5375. }
  5376. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5377. if e != nil {
  5378. if e.Error() == utils.ErrNoRow() {
  5379. br.Msg = "找不到该指标"
  5380. return
  5381. }
  5382. br.Msg = "保存失败"
  5383. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  5384. return
  5385. }
  5386. edbInfo.ChartImage = req.ImageUrl
  5387. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  5388. br.Msg = "保存失败"
  5389. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  5390. return
  5391. }
  5392. // 修改es数据
  5393. go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  5394. br.Ret = 200
  5395. br.Success = true
  5396. br.Msg = "保存成功"
  5397. }
  5398. // EdbInfoExistCheck
  5399. // @Title 新增指标-检验指标是否存在接口
  5400. // @Description 新增指标-检验指标是否存在接口
  5401. // @Param Source query int true "来源:1:同花顺,2:wind"
  5402. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5403. // @Param EdbCode query string false "指标编码/指标代码"
  5404. // @Param StockCode query string false "证券代码"
  5405. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5406. // @router /edb_info/exist/check [get]
  5407. func (this *EdbInfoController) EdbInfoExistCheck() {
  5408. br := new(models.BaseResponse).Init()
  5409. defer func() {
  5410. this.Data["json"] = br
  5411. this.ServeJSON()
  5412. }()
  5413. source, _ := this.GetInt("Source")
  5414. edbCode := this.GetString("EdbCode")
  5415. edbCode = strings.Trim(edbCode, "\t")
  5416. edbCode = strings.Trim(edbCode, " ")
  5417. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5418. subSource, _ := this.GetInt("SubSource")
  5419. stockCode := this.GetString("StockCode")
  5420. if source <= 0 {
  5421. br.Msg = "无效的数据来源"
  5422. return
  5423. }
  5424. if edbCode == "" {
  5425. br.Msg = "请输入指标ID"
  5426. return
  5427. }
  5428. if source != utils.DATA_SOURCE_WIND && source != utils.DATA_SOURCE_THS {
  5429. br.Msg = "无效的数据来源"
  5430. return
  5431. }
  5432. if subSource != utils.DATA_SUB_SOURCE_DATE {
  5433. br.Msg = "无效的数据库来源"
  5434. return
  5435. }
  5436. var indexCodeArr []string
  5437. edbCodeArr := strings.Split(edbCode, ",")
  5438. stockCodeArr := strings.Split(stockCode, ",")
  5439. var prefix string
  5440. if source == utils.DATA_SOURCE_WIND {
  5441. prefix = utils.WindDbWsd
  5442. } else if source == utils.DATA_SOURCE_THS {
  5443. prefix = utils.ThsDs
  5444. } else {
  5445. br.Msg = "来源错误"
  5446. br.ErrMsg = "来源错误"
  5447. return
  5448. }
  5449. for _, sv := range stockCodeArr {
  5450. for _, ev := range edbCodeArr {
  5451. indexCode := prefix + sv + ev
  5452. indexCodeArr = append(indexCodeArr, indexCode)
  5453. }
  5454. }
  5455. indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr)
  5456. if err != nil && err.Error() != utils.ErrNoRow() {
  5457. br.Msg = "校验指标是否存在失败"
  5458. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5459. return
  5460. }
  5461. var existStockCodeArr []string
  5462. var existEdbCodeArr []string
  5463. var existClassifyId []int
  5464. var existIndexId []int
  5465. for _, indexItem := range indexList {
  5466. for _, sv := range stockCodeArr {
  5467. for _, ev := range edbCodeArr {
  5468. if strings.Contains(indexItem.EdbCode, sv) {
  5469. existStockCodeArr = append(existStockCodeArr, sv)
  5470. }
  5471. if strings.Contains(indexItem.EdbCode, ev) {
  5472. existEdbCodeArr = append(existEdbCodeArr, ev)
  5473. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5474. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5475. }
  5476. }
  5477. }
  5478. }
  5479. resp := new(data_manage.EdbInfoExistCheckResp)
  5480. if len(indexList) > 0 {
  5481. resp.IndexExist = true
  5482. }
  5483. resp.ExistEdbCodeArr = existEdbCodeArr
  5484. resp.ExistStockCodeArr = existStockCodeArr
  5485. resp.ExistClassifyId = existClassifyId
  5486. resp.ExistIndexId = existIndexId
  5487. resp.ExistEdbInfo = indexList
  5488. br.Ret = 200
  5489. br.Success = true
  5490. br.Msg = "获取成功"
  5491. br.Data = resp
  5492. }
  5493. // EdbInfoAdd
  5494. // @Title 指标批量保存接口
  5495. // @Description 指标批量保存接口
  5496. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  5497. // @Success Ret=200 保存成功
  5498. // @router /edb_info/batch/add [post]
  5499. func (this *EdbInfoController) EdbInfoBatchAdd() {
  5500. br := new(models.BaseResponse).Init()
  5501. defer func() {
  5502. this.Data["json"] = br
  5503. this.ServeJSON()
  5504. }()
  5505. sysUser := this.SysUser
  5506. if sysUser == nil {
  5507. br.Msg = "请登录"
  5508. br.ErrMsg = "请登录,SysUser Is Empty"
  5509. br.Ret = 408
  5510. return
  5511. }
  5512. deleteCache := true
  5513. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  5514. defer func() {
  5515. if deleteCache {
  5516. utils.Rc.Delete(cacheKey)
  5517. }
  5518. }()
  5519. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  5520. deleteCache = false
  5521. br.Msg = "系统处理中,请稍后重试!"
  5522. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  5523. return
  5524. }
  5525. var req data_manage.BatchAddEdbInfoReq
  5526. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5527. if err != nil {
  5528. br.Msg = "参数解析异常!"
  5529. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5530. return
  5531. }
  5532. resp := new(data_manage.AddEdbInfoResp)
  5533. var edbNames string
  5534. for _, v := range req.BatchList {
  5535. edbNames += "'" + v.EdbName + "',"
  5536. }
  5537. edbNames = strings.Trim(edbNames, ",")
  5538. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  5539. if err != nil {
  5540. br.Msg = "查询指标名称重复错误!"
  5541. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  5542. return
  5543. }
  5544. if len(infoList) > 0 {
  5545. for _, v := range infoList {
  5546. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  5547. }
  5548. br.Data = resp
  5549. br.Msg = "指标名称重复!"
  5550. br.ErrMsg = "指标名称重复"
  5551. return
  5552. }
  5553. for k, v := range req.BatchList {
  5554. v.EdbName = strings.Trim(v.EdbName, " ")
  5555. v.EdbCode = strings.Trim(v.EdbCode, " ")
  5556. v.StockCode = strings.Trim(v.StockCode, " ")
  5557. if v.Source <= 0 {
  5558. br.Msg = "无效的数据来源"
  5559. return
  5560. }
  5561. if v.EdbCode == "" {
  5562. br.Msg = "指标ID不能为空"
  5563. return
  5564. }
  5565. if v.StockCode == "" {
  5566. br.Msg = "证券代码不能为空"
  5567. return
  5568. }
  5569. if v.EdbName == "" {
  5570. br.Msg = "指标名称不能为空"
  5571. return
  5572. }
  5573. if v.Frequency == "" {
  5574. br.Msg = "频率不能为空"
  5575. return
  5576. }
  5577. if v.ClassifyId <= 0 {
  5578. br.Msg = "请选择分类"
  5579. return
  5580. }
  5581. terminalCode, serverUrl, _, e := data.GetEdbTerminalCodeBySource(v.Source, v.EdbCode, v.StockCode)
  5582. if e != nil {
  5583. br.Msg = "获取可以使用的终端地址失败"
  5584. br.ErrMsg = "获取可以使用的终端地址失败,Err:" + e.Error()
  5585. return
  5586. }
  5587. edbInfoItem := new(data_manage.EdbInfo)
  5588. edbInfoItem.Source = v.Source
  5589. switch v.Source {
  5590. case utils.DATA_SOURCE_WIND:
  5591. edbInfoItem.SourceName = "wind"
  5592. edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
  5593. case utils.DATA_SOURCE_THS:
  5594. edbInfoItem.SourceName = "ths"
  5595. edbInfoItem.EdbCode = utils.ThsDs + v.StockCode + v.EdbCode
  5596. }
  5597. edbInfoItem.SubSource = utils.DATA_SUB_SOURCE_DATE
  5598. edbInfoItem.SubSourceName = "日期序列"
  5599. edbInfoItem.EdbName = v.EdbName
  5600. edbInfoItem.EdbNameSource = v.EdbName
  5601. edbInfoItem.EdbNameEn = v.EdbName
  5602. edbInfoItem.Frequency = v.Frequency
  5603. edbInfoItem.Unit = v.Unit
  5604. edbInfoItem.UnitEn = v.Unit
  5605. edbInfoItem.ClassifyId = v.ClassifyId
  5606. edbInfoItem.SysUserId = sysUser.AdminId
  5607. edbInfoItem.SysUserRealName = sysUser.RealName
  5608. edbInfoItem.IndicatorCode = v.EdbCode
  5609. edbInfoItem.StockCode = v.StockCode
  5610. edbInfoItem.TerminalCode = terminalCode
  5611. edbInfoItem.ServerUrl = serverUrl
  5612. var extra data_manage.EdbInfoExtra
  5613. if v.ApiExtraPars != "" {
  5614. extra.ApiExtraPars = v.ApiExtraPars
  5615. b, e := json.Marshal(extra)
  5616. if e != nil {
  5617. br.Msg = "保存失败"
  5618. br.ErrMsg = fmt.Sprintf("额外参数JSON格式化失败, %v", e)
  5619. return
  5620. }
  5621. edbInfoItem.Extra = string(b)
  5622. }
  5623. // 指标入库
  5624. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  5625. if err != nil {
  5626. br.Msg = "保存失败"
  5627. if errMsg != `` {
  5628. br.Msg = errMsg
  5629. }
  5630. br.ErrMsg = err.Error()
  5631. br.IsSendEmail = isSendEmail
  5632. return
  5633. }
  5634. //新增操作日志
  5635. {
  5636. edbLog := new(data_manage.EdbInfoLog)
  5637. edbLog.EdbInfoId = edbInfo.EdbInfoId
  5638. edbLog.SourceName = edbInfo.SourceName
  5639. edbLog.Source = edbInfo.Source
  5640. edbLog.EdbCode = edbInfo.EdbCode
  5641. edbLog.EdbName = edbInfo.EdbName
  5642. edbLog.ClassifyId = edbInfo.ClassifyId
  5643. edbLog.SysUserId = sysUser.AdminId
  5644. edbLog.SysUserRealName = sysUser.RealName
  5645. edbLog.CreateTime = time.Now()
  5646. edbLog.Content = string(this.Ctx.Input.RequestBody)
  5647. edbLog.Status = "新增指标"
  5648. edbLog.Method = this.Ctx.Input.URI()
  5649. go data_manage.AddEdbInfoLog(edbLog)
  5650. }
  5651. if k <= 0 {
  5652. resp.EdbInfoId = edbInfo.EdbInfoId
  5653. resp.UniqueCode = edbInfo.UniqueCode
  5654. }
  5655. }
  5656. // 试用平台更新用户累计新增指标数
  5657. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  5658. if e != nil {
  5659. br.Msg = "操作失败"
  5660. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  5661. return
  5662. }
  5663. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  5664. go func() {
  5665. var r etaTrialService.EtaTrialUserReq
  5666. r.Mobile = adminItem.Mobile
  5667. _, _ = etaTrialService.UpdateUserIndexNum(r)
  5668. }()
  5669. }
  5670. br.Ret = 200
  5671. br.Success = true
  5672. br.Msg = "保存成功"
  5673. br.Data = resp
  5674. br.IsAddLog = true
  5675. }
  5676. // SmmExistCheck
  5677. // @Title 新增指标-检验指标是否存在接口-smm
  5678. // @Description 新增指标-检验指标是否存在接口-smm
  5679. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5680. // @Param EdbCode query string false "指标编码/指标代码"
  5681. // @Param StockCode query string false "证券代码"
  5682. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5683. // @router /edb_info/smm/exist/check [post]
  5684. func (this *EdbInfoController) SmmExistCheck() {
  5685. br := new(models.BaseResponse).Init()
  5686. defer func() {
  5687. this.Data["json"] = br
  5688. this.ServeJSON()
  5689. }()
  5690. var req data_manage.SmmIndexExistCheckReq
  5691. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5692. if err != nil {
  5693. br.Msg = "参数解析异常!"
  5694. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5695. return
  5696. }
  5697. types := req.Types
  5698. frequency := req.Frequency
  5699. dataState := req.DataState
  5700. selectAll := req.SelectAll
  5701. keyword := req.Keyword
  5702. edbCode := req.EdbCode
  5703. edbCode = strings.Trim(edbCode, "\t")
  5704. edbCode = strings.Trim(edbCode, " ")
  5705. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5706. var edbCodeArr []string
  5707. var codeArr []string
  5708. if selectAll {
  5709. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5710. var condition string
  5711. var pars []interface{}
  5712. if len(types) > 0 {
  5713. condition += " AND ( "
  5714. for _, v := range types {
  5715. typeArr := strings.Split(v, ",")
  5716. for i, v := range typeArr {
  5717. if i == 0 {
  5718. condition += " ( "
  5719. }
  5720. typeStr := "type_"
  5721. typeStr += fmt.Sprintf("%d", i+1)
  5722. condition += typeStr + " =? "
  5723. pars = append(pars, v)
  5724. if i == len(typeArr)-1 {
  5725. condition += " ) "
  5726. } else {
  5727. condition += " AND "
  5728. }
  5729. }
  5730. condition += " OR "
  5731. }
  5732. condition = strings.Trim(condition, "OR ")
  5733. condition += " ) "
  5734. }
  5735. if frequency != "" {
  5736. frequencyArr := strings.Split(frequency, ",")
  5737. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5738. pars = append(pars, frequencyArr)
  5739. }
  5740. if dataState != "" {
  5741. stateArr := strings.Split(dataState, ",")
  5742. if strings.Contains(dataState, "normal") {
  5743. stateArr = append(stateArr, "")
  5744. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5745. pars = append(pars, stateArr)
  5746. } else {
  5747. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5748. pars = append(pars, stateArr)
  5749. }
  5750. }
  5751. if keyword != "" {
  5752. keyWordArr := strings.Split(keyword, " ")
  5753. if len(keyWordArr) > 0 {
  5754. condition += " AND ( "
  5755. for _, v := range keyWordArr {
  5756. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5757. }
  5758. condition = strings.TrimRight(condition, "OR")
  5759. condition += " ) "
  5760. }
  5761. }
  5762. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5763. if err != nil {
  5764. br.Msg = "获取指标列表失败"
  5765. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5766. return
  5767. }
  5768. for _, v := range indexList {
  5769. codeArr = append(codeArr, v.IndexCode)
  5770. }
  5771. noUseCodeArr := strings.Split(edbCode, ",")
  5772. for _, code := range codeArr {
  5773. // 检查code是否在noUseCodeArr数组中
  5774. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5775. // 如果不在,将其添加到结果数组中
  5776. edbCodeArr = append(edbCodeArr, code)
  5777. }
  5778. }
  5779. } else {
  5780. //未勾选全选EdbCode就是需要的code
  5781. edbCodeArr = strings.Split(edbCode, ",")
  5782. }
  5783. if len(edbCodeArr) > 30 {
  5784. br.Msg = "最多只能选择30个指标"
  5785. return
  5786. }
  5787. if len(edbCodeArr) <= 0 {
  5788. br.Msg = "无符合指标或指标代码错误"
  5789. return
  5790. }
  5791. indexList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_YS, edbCodeArr)
  5792. if err != nil && err.Error() != utils.ErrNoRow() {
  5793. br.Msg = "校验指标是否存在失败"
  5794. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5795. return
  5796. }
  5797. var existEdbCodeArr []string
  5798. var existClassifyId []int
  5799. var existIndexId []int
  5800. for _, indexItem := range indexList {
  5801. for _, ev := range edbCodeArr {
  5802. if strings.Contains(indexItem.EdbCode, ev) {
  5803. existEdbCodeArr = append(existEdbCodeArr, ev)
  5804. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5805. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5806. }
  5807. }
  5808. }
  5809. resp := new(data_manage.EdbInfoSmmExistCheckResp)
  5810. if len(indexList) > 0 {
  5811. resp.IndexExist = true
  5812. }
  5813. if len(existEdbCodeArr) == len(edbCodeArr) {
  5814. resp.ExistAll = true
  5815. }
  5816. resp.ExistEdbCodeArr = existEdbCodeArr
  5817. resp.ExistClassifyId = existClassifyId
  5818. resp.ExistIndexId = existIndexId
  5819. resp.ExistEdbInfo = indexList
  5820. br.Ret = 200
  5821. br.Success = true
  5822. br.Msg = "获取成功"
  5823. br.Data = resp
  5824. }
  5825. // EdbInfoSearch
  5826. // @Title 新增指标-查询指标信息接口-smm
  5827. // @Description 新增指标-查询指标信息接口-smm
  5828. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  5829. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5830. // @Param EdbCode query string false "指标编码/指标代码"
  5831. // @Param StockCode query string false "证券代码"
  5832. // @Success 200 {object} data_manage.EdbInfoSearchResp
  5833. // @router /edb_info/smm/search [post]
  5834. func (this *EdbInfoController) EdbInfoSmmSearch() {
  5835. br := new(models.BaseResponse).Init()
  5836. defer func() {
  5837. this.Data["json"] = br
  5838. this.ServeJSON()
  5839. }()
  5840. var req data_manage.SmmIndexExistCheckReq
  5841. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5842. if err != nil {
  5843. br.Msg = "参数解析异常!"
  5844. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5845. return
  5846. }
  5847. types := req.Types
  5848. frequency := req.Frequency
  5849. dataState := req.DataState
  5850. selectAll := req.SelectAll
  5851. keyword := req.Keyword
  5852. edbCode := req.EdbCode
  5853. edbCode = strings.Trim(edbCode, "\t")
  5854. edbCode = strings.Trim(edbCode, " ")
  5855. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5856. var edbCodeArr []string
  5857. var codeArr []string
  5858. if selectAll {
  5859. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5860. var condition string
  5861. var pars []interface{}
  5862. if len(types) > 0 {
  5863. condition += " AND ( "
  5864. for _, v := range types {
  5865. typeArr := strings.Split(v, ",")
  5866. for i, v := range typeArr {
  5867. if i == 0 {
  5868. condition += " ( "
  5869. }
  5870. typeStr := "type_"
  5871. typeStr += fmt.Sprintf("%d", i+1)
  5872. condition += typeStr + " =? "
  5873. pars = append(pars, v)
  5874. if i == len(typeArr)-1 {
  5875. condition += " ) "
  5876. } else {
  5877. condition += " AND "
  5878. }
  5879. }
  5880. condition += " OR "
  5881. }
  5882. condition = strings.Trim(condition, "OR ")
  5883. condition += " ) "
  5884. }
  5885. if frequency != "" {
  5886. frequencyArr := strings.Split(frequency, ",")
  5887. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5888. pars = append(pars, frequencyArr)
  5889. }
  5890. if dataState != "" {
  5891. stateArr := strings.Split(dataState, ",")
  5892. if strings.Contains(dataState, "normal") {
  5893. stateArr = append(stateArr, "")
  5894. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5895. pars = append(pars, stateArr)
  5896. } else {
  5897. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5898. pars = append(pars, stateArr)
  5899. }
  5900. }
  5901. if keyword != "" {
  5902. keyWordArr := strings.Split(keyword, " ")
  5903. if len(keyWordArr) > 0 {
  5904. condition += " AND ( "
  5905. for _, v := range keyWordArr {
  5906. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5907. }
  5908. condition = strings.TrimRight(condition, "OR")
  5909. condition += " ) "
  5910. }
  5911. }
  5912. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5913. if err != nil {
  5914. br.Msg = "获取指标列表失败"
  5915. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5916. return
  5917. }
  5918. for _, v := range indexList {
  5919. codeArr = append(codeArr, v.IndexCode)
  5920. }
  5921. noUseCodeArr := strings.Split(edbCode, ",")
  5922. for _, code := range codeArr {
  5923. // 检查code是否在noUseCodeArr数组中
  5924. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5925. // 如果不在,将其添加到结果数组中
  5926. edbCodeArr = append(edbCodeArr, code)
  5927. }
  5928. }
  5929. } else {
  5930. //未勾选全选EdbCode就是需要的code
  5931. edbCodeArr = strings.Split(edbCode, ",")
  5932. }
  5933. if len(edbCodeArr) > 30 {
  5934. br.Msg = "最多只能选择30个指标"
  5935. return
  5936. }
  5937. if len(edbCodeArr) <= 0 {
  5938. br.Msg = "无符合指标或指标代码错误"
  5939. return
  5940. }
  5941. edbCodeStr := ""
  5942. for i, _ := range edbCodeArr {
  5943. edbCodeStr += "'" + edbCodeArr[i] + "'" + ","
  5944. }
  5945. edbCodeStr = strings.Trim(edbCodeStr, ",")
  5946. smmInfoList, err := data_manage.GetBaseFromSmmIndexByIndexCodes(edbCodeStr)
  5947. if err != nil && err.Error() != utils.ErrNoRow() {
  5948. br.Msg = "获取失败"
  5949. br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
  5950. return
  5951. }
  5952. smmInfoMap := make(map[string]*data_manage.BaseFromSmmIndex)
  5953. for _, v := range smmInfoList {
  5954. smmInfoMap[v.IndexCode] = v
  5955. }
  5956. searchItemList := make([]*data_manage.EdbInfoSearch, 0)
  5957. resp := new(data_manage.EdbInfoSearchResp)
  5958. needAddCodeArr := make([]string, 0)
  5959. noNeedAddCodeMap := make(map[string]string, 0)
  5960. for _, edbCode := range edbCodeArr {
  5961. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  5962. if err != nil && err.Error() != utils.ErrNoRow() {
  5963. br.Msg = "获取失败"
  5964. br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
  5965. return
  5966. }
  5967. fmt.Println("dataItems:", len(dataItems))
  5968. if len(dataItems) > 0 {
  5969. searchItem := new(data_manage.EdbInfoSearch)
  5970. searchItem.EdbCode = edbCode
  5971. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  5972. if err != nil {
  5973. br.Msg = "获取失败"
  5974. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  5975. return
  5976. }
  5977. searchItem.DataList = dataItems
  5978. searchItem.StartDate = minDate
  5979. searchItem.EndDate = maxDate
  5980. searchItem.Frequency = smmInfoMap[edbCode].Frequency
  5981. searchItem.Unit = smmInfoMap[edbCode].Unit
  5982. searchItem.EdbName = smmInfoMap[edbCode].IndexName
  5983. searchItem.EdbCode = smmInfoMap[edbCode].IndexCode
  5984. searchItemList = append(searchItemList, searchItem)
  5985. noNeedAddCodeMap[edbCode] = edbCode
  5986. } else {
  5987. // 把需要新加的code添加到needAddCodeArr数组中,一起批量请求
  5988. needAddCodeArr = append(needAddCodeArr, edbCode)
  5989. }
  5990. }
  5991. if len(needAddCodeArr) > 0 {
  5992. edbCode = strings.Join(needAddCodeArr, ",")
  5993. respItem, err := data.AddEdbData(utils.DATA_SOURCE_YS, edbCode, "")
  5994. if err != nil {
  5995. br.Msg = "获取失败"
  5996. br.ErrMsg = "获取失败,Err:" + err.Error()
  5997. return
  5998. }
  5999. if respItem.Ret != 200 {
  6000. if respItem.Ret == 421 {
  6001. br.Msg = "该渠道已超过添加上限"
  6002. } else if respItem.Ret == 4052 {
  6003. br.Msg = "该指标已下架"
  6004. } else {
  6005. br.Msg = "未搜索到该指标"
  6006. }
  6007. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  6008. return
  6009. }
  6010. }
  6011. for _, smmInfo := range smmInfoList {
  6012. if smmInfo != nil {
  6013. if _, ok := noNeedAddCodeMap[smmInfo.IndexCode]; !ok {
  6014. searchItem := new(data_manage.EdbInfoSearch)
  6015. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(smmInfo.IndexCode)
  6016. if err != nil {
  6017. br.Msg = "获取失败"
  6018. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  6019. return
  6020. }
  6021. searchItem.StartDate = minDate
  6022. searchItem.EndDate = maxDate
  6023. searchItem.Frequency = smmInfo.Frequency
  6024. searchItem.Unit = smmInfo.Unit
  6025. searchItem.EdbName = smmInfo.IndexName
  6026. searchItem.EdbCode = smmInfo.IndexCode
  6027. dataList, err := data_manage.GetEdbDataAllByEdbCode(smmInfo.IndexCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  6028. if err != nil && err.Error() != utils.ErrNoRow() {
  6029. br.Msg = "获取失败"
  6030. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  6031. return
  6032. }
  6033. searchItem.DataList = dataList
  6034. searchItemList = append(searchItemList, searchItem)
  6035. }
  6036. }
  6037. }
  6038. resp.Status = 2
  6039. resp.StockSearchList = searchItemList
  6040. br.Ret = 200
  6041. br.Success = true
  6042. br.Msg = "获取成功"
  6043. br.Data = resp
  6044. }
  6045. // SmmEdbInfoBatchAdd
  6046. // @Title 指标批量保存接口-smm
  6047. // @Description 指标批量保存接口-smm
  6048. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  6049. // @Success Ret=200 保存成功
  6050. // @router /edb_info/smm/batch/add [post]
  6051. func (this *EdbInfoController) SmmEdbInfoBatchAdd() {
  6052. br := new(models.BaseResponse).Init()
  6053. defer func() {
  6054. this.Data["json"] = br
  6055. this.ServeJSON()
  6056. }()
  6057. sysUser := this.SysUser
  6058. if sysUser == nil {
  6059. br.Msg = "请登录"
  6060. br.ErrMsg = "请登录,SysUser Is Empty"
  6061. br.Ret = 408
  6062. return
  6063. }
  6064. deleteCache := true
  6065. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  6066. defer func() {
  6067. if deleteCache {
  6068. utils.Rc.Delete(cacheKey)
  6069. }
  6070. }()
  6071. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  6072. deleteCache = false
  6073. br.Msg = "系统处理中,请稍后重试!"
  6074. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  6075. return
  6076. }
  6077. var req data_manage.BatchAddEdbInfoReq
  6078. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  6079. if err != nil {
  6080. br.Msg = "参数解析异常!"
  6081. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  6082. return
  6083. }
  6084. resp := new(data_manage.AddEdbInfoResp)
  6085. var edbNames string
  6086. for _, v := range req.BatchList {
  6087. edbNames += "'" + v.EdbName + "',"
  6088. }
  6089. edbNames = strings.Trim(edbNames, ",")
  6090. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  6091. if err != nil {
  6092. br.Msg = "查询指标名称重复错误!"
  6093. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  6094. return
  6095. }
  6096. if len(infoList) > 0 {
  6097. for _, v := range infoList {
  6098. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  6099. }
  6100. br.Data = resp
  6101. br.Msg = "指标名称重复!"
  6102. br.ErrMsg = "指标名称重复"
  6103. return
  6104. }
  6105. for k, v := range req.BatchList {
  6106. v.EdbName = strings.Trim(v.EdbName, " ")
  6107. v.EdbCode = strings.Trim(v.EdbCode, " ")
  6108. if v.Source <= 0 {
  6109. br.Msg = "无效的数据来源"
  6110. return
  6111. }
  6112. if v.EdbCode == "" {
  6113. br.Msg = "指标ID不能为空"
  6114. return
  6115. }
  6116. if v.EdbName == "" {
  6117. br.Msg = "指标名称不能为空"
  6118. return
  6119. }
  6120. if v.Frequency == "" {
  6121. br.Msg = "频率不能为空"
  6122. return
  6123. }
  6124. if v.ClassifyId <= 0 {
  6125. br.Msg = "请选择分类"
  6126. return
  6127. }
  6128. edbInfoItem := new(data_manage.EdbInfo)
  6129. edbInfoItem.Source = v.Source
  6130. edbInfoItem.SourceName = "SMM"
  6131. edbInfoItem.EdbCode = v.EdbCode
  6132. edbInfoItem.SubSource = 0
  6133. edbInfoItem.SubSourceName = ""
  6134. edbInfoItem.EdbName = v.EdbName
  6135. edbInfoItem.EdbNameSource = v.EdbName
  6136. edbInfoItem.EdbNameEn = v.EdbName
  6137. edbInfoItem.Frequency = v.Frequency
  6138. edbInfoItem.Unit = v.Unit
  6139. edbInfoItem.UnitEn = v.Unit
  6140. edbInfoItem.ClassifyId = v.ClassifyId
  6141. edbInfoItem.SysUserId = sysUser.AdminId
  6142. edbInfoItem.SysUserRealName = sysUser.RealName
  6143. edbInfoItem.IndicatorCode = ""
  6144. edbInfoItem.StockCode = ""
  6145. // 指标入库
  6146. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  6147. if err != nil {
  6148. br.Msg = "保存失败"
  6149. if errMsg != `` {
  6150. br.Msg = errMsg
  6151. }
  6152. br.ErrMsg = err.Error()
  6153. br.IsSendEmail = isSendEmail
  6154. return
  6155. }
  6156. //新增操作日志
  6157. {
  6158. edbLog := new(data_manage.EdbInfoLog)
  6159. edbLog.EdbInfoId = edbInfo.EdbInfoId
  6160. edbLog.SourceName = edbInfo.SourceName
  6161. edbLog.Source = edbInfo.Source
  6162. edbLog.EdbCode = edbInfo.EdbCode
  6163. edbLog.EdbName = edbInfo.EdbName
  6164. edbLog.ClassifyId = edbInfo.ClassifyId
  6165. edbLog.SysUserId = sysUser.AdminId
  6166. edbLog.SysUserRealName = sysUser.RealName
  6167. edbLog.CreateTime = time.Now()
  6168. edbLog.Content = string(this.Ctx.Input.RequestBody)
  6169. edbLog.Status = "新增指标"
  6170. edbLog.Method = this.Ctx.Input.URI()
  6171. go data_manage.AddEdbInfoLog(edbLog)
  6172. }
  6173. if k <= 0 {
  6174. resp.EdbInfoId = edbInfo.EdbInfoId
  6175. resp.UniqueCode = edbInfo.UniqueCode
  6176. }
  6177. }
  6178. br.Ret = 200
  6179. br.Success = true
  6180. br.Msg = "保存成功"
  6181. br.Data = resp
  6182. br.IsAddLog = true
  6183. }
  6184. // ChartImageSetBySvg
  6185. // @Title 设置指标的图表图片
  6186. // @Description 设置指标的图表图片接口
  6187. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  6188. // @Success Ret=200 保存成功
  6189. // @router /edb_info/image/set_by_svg [post]
  6190. func (this *EdbInfoController) ChartImageSetBySvg() {
  6191. br := new(models.BaseResponse).Init()
  6192. defer func() {
  6193. if br.ErrMsg == "" {
  6194. br.IsSendEmail = false
  6195. }
  6196. this.Data["json"] = br
  6197. this.ServeJSON()
  6198. }()
  6199. sysUser := this.SysUser
  6200. if sysUser == nil {
  6201. br.Msg = "请登录"
  6202. br.ErrMsg = "请登录,SysUser Is Empty"
  6203. br.Ret = 408
  6204. return
  6205. }
  6206. imgData := this.GetString("Img")
  6207. if imgData == "" {
  6208. br.Msg = "图片参数错误"
  6209. br.ErrMsg = "图片参数错误,Img Is Empty"
  6210. return
  6211. }
  6212. edbInfoId, _ := this.GetInt("EdbInfoId", 0)
  6213. if edbInfoId <= 0 {
  6214. br.Msg = "指标参数错误"
  6215. br.ErrMsg = "指标参数错误,EdbInfoId Is Empty"
  6216. return
  6217. }
  6218. // 通过svg图片生成图片资源地址
  6219. resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData)
  6220. if err != nil {
  6221. br.Msg = errMsg
  6222. br.ErrMsg = err.Error()
  6223. return
  6224. }
  6225. if edbInfoId <= 0 || resourceUrl == "" {
  6226. br.Ret = 200
  6227. br.Success = true
  6228. br.Msg = "保存成功"
  6229. return
  6230. }
  6231. edbInfo, e := data_manage.GetEdbInfoById(edbInfoId)
  6232. if e != nil {
  6233. if e.Error() == utils.ErrNoRow() {
  6234. br.Msg = "找不到该指标"
  6235. return
  6236. }
  6237. br.Msg = "保存失败"
  6238. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  6239. return
  6240. }
  6241. edbInfo.ChartImage = resourceUrl
  6242. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  6243. br.Msg = "保存失败"
  6244. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  6245. return
  6246. }
  6247. // 修改es数据
  6248. go data.AddOrEditEdbInfoToEs(edbInfoId)
  6249. br.Ret = 200
  6250. br.Success = true
  6251. br.Msg = "保存成功"
  6252. }
  6253. // ModifyChartList
  6254. // @Title 批量修改图表
  6255. // @Description 批量修改图表
  6256. // @Param SysUserIds query string true "根据创建人查询"
  6257. // @Param ChartClassifyIds query string true "图片分类id"
  6258. // @Success 200 {object} models.ChartClassifyListResp
  6259. // @router /modify/edbList [post]
  6260. func (this *EdbInfoController) ModifyEdbList() {
  6261. br := new(models.BaseResponse).Init()
  6262. defer func() {
  6263. this.Data["json"] = br
  6264. this.ServeJSON()
  6265. }()
  6266. sysUser := this.SysUser
  6267. if sysUser == nil {
  6268. br.Msg = "请登录"
  6269. br.ErrMsg = "请登录,SysUser Is Empty"
  6270. br.Ret = 408
  6271. return
  6272. }
  6273. var req request.ModifyEdbListReq
  6274. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  6275. if err != nil {
  6276. br.Msg = "参数解析异常!"
  6277. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  6278. return
  6279. }
  6280. classifyIds := strings.Split(req.EdbClassifyIds, ",")
  6281. if !req.SelectAll && req.EdbInfoIds == "" {
  6282. br.Msg = "请选择图表"
  6283. return
  6284. }
  6285. if req.ClassifyId < 0 {
  6286. br.Msg = "请选择新分类"
  6287. return
  6288. }
  6289. var condition string
  6290. var pars []interface{}
  6291. edbInfoIds := make([]int, 0)
  6292. if req.SelectAll {
  6293. // 已授权分类id
  6294. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  6295. if err != nil {
  6296. br.Msg = "获取失败"
  6297. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  6298. return
  6299. }
  6300. classifyIdsArr := make([]int, 0)
  6301. for _, v := range classifyIds {
  6302. if v != `` {
  6303. id, _ := strconv.Atoi(v)
  6304. classifyIdsArr = append(classifyIdsArr, id)
  6305. }
  6306. }
  6307. if len(permissionClassifyIdList) > 0 {
  6308. classifyIdsArr = utils.IntersectInt(permissionClassifyIdList, classifyIdsArr)
  6309. }
  6310. condition += " AND edb_info_type = 0 "
  6311. if len(classifyIdsArr) > 0 {
  6312. if !req.SubClassify {
  6313. condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(classifyIdsArr)) + ") "
  6314. pars = append(pars, classifyIdsArr)
  6315. } else {
  6316. classifyAll, err := data_manage.GetNormalEdbClassifyAll()
  6317. if err != nil && err.Error() != utils.ErrNoRow() {
  6318. br.Msg = "获取失败"
  6319. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6320. return
  6321. }
  6322. finalClassifyIds := make([]int, 0)
  6323. parents := data.GetEdbClassifyChildrenRecursiveByParentIds(classifyAll, classifyIds)
  6324. sort.Slice(parents, func(i, j int) bool {
  6325. return parents[i].Level < parents[i].Level
  6326. })
  6327. for _, v := range parents {
  6328. finalClassifyIds = append(finalClassifyIds, v.ClassifyId)
  6329. }
  6330. condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(finalClassifyIds)) + ") "
  6331. pars = append(pars, finalClassifyIds)
  6332. }
  6333. }
  6334. if req.KeyWord != "" {
  6335. condition += ` AND edb_name LIKE '%` + req.KeyWord + `%' `
  6336. }
  6337. if req.Sources != "" {
  6338. condition += " AND source IN(" + utils.GetOrmInReplace(len(strings.Split(req.Sources, ","))) + ") "
  6339. pars = append(pars, strings.Split(req.Sources, ","))
  6340. }
  6341. if req.SysUserIds != "" {
  6342. adminIds := strings.Split(req.SysUserIds, ",")
  6343. if len(adminIds) == 0 {
  6344. br.Msg = "请选择正确的创建人"
  6345. return
  6346. }
  6347. adminIdsSlice := make([]int, 0)
  6348. for _, adminId := range adminIds {
  6349. adminIdInt, e := strconv.Atoi(adminId)
  6350. if e != nil {
  6351. br.Msg = "请选择正确的创建人"
  6352. return
  6353. }
  6354. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  6355. }
  6356. condition += " AND sys_user_id in (" + utils.GetOrmInReplace(len(adminIds)) + ") "
  6357. pars = append(pars, adminIdsSlice)
  6358. }
  6359. // 获取当前账号的不可见指标
  6360. obj := data_manage.EdbInfoNoPermissionAdmin{}
  6361. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  6362. if err != nil && err.Error() != utils.ErrNoRow() {
  6363. br.Msg = "获取失败"
  6364. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  6365. return
  6366. }
  6367. noPermissionEdbInfoIds := make([]int, 0)
  6368. for _, v := range confList {
  6369. noPermissionEdbInfoIds = append(noPermissionEdbInfoIds, v.EdbInfoId)
  6370. }
  6371. if len(noPermissionEdbInfoIds) > 0 {
  6372. condition += " AND edb_info_id NOT IN(" + utils.GetOrmInReplace(len(noPermissionEdbInfoIds)) + ") "
  6373. pars = append(pars, noPermissionEdbInfoIds)
  6374. }
  6375. count, err := data_manage.GetEdbInfoByConditionCount(condition, pars)
  6376. if err != nil && err.Error() != utils.ErrNoRow() {
  6377. br.Msg = "获取失败"
  6378. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6379. return
  6380. }
  6381. if count > 100 {
  6382. br.Msg = "最多选择100个"
  6383. return
  6384. }
  6385. list, err := data_manage.GetEdbInfoListByCondition(condition, pars, 0, 0, "")
  6386. if err != nil && err.Error() != utils.ErrNoRow() {
  6387. br.Msg = "获取失败"
  6388. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6389. return
  6390. }
  6391. for _, v := range list {
  6392. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  6393. }
  6394. } else {
  6395. edbIds := strings.Split(req.EdbInfoIds, ",")
  6396. if len(edbIds) == 0 {
  6397. br.Msg = "请选择图表"
  6398. return
  6399. }
  6400. for _, id := range edbIds {
  6401. tmp, e := strconv.Atoi(id)
  6402. if e != nil {
  6403. br.Msg = "请选择正确的分类"
  6404. return
  6405. }
  6406. edbInfoIds = append(edbInfoIds, tmp)
  6407. }
  6408. if len(edbInfoIds) > 100 {
  6409. br.Msg = "最多只能选择100个图表"
  6410. return
  6411. }
  6412. }
  6413. err = data_manage.UpdateEdbClassifyIdByChartInfoId(edbInfoIds, req.ClassifyId)
  6414. if err != nil {
  6415. br.Msg = "更新失败"
  6416. br.ErrMsg = "更新图表分类失败,Err:" + err.Error()
  6417. return
  6418. }
  6419. br.Ret = 200
  6420. br.Success = true
  6421. br.Msg = "操作成功"
  6422. }