edb_info.go 196 KB

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