edb_info.go 195 KB

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