edb_info.go 188 KB

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