edb_info.go 197 KB

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