12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/company"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_manage/cross_variety"
- request2 "eta/eta_api/models/data_manage/excel/request"
- "eta/eta_api/models/data_manage/request"
- "eta/eta_api/models/data_manage/response"
- "eta/eta_api/models/system"
- "eta/eta_api/services"
- "eta/eta_api/services/alarm_msg"
- "eta/eta_api/services/data"
- "eta/eta_api/services/data/data_manage_permission"
- excel2 "eta/eta_api/services/data/excel"
- "eta/eta_api/services/data_stat"
- "eta/eta_api/services/elastic"
- etaTrialService "eta/eta_api/services/eta_trial"
- "eta/eta_api/utils"
- "fmt"
- "strconv"
- "strings"
- "sync"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // EdbInfoController 数据管理
- type EdbInfoController struct {
- controllers.BaseAuthController
- }
- // EdbInfoSearch
- // @Title 新增指标-查询指标信息接口
- // @Description 新增指标-查询指标信息接口
- // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
- // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
- // @Param EdbCode query string false "指标编码/指标代码"
- // @Param StockCode query string false "证券代码"
- // @Param Frequency query string false "频度"
- // @Success 200 {object} data_manage.EdbInfoSearchResp
- // @router /edb_info/search [get]
- func (this *EdbInfoController) EdbInfoSearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source, _ := this.GetInt("Source")
- edbCode := this.GetString("EdbCode")
- edbCode = strings.Trim(edbCode, "\t")
- edbCode = strings.Trim(edbCode, " ")
- edbCode = strings.Replace(edbCode, "\t", "", -1)
- subSource, _ := this.GetInt("SubSource")
- stockCode := this.GetString("StockCode")
- frequency := this.GetString("Frequency")
- extraPars := this.GetString("ExtraPars")
- extraPars = strings.TrimSpace(extraPars)
- if source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- if edbCode == "" {
- br.Msg = "请输入指标ID"
- return
- }
- //如果是彭博财务指标,那么需要传入客户code
- if source == utils.DATA_SOURCE_PB_FINANCE {
- companyCode := this.GetString("CompanyCode")
- companyCode = strings.Trim(companyCode, "\t")
- companyCode = strings.Trim(companyCode, " ")
- companyCode = strings.Replace(companyCode, "\t", "", -1)
- // 如果财务数据,那么需要拼接上客户code
- edbCode = companyCode + "&&" + edbCode
- }
- resp := new(data_manage.EdbInfoSearchResp)
- //判断指标是否存在
- var item *data_manage.EdbInfo
- var err error
- if utils.InArrayByInt([]int{utils.DATA_SOURCE_GL, utils.DATA_SOURCE_MYSTEEL_CHEMICAL}, source) {
- //source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- source, item, err = data.GetMySteelSourceByEdbCode(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- if item == nil {
- item, err = data_manage.GetEdbInfoByEdbCode(source, edbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- }
- var isAdd bool
- var isInEdb bool //是否在指标库中
- if item != nil && item.EdbInfoId > 0 {
- isInEdb = true //在指标库中
- resp.Status = 1
- searchItem := new(data_manage.EdbInfoSearch)
- searchItem.EdbCode = item.EdbCode
- searchItem.StartDate = item.StartDate
- searchItem.EndDate = item.EndDate
- searchItem.EdbName = item.EdbName
- resp.SearchItem = searchItem
- //查询目录
- resultList, _ := data_manage.GetClassifyAllByClassifyId(item.ClassifyId)
- resp.ClassifyList = resultList
- // 查询该指标是否有权限
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, item.EdbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
- return
- }
- if conf != nil {
- resp.Status = 3
- }
- } else {
- //dateNow := time.Now()
- //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDate)
- searchItem := new(data_manage.EdbInfoSearch)
- if source == utils.DATA_SOURCE_THS {
- fmt.Println("subSource:", subSource)
- if subSource == utils.DATA_SUB_SOURCE_EDB {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("ths len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("ths data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data.GetEdbDataByThs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if subSource == utils.DATA_SUB_SOURCE_DATE {
- if stockCode == "" {
- br.Msg = "请输入证券代码"
- return
- }
- if edbCode == "" {
- br.Msg = "请输入指标代码"
- return
- }
- respItem, err := data.AddEdbDataThsDs(source, stockCode, edbCode, extraPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- if respItem.Ret == 421 {
- br.Msg = "该渠道已超过添加上限"
- } else if respItem.Ret == 4052 {
- br.Msg = "该指标已下架"
- } else {
- br.Msg = "未搜索到该指标"
- }
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- } else {
- br.Msg = "无效的渠道来源"
- return
- }
- } else if source == utils.DATA_SOURCE_WIND {
- fmt.Println("subSource:", subSource)
- if subSource == utils.DATA_SUB_SOURCE_EDB {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_WIND, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Wind已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("wind dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataWindMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取wind日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.Format(utils.FormatDate)
- //searchItem, err = data.GetEdbDataByWind(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "wind 获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- if respItem.Ret == 421 {
- br.Msg = "该渠道已超过添加上限"
- } else if respItem.Ret == 4052 {
- br.Msg = "该指标已下架"
- } else {
- br.Msg = "未搜索到该指标"
- }
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if subSource == utils.DATA_SUB_SOURCE_DATE {
- if stockCode == "" {
- br.Msg = "请输入证券代码"
- return
- }
- if edbCode == "" {
- br.Msg = "请输入指标代码"
- return
- }
- respItem, err := data.AddEdbDataWindWsd(source, stockCode, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- if respItem.Ret == 421 {
- br.Msg = "该渠道已超过添加上限"
- } else if respItem.Ret == 4052 {
- br.Msg = "该指标已下架"
- } else {
- br.Msg = "未搜索到该指标"
- }
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- } else {
- br.Msg = "无效的渠道来源"
- return
- }
- } else if source == utils.DATA_SOURCE_PB || source == utils.DATA_SOURCE_PB_FINANCE {
- fmt.Println("pb data exist")
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Pb已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("pb dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Pb日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDateUnSpace)
- //searchItem, err = data.GetEdbDataByPb(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "彭博数据获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_MANUAL { //手工数据指标
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_MANUAL, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("ths len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("ths data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataManualMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByManual(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- manualInfo, err := models.GetEdbinfoByTradeCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
- return
- }
- if manualInfo != nil {
- searchItem.Frequency = manualInfo.Frequency
- searchItem.Unit = manualInfo.Unit
- searchItem.EdbName = manualInfo.SecName
- }
- } else if source == utils.DATA_SOURCE_LZ {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LZ, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("ths len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("ths data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataLzMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByLz(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取隆众数据失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- lzInfo, err := data_manage.GetLongzhongSurveyProductByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
- return
- }
- if lzInfo != nil {
- frequency := lzInfo.Frequency
- var frequencyStr string
- if frequency == 1 {
- frequencyStr = "日度"
- } else if frequency == 2 {
- frequencyStr = "周度"
- } else if frequency == 3 {
- frequencyStr = "月度"
- } else if frequency == 4 {
- frequencyStr = "季度"
- } else if frequency == 5 {
- frequencyStr = "年度"
- } else if frequency == 99 {
- frequencyStr = "无固定频率"
- }
- searchItem.Frequency = frequencyStr
- searchItem.Unit = lzInfo.UnitName
- searchItem.EdbName = lzInfo.SampleName + lzInfo.BreedName + lzInfo.QuotaName
- }
- } else if source == utils.DATA_SOURCE_YS { //有色网
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- smmInfo, err := data_manage.GetBaseFromSmmIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
- return
- }
- if smmInfo != nil {
- searchItem.Frequency = smmInfo.Frequency
- searchItem.Unit = smmInfo.Unit
- searchItem.EdbName = smmInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_GL { //钢联
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataGlMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- glInfo, err := data_manage.GetGlIndexByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if glInfo != nil {
- searchItem.Frequency = glInfo.FrequencyName
- searchItem.Unit = glInfo.UnitName
- searchItem.EdbName = glInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_ZZ { //郑商所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取郑商所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取郑商所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByZz(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByZz Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromZhengzhouByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取郑商所指标详情失败,Err:" + err.Error()
- return
- }
- var zzInfo *data_manage.BaseInfoFromZz
- if allInfo != nil {
- zzInfo = allInfo[0]
- }
- if zzInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = zzInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = zzInfo.BuyName
- } else {
- searchItem.EdbName = zzInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_DL { //大商所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取大商所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取大商所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByDl(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByDl Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromDalianByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取大商所指标详情失败,Err:" + err.Error()
- return
- }
- var dlInfo *data_manage.BaseInfoFromDl
- if allInfo != nil {
- dlInfo = allInfo[0]
- }
- if dlInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = dlInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = dlInfo.BuyName
- } else {
- searchItem.EdbName = dlInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_SH { //上期所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataBySh(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataBySh Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromShByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- var shInfo *data_manage.BaseInfoFromSh
- if allInfo != nil {
- shInfo = allInfo[0]
- }
- if shInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = shInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = shInfo.BuyName
- } else {
- searchItem.EdbName = shInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_CFFEX { //中金所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中金所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中金所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromCffexByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中金所指标详情失败,Err:" + err.Error()
- return
- }
- var cffexInfo *data_manage.BaseInfoFromCffex
- if allInfo != nil {
- cffexInfo = allInfo[0]
- }
- if cffexInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = cffexInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = cffexInfo.BuyName
- } else {
- searchItem.EdbName = cffexInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_SHFE { //上期能源
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期能源已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期能源日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByShfe(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByShfe Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromShfeByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期能源指标详情失败,Err:" + err.Error()
- return
- }
- var shfeInfo *data_manage.BaseInfoFromShfe
- if allInfo != nil {
- shfeInfo = allInfo[0]
- }
- if shfeInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = shfeInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = shfeInfo.BuyName
- } else {
- searchItem.EdbName = shfeInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_GIE { //欧洲天然气
- var suffix string
- l := len(edbCode)
- if strings.Contains(edbCode[l-2:], "GS") {
- suffix = "GS"
- } else if strings.Contains(edbCode[l-2:], "CF") {
- suffix = "CF"
- } else if strings.Contains(edbCode[l-1:], "T") {
- suffix = "T"
- } else if strings.Contains(edbCode[l-2:], "In") {
- suffix = "In"
- } else if strings.Contains(edbCode[l-3:], "Out") {
- suffix = "Out"
- } else if strings.Contains(edbCode[l-3:], "WGV") {
- suffix = "WGV"
- } else if strings.Contains(edbCode[l-2:], "IC") {
- suffix = "IC"
- } else if strings.Contains(edbCode[l-2:], "WC") {
- suffix = "WC"
- } else if strings.Contains(edbCode[l-1:], "F") {
- suffix = "F"
- } else if strings.Contains(edbCode[l-1:], "C") {
- suffix = "C"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取欧洲天然气已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取欧洲天然气日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByGie(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByGie Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseFromEicDataAllByIndexCodeV2(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取欧洲天然气指标详情失败,Err:" + err.Error()
- return
- }
- var eicInfo *data_manage.BaseFromTradeEicIndexV2
- if allInfo != nil {
- eicInfo = allInfo[0]
- }
- var name string
- if eicInfo != nil {
- searchItem.Frequency = "日度"
- if suffix == "GS" {
- name = eicInfo.Name + "_gas_in_storage"
- searchItem.EdbName = name
- searchItem.Unit = "TWh"
- } else if suffix == "C" {
- name = eicInfo.Name + "_consumption"
- searchItem.EdbName = name
- searchItem.Unit = "TWh"
- } else if suffix == "CF" {
- name = eicInfo.Name + "_consumption_full"
- searchItem.EdbName = name
- searchItem.Unit = "百分比"
- } else if suffix == "F" {
- name = eicInfo.Name + "_full"
- searchItem.EdbName = name
- searchItem.Unit = "百分比"
- } else if suffix == "T" {
- name = eicInfo.Name + "_trend"
- searchItem.EdbName = name
- searchItem.Unit = "百分比"
- } else if suffix == "In" {
- name = eicInfo.Name + "_injection"
- searchItem.EdbName = name
- searchItem.Unit = "GWH/d"
- } else if suffix == "Out" {
- name = eicInfo.Name + "_withdrawal"
- searchItem.EdbName = name
- searchItem.Unit = "GWH/d"
- } else if suffix == "WGV" {
- name = eicInfo.Name + "_working_gas_volume"
- searchItem.EdbName = name
- searchItem.Unit = "TWh"
- } else if suffix == "IC" {
- name = eicInfo.Name + "_injection_capacity"
- searchItem.EdbName = name
- searchItem.Unit = "GWh/d"
- } else if suffix == "WC" {
- name = eicInfo.Name + "_withdrawal_capacity"
- searchItem.EdbName = name
- searchItem.Unit = "GWh/d"
- }
- }
- } else if source == utils.DATA_SOURCE_LT {
- fmt.Println("lt data exist")
- if strings.Contains(edbCode, "=") {
- br.Msg = "暂不支持编码中含有=的指标"
- br.ErrMsg = "暂不支持编码中含有=的指标"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LT, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取 lt 已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("lt dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取lt日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
- searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
- } else {
- //endDate := dateNow.Format(utils.FormatDate)
- //searchItem, err = data.GetEdbDataByLt(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "lt 获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_COAL { //中国煤炭市场网
- var suffix string
- if strings.Contains(edbCode, "jsm") {
- suffix = "jsm_index"
- } else if strings.Contains(edbCode, "company") {
- suffix = "company_index"
- } else if strings.Contains(edbCode, "firm") {
- suffix = "firm_index"
- } else if strings.Contains(edbCode, "coastal") {
- suffix = "coastal_index"
- } else if strings.Contains(edbCode, "inland") {
- suffix = "inland_index"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataCoalMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromCoalByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网指标详情失败,Err:" + err.Error()
- return
- }
- var coalInfo *data_manage.BaseInfoFromCoal
- if allInfo != nil {
- coalInfo = allInfo[0]
- }
- if coalInfo != nil {
- searchItem.Frequency = coalInfo.Frequency
- searchItem.Unit = coalInfo.Unit
- searchItem.EdbName = coalInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_GOOGLE_TRAVEL { //谷歌出行数据
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
- return
- }
- if item != nil {
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- }
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL { //钢联化工
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataMysteelChemicalMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- glInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if glInfo != nil {
- searchItem.Frequency = glInfo.Frequency
- searchItem.Unit = glInfo.Unit
- searchItem.EdbName = glInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_EIA_STEO { //eia steo报告
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取eia steo日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- eiasteoInfo, err := data_manage.GetBaseFromEiaSteoIndexByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if eiasteoInfo != nil {
- searchItem.Frequency = eiasteoInfo.Frequency
- searchItem.Unit = eiasteoInfo.Unit
- searchItem.EdbName = eiasteoInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_COM_TRADE { // un数据源
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取联合国商品贸易数据已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取联合国商品贸易数据日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- eiasteoInfo, err := data_manage.GetComTradeIndex(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if eiasteoInfo != nil {
- //eiasteoInfo.
- if eiasteoInfo.Type <= 2 {
- searchItem.Frequency = `年度`
- } else {
- searchItem.Frequency = `月度`
- }
- if eiasteoInfo.Type == 1 || eiasteoInfo.Type == 3 {
- searchItem.Unit = "美元"
- } else {
- searchItem.Unit = "千克"
- }
- searchItem.EdbName = eiasteoInfo.Name
- }
- } else if source == utils.DATA_SOURCE_SCI { //卓创数据(红桃三)
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCI已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataSciMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCI日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- smmInfo, err := data_manage.GetBaseFromSciIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Sci指标详情失败,Err:" + err.Error()
- return
- }
- if smmInfo != nil {
- searchItem.Frequency = smmInfo.Frequency
- searchItem.Unit = smmInfo.Unit
- searchItem.EdbName = smmInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_BAIINFO { //百川盈孚
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取BAIINFO已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataBaiinfoMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取BAIINFO日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- baiInfo, err := data_manage.GetBaseFromBaiinfoIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Baiinfo指标详情失败,Err:" + err.Error()
- return
- }
- if baiInfo != nil {
- searchItem.Frequency = baiInfo.Frequency
- searchItem.Unit = baiInfo.Unit
- searchItem.EdbName = baiInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_NATIONAL_STATISTICS { // 国家统计局
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取国家统计局已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取国家统计局日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- nationalInfo, err := data_manage.GetBaseFromNationalStatisticsIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取国家统计局详情失败,Err:" + err.Error()
- return
- }
- if nationalInfo != nil {
- searchItem.Frequency = nationalInfo.Frequency
- searchItem.Unit = nationalInfo.Unit
- searchItem.EdbName = fmt.Sprintf("%s%s", nationalInfo.Reg, nationalInfo.IndexName)
- }
- } else if source == utils.DATA_SOURCE_FUBAO { //数宝
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_FUBAO, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Fubao已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("fubao len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("fubao data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataFubaoMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败," + respItem.Msg
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标," + respItem.Msg
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_GFEX { //广州期货交易所
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataGzMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- indexInfo, err := data_manage.GetBaseInfoFromGzByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- if indexInfo != nil {
- searchItem.Frequency = indexInfo.Frequency
- searchItem.Unit = indexInfo.Unit
- searchItem.EdbName = indexInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_ICPI { //消费者指数
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataIcpiMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- indexInfo, err := data_manage.GetBaseInfoFromIcpiByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- if indexInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "%"
- searchItem.EdbName = indexInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_BUSINESS { //自有数据
- indexObj := data_manage.BaseFromBusinessIndex{}
- indexInfo, err := indexObj.GetDetailByEdbCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取自有数据指标信息失败,Err:" + err.Error()
- return
- }
- _, tmpDataList, err := data.GetPageBaseBusinessIndexData(edbCode, 1, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取自有数据已存在信息失败,Err:" + err.Error()
- return
- }
- dataItems := make([]*data_manage.EdbInfoSearchData, 0)
- for _, v := range tmpDataList {
- dataItems = append(dataItems, &data_manage.EdbInfoSearchData{
- DataTime: v.DataTime,
- Value: v.Value,
- })
- }
- searchItem.EdbCode = edbCode
- searchItem.DataList = dataItems
- searchItem.StartDate = indexInfo.StartDate.Format(utils.FormatDate)
- searchItem.EndDate = indexInfo.EndDate.Format(utils.FormatDate)
- searchItem.Frequency = indexInfo.Frequency
- searchItem.Unit = indexInfo.Unit
- searchItem.EdbName = indexInfo.IndexName
- } else if source == utils.DATA_SOURCE_SCI99 { //卓创资讯
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataSci99MaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- indexInfo, err := data_manage.GetBaseInfoFromSci99ByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- if indexInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "元/吨"
- searchItem.EdbName = indexInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_SCI_HQ {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCIHQ已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataSciHqMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCIHQ日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- sciHqInfo, err := data_manage.GetSciHqIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SciHq指标详情失败,Err:" + err.Error()
- return
- }
- if sciHqInfo != nil {
- searchItem.Frequency = sciHqInfo.Frequency
- searchItem.Unit = sciHqInfo.Unit
- searchItem.EdbName = sciHqInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_OILCHEM { //隆众资讯
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众资讯已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataOilchemMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- indexInfo, err := data_manage.GetBaseInfoFromOilchemByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众资讯指标详情失败,Err:" + err.Error()
- return
- }
- if indexInfo != nil {
- searchItem.Frequency = indexInfo.Frequency
- searchItem.Unit = indexInfo.Unit
- searchItem.EdbName = indexInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_HISUGAR { //泛糖科技
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取泛糖科技已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataHisugarMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取泛糖科技日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- indexInfo, err := data_manage.GetBaseInfoFromHisugarByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取泛糖科技指标详情失败,Err:" + err.Error()
- return
- }
- if indexInfo != nil {
- searchItem.Frequency = indexInfo.Frequency
- searchItem.Unit = indexInfo.Unit
- searchItem.EdbName = indexInfo.IndexName
- }
- } else {
- // 代码中没有的来源那么从edb_source中找是否有对应的
- sourceItem := data_manage.EdbSourceIdMap[source]
- if sourceItem == nil {
- br.Msg = "无效指标来源"
- return
- }
- // 获取指标数据
- dataList, e := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标数据失败, Err: " + e.Error()
- return
- }
- if len(dataList) > 0 {
- searchItem.EdbCode = edbCode
- searchItem.DataList = dataList
- // 获取最大最小值
- edbInfoMaxAndMinInfo, e := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败, GetEdbInfoMaxAndMinInfo Err:" + e.Error()
- return
- }
- if edbInfoMaxAndMinInfo != nil {
- searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
- searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
- }
- } else {
- // 新增指标数据
- addRes, e := data.AddEdbData(source, edbCode, frequency)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + e.Error()
- return
- }
- if addRes == nil {
- br.Msg = "获取失败"
- br.ErrMsg = "新增指标数据失败, addRes nil"
- return
- }
- if addRes.Ret != 200 {
- br.Msg = "未搜索到该指标, " + addRes.Msg
- //br.ErrMsg = addRes.ErrMsg + ";EdbCode:" + edbCode
- br.Success = true
- return
- }
- isAdd = true
- }
- // 查询基本信息
- baseIndexInfo, tErr := data_manage.GetBaseIndexInfoByEdbCode(edbCode, source)
- if tErr == nil {
- searchItem.EdbName = baseIndexInfo.IndexName
- searchItem.Frequency = baseIndexInfo.Frequency
- searchItem.Unit = baseIndexInfo.Unit
- }
- // 指标来源于桥接服务: 桥接服务获取指标取频度信息等
- if sourceItem.BridgeFlag != "" {
- bridgeOb := data.InitBridgeOB(sourceItem.BridgeFlag)
- if bridgeOb != nil {
- var r data.GetIndexFromBridgeReq
- r.IndexCode = edbCode
- r.Source = sourceItem.EdbSourceId
- r.SourceExtend = sourceItem.SourceExtend
- r.IndexCodeRequired = sourceItem.EdbCodeRequired
- bridgeIndex, e := bridgeOb.GetIndex(r)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "桥接服务获取指标信息失败, Err: " + e.Error()
- return
- }
- searchItem.EdbName = bridgeIndex.IndexName
- searchItem.Frequency = bridgeIndex.Frequency
- searchItem.Unit = bridgeIndex.Unit
- }
- }
- }
- if isAdd {
- if subSource == utils.DATA_SUB_SOURCE_DATE {
- if source == utils.DATA_SOURCE_WIND {
- //wsdData := windWsdRespItem.Data
- //var buf bytes.Buffer
- //// 创建一个encoder并指定目标为buf
- //enc := gob.NewEncoder(&buf)
- //
- //// 将data编码到buf中
- //err = enc.Encode(wsdData)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error()
- // return
- //}
- //
- //wsdDataMap := make(map[string]map[string]interface{})
- //err = json.Unmarshal(buf.Bytes(), &wsdDataMap)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error()
- // return
- //}
- //
- //stockList := make([]*data_manage.StockInfo, 0)
- //
- //dataList := make([]*data_manage.EdbInfoSearchData, 0)
- //for wk, wv := range wsdDataMap {
- // for vk, vv := range wv {
- // wkInt, err := strconv.ParseInt(wk, 10, 64)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error()
- // return
- // }
- //
- // vk = strings.ToLower(vk)
- // wkInt = wkInt / 1000
- // t := time.Unix(wkInt, 0)
- // dateTime := t.Format(utils.FormatDate)
- // //saveVal := utils.SubFloatToString(val, 20)
- // if vv == nil {
- // continue
- // }
- // var saveVal string
- // switch vt := vv.(type) {
- // case int:
- // saveVal = strconv.Itoa(vt)
- // case float64:
- // saveVal = utils.SubFloatToFloatStr(vt, 20)
- // case string:
- // saveVal = vt
- // }
- //
- // dataItem := new(data_manage.EdbInfoSearchData)
- // dataItem.Value = saveVal
- // dataItem.DataTime = dateTime
- // dataList = append(dataList, dataItem)
- // if len(dataList) >= 10 {
- // break
- // }
- // }
- //}
- //searchItem.StockList = stockList
- stockList := make([]*data_manage.StockInfo, 0)
- edbCodeArr := strings.Split(edbCode, ",")
- for _, v := range edbCodeArr {
- indexCode := utils.WindDbWsd + stockCode + v
- dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
- return
- }
- stockInfo := new(data_manage.StockInfo)
- stockInfo.StockCode = stockCode
- stockInfo.EdbCode = v
- stockInfo.DataList = dataList
- stockList = append(stockList, stockInfo)
- }
- searchItem.StockList = stockList
- } else if source == utils.DATA_SOURCE_THS {
- stockList := make([]*data_manage.StockInfo, 0)
- edbCodeArr := strings.Split(edbCode, ",")
- for _, v := range edbCodeArr {
- indexCode := utils.ThsDs + stockCode + v
- dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
- return
- }
- stockInfo := new(data_manage.StockInfo)
- stockInfo.StockCode = stockCode
- stockInfo.EdbCode = v
- stockInfo.DataList = dataList
- stockList = append(stockList, stockInfo)
- }
- searchItem.StockList = stockList
- } else {
- br.Msg = "来源错误"
- br.ErrMsg = "来源错误"
- return
- }
- } else {
- dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
- return
- }
- searchItem.DataList = dataList
- edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
- return
- }
- searchItem.EdbCode = edbCode
- searchItem.DataList = dataList
- if edbInfoMaxAndMinInfo != nil {
- searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
- searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
- }
- //edb指标信息
- edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode)
- if edbInfoItem != nil {
- searchItem.EdbName = edbInfoItem.EdbName
- }
- }
- }
- resp.Status = 2
- resp.SearchItem = searchItem
- }
- //如果不在指标库中,且不是新增
- if !isInEdb && !isAdd {
- if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 {
- br.Msg = "目标指标无有效值,请重新搜索"
- br.Data = resp
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoList
- // @Title 指标列表接口
- // @Description 指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Success 200 {object} data_manage.EdbInfoListResp
- // @router /edb_info/list [get]
- func (this *EdbInfoController) EdbInfoList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoId, _ := this.GetInt("EdbInfoId")
- keyWord := this.GetString("KeyWord")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //if edbInfoId <= 0 && keyWord == "" {
- // br.Msg = "参数错误"
- // return
- //}
- // 指标类型,0:普通指标,1:预测指标
- condition += " AND edb_info_type=? "
- pars = append(pars, 0)
- if edbInfoId > 0 {
- condition += " AND edb_info_id=? "
- pars = append(pars, edbInfoId)
- // 获取当前账号的不可见指标配置
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
- return
- }
- if conf != nil {
- br.Msg = "无权限,请联系管理员"
- br.IsSendEmail = false
- return
- }
- }
- if keyWord != "" {
- condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
- //pars = append(pars, keyWord)
- //pars = append(pars, keyWord)
- }
- resp := new(data_manage.EdbInfoListResp)
- if condition == "" {
- item := new(data_manage.EdbInfoList)
- resp.Paging = page
- resp.Item = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- //获取指标信息
- edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
- item := new(data_manage.EdbInfoList)
- resp.Paging = page
- resp.Item = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- //获取英文频度
- edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
- // 获取是否供应商停更
- edbInfoItem.IsSupplierStop = data.GetIsSupplierStop(edbInfoItem.Source, edbInfoItem.EdbCode)
- //查询目录
- classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- // 权限校验
- {
- var currClassify *data_manage.EdbClassifyIdItems
- for _, v := range classifyList {
- if edbInfoItem.ClassifyId == v.ClassifyId {
- currClassify = v
- break
- }
- }
- if currClassify != nil {
- edbInfoItem.HaveOperaAuth, err = data_manage_permission.CheckEdbPermission(edbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfoItem.EdbInfoId, edbInfoItem.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- }
- // 按钮校验
- button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType, edbInfoItem.HaveOperaAuth)
- button.AddButton = false
- edbInfoItem.Button = button
- edbInfoItem.DataList = make([]*data_manage.EdbData, 0)
- // 如果有数据权限,那么就去获取指标数据
- if edbInfoItem.HaveOperaAuth {
- dataCount, dataList, err := data.GetPageData(edbInfoItem.EdbInfoId, edbInfoItem.Source, edbInfoItem.SubSource, "", startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- edbInfoItem.DataList = dataList
- }
- // 获取指标插入配置
- {
- edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if edbDataInsertConfig != nil {
- edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate)
- edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate)
- edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value
- }
- }
- //是否展示英文标识
- edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn)
- resp.Paging = page
- resp.Item = edbInfoItem
- resp.ClassifyList = classifyList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoAdd
- // @Title 新增指标接口
- // @Description 新增指标接口
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/add [post]
- func (this *EdbInfoController) EdbInfoAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req data_manage.AddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- source := req.Source
- if source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- req.EdbCode = strings.Trim(req.EdbCode, " ")
- if req.EdbCode == "" {
- br.Msg = "指标ID不能为空"
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if req.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if req.Unit == "" {
- br.Msg = "单位不能为空"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- //if req.StartDate == "" || req.EndDate == "" {
- // br.Msg = "日期不能为空"
- // return
- //}
- // 兼容钢联与钢联化工数据
- if utils.InArrayByInt([]int{utils.DATA_SOURCE_GL, utils.DATA_SOURCE_MYSTEEL_CHEMICAL}, source) {
- // 如果是钢联的话,那么就先判断是不是存在钢联化工
- tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- if tmpInfo != nil {
- source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- req.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- } else {
- source = utils.DATA_SOURCE_GL
- req.Source = utils.DATA_SOURCE_GL
- }
- }
- // 指标入库
- 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)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- // 试用平台更新用户累计新增指标数
- adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
- return
- }
- if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
- go func() {
- var r etaTrialService.EtaTrialUserReq
- r.Mobile = adminItem.Mobile
- _, _ = etaTrialService.UpdateUserIndexNum(r)
- }()
- }
- //新增操作日志
- {
- // 添加钢联指标更新日志
- if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
- }
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- // 更新es
- go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
- resp := new(data_manage.AddEdbInfoResp)
- resp.EdbInfoId = edbInfo.EdbInfoId
- resp.UniqueCode = edbInfo.UniqueCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // EdbInfoEdit
- // @Title 编辑指标接口
- // @Description 编辑指标接口
- // @Success 200 {object} data_manage.EditEdbInfoReq
- // @router /edb_info/edit [post]
- func (this *EdbInfoController) EdbInfoEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.EditEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if req.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if req.Unit == "" {
- br.Msg = "单位不能为空"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- // 记录旧的指标基本信息
- oldEdbName := edbInfo.EdbName
- oldFrequency := edbInfo.Frequency
- oldUnit := edbInfo.Unit
- var haveOperaAuth bool
- // 权限校验
- {
- haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- // 编辑权限校验
- button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无权限操作"
- br.IsSendEmail = false
- return
- }
- //判断指标名称是否存在
- var condition string
- var pars []interface{}
- condition += " AND edb_info_id<>? "
- pars = append(pars, req.EdbInfoId)
- //condition += " AND source=? "
- //pars = append(pars, edbInfo.Source)
- updateCols := make([]string, 0)
- switch this.Lang {
- case utils.EnLangVersion:
- condition += " AND edb_name_en = ? "
- edbInfo.EdbNameEn = req.EdbName
- edbInfo.Frequency = req.Frequency
- edbInfo.UnitEn = req.Unit
- edbInfo.ClassifyId = req.ClassifyId
- updateCols = append(updateCols, "EdbNameEn", "Frequency", "UnitEn", "ClassifyId")
- default:
- condition += " AND edb_name=? "
- edbInfo.EdbName = req.EdbName
- edbInfo.EdbNameSource = req.EdbName
- edbInfo.Frequency = req.Frequency
- edbInfo.Unit = req.Unit
- edbInfo.ClassifyId = req.ClassifyId
- updateCols = append(updateCols, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId")
- }
- pars = append(pars, req.EdbName)
- count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "判断指标名称是否存在失败"
- br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "指标名称已存在,请重新填写"
- br.ErrMsg = "指标名称已存在,请重新填写"
- br.IsSendEmail = false
- return
- }
- if len(updateCols) > 0 {
- err = edbInfo.Update(updateCols)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- //处理同名指标
- //{
- // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName)
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- // return
- // }
- // if len(edbNameList) >= 2 {
- // for _, v := range edbNameList {
- // edbName := v.EdbName + "(" + v.SourceName + ")"
- // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "修改指标名称失败,Err:" + err.Error()
- // return
- // }
- // }
- // }
- //}
- // 新增保存记录日志
- oldEdbInfo := new(data_manage.EdbInfo)
- oldEdbInfo.EdbInfoId = edbInfo.EdbInfoId
- oldEdbInfo.EdbName = oldEdbName
- oldEdbInfo.Frequency = oldFrequency
- oldEdbInfo.Unit = oldUnit
- newEdbInfoRecord := new(data_manage.EdbInfoEditRecord)
- newEdbInfoRecord.EdbName = req.EdbName
- newEdbInfoRecord.Frequency = req.Frequency
- newEdbInfoRecord.Unit = req.Unit
- newEdbInfoRecord.OperateUserId = sysUser.AdminId
- newEdbInfoRecord.OperateUserRealName = sysUser.RealName
- go data.AddEditEdbInfoRcord(oldEdbInfo, newEdbInfoRecord)
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- switch this.Lang {
- case utils.EnLangVersion:
- // 修改关联的预测指标基础信息
- go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
- default:
- // 修改关联的预测指标基础信息
- go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, req.Frequency, req.Unit)
- }
- // 添加钢联指标更新日志
- if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- if edbInfo.EdbName != req.EdbName || edbInfo.Frequency != req.Frequency || edbInfo.Unit != req.Unit {
- go data_stat.AddEdbInfoUpdateLog(req.EdbInfoId, 1, "", sysUser, 1)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // EdbEnInfoEdit
- // @Title 编辑指标英文信息接口
- // @Description 编辑指标英文信息接口
- // @Success 200 {object} data_manage.EditEdbEnInfoReq
- // @router /edb_info/en/edit [post]
- func (this *EdbInfoController) EdbEnInfoEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.EditEdbEnInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbNameEn = strings.Trim(req.EdbNameEn, " ")
- req.UnitEn = strings.Trim(req.UnitEn, " ")
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if req.EdbNameEn != "" {
- //判断指标名称是否存在
- var condition string
- var pars []interface{}
- condition += " AND edb_info_id<>? "
- pars = append(pars, req.EdbInfoId)
- /*condition += " AND source=? "
- pars = append(pars, edbInfo.Source)*/
- condition += " AND edb_name_en=? "
- pars = append(pars, req.EdbNameEn)
- edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "判断英文指标名称是否存在失败"
- br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
- return
- }
- }
- if err == nil && edbExist.EdbInfoId > 0 {
- br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在"
- br.ErrMsg = "英文指标名称已存在,请重新填写"
- br.IsSendEmail = false
- return
- }
- }
- err = data_manage.ModifyEdbEnInfo(&req)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑指标英文信息"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- // 修改关联的预测指标基础信息
- if edbInfo.EdbInfoType == 0 {
- go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.UnitEn)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // EdbInfoBaseEdit
- // @Title 编辑指标基础信息接口
- // @Description 编辑指标基础信息接口
- // @Success 200 {object} data_manage.EditEdbBaseInfoReq
- // @router /edb_info/base/edit [post]
- func (this *EdbInfoController) EdbInfoBaseEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.EditEdbBaseInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- req.Unit = strings.Trim(req.Unit, " ")
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- updateCols := make([]string, 0)
- if req.EdbName != "" {
- //判断指标名称是否存在
- var condition string
- var pars []interface{}
- condition += " AND edb_info_id<>? "
- pars = append(pars, req.EdbInfoId)
- /*condition += " AND source=? "
- pars = append(pars, edbInfo.Source)*/
- switch this.Lang {
- case utils.EnLangVersion:
- condition += " AND edb_name_en = ? "
- edbInfo.EdbNameEn = req.EdbName
- edbInfo.UnitEn = req.Unit
- edbInfo.ModifyTime = time.Now()
- updateCols = append(updateCols, "EdbNameEn", "UnitEn", "ModifyTime")
- default:
- condition += " AND edb_name = ? "
- edbInfo.EdbName = req.EdbName
- edbInfo.EdbNameSource = req.EdbName
- edbInfo.Unit = req.Unit
- edbInfo.ModifyTime = time.Now()
- updateCols = append(updateCols, "EdbName", "EdbNameSource", "Unit", "ModifyTime")
- }
- pars = append(pars, req.EdbName)
- edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "判断英文指标名称是否存在失败"
- br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
- return
- }
- }
- if err == nil && edbExist.EdbInfoId > 0 {
- br.Msg = edbExist.EdbName + ":" + req.EdbName + "指标名称已存在"
- br.ErrMsg = "英文指标名称已存在,请重新填写"
- br.IsSendEmail = false
- return
- }
- }
- if len(updateCols) > 0 {
- err = edbInfo.Update(updateCols)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑指标英文信息"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- // 修改关联的预测指标基础信息
- if edbInfo.EdbInfoType == 0 {
- switch this.Lang {
- case utils.EnLangVersion:
- go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
- default:
- go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, edbInfo.Frequency, req.Unit)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // EdbInfoNewest
- // @Title 获取最新指标接口
- // @Description 获取最新指标接口
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/newest [get]
- func (this *EdbInfoController) EdbInfoNewest() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- item, err := data_manage.GetEdbInfoByNewest()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取最新指标失败"
- br.ErrMsg = "获取最新指标失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = item
- }
- // EdbInfoRefresh
- // @Title 指标刷新接口
- // @Description 指标刷新接口
- // @Param EdbInfoId query int true "指标id"
- // @Success Ret=200 刷新成功
- // @router /edb_info/refresh [get]
- func (this *EdbInfoController) EdbInfoRefresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- _, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "数据已被删除,请刷新页面"
- br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
- return
- }
- br.Msg = "刷新失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false, false)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Msg = "刷新成功"
- if isAsync {
- br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
- }
- br.Success = true
- br.IsAddLog = true
- }
- // EdbInfoMove
- // @Title 移动指标接口
- // @Description 移动指标接口
- // @Success 200 {object} data_manage.MoveEdbInfoReq
- // @router /edb_info/move [post]
- func (this *EdbInfoController) EdbInfoMove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.MoveEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- //判断分类是否存在
- count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId)
- if count <= 0 {
- br.Msg = "分类已被删除,不可移动,请刷新页面"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- var haveOperaAuth bool
- // 权限校验
- {
- haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.IsJoinPermission, edbInfo.EdbInfoId, edbInfo.ClassifyId, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- // 移动权限校验
- button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
- if !button.MoveButton {
- br.Msg = "无权限操作"
- br.IsSendEmail = false
- return
- }
- //如果改变了分类,那么移动该指标数据
- if edbInfo.ClassifyId != req.ClassifyId {
- err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "移动指标失败,Err:" + err.Error()
- return
- }
- }
- updateCol := make([]string, 0)
- //如果有传入 上一个兄弟节点分类id
- if req.PrevEdbInfoId > 0 {
- prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextEdbInfoId > 0 {
- //下一个兄弟节点
- nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
- if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
- } else {
- //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
- if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
- }
- }
- }
- edbInfo.Sort = prevEdbInfo.Sort + 1
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "移动失败"
- br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
- return
- }
- //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
- if firstClassify != nil && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr)
- }
- edbInfo.Sort = 0 //那就是排在第一位
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- //更新
- if len(updateCol) > 0 {
- err = edbInfo.Update(updateCol)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- }
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "移动指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- }
- // EdbInfoDetail
- // @Title 获取指标详情
- // @Description 获取指标详情接口
- // @Param EdbInfoId query int true "指标id"
- // @Success 200 {object} data_manage.EdbInfo
- // @router /edb_info/detail [get]
- func (this *EdbInfoController) EdbInfoDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- var resp data_manage.EdbInfoFullClassify
- classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- // 权限校验
- {
- classifyMap := make(map[int]*data_manage.EdbClassifyIdItems)
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- if currClassify, ok := classifyMap[edbInfo.ClassifyId]; ok {
- haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- resp.HaveOperaAuth = haveOperaAuth
- }
- }
- resp.EdbInfo = edbInfo
- resp.ClassifyList = classifyList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoFilter
- // @Title 指标筛选接口
- // @Description 指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/filter [get]
- func (this *EdbInfoController) EdbInfoFilter() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- var pars []interface{}
- noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
- // 获取当前账号的不可见指标
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- }
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- if keyWord != "" {
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- }
- //var err error
- edbInfoList := make([]*data_manage.EdbInfoList, 0)
- //if keyWord == "" {
- // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Success = true
- // br.Msg = "获取指标信息失败"
- // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- // return
- // }
- //} else {
- // //获取指标信息
- // indexName := utils.DATA_INDEX_NAME
- // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Success = true
- // br.Msg = "获取指标信息失败"
- // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- // return
- // }
- //}
- var baseCondition string
- // 无权限指标id
- lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
- if lenNoPermissionEdbInfoIdList > 0 {
- baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- existMap := make(map[int]string)
- for _, v := range keyWordArr {
- v = strings.Replace(v, " ", "%", -1)
- var condition string
- if filterSource == 2 {
- condition += ` AND frequency='月度' `
- }
- if filterSource == 3 {
- condition += ` AND frequency <> '日度' `
- }
- if filterSource == 4 {
- condition += ` AND edb_type = 1 `
- }
- conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
- condition += conditionWhere + baseCondition
- newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- for _, nv := range newEdbInfoList {
- if _, ok := existMap[nv.EdbInfoId]; !ok {
- edbInfoList = append(edbInfoList, nv)
- }
- existMap[nv.EdbInfoId] = nv.EdbCode
- }
- }
- if edbInfoList == nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- edbInfoListLen := len(edbInfoList)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = edbInfoList
- }
- // EdbInfoFilterByEs
- // @Title 指标筛选接口
- // @Description 指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
- // @Param Frequency query string false "频度"
- // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/filter_by_es [get]
- func (this *EdbInfoController) EdbInfoFilterByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int64
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- //指标来源
- source, _ := this.GetInt("Source")
- frequency := this.GetString("Frequency") //频度
- isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
- var edbInfoList []*data_manage.EdbInfoList
- var err error
- noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
- // 获取当前账号的不可见指标
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- }
- // 是否走ES
- isEs := false
- if keyWord != "" {
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- // 普通的搜索
- if !isAddPredictEdb {
- total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
- } else {
- // 允许添加预测指标的搜索
- total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize)
- }
- isEs = true
- } else {
- var condition string
- var pars []interface{}
- // 普通指标
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 0)
- // 无权限指标id
- lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
- if lenNoPermissionEdbInfoIdList > 0 {
- condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- switch filterSource {
- case 2:
- condition += ` AND frequency='月度' `
- case 3:
- condition += ` AND frequency <> '日度' `
- case 4:
- condition += ` AND edb_type = 1 `
- case 5:
- condition += ` AND source = 6 ` //来源(同比值)
- case 6:
- condition += ` AND frequency != ? `
- pars = append(pars, "年度")
- }
- //频度
- if frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, frequency)
- }
- if source > 0 && filterSource != 5 {
- condition += ` AND source = ? `
- pars = append(pars, source)
- }
- // 查询只允许添加预测指标的搜索
- if isAddPredictEdb {
- condition += ` AND frequency in ("日度","周度","月度") `
- }
- total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
- }
- if err != nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- edbInfoListLen := len(edbInfoList)
- classifyIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
- }
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.EdbClassify)
- if edbInfoListLen > 0 {
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
- if isEs {
- edbInfoIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
- tmpEdbInfo := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
- return
- }
- edbInfoMap := make(map[int]*data_manage.EdbInfo)
- for _, v := range tmpEdbList {
- edbInfoMap[v.EdbInfoId] = v
- }
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
- if !ok {
- continue
- }
- edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
- }
- }
- // 权限校验
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfoItem := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- resp := data_manage.EdbInfoFilterDataResp{
- Paging: page,
- List: edbInfoList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *EdbInfoController) EdbInfoFilter2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- var pars []interface{}
- //if keyWord != "" {
- // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
- //}
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- if keyWord != "" {
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- }
- keywordLen := len(keyWordArr)
- ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen)
- searchWait := sync.WaitGroup{}
- searchWait.Add(keywordLen)
- for index, v := range keyWordArr {
- v = strings.Replace(v, " ", "%", -1)
- var condition string
- if filterSource == 2 {
- condition += ` AND frequency='月度' `
- }
- if filterSource == 3 {
- condition += ` AND frequency <> '日度' `
- }
- if filterSource == 4 {
- condition += ` AND edb_type = 1 `
- }
- conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
- condition += conditionWhere
- go searchEdbInfoFilter(condition, pars, index, ch, &searchWait)
- }
- searchWait.Wait()
- newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList)
- i := 0
- for tmpEdbInfoList := range ch {
- i++
- for k, v := range tmpEdbInfoList {
- newEdbInfoListMap[k] = v
- }
- if i == keywordLen {
- break
- }
- }
- close(ch)
- edbInfoList := make([]*data_manage.EdbInfoList, 0)
- existMap := make(map[int]string)
- for i := 0; i < keywordLen; i++ {
- if newEdbInfoList, ok := newEdbInfoListMap[i]; ok {
- for _, nv := range newEdbInfoList {
- if _, ok := existMap[nv.EdbInfoId]; !ok {
- edbInfoList = append(edbInfoList, nv)
- }
- existMap[nv.EdbInfoId] = nv.EdbCode
- }
- }
- }
- if edbInfoList == nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- edbInfoListLen := len(edbInfoList)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = edbInfoList
- }
- 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) {
- newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList)
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
- }
- ch <- newEdbInfoListMap
- searchWait.Done()
- }()
- newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
- newEdbInfoListMap[i] = newEdbInfoList
- return
- }
- // EdbInfoAllRefresh
- // @Title 指标全部刷新接口
- // @Description 指标全部刷新接口
- // @Param EdbInfoId query int true "指标id"
- // @Success Ret=200 全部刷新成功
- // @router /edb_info/refresh/all [get]
- func (this *EdbInfoController) EdbInfoAllRefresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "数据已被删除,请刷新页面"
- br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
- return
- }
- br.Msg = "刷新失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if edbInfo == nil {
- br.Msg = "数据已被删除,请刷新页面"
- br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
- return
- }
- err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true, false)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- if isAsync {
- br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
- }
- }
- // EdbInfoData
- // @Title 获取指标数据
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/data [get]
- func (this *ChartInfoController) EdbInfoData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- fullEdb := new(data_manage.EdbInfoFullClassify)
- resp := new(data_manage.EdbInfoDataFullClassifyResp)
- dataList := make([]*data_manage.EdbDataList, 0)
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- return
- }
- dateType, _ := this.GetInt("DateType")
- if dateType <= 0 {
- dateType = 3
- }
- edbInfoType, _ := this.GetInt("EdbInfoType")
- if edbInfoType < 0 {
- edbInfoType = 1
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- startYear, _ := this.GetInt("StartYear")
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Ret = 200
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- // 分类
- classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- fullEdb.EdbInfo = edbInfo
- // 是否供应商停更
- fullEdb.IsSupplierStop = data.GetIsSupplierStop(edbInfo.Source, edbInfo.EdbCode)
- fullEdb.ClassifyList = classifyList
- var currClassifyItem *data_manage.EdbClassifyIdItems
- for _, v := range classifyList {
- if v.ClassifyId == edbInfo.ClassifyId {
- currClassifyItem = v
- }
- }
- if currClassifyItem != nil {
- haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassifyItem.IsJoinPermission, sysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- fullEdb.HaveOperaAuth = haveOperaAuth
- }
- resp.EdbInfo = fullEdb
- resp.DataList = make([]*data_manage.EdbDataList, 0)
- // 数据获取
- if fullEdb.HaveOperaAuth { // 有权限才获取数据
- maxYear := 0
- if edbInfo.LatestDate != "" {
- latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
- maxYear = latestDateT.Year()
- }
- startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
- dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp.DataList = dataList
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoReplaceCheck
- // @Title 指标一键刷新接口
- // @Description 指标一键刷新接口
- // @Success Ret=200 更新成功
- // @router /edb_info/replace/check [post]
- func (this *EdbInfoController) EdbInfoReplaceCheck() {
- br := new(models.BaseResponse).Init()
- setNxKey := "EDB_INFO_REPLACE"
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- status := 0
- if utils.Rc.IsExist(setNxKey) {
- status = 1
- } else {
- status = 2
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "检测成功"
- br.Data = status
- }
- // EdbInfoReplace
- // @Title 替换指标
- // @Description 替换指标
- // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/replace [post]
- func (this *ChartInfoController) EdbInfoReplace() {
- br := new(models.BaseResponse).Init()
- setNxKey := "EDB_INFO_REPLACE"
- deleteCache := true
- defer func() {
- if deleteCache {
- utils.Rc.Delete(setNxKey)
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
- deleteCache = false
- br.Msg = "当前正在替换中,请耐心等待!"
- br.IsSendEmail = false
- return
- }
- var req data_manage.EdbInfoReplaceReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "参数错误,指标id为0"
- return
- }
- oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
- if err != nil {
- br.Msg = "替换失败!"
- br.ErrMsg = "获取原指标失败,Err:" + err.Error()
- return
- }
- newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
- if err != nil {
- br.Msg = "替换失败!"
- br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
- return
- }
- //if oldEdbInfo.EdbType != 1 {
- // br.Msg = "原指标为计算指标,不可替换!"
- // br.ErrMsg = "原指标为计算指标,不可替换!"
- // return
- //}
- //
- //if newEdbInfo.EdbType != 1 {
- // br.Msg = "替换指标为计算指标,不可替换!"
- // br.ErrMsg = "替换指标为计算指标,不可替换!"
- // return
- //}
- if oldEdbInfo.Frequency != newEdbInfo.Frequency {
- br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
- br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
- return
- }
- sysAdminId := sysUser.AdminId
- //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
- _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
- //msgContent := ``
- if err != nil {
- br.Msg = "替换失败"
- br.ErrMsg = "替换失败 replace err:" + err.Error()
- return
- }
- br.Msg = "替换成功"
- br.ErrMsg = "替换成功"
- br.Ret = 200
- br.IsAddLog = true
- return
- }
- // RelationChartList
- // @Title 获取ETA指标关联的图表列表接口
- // @Description 获取ETA指标关联的图表列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/relation/chart_list [get]
- func (this *EdbInfoController) RelationChartList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- resp := data_manage.ChartListResp{}
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- /*// 关联指标
- condition += ` AND b.edb_info_id = ? `
- pars = append(pars, edbInfoId)*/
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- if isShowMe {
- condition += ` AND a.sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- chartIds := make([]int, 0)
- chartIdMap := make(map[int]bool)
- // 查询指标绑定的图表
- edbListTemp, err := data_manage.GetEdbMappingListByEdbInfoId(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- for _, v := range edbListTemp {
- if _, ok := chartIdMap[v.ChartInfoId]; !ok {
- chartIdMap[v.ChartInfoId] = true
- }
- }
- // 查询相关性的图表
- correlationChart := new(data_manage.ChartInfoCorrelation)
- correlationChartId, err := correlationChart.GetChartInfoIdByEdb(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if correlationChartId > 0 {
- chartIdMap[correlationChartId] = true
- }
- // 查询跨品种的图表
- tagXList, err := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- for _, v := range tagXList {
- if _, ok := chartIdMap[v.ChartInfoId]; !ok {
- chartIdMap[v.ChartInfoId] = true
- }
- }
- tagYList, err := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- for _, v := range tagYList {
- if _, ok := chartIdMap[v.ChartInfoId]; !ok {
- chartIdMap[v.ChartInfoId] = true
- }
- }
- // 获取当前账号的不可见图表
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- if _, ok := chartIdMap[v.ChartInfoId]; ok {
- delete(chartIdMap, v.ChartInfoId)
- }
- }
- }
- for k, _ := range chartIdMap {
- chartIds = append(chartIds, k)
- }
- // 关联指标
- if len(chartIds) > 0 {
- condition += ` AND a.chart_info_id in (` + utils.GetOrmInReplace(len(chartIds)) + `)`
- pars = append(pars, chartIds)
- } else {
- items := make([]*data_manage.ChartInfoView, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 得到图表ID
- //获取关联图表列表
- list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.ChartInfoView, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 获取关联图表总数
- dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- // 获取MY ETA 图表,用来判断是否加入我的图库
- myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
- return
- }
- myChartMap := make(map[int]*data_manage.MyChartView)
- for _, v := range myChartList {
- myChartMap[v.ChartInfoId] = v
- }
- listLen := len(list)
- if listLen > 0 {
- // 分类id
- classifyIdList := make([]int, 0)
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.ChartClassify)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ChartClassifyId)
- }
- classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ChartClassifyId] = v
- }
- // 已授权分类id
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- if existItem, ok := myChartMap[v.ChartInfoId]; ok {
- v.IsAdd = true
- v.MyChartId = existItem.MyChartId
- v.MyChartClassifyId = existItem.MyChartClassifyId
- }
- // 权限
- if currClassify, ok := classifyMap[v.ChartClassifyId]; ok {
- v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- }
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // RelationEdbList
- // @Title 获取ETA指标关联的指标列表接口
- // @Description 获取ETA指标关联的指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/relation/edbinfo_list [get]
- func (this *EdbInfoController) RelationEdbList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- resp := data_manage.RelationEdbInfoListResp{}
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- // 关联指标
- condition += ` AND b.from_edb_info_id = ? `
- pars = append(pars, edbInfoId)
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- if isShowMe {
- condition += ` AND a.sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- // 获取当前账号的不可见图表
- noPermissionEdbIdList := make([]int, 0)
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
- }
- }
- noPermissionEdbIdNum := len(noPermissionEdbIdList)
- if noPermissionEdbIdNum > 0 {
- condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
- pars = append(pars, noPermissionEdbIdList)
- }
- //获取关联图表列表
- list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.ChartEdbInfoMapping, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 获取关联图表总数
- dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
- if len(list) > 0 {
- // 当前的分类
- classifyMap := make(map[int]*data_manage.EdbClassify)
- {
- classifyIdList := make([]int, 0)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ClassifyId)
- }
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- item := new(data_manage.ChartEdbInfoMapping)
- item.EdbInfoId = v.EdbInfoId
- item.SourceName = v.SourceName
- item.Source = v.Source
- item.EdbCode = v.EdbCode
- item.EdbName = v.EdbName
- item.EdbNameEn = v.EdbNameEn
- item.Frequency = v.Frequency
- item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
- if v.Unit != `无` {
- item.Unit = v.Unit
- }
- item.UnitEn = v.UnitEn
- item.StartDate = v.StartDate
- item.EndDate = v.EndDate
- item.ModifyTime = v.ModifyTime
- item.IsAxis = 1
- item.LeadValue = 0
- item.LeadUnit = ""
- item.ChartEdbMappingId = 0
- item.ChartInfoId = 0
- item.IsOrder = false
- item.EdbInfoType = v.EdbInfoType
- item.EdbInfoCategoryType = v.EdbInfoType
- item.ChartStyle = ""
- item.ChartColor = ""
- item.ChartWidth = 0
- item.MaxData = v.MaxValue
- item.MinData = v.MinValue
- item.LatestValue = v.LatestValue
- item.LatestDate = v.LatestDate
- item.UniqueCode = v.UniqueCode
- item.ClassifyId = v.ClassifyId
- dataList := make([]*data_manage.EdbDataList, 0)
- // 指标权限
- if currClassify, ok := classifyMap[v.ClassifyId]; ok {
- item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- // 有权限则获取数据
- if item.HaveOperaAuth {
- if v.EdbInfoType == 0 {
- dataList, err = data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, "", "")
- } else {
- _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
- }
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- }
- item.DataList = dataList
- edbList = append(edbList, item)
- }
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- resp.Paging = page
- resp.List = edbList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoDataTb
- // @Title 获取指标数据同比值
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/data/tb [get]
- func (this *ChartInfoController) EdbInfoDataTb() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- return
- }
- dateType, _ := this.GetInt("DateType")
- if dateType <= 0 {
- dateType = 3
- }
- edbInfoType, _ := this.GetInt("EdbInfoType")
- if edbInfoType < 0 {
- edbInfoType = 1
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- startYear, _ := this.GetInt("StartYear")
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- maxYear := 0
- if edbInfo.LatestDate != "" {
- latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
- maxYear = latestDateT.Year()
- }
- startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
- var startDateTime time.Time
- if startDate != `` {
- startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- if err != nil {
- br.Msg = "开始日期异常"
- br.Msg = "开始日期异常,Err:" + err.Error()
- return
- }
- //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
- startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
- }
- tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- // 计算同比值
- dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "计算同比值失败,Err:" + err.Error()
- return
- }
- edbInfo.MaxValue = maxValue
- edbInfo.MinValue = minValue
- resp := new(data_manage.EdbInfoDataResp)
- resp.EdbInfo = edbInfo
- resp.DataList = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoDataSeasonal
- // @Title 获取指标数据(季节性)
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Param Calendar query string true "公历/农历"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/data/seasonal [get]
- func (this *ChartInfoController) EdbInfoDataSeasonal() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dateType, _ := this.GetInt("DateType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- startYear, _ := this.GetInt("StartYear")
- edbInfoIdStr := this.GetString("EdbInfoId")
- edbInfoId, err := strconv.Atoi(edbInfoIdStr)
- if err != nil {
- br.Msg = "指标id异常"
- br.Msg = "指标id转换异常,Err:" + err.Error()
- return
- }
- fmt.Println("startDate:", startDate)
- fmt.Println("endDate:", endDate)
- calendar := this.GetString("Calendar")
- if calendar == "" {
- calendar = "公历"
- }
- if dateType == 0 {
- if startDate == "" {
- dateType = utils.DateTypeNYears
- } else {
- dateType = 5
- }
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- maxYear := 0
- if edbInfo.LatestDate != "" {
- latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
- maxYear = latestDateT.Year()
- }
- startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
- dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.EdbInfoDataSeasonalResp)
- resp.EdbInfo = edbInfo
- resp.DataList = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SetEdbDataInsertConfig 设置插入值
- // @Title 设置插入值接口
- // @Description 设置插入值接口
- // @Success 200 {object} data_manage.EditEdbEnInfoReq
- // @router /edb_info/insert_config/set [post]
- func (this *EdbInfoController) SetEdbDataInsertConfig() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.SetEdbDataInsertConfigReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- dateStr := req.Date
- if dateStr == `` {
- br.Msg = "请选择日期"
- br.IsSendEmail = false
- return
- }
- date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
- if err != nil {
- br.Msg = "日期异常"
- br.ErrMsg = "日期异常,err:" + err.Error()
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
- if err != nil {
- br.Msg = "设置失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "修改失败,Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "设置插入值"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // TraceEdbInfo
- // @Title 指标溯源接口
- // @Description 指标溯源接口
- // @Param UniqueCode query int true "指标唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/trace [get]
- func (this *EdbInfoController) TraceEdbInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- //edbInfoId, _ := this.GetInt("EdbInfoId")
- //if edbInfoId <= 0 {
- // br.Msg = "参数错误"
- // br.ErrMsg = "参数错误"
- // return
- //}
- uniqueCode := this.GetString("UniqueCode")
- if uniqueCode == `` {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- // 根据UniqueCode获取指标信息
- edbInfo, err := data_manage.GetEdbInfoByUniqueCode(uniqueCode)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- }
- return
- }
- resp, err := data.TraceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Data = resp
- br.Success = true
- br.Msg = "刷新成功"
- }
- // AllEdbInfoByEs
- // @Title 所有指标筛选接口
- // @Description 所有指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
- // @Param Frequency query string false "频度"
- // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/filter_by_es/all [get]
- func (this *EdbInfoController) AllEdbInfoByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int64
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- //指标来源
- source, _ := this.GetInt("Source")
- frequency := this.GetString("Frequency") //频度
- isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
- var edbInfoList []*data_manage.EdbInfoList
- var err error
- noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
- // 获取当前账号的不可见指标
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- }
- // 是否走ES
- isEs := false
- if keyWord != "" {
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- // 普通的搜索
- total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, frequency, noPermissionEdbInfoIdList)
- isEs = true
- } else {
- var condition string
- var pars []interface{}
- // 普通指标
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 0)
- // 无权限指标id
- lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
- if lenNoPermissionEdbInfoIdList > 0 {
- condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- switch filterSource {
- case 2:
- condition += ` AND frequency='月度' `
- case 3:
- condition += ` AND frequency <> '日度' `
- case 4:
- condition += ` AND edb_type = 1 `
- case 5:
- condition += ` AND source = 6 ` //来源(同比值)
- case 6:
- condition += ` AND frequency != ? `
- pars = append(pars, "年度")
- }
- //频度
- if frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, frequency)
- }
- // 查询只允许添加预测指标的搜索
- if isAddPredictEdb {
- condition += ` AND frequency in ("日度","周度","月度") `
- }
- total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
- }
- if err != nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- edbInfoListLen := len(edbInfoList)
- classifyIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
- }
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.EdbClassify)
- if edbInfoListLen > 0 {
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
- if isEs {
- edbInfoIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
- tmpEdbInfo := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- edbInfoMap := make(map[int]*data_manage.EdbInfo)
- for _, v := range tmpEdbList {
- edbInfoMap[v.EdbInfoId] = v
- }
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
- if !ok {
- continue
- }
- edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
- }
- }
- // 权限校验
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfoItem := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- resp := data_manage.EdbInfoFilterDataResp{
- Paging: page,
- List: edbInfoList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetEdbDateData
- // @Title 根据指标ID和具体日期获取对应日期的数据值
- // @Description 根据指标ID和具体日期获取对应日期的数据值
- // @Param EdbInfoId query int false "指标id"
- // @Param Date query string false "日期"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/date_data [get]
- func (this *EdbInfoController) GetEdbDateData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoId, _ := this.GetInt("EdbInfoId")
- date := this.GetString("Date")
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- if date == `` {
- br.Msg = "请选择日期"
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
- return
- }
- startDate := date
- endDate := date
- dateType := "day"
- //如果填写的是月度日期
- if strings.Count(date, "-") == 1 {
- startDate = date + "-01"
- endDate = ``
- dateType = "month"
- }
- dataItem, err := data.GetDateData(edbInfo, startDate, endDate)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
- return
- }
- val := ``
- if dataItem != nil {
- switch dateType {
- case "month":
- dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local)
- dateTimeStr := dateTime.Format(utils.FormatYearMonthDate)
- if dateTimeStr != date {
- val = ``
- }
- }
- val = fmt.Sprint(dataItem.Value)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = val
- }
- // GetEdbBeforeAndAfterDateData
- // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期
- // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期
- // @Param EdbInfoId query int false "指标id"
- // @Param Date query string false "日期"
- // @Param Num query int false "前后几期数据"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/date_data/before_after [post]
- func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- requestBody := string(this.Ctx.Input.RequestBody)
- var req request2.DateDataBeforeAfterReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- edbInfoId := req.EdbInfoId
- currDate := req.Date
- num := req.Num
- // 默认2期数据
- if num <= 0 {
- num = 2
- }
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
- return
- }
- dataList := make([]*data_manage.EdbDataList, 0)
- switch edbInfo.EdbInfoType {
- case 0:
- dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
- case 1:
- _, dataList, _, _, _, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
- default:
- br.Msg = "指标类型异常!"
- br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType)
- return
- }
- if currDate == `` {
- currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList)
- if err != nil {
- br.Msg = "日期前移失败"
- br.ErrMsg = "日期前移失败,Err:" + err.Error()
- return
- }
- } else {
- if strings.Count(currDate, "-") == 1 {
- currDate = currDate + "-01"
- // 查找这个月早的时间作为起始时间
- for _, v := range dataList {
- if v.DataTime >= currDate {
- currDate = v.DataTime
- break
- }
- }
- }
- }
- currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody)
- if err != nil {
- br.Msg = "日期变换失败"
- br.ErrMsg = "日期变换失败,Err:" + err.Error()
- return
- }
- list := make([]*data_manage.EdbDataList, 5)
- list, err = data.GetEdbBeforeAndAfterDateData(currDate, dataList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
- return
- }
- // 这个日期不存在的话直接返回空数组
- resp := data_manage.BeforeAndAfterDateDataResp{
- List: list,
- Date: currDate,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbChartAdminList
- // @Title 获取创建人员分组
- // @Description 获取创建人员分组
- // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
- // @Success 200 {object} company.DepartmentGroupSellersResp
- // @router /edb_chart/adminList [get]
- func (this *EdbInfoController) EdbChartAdminList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- source, _ := this.GetInt("Source", 0)
- if source <= 0 || source > 5 {
- br.Msg = "错误的来源"
- br.IsSendEmail = false
- return
- }
- idList, err := data.GetEdbChartAdminList(source)
- if err != nil {
- //br.Success = true
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- fmt.Println("idlist:", idList)
- systemAdminMap := make(map[int]*system.Admin)
- departmentMap := make(map[string]string)
- departmentAdminMap := make(map[int]string)
- groupMap := make(map[string]string)
- systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList)
- if err != nil {
- br.Msg = "获取用户列表失败"
- br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
- return
- }
- for _, v := range systemAdminList {
- systemAdminMap[v.AdminId] = v
- departmentMap[v.DepartmentName] = v.DepartmentName
- departmentAdminMap[v.AdminId] = v.DepartmentName
- groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName
- }
- depList := make([]company.DepartmentGroupAdmins, 0)
- i := 1
- for _, v := range departmentMap {
- item := company.DepartmentGroupAdmins{
- AdminId: "dep_" + strconv.Itoa(i),
- RealName: v,
- }
- i++
- depList = append(depList, item)
- }
- for k := 0; k < len(depList); k++ {
- for k1, v1 := range groupMap {
- if v1 == depList[k].RealName && v1 != "" {
- item := &company.DepartmentGroupAdmins{
- AdminId: "group_" + strconv.Itoa(k),
- RealName: strings.Replace(k1, v1, "", -1),
- }
- depList[k].ChildrenList = append(depList[k].ChildrenList, item)
- }
- }
- }
- for _, admin := range systemAdminList {
- for i, v := range depList {
- for k, group := range v.ChildrenList {
- if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName {
- item := &company.DepartmentGroupAdmins{
- AdminId: strconv.Itoa(admin.AdminId),
- RealName: admin.RealName,
- RoleTypeCode: admin.RoleTypeCode,
- Authority: admin.Authority,
- }
- if group.RealName != "" {
- depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item)
- } else {
- depList[i].ChildrenList = append(depList[i].ChildrenList, item)
- }
- }
- }
- }
- }
- for i, groupList := range depList {
- for k, v := range groupList.ChildrenList {
- if v.RealName == "" {
- newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...)
- depList[i].ChildrenList = newChildrenList
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = depList
- }
- // EdbSourceList
- // @Title 指标来源列表
- // @Description 指标来源列表
- // @Param IsBase query int false "是否为基础指标: 1-是"
- // @Success 200 {object} data_manage.EdbInfoListResp
- // @router /edb_source/list [get]
- func (this *EdbInfoController) EdbSourceList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- isBase, _ := this.GetInt("IsBase", 0)
- cond := ``
- if isBase > 0 {
- cond = ` AND is_base = 1`
- }
- pars := make([]interface{}, 0)
- list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
- return
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // EdbSourceListByPython
- // @Title 指标来源列表
- // @Description 指标来源列表
- // @Param IsBase query int false "是否为基础指标: 1-是"
- // @Success 200 {object} data_manage.EdbInfoListResp
- // @router /edb_source/list/python [get]
- func (this *EdbInfoController) EdbSourceListByPython() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- isBase, _ := this.GetInt("IsBase", 0)
- cond := ``
- if isBase > 0 {
- cond = ` AND is_base = 1`
- }
- pars := make([]interface{}, 0)
- list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
- return
- }
- baseEdbList := make([]data_manage.EdbSourceChild, 0)
- calEdbList := make([]data_manage.EdbSourceChild, 0)
- for _, v := range list {
- switch v.IsBase {
- case 1:
- baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{
- EdbSourceId: v.EdbSourceId,
- SourceName: v.SourceName,
- IsBase: v.IsBase,
- TableName: v.TableName,
- Child: []data_manage.EdbSourceChild{},
- })
- case 2:
- calEdbList = append(calEdbList, data_manage.EdbSourceChild{
- EdbSourceId: v.EdbSourceId,
- SourceName: v.SourceName,
- IsBase: v.IsBase,
- TableName: v.TableName,
- Child: []data_manage.EdbSourceChild{},
- })
- }
- }
- resp := []data_manage.EdbSourceChild{
- {
- EdbSourceId: 0,
- SourceName: "基础指标",
- IsBase: 1,
- Child: baseEdbList,
- },
- {
- EdbSourceId: 0,
- SourceName: "计算指标",
- IsBase: 1,
- Child: calEdbList,
- },
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // EdbChartList
- // @Title 指标缩略图列表接口
- // @Description 指标缩略图列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query int true "分类id"
- // @Param AdminId query int false "创建人id"
- // @Param IsOnlyMe query bool false "是否只看我的"
- // @Success 200 {object} response.EdbInfoChartListResp
- // @router /edb_info/chart/list [get]
- func (this *EdbInfoController) EdbChartList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- // 分页
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- // 基础指标
- var condition string
- var pars []interface{}
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 0)
- // 分类筛选
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId > 0 {
- childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
- return
- }
- var classifyIds []int
- for _, v := range childClassify {
- classifyIds = append(classifyIds, v.ClassifyId)
- }
- condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
- pars = append(pars, classifyIds)
- }
- // 创建人
- adminId, _ := this.GetInt("AdminId")
- if adminId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, adminId)
- }
- // 只看我的
- isOnlyMe, _ := this.GetBool("IsOnlyMe")
- if isOnlyMe {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- // 获取当前账号的不可见指标
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
- return
- }
- noPermissionEdbInfoIdList := make([]int, 0)
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
- if noPermissionEdbInfoIdNum > 0 {
- condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- // 获取指标信息
- dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
- return
- }
- if len(list) == 0 {
- list = make([]*data_manage.EdbInfoList, 0)
- } else {
- classifyIdList := make([]int, 0)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ClassifyId)
- }
- // 指标权限
- {
- // 当前的分类
- classifyMap := make(map[int]*data_manage.EdbClassify)
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- issSupplierStopIndexCodeMap := make(map[string]bool)
- {
- tmpEdbCodeList := make([]string, 0)
- for _, v := range list {
- if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode)
- }
- }
- if len(tmpEdbCodeList) > 0 {
- notIsSupplierStopIndexList, e := data_manage.GetNotIsSupplierStopIndexByCodeList(tmpEdbCodeList, 1)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + e.Error()
- return
- }
- // 已被供应商暂停的指标编码
- for _, v := range notIsSupplierStopIndexList {
- issSupplierStopIndexCodeMap[v.IndexCode] = true
- }
- }
- }
- for _, v := range list {
- if currClassify, ok := classifyMap[v.ClassifyId]; ok {
- v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType, v.HaveOperaAuth)
- }
- // 供应商停用
- if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- if _, ok := issSupplierStopIndexCodeMap[v.EdbCode]; ok {
- v.IsSupplierStop = 1
- }
- }
- }
- }
- page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
- }
- resp := response.EdbInfoChartListResp{
- Paging: page,
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Modify
- // @Title 修改指标信息接口
- // @Description 编辑指标接口
- // @Success 200 string "操作成功"
- // @router /edb_info/modify [post]
- func (this *EdbInfoController) Modify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.ModifyEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- edbInfoId := req.EdbInfoId
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取指标信息失败, Err:" + err.Error()
- return
- }
- var haveOperaAuth bool
- // 权限校验
- {
- haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- // 编辑权限校验
- button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无权限操作"
- return
- }
- edbInfo.MaxValue = req.MaxValue
- edbInfo.MinValue = req.MinValue
- edbInfo.ManualSave = 1
- edbInfo.ModifyTime = time.Now()
- err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //修改es
- data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "修改成功"
- br.IsAddLog = true
- }
- // ChartImageSet
- // @Title 设置指标的图表图片
- // @Description 设置指标的图表图片接口
- // @Param request body data_manage.SetChartInfoImageReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/image/set [post]
- func (this *EdbInfoController) ChartImageSet() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.SetEdbInfoImageReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.EdbInfoId <= 0 || req.ImageUrl == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- return
- }
- edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "找不到该指标"
- return
- }
- br.Msg = "保存失败"
- br.ErrMsg = "获取指标失败, Err:" + e.Error()
- return
- }
- edbInfo.ChartImage = req.ImageUrl
- if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
- return
- }
- // 修改es数据
- go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // EdbInfoExistCheck
- // @Title 新增指标-检验指标是否存在接口
- // @Description 新增指标-检验指标是否存在接口
- // @Param Source query int true "来源:1:同花顺,2:wind"
- // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
- // @Param EdbCode query string false "指标编码/指标代码"
- // @Param StockCode query string false "证券代码"
- // @Success 200 {object} data_manage.EdbInfoExistCheckResp
- // @router /edb_info/exist/check [get]
- func (this *EdbInfoController) EdbInfoExistCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source, _ := this.GetInt("Source")
- edbCode := this.GetString("EdbCode")
- edbCode = strings.Trim(edbCode, "\t")
- edbCode = strings.Trim(edbCode, " ")
- edbCode = strings.Replace(edbCode, "\t", "", -1)
- subSource, _ := this.GetInt("SubSource")
- stockCode := this.GetString("StockCode")
- if source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- if edbCode == "" {
- br.Msg = "请输入指标ID"
- return
- }
- if source != utils.DATA_SOURCE_WIND && source != utils.DATA_SOURCE_THS {
- br.Msg = "无效的数据来源"
- return
- }
- if subSource != utils.DATA_SUB_SOURCE_DATE {
- br.Msg = "无效的数据库来源"
- return
- }
- var indexCodeArr []string
- edbCodeArr := strings.Split(edbCode, ",")
- stockCodeArr := strings.Split(stockCode, ",")
- var prefix string
- if source == utils.DATA_SOURCE_WIND {
- prefix = utils.WindDbWsd
- } else if source == utils.DATA_SOURCE_THS {
- prefix = utils.ThsDs
- } else {
- br.Msg = "来源错误"
- br.ErrMsg = "来源错误"
- return
- }
- for _, sv := range stockCodeArr {
- for _, ev := range edbCodeArr {
- indexCode := prefix + sv + ev
- indexCodeArr = append(indexCodeArr, indexCode)
- }
- }
- indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验指标是否存在失败"
- br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
- return
- }
- var existStockCodeArr []string
- var existEdbCodeArr []string
- var existClassifyId []int
- var existIndexId []int
- for _, indexItem := range indexList {
- for _, sv := range stockCodeArr {
- for _, ev := range edbCodeArr {
- if strings.Contains(indexItem.EdbCode, sv) {
- existStockCodeArr = append(existStockCodeArr, sv)
- }
- if strings.Contains(indexItem.EdbCode, ev) {
- existEdbCodeArr = append(existEdbCodeArr, ev)
- existClassifyId = append(existClassifyId, indexItem.ClassifyId)
- existIndexId = append(existIndexId, indexItem.EdbInfoId)
- }
- }
- }
- }
- resp := new(data_manage.EdbInfoExistCheckResp)
- if len(indexList) > 0 {
- resp.IndexExist = true
- }
- resp.ExistEdbCodeArr = existEdbCodeArr
- resp.ExistStockCodeArr = existStockCodeArr
- resp.ExistClassifyId = existClassifyId
- resp.ExistIndexId = existIndexId
- resp.ExistEdbInfo = indexList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoAdd
- // @Title 指标批量保存接口
- // @Description 指标批量保存接口
- // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/batch/add [post]
- func (this *EdbInfoController) EdbInfoBatchAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req data_manage.BatchAddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.AddEdbInfoResp)
- var edbNames string
- for _, v := range req.BatchList {
- edbNames += "'" + v.EdbName + "',"
- }
- edbNames = strings.Trim(edbNames, ",")
- infoList, err := data_manage.GetEdbInfoByNames(edbNames)
- if err != nil {
- br.Msg = "查询指标名称重复错误!"
- br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
- return
- }
- if len(infoList) > 0 {
- for _, v := range infoList {
- resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
- }
- br.Data = resp
- br.Msg = "指标名称重复!"
- br.ErrMsg = "指标名称重复"
- return
- }
- for k, v := range req.BatchList {
- v.EdbName = strings.Trim(v.EdbName, " ")
- v.EdbCode = strings.Trim(v.EdbCode, " ")
- v.StockCode = strings.Trim(v.StockCode, " ")
- if v.Source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- if v.EdbCode == "" {
- br.Msg = "指标ID不能为空"
- return
- }
- if v.StockCode == "" {
- br.Msg = "证券代码不能为空"
- return
- }
- if v.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if v.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if v.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- terminalCode, serverUrl, _, e := data.GetEdbTerminalCodeBySource(v.Source, v.EdbCode, v.StockCode)
- if e != nil {
- br.Msg = "获取可以使用的终端地址失败"
- br.ErrMsg = "获取可以使用的终端地址失败,Err:" + e.Error()
- return
- }
- edbInfoItem := new(data_manage.EdbInfo)
- edbInfoItem.Source = v.Source
- switch v.Source {
- case utils.DATA_SOURCE_WIND:
- edbInfoItem.SourceName = "wind"
- edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
- case utils.DATA_SOURCE_THS:
- edbInfoItem.SourceName = "ths"
- edbInfoItem.EdbCode = utils.ThsDs + v.StockCode + v.EdbCode
- }
- edbInfoItem.SubSource = utils.DATA_SUB_SOURCE_DATE
- edbInfoItem.SubSourceName = "日期序列"
- edbInfoItem.EdbName = v.EdbName
- edbInfoItem.EdbNameSource = v.EdbName
- edbInfoItem.EdbNameEn = v.EdbName
- edbInfoItem.Frequency = v.Frequency
- edbInfoItem.Unit = v.Unit
- edbInfoItem.UnitEn = v.Unit
- edbInfoItem.ClassifyId = v.ClassifyId
- edbInfoItem.SysUserId = sysUser.AdminId
- edbInfoItem.SysUserRealName = sysUser.RealName
- edbInfoItem.IndicatorCode = v.EdbCode
- edbInfoItem.StockCode = v.StockCode
- edbInfoItem.TerminalCode = terminalCode
- edbInfoItem.ServerUrl = serverUrl
- var extra data_manage.EdbInfoExtra
- if v.ApiExtraPars != "" {
- extra.ApiExtraPars = v.ApiExtraPars
- b, e := json.Marshal(extra)
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = fmt.Sprintf("额外参数JSON格式化失败, %v", e)
- return
- }
- edbInfoItem.Extra = string(b)
- }
- // 指标入库
- edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- if k <= 0 {
- resp.EdbInfoId = edbInfo.EdbInfoId
- resp.UniqueCode = edbInfo.UniqueCode
- }
- }
- // 试用平台更新用户累计新增指标数
- adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
- return
- }
- if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
- go func() {
- var r etaTrialService.EtaTrialUserReq
- r.Mobile = adminItem.Mobile
- _, _ = etaTrialService.UpdateUserIndexNum(r)
- }()
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // SmmExistCheck
- // @Title 新增指标-检验指标是否存在接口-smm
- // @Description 新增指标-检验指标是否存在接口-smm
- // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
- // @Param EdbCode query string false "指标编码/指标代码"
- // @Param StockCode query string false "证券代码"
- // @Success 200 {object} data_manage.EdbInfoExistCheckResp
- // @router /edb_info/smm/exist/check [post]
- func (this *EdbInfoController) SmmExistCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req data_manage.SmmIndexExistCheckReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- types := req.Types
- frequency := req.Frequency
- dataState := req.DataState
- selectAll := req.SelectAll
- keyword := req.Keyword
- edbCode := req.EdbCode
- edbCode = strings.Trim(edbCode, "\t")
- edbCode = strings.Trim(edbCode, " ")
- edbCode = strings.Replace(edbCode, "\t", "", -1)
- var edbCodeArr []string
- var codeArr []string
- if selectAll {
- // 如果勾了列表全选,那么EdbCode传的就是排除的code
- var condition string
- var pars []interface{}
- if len(types) > 0 {
- condition += " AND ( "
- for _, v := range types {
- typeArr := strings.Split(v, ",")
- for i, v := range typeArr {
- if i == 0 {
- condition += " ( "
- }
- typeStr := "type_"
- typeStr += fmt.Sprintf("%d", i+1)
- condition += typeStr + " =? "
- pars = append(pars, v)
- if i == len(typeArr)-1 {
- condition += " ) "
- } else {
- condition += " AND "
- }
- }
- condition += " OR "
- }
- condition = strings.Trim(condition, "OR ")
- condition += " ) "
- }
- if frequency != "" {
- frequencyArr := strings.Split(frequency, ",")
- condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
- pars = append(pars, frequencyArr)
- }
- if dataState != "" {
- stateArr := strings.Split(dataState, ",")
- if strings.Contains(dataState, "normal") {
- stateArr = append(stateArr, "")
- condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
- pars = append(pars, stateArr)
- } else {
- condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
- pars = append(pars, stateArr)
- }
- }
- if keyword != "" {
- keyWordArr := strings.Split(keyword, " ")
- if len(keyWordArr) > 0 {
- condition += " AND ( "
- for _, v := range keyWordArr {
- condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
- }
- condition = strings.TrimRight(condition, "OR")
- condition += " ) "
- }
- }
- indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
- if err != nil {
- br.Msg = "获取指标列表失败"
- br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
- return
- }
- for _, v := range indexList {
- codeArr = append(codeArr, v.IndexCode)
- }
- noUseCodeArr := strings.Split(edbCode, ",")
- for _, code := range codeArr {
- // 检查code是否在noUseCodeArr数组中
- if !utils.ArrContainsStr(noUseCodeArr, code) {
- // 如果不在,将其添加到结果数组中
- edbCodeArr = append(edbCodeArr, code)
- }
- }
- } else {
- //未勾选全选EdbCode就是需要的code
- edbCodeArr = strings.Split(edbCode, ",")
- }
- if len(edbCodeArr) > 30 {
- br.Msg = "最多只能选择30个指标"
- return
- }
- if len(edbCodeArr) <= 0 {
- br.Msg = "无符合指标或指标代码错误"
- return
- }
- indexList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_YS, edbCodeArr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验指标是否存在失败"
- br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
- return
- }
- var existEdbCodeArr []string
- var existClassifyId []int
- var existIndexId []int
- for _, indexItem := range indexList {
- for _, ev := range edbCodeArr {
- if strings.Contains(indexItem.EdbCode, ev) {
- existEdbCodeArr = append(existEdbCodeArr, ev)
- existClassifyId = append(existClassifyId, indexItem.ClassifyId)
- existIndexId = append(existIndexId, indexItem.EdbInfoId)
- }
- }
- }
- resp := new(data_manage.EdbInfoSmmExistCheckResp)
- if len(indexList) > 0 {
- resp.IndexExist = true
- }
- if len(existEdbCodeArr) == len(edbCodeArr) {
- resp.ExistAll = true
- }
- resp.ExistEdbCodeArr = existEdbCodeArr
- resp.ExistClassifyId = existClassifyId
- resp.ExistIndexId = existIndexId
- resp.ExistEdbInfo = indexList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoSearch
- // @Title 新增指标-查询指标信息接口-smm
- // @Description 新增指标-查询指标信息接口-smm
- // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
- // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
- // @Param EdbCode query string false "指标编码/指标代码"
- // @Param StockCode query string false "证券代码"
- // @Success 200 {object} data_manage.EdbInfoSearchResp
- // @router /edb_info/smm/search [post]
- func (this *EdbInfoController) EdbInfoSmmSearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req data_manage.SmmIndexExistCheckReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- types := req.Types
- frequency := req.Frequency
- dataState := req.DataState
- selectAll := req.SelectAll
- keyword := req.Keyword
- edbCode := req.EdbCode
- edbCode = strings.Trim(edbCode, "\t")
- edbCode = strings.Trim(edbCode, " ")
- edbCode = strings.Replace(edbCode, "\t", "", -1)
- var edbCodeArr []string
- var codeArr []string
- if selectAll {
- // 如果勾了列表全选,那么EdbCode传的就是排除的code
- var condition string
- var pars []interface{}
- if len(types) > 0 {
- condition += " AND ( "
- for _, v := range types {
- typeArr := strings.Split(v, ",")
- for i, v := range typeArr {
- if i == 0 {
- condition += " ( "
- }
- typeStr := "type_"
- typeStr += fmt.Sprintf("%d", i+1)
- condition += typeStr + " =? "
- pars = append(pars, v)
- if i == len(typeArr)-1 {
- condition += " ) "
- } else {
- condition += " AND "
- }
- }
- condition += " OR "
- }
- condition = strings.Trim(condition, "OR ")
- condition += " ) "
- }
- if frequency != "" {
- frequencyArr := strings.Split(frequency, ",")
- condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
- pars = append(pars, frequencyArr)
- }
- if dataState != "" {
- stateArr := strings.Split(dataState, ",")
- if strings.Contains(dataState, "normal") {
- stateArr = append(stateArr, "")
- condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
- pars = append(pars, stateArr)
- } else {
- condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
- pars = append(pars, stateArr)
- }
- }
- if keyword != "" {
- keyWordArr := strings.Split(keyword, " ")
- if len(keyWordArr) > 0 {
- condition += " AND ( "
- for _, v := range keyWordArr {
- condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
- }
- condition = strings.TrimRight(condition, "OR")
- condition += " ) "
- }
- }
- indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
- if err != nil {
- br.Msg = "获取指标列表失败"
- br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
- return
- }
- for _, v := range indexList {
- codeArr = append(codeArr, v.IndexCode)
- }
- noUseCodeArr := strings.Split(edbCode, ",")
- for _, code := range codeArr {
- // 检查code是否在noUseCodeArr数组中
- if !utils.ArrContainsStr(noUseCodeArr, code) {
- // 如果不在,将其添加到结果数组中
- edbCodeArr = append(edbCodeArr, code)
- }
- }
- } else {
- //未勾选全选EdbCode就是需要的code
- edbCodeArr = strings.Split(edbCode, ",")
- }
- if len(edbCodeArr) > 30 {
- br.Msg = "最多只能选择30个指标"
- return
- }
- if len(edbCodeArr) <= 0 {
- br.Msg = "无符合指标或指标代码错误"
- return
- }
- edbCodeStr := ""
- for i, _ := range edbCodeArr {
- edbCodeStr += "'" + edbCodeArr[i] + "'" + ","
- }
- edbCodeStr = strings.Trim(edbCodeStr, ",")
- smmInfoList, err := data_manage.GetBaseFromSmmIndexByIndexCodes(edbCodeStr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
- return
- }
- smmInfoMap := make(map[string]*data_manage.BaseFromSmmIndex)
- for _, v := range smmInfoList {
- smmInfoMap[v.IndexCode] = v
- }
- searchItemList := make([]*data_manage.EdbInfoSearch, 0)
- resp := new(data_manage.EdbInfoSearchResp)
- needAddCodeArr := make([]string, 0)
- noNeedAddCodeMap := make(map[string]string, 0)
- for _, edbCode := range edbCodeArr {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem := new(data_manage.EdbInfoSearch)
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- searchItem.Frequency = smmInfoMap[edbCode].Frequency
- searchItem.Unit = smmInfoMap[edbCode].Unit
- searchItem.EdbName = smmInfoMap[edbCode].IndexName
- searchItem.EdbCode = smmInfoMap[edbCode].IndexCode
- searchItemList = append(searchItemList, searchItem)
- noNeedAddCodeMap[edbCode] = edbCode
- } else {
- // 把需要新加的code添加到needAddCodeArr数组中,一起批量请求
- needAddCodeArr = append(needAddCodeArr, edbCode)
- }
- }
- if len(needAddCodeArr) > 0 {
- edbCode = strings.Join(needAddCodeArr, ",")
- respItem, err := data.AddEdbData(utils.DATA_SOURCE_YS, edbCode, "")
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- if respItem.Ret == 421 {
- br.Msg = "该渠道已超过添加上限"
- } else if respItem.Ret == 4052 {
- br.Msg = "该指标已下架"
- } else {
- br.Msg = "未搜索到该指标"
- }
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- }
- for _, smmInfo := range smmInfoList {
- if smmInfo != nil {
- if _, ok := noNeedAddCodeMap[smmInfo.IndexCode]; !ok {
- searchItem := new(data_manage.EdbInfoSearch)
- minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(smmInfo.IndexCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- searchItem.Frequency = smmInfo.Frequency
- searchItem.Unit = smmInfo.Unit
- searchItem.EdbName = smmInfo.IndexName
- searchItem.EdbCode = smmInfo.IndexCode
- dataList, err := data_manage.GetEdbDataAllByEdbCode(smmInfo.IndexCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
- return
- }
- searchItem.DataList = dataList
- searchItemList = append(searchItemList, searchItem)
- }
- }
- }
- resp.Status = 2
- resp.StockSearchList = searchItemList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SmmEdbInfoBatchAdd
- // @Title 指标批量保存接口-smm
- // @Description 指标批量保存接口-smm
- // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/smm/batch/add [post]
- func (this *EdbInfoController) SmmEdbInfoBatchAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req data_manage.BatchAddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.AddEdbInfoResp)
- var edbNames string
- for _, v := range req.BatchList {
- edbNames += "'" + v.EdbName + "',"
- }
- edbNames = strings.Trim(edbNames, ",")
- infoList, err := data_manage.GetEdbInfoByNames(edbNames)
- if err != nil {
- br.Msg = "查询指标名称重复错误!"
- br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
- return
- }
- if len(infoList) > 0 {
- for _, v := range infoList {
- resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
- }
- br.Data = resp
- br.Msg = "指标名称重复!"
- br.ErrMsg = "指标名称重复"
- return
- }
- for k, v := range req.BatchList {
- v.EdbName = strings.Trim(v.EdbName, " ")
- v.EdbCode = strings.Trim(v.EdbCode, " ")
- if v.Source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- if v.EdbCode == "" {
- br.Msg = "指标ID不能为空"
- return
- }
- if v.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if v.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if v.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- edbInfoItem := new(data_manage.EdbInfo)
- edbInfoItem.Source = v.Source
- edbInfoItem.SourceName = "SMM"
- edbInfoItem.EdbCode = v.EdbCode
- edbInfoItem.SubSource = 0
- edbInfoItem.SubSourceName = ""
- edbInfoItem.EdbName = v.EdbName
- edbInfoItem.EdbNameSource = v.EdbName
- edbInfoItem.EdbNameEn = v.EdbName
- edbInfoItem.Frequency = v.Frequency
- edbInfoItem.Unit = v.Unit
- edbInfoItem.UnitEn = v.Unit
- edbInfoItem.ClassifyId = v.ClassifyId
- edbInfoItem.SysUserId = sysUser.AdminId
- edbInfoItem.SysUserRealName = sysUser.RealName
- edbInfoItem.IndicatorCode = ""
- edbInfoItem.StockCode = ""
- // 指标入库
- edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- if k <= 0 {
- resp.EdbInfoId = edbInfo.EdbInfoId
- resp.UniqueCode = edbInfo.UniqueCode
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // ChartImageSetBySvg
- // @Title 设置指标的图表图片
- // @Description 设置指标的图表图片接口
- // @Param request body data_manage.SetChartInfoImageReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/image/set_by_svg [post]
- func (this *EdbInfoController) ChartImageSetBySvg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- imgData := this.GetString("Img")
- if imgData == "" {
- br.Msg = "图片参数错误"
- br.ErrMsg = "图片参数错误,Img Is Empty"
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId", 0)
- if edbInfoId <= 0 {
- br.Msg = "指标参数错误"
- br.ErrMsg = "指标参数错误,EdbInfoId Is Empty"
- return
- }
- // 通过svg图片生成图片资源地址
- resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- if edbInfoId <= 0 || resourceUrl == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- return
- }
- edbInfo, e := data_manage.GetEdbInfoById(edbInfoId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "找不到该指标"
- return
- }
- br.Msg = "保存失败"
- br.ErrMsg = "获取指标失败, Err:" + e.Error()
- return
- }
- edbInfo.ChartImage = resourceUrl
- if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
- return
- }
- // 修改es数据
- go data.AddOrEditEdbInfoToEs(edbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
|