edb_info.go 188 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404
  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 {
  1705. // 代码中没有的来源那么从edb_source中找是否有对应的
  1706. sourceItem := data_manage.EdbSourceIdMap[source]
  1707. if sourceItem == nil {
  1708. br.Msg = "无效指标来源"
  1709. return
  1710. }
  1711. // 获取指标数据
  1712. dataList, e := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1713. if e != nil {
  1714. br.Msg = "获取失败"
  1715. br.ErrMsg = "获取指标数据失败, Err: " + e.Error()
  1716. return
  1717. }
  1718. if len(dataList) > 0 {
  1719. searchItem.EdbCode = edbCode
  1720. searchItem.DataList = dataList
  1721. // 获取最大最小值
  1722. edbInfoMaxAndMinInfo, e := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1723. if e != nil && e.Error() != utils.ErrNoRow() {
  1724. br.Msg = "获取失败"
  1725. br.ErrMsg = "获取数据失败, GetEdbInfoMaxAndMinInfo Err:" + e.Error()
  1726. return
  1727. }
  1728. if edbInfoMaxAndMinInfo != nil {
  1729. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1730. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1731. }
  1732. } else {
  1733. // 新增指标数据
  1734. addRes, e := data.AddEdbData(source, edbCode, frequency)
  1735. if e != nil {
  1736. br.Msg = "获取失败"
  1737. br.ErrMsg = "获取失败,Err:" + e.Error()
  1738. return
  1739. }
  1740. if addRes == nil {
  1741. br.Msg = "获取失败"
  1742. br.ErrMsg = "新增指标数据失败, addRes nil"
  1743. return
  1744. }
  1745. if addRes.Ret != 200 {
  1746. br.Msg = "未搜索到该指标, " + addRes.Msg
  1747. //br.ErrMsg = addRes.ErrMsg + ";EdbCode:" + edbCode
  1748. br.Success = true
  1749. return
  1750. }
  1751. isAdd = true
  1752. }
  1753. // 查询基本信息
  1754. baseIndexInfo, tErr := data_manage.GetBaseIndexInfoByEdbCode(edbCode, source)
  1755. if tErr == nil {
  1756. searchItem.EdbName = baseIndexInfo.IndexName
  1757. searchItem.Frequency = baseIndexInfo.Frequency
  1758. searchItem.Unit = baseIndexInfo.Unit
  1759. }
  1760. // 指标来源于桥接服务: 桥接服务获取指标取频度信息等
  1761. if sourceItem.BridgeFlag != "" {
  1762. bridgeOb := data.InitBridgeOB(sourceItem.BridgeFlag)
  1763. if bridgeOb != nil {
  1764. var r data.GetIndexFromBridgeReq
  1765. r.IndexCode = edbCode
  1766. r.Source = sourceItem.EdbSourceId
  1767. r.SourceExtend = sourceItem.SourceExtend
  1768. r.IndexCodeRequired = sourceItem.EdbCodeRequired
  1769. bridgeIndex, e := bridgeOb.GetIndex(r)
  1770. if e != nil {
  1771. br.Msg = "获取失败"
  1772. br.ErrMsg = "桥接服务获取指标信息失败, Err: " + e.Error()
  1773. return
  1774. }
  1775. searchItem.EdbName = bridgeIndex.IndexName
  1776. searchItem.Frequency = bridgeIndex.Frequency
  1777. searchItem.Unit = bridgeIndex.Unit
  1778. }
  1779. }
  1780. }
  1781. if isAdd {
  1782. if subSource == utils.DATA_SUB_SOURCE_DATE {
  1783. if source == utils.DATA_SOURCE_WIND {
  1784. //wsdData := windWsdRespItem.Data
  1785. //var buf bytes.Buffer
  1786. //// 创建一个encoder并指定目标为buf
  1787. //enc := gob.NewEncoder(&buf)
  1788. //
  1789. //// 将data编码到buf中
  1790. //err = enc.Encode(wsdData)
  1791. //if err != nil {
  1792. // br.Msg = "获取失败"
  1793. // br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error()
  1794. // return
  1795. //}
  1796. //
  1797. //wsdDataMap := make(map[string]map[string]interface{})
  1798. //err = json.Unmarshal(buf.Bytes(), &wsdDataMap)
  1799. //if err != nil {
  1800. // br.Msg = "获取失败"
  1801. // br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error()
  1802. // return
  1803. //}
  1804. //
  1805. //stockList := make([]*data_manage.StockInfo, 0)
  1806. //
  1807. //dataList := make([]*data_manage.EdbInfoSearchData, 0)
  1808. //for wk, wv := range wsdDataMap {
  1809. // for vk, vv := range wv {
  1810. // wkInt, err := strconv.ParseInt(wk, 10, 64)
  1811. // if err != nil {
  1812. // br.Msg = "获取失败"
  1813. // br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error()
  1814. // return
  1815. // }
  1816. //
  1817. // vk = strings.ToLower(vk)
  1818. // wkInt = wkInt / 1000
  1819. // t := time.Unix(wkInt, 0)
  1820. // dateTime := t.Format(utils.FormatDate)
  1821. // //saveVal := utils.SubFloatToString(val, 20)
  1822. // if vv == nil {
  1823. // continue
  1824. // }
  1825. // var saveVal string
  1826. // switch vt := vv.(type) {
  1827. // case int:
  1828. // saveVal = strconv.Itoa(vt)
  1829. // case float64:
  1830. // saveVal = utils.SubFloatToFloatStr(vt, 20)
  1831. // case string:
  1832. // saveVal = vt
  1833. // }
  1834. //
  1835. // dataItem := new(data_manage.EdbInfoSearchData)
  1836. // dataItem.Value = saveVal
  1837. // dataItem.DataTime = dateTime
  1838. // dataList = append(dataList, dataItem)
  1839. // if len(dataList) >= 10 {
  1840. // break
  1841. // }
  1842. // }
  1843. //}
  1844. //searchItem.StockList = stockList
  1845. stockList := make([]*data_manage.StockInfo, 0)
  1846. edbCodeArr := strings.Split(edbCode, ",")
  1847. for _, v := range edbCodeArr {
  1848. indexCode := utils.WindDbWsd + stockCode + v
  1849. dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
  1850. if err != nil && err.Error() != utils.ErrNoRow() {
  1851. br.Msg = "获取失败"
  1852. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  1853. return
  1854. }
  1855. stockInfo := new(data_manage.StockInfo)
  1856. stockInfo.StockCode = stockCode
  1857. stockInfo.EdbCode = v
  1858. stockInfo.DataList = dataList
  1859. stockList = append(stockList, stockInfo)
  1860. }
  1861. searchItem.StockList = stockList
  1862. } else if source == utils.DATA_SOURCE_THS {
  1863. stockList := make([]*data_manage.StockInfo, 0)
  1864. edbCodeArr := strings.Split(edbCode, ",")
  1865. for _, v := range edbCodeArr {
  1866. indexCode := utils.ThsDs + stockCode + v
  1867. dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
  1868. if err != nil && err.Error() != utils.ErrNoRow() {
  1869. br.Msg = "获取失败"
  1870. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  1871. return
  1872. }
  1873. stockInfo := new(data_manage.StockInfo)
  1874. stockInfo.StockCode = stockCode
  1875. stockInfo.EdbCode = v
  1876. stockInfo.DataList = dataList
  1877. stockList = append(stockList, stockInfo)
  1878. }
  1879. searchItem.StockList = stockList
  1880. } else {
  1881. br.Msg = "来源错误"
  1882. br.ErrMsg = "来源错误"
  1883. return
  1884. }
  1885. } else {
  1886. dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1887. if err != nil && err.Error() != utils.ErrNoRow() {
  1888. br.Msg = "获取失败"
  1889. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  1890. return
  1891. }
  1892. searchItem.DataList = dataList
  1893. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1894. if err != nil && err.Error() != utils.ErrNoRow() {
  1895. br.Msg = "获取失败"
  1896. br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
  1897. return
  1898. }
  1899. searchItem.EdbCode = edbCode
  1900. searchItem.DataList = dataList
  1901. if edbInfoMaxAndMinInfo != nil {
  1902. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1903. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1904. }
  1905. //edb指标信息
  1906. edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode)
  1907. if edbInfoItem != nil {
  1908. searchItem.EdbName = edbInfoItem.EdbName
  1909. }
  1910. }
  1911. }
  1912. resp.Status = 2
  1913. resp.SearchItem = searchItem
  1914. }
  1915. //如果不在指标库中,且不是新增
  1916. if !isInEdb && !isAdd {
  1917. if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 {
  1918. br.Msg = "目标指标无有效值,请重新搜索"
  1919. br.Data = resp
  1920. return
  1921. }
  1922. }
  1923. br.Ret = 200
  1924. br.Success = true
  1925. br.Msg = "获取成功"
  1926. br.Data = resp
  1927. }
  1928. // EdbInfoList
  1929. // @Title 指标列表接口
  1930. // @Description 指标列表接口
  1931. // @Param PageSize query int true "每页数据条数"
  1932. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1933. // @Param EdbInfoId query int true "指标id"
  1934. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  1935. // @Success 200 {object} data_manage.EdbInfoListResp
  1936. // @router /edb_info/list [get]
  1937. func (this *EdbInfoController) EdbInfoList() {
  1938. br := new(models.BaseResponse).Init()
  1939. defer func() {
  1940. this.Data["json"] = br
  1941. this.ServeJSON()
  1942. }()
  1943. edbInfoId, _ := this.GetInt("EdbInfoId")
  1944. keyWord := this.GetString("KeyWord")
  1945. pageSize, _ := this.GetInt("PageSize")
  1946. currentIndex, _ := this.GetInt("CurrentIndex")
  1947. var total int
  1948. page := paging.GetPaging(currentIndex, pageSize, total)
  1949. var startSize int
  1950. if pageSize <= 0 {
  1951. pageSize = utils.PageSize20
  1952. }
  1953. if currentIndex <= 0 {
  1954. currentIndex = 1
  1955. }
  1956. startSize = paging.StartIndex(currentIndex, pageSize)
  1957. var condition string
  1958. var pars []interface{}
  1959. //if edbInfoId <= 0 && keyWord == "" {
  1960. // br.Msg = "参数错误"
  1961. // return
  1962. //}
  1963. // 指标类型,0:普通指标,1:预测指标
  1964. condition += " AND edb_info_type=? "
  1965. pars = append(pars, 0)
  1966. if edbInfoId > 0 {
  1967. condition += " AND edb_info_id=? "
  1968. pars = append(pars, edbInfoId)
  1969. // 获取当前账号的不可见指标配置
  1970. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1971. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId)
  1972. if err != nil && err.Error() != utils.ErrNoRow() {
  1973. br.Msg = "获取失败"
  1974. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  1975. return
  1976. }
  1977. if conf != nil {
  1978. br.Msg = "无权限,请联系管理员"
  1979. br.IsSendEmail = false
  1980. return
  1981. }
  1982. }
  1983. if keyWord != "" {
  1984. condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  1985. //pars = append(pars, keyWord)
  1986. //pars = append(pars, keyWord)
  1987. }
  1988. resp := new(data_manage.EdbInfoListResp)
  1989. if condition == "" {
  1990. item := new(data_manage.EdbInfoList)
  1991. resp.Paging = page
  1992. resp.Item = item
  1993. br.Ret = 200
  1994. br.Success = true
  1995. br.Msg = "获取成功"
  1996. return
  1997. }
  1998. //获取指标信息
  1999. edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2000. if err != nil && err.Error() != utils.ErrNoRow() {
  2001. br.Success = true
  2002. br.Msg = "获取指标信息失败"
  2003. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2004. return
  2005. }
  2006. if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  2007. item := new(data_manage.EdbInfoList)
  2008. resp.Paging = page
  2009. resp.Item = item
  2010. br.Ret = 200
  2011. br.Success = true
  2012. br.Msg = "获取成功"
  2013. return
  2014. }
  2015. //获取英文频度
  2016. edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
  2017. //查询目录
  2018. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId)
  2019. if err != nil {
  2020. br.Msg = err.Error()
  2021. br.ErrMsg = errMsg
  2022. return
  2023. }
  2024. // 权限校验
  2025. {
  2026. var currClassify *data_manage.EdbClassifyIdItems
  2027. for _, v := range classifyList {
  2028. if edbInfoItem.ClassifyId == v.ClassifyId {
  2029. currClassify = v
  2030. break
  2031. }
  2032. }
  2033. if currClassify != nil {
  2034. edbInfoItem.HaveOperaAuth, err = data_manage_permission.CheckEdbPermission(edbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfoItem.EdbInfoId, edbInfoItem.ClassifyId)
  2035. if err != nil {
  2036. br.Msg = err.Error()
  2037. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2038. return
  2039. }
  2040. }
  2041. }
  2042. // 按钮校验
  2043. button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType, edbInfoItem.HaveOperaAuth)
  2044. button.AddButton = false
  2045. edbInfoItem.Button = button
  2046. edbInfoItem.DataList = make([]*data_manage.EdbData, 0)
  2047. // 如果有数据权限,那么就去获取指标数据
  2048. if edbInfoItem.HaveOperaAuth {
  2049. var dataCondition string
  2050. var dataPars []interface{}
  2051. dataCondition += ` AND edb_info_id=? `
  2052. dataPars = append(dataPars, edbInfoItem.EdbInfoId)
  2053. if edbInfoItem.SubSource == utils.DATA_SUB_SOURCE_DATE {
  2054. if edbInfoItem.Source == utils.DATA_SOURCE_WIND {
  2055. dataCount, err := data_manage.GetEdbWsdDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
  2056. if err != nil && err.Error() != utils.ErrNoRow() {
  2057. br.Msg = "获取指标信息失败"
  2058. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  2059. return
  2060. }
  2061. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  2062. dataList, err := data_manage.GetEdbWsdDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
  2063. if err != nil {
  2064. br.Msg = "获取指标信息失败"
  2065. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2066. return
  2067. }
  2068. edbInfoItem.DataList = dataList
  2069. } else if edbInfoItem.Source == utils.DATA_SOURCE_THS {
  2070. dataCount, err := data_manage.GetTHsDsDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
  2071. if err != nil && err.Error() != utils.ErrNoRow() {
  2072. br.Msg = "获取指标信息失败"
  2073. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  2074. return
  2075. }
  2076. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  2077. dataList, err := data_manage.GetThsDsDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
  2078. if err != nil {
  2079. br.Msg = "获取指标信息失败"
  2080. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2081. return
  2082. }
  2083. edbInfoItem.DataList = dataList
  2084. } else {
  2085. br.Msg = "指标数据源id错误"
  2086. br.ErrMsg = "指标数据源id错误"
  2087. return
  2088. }
  2089. } else {
  2090. dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source, edbInfoItem.SubSource)
  2091. if err != nil && err.Error() != utils.ErrNoRow() {
  2092. br.Msg = "获取指标信息失败"
  2093. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  2094. return
  2095. }
  2096. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  2097. dataList, err := data_manage.GetEdbDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, edbInfoItem.SubSource, pageSize, startSize)
  2098. if err != nil {
  2099. br.Msg = "获取指标信息失败"
  2100. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2101. return
  2102. }
  2103. edbInfoItem.DataList = dataList
  2104. }
  2105. }
  2106. // 获取指标插入配置
  2107. {
  2108. edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId)
  2109. if err != nil && err.Error() != utils.ErrNoRow() {
  2110. br.Msg = "获取指标信息失败"
  2111. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2112. return
  2113. }
  2114. if edbDataInsertConfig != nil {
  2115. edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate)
  2116. edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate)
  2117. edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value
  2118. }
  2119. }
  2120. //是否展示英文标识
  2121. edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn)
  2122. resp.Paging = page
  2123. resp.Item = edbInfoItem
  2124. resp.ClassifyList = classifyList
  2125. br.Ret = 200
  2126. br.Success = true
  2127. br.Msg = "获取成功"
  2128. br.Data = resp
  2129. }
  2130. // EdbInfoAdd
  2131. // @Title 新增指标接口
  2132. // @Description 新增指标接口
  2133. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  2134. // @Success Ret=200 保存成功
  2135. // @router /edb_info/add [post]
  2136. func (this *EdbInfoController) EdbInfoAdd() {
  2137. br := new(models.BaseResponse).Init()
  2138. defer func() {
  2139. this.Data["json"] = br
  2140. this.ServeJSON()
  2141. }()
  2142. sysUser := this.SysUser
  2143. if sysUser == nil {
  2144. br.Msg = "请登录"
  2145. br.ErrMsg = "请登录,SysUser Is Empty"
  2146. br.Ret = 408
  2147. return
  2148. }
  2149. deleteCache := true
  2150. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  2151. defer func() {
  2152. if deleteCache {
  2153. utils.Rc.Delete(cacheKey)
  2154. }
  2155. }()
  2156. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  2157. deleteCache = false
  2158. br.Msg = "系统处理中,请稍后重试!"
  2159. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  2160. return
  2161. }
  2162. var req data_manage.AddEdbInfoReq
  2163. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2164. if err != nil {
  2165. br.Msg = "参数解析异常!"
  2166. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2167. return
  2168. }
  2169. source := req.Source
  2170. if source <= 0 {
  2171. br.Msg = "无效的数据来源"
  2172. return
  2173. }
  2174. req.EdbName = strings.Trim(req.EdbName, " ")
  2175. req.EdbCode = strings.Trim(req.EdbCode, " ")
  2176. if req.EdbCode == "" {
  2177. br.Msg = "指标ID不能为空"
  2178. return
  2179. }
  2180. if req.EdbName == "" {
  2181. br.Msg = "指标名称不能为空"
  2182. return
  2183. }
  2184. if req.Frequency == "" {
  2185. br.Msg = "频率不能为空"
  2186. return
  2187. }
  2188. if req.Unit == "" {
  2189. br.Msg = "单位不能为空"
  2190. return
  2191. }
  2192. if req.ClassifyId <= 0 {
  2193. br.Msg = "请选择分类"
  2194. return
  2195. }
  2196. //if req.StartDate == "" || req.EndDate == "" {
  2197. // br.Msg = "日期不能为空"
  2198. // return
  2199. //}
  2200. // 兼容钢联与钢联化工数据
  2201. if source == utils.DATA_SOURCE_GL {
  2202. // 如果是钢联的话,那么就先判断是不是存在钢联化工
  2203. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
  2204. if err != nil {
  2205. if err.Error() != utils.ErrNoRow() {
  2206. br.Msg = "获取失败"
  2207. br.ErrMsg = "获取失败,Err:" + err.Error()
  2208. return
  2209. }
  2210. }
  2211. if tmpInfo != nil {
  2212. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  2213. req.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  2214. }
  2215. }
  2216. // 指标入库
  2217. 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)
  2218. if err != nil {
  2219. br.Msg = "保存失败"
  2220. if errMsg != `` {
  2221. br.Msg = errMsg
  2222. }
  2223. br.ErrMsg = err.Error()
  2224. br.IsSendEmail = isSendEmail
  2225. return
  2226. }
  2227. // 试用平台更新用户累计新增指标数
  2228. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  2229. if e != nil {
  2230. br.Msg = "操作失败"
  2231. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  2232. return
  2233. }
  2234. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  2235. go func() {
  2236. var r etaTrialService.EtaTrialUserReq
  2237. r.Mobile = adminItem.Mobile
  2238. _, _ = etaTrialService.UpdateUserIndexNum(r)
  2239. }()
  2240. }
  2241. //新增操作日志
  2242. {
  2243. // 添加钢联指标更新日志
  2244. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2245. go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
  2246. }
  2247. edbLog := new(data_manage.EdbInfoLog)
  2248. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2249. edbLog.SourceName = edbInfo.SourceName
  2250. edbLog.Source = edbInfo.Source
  2251. edbLog.EdbCode = edbInfo.EdbCode
  2252. edbLog.EdbName = edbInfo.EdbName
  2253. edbLog.ClassifyId = edbInfo.ClassifyId
  2254. edbLog.SysUserId = sysUser.AdminId
  2255. edbLog.SysUserRealName = sysUser.RealName
  2256. edbLog.CreateTime = time.Now()
  2257. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2258. edbLog.Status = "新增指标"
  2259. edbLog.Method = this.Ctx.Input.URI()
  2260. go data_manage.AddEdbInfoLog(edbLog)
  2261. }
  2262. // 更新es
  2263. go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  2264. resp := new(data_manage.AddEdbInfoResp)
  2265. resp.EdbInfoId = edbInfo.EdbInfoId
  2266. resp.UniqueCode = edbInfo.UniqueCode
  2267. br.Ret = 200
  2268. br.Success = true
  2269. br.Msg = "保存成功"
  2270. br.Data = resp
  2271. br.IsAddLog = true
  2272. }
  2273. // EdbInfoEdit
  2274. // @Title 编辑指标接口
  2275. // @Description 编辑指标接口
  2276. // @Success 200 {object} data_manage.EditEdbInfoReq
  2277. // @router /edb_info/edit [post]
  2278. func (this *EdbInfoController) EdbInfoEdit() {
  2279. br := new(models.BaseResponse).Init()
  2280. defer func() {
  2281. this.Data["json"] = br
  2282. this.ServeJSON()
  2283. }()
  2284. sysUser := this.SysUser
  2285. if sysUser == nil {
  2286. br.Msg = "请登录"
  2287. br.ErrMsg = "请登录,SysUser Is Empty"
  2288. br.Ret = 408
  2289. return
  2290. }
  2291. var req data_manage.EditEdbInfoReq
  2292. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2293. if err != nil {
  2294. br.Msg = "参数解析异常!"
  2295. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2296. return
  2297. }
  2298. req.EdbName = strings.Trim(req.EdbName, " ")
  2299. if req.EdbInfoId <= 0 {
  2300. br.Msg = "参数错误"
  2301. br.ErrMsg = "指标id小于等于0"
  2302. return
  2303. }
  2304. if req.EdbName == "" {
  2305. br.Msg = "指标名称不能为空"
  2306. return
  2307. }
  2308. if req.Frequency == "" {
  2309. br.Msg = "频率不能为空"
  2310. return
  2311. }
  2312. if req.Unit == "" {
  2313. br.Msg = "单位不能为空"
  2314. return
  2315. }
  2316. if req.ClassifyId <= 0 {
  2317. br.Msg = "请选择分类"
  2318. return
  2319. }
  2320. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2321. if err != nil {
  2322. br.Msg = "修改失败"
  2323. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2324. return
  2325. }
  2326. // 记录旧的指标基本信息
  2327. oldEdbName := edbInfo.EdbName
  2328. oldFrequency := edbInfo.Frequency
  2329. oldUnit := edbInfo.Unit
  2330. var haveOperaAuth bool
  2331. // 权限校验
  2332. {
  2333. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
  2334. if err != nil {
  2335. br.Msg = err.Error()
  2336. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2337. return
  2338. }
  2339. }
  2340. // 编辑权限校验
  2341. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  2342. if !button.OpButton {
  2343. br.Msg = "无权限操作"
  2344. br.IsSendEmail = false
  2345. return
  2346. }
  2347. //判断指标名称是否存在
  2348. var condition string
  2349. var pars []interface{}
  2350. condition += " AND edb_info_id<>? "
  2351. pars = append(pars, req.EdbInfoId)
  2352. //condition += " AND source=? "
  2353. //pars = append(pars, edbInfo.Source)
  2354. updateCols := make([]string, 0)
  2355. switch this.Lang {
  2356. case utils.EnLangVersion:
  2357. condition += " AND edb_name_en = ? "
  2358. edbInfo.EdbNameEn = req.EdbName
  2359. edbInfo.Frequency = req.Frequency
  2360. edbInfo.UnitEn = req.Unit
  2361. edbInfo.ClassifyId = req.ClassifyId
  2362. updateCols = append(updateCols, "EdbNameEn", "Frequency", "UnitEn", "ClassifyId")
  2363. default:
  2364. condition += " AND edb_name=? "
  2365. edbInfo.EdbName = req.EdbName
  2366. edbInfo.EdbNameSource = req.EdbName
  2367. edbInfo.Frequency = req.Frequency
  2368. edbInfo.Unit = req.Unit
  2369. edbInfo.ClassifyId = req.ClassifyId
  2370. updateCols = append(updateCols, "EdbNameEn", "EdbNameSource", "Frequency", "UnitEn", "ClassifyId")
  2371. }
  2372. pars = append(pars, req.EdbName)
  2373. count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
  2374. if err != nil {
  2375. br.Msg = "判断指标名称是否存在失败"
  2376. br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error()
  2377. return
  2378. }
  2379. if count > 0 {
  2380. br.Msg = "指标名称已存在,请重新填写"
  2381. br.ErrMsg = "指标名称已存在,请重新填写"
  2382. br.IsSendEmail = false
  2383. return
  2384. }
  2385. if len(updateCols) > 0 {
  2386. err = edbInfo.Update(updateCols)
  2387. if err != nil {
  2388. br.Msg = "保存失败"
  2389. br.ErrMsg = "修改失败,Err:" + err.Error()
  2390. return
  2391. }
  2392. }
  2393. //处理同名指标
  2394. //{
  2395. // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName)
  2396. // if err != nil {
  2397. // br.Msg = "保存失败"
  2398. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2399. // return
  2400. // }
  2401. // if len(edbNameList) >= 2 {
  2402. // for _, v := range edbNameList {
  2403. // edbName := v.EdbName + "(" + v.SourceName + ")"
  2404. // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
  2405. // if err != nil {
  2406. // br.Msg = "保存失败"
  2407. // br.ErrMsg = "修改指标名称失败,Err:" + err.Error()
  2408. // return
  2409. // }
  2410. // }
  2411. // }
  2412. //}
  2413. // 新增保存记录日志
  2414. oldEdbInfo := new(data_manage.EdbInfo)
  2415. oldEdbInfo.EdbInfoId = edbInfo.EdbInfoId
  2416. oldEdbInfo.EdbName = oldEdbName
  2417. oldEdbInfo.Frequency = oldFrequency
  2418. oldEdbInfo.Unit = oldUnit
  2419. newEdbInfoRecord := new(data_manage.EdbInfoEditRecord)
  2420. newEdbInfoRecord.EdbName = req.EdbName
  2421. newEdbInfoRecord.Frequency = req.Frequency
  2422. newEdbInfoRecord.Unit = req.Unit
  2423. newEdbInfoRecord.OperateUserId = sysUser.AdminId
  2424. newEdbInfoRecord.OperateUserRealName = sysUser.RealName
  2425. go data.AddEditEdbInfoRcord(oldEdbInfo, newEdbInfoRecord)
  2426. //新增操作日志
  2427. {
  2428. edbLog := new(data_manage.EdbInfoLog)
  2429. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2430. edbLog.SourceName = edbInfo.SourceName
  2431. edbLog.Source = edbInfo.Source
  2432. edbLog.EdbCode = edbInfo.EdbCode
  2433. edbLog.EdbName = edbInfo.EdbName
  2434. edbLog.ClassifyId = edbInfo.ClassifyId
  2435. edbLog.SysUserId = sysUser.AdminId
  2436. edbLog.SysUserRealName = sysUser.RealName
  2437. edbLog.CreateTime = time.Now()
  2438. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2439. edbLog.Status = "编辑指标"
  2440. edbLog.Method = this.Ctx.Input.URI()
  2441. go data_manage.AddEdbInfoLog(edbLog)
  2442. }
  2443. //添加es
  2444. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2445. switch this.Lang {
  2446. case utils.EnLangVersion:
  2447. // 修改关联的预测指标基础信息
  2448. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
  2449. default:
  2450. // 修改关联的预测指标基础信息
  2451. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, req.Frequency, req.Unit)
  2452. }
  2453. // 添加钢联指标更新日志
  2454. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2455. if edbInfo.EdbName != req.EdbName || edbInfo.Frequency != req.Frequency || edbInfo.Unit != req.Unit {
  2456. go data_stat.AddEdbInfoUpdateLog(req.EdbInfoId, 1, "", sysUser, 1)
  2457. }
  2458. }
  2459. br.Ret = 200
  2460. br.Success = true
  2461. br.Msg = "保存成功"
  2462. br.IsAddLog = true
  2463. }
  2464. // EdbEnInfoEdit
  2465. // @Title 编辑指标英文信息接口
  2466. // @Description 编辑指标英文信息接口
  2467. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  2468. // @router /edb_info/en/edit [post]
  2469. func (this *EdbInfoController) EdbEnInfoEdit() {
  2470. br := new(models.BaseResponse).Init()
  2471. defer func() {
  2472. this.Data["json"] = br
  2473. this.ServeJSON()
  2474. }()
  2475. sysUser := this.SysUser
  2476. if sysUser == nil {
  2477. br.Msg = "请登录"
  2478. br.ErrMsg = "请登录,SysUser Is Empty"
  2479. br.Ret = 408
  2480. return
  2481. }
  2482. var req data_manage.EditEdbEnInfoReq
  2483. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2484. if err != nil {
  2485. br.Msg = "参数解析异常!"
  2486. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2487. return
  2488. }
  2489. req.EdbNameEn = strings.Trim(req.EdbNameEn, " ")
  2490. req.UnitEn = strings.Trim(req.UnitEn, " ")
  2491. if req.EdbInfoId <= 0 {
  2492. br.Msg = "参数错误"
  2493. br.ErrMsg = "指标id小于等于0"
  2494. return
  2495. }
  2496. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2497. if err != nil {
  2498. br.Msg = "获取指标信息失败"
  2499. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2500. return
  2501. }
  2502. if req.EdbNameEn != "" {
  2503. //判断指标名称是否存在
  2504. var condition string
  2505. var pars []interface{}
  2506. condition += " AND edb_info_id<>? "
  2507. pars = append(pars, req.EdbInfoId)
  2508. /*condition += " AND source=? "
  2509. pars = append(pars, edbInfo.Source)*/
  2510. condition += " AND edb_name_en=? "
  2511. pars = append(pars, req.EdbNameEn)
  2512. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2513. if err != nil {
  2514. if err.Error() != utils.ErrNoRow() {
  2515. br.Msg = "判断英文指标名称是否存在失败"
  2516. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2517. return
  2518. }
  2519. }
  2520. if err == nil && edbExist.EdbInfoId > 0 {
  2521. br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在"
  2522. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2523. br.IsSendEmail = false
  2524. return
  2525. }
  2526. }
  2527. err = data_manage.ModifyEdbEnInfo(&req)
  2528. if err != nil {
  2529. br.Msg = "保存失败"
  2530. br.ErrMsg = "修改失败,Err:" + err.Error()
  2531. return
  2532. }
  2533. //新增操作日志
  2534. {
  2535. edbLog := new(data_manage.EdbInfoLog)
  2536. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2537. edbLog.SourceName = edbInfo.SourceName
  2538. edbLog.Source = edbInfo.Source
  2539. edbLog.EdbCode = edbInfo.EdbCode
  2540. edbLog.EdbName = edbInfo.EdbName
  2541. edbLog.ClassifyId = edbInfo.ClassifyId
  2542. edbLog.SysUserId = sysUser.AdminId
  2543. edbLog.SysUserRealName = sysUser.RealName
  2544. edbLog.CreateTime = time.Now()
  2545. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2546. edbLog.Status = "编辑指标英文信息"
  2547. edbLog.Method = this.Ctx.Input.URI()
  2548. go data_manage.AddEdbInfoLog(edbLog)
  2549. }
  2550. //添加es
  2551. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2552. // 修改关联的预测指标基础信息
  2553. if edbInfo.EdbInfoType == 0 {
  2554. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.UnitEn)
  2555. }
  2556. br.Ret = 200
  2557. br.Success = true
  2558. br.Msg = "保存成功"
  2559. br.IsAddLog = true
  2560. }
  2561. // EdbInfoBaseEdit
  2562. // @Title 编辑指标基础信息接口
  2563. // @Description 编辑指标基础信息接口
  2564. // @Success 200 {object} data_manage.EditEdbBaseInfoReq
  2565. // @router /edb_info/base/edit [post]
  2566. func (this *EdbInfoController) EdbInfoBaseEdit() {
  2567. br := new(models.BaseResponse).Init()
  2568. defer func() {
  2569. this.Data["json"] = br
  2570. this.ServeJSON()
  2571. }()
  2572. sysUser := this.SysUser
  2573. if sysUser == nil {
  2574. br.Msg = "请登录"
  2575. br.ErrMsg = "请登录,SysUser Is Empty"
  2576. br.Ret = 408
  2577. return
  2578. }
  2579. var req data_manage.EditEdbBaseInfoReq
  2580. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2581. if err != nil {
  2582. br.Msg = "参数解析异常!"
  2583. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2584. return
  2585. }
  2586. req.EdbName = strings.Trim(req.EdbName, " ")
  2587. req.Unit = strings.Trim(req.Unit, " ")
  2588. if req.EdbInfoId <= 0 {
  2589. br.Msg = "参数错误"
  2590. br.ErrMsg = "指标id小于等于0"
  2591. return
  2592. }
  2593. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2594. if err != nil {
  2595. br.Msg = "获取指标信息失败"
  2596. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2597. return
  2598. }
  2599. updateCols := make([]string, 0)
  2600. if req.EdbName != "" {
  2601. //判断指标名称是否存在
  2602. var condition string
  2603. var pars []interface{}
  2604. condition += " AND edb_info_id<>? "
  2605. pars = append(pars, req.EdbInfoId)
  2606. /*condition += " AND source=? "
  2607. pars = append(pars, edbInfo.Source)*/
  2608. switch this.Lang {
  2609. case utils.EnLangVersion:
  2610. condition += " AND edb_name_en = ? "
  2611. edbInfo.EdbNameEn = req.EdbName
  2612. edbInfo.UnitEn = req.Unit
  2613. edbInfo.ModifyTime = time.Now()
  2614. updateCols = append(updateCols, "EdbNameEn", "UnitEn", "ModifyTime")
  2615. default:
  2616. condition += " AND edb_name = ? "
  2617. edbInfo.EdbName = req.EdbName
  2618. edbInfo.EdbNameSource = req.EdbName
  2619. edbInfo.Unit = req.Unit
  2620. edbInfo.ModifyTime = time.Now()
  2621. updateCols = append(updateCols, "EdbName", "EdbNameSource", "Unit", "ModifyTime")
  2622. }
  2623. pars = append(pars, req.EdbName)
  2624. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2625. if err != nil {
  2626. if err.Error() != utils.ErrNoRow() {
  2627. br.Msg = "判断英文指标名称是否存在失败"
  2628. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2629. return
  2630. }
  2631. }
  2632. if err == nil && edbExist.EdbInfoId > 0 {
  2633. br.Msg = edbExist.EdbName + ":" + req.EdbName + "指标名称已存在"
  2634. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2635. br.IsSendEmail = false
  2636. return
  2637. }
  2638. }
  2639. if len(updateCols) > 0 {
  2640. err = edbInfo.Update(updateCols)
  2641. if err != nil {
  2642. br.Msg = "保存失败"
  2643. br.ErrMsg = "修改失败,Err:" + err.Error()
  2644. return
  2645. }
  2646. }
  2647. //新增操作日志
  2648. {
  2649. edbLog := new(data_manage.EdbInfoLog)
  2650. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2651. edbLog.SourceName = edbInfo.SourceName
  2652. edbLog.Source = edbInfo.Source
  2653. edbLog.EdbCode = edbInfo.EdbCode
  2654. edbLog.EdbName = edbInfo.EdbName
  2655. edbLog.ClassifyId = edbInfo.ClassifyId
  2656. edbLog.SysUserId = sysUser.AdminId
  2657. edbLog.SysUserRealName = sysUser.RealName
  2658. edbLog.CreateTime = time.Now()
  2659. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2660. edbLog.Status = "编辑指标英文信息"
  2661. edbLog.Method = this.Ctx.Input.URI()
  2662. go data_manage.AddEdbInfoLog(edbLog)
  2663. }
  2664. //添加es
  2665. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2666. // 修改关联的预测指标基础信息
  2667. if edbInfo.EdbInfoType == 0 {
  2668. switch this.Lang {
  2669. case utils.EnLangVersion:
  2670. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
  2671. default:
  2672. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, edbInfo.Frequency, req.Unit)
  2673. }
  2674. }
  2675. br.Ret = 200
  2676. br.Success = true
  2677. br.Msg = "保存成功"
  2678. br.IsAddLog = true
  2679. }
  2680. // EdbInfoNewest
  2681. // @Title 获取最新指标接口
  2682. // @Description 获取最新指标接口
  2683. // @Success 200 {object} data_manage.EdbInfoList
  2684. // @router /edb_info/newest [get]
  2685. func (this *EdbInfoController) EdbInfoNewest() {
  2686. br := new(models.BaseResponse).Init()
  2687. defer func() {
  2688. this.Data["json"] = br
  2689. this.ServeJSON()
  2690. }()
  2691. item, err := data_manage.GetEdbInfoByNewest()
  2692. if err != nil && err.Error() != utils.ErrNoRow() {
  2693. br.Msg = "获取最新指标失败"
  2694. br.ErrMsg = "获取最新指标失败,Err:" + err.Error()
  2695. return
  2696. }
  2697. br.Ret = 200
  2698. br.Success = true
  2699. br.Msg = "获取成功"
  2700. br.Data = item
  2701. }
  2702. // EdbInfoRefresh
  2703. // @Title 指标刷新接口
  2704. // @Description 指标刷新接口
  2705. // @Param EdbInfoId query int true "指标id"
  2706. // @Success Ret=200 刷新成功
  2707. // @router /edb_info/refresh [get]
  2708. func (this *EdbInfoController) EdbInfoRefresh() {
  2709. br := new(models.BaseResponse).Init()
  2710. defer func() {
  2711. this.Data["json"] = br
  2712. this.ServeJSON()
  2713. }()
  2714. sysUser := this.SysUser
  2715. if sysUser == nil {
  2716. br.Msg = "请登录"
  2717. br.ErrMsg = "请登录,SysUser Is Empty"
  2718. br.Ret = 408
  2719. return
  2720. }
  2721. edbInfoId, _ := this.GetInt("EdbInfoId")
  2722. if edbInfoId <= 0 {
  2723. br.Msg = "参数错误"
  2724. br.ErrMsg = "参数错误"
  2725. return
  2726. }
  2727. _, err := data_manage.GetEdbInfoById(edbInfoId)
  2728. if err != nil {
  2729. if err.Error() == utils.ErrNoRow() {
  2730. br.Msg = "数据已被删除,请刷新页面"
  2731. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2732. return
  2733. }
  2734. br.Msg = "刷新失败"
  2735. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2736. return
  2737. }
  2738. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false, false)
  2739. if err != nil {
  2740. br.Msg = "刷新失败"
  2741. br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error()
  2742. return
  2743. }
  2744. br.Ret = 200
  2745. br.Msg = "刷新成功"
  2746. if isAsync {
  2747. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  2748. }
  2749. br.Success = true
  2750. br.IsAddLog = true
  2751. }
  2752. // EdbInfoMove
  2753. // @Title 移动指标接口
  2754. // @Description 移动指标接口
  2755. // @Success 200 {object} data_manage.MoveEdbInfoReq
  2756. // @router /edb_info/move [post]
  2757. func (this *EdbInfoController) EdbInfoMove() {
  2758. br := new(models.BaseResponse).Init()
  2759. defer func() {
  2760. this.Data["json"] = br
  2761. this.ServeJSON()
  2762. }()
  2763. sysUser := this.SysUser
  2764. if sysUser == nil {
  2765. br.Msg = "请登录"
  2766. br.ErrMsg = "请登录,SysUser Is Empty"
  2767. br.Ret = 408
  2768. return
  2769. }
  2770. var req data_manage.MoveEdbInfoReq
  2771. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2772. if err != nil {
  2773. br.Msg = "参数解析异常!"
  2774. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2775. return
  2776. }
  2777. if req.EdbInfoId <= 0 {
  2778. br.Msg = "参数错误"
  2779. br.ErrMsg = "指标id小于等于0"
  2780. return
  2781. }
  2782. if req.ClassifyId <= 0 {
  2783. br.Msg = "请选择分类"
  2784. return
  2785. }
  2786. //判断分类是否存在
  2787. count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId)
  2788. if count <= 0 {
  2789. br.Msg = "分类已被删除,不可移动,请刷新页面"
  2790. return
  2791. }
  2792. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2793. if err != nil {
  2794. br.Msg = "移动失败"
  2795. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2796. return
  2797. }
  2798. var haveOperaAuth bool
  2799. // 权限校验
  2800. {
  2801. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.IsJoinPermission, edbInfo.EdbInfoId, edbInfo.ClassifyId, this.SysUser.AdminId)
  2802. if err != nil {
  2803. br.Msg = err.Error()
  2804. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2805. return
  2806. }
  2807. }
  2808. // 移动权限校验
  2809. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  2810. if !button.MoveButton {
  2811. br.Msg = "无权限操作"
  2812. br.IsSendEmail = false
  2813. return
  2814. }
  2815. //如果改变了分类,那么移动该指标数据
  2816. if edbInfo.ClassifyId != req.ClassifyId {
  2817. err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId)
  2818. if err != nil {
  2819. br.Msg = "移动失败"
  2820. br.ErrMsg = "移动指标失败,Err:" + err.Error()
  2821. return
  2822. }
  2823. }
  2824. updateCol := make([]string, 0)
  2825. //如果有传入 上一个兄弟节点分类id
  2826. if req.PrevEdbInfoId > 0 {
  2827. prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId)
  2828. if err != nil {
  2829. br.Msg = "移动失败"
  2830. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  2831. return
  2832. }
  2833. //如果是移动在两个兄弟节点之间
  2834. if req.NextEdbInfoId > 0 {
  2835. //下一个兄弟节点
  2836. nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId)
  2837. if err != nil {
  2838. br.Msg = "移动失败"
  2839. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  2840. return
  2841. }
  2842. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  2843. if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort {
  2844. //变更兄弟节点的排序
  2845. updateSortStr := `sort + 2`
  2846. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2847. } else {
  2848. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  2849. if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 {
  2850. //变更兄弟节点的排序
  2851. updateSortStr := `sort + 1`
  2852. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2853. }
  2854. }
  2855. }
  2856. edbInfo.Sort = prevEdbInfo.Sort + 1
  2857. edbInfo.ModifyTime = time.Now()
  2858. updateCol = append(updateCol, "Sort", "ModifyTime")
  2859. } else {
  2860. firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId)
  2861. if err != nil && err.Error() != utils.ErrNoRow() {
  2862. br.Msg = "移动失败"
  2863. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2864. return
  2865. }
  2866. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2867. if firstClassify != nil && firstClassify.Sort == 0 {
  2868. updateSortStr := ` sort + 1 `
  2869. _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr)
  2870. }
  2871. edbInfo.Sort = 0 //那就是排在第一位
  2872. edbInfo.ModifyTime = time.Now()
  2873. updateCol = append(updateCol, "Sort", "ModifyTime")
  2874. }
  2875. //更新
  2876. if len(updateCol) > 0 {
  2877. err = edbInfo.Update(updateCol)
  2878. if err != nil {
  2879. br.Msg = "移动失败"
  2880. br.ErrMsg = "修改失败,Err:" + err.Error()
  2881. return
  2882. }
  2883. }
  2884. if err != nil {
  2885. br.Msg = "移动失败"
  2886. br.ErrMsg = "修改失败,Err:" + err.Error()
  2887. return
  2888. }
  2889. //新增操作日志
  2890. {
  2891. edbLog := new(data_manage.EdbInfoLog)
  2892. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2893. edbLog.SourceName = edbInfo.SourceName
  2894. edbLog.Source = edbInfo.Source
  2895. edbLog.EdbCode = edbInfo.EdbCode
  2896. edbLog.EdbName = edbInfo.EdbName
  2897. edbLog.ClassifyId = edbInfo.ClassifyId
  2898. edbLog.SysUserId = sysUser.AdminId
  2899. edbLog.SysUserRealName = sysUser.RealName
  2900. edbLog.CreateTime = time.Now()
  2901. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2902. edbLog.Status = "移动指标"
  2903. edbLog.Method = this.Ctx.Input.URI()
  2904. go data_manage.AddEdbInfoLog(edbLog)
  2905. }
  2906. br.Ret = 200
  2907. br.Success = true
  2908. br.Msg = "移动成功"
  2909. }
  2910. // EdbInfoDetail
  2911. // @Title 获取指标详情
  2912. // @Description 获取指标详情接口
  2913. // @Param EdbInfoId query int true "指标id"
  2914. // @Success 200 {object} data_manage.EdbInfo
  2915. // @router /edb_info/detail [get]
  2916. func (this *EdbInfoController) EdbInfoDetail() {
  2917. br := new(models.BaseResponse).Init()
  2918. defer func() {
  2919. this.Data["json"] = br
  2920. this.ServeJSON()
  2921. }()
  2922. sysUser := this.SysUser
  2923. if sysUser == nil {
  2924. br.Msg = "请登录"
  2925. br.ErrMsg = "请登录,SysUser Is Empty"
  2926. br.Ret = 408
  2927. return
  2928. }
  2929. edbInfoId, _ := this.GetInt("EdbInfoId")
  2930. if edbInfoId <= 0 {
  2931. br.Msg = "参数错误"
  2932. br.ErrMsg = "参数错误"
  2933. return
  2934. }
  2935. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  2936. if err != nil {
  2937. br.Msg = "获取失败"
  2938. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2939. return
  2940. }
  2941. var resp data_manage.EdbInfoFullClassify
  2942. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  2943. if err != nil {
  2944. br.Msg = err.Error()
  2945. br.ErrMsg = errMsg
  2946. return
  2947. }
  2948. // 权限校验
  2949. {
  2950. classifyMap := make(map[int]*data_manage.EdbClassifyIdItems)
  2951. for _, v := range classifyList {
  2952. classifyMap[v.ClassifyId] = v
  2953. }
  2954. if currClassify, ok := classifyMap[edbInfo.ClassifyId]; ok {
  2955. haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
  2956. if err != nil {
  2957. br.Msg = err.Error()
  2958. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2959. return
  2960. }
  2961. resp.HaveOperaAuth = haveOperaAuth
  2962. }
  2963. }
  2964. resp.EdbInfo = edbInfo
  2965. resp.ClassifyList = classifyList
  2966. br.Ret = 200
  2967. br.Success = true
  2968. br.Msg = "获取成功"
  2969. br.Data = resp
  2970. }
  2971. // EdbInfoFilter
  2972. // @Title 指标筛选接口
  2973. // @Description 指标筛选接口
  2974. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  2975. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标"
  2976. // @Param PageSize query int true "每页数据条数"
  2977. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2978. // @Success 200 {object} data_manage.EdbInfoList
  2979. // @router /edb_info/filter [get]
  2980. func (this *EdbInfoController) EdbInfoFilter() {
  2981. br := new(models.BaseResponse).Init()
  2982. defer func() {
  2983. this.Data["json"] = br
  2984. this.ServeJSON()
  2985. }()
  2986. keyWord := this.GetString("KeyWord")
  2987. filterSource, _ := this.GetInt("FilterSource")
  2988. if filterSource <= 0 {
  2989. filterSource = 1
  2990. }
  2991. var pars []interface{}
  2992. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  2993. // 获取当前账号的不可见指标
  2994. {
  2995. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2996. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  2997. if err != nil && err.Error() != utils.ErrNoRow() {
  2998. br.Msg = "获取失败"
  2999. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3000. return
  3001. }
  3002. for _, v := range confList {
  3003. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3004. }
  3005. }
  3006. var keyWordArr []string
  3007. keyWordArr = append(keyWordArr, keyWord)
  3008. if keyWord != "" {
  3009. newKeyWord := strings.Split(keyWord, " ")
  3010. keyWordArr = append(keyWordArr, newKeyWord...)
  3011. }
  3012. //var err error
  3013. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  3014. //if keyWord == "" {
  3015. // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars)
  3016. // if err != nil && err.Error() != utils.ErrNoRow() {
  3017. // br.Success = true
  3018. // br.Msg = "获取指标信息失败"
  3019. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3020. // return
  3021. // }
  3022. //} else {
  3023. // //获取指标信息
  3024. // indexName := utils.DATA_INDEX_NAME
  3025. // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource)
  3026. // if err != nil && err.Error() != utils.ErrNoRow() {
  3027. // br.Success = true
  3028. // br.Msg = "获取指标信息失败"
  3029. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3030. // return
  3031. // }
  3032. //}
  3033. var baseCondition string
  3034. // 无权限指标id
  3035. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3036. if lenNoPermissionEdbInfoIdList > 0 {
  3037. baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3038. pars = append(pars, noPermissionEdbInfoIdList)
  3039. }
  3040. existMap := make(map[int]string)
  3041. for _, v := range keyWordArr {
  3042. v = strings.Replace(v, " ", "%", -1)
  3043. var condition string
  3044. if filterSource == 2 {
  3045. condition += ` AND frequency='月度' `
  3046. }
  3047. if filterSource == 3 {
  3048. condition += ` AND frequency <> '日度' `
  3049. }
  3050. if filterSource == 4 {
  3051. condition += ` AND edb_type = 1 `
  3052. }
  3053. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  3054. condition += conditionWhere + baseCondition
  3055. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  3056. if err != nil && err.Error() != utils.ErrNoRow() {
  3057. br.Success = true
  3058. br.Msg = "获取指标信息失败"
  3059. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3060. return
  3061. }
  3062. for _, nv := range newEdbInfoList {
  3063. if _, ok := existMap[nv.EdbInfoId]; !ok {
  3064. edbInfoList = append(edbInfoList, nv)
  3065. }
  3066. existMap[nv.EdbInfoId] = nv.EdbCode
  3067. }
  3068. }
  3069. if edbInfoList == nil {
  3070. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3071. }
  3072. edbInfoListLen := len(edbInfoList)
  3073. for i := 0; i < edbInfoListLen; i++ {
  3074. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3075. }
  3076. for i := 0; i < edbInfoListLen; i++ {
  3077. for j := 0; j < edbInfoListLen; j++ {
  3078. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3079. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3080. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3081. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3082. }
  3083. }
  3084. }
  3085. //新增搜索词记录
  3086. {
  3087. searchKeyword := new(data_manage.SearchKeyword)
  3088. searchKeyword.KeyWord = keyWord
  3089. searchKeyword.CreateTime = time.Now()
  3090. go data_manage.AddSearchKeyword(searchKeyword)
  3091. }
  3092. br.Ret = 200
  3093. br.Success = true
  3094. br.Msg = "获取成功"
  3095. br.Data = edbInfoList
  3096. }
  3097. // EdbInfoFilterByEs
  3098. // @Title 指标筛选接口
  3099. // @Description 指标筛选接口
  3100. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  3101. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  3102. // @Param Frequency query string false "频度"
  3103. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  3104. // @Param PageSize query int true "每页数据条数"
  3105. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3106. // @Success 200 {object} data_manage.EdbInfoList
  3107. // @router /edb_info/filter_by_es [get]
  3108. func (this *EdbInfoController) EdbInfoFilterByEs() {
  3109. br := new(models.BaseResponse).Init()
  3110. defer func() {
  3111. this.Data["json"] = br
  3112. this.ServeJSON()
  3113. }()
  3114. pageSize, _ := this.GetInt("PageSize")
  3115. currentIndex, _ := this.GetInt("CurrentIndex")
  3116. var total int64
  3117. var startSize int
  3118. if pageSize <= 0 {
  3119. pageSize = utils.PageSize20
  3120. }
  3121. if currentIndex <= 0 {
  3122. currentIndex = 1
  3123. }
  3124. startSize = paging.StartIndex(currentIndex, pageSize)
  3125. keyWord := this.GetString("KeyWord")
  3126. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3127. filterSource, _ := this.GetInt("FilterSource")
  3128. if filterSource <= 0 {
  3129. filterSource = 1
  3130. }
  3131. //指标来源
  3132. source, _ := this.GetInt("Source")
  3133. frequency := this.GetString("Frequency") //频度
  3134. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  3135. var edbInfoList []*data_manage.EdbInfoList
  3136. var err error
  3137. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  3138. // 获取当前账号的不可见指标
  3139. {
  3140. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3141. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3142. if err != nil && err.Error() != utils.ErrNoRow() {
  3143. br.Msg = "获取失败"
  3144. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3145. return
  3146. }
  3147. for _, v := range confList {
  3148. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3149. }
  3150. }
  3151. // 是否走ES
  3152. isEs := false
  3153. if keyWord != "" {
  3154. var keyWordArr []string
  3155. keyWordArr = append(keyWordArr, keyWord)
  3156. newKeyWord := strings.Split(keyWord, " ")
  3157. keyWordArr = append(keyWordArr, newKeyWord...)
  3158. // 普通的搜索
  3159. if !isAddPredictEdb {
  3160. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
  3161. } else {
  3162. // 允许添加预测指标的搜索
  3163. total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize)
  3164. }
  3165. isEs = true
  3166. } else {
  3167. var condition string
  3168. var pars []interface{}
  3169. // 普通指标
  3170. condition += ` AND edb_info_type = ? `
  3171. pars = append(pars, 0)
  3172. // 无权限指标id
  3173. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3174. if lenNoPermissionEdbInfoIdList > 0 {
  3175. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3176. pars = append(pars, noPermissionEdbInfoIdList)
  3177. }
  3178. switch filterSource {
  3179. case 2:
  3180. condition += ` AND frequency='月度' `
  3181. case 3:
  3182. condition += ` AND frequency <> '日度' `
  3183. case 4:
  3184. condition += ` AND edb_type = 1 `
  3185. case 5:
  3186. condition += ` AND source = 6 ` //来源(同比值)
  3187. case 6:
  3188. condition += ` AND frequency != ? `
  3189. pars = append(pars, "年度")
  3190. }
  3191. //频度
  3192. if frequency != "" {
  3193. condition += ` AND frequency = ? `
  3194. pars = append(pars, frequency)
  3195. }
  3196. // 查询只允许添加预测指标的搜索
  3197. if isAddPredictEdb {
  3198. condition += ` AND frequency in ("日度","周度","月度") `
  3199. }
  3200. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  3201. }
  3202. if err != nil {
  3203. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3204. }
  3205. page := paging.GetPaging(currentIndex, pageSize, int(total))
  3206. edbInfoListLen := len(edbInfoList)
  3207. classifyIdList := make([]int, 0)
  3208. for i := 0; i < edbInfoListLen; i++ {
  3209. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3210. classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
  3211. }
  3212. // 当前列表中的分类map
  3213. classifyMap := make(map[int]*data_manage.EdbClassify)
  3214. if edbInfoListLen > 0 {
  3215. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  3216. if err != nil {
  3217. br.Msg = "获取失败"
  3218. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  3219. return
  3220. }
  3221. for _, v := range classifyList {
  3222. classifyMap[v.ClassifyId] = v
  3223. }
  3224. // 获取所有有权限的指标和分类
  3225. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  3226. if err != nil {
  3227. br.Msg = "获取失败"
  3228. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  3229. return
  3230. }
  3231. // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  3232. if isEs {
  3233. edbInfoIdList := make([]int, 0)
  3234. for i := 0; i < edbInfoListLen; i++ {
  3235. edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
  3236. tmpEdbInfo := edbInfoList[i]
  3237. if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
  3238. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  3239. }
  3240. }
  3241. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  3242. if err != nil {
  3243. br.Msg = "获取失败"
  3244. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  3245. return
  3246. }
  3247. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  3248. for _, v := range tmpEdbList {
  3249. edbInfoMap[v.EdbInfoId] = v
  3250. }
  3251. for i := 0; i < edbInfoListLen; i++ {
  3252. tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
  3253. if !ok {
  3254. continue
  3255. }
  3256. edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
  3257. }
  3258. }
  3259. // 权限校验
  3260. for i := 0; i < edbInfoListLen; i++ {
  3261. tmpEdbInfoItem := edbInfoList[i]
  3262. if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
  3263. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  3264. }
  3265. }
  3266. }
  3267. for i := 0; i < edbInfoListLen; i++ {
  3268. for j := 0; j < edbInfoListLen; j++ {
  3269. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3270. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3271. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3272. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3273. }
  3274. }
  3275. }
  3276. //新增搜索词记录
  3277. {
  3278. searchKeyword := new(data_manage.SearchKeyword)
  3279. searchKeyword.KeyWord = keyWord
  3280. searchKeyword.CreateTime = time.Now()
  3281. go data_manage.AddSearchKeyword(searchKeyword)
  3282. }
  3283. resp := data_manage.EdbInfoFilterDataResp{
  3284. Paging: page,
  3285. List: edbInfoList,
  3286. }
  3287. br.Ret = 200
  3288. br.Success = true
  3289. br.Msg = "获取成功"
  3290. br.Data = resp
  3291. }
  3292. func (this *EdbInfoController) EdbInfoFilter2() {
  3293. br := new(models.BaseResponse).Init()
  3294. defer func() {
  3295. this.Data["json"] = br
  3296. this.ServeJSON()
  3297. }()
  3298. keyWord := this.GetString("KeyWord")
  3299. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3300. filterSource, _ := this.GetInt("FilterSource")
  3301. if filterSource <= 0 {
  3302. filterSource = 1
  3303. }
  3304. var pars []interface{}
  3305. //if keyWord != "" {
  3306. // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  3307. //}
  3308. var keyWordArr []string
  3309. keyWordArr = append(keyWordArr, keyWord)
  3310. if keyWord != "" {
  3311. newKeyWord := strings.Split(keyWord, " ")
  3312. keyWordArr = append(keyWordArr, newKeyWord...)
  3313. }
  3314. keywordLen := len(keyWordArr)
  3315. ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen)
  3316. searchWait := sync.WaitGroup{}
  3317. searchWait.Add(keywordLen)
  3318. for index, v := range keyWordArr {
  3319. v = strings.Replace(v, " ", "%", -1)
  3320. var condition string
  3321. if filterSource == 2 {
  3322. condition += ` AND frequency='月度' `
  3323. }
  3324. if filterSource == 3 {
  3325. condition += ` AND frequency <> '日度' `
  3326. }
  3327. if filterSource == 4 {
  3328. condition += ` AND edb_type = 1 `
  3329. }
  3330. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  3331. condition += conditionWhere
  3332. go searchEdbInfoFilter(condition, pars, index, ch, &searchWait)
  3333. }
  3334. searchWait.Wait()
  3335. newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList)
  3336. i := 0
  3337. for tmpEdbInfoList := range ch {
  3338. i++
  3339. for k, v := range tmpEdbInfoList {
  3340. newEdbInfoListMap[k] = v
  3341. }
  3342. if i == keywordLen {
  3343. break
  3344. }
  3345. }
  3346. close(ch)
  3347. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  3348. existMap := make(map[int]string)
  3349. for i := 0; i < keywordLen; i++ {
  3350. if newEdbInfoList, ok := newEdbInfoListMap[i]; ok {
  3351. for _, nv := range newEdbInfoList {
  3352. if _, ok := existMap[nv.EdbInfoId]; !ok {
  3353. edbInfoList = append(edbInfoList, nv)
  3354. }
  3355. existMap[nv.EdbInfoId] = nv.EdbCode
  3356. }
  3357. }
  3358. }
  3359. if edbInfoList == nil {
  3360. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3361. }
  3362. edbInfoListLen := len(edbInfoList)
  3363. for i := 0; i < edbInfoListLen; i++ {
  3364. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3365. }
  3366. for i := 0; i < edbInfoListLen; i++ {
  3367. for j := 0; j < edbInfoListLen; j++ {
  3368. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3369. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3370. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3371. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3372. }
  3373. }
  3374. }
  3375. //新增搜索词记录
  3376. {
  3377. searchKeyword := new(data_manage.SearchKeyword)
  3378. searchKeyword.KeyWord = keyWord
  3379. searchKeyword.CreateTime = time.Now()
  3380. go data_manage.AddSearchKeyword(searchKeyword)
  3381. }
  3382. br.Ret = 200
  3383. br.Success = true
  3384. br.Msg = "获取成功"
  3385. br.Data = edbInfoList
  3386. }
  3387. 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) {
  3388. newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList)
  3389. defer func() {
  3390. if err != nil {
  3391. go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3)
  3392. //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  3393. }
  3394. ch <- newEdbInfoListMap
  3395. searchWait.Done()
  3396. }()
  3397. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  3398. newEdbInfoListMap[i] = newEdbInfoList
  3399. return
  3400. }
  3401. // EdbInfoAllRefresh
  3402. // @Title 指标全部刷新接口
  3403. // @Description 指标全部刷新接口
  3404. // @Param EdbInfoId query int true "指标id"
  3405. // @Success Ret=200 全部刷新成功
  3406. // @router /edb_info/refresh/all [get]
  3407. func (this *EdbInfoController) EdbInfoAllRefresh() {
  3408. br := new(models.BaseResponse).Init()
  3409. defer func() {
  3410. this.Data["json"] = br
  3411. this.ServeJSON()
  3412. }()
  3413. sysUser := this.SysUser
  3414. if sysUser == nil {
  3415. br.Msg = "请登录"
  3416. br.ErrMsg = "请登录,SysUser Is Empty"
  3417. br.Ret = 408
  3418. return
  3419. }
  3420. edbInfoId, _ := this.GetInt("EdbInfoId")
  3421. if edbInfoId <= 0 {
  3422. br.Msg = "参数错误"
  3423. br.ErrMsg = "参数错误"
  3424. return
  3425. }
  3426. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3427. if err != nil {
  3428. if err.Error() == utils.ErrNoRow() {
  3429. br.Msg = "数据已被删除,请刷新页面"
  3430. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  3431. return
  3432. }
  3433. br.Msg = "刷新失败"
  3434. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3435. return
  3436. }
  3437. if edbInfo == nil {
  3438. br.Msg = "数据已被删除,请刷新页面"
  3439. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  3440. return
  3441. }
  3442. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true, false)
  3443. if err != nil {
  3444. br.Msg = "刷新失败"
  3445. br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error()
  3446. return
  3447. }
  3448. br.Ret = 200
  3449. br.Success = true
  3450. br.Msg = "刷新成功"
  3451. if isAsync {
  3452. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  3453. }
  3454. }
  3455. // EdbInfoData
  3456. // @Title 获取指标数据
  3457. // @Description 获取指标数据
  3458. // @Param EdbInfoId query int true "指标ID"
  3459. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  3460. // @Param StartDate query string true "自定义开始日期"
  3461. // @Param EndDate query string true "自定义结束日期"
  3462. // @Success 200 {object} data_manage.EdbInfoDataResp
  3463. // @router /edb_info/data [get]
  3464. func (this *ChartInfoController) EdbInfoData() {
  3465. br := new(models.BaseResponse).Init()
  3466. defer func() {
  3467. this.Data["json"] = br
  3468. this.ServeJSON()
  3469. }()
  3470. sysUser := this.SysUser
  3471. if sysUser == nil {
  3472. br.Msg = "请登录"
  3473. br.ErrMsg = "请登录,SysUser Is Empty"
  3474. br.Ret = 408
  3475. return
  3476. }
  3477. fullEdb := new(data_manage.EdbInfoFullClassify)
  3478. resp := new(data_manage.EdbInfoDataFullClassifyResp)
  3479. dataList := make([]*data_manage.EdbDataList, 0)
  3480. edbInfoId, _ := this.GetInt("EdbInfoId")
  3481. if edbInfoId <= 0 {
  3482. br.Msg = "参数错误"
  3483. return
  3484. }
  3485. dateType, _ := this.GetInt("DateType")
  3486. if dateType <= 0 {
  3487. dateType = 3
  3488. }
  3489. edbInfoType, _ := this.GetInt("EdbInfoType")
  3490. if edbInfoType < 0 {
  3491. edbInfoType = 1
  3492. }
  3493. startDate := this.GetString("StartDate")
  3494. endDate := this.GetString("EndDate")
  3495. startYear, _ := this.GetInt("StartYear")
  3496. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3497. if err != nil {
  3498. if err.Error() == utils.ErrNoRow() {
  3499. br.Ret = 200
  3500. return
  3501. }
  3502. br.Msg = "获取失败"
  3503. br.ErrMsg = "获取失败,Err:" + err.Error()
  3504. return
  3505. }
  3506. // 分类
  3507. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  3508. if err != nil {
  3509. br.Msg = err.Error()
  3510. br.ErrMsg = errMsg
  3511. return
  3512. }
  3513. fullEdb.EdbInfo = edbInfo
  3514. fullEdb.ClassifyList = classifyList
  3515. var currClassifyItem *data_manage.EdbClassifyIdItems
  3516. for _, v := range classifyList {
  3517. if v.ClassifyId == edbInfo.ClassifyId {
  3518. currClassifyItem = v
  3519. }
  3520. }
  3521. if currClassifyItem != nil {
  3522. haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassifyItem.IsJoinPermission, sysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
  3523. if err != nil {
  3524. br.Msg = err.Error()
  3525. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  3526. return
  3527. }
  3528. fullEdb.HaveOperaAuth = haveOperaAuth
  3529. }
  3530. resp.EdbInfo = fullEdb
  3531. resp.DataList = make([]*data_manage.EdbDataList, 0)
  3532. // 数据获取
  3533. if fullEdb.HaveOperaAuth { // 有权限才获取数据
  3534. maxYear := 0
  3535. if edbInfo.LatestDate != "" {
  3536. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3537. maxYear = latestDateT.Year()
  3538. }
  3539. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  3540. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  3541. if err != nil {
  3542. br.Msg = "获取失败"
  3543. br.ErrMsg = "获取失败,Err:" + err.Error()
  3544. return
  3545. }
  3546. resp.DataList = dataList
  3547. }
  3548. br.Ret = 200
  3549. br.Success = true
  3550. br.Msg = "获取成功"
  3551. br.Data = resp
  3552. }
  3553. // EdbInfoReplaceCheck
  3554. // @Title 指标一键刷新接口
  3555. // @Description 指标一键刷新接口
  3556. // @Success Ret=200 更新成功
  3557. // @router /edb_info/replace/check [post]
  3558. func (this *EdbInfoController) EdbInfoReplaceCheck() {
  3559. br := new(models.BaseResponse).Init()
  3560. setNxKey := "EDB_INFO_REPLACE"
  3561. defer func() {
  3562. this.Data["json"] = br
  3563. this.ServeJSON()
  3564. }()
  3565. status := 0
  3566. if utils.Rc.IsExist(setNxKey) {
  3567. status = 1
  3568. } else {
  3569. status = 2
  3570. }
  3571. br.Ret = 200
  3572. br.Success = true
  3573. br.Msg = "检测成功"
  3574. br.Data = status
  3575. }
  3576. // EdbInfoReplace
  3577. // @Title 替换指标
  3578. // @Description 替换指标
  3579. // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
  3580. // @Success 200 {object} data_manage.EdbInfoDataResp
  3581. // @router /edb_info/replace [post]
  3582. func (this *ChartInfoController) EdbInfoReplace() {
  3583. br := new(models.BaseResponse).Init()
  3584. setNxKey := "EDB_INFO_REPLACE"
  3585. deleteCache := true
  3586. defer func() {
  3587. if deleteCache {
  3588. utils.Rc.Delete(setNxKey)
  3589. }
  3590. this.Data["json"] = br
  3591. this.ServeJSON()
  3592. }()
  3593. sysUser := this.SysUser
  3594. if sysUser == nil {
  3595. br.Msg = "请登录"
  3596. br.ErrMsg = "请登录,SysUser Is Empty"
  3597. br.Ret = 408
  3598. return
  3599. }
  3600. if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
  3601. deleteCache = false
  3602. br.Msg = "当前正在替换中,请耐心等待!"
  3603. br.IsSendEmail = false
  3604. return
  3605. }
  3606. var req data_manage.EdbInfoReplaceReq
  3607. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3608. if err != nil {
  3609. br.Msg = "参数解析异常!"
  3610. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3611. return
  3612. }
  3613. if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
  3614. br.Msg = "参数错误!"
  3615. br.ErrMsg = "参数错误,指标id为0"
  3616. return
  3617. }
  3618. oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
  3619. if err != nil {
  3620. br.Msg = "替换失败!"
  3621. br.ErrMsg = "获取原指标失败,Err:" + err.Error()
  3622. return
  3623. }
  3624. newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
  3625. if err != nil {
  3626. br.Msg = "替换失败!"
  3627. br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
  3628. return
  3629. }
  3630. //if oldEdbInfo.EdbType != 1 {
  3631. // br.Msg = "原指标为计算指标,不可替换!"
  3632. // br.ErrMsg = "原指标为计算指标,不可替换!"
  3633. // return
  3634. //}
  3635. //
  3636. //if newEdbInfo.EdbType != 1 {
  3637. // br.Msg = "替换指标为计算指标,不可替换!"
  3638. // br.ErrMsg = "替换指标为计算指标,不可替换!"
  3639. // return
  3640. //}
  3641. if oldEdbInfo.Frequency != newEdbInfo.Frequency {
  3642. br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3643. br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3644. return
  3645. }
  3646. sysAdminId := sysUser.AdminId
  3647. //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3648. _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3649. //msgContent := ``
  3650. isFail := false
  3651. var errmsg string
  3652. if err != nil {
  3653. //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换失败,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n " + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
  3654. isFail = true
  3655. errmsg = "replace err:" + err.Error()
  3656. } else {
  3657. //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换成功,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n" + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
  3658. isFail = false
  3659. }
  3660. // 添加站内信息
  3661. //{
  3662. // msgItem := new(company.CompanyApprovalMessage)
  3663. // msgItem.CreateUserId = sysAdminId
  3664. // msgItem.ReceiveUserId = sysAdminId
  3665. // msgItem.MessageStatus = 0
  3666. // msgItem.Remark = "指标替换"
  3667. // msgItem.OperationStatus = 1
  3668. // msgItem.Content = msgContent
  3669. // msgItem.CreateTime = time.Now()
  3670. // msgItem.ModifyTime = time.Now()
  3671. // msgItem.MessageType = 3 //1:申请消息,2:审批结果,3:文字消息
  3672. // msgItem.SourceType = 4 //消息来源
  3673. // err = company.AddCompanyApprovalMessage(msgItem)
  3674. //}
  3675. if isFail {
  3676. br.Msg = "替换失败"
  3677. br.ErrMsg = "替换失败 err:" + errmsg
  3678. } else {
  3679. br.Msg = "替换成功"
  3680. br.ErrMsg = "替换成功"
  3681. br.Ret = 200
  3682. }
  3683. br.IsAddLog = true
  3684. return
  3685. }
  3686. // RelationChartList
  3687. // @Title 获取ETA指标关联的图表列表接口
  3688. // @Description 获取ETA指标关联的图表列表接口
  3689. // @Param PageSize query int true "每页数据条数"
  3690. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3691. // @Param EdbInfoId query int true "指标id"
  3692. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3693. // @Success 200 {object} data_manage.ChartListResp
  3694. // @router /edb_info/relation/chart_list [get]
  3695. func (this *EdbInfoController) RelationChartList() {
  3696. br := new(models.BaseResponse).Init()
  3697. defer func() {
  3698. this.Data["json"] = br
  3699. this.ServeJSON()
  3700. }()
  3701. sysUser := this.SysUser
  3702. if sysUser == nil {
  3703. br.Msg = "请登录"
  3704. br.ErrMsg = "请登录,SysUser Is Empty"
  3705. br.Ret = 408
  3706. return
  3707. }
  3708. edbInfoId, _ := this.GetInt("EdbInfoId")
  3709. pageSize, _ := this.GetInt("PageSize")
  3710. currentIndex, _ := this.GetInt("CurrentIndex")
  3711. resp := data_manage.ChartListResp{}
  3712. var total int
  3713. page := paging.GetPaging(currentIndex, pageSize, total)
  3714. var startSize int
  3715. if pageSize <= 0 {
  3716. pageSize = utils.PageSize20
  3717. }
  3718. if currentIndex <= 0 {
  3719. currentIndex = 1
  3720. }
  3721. startSize = paging.StartIndex(currentIndex, pageSize)
  3722. var condition string
  3723. var pars []interface{}
  3724. if edbInfoId <= 0 {
  3725. br.Msg = "请选择指标"
  3726. br.ErrMsg = "请选择指标"
  3727. br.IsSendEmail = false
  3728. return
  3729. }
  3730. // 关联指标
  3731. condition += ` AND b.edb_info_id = ? `
  3732. pars = append(pars, edbInfoId)
  3733. //只看我的
  3734. isShowMe, _ := this.GetBool("IsShowMe")
  3735. if isShowMe {
  3736. condition += ` AND a.sys_user_id = ? `
  3737. pars = append(pars, sysUser.AdminId)
  3738. }
  3739. // 获取当前账号的不可见图表
  3740. noPermissionChartIdList := make([]int, 0)
  3741. {
  3742. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3743. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  3744. if err != nil && err.Error() != utils.ErrNoRow() {
  3745. br.Msg = "获取失败"
  3746. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3747. return
  3748. }
  3749. for _, v := range confList {
  3750. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  3751. }
  3752. }
  3753. noPermissionChartIdNum := len(noPermissionChartIdList)
  3754. if noPermissionChartIdNum > 0 {
  3755. condition += ` AND a.chart_info_id not in (` + utils.GetOrmInReplace(noPermissionChartIdNum) + `) `
  3756. pars = append(pars, noPermissionChartIdList)
  3757. }
  3758. //获取关联图表列表
  3759. list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
  3760. if err != nil && err.Error() != utils.ErrNoRow() {
  3761. br.Success = true
  3762. br.Msg = "获取图表信息失败"
  3763. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3764. return
  3765. }
  3766. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3767. items := make([]*data_manage.ChartInfoView, 0)
  3768. resp.Paging = page
  3769. resp.List = items
  3770. br.Ret = 200
  3771. br.Success = true
  3772. br.Msg = "获取成功"
  3773. return
  3774. }
  3775. // 获取关联图表总数
  3776. dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
  3777. if err != nil && err.Error() != utils.ErrNoRow() {
  3778. br.Msg = "获取指标信息失败"
  3779. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3780. return
  3781. }
  3782. // 获取MY ETA 图表,用来判断是否加入我的图库
  3783. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  3784. if err != nil && err.Error() != utils.ErrNoRow() {
  3785. br.Msg = "获取图表信息失败"
  3786. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  3787. return
  3788. }
  3789. myChartMap := make(map[int]*data_manage.MyChartView)
  3790. for _, v := range myChartList {
  3791. myChartMap[v.ChartInfoId] = v
  3792. }
  3793. listLen := len(list)
  3794. if listLen > 0 {
  3795. // 分类id
  3796. classifyIdList := make([]int, 0)
  3797. // 当前列表中的分类map
  3798. classifyMap := make(map[int]*data_manage.ChartClassify)
  3799. for _, v := range list {
  3800. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  3801. }
  3802. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  3803. if err != nil {
  3804. br.Msg = "获取失败"
  3805. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  3806. return
  3807. }
  3808. for _, v := range classifyList {
  3809. classifyMap[v.ChartClassifyId] = v
  3810. }
  3811. // 已授权分类id
  3812. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  3813. if err != nil {
  3814. br.Msg = "获取失败"
  3815. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  3816. return
  3817. }
  3818. for _, v := range list {
  3819. if existItem, ok := myChartMap[v.ChartInfoId]; ok {
  3820. v.IsAdd = true
  3821. v.MyChartId = existItem.MyChartId
  3822. v.MyChartClassifyId = existItem.MyChartClassifyId
  3823. }
  3824. // 权限
  3825. if currClassify, ok := classifyMap[v.ChartClassifyId]; ok {
  3826. v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  3827. }
  3828. }
  3829. }
  3830. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  3831. resp.Paging = page
  3832. resp.List = list
  3833. br.Ret = 200
  3834. br.Success = true
  3835. br.Msg = "获取成功"
  3836. br.Data = resp
  3837. }
  3838. // RelationEdbList
  3839. // @Title 获取ETA指标关联的指标列表接口
  3840. // @Description 获取ETA指标关联的指标列表接口
  3841. // @Param PageSize query int true "每页数据条数"
  3842. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3843. // @Param EdbInfoId query int true "指标id"
  3844. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3845. // @Success 200 {object} data_manage.ChartListResp
  3846. // @router /edb_info/relation/edbinfo_list [get]
  3847. func (this *EdbInfoController) RelationEdbList() {
  3848. br := new(models.BaseResponse).Init()
  3849. defer func() {
  3850. this.Data["json"] = br
  3851. this.ServeJSON()
  3852. }()
  3853. sysUser := this.SysUser
  3854. if sysUser == nil {
  3855. br.Msg = "请登录"
  3856. br.ErrMsg = "请登录,SysUser Is Empty"
  3857. br.Ret = 408
  3858. return
  3859. }
  3860. edbInfoId, _ := this.GetInt("EdbInfoId")
  3861. pageSize, _ := this.GetInt("PageSize")
  3862. currentIndex, _ := this.GetInt("CurrentIndex")
  3863. resp := data_manage.RelationEdbInfoListResp{}
  3864. var total int
  3865. page := paging.GetPaging(currentIndex, pageSize, total)
  3866. var startSize int
  3867. if pageSize <= 0 {
  3868. pageSize = utils.PageSize20
  3869. }
  3870. if currentIndex <= 0 {
  3871. currentIndex = 1
  3872. }
  3873. startSize = paging.StartIndex(currentIndex, pageSize)
  3874. var condition string
  3875. var pars []interface{}
  3876. if edbInfoId <= 0 {
  3877. br.Msg = "请选择指标"
  3878. br.ErrMsg = "请选择指标"
  3879. br.IsSendEmail = false
  3880. return
  3881. }
  3882. // 关联指标
  3883. condition += ` AND b.from_edb_info_id = ? `
  3884. pars = append(pars, edbInfoId)
  3885. //只看我的
  3886. isShowMe, _ := this.GetBool("IsShowMe")
  3887. if isShowMe {
  3888. condition += ` AND a.sys_user_id = ? `
  3889. pars = append(pars, sysUser.AdminId)
  3890. }
  3891. // 获取当前账号的不可见图表
  3892. noPermissionEdbIdList := make([]int, 0)
  3893. {
  3894. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3895. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3896. if err != nil && err.Error() != utils.ErrNoRow() {
  3897. br.Msg = "获取失败"
  3898. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3899. return
  3900. }
  3901. for _, v := range confList {
  3902. noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
  3903. }
  3904. }
  3905. noPermissionEdbIdNum := len(noPermissionEdbIdList)
  3906. if noPermissionEdbIdNum > 0 {
  3907. condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
  3908. pars = append(pars, noPermissionEdbIdList)
  3909. }
  3910. //获取关联图表列表
  3911. list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
  3912. if err != nil && err.Error() != utils.ErrNoRow() {
  3913. br.Success = true
  3914. br.Msg = "获取图表信息失败"
  3915. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3916. return
  3917. }
  3918. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3919. items := make([]*data_manage.ChartEdbInfoMapping, 0)
  3920. resp.Paging = page
  3921. resp.List = items
  3922. br.Ret = 200
  3923. br.Success = true
  3924. br.Msg = "获取成功"
  3925. return
  3926. }
  3927. // 获取关联图表总数
  3928. dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
  3929. if err != nil && err.Error() != utils.ErrNoRow() {
  3930. br.Msg = "获取指标信息失败"
  3931. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3932. return
  3933. }
  3934. if err != nil {
  3935. br.Msg = "获取失败"
  3936. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3937. return
  3938. }
  3939. edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
  3940. if len(list) > 0 {
  3941. // 当前的分类
  3942. classifyMap := make(map[int]*data_manage.EdbClassify)
  3943. {
  3944. classifyIdList := make([]int, 0)
  3945. for _, v := range list {
  3946. classifyIdList = append(classifyIdList, v.ClassifyId)
  3947. }
  3948. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  3949. if err != nil {
  3950. if err != nil {
  3951. br.Msg = "获取失败"
  3952. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  3953. return
  3954. }
  3955. }
  3956. for _, v := range classifyList {
  3957. classifyMap[v.ClassifyId] = v
  3958. }
  3959. }
  3960. // 获取所有有权限的指标和分类
  3961. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  3962. if err != nil {
  3963. br.Msg = "获取失败"
  3964. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  3965. return
  3966. }
  3967. for _, v := range list {
  3968. item := new(data_manage.ChartEdbInfoMapping)
  3969. item.EdbInfoId = v.EdbInfoId
  3970. item.SourceName = v.SourceName
  3971. item.Source = v.Source
  3972. item.EdbCode = v.EdbCode
  3973. item.EdbName = v.EdbName
  3974. item.EdbNameEn = v.EdbNameEn
  3975. item.Frequency = v.Frequency
  3976. item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
  3977. if v.Unit != `无` {
  3978. item.Unit = v.Unit
  3979. }
  3980. item.UnitEn = v.UnitEn
  3981. item.StartDate = v.StartDate
  3982. item.EndDate = v.EndDate
  3983. item.ModifyTime = v.ModifyTime
  3984. item.IsAxis = 1
  3985. item.LeadValue = 0
  3986. item.LeadUnit = ""
  3987. item.ChartEdbMappingId = 0
  3988. item.ChartInfoId = 0
  3989. item.IsOrder = false
  3990. item.EdbInfoType = v.EdbInfoType
  3991. item.EdbInfoCategoryType = v.EdbInfoType
  3992. item.ChartStyle = ""
  3993. item.ChartColor = ""
  3994. item.ChartWidth = 0
  3995. item.MaxData = v.MaxValue
  3996. item.MinData = v.MinValue
  3997. item.LatestValue = v.LatestValue
  3998. item.LatestDate = v.LatestDate
  3999. item.UniqueCode = v.UniqueCode
  4000. item.ClassifyId = v.ClassifyId
  4001. dataList := make([]*data_manage.EdbDataList, 0)
  4002. // 指标权限
  4003. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  4004. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4005. }
  4006. // 有权限则获取数据
  4007. if item.HaveOperaAuth {
  4008. if v.EdbInfoType == 0 {
  4009. dataList, err = data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, "", "")
  4010. } else {
  4011. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
  4012. }
  4013. if err != nil {
  4014. br.Msg = "获取失败"
  4015. br.Msg = "获取失败,Err:" + err.Error()
  4016. return
  4017. }
  4018. }
  4019. item.DataList = dataList
  4020. edbList = append(edbList, item)
  4021. }
  4022. }
  4023. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  4024. resp.Paging = page
  4025. resp.List = edbList
  4026. br.Ret = 200
  4027. br.Success = true
  4028. br.Msg = "获取成功"
  4029. br.Data = resp
  4030. }
  4031. // EdbInfoDataTb
  4032. // @Title 获取指标数据同比值
  4033. // @Description 获取指标数据
  4034. // @Param EdbInfoId query int true "指标ID"
  4035. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4036. // @Param StartDate query string true "自定义开始日期"
  4037. // @Param EndDate query string true "自定义结束日期"
  4038. // @Success 200 {object} data_manage.EdbInfoDataResp
  4039. // @router /edb_info/data/tb [get]
  4040. func (this *ChartInfoController) EdbInfoDataTb() {
  4041. br := new(models.BaseResponse).Init()
  4042. defer func() {
  4043. this.Data["json"] = br
  4044. this.ServeJSON()
  4045. }()
  4046. sysUser := this.SysUser
  4047. if sysUser == nil {
  4048. br.Msg = "请登录"
  4049. br.ErrMsg = "请登录,SysUser Is Empty"
  4050. br.Ret = 408
  4051. return
  4052. }
  4053. edbInfoId, _ := this.GetInt("EdbInfoId")
  4054. if edbInfoId <= 0 {
  4055. br.Msg = "参数错误"
  4056. return
  4057. }
  4058. dateType, _ := this.GetInt("DateType")
  4059. if dateType <= 0 {
  4060. dateType = 3
  4061. }
  4062. edbInfoType, _ := this.GetInt("EdbInfoType")
  4063. if edbInfoType < 0 {
  4064. edbInfoType = 1
  4065. }
  4066. startDate := this.GetString("StartDate")
  4067. endDate := this.GetString("EndDate")
  4068. startYear, _ := this.GetInt("StartYear")
  4069. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4070. if err != nil {
  4071. br.Msg = "获取失败"
  4072. br.Msg = "获取失败,Err:" + err.Error()
  4073. return
  4074. }
  4075. maxYear := 0
  4076. if edbInfo.LatestDate != "" {
  4077. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4078. maxYear = latestDateT.Year()
  4079. }
  4080. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  4081. var startDateTime time.Time
  4082. if startDate != `` {
  4083. startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  4084. if err != nil {
  4085. br.Msg = "开始日期异常"
  4086. br.Msg = "开始日期异常,Err:" + err.Error()
  4087. return
  4088. }
  4089. //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
  4090. startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
  4091. }
  4092. tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  4093. if err != nil {
  4094. br.Msg = "获取失败"
  4095. br.Msg = "获取失败,Err:" + err.Error()
  4096. return
  4097. }
  4098. // 计算同比值
  4099. dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
  4100. if err != nil {
  4101. br.Msg = "获取失败"
  4102. br.Msg = "计算同比值失败,Err:" + err.Error()
  4103. return
  4104. }
  4105. edbInfo.MaxValue = maxValue
  4106. edbInfo.MinValue = minValue
  4107. resp := new(data_manage.EdbInfoDataResp)
  4108. resp.EdbInfo = edbInfo
  4109. resp.DataList = dataList
  4110. br.Ret = 200
  4111. br.Success = true
  4112. br.Msg = "获取成功"
  4113. br.Data = resp
  4114. }
  4115. // EdbInfoDataSeasonal
  4116. // @Title 获取指标数据(季节性)
  4117. // @Description 获取指标数据
  4118. // @Param EdbInfoId query int true "指标ID"
  4119. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4120. // @Param StartDate query string true "自定义开始日期"
  4121. // @Param EndDate query string true "自定义结束日期"
  4122. // @Param Calendar query string true "公历/农历"
  4123. // @Success 200 {object} data_manage.EdbInfoDataResp
  4124. // @router /edb_info/data/seasonal [get]
  4125. func (this *ChartInfoController) EdbInfoDataSeasonal() {
  4126. br := new(models.BaseResponse).Init()
  4127. defer func() {
  4128. this.Data["json"] = br
  4129. this.ServeJSON()
  4130. }()
  4131. sysUser := this.SysUser
  4132. if sysUser == nil {
  4133. br.Msg = "请登录"
  4134. br.ErrMsg = "请登录,SysUser Is Empty"
  4135. br.Ret = 408
  4136. return
  4137. }
  4138. dateType, _ := this.GetInt("DateType")
  4139. startDate := this.GetString("StartDate")
  4140. endDate := this.GetString("EndDate")
  4141. startYear, _ := this.GetInt("StartYear")
  4142. edbInfoIdStr := this.GetString("EdbInfoId")
  4143. edbInfoId, err := strconv.Atoi(edbInfoIdStr)
  4144. if err != nil {
  4145. br.Msg = "指标id异常"
  4146. br.Msg = "指标id转换异常,Err:" + err.Error()
  4147. return
  4148. }
  4149. fmt.Println("startDate:", startDate)
  4150. fmt.Println("endDate:", endDate)
  4151. calendar := this.GetString("Calendar")
  4152. if calendar == "" {
  4153. calendar = "公历"
  4154. }
  4155. if dateType == 0 {
  4156. if startDate == "" {
  4157. dateType = utils.DateTypeNYears
  4158. } else {
  4159. dateType = 5
  4160. }
  4161. }
  4162. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4163. if err != nil {
  4164. br.Msg = "获取失败"
  4165. br.Msg = "获取失败,Err:" + err.Error()
  4166. return
  4167. }
  4168. maxYear := 0
  4169. if edbInfo.LatestDate != "" {
  4170. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4171. maxYear = latestDateT.Year()
  4172. }
  4173. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  4174. dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
  4175. if err != nil {
  4176. br.Msg = "获取失败"
  4177. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  4178. return
  4179. }
  4180. resp := new(data_manage.EdbInfoDataSeasonalResp)
  4181. resp.EdbInfo = edbInfo
  4182. resp.DataList = dataList
  4183. br.Ret = 200
  4184. br.Success = true
  4185. br.Msg = "获取成功"
  4186. br.Data = resp
  4187. }
  4188. // SetEdbDataInsertConfig 设置插入值
  4189. // @Title 设置插入值接口
  4190. // @Description 设置插入值接口
  4191. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  4192. // @router /edb_info/insert_config/set [post]
  4193. func (this *EdbInfoController) SetEdbDataInsertConfig() {
  4194. br := new(models.BaseResponse).Init()
  4195. defer func() {
  4196. this.Data["json"] = br
  4197. this.ServeJSON()
  4198. }()
  4199. sysUser := this.SysUser
  4200. if sysUser == nil {
  4201. br.Msg = "请登录"
  4202. br.ErrMsg = "请登录,SysUser Is Empty"
  4203. br.Ret = 408
  4204. return
  4205. }
  4206. var req data_manage.SetEdbDataInsertConfigReq
  4207. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4208. if err != nil {
  4209. br.Msg = "参数解析异常!"
  4210. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4211. return
  4212. }
  4213. dateStr := req.Date
  4214. if dateStr == `` {
  4215. br.Msg = "请选择日期"
  4216. br.IsSendEmail = false
  4217. return
  4218. }
  4219. date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
  4220. if err != nil {
  4221. br.Msg = "日期异常"
  4222. br.ErrMsg = "日期异常,err:" + err.Error()
  4223. br.IsSendEmail = false
  4224. return
  4225. }
  4226. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  4227. if err != nil {
  4228. br.Msg = "获取指标信息失败"
  4229. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  4230. return
  4231. }
  4232. err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
  4233. if err != nil {
  4234. br.Msg = "设置失败"
  4235. if errMsg != `` {
  4236. br.Msg = errMsg
  4237. }
  4238. br.ErrMsg = "修改失败,Err:" + err.Error()
  4239. br.IsSendEmail = isSendEmail
  4240. return
  4241. }
  4242. //新增操作日志
  4243. {
  4244. edbLog := new(data_manage.EdbInfoLog)
  4245. edbLog.EdbInfoId = edbInfo.EdbInfoId
  4246. edbLog.SourceName = edbInfo.SourceName
  4247. edbLog.Source = edbInfo.Source
  4248. edbLog.EdbCode = edbInfo.EdbCode
  4249. edbLog.EdbName = edbInfo.EdbName
  4250. edbLog.ClassifyId = edbInfo.ClassifyId
  4251. edbLog.SysUserId = sysUser.AdminId
  4252. edbLog.SysUserRealName = sysUser.RealName
  4253. edbLog.CreateTime = time.Now()
  4254. edbLog.Content = string(this.Ctx.Input.RequestBody)
  4255. edbLog.Status = "设置插入值"
  4256. edbLog.Method = this.Ctx.Input.URI()
  4257. go data_manage.AddEdbInfoLog(edbLog)
  4258. }
  4259. br.Ret = 200
  4260. br.Success = true
  4261. br.Msg = "保存成功"
  4262. br.IsAddLog = true
  4263. }
  4264. // TraceEdbInfo
  4265. // @Title 指标溯源接口
  4266. // @Description 指标溯源接口
  4267. // @Param UniqueCode query int true "指标唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  4268. // @Success 200 {object} data_manage.ChartListResp
  4269. // @router /edb_info/trace [get]
  4270. func (this *EdbInfoController) TraceEdbInfo() {
  4271. br := new(models.BaseResponse).Init()
  4272. defer func() {
  4273. this.Data["json"] = br
  4274. this.ServeJSON()
  4275. }()
  4276. sysUser := this.SysUser
  4277. if sysUser == nil {
  4278. br.Msg = "请登录"
  4279. br.ErrMsg = "请登录,SysUser Is Empty"
  4280. br.Ret = 408
  4281. return
  4282. }
  4283. //edbInfoId, _ := this.GetInt("EdbInfoId")
  4284. //if edbInfoId <= 0 {
  4285. // br.Msg = "参数错误"
  4286. // br.ErrMsg = "参数错误"
  4287. // return
  4288. //}
  4289. uniqueCode := this.GetString("UniqueCode")
  4290. if uniqueCode == `` {
  4291. br.Msg = "参数错误"
  4292. br.ErrMsg = "参数错误"
  4293. return
  4294. }
  4295. // 根据UniqueCode获取指标信息
  4296. edbInfo, err := data_manage.GetEdbInfoByUniqueCode(uniqueCode)
  4297. if err != nil {
  4298. br.Msg = "获取失败"
  4299. br.Msg = "获取失败,Err:" + err.Error()
  4300. if err.Error() == utils.ErrNoRow() {
  4301. br.Msg = "指标不存在"
  4302. }
  4303. return
  4304. }
  4305. resp, err := data.TraceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, this.SysUser.AdminId)
  4306. if err != nil {
  4307. br.Msg = "获取失败"
  4308. br.Msg = "获取失败,Err:" + err.Error()
  4309. return
  4310. }
  4311. br.Ret = 200
  4312. br.Data = resp
  4313. br.Success = true
  4314. br.Msg = "刷新成功"
  4315. }
  4316. // AllEdbInfoByEs
  4317. // @Title 所有指标筛选接口
  4318. // @Description 所有指标筛选接口
  4319. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  4320. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  4321. // @Param Frequency query string false "频度"
  4322. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  4323. // @Param PageSize query int true "每页数据条数"
  4324. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4325. // @Success 200 {object} data_manage.EdbInfoList
  4326. // @router /edb_info/filter_by_es/all [get]
  4327. func (this *EdbInfoController) AllEdbInfoByEs() {
  4328. br := new(models.BaseResponse).Init()
  4329. defer func() {
  4330. this.Data["json"] = br
  4331. this.ServeJSON()
  4332. }()
  4333. pageSize, _ := this.GetInt("PageSize")
  4334. currentIndex, _ := this.GetInt("CurrentIndex")
  4335. var total int64
  4336. var startSize int
  4337. if pageSize <= 0 {
  4338. pageSize = utils.PageSize20
  4339. }
  4340. if currentIndex <= 0 {
  4341. currentIndex = 1
  4342. }
  4343. startSize = paging.StartIndex(currentIndex, pageSize)
  4344. keyWord := this.GetString("KeyWord")
  4345. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  4346. filterSource, _ := this.GetInt("FilterSource")
  4347. if filterSource <= 0 {
  4348. filterSource = 1
  4349. }
  4350. //指标来源
  4351. source, _ := this.GetInt("Source")
  4352. frequency := this.GetString("Frequency") //频度
  4353. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  4354. var edbInfoList []*data_manage.EdbInfoList
  4355. var err error
  4356. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  4357. // 获取当前账号的不可见指标
  4358. {
  4359. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4360. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4361. if err != nil && err.Error() != utils.ErrNoRow() {
  4362. br.Msg = "获取失败"
  4363. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  4364. return
  4365. }
  4366. for _, v := range confList {
  4367. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  4368. }
  4369. }
  4370. // 是否走ES
  4371. isEs := false
  4372. if keyWord != "" {
  4373. var keyWordArr []string
  4374. keyWordArr = append(keyWordArr, keyWord)
  4375. newKeyWord := strings.Split(keyWord, " ")
  4376. keyWordArr = append(keyWordArr, newKeyWord...)
  4377. // 普通的搜索
  4378. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, frequency, noPermissionEdbInfoIdList)
  4379. isEs = true
  4380. } else {
  4381. var condition string
  4382. var pars []interface{}
  4383. // 普通指标
  4384. condition += ` AND edb_info_type = ? `
  4385. pars = append(pars, 0)
  4386. // 无权限指标id
  4387. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  4388. if lenNoPermissionEdbInfoIdList > 0 {
  4389. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  4390. pars = append(pars, noPermissionEdbInfoIdList)
  4391. }
  4392. switch filterSource {
  4393. case 2:
  4394. condition += ` AND frequency='月度' `
  4395. case 3:
  4396. condition += ` AND frequency <> '日度' `
  4397. case 4:
  4398. condition += ` AND edb_type = 1 `
  4399. case 5:
  4400. condition += ` AND source = 6 ` //来源(同比值)
  4401. case 6:
  4402. condition += ` AND frequency != ? `
  4403. pars = append(pars, "年度")
  4404. }
  4405. //频度
  4406. if frequency != "" {
  4407. condition += ` AND frequency = ? `
  4408. pars = append(pars, frequency)
  4409. }
  4410. // 查询只允许添加预测指标的搜索
  4411. if isAddPredictEdb {
  4412. condition += ` AND frequency in ("日度","周度","月度") `
  4413. }
  4414. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  4415. }
  4416. if err != nil {
  4417. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  4418. }
  4419. page := paging.GetPaging(currentIndex, pageSize, int(total))
  4420. edbInfoListLen := len(edbInfoList)
  4421. classifyIdList := make([]int, 0)
  4422. for i := 0; i < edbInfoListLen; i++ {
  4423. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  4424. classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
  4425. }
  4426. // 当前列表中的分类map
  4427. classifyMap := make(map[int]*data_manage.EdbClassify)
  4428. if edbInfoListLen > 0 {
  4429. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4430. if err != nil {
  4431. br.Msg = "获取失败"
  4432. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4433. return
  4434. }
  4435. for _, v := range classifyList {
  4436. classifyMap[v.ClassifyId] = v
  4437. }
  4438. // 获取所有有权限的指标和分类
  4439. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4440. if err != nil {
  4441. br.Msg = "获取失败"
  4442. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4443. return
  4444. }
  4445. // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  4446. if isEs {
  4447. edbInfoIdList := make([]int, 0)
  4448. for i := 0; i < edbInfoListLen; i++ {
  4449. edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
  4450. tmpEdbInfo := edbInfoList[i]
  4451. if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
  4452. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4453. }
  4454. }
  4455. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  4456. if err != nil {
  4457. br.Msg = "获取失败"
  4458. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4459. return
  4460. }
  4461. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  4462. for _, v := range tmpEdbList {
  4463. edbInfoMap[v.EdbInfoId] = v
  4464. }
  4465. for i := 0; i < edbInfoListLen; i++ {
  4466. tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
  4467. if !ok {
  4468. continue
  4469. }
  4470. edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
  4471. }
  4472. }
  4473. // 权限校验
  4474. for i := 0; i < edbInfoListLen; i++ {
  4475. tmpEdbInfoItem := edbInfoList[i]
  4476. if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
  4477. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4478. }
  4479. }
  4480. }
  4481. for i := 0; i < edbInfoListLen; i++ {
  4482. for j := 0; j < edbInfoListLen; j++ {
  4483. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  4484. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  4485. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  4486. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  4487. }
  4488. }
  4489. }
  4490. //新增搜索词记录
  4491. {
  4492. searchKeyword := new(data_manage.SearchKeyword)
  4493. searchKeyword.KeyWord = keyWord
  4494. searchKeyword.CreateTime = time.Now()
  4495. go data_manage.AddSearchKeyword(searchKeyword)
  4496. }
  4497. resp := data_manage.EdbInfoFilterDataResp{
  4498. Paging: page,
  4499. List: edbInfoList,
  4500. }
  4501. br.Ret = 200
  4502. br.Success = true
  4503. br.Msg = "获取成功"
  4504. br.Data = resp
  4505. }
  4506. // GetEdbDateData
  4507. // @Title 根据指标ID和具体日期获取对应日期的数据值
  4508. // @Description 根据指标ID和具体日期获取对应日期的数据值
  4509. // @Param EdbInfoId query int false "指标id"
  4510. // @Param Date query string false "日期"
  4511. // @Success 200 {object} data_manage.EdbInfoList
  4512. // @router /edb_info/date_data [get]
  4513. func (this *EdbInfoController) GetEdbDateData() {
  4514. br := new(models.BaseResponse).Init()
  4515. defer func() {
  4516. this.Data["json"] = br
  4517. this.ServeJSON()
  4518. }()
  4519. edbInfoId, _ := this.GetInt("EdbInfoId")
  4520. date := this.GetString("Date")
  4521. if edbInfoId <= 0 {
  4522. br.Msg = "请选择指标"
  4523. br.IsSendEmail = false
  4524. return
  4525. }
  4526. if date == `` {
  4527. br.Msg = "请选择日期"
  4528. br.IsSendEmail = false
  4529. return
  4530. }
  4531. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4532. if err != nil {
  4533. br.Msg = "获取失败"
  4534. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4535. return
  4536. }
  4537. startDate := date
  4538. endDate := date
  4539. dateType := "day"
  4540. //如果填写的是月度日期
  4541. if strings.Count(date, "-") == 1 {
  4542. startDate = date + "-01"
  4543. endDate = ``
  4544. dateType = "month"
  4545. }
  4546. dataItem, err := data.GetDateData(edbInfo, startDate, endDate)
  4547. if err != nil {
  4548. br.Msg = "获取失败"
  4549. br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
  4550. return
  4551. }
  4552. val := ``
  4553. if dataItem != nil {
  4554. switch dateType {
  4555. case "month":
  4556. dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local)
  4557. dateTimeStr := dateTime.Format(utils.FormatYearMonthDate)
  4558. if dateTimeStr != date {
  4559. val = ``
  4560. }
  4561. }
  4562. val = fmt.Sprint(dataItem.Value)
  4563. }
  4564. br.Ret = 200
  4565. br.Success = true
  4566. br.Msg = "获取成功"
  4567. br.Data = val
  4568. }
  4569. // GetEdbBeforeAndAfterDateData
  4570. // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4571. // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4572. // @Param EdbInfoId query int false "指标id"
  4573. // @Param Date query string false "日期"
  4574. // @Param Num query int false "前后几期数据"
  4575. // @Success 200 {object} data_manage.EdbInfoList
  4576. // @router /edb_info/date_data/before_after [post]
  4577. func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
  4578. br := new(models.BaseResponse).Init()
  4579. defer func() {
  4580. this.Data["json"] = br
  4581. this.ServeJSON()
  4582. }()
  4583. requestBody := string(this.Ctx.Input.RequestBody)
  4584. var req request2.DateDataBeforeAfterReq
  4585. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4586. if err != nil {
  4587. br.Msg = "参数解析异常!"
  4588. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4589. return
  4590. }
  4591. edbInfoId := req.EdbInfoId
  4592. currDate := req.Date
  4593. num := req.Num
  4594. // 默认2期数据
  4595. if num <= 0 {
  4596. num = 2
  4597. }
  4598. if edbInfoId <= 0 {
  4599. br.Msg = "请选择指标"
  4600. br.IsSendEmail = false
  4601. return
  4602. }
  4603. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4604. if err != nil {
  4605. br.Msg = "获取失败"
  4606. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4607. return
  4608. }
  4609. dataList := make([]*data_manage.EdbDataList, 0)
  4610. switch edbInfo.EdbInfoType {
  4611. case 0:
  4612. dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
  4613. case 1:
  4614. _, dataList, _, _, _, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  4615. default:
  4616. br.Msg = "指标类型异常!"
  4617. br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType)
  4618. return
  4619. }
  4620. if currDate == `` {
  4621. currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList)
  4622. if err != nil {
  4623. br.Msg = "日期前移失败"
  4624. br.ErrMsg = "日期前移失败,Err:" + err.Error()
  4625. return
  4626. }
  4627. } else {
  4628. if strings.Count(currDate, "-") == 1 {
  4629. currDate = currDate + "-01"
  4630. // 查找这个月早的时间作为起始时间
  4631. for _, v := range dataList {
  4632. if v.DataTime >= currDate {
  4633. currDate = v.DataTime
  4634. break
  4635. }
  4636. }
  4637. }
  4638. }
  4639. currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody)
  4640. if err != nil {
  4641. br.Msg = "日期变换失败"
  4642. br.ErrMsg = "日期变换失败,Err:" + err.Error()
  4643. return
  4644. }
  4645. list := make([]*data_manage.EdbDataList, 5)
  4646. list, err = data.GetEdbBeforeAndAfterDateData(currDate, dataList)
  4647. if err != nil {
  4648. br.Msg = "获取失败"
  4649. br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
  4650. return
  4651. }
  4652. // 这个日期不存在的话直接返回空数组
  4653. resp := data_manage.BeforeAndAfterDateDataResp{
  4654. List: list,
  4655. Date: currDate,
  4656. }
  4657. br.Ret = 200
  4658. br.Success = true
  4659. br.Msg = "获取成功"
  4660. br.Data = resp
  4661. }
  4662. // EdbChartAdminList
  4663. // @Title 获取创建人员分组
  4664. // @Description 获取创建人员分组
  4665. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  4666. // @Success 200 {object} company.DepartmentGroupSellersResp
  4667. // @router /edb_chart/adminList [get]
  4668. func (this *EdbInfoController) EdbChartAdminList() {
  4669. br := new(models.BaseResponse).Init()
  4670. defer func() {
  4671. this.Data["json"] = br
  4672. this.ServeJSON()
  4673. }()
  4674. sysUser := this.SysUser
  4675. if sysUser == nil {
  4676. br.Msg = "请登录"
  4677. br.ErrMsg = "请登录,SysUser Is Empty"
  4678. br.Ret = 408
  4679. return
  4680. }
  4681. source, _ := this.GetInt("Source", 0)
  4682. if source <= 0 || source > 5 {
  4683. br.Msg = "错误的来源"
  4684. br.IsSendEmail = false
  4685. return
  4686. }
  4687. idList, err := data.GetEdbChartAdminList(source)
  4688. if err != nil {
  4689. //br.Success = true
  4690. br.Msg = "获取失败"
  4691. br.ErrMsg = "获取失败,Err:" + err.Error()
  4692. return
  4693. }
  4694. fmt.Println("idlist:", idList)
  4695. systemAdminMap := make(map[int]*system.Admin)
  4696. departmentMap := make(map[string]string)
  4697. departmentAdminMap := make(map[int]string)
  4698. groupMap := make(map[string]string)
  4699. systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList)
  4700. if err != nil {
  4701. br.Msg = "获取用户列表失败"
  4702. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  4703. return
  4704. }
  4705. for _, v := range systemAdminList {
  4706. systemAdminMap[v.AdminId] = v
  4707. departmentMap[v.DepartmentName] = v.DepartmentName
  4708. departmentAdminMap[v.AdminId] = v.DepartmentName
  4709. groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName
  4710. }
  4711. depList := make([]company.DepartmentGroupAdmins, 0)
  4712. i := 1
  4713. for _, v := range departmentMap {
  4714. item := company.DepartmentGroupAdmins{
  4715. AdminId: "dep_" + strconv.Itoa(i),
  4716. RealName: v,
  4717. }
  4718. i++
  4719. depList = append(depList, item)
  4720. }
  4721. for k := 0; k < len(depList); k++ {
  4722. for k1, v1 := range groupMap {
  4723. if v1 == depList[k].RealName && v1 != "" {
  4724. item := &company.DepartmentGroupAdmins{
  4725. AdminId: "group_" + strconv.Itoa(k),
  4726. RealName: strings.Replace(k1, v1, "", -1),
  4727. }
  4728. depList[k].ChildrenList = append(depList[k].ChildrenList, item)
  4729. }
  4730. }
  4731. }
  4732. for _, admin := range systemAdminList {
  4733. for i, v := range depList {
  4734. for k, group := range v.ChildrenList {
  4735. if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName {
  4736. item := &company.DepartmentGroupAdmins{
  4737. AdminId: strconv.Itoa(admin.AdminId),
  4738. RealName: admin.RealName,
  4739. RoleTypeCode: admin.RoleTypeCode,
  4740. Authority: admin.Authority,
  4741. }
  4742. if group.RealName != "" {
  4743. depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item)
  4744. } else {
  4745. depList[i].ChildrenList = append(depList[i].ChildrenList, item)
  4746. }
  4747. }
  4748. }
  4749. }
  4750. }
  4751. for i, groupList := range depList {
  4752. for k, v := range groupList.ChildrenList {
  4753. if v.RealName == "" {
  4754. newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...)
  4755. depList[i].ChildrenList = newChildrenList
  4756. }
  4757. }
  4758. }
  4759. br.Ret = 200
  4760. br.Success = true
  4761. br.Msg = "获取成功"
  4762. br.Data = depList
  4763. }
  4764. // EdbSourceList
  4765. // @Title 指标来源列表
  4766. // @Description 指标来源列表
  4767. // @Param IsBase query int false "是否为基础指标: 1-是"
  4768. // @Success 200 {object} data_manage.EdbInfoListResp
  4769. // @router /edb_source/list [get]
  4770. func (this *EdbInfoController) EdbSourceList() {
  4771. br := new(models.BaseResponse).Init()
  4772. defer func() {
  4773. if br.ErrMsg == "" {
  4774. br.IsSendEmail = false
  4775. }
  4776. this.Data["json"] = br
  4777. this.ServeJSON()
  4778. }()
  4779. isBase, _ := this.GetInt("IsBase", 0)
  4780. cond := ``
  4781. if isBase > 0 {
  4782. cond = ` AND is_base = 1`
  4783. }
  4784. pars := make([]interface{}, 0)
  4785. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4786. if e != nil {
  4787. br.Msg = "获取失败"
  4788. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4789. return
  4790. }
  4791. br.Data = list
  4792. br.Ret = 200
  4793. br.Success = true
  4794. br.Msg = "获取成功"
  4795. }
  4796. // EdbSourceListByPython
  4797. // @Title 指标来源列表
  4798. // @Description 指标来源列表
  4799. // @Param IsBase query int false "是否为基础指标: 1-是"
  4800. // @Success 200 {object} data_manage.EdbInfoListResp
  4801. // @router /edb_source/list/python [get]
  4802. func (this *EdbInfoController) EdbSourceListByPython() {
  4803. br := new(models.BaseResponse).Init()
  4804. defer func() {
  4805. if br.ErrMsg == "" {
  4806. br.IsSendEmail = false
  4807. }
  4808. this.Data["json"] = br
  4809. this.ServeJSON()
  4810. }()
  4811. isBase, _ := this.GetInt("IsBase", 0)
  4812. cond := ``
  4813. if isBase > 0 {
  4814. cond = ` AND is_base = 1`
  4815. }
  4816. pars := make([]interface{}, 0)
  4817. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4818. if e != nil {
  4819. br.Msg = "获取失败"
  4820. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4821. return
  4822. }
  4823. baseEdbList := make([]data_manage.EdbSourceChild, 0)
  4824. calEdbList := make([]data_manage.EdbSourceChild, 0)
  4825. for _, v := range list {
  4826. switch v.IsBase {
  4827. case 1:
  4828. baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{
  4829. EdbSourceId: v.EdbSourceId,
  4830. SourceName: v.SourceName,
  4831. IsBase: v.IsBase,
  4832. TableName: v.TableName,
  4833. Child: []data_manage.EdbSourceChild{},
  4834. })
  4835. case 2:
  4836. calEdbList = append(calEdbList, data_manage.EdbSourceChild{
  4837. EdbSourceId: v.EdbSourceId,
  4838. SourceName: v.SourceName,
  4839. IsBase: v.IsBase,
  4840. TableName: v.TableName,
  4841. Child: []data_manage.EdbSourceChild{},
  4842. })
  4843. }
  4844. }
  4845. resp := []data_manage.EdbSourceChild{
  4846. {
  4847. EdbSourceId: 0,
  4848. SourceName: "基础指标",
  4849. IsBase: 1,
  4850. Child: baseEdbList,
  4851. },
  4852. {
  4853. EdbSourceId: 0,
  4854. SourceName: "计算指标",
  4855. IsBase: 1,
  4856. Child: calEdbList,
  4857. },
  4858. }
  4859. br.Data = resp
  4860. br.Ret = 200
  4861. br.Success = true
  4862. br.Msg = "获取成功"
  4863. }
  4864. // EdbChartList
  4865. // @Title 指标缩略图列表接口
  4866. // @Description 指标缩略图列表接口
  4867. // @Param PageSize query int true "每页数据条数"
  4868. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4869. // @Param ClassifyId query int true "分类id"
  4870. // @Param AdminId query int false "创建人id"
  4871. // @Param IsOnlyMe query bool false "是否只看我的"
  4872. // @Success 200 {object} response.EdbInfoChartListResp
  4873. // @router /edb_info/chart/list [get]
  4874. func (this *EdbInfoController) EdbChartList() {
  4875. br := new(models.BaseResponse).Init()
  4876. defer func() {
  4877. if br.ErrMsg == "" {
  4878. br.IsSendEmail = false
  4879. }
  4880. this.Data["json"] = br
  4881. this.ServeJSON()
  4882. }()
  4883. sysUser := this.SysUser
  4884. if sysUser == nil {
  4885. br.Msg = "请登录"
  4886. br.ErrMsg = "请登录,SysUser Is Empty"
  4887. br.Ret = 408
  4888. return
  4889. }
  4890. // 分页
  4891. pageSize, _ := this.GetInt("PageSize")
  4892. currentIndex, _ := this.GetInt("CurrentIndex")
  4893. var total int
  4894. page := paging.GetPaging(currentIndex, pageSize, total)
  4895. var startSize int
  4896. if pageSize <= 0 {
  4897. pageSize = utils.PageSize20
  4898. }
  4899. if currentIndex <= 0 {
  4900. currentIndex = 1
  4901. }
  4902. startSize = paging.StartIndex(currentIndex, pageSize)
  4903. // 基础指标
  4904. var condition string
  4905. var pars []interface{}
  4906. condition += ` AND edb_info_type = ? `
  4907. pars = append(pars, 0)
  4908. // 分类筛选
  4909. classifyId, _ := this.GetInt("ClassifyId")
  4910. if classifyId > 0 {
  4911. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  4912. if e != nil && e.Error() != utils.ErrNoRow() {
  4913. br.Msg = "获取失败"
  4914. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  4915. return
  4916. }
  4917. var classifyIds []int
  4918. for _, v := range childClassify {
  4919. classifyIds = append(classifyIds, v.ClassifyId)
  4920. }
  4921. condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  4922. pars = append(pars, classifyIds)
  4923. }
  4924. // 创建人
  4925. adminId, _ := this.GetInt("AdminId")
  4926. if adminId > 0 {
  4927. condition += ` AND sys_user_id = ? `
  4928. pars = append(pars, adminId)
  4929. }
  4930. // 只看我的
  4931. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  4932. if isOnlyMe {
  4933. condition += ` AND sys_user_id = ? `
  4934. pars = append(pars, sysUser.AdminId)
  4935. }
  4936. // 获取当前账号的不可见指标
  4937. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4938. confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4939. if e != nil {
  4940. br.Msg = "获取失败"
  4941. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
  4942. return
  4943. }
  4944. noPermissionEdbInfoIdList := make([]int, 0)
  4945. for _, v := range confList {
  4946. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  4947. }
  4948. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  4949. if noPermissionEdbInfoIdNum > 0 {
  4950. condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  4951. pars = append(pars, noPermissionEdbInfoIdList)
  4952. }
  4953. // 获取指标信息
  4954. dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  4955. if e != nil {
  4956. br.Msg = "获取失败"
  4957. br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
  4958. return
  4959. }
  4960. if len(list) == 0 {
  4961. list = make([]*data_manage.EdbInfoList, 0)
  4962. } else {
  4963. classifyIdList := make([]int, 0)
  4964. for _, v := range list {
  4965. classifyIdList = append(classifyIdList, v.ClassifyId)
  4966. }
  4967. // 指标权限
  4968. {
  4969. // 当前的分类
  4970. classifyMap := make(map[int]*data_manage.EdbClassify)
  4971. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4972. if err != nil {
  4973. if err != nil {
  4974. br.Msg = "获取失败"
  4975. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4976. return
  4977. }
  4978. }
  4979. for _, v := range classifyList {
  4980. classifyMap[v.ClassifyId] = v
  4981. }
  4982. // 获取所有有权限的指标和分类
  4983. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4984. if err != nil {
  4985. br.Msg = "获取失败"
  4986. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4987. return
  4988. }
  4989. for _, v := range list {
  4990. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  4991. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4992. v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType, v.HaveOperaAuth)
  4993. }
  4994. }
  4995. }
  4996. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  4997. }
  4998. resp := response.EdbInfoChartListResp{
  4999. Paging: page,
  5000. List: list,
  5001. }
  5002. br.Ret = 200
  5003. br.Success = true
  5004. br.Msg = "获取成功"
  5005. br.Data = resp
  5006. }
  5007. // Modify
  5008. // @Title 修改指标信息接口
  5009. // @Description 编辑指标接口
  5010. // @Success 200 string "操作成功"
  5011. // @router /edb_info/modify [post]
  5012. func (this *EdbInfoController) Modify() {
  5013. br := new(models.BaseResponse).Init()
  5014. defer func() {
  5015. if br.ErrMsg == "" {
  5016. br.IsSendEmail = false
  5017. }
  5018. this.Data["json"] = br
  5019. this.ServeJSON()
  5020. }()
  5021. sysUser := this.SysUser
  5022. if sysUser == nil {
  5023. br.Msg = "请登录"
  5024. br.ErrMsg = "请登录,SysUser Is Empty"
  5025. br.Ret = 408
  5026. return
  5027. }
  5028. var req request.ModifyEdbInfoReq
  5029. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5030. if err != nil {
  5031. br.Msg = "参数解析异常!"
  5032. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5033. return
  5034. }
  5035. edbInfoId := req.EdbInfoId
  5036. if edbInfoId <= 0 {
  5037. br.Msg = "请选择指标"
  5038. br.IsSendEmail = false
  5039. return
  5040. }
  5041. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5042. if e != nil {
  5043. br.Msg = "操作失败"
  5044. br.ErrMsg = "获取指标信息失败, Err:" + err.Error()
  5045. return
  5046. }
  5047. var haveOperaAuth bool
  5048. // 权限校验
  5049. {
  5050. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
  5051. if err != nil {
  5052. br.Msg = err.Error()
  5053. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  5054. return
  5055. }
  5056. }
  5057. // 编辑权限校验
  5058. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  5059. if !button.OpButton {
  5060. br.Msg = "无权限操作"
  5061. return
  5062. }
  5063. edbInfo.MaxValue = req.MaxValue
  5064. edbInfo.MinValue = req.MinValue
  5065. edbInfo.ManualSave = 1
  5066. edbInfo.ModifyTime = time.Now()
  5067. err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"})
  5068. if err != nil {
  5069. br.Msg = "获取失败"
  5070. br.ErrMsg = "获取失败,Err:" + err.Error()
  5071. return
  5072. }
  5073. //修改es
  5074. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  5075. br.Ret = 200
  5076. br.Success = true
  5077. br.Msg = "修改成功"
  5078. br.IsAddLog = true
  5079. }
  5080. // ChartImageSet
  5081. // @Title 设置指标的图表图片
  5082. // @Description 设置指标的图表图片接口
  5083. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  5084. // @Success Ret=200 保存成功
  5085. // @router /edb_info/image/set [post]
  5086. func (this *EdbInfoController) ChartImageSet() {
  5087. br := new(models.BaseResponse).Init()
  5088. defer func() {
  5089. if br.ErrMsg == "" {
  5090. br.IsSendEmail = false
  5091. }
  5092. this.Data["json"] = br
  5093. this.ServeJSON()
  5094. }()
  5095. sysUser := this.SysUser
  5096. if sysUser == nil {
  5097. br.Msg = "请登录"
  5098. br.ErrMsg = "请登录,SysUser Is Empty"
  5099. br.Ret = 408
  5100. return
  5101. }
  5102. var req data_manage.SetEdbInfoImageReq
  5103. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  5104. br.Msg = "参数解析异常!"
  5105. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  5106. return
  5107. }
  5108. if req.EdbInfoId <= 0 || req.ImageUrl == "" {
  5109. br.Ret = 200
  5110. br.Success = true
  5111. br.Msg = "保存成功"
  5112. return
  5113. }
  5114. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5115. if e != nil {
  5116. if e.Error() == utils.ErrNoRow() {
  5117. br.Msg = "找不到该指标"
  5118. return
  5119. }
  5120. br.Msg = "保存失败"
  5121. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  5122. return
  5123. }
  5124. edbInfo.ChartImage = req.ImageUrl
  5125. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  5126. br.Msg = "保存失败"
  5127. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  5128. return
  5129. }
  5130. // 修改es数据
  5131. go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  5132. br.Ret = 200
  5133. br.Success = true
  5134. br.Msg = "保存成功"
  5135. }
  5136. // EdbInfoExistCheck
  5137. // @Title 新增指标-检验指标是否存在接口
  5138. // @Description 新增指标-检验指标是否存在接口
  5139. // @Param Source query int true "来源:1:同花顺,2:wind"
  5140. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5141. // @Param EdbCode query string false "指标编码/指标代码"
  5142. // @Param StockCode query string false "证券代码"
  5143. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5144. // @router /edb_info/exist/check [get]
  5145. func (this *EdbInfoController) EdbInfoExistCheck() {
  5146. br := new(models.BaseResponse).Init()
  5147. defer func() {
  5148. this.Data["json"] = br
  5149. this.ServeJSON()
  5150. }()
  5151. source, _ := this.GetInt("Source")
  5152. edbCode := this.GetString("EdbCode")
  5153. edbCode = strings.Trim(edbCode, "\t")
  5154. edbCode = strings.Trim(edbCode, " ")
  5155. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5156. subSource, _ := this.GetInt("SubSource")
  5157. stockCode := this.GetString("StockCode")
  5158. if source <= 0 {
  5159. br.Msg = "无效的数据来源"
  5160. return
  5161. }
  5162. if edbCode == "" {
  5163. br.Msg = "请输入指标ID"
  5164. return
  5165. }
  5166. if source != utils.DATA_SOURCE_WIND && source != utils.DATA_SOURCE_THS {
  5167. br.Msg = "无效的数据来源"
  5168. return
  5169. }
  5170. if subSource != utils.DATA_SUB_SOURCE_DATE {
  5171. br.Msg = "无效的数据库来源"
  5172. return
  5173. }
  5174. var indexCodeArr []string
  5175. edbCodeArr := strings.Split(edbCode, ",")
  5176. stockCodeArr := strings.Split(stockCode, ",")
  5177. var prefix string
  5178. if source == utils.DATA_SOURCE_WIND {
  5179. prefix = utils.WindDbWsd
  5180. } else if source == utils.DATA_SOURCE_THS {
  5181. prefix = utils.ThsDs
  5182. } else {
  5183. br.Msg = "来源错误"
  5184. br.ErrMsg = "来源错误"
  5185. return
  5186. }
  5187. for _, sv := range stockCodeArr {
  5188. for _, ev := range edbCodeArr {
  5189. indexCode := prefix + sv + ev
  5190. indexCodeArr = append(indexCodeArr, indexCode)
  5191. }
  5192. }
  5193. indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr)
  5194. if err != nil && err.Error() != utils.ErrNoRow() {
  5195. br.Msg = "校验指标是否存在失败"
  5196. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5197. return
  5198. }
  5199. var existStockCodeArr []string
  5200. var existEdbCodeArr []string
  5201. var existClassifyId []int
  5202. var existIndexId []int
  5203. for _, indexItem := range indexList {
  5204. for _, sv := range stockCodeArr {
  5205. for _, ev := range edbCodeArr {
  5206. if strings.Contains(indexItem.EdbCode, sv) {
  5207. existStockCodeArr = append(existStockCodeArr, sv)
  5208. }
  5209. if strings.Contains(indexItem.EdbCode, ev) {
  5210. existEdbCodeArr = append(existEdbCodeArr, ev)
  5211. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5212. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5213. }
  5214. }
  5215. }
  5216. }
  5217. resp := new(data_manage.EdbInfoExistCheckResp)
  5218. if len(indexList) > 0 {
  5219. resp.IndexExist = true
  5220. }
  5221. resp.ExistEdbCodeArr = existEdbCodeArr
  5222. resp.ExistStockCodeArr = existStockCodeArr
  5223. resp.ExistClassifyId = existClassifyId
  5224. resp.ExistIndexId = existIndexId
  5225. resp.ExistEdbInfo = indexList
  5226. br.Ret = 200
  5227. br.Success = true
  5228. br.Msg = "获取成功"
  5229. br.Data = resp
  5230. }
  5231. // EdbInfoAdd
  5232. // @Title 指标批量保存接口
  5233. // @Description 指标批量保存接口
  5234. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  5235. // @Success Ret=200 保存成功
  5236. // @router /edb_info/batch/add [post]
  5237. func (this *EdbInfoController) EdbInfoBatchAdd() {
  5238. br := new(models.BaseResponse).Init()
  5239. defer func() {
  5240. this.Data["json"] = br
  5241. this.ServeJSON()
  5242. }()
  5243. sysUser := this.SysUser
  5244. if sysUser == nil {
  5245. br.Msg = "请登录"
  5246. br.ErrMsg = "请登录,SysUser Is Empty"
  5247. br.Ret = 408
  5248. return
  5249. }
  5250. deleteCache := true
  5251. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  5252. defer func() {
  5253. if deleteCache {
  5254. utils.Rc.Delete(cacheKey)
  5255. }
  5256. }()
  5257. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  5258. deleteCache = false
  5259. br.Msg = "系统处理中,请稍后重试!"
  5260. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  5261. return
  5262. }
  5263. var req data_manage.BatchAddEdbInfoReq
  5264. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5265. if err != nil {
  5266. br.Msg = "参数解析异常!"
  5267. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5268. return
  5269. }
  5270. resp := new(data_manage.AddEdbInfoResp)
  5271. var edbNames string
  5272. for _, v := range req.BatchList {
  5273. edbNames += "'" + v.EdbName + "',"
  5274. }
  5275. edbNames = strings.Trim(edbNames, ",")
  5276. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  5277. if err != nil {
  5278. br.Msg = "查询指标名称重复错误!"
  5279. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  5280. return
  5281. }
  5282. if len(infoList) > 0 {
  5283. for _, v := range infoList {
  5284. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  5285. }
  5286. br.Data = resp
  5287. br.Msg = "指标名称重复!"
  5288. br.ErrMsg = "指标名称重复"
  5289. return
  5290. }
  5291. for k, v := range req.BatchList {
  5292. v.EdbName = strings.Trim(v.EdbName, " ")
  5293. v.EdbCode = strings.Trim(v.EdbCode, " ")
  5294. v.StockCode = strings.Trim(v.StockCode, " ")
  5295. if v.Source <= 0 {
  5296. br.Msg = "无效的数据来源"
  5297. return
  5298. }
  5299. if v.EdbCode == "" {
  5300. br.Msg = "指标ID不能为空"
  5301. return
  5302. }
  5303. if v.StockCode == "" {
  5304. br.Msg = "证券代码不能为空"
  5305. return
  5306. }
  5307. if v.EdbName == "" {
  5308. br.Msg = "指标名称不能为空"
  5309. return
  5310. }
  5311. if v.Frequency == "" {
  5312. br.Msg = "频率不能为空"
  5313. return
  5314. }
  5315. if v.ClassifyId <= 0 {
  5316. br.Msg = "请选择分类"
  5317. return
  5318. }
  5319. terminalCode, serverUrl, _, e := data.GetEdbTerminalCodeBySource(v.Source, v.EdbCode, v.StockCode)
  5320. if e != nil {
  5321. br.Msg = "获取可以使用的终端地址失败"
  5322. br.ErrMsg = "获取可以使用的终端地址失败,Err:" + e.Error()
  5323. return
  5324. }
  5325. edbInfoItem := new(data_manage.EdbInfo)
  5326. edbInfoItem.Source = v.Source
  5327. switch v.Source {
  5328. case utils.DATA_SOURCE_WIND:
  5329. edbInfoItem.SourceName = "wind"
  5330. edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
  5331. case utils.DATA_SOURCE_THS:
  5332. edbInfoItem.SourceName = "ths"
  5333. edbInfoItem.EdbCode = utils.ThsDs + v.StockCode + v.EdbCode
  5334. }
  5335. edbInfoItem.SubSource = 1
  5336. edbInfoItem.SubSourceName = "日期序列"
  5337. edbInfoItem.EdbName = v.EdbName
  5338. edbInfoItem.Frequency = v.Frequency
  5339. edbInfoItem.Unit = v.Unit
  5340. edbInfoItem.ClassifyId = v.ClassifyId
  5341. edbInfoItem.SysUserId = sysUser.AdminId
  5342. edbInfoItem.SysUserRealName = sysUser.RealName
  5343. edbInfoItem.IndicatorCode = v.EdbCode
  5344. edbInfoItem.StockCode = v.StockCode
  5345. edbInfoItem.TerminalCode = terminalCode
  5346. edbInfoItem.ServerUrl = serverUrl
  5347. // 指标入库
  5348. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  5349. if err != nil {
  5350. br.Msg = "保存失败"
  5351. if errMsg != `` {
  5352. br.Msg = errMsg
  5353. }
  5354. br.ErrMsg = err.Error()
  5355. br.IsSendEmail = isSendEmail
  5356. return
  5357. }
  5358. //新增操作日志
  5359. {
  5360. edbLog := new(data_manage.EdbInfoLog)
  5361. edbLog.EdbInfoId = edbInfo.EdbInfoId
  5362. edbLog.SourceName = edbInfo.SourceName
  5363. edbLog.Source = edbInfo.Source
  5364. edbLog.EdbCode = edbInfo.EdbCode
  5365. edbLog.EdbName = edbInfo.EdbName
  5366. edbLog.ClassifyId = edbInfo.ClassifyId
  5367. edbLog.SysUserId = sysUser.AdminId
  5368. edbLog.SysUserRealName = sysUser.RealName
  5369. edbLog.CreateTime = time.Now()
  5370. edbLog.Content = string(this.Ctx.Input.RequestBody)
  5371. edbLog.Status = "新增指标"
  5372. edbLog.Method = this.Ctx.Input.URI()
  5373. go data_manage.AddEdbInfoLog(edbLog)
  5374. }
  5375. if k <= 0 {
  5376. resp.EdbInfoId = edbInfo.EdbInfoId
  5377. resp.UniqueCode = edbInfo.UniqueCode
  5378. }
  5379. }
  5380. // 试用平台更新用户累计新增指标数
  5381. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  5382. if e != nil {
  5383. br.Msg = "操作失败"
  5384. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  5385. return
  5386. }
  5387. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  5388. go func() {
  5389. var r etaTrialService.EtaTrialUserReq
  5390. r.Mobile = adminItem.Mobile
  5391. _, _ = etaTrialService.UpdateUserIndexNum(r)
  5392. }()
  5393. }
  5394. br.Ret = 200
  5395. br.Success = true
  5396. br.Msg = "保存成功"
  5397. br.Data = resp
  5398. br.IsAddLog = true
  5399. }
  5400. // SmmExistCheck
  5401. // @Title 新增指标-检验指标是否存在接口-smm
  5402. // @Description 新增指标-检验指标是否存在接口-smm
  5403. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5404. // @Param EdbCode query string false "指标编码/指标代码"
  5405. // @Param StockCode query string false "证券代码"
  5406. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5407. // @router /edb_info/smm/exist/check [post]
  5408. func (this *EdbInfoController) SmmExistCheck() {
  5409. br := new(models.BaseResponse).Init()
  5410. defer func() {
  5411. this.Data["json"] = br
  5412. this.ServeJSON()
  5413. }()
  5414. var req data_manage.SmmIndexExistCheckReq
  5415. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5416. if err != nil {
  5417. br.Msg = "参数解析异常!"
  5418. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5419. return
  5420. }
  5421. types := req.Types
  5422. frequency := req.Frequency
  5423. dataState := req.DataState
  5424. selectAll := req.SelectAll
  5425. keyword := req.Keyword
  5426. edbCode := req.EdbCode
  5427. edbCode = strings.Trim(edbCode, "\t")
  5428. edbCode = strings.Trim(edbCode, " ")
  5429. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5430. var edbCodeArr []string
  5431. var codeArr []string
  5432. if selectAll {
  5433. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5434. var condition string
  5435. var pars []interface{}
  5436. if len(types) > 0 {
  5437. condition += " AND ( "
  5438. for _, v := range types {
  5439. typeArr := strings.Split(v, ",")
  5440. for i, v := range typeArr {
  5441. if i == 0 {
  5442. condition += " ( "
  5443. }
  5444. typeStr := "type_"
  5445. typeStr += fmt.Sprintf("%d", i+1)
  5446. condition += typeStr + " =? "
  5447. pars = append(pars, v)
  5448. if i == len(typeArr)-1 {
  5449. condition += " ) "
  5450. } else {
  5451. condition += " AND "
  5452. }
  5453. }
  5454. condition += " OR "
  5455. }
  5456. condition = strings.Trim(condition, "OR ")
  5457. condition += " ) "
  5458. }
  5459. if frequency != "" {
  5460. frequencyArr := strings.Split(frequency, ",")
  5461. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5462. pars = append(pars, frequencyArr)
  5463. }
  5464. if dataState != "" {
  5465. stateArr := strings.Split(dataState, ",")
  5466. if strings.Contains(dataState, "normal") {
  5467. stateArr = append(stateArr, "")
  5468. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5469. pars = append(pars, stateArr)
  5470. } else {
  5471. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5472. pars = append(pars, stateArr)
  5473. }
  5474. }
  5475. if keyword != "" {
  5476. keyWordArr := strings.Split(keyword, " ")
  5477. if len(keyWordArr) > 0 {
  5478. condition += " AND ( "
  5479. for _, v := range keyWordArr {
  5480. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5481. }
  5482. condition = strings.TrimRight(condition, "OR")
  5483. condition += " ) "
  5484. }
  5485. }
  5486. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5487. if err != nil {
  5488. br.Msg = "获取指标列表失败"
  5489. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5490. return
  5491. }
  5492. for _, v := range indexList {
  5493. codeArr = append(codeArr, v.IndexCode)
  5494. }
  5495. noUseCodeArr := strings.Split(edbCode, ",")
  5496. for _, code := range codeArr {
  5497. // 检查code是否在noUseCodeArr数组中
  5498. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5499. // 如果不在,将其添加到结果数组中
  5500. edbCodeArr = append(edbCodeArr, code)
  5501. }
  5502. }
  5503. } else {
  5504. //未勾选全选EdbCode就是需要的code
  5505. edbCodeArr = strings.Split(edbCode, ",")
  5506. }
  5507. if len(edbCodeArr) > 30 {
  5508. br.Msg = "最多只能选择30个指标"
  5509. return
  5510. }
  5511. if len(edbCodeArr) <= 0 {
  5512. br.Msg = "无符合指标或指标代码错误"
  5513. return
  5514. }
  5515. indexList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_YS, edbCodeArr)
  5516. if err != nil && err.Error() != utils.ErrNoRow() {
  5517. br.Msg = "校验指标是否存在失败"
  5518. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5519. return
  5520. }
  5521. var existEdbCodeArr []string
  5522. var existClassifyId []int
  5523. var existIndexId []int
  5524. for _, indexItem := range indexList {
  5525. for _, ev := range edbCodeArr {
  5526. if strings.Contains(indexItem.EdbCode, ev) {
  5527. existEdbCodeArr = append(existEdbCodeArr, ev)
  5528. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5529. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5530. }
  5531. }
  5532. }
  5533. resp := new(data_manage.EdbInfoSmmExistCheckResp)
  5534. if len(indexList) > 0 {
  5535. resp.IndexExist = true
  5536. }
  5537. if len(existEdbCodeArr) == len(edbCodeArr) {
  5538. resp.ExistAll = true
  5539. }
  5540. resp.ExistEdbCodeArr = existEdbCodeArr
  5541. resp.ExistClassifyId = existClassifyId
  5542. resp.ExistIndexId = existIndexId
  5543. resp.ExistEdbInfo = indexList
  5544. br.Ret = 200
  5545. br.Success = true
  5546. br.Msg = "获取成功"
  5547. br.Data = resp
  5548. }
  5549. // EdbInfoSearch
  5550. // @Title 新增指标-查询指标信息接口-smm
  5551. // @Description 新增指标-查询指标信息接口-smm
  5552. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  5553. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5554. // @Param EdbCode query string false "指标编码/指标代码"
  5555. // @Param StockCode query string false "证券代码"
  5556. // @Success 200 {object} data_manage.EdbInfoSearchResp
  5557. // @router /edb_info/smm/search [post]
  5558. func (this *EdbInfoController) EdbInfoSmmSearch() {
  5559. br := new(models.BaseResponse).Init()
  5560. defer func() {
  5561. this.Data["json"] = br
  5562. this.ServeJSON()
  5563. }()
  5564. var req data_manage.SmmIndexExistCheckReq
  5565. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5566. if err != nil {
  5567. br.Msg = "参数解析异常!"
  5568. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5569. return
  5570. }
  5571. types := req.Types
  5572. frequency := req.Frequency
  5573. dataState := req.DataState
  5574. selectAll := req.SelectAll
  5575. keyword := req.Keyword
  5576. edbCode := req.EdbCode
  5577. edbCode = strings.Trim(edbCode, "\t")
  5578. edbCode = strings.Trim(edbCode, " ")
  5579. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5580. var edbCodeArr []string
  5581. var codeArr []string
  5582. if selectAll {
  5583. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5584. var condition string
  5585. var pars []interface{}
  5586. if len(types) > 0 {
  5587. condition += " AND ( "
  5588. for _, v := range types {
  5589. typeArr := strings.Split(v, ",")
  5590. for i, v := range typeArr {
  5591. if i == 0 {
  5592. condition += " ( "
  5593. }
  5594. typeStr := "type_"
  5595. typeStr += fmt.Sprintf("%d", i+1)
  5596. condition += typeStr + " =? "
  5597. pars = append(pars, v)
  5598. if i == len(typeArr)-1 {
  5599. condition += " ) "
  5600. } else {
  5601. condition += " AND "
  5602. }
  5603. }
  5604. condition += " OR "
  5605. }
  5606. condition = strings.Trim(condition, "OR ")
  5607. condition += " ) "
  5608. }
  5609. if frequency != "" {
  5610. frequencyArr := strings.Split(frequency, ",")
  5611. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5612. pars = append(pars, frequencyArr)
  5613. }
  5614. if dataState != "" {
  5615. stateArr := strings.Split(dataState, ",")
  5616. if strings.Contains(dataState, "normal") {
  5617. stateArr = append(stateArr, "")
  5618. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5619. pars = append(pars, stateArr)
  5620. } else {
  5621. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5622. pars = append(pars, stateArr)
  5623. }
  5624. }
  5625. if keyword != "" {
  5626. keyWordArr := strings.Split(keyword, " ")
  5627. if len(keyWordArr) > 0 {
  5628. condition += " AND ( "
  5629. for _, v := range keyWordArr {
  5630. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5631. }
  5632. condition = strings.TrimRight(condition, "OR")
  5633. condition += " ) "
  5634. }
  5635. }
  5636. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5637. if err != nil {
  5638. br.Msg = "获取指标列表失败"
  5639. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5640. return
  5641. }
  5642. for _, v := range indexList {
  5643. codeArr = append(codeArr, v.IndexCode)
  5644. }
  5645. noUseCodeArr := strings.Split(edbCode, ",")
  5646. for _, code := range codeArr {
  5647. // 检查code是否在noUseCodeArr数组中
  5648. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5649. // 如果不在,将其添加到结果数组中
  5650. edbCodeArr = append(edbCodeArr, code)
  5651. }
  5652. }
  5653. } else {
  5654. //未勾选全选EdbCode就是需要的code
  5655. edbCodeArr = strings.Split(edbCode, ",")
  5656. }
  5657. if len(edbCodeArr) > 30 {
  5658. br.Msg = "最多只能选择30个指标"
  5659. return
  5660. }
  5661. if len(edbCodeArr) <= 0 {
  5662. br.Msg = "无符合指标或指标代码错误"
  5663. return
  5664. }
  5665. edbCodeStr := ""
  5666. for i, _ := range edbCodeArr {
  5667. edbCodeStr += "'" + edbCodeArr[i] + "'" + ","
  5668. }
  5669. edbCodeStr = strings.Trim(edbCodeStr, ",")
  5670. smmInfoList, err := data_manage.GetBaseFromSmmIndexByIndexCodes(edbCodeStr)
  5671. if err != nil && err.Error() != utils.ErrNoRow() {
  5672. br.Msg = "获取失败"
  5673. br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
  5674. return
  5675. }
  5676. smmInfoMap := make(map[string]*data_manage.BaseFromSmmIndex)
  5677. for _, v := range smmInfoList {
  5678. smmInfoMap[v.IndexCode] = v
  5679. }
  5680. searchItemList := make([]*data_manage.EdbInfoSearch, 0)
  5681. resp := new(data_manage.EdbInfoSearchResp)
  5682. needAddCodeArr := make([]string, 0)
  5683. noNeedAddCodeMap := make(map[string]string, 0)
  5684. for _, edbCode := range edbCodeArr {
  5685. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  5686. if err != nil && err.Error() != utils.ErrNoRow() {
  5687. br.Msg = "获取失败"
  5688. br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
  5689. return
  5690. }
  5691. fmt.Println("dataItems:", len(dataItems))
  5692. if len(dataItems) > 0 {
  5693. searchItem := new(data_manage.EdbInfoSearch)
  5694. searchItem.EdbCode = edbCode
  5695. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  5696. if err != nil {
  5697. br.Msg = "获取失败"
  5698. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  5699. return
  5700. }
  5701. searchItem.DataList = dataItems
  5702. searchItem.StartDate = minDate
  5703. searchItem.EndDate = maxDate
  5704. searchItem.Frequency = smmInfoMap[edbCode].Frequency
  5705. searchItem.Unit = smmInfoMap[edbCode].Unit
  5706. searchItem.EdbName = smmInfoMap[edbCode].IndexName
  5707. searchItem.EdbCode = smmInfoMap[edbCode].IndexCode
  5708. searchItemList = append(searchItemList, searchItem)
  5709. noNeedAddCodeMap[edbCode] = edbCode
  5710. } else {
  5711. // 把需要新加的code添加到needAddCodeArr数组中,一起批量请求
  5712. needAddCodeArr = append(needAddCodeArr, edbCode)
  5713. }
  5714. }
  5715. if len(needAddCodeArr) > 0 {
  5716. edbCode = strings.Join(needAddCodeArr, ",")
  5717. respItem, err := data.AddEdbData(utils.DATA_SOURCE_YS, edbCode, "")
  5718. if err != nil {
  5719. br.Msg = "获取失败"
  5720. br.ErrMsg = "获取失败,Err:" + err.Error()
  5721. return
  5722. }
  5723. if respItem.Ret != 200 {
  5724. if respItem.Ret == 421 {
  5725. br.Msg = "该渠道已超过添加上限"
  5726. } else if respItem.Ret == 4052 {
  5727. br.Msg = "该指标已下架"
  5728. } else {
  5729. br.Msg = "未搜索到该指标"
  5730. }
  5731. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  5732. return
  5733. }
  5734. }
  5735. for _, smmInfo := range smmInfoList {
  5736. if smmInfo != nil {
  5737. if _, ok := noNeedAddCodeMap[smmInfo.IndexCode]; !ok {
  5738. searchItem := new(data_manage.EdbInfoSearch)
  5739. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(smmInfo.IndexCode)
  5740. if err != nil {
  5741. br.Msg = "获取失败"
  5742. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  5743. return
  5744. }
  5745. searchItem.StartDate = minDate
  5746. searchItem.EndDate = maxDate
  5747. searchItem.Frequency = smmInfo.Frequency
  5748. searchItem.Unit = smmInfo.Unit
  5749. searchItem.EdbName = smmInfo.IndexName
  5750. searchItem.EdbCode = smmInfo.IndexCode
  5751. dataList, err := data_manage.GetEdbDataAllByEdbCode(smmInfo.IndexCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  5752. if err != nil && err.Error() != utils.ErrNoRow() {
  5753. br.Msg = "获取失败"
  5754. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  5755. return
  5756. }
  5757. searchItem.DataList = dataList
  5758. searchItemList = append(searchItemList, searchItem)
  5759. }
  5760. }
  5761. }
  5762. resp.Status = 2
  5763. resp.StockSearchList = searchItemList
  5764. br.Ret = 200
  5765. br.Success = true
  5766. br.Msg = "获取成功"
  5767. br.Data = resp
  5768. }
  5769. // SmmEdbInfoBatchAdd
  5770. // @Title 指标批量保存接口-smm
  5771. // @Description 指标批量保存接口-smm
  5772. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  5773. // @Success Ret=200 保存成功
  5774. // @router /edb_info/smm/batch/add [post]
  5775. func (this *EdbInfoController) SmmEdbInfoBatchAdd() {
  5776. br := new(models.BaseResponse).Init()
  5777. defer func() {
  5778. this.Data["json"] = br
  5779. this.ServeJSON()
  5780. }()
  5781. sysUser := this.SysUser
  5782. if sysUser == nil {
  5783. br.Msg = "请登录"
  5784. br.ErrMsg = "请登录,SysUser Is Empty"
  5785. br.Ret = 408
  5786. return
  5787. }
  5788. deleteCache := true
  5789. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  5790. defer func() {
  5791. if deleteCache {
  5792. utils.Rc.Delete(cacheKey)
  5793. }
  5794. }()
  5795. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  5796. deleteCache = false
  5797. br.Msg = "系统处理中,请稍后重试!"
  5798. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  5799. return
  5800. }
  5801. var req data_manage.BatchAddEdbInfoReq
  5802. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5803. if err != nil {
  5804. br.Msg = "参数解析异常!"
  5805. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5806. return
  5807. }
  5808. resp := new(data_manage.AddEdbInfoResp)
  5809. var edbNames string
  5810. for _, v := range req.BatchList {
  5811. edbNames += "'" + v.EdbName + "',"
  5812. }
  5813. edbNames = strings.Trim(edbNames, ",")
  5814. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  5815. if err != nil {
  5816. br.Msg = "查询指标名称重复错误!"
  5817. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  5818. return
  5819. }
  5820. if len(infoList) > 0 {
  5821. for _, v := range infoList {
  5822. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  5823. }
  5824. br.Data = resp
  5825. br.Msg = "指标名称重复!"
  5826. br.ErrMsg = "指标名称重复"
  5827. return
  5828. }
  5829. for k, v := range req.BatchList {
  5830. v.EdbName = strings.Trim(v.EdbName, " ")
  5831. v.EdbCode = strings.Trim(v.EdbCode, " ")
  5832. if v.Source <= 0 {
  5833. br.Msg = "无效的数据来源"
  5834. return
  5835. }
  5836. if v.EdbCode == "" {
  5837. br.Msg = "指标ID不能为空"
  5838. return
  5839. }
  5840. if v.EdbName == "" {
  5841. br.Msg = "指标名称不能为空"
  5842. return
  5843. }
  5844. if v.Frequency == "" {
  5845. br.Msg = "频率不能为空"
  5846. return
  5847. }
  5848. if v.ClassifyId <= 0 {
  5849. br.Msg = "请选择分类"
  5850. return
  5851. }
  5852. edbInfoItem := new(data_manage.EdbInfo)
  5853. edbInfoItem.Source = v.Source
  5854. edbInfoItem.SourceName = "SMM"
  5855. edbInfoItem.EdbCode = v.EdbCode
  5856. edbInfoItem.SubSource = 0
  5857. edbInfoItem.SubSourceName = ""
  5858. edbInfoItem.EdbName = v.EdbName
  5859. edbInfoItem.Frequency = v.Frequency
  5860. edbInfoItem.Unit = v.Unit
  5861. edbInfoItem.ClassifyId = v.ClassifyId
  5862. edbInfoItem.SysUserId = sysUser.AdminId
  5863. edbInfoItem.SysUserRealName = sysUser.RealName
  5864. edbInfoItem.IndicatorCode = ""
  5865. edbInfoItem.StockCode = ""
  5866. // 指标入库
  5867. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  5868. if err != nil {
  5869. br.Msg = "保存失败"
  5870. if errMsg != `` {
  5871. br.Msg = errMsg
  5872. }
  5873. br.ErrMsg = err.Error()
  5874. br.IsSendEmail = isSendEmail
  5875. return
  5876. }
  5877. //新增操作日志
  5878. {
  5879. edbLog := new(data_manage.EdbInfoLog)
  5880. edbLog.EdbInfoId = edbInfo.EdbInfoId
  5881. edbLog.SourceName = edbInfo.SourceName
  5882. edbLog.Source = edbInfo.Source
  5883. edbLog.EdbCode = edbInfo.EdbCode
  5884. edbLog.EdbName = edbInfo.EdbName
  5885. edbLog.ClassifyId = edbInfo.ClassifyId
  5886. edbLog.SysUserId = sysUser.AdminId
  5887. edbLog.SysUserRealName = sysUser.RealName
  5888. edbLog.CreateTime = time.Now()
  5889. edbLog.Content = string(this.Ctx.Input.RequestBody)
  5890. edbLog.Status = "新增指标"
  5891. edbLog.Method = this.Ctx.Input.URI()
  5892. go data_manage.AddEdbInfoLog(edbLog)
  5893. }
  5894. if k <= 0 {
  5895. resp.EdbInfoId = edbInfo.EdbInfoId
  5896. resp.UniqueCode = edbInfo.UniqueCode
  5897. }
  5898. }
  5899. br.Ret = 200
  5900. br.Success = true
  5901. br.Msg = "保存成功"
  5902. br.Data = resp
  5903. br.IsAddLog = true
  5904. }