edb_info.go 191 KB

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