edb_info.go 202 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908
  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. "sort"
  24. "strconv"
  25. "strings"
  26. "sync"
  27. "time"
  28. "github.com/rdlucklib/rdluck_tools/paging"
  29. )
  30. // EdbInfoController 数据管理
  31. type EdbInfoController struct {
  32. controllers.BaseAuthController
  33. }
  34. // EdbInfoSearch
  35. // @Title 新增指标-查询指标信息接口
  36. // @Description 新增指标-查询指标信息接口
  37. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  38. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  39. // @Param EdbCode query string false "指标编码/指标代码"
  40. // @Param StockCode query string false "证券代码"
  41. // @Param Frequency query string false "频度"
  42. // @Success 200 {object} data_manage.EdbInfoSearchResp
  43. // @router /edb_info/search [get]
  44. func (this *EdbInfoController) EdbInfoSearch() {
  45. br := new(models.BaseResponse).Init()
  46. defer func() {
  47. this.Data["json"] = br
  48. this.ServeJSON()
  49. }()
  50. source, _ := this.GetInt("Source")
  51. edbCode := this.GetString("EdbCode")
  52. edbCode = strings.Trim(edbCode, "\t")
  53. edbCode = strings.Trim(edbCode, " ")
  54. edbCode = strings.Replace(edbCode, "\t", "", -1)
  55. subSource, _ := this.GetInt("SubSource")
  56. stockCode := this.GetString("StockCode")
  57. frequency := this.GetString("Frequency")
  58. extraPars := this.GetString("ExtraPars")
  59. extraPars = strings.TrimSpace(extraPars)
  60. if source <= 0 {
  61. br.Msg = "无效的数据来源"
  62. return
  63. }
  64. if edbCode == "" {
  65. br.Msg = "请输入指标ID"
  66. return
  67. }
  68. //如果是彭博财务指标,那么需要传入客户code
  69. if source == utils.DATA_SOURCE_PB_FINANCE {
  70. companyCode := this.GetString("CompanyCode")
  71. companyCode = strings.Trim(companyCode, "\t")
  72. companyCode = strings.Trim(companyCode, " ")
  73. companyCode = strings.Replace(companyCode, "\t", "", -1)
  74. // 如果财务数据,那么需要拼接上客户code
  75. edbCode = companyCode + "&&" + edbCode
  76. }
  77. resp := new(data_manage.EdbInfoSearchResp)
  78. //判断指标是否存在
  79. var item *data_manage.EdbInfo
  80. var err error
  81. if utils.InArrayByInt([]int{utils.DATA_SOURCE_GL, utils.DATA_SOURCE_MYSTEEL_CHEMICAL}, source) {
  82. //source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  83. source, item, err = data.GetMySteelSourceByEdbCode(edbCode)
  84. if err != nil {
  85. br.Msg = "获取失败"
  86. br.ErrMsg = "获取失败,Err:" + err.Error()
  87. return
  88. }
  89. }
  90. if item == nil {
  91. item, err = data_manage.GetEdbInfoByEdbCode(source, edbCode)
  92. if err != nil {
  93. if err.Error() != utils.ErrNoRow() {
  94. br.Msg = "获取失败"
  95. br.ErrMsg = "获取失败,Err:" + err.Error()
  96. return
  97. }
  98. }
  99. }
  100. var isAdd bool
  101. var isInEdb bool //是否在指标库中
  102. if item != nil && item.EdbInfoId > 0 {
  103. isInEdb = true //在指标库中
  104. resp.Status = 1
  105. searchItem := new(data_manage.EdbInfoSearch)
  106. searchItem.EdbCode = item.EdbCode
  107. searchItem.StartDate = item.StartDate
  108. searchItem.EndDate = item.EndDate
  109. searchItem.EdbName = item.EdbName
  110. resp.SearchItem = searchItem
  111. //查询目录
  112. resultList, _ := data_manage.GetClassifyAllByClassifyId(item.ClassifyId)
  113. resp.ClassifyList = resultList
  114. // 查询该指标是否有权限
  115. obj := data_manage.EdbInfoNoPermissionAdmin{}
  116. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, item.EdbInfoId)
  117. if err != nil && err.Error() != utils.ErrNoRow() {
  118. br.Msg = "获取失败"
  119. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  120. return
  121. }
  122. if conf != nil {
  123. resp.Status = 3
  124. }
  125. } else {
  126. //dateNow := time.Now()
  127. //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDate)
  128. searchItem := new(data_manage.EdbInfoSearch)
  129. if source == utils.DATA_SOURCE_THS {
  130. fmt.Println("subSource:", subSource)
  131. if subSource == utils.DATA_SUB_SOURCE_EDB {
  132. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, subSource, utils.EDB_DATA_LIMIT)
  133. if err != nil && err.Error() != utils.ErrNoRow() {
  134. br.Msg = "获取失败"
  135. br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
  136. return
  137. }
  138. fmt.Println("ths len:", len(dataItems))
  139. if len(dataItems) > 0 {
  140. fmt.Println("ths data exist")
  141. searchItem.EdbCode = edbCode
  142. minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
  143. if err != nil {
  144. br.Msg = "获取失败"
  145. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  146. return
  147. }
  148. searchItem.DataList = dataItems
  149. searchItem.StartDate = minDate
  150. searchItem.EndDate = maxDate
  151. } else {
  152. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  153. //searchItem, err = data.GetEdbDataByThs(edbCode, startDate, endDate)
  154. //if err != nil {
  155. // br.Msg = "获取失败"
  156. // br.ErrMsg = "获取失败,Err:" + err.Error()
  157. // return
  158. //}
  159. respItem, err := data.AddEdbData(source, edbCode, frequency)
  160. if err != nil {
  161. br.Msg = "获取失败"
  162. br.ErrMsg = "获取失败,Err:" + err.Error()
  163. return
  164. }
  165. if respItem.Ret != 200 {
  166. br.Msg = "未搜索到该指标"
  167. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  168. return
  169. }
  170. isAdd = true
  171. }
  172. } else if subSource == utils.DATA_SUB_SOURCE_DATE {
  173. if stockCode == "" {
  174. br.Msg = "请输入证券代码"
  175. return
  176. }
  177. if edbCode == "" {
  178. br.Msg = "请输入指标代码"
  179. return
  180. }
  181. respItem, err := data.AddEdbDataThsDs(source, stockCode, edbCode, extraPars)
  182. if err != nil {
  183. br.Msg = "获取失败"
  184. br.ErrMsg = "获取失败,Err:" + err.Error()
  185. return
  186. }
  187. if respItem.Ret != 200 {
  188. if respItem.Ret == 421 {
  189. br.Msg = "该渠道已超过添加上限"
  190. } else if respItem.Ret == 4052 {
  191. br.Msg = "该指标已下架"
  192. } else {
  193. br.Msg = "未搜索到该指标"
  194. }
  195. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  196. return
  197. }
  198. isAdd = true
  199. } else {
  200. br.Msg = "无效的渠道来源"
  201. return
  202. }
  203. } else if source == utils.DATA_SOURCE_WIND {
  204. fmt.Println("subSource:", subSource)
  205. if subSource == utils.DATA_SUB_SOURCE_EDB {
  206. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_WIND, subSource, utils.EDB_DATA_LIMIT)
  207. if err != nil && err.Error() != utils.ErrNoRow() {
  208. br.Msg = "获取失败"
  209. br.ErrMsg = "获取Wind已存在信息失败,Err:" + err.Error()
  210. return
  211. }
  212. fmt.Println("wind dataItems:", len(dataItems))
  213. if len(dataItems) > 0 {
  214. searchItem.EdbCode = edbCode
  215. minDate, maxDate, err := data_manage.GetEdbDataWindMaxOrMinDate(edbCode)
  216. if err != nil {
  217. br.Msg = "获取失败"
  218. br.ErrMsg = "获取wind日期信息失败,Err:" + err.Error()
  219. return
  220. }
  221. searchItem.DataList = dataItems
  222. searchItem.StartDate = minDate
  223. searchItem.EndDate = maxDate
  224. } else {
  225. //endDate := dateNow.Format(utils.FormatDate)
  226. //searchItem, err = data.GetEdbDataByWind(edbCode, startDate, endDate)
  227. //if err != nil {
  228. // br.Msg = "获取失败"
  229. // br.ErrMsg = "wind 获取失败,Err:" + err.Error()
  230. // return
  231. //}
  232. respItem, err := data.AddEdbData(source, edbCode, frequency)
  233. if err != nil {
  234. br.Msg = "获取失败"
  235. br.ErrMsg = "获取失败,Err:" + err.Error()
  236. return
  237. }
  238. if respItem.Ret != 200 {
  239. if respItem.Ret == 421 {
  240. br.Msg = "该渠道已超过添加上限"
  241. } else if respItem.Ret == 4052 {
  242. br.Msg = "该指标已下架"
  243. } else {
  244. br.Msg = "未搜索到该指标"
  245. }
  246. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  247. return
  248. }
  249. isAdd = true
  250. }
  251. } else if subSource == utils.DATA_SUB_SOURCE_DATE {
  252. if stockCode == "" {
  253. br.Msg = "请输入证券代码"
  254. return
  255. }
  256. if edbCode == "" {
  257. br.Msg = "请输入指标代码"
  258. return
  259. }
  260. respItem, err := data.AddEdbDataWindWsd(source, stockCode, edbCode)
  261. if err != nil {
  262. br.Msg = "获取失败"
  263. br.ErrMsg = "获取失败,Err:" + err.Error()
  264. return
  265. }
  266. if respItem.Ret != 200 {
  267. if respItem.Ret == 421 {
  268. br.Msg = "该渠道已超过添加上限"
  269. } else if respItem.Ret == 4052 {
  270. br.Msg = "该指标已下架"
  271. } else {
  272. br.Msg = "未搜索到该指标"
  273. }
  274. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  275. return
  276. }
  277. isAdd = true
  278. } else {
  279. br.Msg = "无效的渠道来源"
  280. return
  281. }
  282. } else if source == utils.DATA_SOURCE_PB || source == utils.DATA_SOURCE_PB_FINANCE {
  283. fmt.Println("pb data exist")
  284. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  285. if err != nil && err.Error() != utils.ErrNoRow() {
  286. br.Msg = "获取失败"
  287. br.ErrMsg = "获取Pb已存在信息失败,Err:" + err.Error()
  288. return
  289. }
  290. fmt.Println("pb dataItems:", len(dataItems))
  291. if len(dataItems) > 0 {
  292. searchItem.EdbCode = edbCode
  293. minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(edbCode)
  294. if err != nil {
  295. br.Msg = "获取失败"
  296. br.ErrMsg = "获取Pb日期信息失败,Err:" + err.Error()
  297. return
  298. }
  299. searchItem.DataList = dataItems
  300. searchItem.StartDate = minDate
  301. searchItem.EndDate = maxDate
  302. } else {
  303. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  304. //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDateUnSpace)
  305. //searchItem, err = data.GetEdbDataByPb(edbCode, startDate, endDate)
  306. //if err != nil {
  307. // br.Msg = "获取失败"
  308. // br.ErrMsg = "彭博数据获取失败,Err:" + err.Error()
  309. // return
  310. //}
  311. respItem, err := data.AddEdbData(source, edbCode, frequency)
  312. if err != nil {
  313. br.Msg = "获取失败"
  314. br.ErrMsg = "获取失败,Err:" + err.Error()
  315. return
  316. }
  317. if respItem.Ret != 200 {
  318. br.Msg = "未搜索到该指标"
  319. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  320. return
  321. }
  322. isAdd = true
  323. }
  324. } else if source == utils.DATA_SOURCE_MANUAL { //手工数据指标
  325. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_MANUAL, subSource, utils.EDB_DATA_LIMIT)
  326. if err != nil && err.Error() != utils.ErrNoRow() {
  327. br.Msg = "获取失败"
  328. br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
  329. return
  330. }
  331. fmt.Println("ths len:", len(dataItems))
  332. if len(dataItems) > 0 {
  333. fmt.Println("ths data exist")
  334. searchItem.EdbCode = edbCode
  335. minDate, maxDate, err := data_manage.GetEdbDataManualMaxOrMinDate(edbCode)
  336. if err != nil {
  337. br.Msg = "获取失败"
  338. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  339. return
  340. }
  341. searchItem.DataList = dataItems
  342. searchItem.StartDate = minDate
  343. searchItem.EndDate = maxDate
  344. } else {
  345. //searchItem, err = data_manage.GetEdbDataByManual(edbCode, startDate, endDate)
  346. //if err != nil {
  347. // br.Msg = "获取失败"
  348. // br.ErrMsg = "获取失败,Err:" + err.Error()
  349. // return
  350. //}
  351. respItem, err := data.AddEdbData(source, edbCode, frequency)
  352. if err != nil {
  353. br.Msg = "获取失败"
  354. br.ErrMsg = "获取失败,Err:" + err.Error()
  355. return
  356. }
  357. if respItem.Ret != 200 {
  358. br.Msg = "未搜索到该指标"
  359. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  360. return
  361. }
  362. isAdd = true
  363. }
  364. //获取指标信息
  365. manualInfo, err := models.GetEdbinfoByTradeCode(edbCode)
  366. if err != nil && err.Error() != utils.ErrNoRow() {
  367. br.Msg = "获取失败"
  368. br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
  369. return
  370. }
  371. if manualInfo != nil {
  372. searchItem.Frequency = manualInfo.Frequency
  373. searchItem.Unit = manualInfo.Unit
  374. searchItem.EdbName = manualInfo.SecName
  375. }
  376. } else if source == utils.DATA_SOURCE_LZ {
  377. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LZ, subSource, utils.EDB_DATA_LIMIT)
  378. if err != nil && err.Error() != utils.ErrNoRow() {
  379. br.Msg = "获取失败"
  380. br.ErrMsg = "获取隆众已存在信息失败,Err:" + err.Error()
  381. return
  382. }
  383. fmt.Println("ths len:", len(dataItems))
  384. if len(dataItems) > 0 {
  385. fmt.Println("ths data exist")
  386. searchItem.EdbCode = edbCode
  387. minDate, maxDate, err := data_manage.GetEdbDataLzMaxOrMinDate(edbCode)
  388. if err != nil {
  389. br.Msg = "获取失败"
  390. br.ErrMsg = "获取隆众日期信息失败,Err:" + err.Error()
  391. return
  392. }
  393. searchItem.DataList = dataItems
  394. searchItem.StartDate = minDate
  395. searchItem.EndDate = maxDate
  396. } else {
  397. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  398. //searchItem, err = data_manage.GetEdbDataByLz(edbCode, startDate, endDate)
  399. //if err != nil {
  400. // br.Msg = "获取失败"
  401. // br.ErrMsg = "获取隆众数据失败,Err:" + err.Error()
  402. // return
  403. //}
  404. respItem, err := data.AddEdbData(source, edbCode, frequency)
  405. if err != nil {
  406. br.Msg = "获取失败"
  407. br.ErrMsg = "获取失败,Err:" + err.Error()
  408. return
  409. }
  410. if respItem.Ret != 200 {
  411. br.Msg = "未搜索到该指标"
  412. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  413. return
  414. }
  415. isAdd = true
  416. }
  417. //获取指标信息
  418. lzInfo, err := data_manage.GetLongzhongSurveyProductByCode(edbCode)
  419. if err != nil && err.Error() != utils.ErrNoRow() {
  420. br.Msg = "获取失败"
  421. br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
  422. return
  423. }
  424. if lzInfo != nil {
  425. frequency := lzInfo.Frequency
  426. var frequencyStr string
  427. if frequency == 1 {
  428. frequencyStr = "日度"
  429. } else if frequency == 2 {
  430. frequencyStr = "周度"
  431. } else if frequency == 3 {
  432. frequencyStr = "月度"
  433. } else if frequency == 4 {
  434. frequencyStr = "季度"
  435. } else if frequency == 5 {
  436. frequencyStr = "年度"
  437. } else if frequency == 99 {
  438. frequencyStr = "无固定频率"
  439. }
  440. searchItem.Frequency = frequencyStr
  441. searchItem.Unit = lzInfo.UnitName
  442. searchItem.EdbName = lzInfo.SampleName + lzInfo.BreedName + lzInfo.QuotaName
  443. }
  444. } else if source == utils.DATA_SOURCE_YS { //有色网
  445. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, subSource, utils.EDB_DATA_LIMIT)
  446. if err != nil && err.Error() != utils.ErrNoRow() {
  447. br.Msg = "获取失败"
  448. br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
  449. return
  450. }
  451. fmt.Println("dataItems:", len(dataItems))
  452. if len(dataItems) > 0 {
  453. searchItem.EdbCode = edbCode
  454. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  455. if err != nil {
  456. br.Msg = "获取失败"
  457. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  458. return
  459. }
  460. searchItem.DataList = dataItems
  461. searchItem.StartDate = minDate
  462. searchItem.EndDate = maxDate
  463. } else {
  464. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  465. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  466. //if err != nil {
  467. // br.Msg = "获取失败"
  468. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  469. // return
  470. //}
  471. //if searchItem.StartDate == "" {
  472. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  473. // searchItem.StartDate = minDate
  474. // searchItem.EndDate = maxDate
  475. //}
  476. respItem, err := data.AddEdbData(source, edbCode, frequency)
  477. if err != nil {
  478. br.Msg = "获取失败"
  479. br.ErrMsg = "获取失败,Err:" + err.Error()
  480. return
  481. }
  482. if respItem.Ret != 200 {
  483. br.Msg = "未搜索到该指标"
  484. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  485. return
  486. }
  487. isAdd = true
  488. }
  489. //获取指标信息
  490. smmInfo, err := data_manage.GetBaseFromSmmIndexByIndexCode(edbCode)
  491. if err != nil && err.Error() != utils.ErrNoRow() {
  492. br.Msg = "获取失败"
  493. br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
  494. return
  495. }
  496. if smmInfo != nil {
  497. searchItem.Frequency = smmInfo.Frequency
  498. searchItem.Unit = smmInfo.Unit
  499. searchItem.EdbName = smmInfo.IndexName
  500. }
  501. } else if source == utils.DATA_SOURCE_GL { //钢联
  502. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  503. if err != nil && err.Error() != utils.ErrNoRow() {
  504. br.Msg = "获取失败"
  505. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  506. return
  507. }
  508. if len(dataItems) > 0 {
  509. searchItem.EdbCode = edbCode
  510. minDate, maxDate, err := data_manage.GetEdbDataGlMaxOrMinDate(edbCode)
  511. if err != nil {
  512. br.Msg = "获取失败"
  513. br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
  514. return
  515. }
  516. searchItem.DataList = dataItems
  517. searchItem.StartDate = minDate
  518. searchItem.EndDate = maxDate
  519. } else {
  520. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  521. //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
  522. //if err != nil {
  523. // br.Msg = "获取失败"
  524. // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
  525. // return
  526. //}
  527. respItem, err := data.AddEdbData(source, edbCode, frequency)
  528. if err != nil {
  529. br.Msg = "获取失败"
  530. br.ErrMsg = "获取失败,Err:" + err.Error()
  531. return
  532. }
  533. if respItem.Ret != 200 {
  534. br.Msg = "未搜索到该指标"
  535. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  536. return
  537. }
  538. isAdd = true
  539. }
  540. //获取指标信息
  541. glInfo, err := data_manage.GetGlIndexByCode(edbCode)
  542. if err != nil && err.Error() != utils.ErrNoRow() {
  543. br.Msg = "获取失败"
  544. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  545. return
  546. }
  547. if glInfo != nil {
  548. searchItem.Frequency = glInfo.FrequencyName
  549. searchItem.Unit = glInfo.UnitName
  550. searchItem.EdbName = glInfo.IndexName
  551. }
  552. } else if source == utils.DATA_SOURCE_ZZ { //郑商所
  553. var suffix string
  554. if strings.Contains(edbCode, "deal") {
  555. suffix = "deal"
  556. } else if strings.Contains(edbCode, "buy") {
  557. suffix = "buy"
  558. } else if strings.Contains(edbCode, "sold") {
  559. suffix = "sold"
  560. } else {
  561. br.Msg = "未搜索到该指标"
  562. br.ErrMsg = "指标code异常"
  563. return
  564. }
  565. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  566. if err != nil && err.Error() != utils.ErrNoRow() {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取郑商所已存在信息失败,Err:" + err.Error()
  569. return
  570. }
  571. if len(dataItems) > 0 {
  572. searchItem.EdbCode = edbCode
  573. minDate, maxDate, err := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
  574. if err != nil {
  575. br.Msg = "获取失败"
  576. br.ErrMsg = "获取郑商所日期信息失败,Err:" + err.Error()
  577. return
  578. }
  579. searchItem.DataList = dataItems
  580. searchItem.StartDate = minDate
  581. searchItem.EndDate = maxDate
  582. } else {
  583. //searchItem, err = data_manage.GetEdbDataByZz(edbCode, suffix, startDate, "")
  584. //if err != nil {
  585. // br.Msg = "获取失败"
  586. // br.ErrMsg = "获取失败,GetEdbDataByZz Err:" + err.Error()
  587. // return
  588. //}
  589. //if searchItem.StartDate == "" {
  590. // minDate, maxDate, _ := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
  591. // searchItem.StartDate = minDate
  592. // searchItem.EndDate = maxDate
  593. //}
  594. respItem, err := data.AddEdbData(source, edbCode, frequency)
  595. if err != nil {
  596. br.Msg = "获取失败"
  597. br.ErrMsg = "获取失败,Err:" + err.Error()
  598. return
  599. }
  600. if respItem.Ret != 200 {
  601. br.Msg = "未搜索到该指标"
  602. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  603. return
  604. }
  605. isAdd = true
  606. }
  607. //获取指标信息
  608. allInfo, err := data_manage.GetBaseInfoFromZhengzhouByIndexCode(edbCode, suffix)
  609. if err != nil && err.Error() != utils.ErrNoRow() {
  610. br.Msg = "获取失败"
  611. br.ErrMsg = "获取郑商所指标详情失败,Err:" + err.Error()
  612. return
  613. }
  614. var zzInfo *data_manage.BaseInfoFromZz
  615. if allInfo != nil {
  616. zzInfo = allInfo[0]
  617. }
  618. if zzInfo != nil {
  619. searchItem.Frequency = "日度"
  620. searchItem.Unit = "手"
  621. if suffix == "deal" {
  622. searchItem.EdbName = zzInfo.DealName
  623. } else if suffix == "buy" {
  624. searchItem.EdbName = zzInfo.BuyName
  625. } else {
  626. searchItem.EdbName = zzInfo.SoldName
  627. }
  628. }
  629. } else if source == utils.DATA_SOURCE_DL { //大商所
  630. var suffix string
  631. if strings.Contains(edbCode, "deal") {
  632. suffix = "deal"
  633. } else if strings.Contains(edbCode, "buy") {
  634. suffix = "buy"
  635. } else if strings.Contains(edbCode, "sold") {
  636. suffix = "sold"
  637. } else {
  638. br.Msg = "未搜索到该指标"
  639. br.ErrMsg = "指标code异常"
  640. return
  641. }
  642. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  643. if err != nil && err.Error() != utils.ErrNoRow() {
  644. br.Msg = "获取失败"
  645. br.ErrMsg = "获取大商所已存在信息失败,Err:" + err.Error()
  646. return
  647. }
  648. if len(dataItems) > 0 {
  649. searchItem.EdbCode = edbCode
  650. minDate, maxDate, err := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
  651. if err != nil {
  652. br.Msg = "获取失败"
  653. br.ErrMsg = "获取大商所日期信息失败,Err:" + err.Error()
  654. return
  655. }
  656. searchItem.DataList = dataItems
  657. searchItem.StartDate = minDate
  658. searchItem.EndDate = maxDate
  659. } else {
  660. //searchItem, err = data_manage.GetEdbDataByDl(edbCode, suffix, startDate, "")
  661. //if err != nil {
  662. // br.Msg = "获取失败"
  663. // br.ErrMsg = "获取失败,GetEdbDataByDl Err:" + err.Error()
  664. // return
  665. //}
  666. //if searchItem.StartDate == "" {
  667. // minDate, maxDate, _ := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
  668. // searchItem.StartDate = minDate
  669. // searchItem.EndDate = maxDate
  670. //}
  671. respItem, err := data.AddEdbData(source, edbCode, frequency)
  672. if err != nil {
  673. br.Msg = "获取失败"
  674. br.ErrMsg = "获取失败,Err:" + err.Error()
  675. return
  676. }
  677. if respItem.Ret != 200 {
  678. br.Msg = "未搜索到该指标"
  679. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  680. return
  681. }
  682. isAdd = true
  683. }
  684. //获取指标信息
  685. allInfo, err := data_manage.GetBaseInfoFromDalianByIndexCode(edbCode, suffix)
  686. if err != nil && err.Error() != utils.ErrNoRow() {
  687. br.Msg = "获取失败"
  688. br.ErrMsg = "获取大商所指标详情失败,Err:" + err.Error()
  689. return
  690. }
  691. var dlInfo *data_manage.BaseInfoFromDl
  692. if allInfo != nil {
  693. dlInfo = allInfo[0]
  694. }
  695. if dlInfo != nil {
  696. searchItem.Frequency = "日度"
  697. searchItem.Unit = "手"
  698. if suffix == "deal" {
  699. searchItem.EdbName = dlInfo.DealName
  700. } else if suffix == "buy" {
  701. searchItem.EdbName = dlInfo.BuyName
  702. } else {
  703. searchItem.EdbName = dlInfo.SoldName
  704. }
  705. }
  706. } else if source == utils.DATA_SOURCE_SH { //上期所
  707. var suffix string
  708. if strings.Contains(edbCode, "deal") {
  709. suffix = "deal"
  710. } else if strings.Contains(edbCode, "buy") {
  711. suffix = "buy"
  712. } else if strings.Contains(edbCode, "sold") {
  713. suffix = "sold"
  714. } else {
  715. br.Msg = "未搜索到该指标"
  716. br.ErrMsg = "指标code异常"
  717. return
  718. }
  719. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  720. if err != nil && err.Error() != utils.ErrNoRow() {
  721. br.Msg = "获取失败"
  722. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  723. return
  724. }
  725. if len(dataItems) > 0 {
  726. searchItem.EdbCode = edbCode
  727. minDate, maxDate, err := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
  728. if err != nil {
  729. br.Msg = "获取失败"
  730. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  731. return
  732. }
  733. searchItem.DataList = dataItems
  734. searchItem.StartDate = minDate
  735. searchItem.EndDate = maxDate
  736. } else {
  737. //searchItem, err = data_manage.GetEdbDataBySh(edbCode, suffix, startDate, "")
  738. //if err != nil {
  739. // br.Msg = "获取失败"
  740. // br.ErrMsg = "获取失败,GetEdbDataBySh Err:" + err.Error()
  741. // return
  742. //}
  743. //if searchItem.StartDate == "" {
  744. // minDate, maxDate, _ := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
  745. // searchItem.StartDate = minDate
  746. // searchItem.EndDate = maxDate
  747. //}
  748. respItem, err := data.AddEdbData(source, edbCode, frequency)
  749. if err != nil {
  750. br.Msg = "获取失败"
  751. br.ErrMsg = "获取失败,Err:" + err.Error()
  752. return
  753. }
  754. if respItem.Ret != 200 {
  755. br.Msg = "未搜索到该指标"
  756. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  757. return
  758. }
  759. isAdd = true
  760. }
  761. //获取指标信息
  762. allInfo, err := data_manage.GetBaseInfoFromShByIndexCode(edbCode, suffix)
  763. if err != nil && err.Error() != utils.ErrNoRow() {
  764. br.Msg = "获取失败"
  765. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  766. return
  767. }
  768. var shInfo *data_manage.BaseInfoFromSh
  769. if allInfo != nil {
  770. shInfo = allInfo[0]
  771. }
  772. if shInfo != nil {
  773. searchItem.Frequency = "日度"
  774. searchItem.Unit = "手"
  775. if suffix == "deal" {
  776. searchItem.EdbName = shInfo.DealName
  777. } else if suffix == "buy" {
  778. searchItem.EdbName = shInfo.BuyName
  779. } else {
  780. searchItem.EdbName = shInfo.SoldName
  781. }
  782. }
  783. } else if source == utils.DATA_SOURCE_CFFEX { //中金所
  784. var suffix string
  785. if strings.Contains(edbCode, "deal") {
  786. suffix = "deal"
  787. } else if strings.Contains(edbCode, "buy") {
  788. suffix = "buy"
  789. } else if strings.Contains(edbCode, "sold") {
  790. suffix = "sold"
  791. } else {
  792. br.Msg = "未搜索到该指标"
  793. br.ErrMsg = "指标code异常"
  794. return
  795. }
  796. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  797. if err != nil && err.Error() != utils.ErrNoRow() {
  798. br.Msg = "获取失败"
  799. br.ErrMsg = "获取中金所已存在信息失败,Err:" + err.Error()
  800. return
  801. }
  802. if len(dataItems) > 0 {
  803. searchItem.EdbCode = edbCode
  804. minDate, maxDate, err := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  805. if err != nil {
  806. br.Msg = "获取失败"
  807. br.ErrMsg = "获取中金所日期信息失败,Err:" + err.Error()
  808. return
  809. }
  810. searchItem.DataList = dataItems
  811. searchItem.StartDate = minDate
  812. searchItem.EndDate = maxDate
  813. } else {
  814. //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
  815. //if err != nil {
  816. // br.Msg = "获取失败"
  817. // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
  818. // return
  819. //}
  820. //if searchItem.StartDate == "" {
  821. // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  822. // searchItem.StartDate = minDate
  823. // searchItem.EndDate = maxDate
  824. //}
  825. respItem, err := data.AddEdbData(source, edbCode, frequency)
  826. if err != nil {
  827. br.Msg = "获取失败"
  828. br.ErrMsg = "获取失败,Err:" + err.Error()
  829. return
  830. }
  831. if respItem.Ret != 200 {
  832. br.Msg = "未搜索到该指标"
  833. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  834. return
  835. }
  836. isAdd = true
  837. }
  838. //获取指标信息
  839. allInfo, err := data_manage.GetBaseInfoFromCffexByIndexCode(edbCode, suffix)
  840. if err != nil && err.Error() != utils.ErrNoRow() {
  841. br.Msg = "获取失败"
  842. br.ErrMsg = "获取中金所指标详情失败,Err:" + err.Error()
  843. return
  844. }
  845. var cffexInfo *data_manage.BaseInfoFromCffex
  846. if allInfo != nil {
  847. cffexInfo = allInfo[0]
  848. }
  849. if cffexInfo != nil {
  850. searchItem.Frequency = "日度"
  851. searchItem.Unit = "手"
  852. if suffix == "deal" {
  853. searchItem.EdbName = cffexInfo.DealName
  854. } else if suffix == "buy" {
  855. searchItem.EdbName = cffexInfo.BuyName
  856. } else {
  857. searchItem.EdbName = cffexInfo.SoldName
  858. }
  859. }
  860. } else if source == utils.DATA_SOURCE_SHFE { //上期能源
  861. var suffix string
  862. if strings.Contains(edbCode, "deal") {
  863. suffix = "deal"
  864. } else if strings.Contains(edbCode, "buy") {
  865. suffix = "buy"
  866. } else if strings.Contains(edbCode, "sold") {
  867. suffix = "sold"
  868. } else {
  869. br.Msg = "未搜索到该指标"
  870. br.ErrMsg = "指标code异常"
  871. return
  872. }
  873. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  874. if err != nil && err.Error() != utils.ErrNoRow() {
  875. br.Msg = "获取失败"
  876. br.ErrMsg = "获取上期能源已存在信息失败,Err:" + err.Error()
  877. return
  878. }
  879. if len(dataItems) > 0 {
  880. searchItem.EdbCode = edbCode
  881. minDate, maxDate, err := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
  882. if err != nil {
  883. br.Msg = "获取失败"
  884. br.ErrMsg = "获取上期能源日期信息失败,Err:" + err.Error()
  885. return
  886. }
  887. searchItem.DataList = dataItems
  888. searchItem.StartDate = minDate
  889. searchItem.EndDate = maxDate
  890. } else {
  891. //searchItem, err = data_manage.GetEdbDataByShfe(edbCode, suffix, startDate, "")
  892. //if err != nil {
  893. // br.Msg = "获取失败"
  894. // br.ErrMsg = "获取失败,GetEdbDataByShfe Err:" + err.Error()
  895. // return
  896. //}
  897. //if searchItem.StartDate == "" {
  898. // minDate, maxDate, _ := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
  899. // searchItem.StartDate = minDate
  900. // searchItem.EndDate = maxDate
  901. //}
  902. respItem, err := data.AddEdbData(source, edbCode, frequency)
  903. if err != nil {
  904. br.Msg = "获取失败"
  905. br.ErrMsg = "获取失败,Err:" + err.Error()
  906. return
  907. }
  908. if respItem.Ret != 200 {
  909. br.Msg = "未搜索到该指标"
  910. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  911. return
  912. }
  913. isAdd = true
  914. }
  915. //获取指标信息
  916. allInfo, err := data_manage.GetBaseInfoFromShfeByIndexCode(edbCode, suffix)
  917. if err != nil && err.Error() != utils.ErrNoRow() {
  918. br.Msg = "获取失败"
  919. br.ErrMsg = "获取上期能源指标详情失败,Err:" + err.Error()
  920. return
  921. }
  922. var shfeInfo *data_manage.BaseInfoFromShfe
  923. if allInfo != nil {
  924. shfeInfo = allInfo[0]
  925. }
  926. if shfeInfo != nil {
  927. searchItem.Frequency = "日度"
  928. searchItem.Unit = "手"
  929. if suffix == "deal" {
  930. searchItem.EdbName = shfeInfo.DealName
  931. } else if suffix == "buy" {
  932. searchItem.EdbName = shfeInfo.BuyName
  933. } else {
  934. searchItem.EdbName = shfeInfo.SoldName
  935. }
  936. }
  937. } else if source == utils.DATA_SOURCE_GIE { //欧洲天然气
  938. var suffix string
  939. l := len(edbCode)
  940. if strings.Contains(edbCode[l-2:], "GS") {
  941. suffix = "GS"
  942. } else if strings.Contains(edbCode[l-2:], "CF") {
  943. suffix = "CF"
  944. } else if strings.Contains(edbCode[l-1:], "T") {
  945. suffix = "T"
  946. } else if strings.Contains(edbCode[l-2:], "In") {
  947. suffix = "In"
  948. } else if strings.Contains(edbCode[l-3:], "Out") {
  949. suffix = "Out"
  950. } else if strings.Contains(edbCode[l-3:], "WGV") {
  951. suffix = "WGV"
  952. } else if strings.Contains(edbCode[l-2:], "IC") {
  953. suffix = "IC"
  954. } else if strings.Contains(edbCode[l-2:], "WC") {
  955. suffix = "WC"
  956. } else if strings.Contains(edbCode[l-1:], "F") {
  957. suffix = "F"
  958. } else if strings.Contains(edbCode[l-1:], "C") {
  959. suffix = "C"
  960. } else {
  961. br.Msg = "未搜索到该指标"
  962. br.ErrMsg = "指标code异常"
  963. return
  964. }
  965. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  966. if err != nil && err.Error() != utils.ErrNoRow() {
  967. br.Msg = "获取失败"
  968. br.ErrMsg = "获取欧洲天然气已存在信息失败,Err:" + err.Error()
  969. return
  970. }
  971. if len(dataItems) > 0 {
  972. searchItem.EdbCode = edbCode
  973. minDate, maxDate, err := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
  974. if err != nil {
  975. br.Msg = "获取失败"
  976. br.ErrMsg = "获取欧洲天然气日期信息失败,Err:" + err.Error()
  977. return
  978. }
  979. searchItem.DataList = dataItems
  980. searchItem.StartDate = minDate
  981. searchItem.EndDate = maxDate
  982. } else {
  983. //searchItem, err = data_manage.GetEdbDataByGie(edbCode, suffix, startDate, "")
  984. //if err != nil {
  985. // br.Msg = "获取失败"
  986. // br.ErrMsg = "获取失败,GetEdbDataByGie Err:" + err.Error()
  987. // return
  988. //}
  989. //if searchItem.StartDate == "" {
  990. // minDate, maxDate, _ := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
  991. // searchItem.StartDate = minDate
  992. // searchItem.EndDate = maxDate
  993. //}
  994. respItem, err := data.AddEdbData(source, edbCode, frequency)
  995. if err != nil {
  996. br.Msg = "获取失败"
  997. br.ErrMsg = "获取失败,Err:" + err.Error()
  998. return
  999. }
  1000. if respItem.Ret != 200 {
  1001. br.Msg = "未搜索到该指标"
  1002. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1003. return
  1004. }
  1005. isAdd = true
  1006. }
  1007. //获取指标信息
  1008. allInfo, err := data_manage.GetBaseFromEicDataAllByIndexCodeV2(edbCode, suffix)
  1009. if err != nil && err.Error() != utils.ErrNoRow() {
  1010. br.Msg = "获取失败"
  1011. br.ErrMsg = "获取欧洲天然气指标详情失败,Err:" + err.Error()
  1012. return
  1013. }
  1014. var eicInfo *data_manage.BaseFromTradeEicIndexV2
  1015. if allInfo != nil {
  1016. eicInfo = allInfo[0]
  1017. }
  1018. var name string
  1019. if eicInfo != nil {
  1020. searchItem.Frequency = "日度"
  1021. if suffix == "GS" {
  1022. name = eicInfo.Name + "_gas_in_storage"
  1023. searchItem.EdbName = name
  1024. searchItem.Unit = "TWh"
  1025. } else if suffix == "C" {
  1026. name = eicInfo.Name + "_consumption"
  1027. searchItem.EdbName = name
  1028. searchItem.Unit = "TWh"
  1029. } else if suffix == "CF" {
  1030. name = eicInfo.Name + "_consumption_full"
  1031. searchItem.EdbName = name
  1032. searchItem.Unit = "百分比"
  1033. } else if suffix == "F" {
  1034. name = eicInfo.Name + "_full"
  1035. searchItem.EdbName = name
  1036. searchItem.Unit = "百分比"
  1037. } else if suffix == "T" {
  1038. name = eicInfo.Name + "_trend"
  1039. searchItem.EdbName = name
  1040. searchItem.Unit = "百分比"
  1041. } else if suffix == "In" {
  1042. name = eicInfo.Name + "_injection"
  1043. searchItem.EdbName = name
  1044. searchItem.Unit = "GWH/d"
  1045. } else if suffix == "Out" {
  1046. name = eicInfo.Name + "_withdrawal"
  1047. searchItem.EdbName = name
  1048. searchItem.Unit = "GWH/d"
  1049. } else if suffix == "WGV" {
  1050. name = eicInfo.Name + "_working_gas_volume"
  1051. searchItem.EdbName = name
  1052. searchItem.Unit = "TWh"
  1053. } else if suffix == "IC" {
  1054. name = eicInfo.Name + "_injection_capacity"
  1055. searchItem.EdbName = name
  1056. searchItem.Unit = "GWh/d"
  1057. } else if suffix == "WC" {
  1058. name = eicInfo.Name + "_withdrawal_capacity"
  1059. searchItem.EdbName = name
  1060. searchItem.Unit = "GWh/d"
  1061. }
  1062. }
  1063. } else if source == utils.DATA_SOURCE_LT {
  1064. fmt.Println("lt data exist")
  1065. if strings.Contains(edbCode, "=") {
  1066. br.Msg = "暂不支持编码中含有=的指标"
  1067. br.ErrMsg = "暂不支持编码中含有=的指标"
  1068. return
  1069. }
  1070. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LT, subSource, utils.EDB_DATA_LIMIT)
  1071. if err != nil && err.Error() != utils.ErrNoRow() {
  1072. br.Msg = "获取失败"
  1073. br.ErrMsg = "获取 lt 已存在信息失败,Err:" + err.Error()
  1074. return
  1075. }
  1076. fmt.Println("lt dataItems:", len(dataItems))
  1077. if len(dataItems) > 0 {
  1078. searchItem.EdbCode = edbCode
  1079. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1080. if err != nil {
  1081. br.Msg = "获取失败"
  1082. br.ErrMsg = "获取lt日期信息失败,Err:" + err.Error()
  1083. return
  1084. }
  1085. searchItem.DataList = dataItems
  1086. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1087. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1088. } else {
  1089. //endDate := dateNow.Format(utils.FormatDate)
  1090. //searchItem, err = data.GetEdbDataByLt(edbCode, startDate, endDate)
  1091. //if err != nil {
  1092. // br.Msg = "获取失败"
  1093. // br.ErrMsg = "lt 获取失败,Err:" + err.Error()
  1094. // return
  1095. //}
  1096. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1097. if err != nil {
  1098. br.Msg = "获取失败"
  1099. br.ErrMsg = "获取失败,Err:" + err.Error()
  1100. return
  1101. }
  1102. if respItem.Ret != 200 {
  1103. br.Msg = respItem.Msg
  1104. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1105. return
  1106. }
  1107. isAdd = true
  1108. }
  1109. } else if source == utils.DATA_SOURCE_COAL { //中国煤炭市场网
  1110. var suffix string
  1111. if strings.Contains(edbCode, "jsm") {
  1112. suffix = "jsm_index"
  1113. } else if strings.Contains(edbCode, "company") {
  1114. suffix = "company_index"
  1115. } else if strings.Contains(edbCode, "firm") {
  1116. suffix = "firm_index"
  1117. } else if strings.Contains(edbCode, "coastal") {
  1118. suffix = "coastal_index"
  1119. } else if strings.Contains(edbCode, "inland") {
  1120. suffix = "inland_index"
  1121. } else {
  1122. br.Msg = "未搜索到该指标"
  1123. br.ErrMsg = "指标code异常"
  1124. return
  1125. }
  1126. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1127. if err != nil && err.Error() != utils.ErrNoRow() {
  1128. br.Msg = "获取失败"
  1129. br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
  1130. return
  1131. }
  1132. if len(dataItems) > 0 {
  1133. searchItem.EdbCode = edbCode
  1134. minDate, maxDate, err := data_manage.GetEdbDataCoalMaxOrMinDate(edbCode)
  1135. if err != nil {
  1136. br.Msg = "获取失败"
  1137. br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
  1138. return
  1139. }
  1140. searchItem.DataList = dataItems
  1141. searchItem.StartDate = minDate
  1142. searchItem.EndDate = maxDate
  1143. } else {
  1144. //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
  1145. //if err != nil {
  1146. // br.Msg = "获取失败"
  1147. // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
  1148. // return
  1149. //}
  1150. //if searchItem.StartDate == "" {
  1151. // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  1152. // searchItem.StartDate = minDate
  1153. // searchItem.EndDate = maxDate
  1154. //}
  1155. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1156. if err != nil {
  1157. br.Msg = "获取失败"
  1158. br.ErrMsg = "获取失败,Err:" + err.Error()
  1159. return
  1160. }
  1161. if respItem.Ret != 200 {
  1162. br.Msg = "未搜索到该指标"
  1163. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1164. return
  1165. }
  1166. isAdd = true
  1167. }
  1168. //获取指标信息
  1169. allInfo, err := data_manage.GetBaseInfoFromCoalByIndexCode(edbCode, suffix)
  1170. if err != nil && err.Error() != utils.ErrNoRow() {
  1171. br.Msg = "获取失败"
  1172. br.ErrMsg = "获取煤炭网指标详情失败,Err:" + err.Error()
  1173. return
  1174. }
  1175. var coalInfo *data_manage.BaseInfoFromCoal
  1176. if allInfo != nil {
  1177. coalInfo = allInfo[0]
  1178. }
  1179. if coalInfo != nil {
  1180. searchItem.Frequency = coalInfo.Frequency
  1181. searchItem.Unit = coalInfo.Unit
  1182. searchItem.EdbName = coalInfo.IndexName
  1183. }
  1184. } else if source == utils.DATA_SOURCE_GOOGLE_TRAVEL { //谷歌出行数据
  1185. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1186. if err != nil && err.Error() != utils.ErrNoRow() {
  1187. br.Msg = "获取失败"
  1188. br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
  1189. return
  1190. }
  1191. if len(dataItems) > 0 {
  1192. searchItem.EdbCode = edbCode
  1193. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1194. if err != nil {
  1195. br.Msg = "获取失败"
  1196. br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
  1197. return
  1198. }
  1199. if item != nil {
  1200. searchItem.DataList = dataItems
  1201. searchItem.StartDate = item.MinDate
  1202. searchItem.EndDate = item.MaxDate
  1203. }
  1204. } else {
  1205. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1206. if err != nil {
  1207. br.Msg = "获取失败"
  1208. br.ErrMsg = "获取失败,Err:" + err.Error()
  1209. return
  1210. }
  1211. if respItem.Ret != 200 {
  1212. br.Msg = "未搜索到该指标"
  1213. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1214. return
  1215. }
  1216. isAdd = true
  1217. }
  1218. } else if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL { //钢联化工
  1219. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1220. if err != nil && err.Error() != utils.ErrNoRow() {
  1221. br.Msg = "获取失败"
  1222. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1223. return
  1224. }
  1225. if len(dataItems) > 0 {
  1226. searchItem.EdbCode = edbCode
  1227. minDate, maxDate, err := data_manage.GetEdbDataMysteelChemicalMaxOrMinDate(edbCode)
  1228. if err != nil {
  1229. br.Msg = "获取失败"
  1230. br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
  1231. return
  1232. }
  1233. searchItem.DataList = dataItems
  1234. searchItem.StartDate = minDate
  1235. searchItem.EndDate = maxDate
  1236. } else {
  1237. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1238. //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
  1239. //if err != nil {
  1240. // br.Msg = "获取失败"
  1241. // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
  1242. // return
  1243. //}
  1244. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1245. if err != nil {
  1246. br.Msg = "获取失败"
  1247. br.ErrMsg = "获取失败,Err:" + err.Error()
  1248. return
  1249. }
  1250. if respItem.Ret != 200 {
  1251. br.Msg = "未搜索到该指标"
  1252. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1253. return
  1254. }
  1255. isAdd = true
  1256. }
  1257. //获取指标信息
  1258. glInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
  1259. if err != nil && err.Error() != utils.ErrNoRow() {
  1260. br.Msg = "获取失败"
  1261. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1262. return
  1263. }
  1264. if glInfo != nil {
  1265. searchItem.Frequency = glInfo.Frequency
  1266. searchItem.Unit = glInfo.Unit
  1267. searchItem.EdbName = glInfo.IndexName
  1268. }
  1269. } else if source == utils.DATA_SOURCE_EIA_STEO { //eia steo报告
  1270. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1271. if err != nil && err.Error() != utils.ErrNoRow() {
  1272. br.Msg = "获取失败"
  1273. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1274. return
  1275. }
  1276. if len(dataItems) > 0 {
  1277. searchItem.EdbCode = edbCode
  1278. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1279. if err != nil {
  1280. br.Msg = "获取失败"
  1281. br.ErrMsg = "获取eia steo日期信息失败,Err:" + err.Error()
  1282. return
  1283. }
  1284. searchItem.DataList = dataItems
  1285. searchItem.StartDate = item.MinDate
  1286. searchItem.EndDate = item.MaxDate
  1287. } else {
  1288. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1289. if err != nil {
  1290. br.Msg = "获取失败"
  1291. br.ErrMsg = "获取失败,Err:" + err.Error()
  1292. return
  1293. }
  1294. if respItem.Ret != 200 {
  1295. br.Msg = "未搜索到该指标"
  1296. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1297. return
  1298. }
  1299. isAdd = true
  1300. }
  1301. //获取指标信息
  1302. eiasteoInfo, err := data_manage.GetBaseFromEiaSteoIndexByCode(edbCode)
  1303. if err != nil && err.Error() != utils.ErrNoRow() {
  1304. br.Msg = "获取失败"
  1305. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1306. return
  1307. }
  1308. if eiasteoInfo != nil {
  1309. searchItem.Frequency = eiasteoInfo.Frequency
  1310. searchItem.Unit = eiasteoInfo.Unit
  1311. searchItem.EdbName = eiasteoInfo.IndexName
  1312. }
  1313. } else if source == utils.DATA_SOURCE_COM_TRADE { // un数据源
  1314. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1315. if err != nil && err.Error() != utils.ErrNoRow() {
  1316. br.Msg = "获取失败"
  1317. br.ErrMsg = "获取联合国商品贸易数据已存在信息失败,Err:" + err.Error()
  1318. return
  1319. }
  1320. if len(dataItems) > 0 {
  1321. searchItem.EdbCode = edbCode
  1322. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1323. if err != nil {
  1324. br.Msg = "获取失败"
  1325. br.ErrMsg = "获取联合国商品贸易数据日期信息失败,Err:" + err.Error()
  1326. return
  1327. }
  1328. searchItem.DataList = dataItems
  1329. searchItem.StartDate = item.MinDate
  1330. searchItem.EndDate = item.MaxDate
  1331. } else {
  1332. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1333. if err != nil {
  1334. br.Msg = "获取失败"
  1335. br.ErrMsg = "获取失败,Err:" + err.Error()
  1336. return
  1337. }
  1338. if respItem.Ret != 200 {
  1339. br.Msg = "未搜索到该指标"
  1340. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1341. return
  1342. }
  1343. isAdd = true
  1344. }
  1345. //获取指标信息
  1346. eiasteoInfo, err := data_manage.GetComTradeIndex(edbCode)
  1347. if err != nil && err.Error() != utils.ErrNoRow() {
  1348. br.Msg = "获取失败"
  1349. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1350. return
  1351. }
  1352. if eiasteoInfo != nil {
  1353. //eiasteoInfo.
  1354. if eiasteoInfo.Type <= 2 {
  1355. searchItem.Frequency = `年度`
  1356. } else {
  1357. searchItem.Frequency = `月度`
  1358. }
  1359. if eiasteoInfo.Type == 1 || eiasteoInfo.Type == 3 {
  1360. searchItem.Unit = "美元"
  1361. } else {
  1362. searchItem.Unit = "千克"
  1363. }
  1364. searchItem.EdbName = eiasteoInfo.Name
  1365. }
  1366. } else if source == utils.DATA_SOURCE_SCI { //卓创数据(红桃三)
  1367. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1368. if err != nil && err.Error() != utils.ErrNoRow() {
  1369. br.Msg = "获取失败"
  1370. br.ErrMsg = "获取SCI已存在信息失败,Err:" + err.Error()
  1371. return
  1372. }
  1373. fmt.Println("dataItems:", len(dataItems))
  1374. if len(dataItems) > 0 {
  1375. searchItem.EdbCode = edbCode
  1376. minDate, maxDate, err := data_manage.GetEdbDataSciMaxAndMinDate(edbCode)
  1377. if err != nil {
  1378. br.Msg = "获取失败"
  1379. br.ErrMsg = "获取SCI日期信息失败,Err:" + err.Error()
  1380. return
  1381. }
  1382. searchItem.DataList = dataItems
  1383. searchItem.StartDate = minDate
  1384. searchItem.EndDate = maxDate
  1385. } else {
  1386. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1387. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  1388. //if err != nil {
  1389. // br.Msg = "获取失败"
  1390. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  1391. // return
  1392. //}
  1393. //if searchItem.StartDate == "" {
  1394. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  1395. // searchItem.StartDate = minDate
  1396. // searchItem.EndDate = maxDate
  1397. //}
  1398. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1399. if err != nil {
  1400. br.Msg = "获取失败"
  1401. br.ErrMsg = "获取失败,Err:" + err.Error()
  1402. return
  1403. }
  1404. if respItem.Ret != 200 {
  1405. br.Msg = "未搜索到该指标"
  1406. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1407. return
  1408. }
  1409. isAdd = true
  1410. }
  1411. //获取指标信息
  1412. smmInfo, err := data_manage.GetBaseFromSciIndexByIndexCode(edbCode)
  1413. if err != nil && err.Error() != utils.ErrNoRow() {
  1414. br.Msg = "获取失败"
  1415. br.ErrMsg = "获取Sci指标详情失败,Err:" + err.Error()
  1416. return
  1417. }
  1418. if smmInfo != nil {
  1419. searchItem.Frequency = smmInfo.Frequency
  1420. searchItem.Unit = smmInfo.Unit
  1421. searchItem.EdbName = smmInfo.IndexName
  1422. }
  1423. } else if source == utils.DATA_SOURCE_BAIINFO { //百川盈孚
  1424. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1425. if err != nil && err.Error() != utils.ErrNoRow() {
  1426. br.Msg = "获取失败"
  1427. br.ErrMsg = "获取BAIINFO已存在信息失败,Err:" + err.Error()
  1428. return
  1429. }
  1430. fmt.Println("dataItems:", len(dataItems))
  1431. if len(dataItems) > 0 {
  1432. searchItem.EdbCode = edbCode
  1433. minDate, maxDate, err := data_manage.GetEdbDataBaiinfoMaxAndMinDate(edbCode)
  1434. if err != nil {
  1435. br.Msg = "获取失败"
  1436. br.ErrMsg = "获取BAIINFO日期信息失败,Err:" + err.Error()
  1437. return
  1438. }
  1439. searchItem.DataList = dataItems
  1440. searchItem.StartDate = minDate
  1441. searchItem.EndDate = maxDate
  1442. } else {
  1443. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1444. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  1445. //if err != nil {
  1446. // br.Msg = "获取失败"
  1447. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  1448. // return
  1449. //}
  1450. //if searchItem.StartDate == "" {
  1451. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  1452. // searchItem.StartDate = minDate
  1453. // searchItem.EndDate = maxDate
  1454. //}
  1455. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1456. if err != nil {
  1457. br.Msg = "获取失败"
  1458. br.ErrMsg = "获取失败,Err:" + err.Error()
  1459. return
  1460. }
  1461. if respItem.Ret != 200 {
  1462. br.Msg = "未搜索到该指标"
  1463. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1464. return
  1465. }
  1466. isAdd = true
  1467. }
  1468. //获取指标信息
  1469. baiInfo, err := data_manage.GetBaseFromBaiinfoIndexByIndexCode(edbCode)
  1470. if err != nil && err.Error() != utils.ErrNoRow() {
  1471. br.Msg = "获取失败"
  1472. br.ErrMsg = "获取Baiinfo指标详情失败,Err:" + err.Error()
  1473. return
  1474. }
  1475. if baiInfo != nil {
  1476. searchItem.Frequency = baiInfo.Frequency
  1477. searchItem.Unit = baiInfo.Unit
  1478. searchItem.EdbName = baiInfo.IndexName
  1479. }
  1480. } else if source == utils.DATA_SOURCE_NATIONAL_STATISTICS { // 国家统计局
  1481. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1482. if err != nil && err.Error() != utils.ErrNoRow() {
  1483. br.Msg = "获取失败"
  1484. br.ErrMsg = "获取国家统计局已存在信息失败,Err:" + err.Error()
  1485. return
  1486. }
  1487. if len(dataItems) > 0 {
  1488. searchItem.EdbCode = edbCode
  1489. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1490. if err != nil {
  1491. br.Msg = "获取失败"
  1492. br.ErrMsg = "获取国家统计局日期信息失败,Err:" + err.Error()
  1493. return
  1494. }
  1495. searchItem.DataList = dataItems
  1496. searchItem.StartDate = item.MinDate
  1497. searchItem.EndDate = item.MaxDate
  1498. } else {
  1499. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1500. if err != nil {
  1501. br.Msg = "获取失败"
  1502. br.ErrMsg = "获取失败,Err:" + err.Error()
  1503. return
  1504. }
  1505. if respItem.Ret != 200 {
  1506. br.Msg = "未搜索到该指标"
  1507. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1508. return
  1509. }
  1510. isAdd = true
  1511. }
  1512. //获取指标信息
  1513. nationalInfo, err := data_manage.GetBaseFromNationalStatisticsIndexByIndexCode(edbCode)
  1514. if err != nil && err.Error() != utils.ErrNoRow() {
  1515. br.Msg = "获取失败"
  1516. br.ErrMsg = "获取国家统计局详情失败,Err:" + err.Error()
  1517. return
  1518. }
  1519. if nationalInfo != nil {
  1520. searchItem.Frequency = nationalInfo.Frequency
  1521. searchItem.Unit = nationalInfo.Unit
  1522. searchItem.EdbName = fmt.Sprintf("%s%s", nationalInfo.Reg, nationalInfo.IndexName)
  1523. }
  1524. } else if source == utils.DATA_SOURCE_FUBAO { //数宝
  1525. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_FUBAO, subSource, utils.EDB_DATA_LIMIT)
  1526. if err != nil && err.Error() != utils.ErrNoRow() {
  1527. br.Msg = "获取失败"
  1528. br.ErrMsg = "获取Fubao已存在信息失败,Err:" + err.Error()
  1529. return
  1530. }
  1531. fmt.Println("fubao len:", len(dataItems))
  1532. if len(dataItems) > 0 {
  1533. fmt.Println("fubao data exist")
  1534. searchItem.EdbCode = edbCode
  1535. minDate, maxDate, err := data_manage.GetEdbDataFubaoMaxOrMinDate(edbCode)
  1536. if err != nil {
  1537. br.Msg = "获取失败"
  1538. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  1539. return
  1540. }
  1541. searchItem.DataList = dataItems
  1542. searchItem.StartDate = minDate
  1543. searchItem.EndDate = maxDate
  1544. } else {
  1545. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1546. if err != nil {
  1547. br.Msg = "获取失败," + respItem.Msg
  1548. br.ErrMsg = "获取失败,Err:" + err.Error()
  1549. return
  1550. }
  1551. if respItem.Ret != 200 {
  1552. br.Msg = "未搜索到该指标," + respItem.Msg
  1553. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1554. return
  1555. }
  1556. isAdd = true
  1557. }
  1558. } else if source == utils.DATA_SOURCE_GFEX { //广州期货交易所
  1559. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1560. if err != nil && err.Error() != utils.ErrNoRow() {
  1561. br.Msg = "获取失败"
  1562. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  1563. return
  1564. }
  1565. if len(dataItems) > 0 {
  1566. searchItem.EdbCode = edbCode
  1567. minDate, maxDate, err := data_manage.GetEdbDataGzMaxOrMinDate(edbCode)
  1568. if err != nil {
  1569. br.Msg = "获取失败"
  1570. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  1571. return
  1572. }
  1573. searchItem.DataList = dataItems
  1574. searchItem.StartDate = minDate
  1575. searchItem.EndDate = maxDate
  1576. } else {
  1577. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1578. if err != nil {
  1579. br.Msg = "获取失败"
  1580. br.ErrMsg = "获取失败,Err:" + err.Error()
  1581. return
  1582. }
  1583. if respItem.Ret != 200 {
  1584. br.Msg = "未搜索到该指标"
  1585. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1586. return
  1587. }
  1588. isAdd = true
  1589. }
  1590. //获取指标信息
  1591. indexInfo, err := data_manage.GetBaseInfoFromGzByIndexCode(edbCode)
  1592. if err != nil && err.Error() != utils.ErrNoRow() {
  1593. br.Msg = "获取失败"
  1594. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  1595. return
  1596. }
  1597. if indexInfo != nil {
  1598. searchItem.Frequency = indexInfo.Frequency
  1599. searchItem.Unit = indexInfo.Unit
  1600. searchItem.EdbName = indexInfo.IndexName
  1601. }
  1602. } else if source == utils.DATA_SOURCE_ICPI { //消费者指数
  1603. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1604. if err != nil && err.Error() != utils.ErrNoRow() {
  1605. br.Msg = "获取失败"
  1606. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  1607. return
  1608. }
  1609. if len(dataItems) > 0 {
  1610. searchItem.EdbCode = edbCode
  1611. minDate, maxDate, err := data_manage.GetEdbDataIcpiMaxOrMinDate(edbCode)
  1612. if err != nil {
  1613. br.Msg = "获取失败"
  1614. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  1615. return
  1616. }
  1617. searchItem.DataList = dataItems
  1618. searchItem.StartDate = minDate
  1619. searchItem.EndDate = maxDate
  1620. } else {
  1621. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1622. if err != nil {
  1623. br.Msg = "获取失败"
  1624. br.ErrMsg = "获取失败,Err:" + err.Error()
  1625. return
  1626. }
  1627. if respItem.Ret != 200 {
  1628. br.Msg = "未搜索到该指标"
  1629. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1630. return
  1631. }
  1632. isAdd = true
  1633. }
  1634. //获取指标信息
  1635. indexInfo, err := data_manage.GetBaseInfoFromIcpiByIndexCode(edbCode)
  1636. if err != nil && err.Error() != utils.ErrNoRow() {
  1637. br.Msg = "获取失败"
  1638. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  1639. return
  1640. }
  1641. if indexInfo != nil {
  1642. searchItem.Frequency = "日度"
  1643. searchItem.Unit = "%"
  1644. searchItem.EdbName = indexInfo.IndexName
  1645. }
  1646. } else if source == utils.DATA_SOURCE_BUSINESS { //自有数据
  1647. indexObj := data_manage.BaseFromBusinessIndex{}
  1648. indexInfo, err := indexObj.GetDetailByEdbCode(edbCode)
  1649. if err != nil && err.Error() != utils.ErrNoRow() {
  1650. br.Msg = "获取失败"
  1651. br.ErrMsg = "获取自有数据指标信息失败,Err:" + err.Error()
  1652. return
  1653. }
  1654. _, tmpDataList, err := data.GetPageBaseBusinessIndexData(edbCode, 1, utils.EDB_DATA_LIMIT)
  1655. if err != nil && err.Error() != utils.ErrNoRow() {
  1656. br.Msg = "获取失败"
  1657. br.ErrMsg = "获取自有数据已存在信息失败,Err:" + err.Error()
  1658. return
  1659. }
  1660. dataItems := make([]*data_manage.EdbInfoSearchData, 0)
  1661. for _, v := range tmpDataList {
  1662. dataItems = append(dataItems, &data_manage.EdbInfoSearchData{
  1663. DataTime: v.DataTime,
  1664. Value: v.Value,
  1665. })
  1666. }
  1667. searchItem.EdbCode = edbCode
  1668. searchItem.DataList = dataItems
  1669. searchItem.StartDate = indexInfo.StartDate.Format(utils.FormatDate)
  1670. searchItem.EndDate = indexInfo.EndDate.Format(utils.FormatDate)
  1671. searchItem.Frequency = indexInfo.Frequency
  1672. searchItem.Unit = indexInfo.Unit
  1673. searchItem.EdbName = indexInfo.IndexName
  1674. } else if source == utils.DATA_SOURCE_SCI99 { //卓创资讯
  1675. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1676. if err != nil && err.Error() != utils.ErrNoRow() {
  1677. br.Msg = "获取失败"
  1678. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  1679. return
  1680. }
  1681. if len(dataItems) > 0 {
  1682. searchItem.EdbCode = edbCode
  1683. minDate, maxDate, err := data_manage.GetEdbDataSci99MaxOrMinDate(edbCode)
  1684. if err != nil {
  1685. br.Msg = "获取失败"
  1686. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  1687. return
  1688. }
  1689. searchItem.DataList = dataItems
  1690. searchItem.StartDate = minDate
  1691. searchItem.EndDate = maxDate
  1692. } else {
  1693. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1694. if err != nil {
  1695. br.Msg = "获取失败"
  1696. br.ErrMsg = "获取失败,Err:" + err.Error()
  1697. return
  1698. }
  1699. if respItem.Ret != 200 {
  1700. br.Msg = "未搜索到该指标"
  1701. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1702. return
  1703. }
  1704. isAdd = true
  1705. }
  1706. //获取指标信息
  1707. indexInfo, err := data_manage.GetBaseInfoFromSci99ByIndexCode(edbCode)
  1708. if err != nil && err.Error() != utils.ErrNoRow() {
  1709. br.Msg = "获取失败"
  1710. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  1711. return
  1712. }
  1713. if indexInfo != nil {
  1714. searchItem.Frequency = "日度"
  1715. searchItem.Unit = "元/吨"
  1716. searchItem.EdbName = indexInfo.IndexName
  1717. }
  1718. } else if source == utils.DATA_SOURCE_SCI_HQ {
  1719. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1720. if err != nil && err.Error() != utils.ErrNoRow() {
  1721. br.Msg = "获取失败"
  1722. br.ErrMsg = "获取SCIHQ已存在信息失败,Err:" + err.Error()
  1723. return
  1724. }
  1725. fmt.Println("dataItems:", len(dataItems))
  1726. if len(dataItems) > 0 {
  1727. searchItem.EdbCode = edbCode
  1728. minDate, maxDate, err := data_manage.GetEdbDataSciHqMaxAndMinDate(edbCode)
  1729. if err != nil {
  1730. br.Msg = "获取失败"
  1731. br.ErrMsg = "获取SCIHQ日期信息失败,Err:" + err.Error()
  1732. return
  1733. }
  1734. searchItem.DataList = dataItems
  1735. searchItem.StartDate = minDate
  1736. searchItem.EndDate = maxDate
  1737. } else {
  1738. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1739. if err != nil {
  1740. br.Msg = "获取失败"
  1741. br.ErrMsg = "获取失败,Err:" + err.Error()
  1742. return
  1743. }
  1744. if respItem.Ret != 200 {
  1745. br.Msg = "未搜索到该指标"
  1746. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1747. return
  1748. }
  1749. isAdd = true
  1750. }
  1751. //获取指标信息
  1752. sciHqInfo, err := data_manage.GetSciHqIndexByIndexCode(edbCode)
  1753. if err != nil && err.Error() != utils.ErrNoRow() {
  1754. br.Msg = "获取失败"
  1755. br.ErrMsg = "获取SciHq指标详情失败,Err:" + err.Error()
  1756. return
  1757. }
  1758. if sciHqInfo != nil {
  1759. searchItem.Frequency = sciHqInfo.Frequency
  1760. searchItem.Unit = sciHqInfo.Unit
  1761. searchItem.EdbName = sciHqInfo.IndexName
  1762. }
  1763. } else if source == utils.DATA_SOURCE_OILCHEM { //隆众资讯
  1764. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1765. if err != nil && err.Error() != utils.ErrNoRow() {
  1766. br.Msg = "获取失败"
  1767. br.ErrMsg = "获取隆众资讯已存在信息失败,Err:" + err.Error()
  1768. return
  1769. }
  1770. if len(dataItems) > 0 {
  1771. searchItem.EdbCode = edbCode
  1772. minDate, maxDate, err := data_manage.GetEdbDataOilchemMaxOrMinDate(edbCode)
  1773. if err != nil {
  1774. br.Msg = "获取失败"
  1775. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  1776. return
  1777. }
  1778. searchItem.DataList = dataItems
  1779. searchItem.StartDate = minDate
  1780. searchItem.EndDate = maxDate
  1781. } else {
  1782. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1783. if err != nil {
  1784. br.Msg = "获取失败"
  1785. br.ErrMsg = "获取失败,Err:" + err.Error()
  1786. return
  1787. }
  1788. if respItem.Ret != 200 {
  1789. br.Msg = "未搜索到该指标"
  1790. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1791. return
  1792. }
  1793. isAdd = true
  1794. }
  1795. //获取指标信息
  1796. indexInfo, err := data_manage.GetBaseInfoFromOilchemByIndexCode(edbCode)
  1797. if err != nil && err.Error() != utils.ErrNoRow() {
  1798. br.Msg = "获取失败"
  1799. br.ErrMsg = "获取隆众资讯指标详情失败,Err:" + err.Error()
  1800. return
  1801. }
  1802. if indexInfo != nil {
  1803. searchItem.Frequency = indexInfo.Frequency
  1804. searchItem.Unit = indexInfo.Unit
  1805. searchItem.EdbName = indexInfo.IndexName
  1806. }
  1807. } else if source == utils.DATA_SOURCE_HISUGAR { //泛糖科技
  1808. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1809. if err != nil && err.Error() != utils.ErrNoRow() {
  1810. br.Msg = "获取失败"
  1811. br.ErrMsg = "获取泛糖科技已存在信息失败,Err:" + err.Error()
  1812. return
  1813. }
  1814. if len(dataItems) > 0 {
  1815. searchItem.EdbCode = edbCode
  1816. minDate, maxDate, err := data_manage.GetEdbDataHisugarMaxOrMinDate(edbCode)
  1817. if err != nil {
  1818. br.Msg = "获取失败"
  1819. br.ErrMsg = "获取泛糖科技日期信息失败,Err:" + err.Error()
  1820. return
  1821. }
  1822. searchItem.DataList = dataItems
  1823. searchItem.StartDate = minDate
  1824. searchItem.EndDate = maxDate
  1825. } else {
  1826. respItem, err := data.AddEdbData(source, edbCode, frequency)
  1827. if err != nil {
  1828. br.Msg = "获取失败"
  1829. br.ErrMsg = "获取失败,Err:" + err.Error()
  1830. return
  1831. }
  1832. if respItem.Ret != 200 {
  1833. br.Msg = "未搜索到该指标"
  1834. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1835. return
  1836. }
  1837. isAdd = true
  1838. }
  1839. //获取指标信息
  1840. indexInfo, err := data_manage.GetBaseInfoFromHisugarByIndexCode(edbCode)
  1841. if err != nil && err.Error() != utils.ErrNoRow() {
  1842. br.Msg = "获取失败"
  1843. br.ErrMsg = "获取泛糖科技指标详情失败,Err:" + err.Error()
  1844. return
  1845. }
  1846. if indexInfo != nil {
  1847. searchItem.Frequency = indexInfo.Frequency
  1848. searchItem.Unit = indexInfo.Unit
  1849. searchItem.EdbName = indexInfo.IndexName
  1850. }
  1851. } else {
  1852. // 代码中没有的来源那么从edb_source中找是否有对应的
  1853. sourceItem := data_manage.EdbSourceIdMap[source]
  1854. if sourceItem == nil {
  1855. br.Msg = "无效指标来源"
  1856. return
  1857. }
  1858. // 获取指标数据
  1859. dataList, e := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1860. if e != nil {
  1861. br.Msg = "获取失败"
  1862. br.ErrMsg = "获取指标数据失败, Err: " + e.Error()
  1863. return
  1864. }
  1865. if len(dataList) > 0 {
  1866. searchItem.EdbCode = edbCode
  1867. searchItem.DataList = dataList
  1868. // 获取最大最小值
  1869. edbInfoMaxAndMinInfo, e := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1870. if e != nil && e.Error() != utils.ErrNoRow() {
  1871. br.Msg = "获取失败"
  1872. br.ErrMsg = "获取数据失败, GetEdbInfoMaxAndMinInfo Err:" + e.Error()
  1873. return
  1874. }
  1875. if edbInfoMaxAndMinInfo != nil {
  1876. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1877. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1878. }
  1879. } else {
  1880. // 新增指标数据
  1881. addRes, e := data.AddEdbData(source, edbCode, frequency)
  1882. if e != nil {
  1883. br.Msg = "获取失败"
  1884. br.ErrMsg = "获取失败,Err:" + e.Error()
  1885. return
  1886. }
  1887. if addRes == nil {
  1888. br.Msg = "获取失败"
  1889. br.ErrMsg = "新增指标数据失败, addRes nil"
  1890. return
  1891. }
  1892. if addRes.Ret != 200 {
  1893. br.Msg = "未搜索到该指标, " + addRes.Msg
  1894. //br.ErrMsg = addRes.ErrMsg + ";EdbCode:" + edbCode
  1895. br.Success = true
  1896. return
  1897. }
  1898. isAdd = true
  1899. }
  1900. // 查询基本信息
  1901. baseIndexInfo, tErr := data_manage.GetBaseIndexInfoByEdbCode(edbCode, source)
  1902. if tErr == nil {
  1903. searchItem.EdbName = baseIndexInfo.IndexName
  1904. searchItem.Frequency = baseIndexInfo.Frequency
  1905. searchItem.Unit = baseIndexInfo.Unit
  1906. }
  1907. // 指标来源于桥接服务: 桥接服务获取指标取频度信息等
  1908. if sourceItem.BridgeFlag != "" {
  1909. bridgeOb := data.InitBridgeOB(sourceItem.BridgeFlag)
  1910. if bridgeOb != nil {
  1911. var r data.GetIndexFromBridgeReq
  1912. r.IndexCode = edbCode
  1913. r.Source = sourceItem.EdbSourceId
  1914. r.SourceExtend = sourceItem.SourceExtend
  1915. r.IndexCodeRequired = sourceItem.EdbCodeRequired
  1916. bridgeIndex, e := bridgeOb.GetIndex(r)
  1917. if e != nil {
  1918. br.Msg = "获取失败"
  1919. br.ErrMsg = "桥接服务获取指标信息失败, Err: " + e.Error()
  1920. return
  1921. }
  1922. searchItem.EdbName = bridgeIndex.IndexName
  1923. searchItem.Frequency = bridgeIndex.Frequency
  1924. searchItem.Unit = bridgeIndex.Unit
  1925. }
  1926. }
  1927. }
  1928. if isAdd {
  1929. if subSource == utils.DATA_SUB_SOURCE_DATE {
  1930. if source == utils.DATA_SOURCE_WIND {
  1931. //wsdData := windWsdRespItem.Data
  1932. //var buf bytes.Buffer
  1933. //// 创建一个encoder并指定目标为buf
  1934. //enc := gob.NewEncoder(&buf)
  1935. //
  1936. //// 将data编码到buf中
  1937. //err = enc.Encode(wsdData)
  1938. //if err != nil {
  1939. // br.Msg = "获取失败"
  1940. // br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error()
  1941. // return
  1942. //}
  1943. //
  1944. //wsdDataMap := make(map[string]map[string]interface{})
  1945. //err = json.Unmarshal(buf.Bytes(), &wsdDataMap)
  1946. //if err != nil {
  1947. // br.Msg = "获取失败"
  1948. // br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error()
  1949. // return
  1950. //}
  1951. //
  1952. //stockList := make([]*data_manage.StockInfo, 0)
  1953. //
  1954. //dataList := make([]*data_manage.EdbInfoSearchData, 0)
  1955. //for wk, wv := range wsdDataMap {
  1956. // for vk, vv := range wv {
  1957. // wkInt, err := strconv.ParseInt(wk, 10, 64)
  1958. // if err != nil {
  1959. // br.Msg = "获取失败"
  1960. // br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error()
  1961. // return
  1962. // }
  1963. //
  1964. // vk = strings.ToLower(vk)
  1965. // wkInt = wkInt / 1000
  1966. // t := time.Unix(wkInt, 0)
  1967. // dateTime := t.Format(utils.FormatDate)
  1968. // //saveVal := utils.SubFloatToString(val, 20)
  1969. // if vv == nil {
  1970. // continue
  1971. // }
  1972. // var saveVal string
  1973. // switch vt := vv.(type) {
  1974. // case int:
  1975. // saveVal = strconv.Itoa(vt)
  1976. // case float64:
  1977. // saveVal = utils.SubFloatToFloatStr(vt, 20)
  1978. // case string:
  1979. // saveVal = vt
  1980. // }
  1981. //
  1982. // dataItem := new(data_manage.EdbInfoSearchData)
  1983. // dataItem.Value = saveVal
  1984. // dataItem.DataTime = dateTime
  1985. // dataList = append(dataList, dataItem)
  1986. // if len(dataList) >= 10 {
  1987. // break
  1988. // }
  1989. // }
  1990. //}
  1991. //searchItem.StockList = stockList
  1992. stockList := make([]*data_manage.StockInfo, 0)
  1993. edbCodeArr := strings.Split(edbCode, ",")
  1994. for _, v := range edbCodeArr {
  1995. indexCode := utils.WindDbWsd + stockCode + v
  1996. dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
  1997. if err != nil && err.Error() != utils.ErrNoRow() {
  1998. br.Msg = "获取失败"
  1999. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  2000. return
  2001. }
  2002. stockInfo := new(data_manage.StockInfo)
  2003. stockInfo.StockCode = stockCode
  2004. stockInfo.EdbCode = v
  2005. stockInfo.DataList = dataList
  2006. stockList = append(stockList, stockInfo)
  2007. }
  2008. searchItem.StockList = stockList
  2009. } else if source == utils.DATA_SOURCE_THS {
  2010. stockList := make([]*data_manage.StockInfo, 0)
  2011. edbCodeArr := strings.Split(edbCode, ",")
  2012. for _, v := range edbCodeArr {
  2013. indexCode := utils.ThsDs + stockCode + v
  2014. dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
  2015. if err != nil && err.Error() != utils.ErrNoRow() {
  2016. br.Msg = "获取失败"
  2017. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  2018. return
  2019. }
  2020. stockInfo := new(data_manage.StockInfo)
  2021. stockInfo.StockCode = stockCode
  2022. stockInfo.EdbCode = v
  2023. stockInfo.DataList = dataList
  2024. stockList = append(stockList, stockInfo)
  2025. }
  2026. searchItem.StockList = stockList
  2027. } else {
  2028. br.Msg = "来源错误"
  2029. br.ErrMsg = "来源错误"
  2030. return
  2031. }
  2032. } else {
  2033. dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  2034. if err != nil && err.Error() != utils.ErrNoRow() {
  2035. br.Msg = "获取失败"
  2036. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  2037. return
  2038. }
  2039. searchItem.DataList = dataList
  2040. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  2041. if err != nil && err.Error() != utils.ErrNoRow() {
  2042. br.Msg = "获取失败"
  2043. br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
  2044. return
  2045. }
  2046. searchItem.EdbCode = edbCode
  2047. searchItem.DataList = dataList
  2048. if edbInfoMaxAndMinInfo != nil {
  2049. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  2050. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  2051. }
  2052. //edb指标信息
  2053. edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode)
  2054. if edbInfoItem != nil {
  2055. searchItem.EdbName = edbInfoItem.EdbName
  2056. }
  2057. }
  2058. }
  2059. resp.Status = 2
  2060. resp.SearchItem = searchItem
  2061. }
  2062. //如果不在指标库中,且不是新增
  2063. if !isInEdb && !isAdd {
  2064. if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 {
  2065. br.Msg = "目标指标无有效值,请重新搜索"
  2066. br.Data = resp
  2067. return
  2068. }
  2069. }
  2070. br.Ret = 200
  2071. br.Success = true
  2072. br.Msg = "获取成功"
  2073. br.Data = resp
  2074. }
  2075. // EdbInfoList
  2076. // @Title 指标列表接口
  2077. // @Description 指标列表接口
  2078. // @Param PageSize query int true "每页数据条数"
  2079. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2080. // @Param EdbInfoId query int true "指标id"
  2081. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  2082. // @Success 200 {object} data_manage.EdbInfoListResp
  2083. // @router /edb_info/list [get]
  2084. func (this *EdbInfoController) EdbInfoList() {
  2085. br := new(models.BaseResponse).Init()
  2086. defer func() {
  2087. this.Data["json"] = br
  2088. this.ServeJSON()
  2089. }()
  2090. edbInfoId, _ := this.GetInt("EdbInfoId")
  2091. keyWord := this.GetString("KeyWord")
  2092. pageSize, _ := this.GetInt("PageSize")
  2093. currentIndex, _ := this.GetInt("CurrentIndex")
  2094. var total int
  2095. page := paging.GetPaging(currentIndex, pageSize, total)
  2096. var startSize int
  2097. if pageSize <= 0 {
  2098. pageSize = utils.PageSize20
  2099. }
  2100. if currentIndex <= 0 {
  2101. currentIndex = 1
  2102. }
  2103. startSize = paging.StartIndex(currentIndex, pageSize)
  2104. var condition string
  2105. var pars []interface{}
  2106. //if edbInfoId <= 0 && keyWord == "" {
  2107. // br.Msg = "参数错误"
  2108. // return
  2109. //}
  2110. // 指标类型,0:普通指标,1:预测指标
  2111. condition += " AND edb_info_type=? "
  2112. pars = append(pars, 0)
  2113. if edbInfoId > 0 {
  2114. condition += " AND edb_info_id=? "
  2115. pars = append(pars, edbInfoId)
  2116. // 获取当前账号的不可见指标配置
  2117. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2118. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId)
  2119. if err != nil && err.Error() != utils.ErrNoRow() {
  2120. br.Msg = "获取失败"
  2121. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  2122. return
  2123. }
  2124. if conf != nil {
  2125. br.Msg = "无权限,请联系管理员"
  2126. br.IsSendEmail = false
  2127. return
  2128. }
  2129. }
  2130. if keyWord != "" {
  2131. condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  2132. //pars = append(pars, keyWord)
  2133. //pars = append(pars, keyWord)
  2134. }
  2135. resp := new(data_manage.EdbInfoListResp)
  2136. if condition == "" {
  2137. item := new(data_manage.EdbInfoList)
  2138. resp.Paging = page
  2139. resp.Item = item
  2140. br.Ret = 200
  2141. br.Success = true
  2142. br.Msg = "获取成功"
  2143. return
  2144. }
  2145. //获取指标信息
  2146. edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2147. if err != nil && err.Error() != utils.ErrNoRow() {
  2148. br.Success = true
  2149. br.Msg = "获取指标信息失败"
  2150. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2151. return
  2152. }
  2153. if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  2154. item := new(data_manage.EdbInfoList)
  2155. resp.Paging = page
  2156. resp.Item = item
  2157. br.Ret = 200
  2158. br.Success = true
  2159. br.Msg = "获取成功"
  2160. return
  2161. }
  2162. //获取英文频度
  2163. edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
  2164. // 获取是否供应商停更
  2165. edbInfoItem.IsSupplierStop = data.GetIsSupplierStop(edbInfoItem.Source, edbInfoItem.EdbCode)
  2166. //查询目录
  2167. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId)
  2168. if err != nil {
  2169. br.Msg = err.Error()
  2170. br.ErrMsg = errMsg
  2171. return
  2172. }
  2173. // 权限校验
  2174. {
  2175. var currClassify *data_manage.EdbClassifyIdItems
  2176. for _, v := range classifyList {
  2177. if edbInfoItem.ClassifyId == v.ClassifyId {
  2178. currClassify = v
  2179. break
  2180. }
  2181. }
  2182. if currClassify != nil {
  2183. edbInfoItem.HaveOperaAuth, err = data_manage_permission.CheckEdbPermission(edbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfoItem.EdbInfoId, edbInfoItem.ClassifyId)
  2184. if err != nil {
  2185. br.Msg = err.Error()
  2186. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2187. return
  2188. }
  2189. }
  2190. }
  2191. // 按钮校验
  2192. button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType, edbInfoItem.HaveOperaAuth)
  2193. button.AddButton = false
  2194. edbInfoItem.Button = button
  2195. edbInfoItem.DataList = make([]*data_manage.EdbData, 0)
  2196. // 如果有数据权限,那么就去获取指标数据
  2197. if edbInfoItem.HaveOperaAuth {
  2198. dataCount, dataList, err := data.GetPageData(edbInfoItem.EdbInfoId, edbInfoItem.Source, edbInfoItem.SubSource, "", startSize, pageSize)
  2199. if err != nil && err.Error() != utils.ErrNoRow() {
  2200. br.Msg = "获取指标信息失败"
  2201. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  2202. return
  2203. }
  2204. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  2205. edbInfoItem.DataList = dataList
  2206. }
  2207. // 获取指标插入配置
  2208. {
  2209. edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId)
  2210. if err != nil && err.Error() != utils.ErrNoRow() {
  2211. br.Msg = "获取指标信息失败"
  2212. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2213. return
  2214. }
  2215. if edbDataInsertConfig != nil {
  2216. edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate)
  2217. edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate)
  2218. edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value
  2219. }
  2220. }
  2221. //是否展示英文标识
  2222. edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn)
  2223. resp.Paging = page
  2224. resp.Item = edbInfoItem
  2225. resp.ClassifyList = classifyList
  2226. br.Ret = 200
  2227. br.Success = true
  2228. br.Msg = "获取成功"
  2229. br.Data = resp
  2230. }
  2231. // EdbInfoAdd
  2232. // @Title 新增指标接口
  2233. // @Description 新增指标接口
  2234. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  2235. // @Success Ret=200 保存成功
  2236. // @router /edb_info/add [post]
  2237. func (this *EdbInfoController) EdbInfoAdd() {
  2238. br := new(models.BaseResponse).Init()
  2239. defer func() {
  2240. this.Data["json"] = br
  2241. this.ServeJSON()
  2242. }()
  2243. sysUser := this.SysUser
  2244. if sysUser == nil {
  2245. br.Msg = "请登录"
  2246. br.ErrMsg = "请登录,SysUser Is Empty"
  2247. br.Ret = 408
  2248. return
  2249. }
  2250. deleteCache := true
  2251. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  2252. defer func() {
  2253. if deleteCache {
  2254. utils.Rc.Delete(cacheKey)
  2255. }
  2256. }()
  2257. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  2258. deleteCache = false
  2259. br.Msg = "系统处理中,请稍后重试!"
  2260. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  2261. return
  2262. }
  2263. var req data_manage.AddEdbInfoReq
  2264. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2265. if err != nil {
  2266. br.Msg = "参数解析异常!"
  2267. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2268. return
  2269. }
  2270. source := req.Source
  2271. if source <= 0 {
  2272. br.Msg = "无效的数据来源"
  2273. return
  2274. }
  2275. req.EdbName = strings.Trim(req.EdbName, " ")
  2276. req.EdbCode = strings.Trim(req.EdbCode, " ")
  2277. if req.EdbCode == "" {
  2278. br.Msg = "指标ID不能为空"
  2279. return
  2280. }
  2281. if req.EdbName == "" {
  2282. br.Msg = "指标名称不能为空"
  2283. return
  2284. }
  2285. if req.Frequency == "" {
  2286. br.Msg = "频率不能为空"
  2287. return
  2288. }
  2289. if req.Unit == "" {
  2290. br.Msg = "单位不能为空"
  2291. return
  2292. }
  2293. if req.ClassifyId <= 0 {
  2294. br.Msg = "请选择分类"
  2295. return
  2296. }
  2297. //if req.StartDate == "" || req.EndDate == "" {
  2298. // br.Msg = "日期不能为空"
  2299. // return
  2300. //}
  2301. // 兼容钢联与钢联化工数据
  2302. if utils.InArrayByInt([]int{utils.DATA_SOURCE_GL, utils.DATA_SOURCE_MYSTEEL_CHEMICAL}, source) {
  2303. // 如果是钢联的话,那么就先判断是不是存在钢联化工
  2304. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
  2305. if err != nil {
  2306. if err.Error() != utils.ErrNoRow() {
  2307. br.Msg = "获取失败"
  2308. br.ErrMsg = "获取失败,Err:" + err.Error()
  2309. return
  2310. }
  2311. }
  2312. if tmpInfo != nil {
  2313. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  2314. req.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  2315. } else {
  2316. source = utils.DATA_SOURCE_GL
  2317. req.Source = utils.DATA_SOURCE_GL
  2318. }
  2319. }
  2320. // 指标入库
  2321. 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)
  2322. if err != nil {
  2323. br.Msg = "保存失败"
  2324. if errMsg != `` {
  2325. br.Msg = errMsg
  2326. }
  2327. br.ErrMsg = err.Error()
  2328. br.IsSendEmail = isSendEmail
  2329. return
  2330. }
  2331. // 试用平台更新用户累计新增指标数
  2332. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  2333. if e != nil {
  2334. br.Msg = "操作失败"
  2335. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  2336. return
  2337. }
  2338. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  2339. go func() {
  2340. var r etaTrialService.EtaTrialUserReq
  2341. r.Mobile = adminItem.Mobile
  2342. _, _ = etaTrialService.UpdateUserIndexNum(r)
  2343. }()
  2344. }
  2345. //新增操作日志
  2346. {
  2347. // 添加钢联指标更新日志
  2348. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2349. go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
  2350. }
  2351. edbLog := new(data_manage.EdbInfoLog)
  2352. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2353. edbLog.SourceName = edbInfo.SourceName
  2354. edbLog.Source = edbInfo.Source
  2355. edbLog.EdbCode = edbInfo.EdbCode
  2356. edbLog.EdbName = edbInfo.EdbName
  2357. edbLog.ClassifyId = edbInfo.ClassifyId
  2358. edbLog.SysUserId = sysUser.AdminId
  2359. edbLog.SysUserRealName = sysUser.RealName
  2360. edbLog.CreateTime = time.Now()
  2361. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2362. edbLog.Status = "新增指标"
  2363. edbLog.Method = this.Ctx.Input.URI()
  2364. go data_manage.AddEdbInfoLog(edbLog)
  2365. }
  2366. // 更新es
  2367. go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  2368. resp := new(data_manage.AddEdbInfoResp)
  2369. resp.EdbInfoId = edbInfo.EdbInfoId
  2370. resp.UniqueCode = edbInfo.UniqueCode
  2371. br.Ret = 200
  2372. br.Success = true
  2373. br.Msg = "保存成功"
  2374. br.Data = resp
  2375. br.IsAddLog = true
  2376. }
  2377. // EdbInfoEdit
  2378. // @Title 编辑指标接口
  2379. // @Description 编辑指标接口
  2380. // @Success 200 {object} data_manage.EditEdbInfoReq
  2381. // @router /edb_info/edit [post]
  2382. func (this *EdbInfoController) EdbInfoEdit() {
  2383. br := new(models.BaseResponse).Init()
  2384. defer func() {
  2385. this.Data["json"] = br
  2386. this.ServeJSON()
  2387. }()
  2388. sysUser := this.SysUser
  2389. if sysUser == nil {
  2390. br.Msg = "请登录"
  2391. br.ErrMsg = "请登录,SysUser Is Empty"
  2392. br.Ret = 408
  2393. return
  2394. }
  2395. var req data_manage.EditEdbInfoReq
  2396. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2397. if err != nil {
  2398. br.Msg = "参数解析异常!"
  2399. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2400. return
  2401. }
  2402. req.EdbName = strings.Trim(req.EdbName, " ")
  2403. if req.EdbInfoId <= 0 {
  2404. br.Msg = "参数错误"
  2405. br.ErrMsg = "指标id小于等于0"
  2406. return
  2407. }
  2408. if req.EdbName == "" {
  2409. br.Msg = "指标名称不能为空"
  2410. return
  2411. }
  2412. if req.Frequency == "" {
  2413. br.Msg = "频率不能为空"
  2414. return
  2415. }
  2416. if req.Unit == "" {
  2417. br.Msg = "单位不能为空"
  2418. return
  2419. }
  2420. if req.ClassifyId <= 0 {
  2421. br.Msg = "请选择分类"
  2422. return
  2423. }
  2424. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2425. if err != nil {
  2426. br.Msg = "修改失败"
  2427. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2428. return
  2429. }
  2430. // 记录旧的指标基本信息
  2431. oldEdbName := edbInfo.EdbName
  2432. oldFrequency := edbInfo.Frequency
  2433. oldUnit := edbInfo.Unit
  2434. var haveOperaAuth bool
  2435. // 权限校验
  2436. {
  2437. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
  2438. if err != nil {
  2439. br.Msg = err.Error()
  2440. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2441. return
  2442. }
  2443. }
  2444. // 编辑权限校验
  2445. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  2446. if !button.OpButton {
  2447. br.Msg = "无权限操作"
  2448. br.IsSendEmail = false
  2449. return
  2450. }
  2451. //判断指标名称是否存在
  2452. var condition string
  2453. var pars []interface{}
  2454. condition += " AND edb_info_id<>? "
  2455. pars = append(pars, req.EdbInfoId)
  2456. //condition += " AND source=? "
  2457. //pars = append(pars, edbInfo.Source)
  2458. updateCols := make([]string, 0)
  2459. switch this.Lang {
  2460. case utils.EnLangVersion:
  2461. condition += " AND edb_name_en = ? "
  2462. edbInfo.EdbNameEn = req.EdbName
  2463. edbInfo.Frequency = req.Frequency
  2464. edbInfo.UnitEn = req.Unit
  2465. edbInfo.ClassifyId = req.ClassifyId
  2466. updateCols = append(updateCols, "EdbNameEn", "Frequency", "UnitEn", "ClassifyId")
  2467. default:
  2468. condition += " AND edb_name=? "
  2469. edbInfo.EdbName = req.EdbName
  2470. edbInfo.EdbNameSource = req.EdbName
  2471. edbInfo.Frequency = req.Frequency
  2472. edbInfo.Unit = req.Unit
  2473. edbInfo.ClassifyId = req.ClassifyId
  2474. updateCols = append(updateCols, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId")
  2475. }
  2476. pars = append(pars, req.EdbName)
  2477. count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
  2478. if err != nil {
  2479. br.Msg = "判断指标名称是否存在失败"
  2480. br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error()
  2481. return
  2482. }
  2483. if count > 0 {
  2484. br.Msg = "指标名称已存在,请重新填写"
  2485. br.ErrMsg = "指标名称已存在,请重新填写"
  2486. br.IsSendEmail = false
  2487. return
  2488. }
  2489. if len(updateCols) > 0 {
  2490. err = edbInfo.Update(updateCols)
  2491. if err != nil {
  2492. br.Msg = "保存失败"
  2493. br.ErrMsg = "修改失败,Err:" + err.Error()
  2494. return
  2495. }
  2496. }
  2497. //处理同名指标
  2498. //{
  2499. // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName)
  2500. // if err != nil {
  2501. // br.Msg = "保存失败"
  2502. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2503. // return
  2504. // }
  2505. // if len(edbNameList) >= 2 {
  2506. // for _, v := range edbNameList {
  2507. // edbName := v.EdbName + "(" + v.SourceName + ")"
  2508. // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
  2509. // if err != nil {
  2510. // br.Msg = "保存失败"
  2511. // br.ErrMsg = "修改指标名称失败,Err:" + err.Error()
  2512. // return
  2513. // }
  2514. // }
  2515. // }
  2516. //}
  2517. // 新增保存记录日志
  2518. oldEdbInfo := new(data_manage.EdbInfo)
  2519. oldEdbInfo.EdbInfoId = edbInfo.EdbInfoId
  2520. oldEdbInfo.EdbName = oldEdbName
  2521. oldEdbInfo.Frequency = oldFrequency
  2522. oldEdbInfo.Unit = oldUnit
  2523. newEdbInfoRecord := new(data_manage.EdbInfoEditRecord)
  2524. newEdbInfoRecord.EdbName = req.EdbName
  2525. newEdbInfoRecord.Frequency = req.Frequency
  2526. newEdbInfoRecord.Unit = req.Unit
  2527. newEdbInfoRecord.OperateUserId = sysUser.AdminId
  2528. newEdbInfoRecord.OperateUserRealName = sysUser.RealName
  2529. go data.AddEditEdbInfoRcord(oldEdbInfo, newEdbInfoRecord)
  2530. //新增操作日志
  2531. {
  2532. edbLog := new(data_manage.EdbInfoLog)
  2533. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2534. edbLog.SourceName = edbInfo.SourceName
  2535. edbLog.Source = edbInfo.Source
  2536. edbLog.EdbCode = edbInfo.EdbCode
  2537. edbLog.EdbName = edbInfo.EdbName
  2538. edbLog.ClassifyId = edbInfo.ClassifyId
  2539. edbLog.SysUserId = sysUser.AdminId
  2540. edbLog.SysUserRealName = sysUser.RealName
  2541. edbLog.CreateTime = time.Now()
  2542. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2543. edbLog.Status = "编辑指标"
  2544. edbLog.Method = this.Ctx.Input.URI()
  2545. go data_manage.AddEdbInfoLog(edbLog)
  2546. }
  2547. //添加es
  2548. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2549. switch this.Lang {
  2550. case utils.EnLangVersion:
  2551. // 修改关联的预测指标基础信息
  2552. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
  2553. default:
  2554. // 修改关联的预测指标基础信息
  2555. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, req.Frequency, req.Unit)
  2556. }
  2557. // 添加钢联指标更新日志
  2558. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2559. if edbInfo.EdbName != req.EdbName || edbInfo.Frequency != req.Frequency || edbInfo.Unit != req.Unit {
  2560. go data_stat.AddEdbInfoUpdateLog(req.EdbInfoId, 1, "", sysUser, 1)
  2561. }
  2562. }
  2563. br.Ret = 200
  2564. br.Success = true
  2565. br.Msg = "保存成功"
  2566. br.IsAddLog = true
  2567. }
  2568. // EdbEnInfoEdit
  2569. // @Title 编辑指标英文信息接口
  2570. // @Description 编辑指标英文信息接口
  2571. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  2572. // @router /edb_info/en/edit [post]
  2573. func (this *EdbInfoController) EdbEnInfoEdit() {
  2574. br := new(models.BaseResponse).Init()
  2575. defer func() {
  2576. this.Data["json"] = br
  2577. this.ServeJSON()
  2578. }()
  2579. sysUser := this.SysUser
  2580. if sysUser == nil {
  2581. br.Msg = "请登录"
  2582. br.ErrMsg = "请登录,SysUser Is Empty"
  2583. br.Ret = 408
  2584. return
  2585. }
  2586. var req data_manage.EditEdbEnInfoReq
  2587. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2588. if err != nil {
  2589. br.Msg = "参数解析异常!"
  2590. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2591. return
  2592. }
  2593. req.EdbNameEn = strings.Trim(req.EdbNameEn, " ")
  2594. req.UnitEn = strings.Trim(req.UnitEn, " ")
  2595. if req.EdbInfoId <= 0 {
  2596. br.Msg = "参数错误"
  2597. br.ErrMsg = "指标id小于等于0"
  2598. return
  2599. }
  2600. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2601. if err != nil {
  2602. br.Msg = "获取指标信息失败"
  2603. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2604. return
  2605. }
  2606. if req.EdbNameEn != "" {
  2607. //判断指标名称是否存在
  2608. var condition string
  2609. var pars []interface{}
  2610. condition += " AND edb_info_id<>? "
  2611. pars = append(pars, req.EdbInfoId)
  2612. /*condition += " AND source=? "
  2613. pars = append(pars, edbInfo.Source)*/
  2614. condition += " AND edb_name_en=? "
  2615. pars = append(pars, req.EdbNameEn)
  2616. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2617. if err != nil {
  2618. if err.Error() != utils.ErrNoRow() {
  2619. br.Msg = "判断英文指标名称是否存在失败"
  2620. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2621. return
  2622. }
  2623. }
  2624. if err == nil && edbExist.EdbInfoId > 0 {
  2625. br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在"
  2626. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2627. br.IsSendEmail = false
  2628. return
  2629. }
  2630. }
  2631. err = data_manage.ModifyEdbEnInfo(&req)
  2632. if err != nil {
  2633. br.Msg = "保存失败"
  2634. br.ErrMsg = "修改失败,Err:" + err.Error()
  2635. return
  2636. }
  2637. //新增操作日志
  2638. {
  2639. edbLog := new(data_manage.EdbInfoLog)
  2640. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2641. edbLog.SourceName = edbInfo.SourceName
  2642. edbLog.Source = edbInfo.Source
  2643. edbLog.EdbCode = edbInfo.EdbCode
  2644. edbLog.EdbName = edbInfo.EdbName
  2645. edbLog.ClassifyId = edbInfo.ClassifyId
  2646. edbLog.SysUserId = sysUser.AdminId
  2647. edbLog.SysUserRealName = sysUser.RealName
  2648. edbLog.CreateTime = time.Now()
  2649. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2650. edbLog.Status = "编辑指标英文信息"
  2651. edbLog.Method = this.Ctx.Input.URI()
  2652. go data_manage.AddEdbInfoLog(edbLog)
  2653. }
  2654. //添加es
  2655. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2656. // 修改关联的预测指标基础信息
  2657. if edbInfo.EdbInfoType == 0 {
  2658. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.UnitEn)
  2659. }
  2660. br.Ret = 200
  2661. br.Success = true
  2662. br.Msg = "保存成功"
  2663. br.IsAddLog = true
  2664. }
  2665. // EdbInfoBaseEdit
  2666. // @Title 编辑指标基础信息接口
  2667. // @Description 编辑指标基础信息接口
  2668. // @Success 200 {object} data_manage.EditEdbBaseInfoReq
  2669. // @router /edb_info/base/edit [post]
  2670. func (this *EdbInfoController) EdbInfoBaseEdit() {
  2671. br := new(models.BaseResponse).Init()
  2672. defer func() {
  2673. this.Data["json"] = br
  2674. this.ServeJSON()
  2675. }()
  2676. sysUser := this.SysUser
  2677. if sysUser == nil {
  2678. br.Msg = "请登录"
  2679. br.ErrMsg = "请登录,SysUser Is Empty"
  2680. br.Ret = 408
  2681. return
  2682. }
  2683. var req data_manage.EditEdbBaseInfoReq
  2684. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2685. if err != nil {
  2686. br.Msg = "参数解析异常!"
  2687. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2688. return
  2689. }
  2690. req.EdbName = strings.Trim(req.EdbName, " ")
  2691. req.Unit = strings.Trim(req.Unit, " ")
  2692. if req.EdbInfoId <= 0 {
  2693. br.Msg = "参数错误"
  2694. br.ErrMsg = "指标id小于等于0"
  2695. return
  2696. }
  2697. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2698. if err != nil {
  2699. br.Msg = "获取指标信息失败"
  2700. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2701. return
  2702. }
  2703. updateCols := make([]string, 0)
  2704. if req.EdbName != "" {
  2705. //判断指标名称是否存在
  2706. var condition string
  2707. var pars []interface{}
  2708. condition += " AND edb_info_id<>? "
  2709. pars = append(pars, req.EdbInfoId)
  2710. /*condition += " AND source=? "
  2711. pars = append(pars, edbInfo.Source)*/
  2712. switch this.Lang {
  2713. case utils.EnLangVersion:
  2714. condition += " AND edb_name_en = ? "
  2715. edbInfo.EdbNameEn = req.EdbName
  2716. edbInfo.UnitEn = req.Unit
  2717. edbInfo.ModifyTime = time.Now()
  2718. updateCols = append(updateCols, "EdbNameEn", "UnitEn", "ModifyTime")
  2719. default:
  2720. condition += " AND edb_name = ? "
  2721. edbInfo.EdbName = req.EdbName
  2722. edbInfo.EdbNameSource = req.EdbName
  2723. edbInfo.Unit = req.Unit
  2724. edbInfo.ModifyTime = time.Now()
  2725. updateCols = append(updateCols, "EdbName", "EdbNameSource", "Unit", "ModifyTime")
  2726. }
  2727. pars = append(pars, req.EdbName)
  2728. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2729. if err != nil {
  2730. if err.Error() != utils.ErrNoRow() {
  2731. br.Msg = "判断英文指标名称是否存在失败"
  2732. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2733. return
  2734. }
  2735. }
  2736. if err == nil && edbExist.EdbInfoId > 0 {
  2737. br.Msg = edbExist.EdbName + ":" + req.EdbName + "指标名称已存在"
  2738. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2739. br.IsSendEmail = false
  2740. return
  2741. }
  2742. }
  2743. if len(updateCols) > 0 {
  2744. err = edbInfo.Update(updateCols)
  2745. if err != nil {
  2746. br.Msg = "保存失败"
  2747. br.ErrMsg = "修改失败,Err:" + err.Error()
  2748. return
  2749. }
  2750. }
  2751. //新增操作日志
  2752. {
  2753. edbLog := new(data_manage.EdbInfoLog)
  2754. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2755. edbLog.SourceName = edbInfo.SourceName
  2756. edbLog.Source = edbInfo.Source
  2757. edbLog.EdbCode = edbInfo.EdbCode
  2758. edbLog.EdbName = edbInfo.EdbName
  2759. edbLog.ClassifyId = edbInfo.ClassifyId
  2760. edbLog.SysUserId = sysUser.AdminId
  2761. edbLog.SysUserRealName = sysUser.RealName
  2762. edbLog.CreateTime = time.Now()
  2763. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2764. edbLog.Status = "编辑指标英文信息"
  2765. edbLog.Method = this.Ctx.Input.URI()
  2766. go data_manage.AddEdbInfoLog(edbLog)
  2767. }
  2768. //添加es
  2769. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2770. // 修改关联的预测指标基础信息
  2771. if edbInfo.EdbInfoType == 0 {
  2772. switch this.Lang {
  2773. case utils.EnLangVersion:
  2774. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
  2775. default:
  2776. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, edbInfo.Frequency, req.Unit)
  2777. }
  2778. }
  2779. br.Ret = 200
  2780. br.Success = true
  2781. br.Msg = "保存成功"
  2782. br.IsAddLog = true
  2783. }
  2784. // EdbInfoNewest
  2785. // @Title 获取最新指标接口
  2786. // @Description 获取最新指标接口
  2787. // @Success 200 {object} data_manage.EdbInfoList
  2788. // @router /edb_info/newest [get]
  2789. func (this *EdbInfoController) EdbInfoNewest() {
  2790. br := new(models.BaseResponse).Init()
  2791. defer func() {
  2792. this.Data["json"] = br
  2793. this.ServeJSON()
  2794. }()
  2795. item, err := data_manage.GetEdbInfoByNewest()
  2796. if err != nil && err.Error() != utils.ErrNoRow() {
  2797. br.Msg = "获取最新指标失败"
  2798. br.ErrMsg = "获取最新指标失败,Err:" + err.Error()
  2799. return
  2800. }
  2801. br.Ret = 200
  2802. br.Success = true
  2803. br.Msg = "获取成功"
  2804. br.Data = item
  2805. }
  2806. // EdbInfoRefresh
  2807. // @Title 指标刷新接口
  2808. // @Description 指标刷新接口
  2809. // @Param EdbInfoId query int true "指标id"
  2810. // @Success Ret=200 刷新成功
  2811. // @router /edb_info/refresh [get]
  2812. func (this *EdbInfoController) EdbInfoRefresh() {
  2813. br := new(models.BaseResponse).Init()
  2814. defer func() {
  2815. this.Data["json"] = br
  2816. this.ServeJSON()
  2817. }()
  2818. sysUser := this.SysUser
  2819. if sysUser == nil {
  2820. br.Msg = "请登录"
  2821. br.ErrMsg = "请登录,SysUser Is Empty"
  2822. br.Ret = 408
  2823. return
  2824. }
  2825. edbInfoId, _ := this.GetInt("EdbInfoId")
  2826. if edbInfoId <= 0 {
  2827. br.Msg = "参数错误"
  2828. br.ErrMsg = "参数错误"
  2829. return
  2830. }
  2831. _, err := data_manage.GetEdbInfoById(edbInfoId)
  2832. if err != nil {
  2833. if err.Error() == utils.ErrNoRow() {
  2834. br.Msg = "数据已被删除,请刷新页面"
  2835. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2836. return
  2837. }
  2838. br.Msg = "刷新失败"
  2839. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2840. return
  2841. }
  2842. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false, false)
  2843. if err != nil {
  2844. br.Msg = "刷新失败"
  2845. br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error()
  2846. return
  2847. }
  2848. br.Ret = 200
  2849. br.Msg = "刷新成功"
  2850. if isAsync {
  2851. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  2852. }
  2853. br.Success = true
  2854. br.IsAddLog = true
  2855. }
  2856. // EdbInfoMove
  2857. // @Title 移动指标接口
  2858. // @Description 移动指标接口
  2859. // @Success 200 {object} data_manage.MoveEdbInfoReq
  2860. // @router /edb_info/move [post]
  2861. func (this *EdbInfoController) EdbInfoMove() {
  2862. br := new(models.BaseResponse).Init()
  2863. defer func() {
  2864. this.Data["json"] = br
  2865. this.ServeJSON()
  2866. }()
  2867. sysUser := this.SysUser
  2868. if sysUser == nil {
  2869. br.Msg = "请登录"
  2870. br.ErrMsg = "请登录,SysUser Is Empty"
  2871. br.Ret = 408
  2872. return
  2873. }
  2874. var req data_manage.MoveEdbInfoReq
  2875. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2876. if err != nil {
  2877. br.Msg = "参数解析异常!"
  2878. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2879. return
  2880. }
  2881. if req.EdbInfoId <= 0 {
  2882. br.Msg = "参数错误"
  2883. br.ErrMsg = "指标id小于等于0"
  2884. return
  2885. }
  2886. if req.ClassifyId <= 0 {
  2887. br.Msg = "请选择分类"
  2888. return
  2889. }
  2890. //判断分类是否存在
  2891. count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId)
  2892. if count <= 0 {
  2893. br.Msg = "分类已被删除,不可移动,请刷新页面"
  2894. return
  2895. }
  2896. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2897. if err != nil {
  2898. br.Msg = "移动失败"
  2899. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2900. return
  2901. }
  2902. var haveOperaAuth bool
  2903. // 权限校验
  2904. {
  2905. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.IsJoinPermission, edbInfo.EdbInfoId, edbInfo.ClassifyId, this.SysUser.AdminId)
  2906. if err != nil {
  2907. br.Msg = err.Error()
  2908. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2909. return
  2910. }
  2911. }
  2912. // 移动权限校验
  2913. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  2914. if !button.MoveButton {
  2915. br.Msg = "无权限操作"
  2916. br.IsSendEmail = false
  2917. return
  2918. }
  2919. //如果改变了分类,那么移动该指标数据
  2920. if edbInfo.ClassifyId != req.ClassifyId {
  2921. err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId)
  2922. if err != nil {
  2923. br.Msg = "移动失败"
  2924. br.ErrMsg = "移动指标失败,Err:" + err.Error()
  2925. return
  2926. }
  2927. }
  2928. updateCol := make([]string, 0)
  2929. //如果有传入 上一个兄弟节点分类id
  2930. if req.PrevEdbInfoId > 0 {
  2931. prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId)
  2932. if err != nil {
  2933. br.Msg = "移动失败"
  2934. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  2935. return
  2936. }
  2937. //如果是移动在两个兄弟节点之间
  2938. if req.NextEdbInfoId > 0 {
  2939. //下一个兄弟节点
  2940. nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId)
  2941. if err != nil {
  2942. br.Msg = "移动失败"
  2943. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  2944. return
  2945. }
  2946. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  2947. if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort {
  2948. //变更兄弟节点的排序
  2949. updateSortStr := `sort + 2`
  2950. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2951. } else {
  2952. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  2953. if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 {
  2954. //变更兄弟节点的排序
  2955. updateSortStr := `sort + 1`
  2956. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2957. }
  2958. }
  2959. }
  2960. edbInfo.Sort = prevEdbInfo.Sort + 1
  2961. edbInfo.ModifyTime = time.Now()
  2962. updateCol = append(updateCol, "Sort", "ModifyTime")
  2963. } else {
  2964. firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId)
  2965. if err != nil && err.Error() != utils.ErrNoRow() {
  2966. br.Msg = "移动失败"
  2967. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2968. return
  2969. }
  2970. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2971. if firstClassify != nil && firstClassify.Sort == 0 {
  2972. updateSortStr := ` sort + 1 `
  2973. _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr)
  2974. }
  2975. edbInfo.Sort = 0 //那就是排在第一位
  2976. edbInfo.ModifyTime = time.Now()
  2977. updateCol = append(updateCol, "Sort", "ModifyTime")
  2978. }
  2979. //更新
  2980. if len(updateCol) > 0 {
  2981. err = edbInfo.Update(updateCol)
  2982. if err != nil {
  2983. br.Msg = "移动失败"
  2984. br.ErrMsg = "修改失败,Err:" + err.Error()
  2985. return
  2986. }
  2987. //添加es
  2988. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2989. }
  2990. if err != nil {
  2991. br.Msg = "移动失败"
  2992. br.ErrMsg = "修改失败,Err:" + err.Error()
  2993. return
  2994. }
  2995. //新增操作日志
  2996. {
  2997. edbLog := new(data_manage.EdbInfoLog)
  2998. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2999. edbLog.SourceName = edbInfo.SourceName
  3000. edbLog.Source = edbInfo.Source
  3001. edbLog.EdbCode = edbInfo.EdbCode
  3002. edbLog.EdbName = edbInfo.EdbName
  3003. edbLog.ClassifyId = edbInfo.ClassifyId
  3004. edbLog.SysUserId = sysUser.AdminId
  3005. edbLog.SysUserRealName = sysUser.RealName
  3006. edbLog.CreateTime = time.Now()
  3007. edbLog.Content = string(this.Ctx.Input.RequestBody)
  3008. edbLog.Status = "移动指标"
  3009. edbLog.Method = this.Ctx.Input.URI()
  3010. go data_manage.AddEdbInfoLog(edbLog)
  3011. }
  3012. br.Ret = 200
  3013. br.Success = true
  3014. br.Msg = "移动成功"
  3015. }
  3016. // EdbInfoDetail
  3017. // @Title 获取指标详情
  3018. // @Description 获取指标详情接口
  3019. // @Param EdbInfoId query int true "指标id"
  3020. // @Success 200 {object} data_manage.EdbInfo
  3021. // @router /edb_info/detail [get]
  3022. func (this *EdbInfoController) EdbInfoDetail() {
  3023. br := new(models.BaseResponse).Init()
  3024. defer func() {
  3025. this.Data["json"] = br
  3026. this.ServeJSON()
  3027. }()
  3028. sysUser := this.SysUser
  3029. if sysUser == nil {
  3030. br.Msg = "请登录"
  3031. br.ErrMsg = "请登录,SysUser Is Empty"
  3032. br.Ret = 408
  3033. return
  3034. }
  3035. edbInfoId, _ := this.GetInt("EdbInfoId")
  3036. if edbInfoId <= 0 {
  3037. br.Msg = "参数错误"
  3038. br.ErrMsg = "参数错误"
  3039. return
  3040. }
  3041. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3042. if err != nil {
  3043. br.Msg = "获取失败"
  3044. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3045. return
  3046. }
  3047. var resp data_manage.EdbInfoFullClassify
  3048. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  3049. if err != nil {
  3050. br.Msg = err.Error()
  3051. br.ErrMsg = errMsg
  3052. return
  3053. }
  3054. // 权限校验
  3055. {
  3056. classifyMap := make(map[int]*data_manage.EdbClassifyIdItems)
  3057. for _, v := range classifyList {
  3058. classifyMap[v.ClassifyId] = v
  3059. }
  3060. if currClassify, ok := classifyMap[edbInfo.ClassifyId]; ok {
  3061. haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
  3062. if err != nil {
  3063. br.Msg = err.Error()
  3064. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  3065. return
  3066. }
  3067. resp.HaveOperaAuth = haveOperaAuth
  3068. }
  3069. }
  3070. resp.EdbInfo = edbInfo
  3071. resp.ClassifyList = classifyList
  3072. br.Ret = 200
  3073. br.Success = true
  3074. br.Msg = "获取成功"
  3075. br.Data = resp
  3076. }
  3077. // EdbInfoFilter
  3078. // @Title 指标筛选接口
  3079. // @Description 指标筛选接口
  3080. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  3081. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标"
  3082. // @Param PageSize query int true "每页数据条数"
  3083. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3084. // @Success 200 {object} data_manage.EdbInfoList
  3085. // @router /edb_info/filter [get]
  3086. func (this *EdbInfoController) EdbInfoFilter() {
  3087. br := new(models.BaseResponse).Init()
  3088. defer func() {
  3089. this.Data["json"] = br
  3090. this.ServeJSON()
  3091. }()
  3092. keyWord := this.GetString("KeyWord")
  3093. filterSource, _ := this.GetInt("FilterSource")
  3094. if filterSource <= 0 {
  3095. filterSource = 1
  3096. }
  3097. var pars []interface{}
  3098. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  3099. // 获取当前账号的不可见指标
  3100. {
  3101. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3102. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3103. if err != nil && err.Error() != utils.ErrNoRow() {
  3104. br.Msg = "获取失败"
  3105. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3106. return
  3107. }
  3108. for _, v := range confList {
  3109. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3110. }
  3111. }
  3112. var keyWordArr []string
  3113. keyWordArr = append(keyWordArr, keyWord)
  3114. if keyWord != "" {
  3115. newKeyWord := strings.Split(keyWord, " ")
  3116. keyWordArr = append(keyWordArr, newKeyWord...)
  3117. }
  3118. //var err error
  3119. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  3120. //if keyWord == "" {
  3121. // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars)
  3122. // if err != nil && err.Error() != utils.ErrNoRow() {
  3123. // br.Success = true
  3124. // br.Msg = "获取指标信息失败"
  3125. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3126. // return
  3127. // }
  3128. //} else {
  3129. // //获取指标信息
  3130. // indexName := utils.DATA_INDEX_NAME
  3131. // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource)
  3132. // if err != nil && err.Error() != utils.ErrNoRow() {
  3133. // br.Success = true
  3134. // br.Msg = "获取指标信息失败"
  3135. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3136. // return
  3137. // }
  3138. //}
  3139. var baseCondition string
  3140. // 无权限指标id
  3141. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3142. if lenNoPermissionEdbInfoIdList > 0 {
  3143. baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3144. pars = append(pars, noPermissionEdbInfoIdList)
  3145. }
  3146. existMap := make(map[int]string)
  3147. for _, v := range keyWordArr {
  3148. v = strings.Replace(v, " ", "%", -1)
  3149. var condition string
  3150. if filterSource == 2 {
  3151. condition += ` AND frequency='月度' `
  3152. }
  3153. if filterSource == 3 {
  3154. condition += ` AND frequency <> '日度' `
  3155. }
  3156. if filterSource == 4 {
  3157. condition += ` AND edb_type = 1 `
  3158. }
  3159. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  3160. condition += conditionWhere + baseCondition
  3161. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  3162. if err != nil && err.Error() != utils.ErrNoRow() {
  3163. br.Success = true
  3164. br.Msg = "获取指标信息失败"
  3165. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3166. return
  3167. }
  3168. for _, nv := range newEdbInfoList {
  3169. if _, ok := existMap[nv.EdbInfoId]; !ok {
  3170. edbInfoList = append(edbInfoList, nv)
  3171. }
  3172. existMap[nv.EdbInfoId] = nv.EdbCode
  3173. }
  3174. }
  3175. if edbInfoList == nil {
  3176. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3177. }
  3178. edbInfoListLen := len(edbInfoList)
  3179. for i := 0; i < edbInfoListLen; i++ {
  3180. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3181. }
  3182. for i := 0; i < edbInfoListLen; i++ {
  3183. for j := 0; j < edbInfoListLen; j++ {
  3184. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3185. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3186. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3187. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3188. }
  3189. }
  3190. }
  3191. //新增搜索词记录
  3192. {
  3193. searchKeyword := new(data_manage.SearchKeyword)
  3194. searchKeyword.KeyWord = keyWord
  3195. searchKeyword.CreateTime = time.Now()
  3196. go data_manage.AddSearchKeyword(searchKeyword)
  3197. }
  3198. br.Ret = 200
  3199. br.Success = true
  3200. br.Msg = "获取成功"
  3201. br.Data = edbInfoList
  3202. }
  3203. // EdbInfoFilterByEs
  3204. // @Title 指标筛选接口
  3205. // @Description 指标筛选接口
  3206. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  3207. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  3208. // @Param Frequency query string false "频度"
  3209. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  3210. // @Param PageSize query int true "每页数据条数"
  3211. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3212. // @Success 200 {object} data_manage.EdbInfoList
  3213. // @router /edb_info/filter_by_es [get]
  3214. func (this *EdbInfoController) EdbInfoFilterByEs() {
  3215. br := new(models.BaseResponse).Init()
  3216. defer func() {
  3217. this.Data["json"] = br
  3218. this.ServeJSON()
  3219. }()
  3220. pageSize, _ := this.GetInt("PageSize")
  3221. currentIndex, _ := this.GetInt("CurrentIndex")
  3222. var total int64
  3223. var startSize int
  3224. if pageSize <= 0 {
  3225. pageSize = utils.PageSize20
  3226. }
  3227. if currentIndex <= 0 {
  3228. currentIndex = 1
  3229. }
  3230. startSize = paging.StartIndex(currentIndex, pageSize)
  3231. keyWord := this.GetString("KeyWord")
  3232. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3233. filterSource, _ := this.GetInt("FilterSource")
  3234. if filterSource <= 0 {
  3235. filterSource = 1
  3236. }
  3237. //指标来源
  3238. source, _ := this.GetInt("Source")
  3239. frequency := this.GetString("Frequency") //频度
  3240. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  3241. var edbInfoList []*data_manage.EdbInfoList
  3242. var err error
  3243. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  3244. // 获取当前账号的不可见指标
  3245. {
  3246. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3247. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3248. if err != nil && err.Error() != utils.ErrNoRow() {
  3249. br.Msg = "获取失败"
  3250. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3251. return
  3252. }
  3253. for _, v := range confList {
  3254. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3255. }
  3256. }
  3257. // 是否走ES
  3258. isEs := false
  3259. if keyWord != "" {
  3260. var keyWordArr []string
  3261. keyWordArr = append(keyWordArr, keyWord)
  3262. newKeyWord := strings.Split(keyWord, " ")
  3263. keyWordArr = append(keyWordArr, newKeyWord...)
  3264. // 普通的搜索
  3265. if !isAddPredictEdb {
  3266. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
  3267. } else {
  3268. // 允许添加预测指标的搜索
  3269. total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize)
  3270. }
  3271. isEs = true
  3272. } else {
  3273. var condition string
  3274. var pars []interface{}
  3275. // 普通指标
  3276. condition += ` AND edb_info_type = ? `
  3277. pars = append(pars, 0)
  3278. // 无权限指标id
  3279. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3280. if lenNoPermissionEdbInfoIdList > 0 {
  3281. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3282. pars = append(pars, noPermissionEdbInfoIdList)
  3283. }
  3284. switch filterSource {
  3285. case 2:
  3286. condition += ` AND frequency='月度' `
  3287. case 3:
  3288. condition += ` AND frequency <> '日度' `
  3289. case 4:
  3290. condition += ` AND edb_type = 1 `
  3291. case 5:
  3292. condition += ` AND source = 6 ` //来源(同比值)
  3293. case 6:
  3294. condition += ` AND frequency != ? `
  3295. pars = append(pars, "年度")
  3296. }
  3297. //频度
  3298. if frequency != "" {
  3299. condition += ` AND frequency = ? `
  3300. pars = append(pars, frequency)
  3301. }
  3302. if source > 0 && filterSource != 5 {
  3303. condition += ` AND source = ? `
  3304. pars = append(pars, source)
  3305. }
  3306. // 查询只允许添加预测指标的搜索
  3307. if isAddPredictEdb {
  3308. condition += ` AND frequency in ("日度","周度","月度") `
  3309. }
  3310. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  3311. }
  3312. if err != nil {
  3313. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3314. }
  3315. page := paging.GetPaging(currentIndex, pageSize, int(total))
  3316. edbInfoListLen := len(edbInfoList)
  3317. classifyIdList := make([]int, 0)
  3318. for i := 0; i < edbInfoListLen; i++ {
  3319. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3320. classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
  3321. }
  3322. // 当前列表中的分类map
  3323. classifyMap := make(map[int]*data_manage.EdbClassify)
  3324. if edbInfoListLen > 0 {
  3325. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  3326. if err != nil {
  3327. br.Msg = "获取失败"
  3328. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  3329. return
  3330. }
  3331. for _, v := range classifyList {
  3332. classifyMap[v.ClassifyId] = v
  3333. }
  3334. // 获取所有有权限的指标和分类
  3335. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  3336. if err != nil {
  3337. br.Msg = "获取失败"
  3338. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  3339. return
  3340. }
  3341. // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  3342. if isEs {
  3343. edbInfoIdList := make([]int, 0)
  3344. for i := 0; i < edbInfoListLen; i++ {
  3345. edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
  3346. tmpEdbInfo := edbInfoList[i]
  3347. if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
  3348. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  3349. }
  3350. }
  3351. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  3352. if err != nil {
  3353. br.Msg = "获取失败"
  3354. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  3355. return
  3356. }
  3357. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  3358. for _, v := range tmpEdbList {
  3359. edbInfoMap[v.EdbInfoId] = v
  3360. }
  3361. for i := 0; i < edbInfoListLen; i++ {
  3362. tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
  3363. if !ok {
  3364. continue
  3365. }
  3366. edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
  3367. }
  3368. }
  3369. // 权限校验
  3370. for i := 0; i < edbInfoListLen; i++ {
  3371. tmpEdbInfoItem := edbInfoList[i]
  3372. if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
  3373. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  3374. }
  3375. }
  3376. }
  3377. for i := 0; i < edbInfoListLen; i++ {
  3378. for j := 0; j < edbInfoListLen; j++ {
  3379. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3380. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3381. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3382. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3383. }
  3384. }
  3385. }
  3386. //新增搜索词记录
  3387. {
  3388. searchKeyword := new(data_manage.SearchKeyword)
  3389. searchKeyword.KeyWord = keyWord
  3390. searchKeyword.CreateTime = time.Now()
  3391. go data_manage.AddSearchKeyword(searchKeyword)
  3392. }
  3393. resp := data_manage.EdbInfoFilterDataResp{
  3394. Paging: page,
  3395. List: edbInfoList,
  3396. }
  3397. br.Ret = 200
  3398. br.Success = true
  3399. br.Msg = "获取成功"
  3400. br.Data = resp
  3401. }
  3402. func (this *EdbInfoController) EdbInfoFilter2() {
  3403. br := new(models.BaseResponse).Init()
  3404. defer func() {
  3405. this.Data["json"] = br
  3406. this.ServeJSON()
  3407. }()
  3408. keyWord := this.GetString("KeyWord")
  3409. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3410. filterSource, _ := this.GetInt("FilterSource")
  3411. if filterSource <= 0 {
  3412. filterSource = 1
  3413. }
  3414. var pars []interface{}
  3415. //if keyWord != "" {
  3416. // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  3417. //}
  3418. var keyWordArr []string
  3419. keyWordArr = append(keyWordArr, keyWord)
  3420. if keyWord != "" {
  3421. newKeyWord := strings.Split(keyWord, " ")
  3422. keyWordArr = append(keyWordArr, newKeyWord...)
  3423. }
  3424. keywordLen := len(keyWordArr)
  3425. ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen)
  3426. searchWait := sync.WaitGroup{}
  3427. searchWait.Add(keywordLen)
  3428. for index, v := range keyWordArr {
  3429. v = strings.Replace(v, " ", "%", -1)
  3430. var condition string
  3431. if filterSource == 2 {
  3432. condition += ` AND frequency='月度' `
  3433. }
  3434. if filterSource == 3 {
  3435. condition += ` AND frequency <> '日度' `
  3436. }
  3437. if filterSource == 4 {
  3438. condition += ` AND edb_type = 1 `
  3439. }
  3440. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  3441. condition += conditionWhere
  3442. go searchEdbInfoFilter(condition, pars, index, ch, &searchWait)
  3443. }
  3444. searchWait.Wait()
  3445. newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList)
  3446. i := 0
  3447. for tmpEdbInfoList := range ch {
  3448. i++
  3449. for k, v := range tmpEdbInfoList {
  3450. newEdbInfoListMap[k] = v
  3451. }
  3452. if i == keywordLen {
  3453. break
  3454. }
  3455. }
  3456. close(ch)
  3457. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  3458. existMap := make(map[int]string)
  3459. for i := 0; i < keywordLen; i++ {
  3460. if newEdbInfoList, ok := newEdbInfoListMap[i]; ok {
  3461. for _, nv := range newEdbInfoList {
  3462. if _, ok := existMap[nv.EdbInfoId]; !ok {
  3463. edbInfoList = append(edbInfoList, nv)
  3464. }
  3465. existMap[nv.EdbInfoId] = nv.EdbCode
  3466. }
  3467. }
  3468. }
  3469. if edbInfoList == nil {
  3470. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3471. }
  3472. edbInfoListLen := len(edbInfoList)
  3473. for i := 0; i < edbInfoListLen; i++ {
  3474. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3475. }
  3476. for i := 0; i < edbInfoListLen; i++ {
  3477. for j := 0; j < edbInfoListLen; j++ {
  3478. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3479. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3480. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3481. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3482. }
  3483. }
  3484. }
  3485. //新增搜索词记录
  3486. {
  3487. searchKeyword := new(data_manage.SearchKeyword)
  3488. searchKeyword.KeyWord = keyWord
  3489. searchKeyword.CreateTime = time.Now()
  3490. go data_manage.AddSearchKeyword(searchKeyword)
  3491. }
  3492. br.Ret = 200
  3493. br.Success = true
  3494. br.Msg = "获取成功"
  3495. br.Data = edbInfoList
  3496. }
  3497. 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) {
  3498. newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList)
  3499. defer func() {
  3500. if err != nil {
  3501. go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3)
  3502. //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  3503. }
  3504. ch <- newEdbInfoListMap
  3505. searchWait.Done()
  3506. }()
  3507. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  3508. newEdbInfoListMap[i] = newEdbInfoList
  3509. return
  3510. }
  3511. // EdbInfoAllRefresh
  3512. // @Title 指标全部刷新接口
  3513. // @Description 指标全部刷新接口
  3514. // @Param EdbInfoId query int true "指标id"
  3515. // @Success Ret=200 全部刷新成功
  3516. // @router /edb_info/refresh/all [get]
  3517. func (this *EdbInfoController) EdbInfoAllRefresh() {
  3518. br := new(models.BaseResponse).Init()
  3519. defer func() {
  3520. this.Data["json"] = br
  3521. this.ServeJSON()
  3522. }()
  3523. sysUser := this.SysUser
  3524. if sysUser == nil {
  3525. br.Msg = "请登录"
  3526. br.ErrMsg = "请登录,SysUser Is Empty"
  3527. br.Ret = 408
  3528. return
  3529. }
  3530. edbInfoId, _ := this.GetInt("EdbInfoId")
  3531. if edbInfoId <= 0 {
  3532. br.Msg = "参数错误"
  3533. br.ErrMsg = "参数错误"
  3534. return
  3535. }
  3536. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3537. if err != nil {
  3538. if err.Error() == utils.ErrNoRow() {
  3539. br.Msg = "数据已被删除,请刷新页面"
  3540. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  3541. return
  3542. }
  3543. br.Msg = "刷新失败"
  3544. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3545. return
  3546. }
  3547. if edbInfo == nil {
  3548. br.Msg = "数据已被删除,请刷新页面"
  3549. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  3550. return
  3551. }
  3552. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true, false)
  3553. if err != nil {
  3554. br.Msg = "刷新失败"
  3555. br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error()
  3556. return
  3557. }
  3558. br.Ret = 200
  3559. br.Success = true
  3560. br.Msg = "刷新成功"
  3561. if isAsync {
  3562. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  3563. }
  3564. }
  3565. // EdbInfoData
  3566. // @Title 获取指标数据
  3567. // @Description 获取指标数据
  3568. // @Param EdbInfoId query int true "指标ID"
  3569. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  3570. // @Param StartDate query string true "自定义开始日期"
  3571. // @Param EndDate query string true "自定义结束日期"
  3572. // @Success 200 {object} data_manage.EdbInfoDataResp
  3573. // @router /edb_info/data [get]
  3574. func (this *ChartInfoController) EdbInfoData() {
  3575. br := new(models.BaseResponse).Init()
  3576. defer func() {
  3577. this.Data["json"] = br
  3578. this.ServeJSON()
  3579. }()
  3580. sysUser := this.SysUser
  3581. if sysUser == nil {
  3582. br.Msg = "请登录"
  3583. br.ErrMsg = "请登录,SysUser Is Empty"
  3584. br.Ret = 408
  3585. return
  3586. }
  3587. fullEdb := new(data_manage.EdbInfoFullClassify)
  3588. resp := new(data_manage.EdbInfoDataFullClassifyResp)
  3589. dataList := make([]*data_manage.EdbDataList, 0)
  3590. edbInfoId, _ := this.GetInt("EdbInfoId")
  3591. if edbInfoId <= 0 {
  3592. br.Msg = "参数错误"
  3593. return
  3594. }
  3595. dateType, _ := this.GetInt("DateType")
  3596. if dateType <= 0 {
  3597. dateType = 3
  3598. }
  3599. edbInfoType, _ := this.GetInt("EdbInfoType")
  3600. if edbInfoType < 0 {
  3601. edbInfoType = 1
  3602. }
  3603. startDate := this.GetString("StartDate")
  3604. endDate := this.GetString("EndDate")
  3605. startYear, _ := this.GetInt("StartYear")
  3606. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3607. if err != nil {
  3608. if err.Error() == utils.ErrNoRow() {
  3609. br.Ret = 200
  3610. return
  3611. }
  3612. br.Msg = "获取失败"
  3613. br.ErrMsg = "获取失败,Err:" + err.Error()
  3614. return
  3615. }
  3616. // 分类
  3617. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  3618. if err != nil {
  3619. br.Msg = err.Error()
  3620. br.ErrMsg = errMsg
  3621. return
  3622. }
  3623. fullEdb.EdbInfo = edbInfo
  3624. // 是否供应商停更
  3625. fullEdb.IsSupplierStop = data.GetIsSupplierStop(edbInfo.Source, edbInfo.EdbCode)
  3626. fullEdb.ClassifyList = classifyList
  3627. var currClassifyItem *data_manage.EdbClassifyIdItems
  3628. for _, v := range classifyList {
  3629. if v.ClassifyId == edbInfo.ClassifyId {
  3630. currClassifyItem = v
  3631. }
  3632. }
  3633. if currClassifyItem != nil {
  3634. haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassifyItem.IsJoinPermission, sysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
  3635. if err != nil {
  3636. br.Msg = err.Error()
  3637. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  3638. return
  3639. }
  3640. fullEdb.HaveOperaAuth = haveOperaAuth
  3641. }
  3642. resp.EdbInfo = fullEdb
  3643. resp.DataList = make([]*data_manage.EdbDataList, 0)
  3644. // 数据获取
  3645. if fullEdb.HaveOperaAuth { // 有权限才获取数据
  3646. var latestDateT time.Time
  3647. if edbInfo.LatestDate != "" {
  3648. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3649. }
  3650. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  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. var latestDateT time.Time
  4257. if edbInfo.LatestDate != "" {
  4258. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4259. }
  4260. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  4261. var startDateTime time.Time
  4262. if startDate != `` {
  4263. startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  4264. if err != nil {
  4265. br.Msg = "开始日期异常"
  4266. br.Msg = "开始日期异常,Err:" + err.Error()
  4267. return
  4268. }
  4269. //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
  4270. startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
  4271. }
  4272. tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  4273. if err != nil {
  4274. br.Msg = "获取失败"
  4275. br.Msg = "获取失败,Err:" + err.Error()
  4276. return
  4277. }
  4278. // 计算同比值
  4279. dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
  4280. if err != nil {
  4281. br.Msg = "获取失败"
  4282. br.Msg = "计算同比值失败,Err:" + err.Error()
  4283. return
  4284. }
  4285. edbInfo.MaxValue = maxValue
  4286. edbInfo.MinValue = minValue
  4287. resp := new(data_manage.EdbInfoDataResp)
  4288. resp.EdbInfo = edbInfo
  4289. resp.DataList = dataList
  4290. br.Ret = 200
  4291. br.Success = true
  4292. br.Msg = "获取成功"
  4293. br.Data = resp
  4294. }
  4295. // EdbInfoDataSeasonal
  4296. // @Title 获取指标数据(季节性)
  4297. // @Description 获取指标数据
  4298. // @Param EdbInfoId query int true "指标ID"
  4299. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4300. // @Param StartDate query string true "自定义开始日期"
  4301. // @Param EndDate query string true "自定义结束日期"
  4302. // @Param Calendar query string true "公历/农历"
  4303. // @Success 200 {object} data_manage.EdbInfoDataResp
  4304. // @router /edb_info/data/seasonal [get]
  4305. func (this *ChartInfoController) EdbInfoDataSeasonal() {
  4306. br := new(models.BaseResponse).Init()
  4307. defer func() {
  4308. this.Data["json"] = br
  4309. this.ServeJSON()
  4310. }()
  4311. sysUser := this.SysUser
  4312. if sysUser == nil {
  4313. br.Msg = "请登录"
  4314. br.ErrMsg = "请登录,SysUser Is Empty"
  4315. br.Ret = 408
  4316. return
  4317. }
  4318. dateType, _ := this.GetInt("DateType")
  4319. startDate := this.GetString("StartDate")
  4320. endDate := this.GetString("EndDate")
  4321. startYear, _ := this.GetInt("StartYear")
  4322. edbInfoIdStr := this.GetString("EdbInfoId")
  4323. edbInfoId, err := strconv.Atoi(edbInfoIdStr)
  4324. if err != nil {
  4325. br.Msg = "指标id异常"
  4326. br.Msg = "指标id转换异常,Err:" + err.Error()
  4327. return
  4328. }
  4329. fmt.Println("startDate:", startDate)
  4330. fmt.Println("endDate:", endDate)
  4331. calendar := this.GetString("Calendar")
  4332. if calendar == "" {
  4333. calendar = "公历"
  4334. }
  4335. if dateType == 0 {
  4336. if startDate == "" {
  4337. dateType = utils.DateTypeNYears
  4338. } else {
  4339. dateType = 5
  4340. }
  4341. }
  4342. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4343. if err != nil {
  4344. br.Msg = "获取失败"
  4345. br.Msg = "获取失败,Err:" + err.Error()
  4346. return
  4347. }
  4348. var latestDateT time.Time
  4349. if edbInfo.LatestDate != "" {
  4350. // 季节性图需要特殊处理最近N年数据
  4351. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4352. latestDateT = time.Date(latestDateT.Year()+1, 1, 1, 0, 0, 0, 0, time.Local)
  4353. }
  4354. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  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. }
  6199. // ModifyChartList
  6200. // @Title 批量修改图表
  6201. // @Description 批量修改图表
  6202. // @Param SysUserIds query string true "根据创建人查询"
  6203. // @Param ChartClassifyIds query string true "图片分类id"
  6204. // @Success 200 {object} models.ChartClassifyListResp
  6205. // @router /modify/edbList [post]
  6206. func (this *EdbInfoController) ModifyEdbList() {
  6207. br := new(models.BaseResponse).Init()
  6208. defer func() {
  6209. this.Data["json"] = br
  6210. this.ServeJSON()
  6211. }()
  6212. sysUser := this.SysUser
  6213. if sysUser == nil {
  6214. br.Msg = "请登录"
  6215. br.ErrMsg = "请登录,SysUser Is Empty"
  6216. br.Ret = 408
  6217. return
  6218. }
  6219. var req request.ModifyEdbListReq
  6220. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  6221. if err != nil {
  6222. br.Msg = "参数解析异常!"
  6223. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  6224. return
  6225. }
  6226. classifyIds := strings.Split(req.EdbClassifyIds, ",")
  6227. if !req.SelectAll && req.EdbInfoIds == "" {
  6228. br.Msg = "请选择图表"
  6229. return
  6230. }
  6231. if req.ClassifyId < 0 {
  6232. br.Msg = "请选择新分类"
  6233. return
  6234. }
  6235. var condition string
  6236. var pars []interface{}
  6237. edbInfoIds := make([]int, 0)
  6238. if req.SelectAll {
  6239. // 已授权分类id
  6240. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  6241. if err != nil {
  6242. br.Msg = "获取失败"
  6243. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  6244. return
  6245. }
  6246. classifyIdsArr := make([]int, 0)
  6247. for _, v := range classifyIds {
  6248. if v != `` {
  6249. id, _ := strconv.Atoi(v)
  6250. classifyIdsArr = append(classifyIdsArr, id)
  6251. }
  6252. }
  6253. if len(permissionClassifyIdList) > 0 {
  6254. classifyIdsArr = utils.IntersectInt(permissionClassifyIdList, classifyIdsArr)
  6255. }
  6256. condition += " AND edb_info_type = 0 "
  6257. if len(classifyIdsArr) > 0 {
  6258. if !req.SubClassify {
  6259. condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(classifyIdsArr)) + ") "
  6260. pars = append(pars, classifyIdsArr)
  6261. } else {
  6262. classifyAll, err := data_manage.GetNormalEdbClassifyAll()
  6263. if err != nil && err.Error() != utils.ErrNoRow() {
  6264. br.Msg = "获取失败"
  6265. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6266. return
  6267. }
  6268. finalClassifyIds := make([]int, 0)
  6269. parents := data.GetEdbClassifyChildrenRecursiveByParentIds(classifyAll, classifyIds)
  6270. sort.Slice(parents, func(i, j int) bool {
  6271. return parents[i].Level < parents[i].Level
  6272. })
  6273. for _, v := range parents {
  6274. finalClassifyIds = append(finalClassifyIds, v.ClassifyId)
  6275. }
  6276. condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(finalClassifyIds)) + ") "
  6277. pars = append(pars, finalClassifyIds)
  6278. }
  6279. }
  6280. if req.KeyWord != "" {
  6281. condition += ` AND edb_name LIKE '%` + req.KeyWord + `%' `
  6282. }
  6283. if req.Sources != "" {
  6284. condition += " AND source IN(" + utils.GetOrmInReplace(len(strings.Split(req.Sources, ","))) + ") "
  6285. pars = append(pars, strings.Split(req.Sources, ","))
  6286. }
  6287. if req.SysUserIds != "" {
  6288. adminIds := strings.Split(req.SysUserIds, ",")
  6289. if len(adminIds) == 0 {
  6290. br.Msg = "请选择正确的创建人"
  6291. return
  6292. }
  6293. adminIdsSlice := make([]int, 0)
  6294. for _, adminId := range adminIds {
  6295. adminIdInt, e := strconv.Atoi(adminId)
  6296. if e != nil {
  6297. br.Msg = "请选择正确的创建人"
  6298. return
  6299. }
  6300. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  6301. }
  6302. condition += " AND sys_user_id in (" + utils.GetOrmInReplace(len(adminIds)) + ") "
  6303. pars = append(pars, adminIdsSlice)
  6304. }
  6305. // 获取当前账号的不可见指标
  6306. obj := data_manage.EdbInfoNoPermissionAdmin{}
  6307. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  6308. if err != nil && err.Error() != utils.ErrNoRow() {
  6309. br.Msg = "获取失败"
  6310. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  6311. return
  6312. }
  6313. noPermissionEdbInfoIds := make([]int, 0)
  6314. for _, v := range confList {
  6315. noPermissionEdbInfoIds = append(noPermissionEdbInfoIds, v.EdbInfoId)
  6316. }
  6317. if len(noPermissionEdbInfoIds) > 0 {
  6318. condition += " AND edb_info_id NOT IN(" + utils.GetOrmInReplace(len(noPermissionEdbInfoIds)) + ") "
  6319. pars = append(pars, noPermissionEdbInfoIds)
  6320. }
  6321. count, err := data_manage.GetEdbInfoByConditionCount(condition, pars)
  6322. if err != nil && err.Error() != utils.ErrNoRow() {
  6323. br.Msg = "获取失败"
  6324. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6325. return
  6326. }
  6327. if count > 100 {
  6328. br.Msg = "最多选择100个"
  6329. return
  6330. }
  6331. list, err := data_manage.GetEdbInfoListByCondition(condition, pars, 0, 0, "")
  6332. if err != nil && err.Error() != utils.ErrNoRow() {
  6333. br.Msg = "获取失败"
  6334. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6335. return
  6336. }
  6337. for _, v := range list {
  6338. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  6339. }
  6340. } else {
  6341. edbIds := strings.Split(req.EdbInfoIds, ",")
  6342. if len(edbIds) == 0 {
  6343. br.Msg = "请选择图表"
  6344. return
  6345. }
  6346. for _, id := range edbIds {
  6347. tmp, e := strconv.Atoi(id)
  6348. if e != nil {
  6349. br.Msg = "请选择正确的分类"
  6350. return
  6351. }
  6352. edbInfoIds = append(edbInfoIds, tmp)
  6353. }
  6354. if len(edbInfoIds) > 100 {
  6355. br.Msg = "最多只能选择100个图表"
  6356. return
  6357. }
  6358. }
  6359. err = data_manage.UpdateEdbClassifyIdByChartInfoId(edbInfoIds, req.ClassifyId)
  6360. if err != nil {
  6361. br.Msg = "更新失败"
  6362. br.ErrMsg = "更新图表分类失败,Err:" + err.Error()
  6363. return
  6364. }
  6365. br.Ret = 200
  6366. br.Success = true
  6367. br.Msg = "操作成功"
  6368. }