edb_info.go 186 KB

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