edb_info.go 188 KB

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