edb_info.go 197 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719
  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. var latestDateT time.Time
  3646. if edbInfo.LatestDate != "" {
  3647. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3648. }
  3649. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  3650. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  3651. if err != nil {
  3652. br.Msg = "获取失败"
  3653. br.ErrMsg = "获取失败,Err:" + err.Error()
  3654. return
  3655. }
  3656. resp.DataList = dataList
  3657. }
  3658. br.Ret = 200
  3659. br.Success = true
  3660. br.Msg = "获取成功"
  3661. br.Data = resp
  3662. }
  3663. // EdbInfoReplaceCheck
  3664. // @Title 指标一键刷新接口
  3665. // @Description 指标一键刷新接口
  3666. // @Success Ret=200 更新成功
  3667. // @router /edb_info/replace/check [post]
  3668. func (this *EdbInfoController) EdbInfoReplaceCheck() {
  3669. br := new(models.BaseResponse).Init()
  3670. setNxKey := "EDB_INFO_REPLACE"
  3671. defer func() {
  3672. this.Data["json"] = br
  3673. this.ServeJSON()
  3674. }()
  3675. status := 0
  3676. if utils.Rc.IsExist(setNxKey) {
  3677. status = 1
  3678. } else {
  3679. status = 2
  3680. }
  3681. br.Ret = 200
  3682. br.Success = true
  3683. br.Msg = "检测成功"
  3684. br.Data = status
  3685. }
  3686. // EdbInfoReplace
  3687. // @Title 替换指标
  3688. // @Description 替换指标
  3689. // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
  3690. // @Success 200 {object} data_manage.EdbInfoDataResp
  3691. // @router /edb_info/replace [post]
  3692. func (this *ChartInfoController) EdbInfoReplace() {
  3693. br := new(models.BaseResponse).Init()
  3694. setNxKey := "EDB_INFO_REPLACE"
  3695. deleteCache := true
  3696. defer func() {
  3697. if deleteCache {
  3698. utils.Rc.Delete(setNxKey)
  3699. }
  3700. this.Data["json"] = br
  3701. this.ServeJSON()
  3702. }()
  3703. sysUser := this.SysUser
  3704. if sysUser == nil {
  3705. br.Msg = "请登录"
  3706. br.ErrMsg = "请登录,SysUser Is Empty"
  3707. br.Ret = 408
  3708. return
  3709. }
  3710. if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
  3711. deleteCache = false
  3712. br.Msg = "当前正在替换中,请耐心等待!"
  3713. br.IsSendEmail = false
  3714. return
  3715. }
  3716. var req data_manage.EdbInfoReplaceReq
  3717. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3718. if err != nil {
  3719. br.Msg = "参数解析异常!"
  3720. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3721. return
  3722. }
  3723. if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
  3724. br.Msg = "参数错误!"
  3725. br.ErrMsg = "参数错误,指标id为0"
  3726. return
  3727. }
  3728. oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
  3729. if err != nil {
  3730. br.Msg = "替换失败!"
  3731. br.ErrMsg = "获取原指标失败,Err:" + err.Error()
  3732. return
  3733. }
  3734. newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
  3735. if err != nil {
  3736. br.Msg = "替换失败!"
  3737. br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
  3738. return
  3739. }
  3740. //if oldEdbInfo.EdbType != 1 {
  3741. // br.Msg = "原指标为计算指标,不可替换!"
  3742. // br.ErrMsg = "原指标为计算指标,不可替换!"
  3743. // return
  3744. //}
  3745. //
  3746. //if newEdbInfo.EdbType != 1 {
  3747. // br.Msg = "替换指标为计算指标,不可替换!"
  3748. // br.ErrMsg = "替换指标为计算指标,不可替换!"
  3749. // return
  3750. //}
  3751. if oldEdbInfo.Frequency != newEdbInfo.Frequency {
  3752. br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3753. br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3754. return
  3755. }
  3756. if oldEdbInfo.EdbInfoType == 1 || newEdbInfo.EdbInfoType == 1 {
  3757. br.Msg = "预测指标不允许替换"
  3758. br.ErrMsg = "预测指标不允许替换"
  3759. return
  3760. }
  3761. // 判断指标是否循环引用
  3762. if oldEdbInfo.EdbType == 2 {
  3763. // 查询该计算指标的所有相关指标,如果相关指标中包含新指标,则提示
  3764. hasRelation, e := data.CheckTwoEdbInfoRelation(oldEdbInfo, newEdbInfo)
  3765. if e != nil {
  3766. br.Msg = "替换失败!"
  3767. br.ErrMsg = "查询指标引用关系失败,Err:" + e.Error()
  3768. return
  3769. }
  3770. if hasRelation {
  3771. br.Msg = "原指标与替换指标存在引用关系,不允许替换"
  3772. br.ErrMsg = "原指标与替换指标存在引用关系,不允许替换"
  3773. return
  3774. }
  3775. }
  3776. if newEdbInfo.EdbType == 2 {
  3777. // 查询该计算指标的所有相关指标,如果相关指标中包含新指标,则提示
  3778. hasRelation, e := data.CheckTwoEdbInfoRelation(newEdbInfo, oldEdbInfo)
  3779. if e != nil {
  3780. br.Msg = "替换失败!"
  3781. br.ErrMsg = "查询指标引用关系失败,Err:" + e.Error()
  3782. return
  3783. }
  3784. if hasRelation {
  3785. br.Msg = "原指标与替换指标存在引用关系,不允许替换"
  3786. br.ErrMsg = "原指标与替换指标存在引用关系,不允许替换"
  3787. return
  3788. }
  3789. }
  3790. sysAdminId := sysUser.AdminId
  3791. //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3792. _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3793. //msgContent := ``
  3794. if err != nil {
  3795. br.Msg = "替换失败"
  3796. br.ErrMsg = "替换失败 replace err:" + err.Error()
  3797. return
  3798. }
  3799. br.Msg = "替换成功"
  3800. br.ErrMsg = "替换成功"
  3801. br.Ret = 200
  3802. br.IsAddLog = true
  3803. return
  3804. }
  3805. // RelationChartList
  3806. // @Title 获取ETA指标关联的图表列表接口
  3807. // @Description 获取ETA指标关联的图表列表接口
  3808. // @Param PageSize query int true "每页数据条数"
  3809. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3810. // @Param EdbInfoId query int true "指标id"
  3811. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3812. // @Success 200 {object} data_manage.ChartListResp
  3813. // @router /edb_info/relation/chart_list [get]
  3814. func (this *EdbInfoController) RelationChartList() {
  3815. br := new(models.BaseResponse).Init()
  3816. defer func() {
  3817. this.Data["json"] = br
  3818. this.ServeJSON()
  3819. }()
  3820. sysUser := this.SysUser
  3821. if sysUser == nil {
  3822. br.Msg = "请登录"
  3823. br.ErrMsg = "请登录,SysUser Is Empty"
  3824. br.Ret = 408
  3825. return
  3826. }
  3827. edbInfoId, _ := this.GetInt("EdbInfoId")
  3828. pageSize, _ := this.GetInt("PageSize")
  3829. currentIndex, _ := this.GetInt("CurrentIndex")
  3830. resp := data_manage.ChartListResp{}
  3831. var total int
  3832. page := paging.GetPaging(currentIndex, pageSize, total)
  3833. var startSize int
  3834. if pageSize <= 0 {
  3835. pageSize = utils.PageSize20
  3836. }
  3837. if currentIndex <= 0 {
  3838. currentIndex = 1
  3839. }
  3840. startSize = paging.StartIndex(currentIndex, pageSize)
  3841. var condition string
  3842. var pars []interface{}
  3843. if edbInfoId <= 0 {
  3844. br.Msg = "请选择指标"
  3845. br.ErrMsg = "请选择指标"
  3846. br.IsSendEmail = false
  3847. return
  3848. }
  3849. /*// 关联指标
  3850. condition += ` AND b.edb_info_id = ? `
  3851. pars = append(pars, edbInfoId)*/
  3852. //只看我的
  3853. isShowMe, _ := this.GetBool("IsShowMe")
  3854. if isShowMe {
  3855. condition += ` AND a.sys_user_id = ? `
  3856. pars = append(pars, sysUser.AdminId)
  3857. }
  3858. chartIds := make([]int, 0)
  3859. chartIdMap := make(map[int]bool)
  3860. // 查询指标绑定的图表
  3861. edbListTemp, err := data_manage.GetEdbMappingListByEdbInfoId(edbInfoId)
  3862. if err != nil && err.Error() != utils.ErrNoRow() {
  3863. br.Msg = "获取图表信息失败"
  3864. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3865. return
  3866. }
  3867. for _, v := range edbListTemp {
  3868. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  3869. chartIdMap[v.ChartInfoId] = true
  3870. }
  3871. }
  3872. // 查询相关性的图表
  3873. correlationChart := new(data_manage.ChartInfoCorrelation)
  3874. correlationChartId, err := correlationChart.GetChartInfoIdByEdb(edbInfoId)
  3875. if err != nil && err.Error() != utils.ErrNoRow() {
  3876. br.Msg = "获取图表信息失败"
  3877. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3878. return
  3879. }
  3880. if correlationChartId > 0 {
  3881. chartIdMap[correlationChartId] = true
  3882. }
  3883. // 查询跨品种的图表
  3884. tagXList, err := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
  3885. if err != nil && err.Error() != utils.ErrNoRow() {
  3886. br.Msg = "获取图表信息失败"
  3887. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3888. return
  3889. }
  3890. for _, v := range tagXList {
  3891. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  3892. chartIdMap[v.ChartInfoId] = true
  3893. }
  3894. }
  3895. tagYList, err := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
  3896. if err != nil && err.Error() != utils.ErrNoRow() {
  3897. br.Msg = "获取图表信息失败"
  3898. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3899. return
  3900. }
  3901. for _, v := range tagYList {
  3902. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  3903. chartIdMap[v.ChartInfoId] = true
  3904. }
  3905. }
  3906. // 获取当前账号的不可见图表
  3907. {
  3908. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3909. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  3910. if err != nil && err.Error() != utils.ErrNoRow() {
  3911. br.Msg = "获取失败"
  3912. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3913. return
  3914. }
  3915. for _, v := range confList {
  3916. if _, ok := chartIdMap[v.ChartInfoId]; ok {
  3917. delete(chartIdMap, v.ChartInfoId)
  3918. }
  3919. }
  3920. }
  3921. for k, _ := range chartIdMap {
  3922. chartIds = append(chartIds, k)
  3923. }
  3924. // 关联指标
  3925. if len(chartIds) > 0 {
  3926. condition += ` AND a.chart_info_id in (` + utils.GetOrmInReplace(len(chartIds)) + `)`
  3927. pars = append(pars, chartIds)
  3928. } else {
  3929. items := make([]*data_manage.ChartInfoView, 0)
  3930. resp.Paging = page
  3931. resp.List = items
  3932. br.Ret = 200
  3933. br.Success = true
  3934. br.Msg = "获取成功"
  3935. return
  3936. }
  3937. // 得到图表ID
  3938. //获取关联图表列表
  3939. list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
  3940. if err != nil && err.Error() != utils.ErrNoRow() {
  3941. br.Success = true
  3942. br.Msg = "获取图表信息失败"
  3943. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3944. return
  3945. }
  3946. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3947. items := make([]*data_manage.ChartInfoView, 0)
  3948. resp.Paging = page
  3949. resp.List = items
  3950. br.Ret = 200
  3951. br.Success = true
  3952. br.Msg = "获取成功"
  3953. return
  3954. }
  3955. // 获取关联图表总数
  3956. dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
  3957. if err != nil && err.Error() != utils.ErrNoRow() {
  3958. br.Msg = "获取指标信息失败"
  3959. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3960. return
  3961. }
  3962. // 获取MY ETA 图表,用来判断是否加入我的图库
  3963. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  3964. if err != nil && err.Error() != utils.ErrNoRow() {
  3965. br.Msg = "获取图表信息失败"
  3966. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  3967. return
  3968. }
  3969. myChartMap := make(map[int]*data_manage.MyChartView)
  3970. for _, v := range myChartList {
  3971. myChartMap[v.ChartInfoId] = v
  3972. }
  3973. listLen := len(list)
  3974. if listLen > 0 {
  3975. // 分类id
  3976. classifyIdList := make([]int, 0)
  3977. // 当前列表中的分类map
  3978. classifyMap := make(map[int]*data_manage.ChartClassify)
  3979. for _, v := range list {
  3980. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  3981. }
  3982. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  3983. if err != nil {
  3984. br.Msg = "获取失败"
  3985. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  3986. return
  3987. }
  3988. for _, v := range classifyList {
  3989. classifyMap[v.ChartClassifyId] = v
  3990. }
  3991. // 已授权分类id
  3992. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  3993. if err != nil {
  3994. br.Msg = "获取失败"
  3995. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  3996. return
  3997. }
  3998. for _, v := range list {
  3999. if existItem, ok := myChartMap[v.ChartInfoId]; ok {
  4000. v.IsAdd = true
  4001. v.MyChartId = existItem.MyChartId
  4002. v.MyChartClassifyId = existItem.MyChartClassifyId
  4003. }
  4004. // 权限
  4005. if currClassify, ok := classifyMap[v.ChartClassifyId]; ok {
  4006. v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  4007. }
  4008. }
  4009. }
  4010. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  4011. resp.Paging = page
  4012. resp.List = list
  4013. br.Ret = 200
  4014. br.Success = true
  4015. br.Msg = "获取成功"
  4016. br.Data = resp
  4017. }
  4018. // RelationEdbList
  4019. // @Title 获取ETA指标关联的指标列表接口
  4020. // @Description 获取ETA指标关联的指标列表接口
  4021. // @Param PageSize query int true "每页数据条数"
  4022. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4023. // @Param EdbInfoId query int true "指标id"
  4024. // @Param IsShowMe query bool true "是否只看我的,true、false"
  4025. // @Success 200 {object} data_manage.ChartListResp
  4026. // @router /edb_info/relation/edbinfo_list [get]
  4027. func (this *EdbInfoController) RelationEdbList() {
  4028. br := new(models.BaseResponse).Init()
  4029. defer func() {
  4030. this.Data["json"] = br
  4031. this.ServeJSON()
  4032. }()
  4033. sysUser := this.SysUser
  4034. if sysUser == nil {
  4035. br.Msg = "请登录"
  4036. br.ErrMsg = "请登录,SysUser Is Empty"
  4037. br.Ret = 408
  4038. return
  4039. }
  4040. edbInfoId, _ := this.GetInt("EdbInfoId")
  4041. pageSize, _ := this.GetInt("PageSize")
  4042. currentIndex, _ := this.GetInt("CurrentIndex")
  4043. resp := data_manage.RelationEdbInfoListResp{}
  4044. var total int
  4045. page := paging.GetPaging(currentIndex, pageSize, total)
  4046. var startSize int
  4047. if pageSize <= 0 {
  4048. pageSize = utils.PageSize20
  4049. }
  4050. if currentIndex <= 0 {
  4051. currentIndex = 1
  4052. }
  4053. startSize = paging.StartIndex(currentIndex, pageSize)
  4054. var condition string
  4055. var pars []interface{}
  4056. if edbInfoId <= 0 {
  4057. br.Msg = "请选择指标"
  4058. br.ErrMsg = "请选择指标"
  4059. br.IsSendEmail = false
  4060. return
  4061. }
  4062. // 关联指标
  4063. condition += ` AND b.from_edb_info_id = ? `
  4064. pars = append(pars, edbInfoId)
  4065. //只看我的
  4066. isShowMe, _ := this.GetBool("IsShowMe")
  4067. if isShowMe {
  4068. condition += ` AND a.sys_user_id = ? `
  4069. pars = append(pars, sysUser.AdminId)
  4070. }
  4071. // 获取当前账号的不可见图表
  4072. noPermissionEdbIdList := make([]int, 0)
  4073. {
  4074. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4075. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4076. if err != nil && err.Error() != utils.ErrNoRow() {
  4077. br.Msg = "获取失败"
  4078. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  4079. return
  4080. }
  4081. for _, v := range confList {
  4082. noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
  4083. }
  4084. }
  4085. noPermissionEdbIdNum := len(noPermissionEdbIdList)
  4086. if noPermissionEdbIdNum > 0 {
  4087. condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
  4088. pars = append(pars, noPermissionEdbIdList)
  4089. }
  4090. //获取关联图表列表
  4091. list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
  4092. if err != nil && err.Error() != utils.ErrNoRow() {
  4093. br.Success = true
  4094. br.Msg = "获取图表信息失败"
  4095. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  4096. return
  4097. }
  4098. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  4099. items := make([]*data_manage.ChartEdbInfoMapping, 0)
  4100. resp.Paging = page
  4101. resp.List = items
  4102. br.Ret = 200
  4103. br.Success = true
  4104. br.Msg = "获取成功"
  4105. return
  4106. }
  4107. // 获取关联图表总数
  4108. dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
  4109. if err != nil && err.Error() != utils.ErrNoRow() {
  4110. br.Msg = "获取指标信息失败"
  4111. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  4112. return
  4113. }
  4114. if err != nil {
  4115. br.Msg = "获取失败"
  4116. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  4117. return
  4118. }
  4119. edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
  4120. if len(list) > 0 {
  4121. // 当前的分类
  4122. classifyMap := make(map[int]*data_manage.EdbClassify)
  4123. {
  4124. classifyIdList := make([]int, 0)
  4125. for _, v := range list {
  4126. classifyIdList = append(classifyIdList, v.ClassifyId)
  4127. }
  4128. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4129. if err != nil {
  4130. if err != nil {
  4131. br.Msg = "获取失败"
  4132. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4133. return
  4134. }
  4135. }
  4136. for _, v := range classifyList {
  4137. classifyMap[v.ClassifyId] = v
  4138. }
  4139. }
  4140. // 获取所有有权限的指标和分类
  4141. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4142. if err != nil {
  4143. br.Msg = "获取失败"
  4144. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4145. return
  4146. }
  4147. for _, v := range list {
  4148. item := new(data_manage.ChartEdbInfoMapping)
  4149. item.EdbInfoId = v.EdbInfoId
  4150. item.SourceName = v.SourceName
  4151. item.Source = v.Source
  4152. item.EdbCode = v.EdbCode
  4153. item.EdbName = v.EdbName
  4154. item.EdbNameEn = v.EdbNameEn
  4155. item.Frequency = v.Frequency
  4156. item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
  4157. if v.Unit != `无` {
  4158. item.Unit = v.Unit
  4159. }
  4160. item.UnitEn = v.UnitEn
  4161. item.StartDate = v.StartDate
  4162. item.EndDate = v.EndDate
  4163. item.ModifyTime = v.ModifyTime
  4164. item.IsAxis = 1
  4165. item.LeadValue = 0
  4166. item.LeadUnit = ""
  4167. item.ChartEdbMappingId = 0
  4168. item.ChartInfoId = 0
  4169. item.IsOrder = false
  4170. item.EdbInfoType = v.EdbInfoType
  4171. item.EdbInfoCategoryType = v.EdbInfoType
  4172. item.ChartStyle = ""
  4173. item.ChartColor = ""
  4174. item.ChartWidth = 0
  4175. item.MaxData = v.MaxValue
  4176. item.MinData = v.MinValue
  4177. item.LatestValue = v.LatestValue
  4178. item.LatestDate = v.LatestDate
  4179. item.UniqueCode = v.UniqueCode
  4180. item.ClassifyId = v.ClassifyId
  4181. dataList := make([]*data_manage.EdbDataList, 0)
  4182. // 指标权限
  4183. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  4184. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4185. }
  4186. // 有权限则获取数据
  4187. if item.HaveOperaAuth {
  4188. if v.EdbInfoType == 0 {
  4189. dataList, err = data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, "", "")
  4190. } else {
  4191. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
  4192. }
  4193. if err != nil {
  4194. br.Msg = "获取失败"
  4195. br.Msg = "获取失败,Err:" + err.Error()
  4196. return
  4197. }
  4198. }
  4199. item.DataList = dataList
  4200. edbList = append(edbList, item)
  4201. }
  4202. }
  4203. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  4204. resp.Paging = page
  4205. resp.List = edbList
  4206. br.Ret = 200
  4207. br.Success = true
  4208. br.Msg = "获取成功"
  4209. br.Data = resp
  4210. }
  4211. // EdbInfoDataTb
  4212. // @Title 获取指标数据同比值
  4213. // @Description 获取指标数据
  4214. // @Param EdbInfoId query int true "指标ID"
  4215. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4216. // @Param StartDate query string true "自定义开始日期"
  4217. // @Param EndDate query string true "自定义结束日期"
  4218. // @Success 200 {object} data_manage.EdbInfoDataResp
  4219. // @router /edb_info/data/tb [get]
  4220. func (this *ChartInfoController) EdbInfoDataTb() {
  4221. br := new(models.BaseResponse).Init()
  4222. defer func() {
  4223. this.Data["json"] = br
  4224. this.ServeJSON()
  4225. }()
  4226. sysUser := this.SysUser
  4227. if sysUser == nil {
  4228. br.Msg = "请登录"
  4229. br.ErrMsg = "请登录,SysUser Is Empty"
  4230. br.Ret = 408
  4231. return
  4232. }
  4233. edbInfoId, _ := this.GetInt("EdbInfoId")
  4234. if edbInfoId <= 0 {
  4235. br.Msg = "参数错误"
  4236. return
  4237. }
  4238. dateType, _ := this.GetInt("DateType")
  4239. if dateType <= 0 {
  4240. dateType = 3
  4241. }
  4242. edbInfoType, _ := this.GetInt("EdbInfoType")
  4243. if edbInfoType < 0 {
  4244. edbInfoType = 1
  4245. }
  4246. startDate := this.GetString("StartDate")
  4247. endDate := this.GetString("EndDate")
  4248. startYear, _ := this.GetInt("StartYear")
  4249. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4250. if err != nil {
  4251. br.Msg = "获取失败"
  4252. br.Msg = "获取失败,Err:" + err.Error()
  4253. return
  4254. }
  4255. var latestDateT time.Time
  4256. if edbInfo.LatestDate != "" {
  4257. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4258. }
  4259. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  4260. var startDateTime time.Time
  4261. if startDate != `` {
  4262. startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  4263. if err != nil {
  4264. br.Msg = "开始日期异常"
  4265. br.Msg = "开始日期异常,Err:" + err.Error()
  4266. return
  4267. }
  4268. //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
  4269. startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
  4270. }
  4271. tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  4272. if err != nil {
  4273. br.Msg = "获取失败"
  4274. br.Msg = "获取失败,Err:" + err.Error()
  4275. return
  4276. }
  4277. // 计算同比值
  4278. dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
  4279. if err != nil {
  4280. br.Msg = "获取失败"
  4281. br.Msg = "计算同比值失败,Err:" + err.Error()
  4282. return
  4283. }
  4284. edbInfo.MaxValue = maxValue
  4285. edbInfo.MinValue = minValue
  4286. resp := new(data_manage.EdbInfoDataResp)
  4287. resp.EdbInfo = edbInfo
  4288. resp.DataList = dataList
  4289. br.Ret = 200
  4290. br.Success = true
  4291. br.Msg = "获取成功"
  4292. br.Data = resp
  4293. }
  4294. // EdbInfoDataSeasonal
  4295. // @Title 获取指标数据(季节性)
  4296. // @Description 获取指标数据
  4297. // @Param EdbInfoId query int true "指标ID"
  4298. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4299. // @Param StartDate query string true "自定义开始日期"
  4300. // @Param EndDate query string true "自定义结束日期"
  4301. // @Param Calendar query string true "公历/农历"
  4302. // @Success 200 {object} data_manage.EdbInfoDataResp
  4303. // @router /edb_info/data/seasonal [get]
  4304. func (this *ChartInfoController) EdbInfoDataSeasonal() {
  4305. br := new(models.BaseResponse).Init()
  4306. defer func() {
  4307. this.Data["json"] = br
  4308. this.ServeJSON()
  4309. }()
  4310. sysUser := this.SysUser
  4311. if sysUser == nil {
  4312. br.Msg = "请登录"
  4313. br.ErrMsg = "请登录,SysUser Is Empty"
  4314. br.Ret = 408
  4315. return
  4316. }
  4317. dateType, _ := this.GetInt("DateType")
  4318. startDate := this.GetString("StartDate")
  4319. endDate := this.GetString("EndDate")
  4320. startYear, _ := this.GetInt("StartYear")
  4321. edbInfoIdStr := this.GetString("EdbInfoId")
  4322. edbInfoId, err := strconv.Atoi(edbInfoIdStr)
  4323. if err != nil {
  4324. br.Msg = "指标id异常"
  4325. br.Msg = "指标id转换异常,Err:" + err.Error()
  4326. return
  4327. }
  4328. fmt.Println("startDate:", startDate)
  4329. fmt.Println("endDate:", endDate)
  4330. calendar := this.GetString("Calendar")
  4331. if calendar == "" {
  4332. calendar = "公历"
  4333. }
  4334. if dateType == 0 {
  4335. if startDate == "" {
  4336. dateType = utils.DateTypeNYears
  4337. } else {
  4338. dateType = 5
  4339. }
  4340. }
  4341. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4342. if err != nil {
  4343. br.Msg = "获取失败"
  4344. br.Msg = "获取失败,Err:" + err.Error()
  4345. return
  4346. }
  4347. var latestDateT time.Time
  4348. if edbInfo.LatestDate != "" {
  4349. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4350. }
  4351. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  4352. dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
  4353. if err != nil {
  4354. br.Msg = "获取失败"
  4355. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  4356. return
  4357. }
  4358. resp := new(data_manage.EdbInfoDataSeasonalResp)
  4359. resp.EdbInfo = edbInfo
  4360. resp.DataList = dataList
  4361. br.Ret = 200
  4362. br.Success = true
  4363. br.Msg = "获取成功"
  4364. br.Data = resp
  4365. }
  4366. // SetEdbDataInsertConfig 设置插入值
  4367. // @Title 设置插入值接口
  4368. // @Description 设置插入值接口
  4369. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  4370. // @router /edb_info/insert_config/set [post]
  4371. func (this *EdbInfoController) SetEdbDataInsertConfig() {
  4372. br := new(models.BaseResponse).Init()
  4373. defer func() {
  4374. this.Data["json"] = br
  4375. this.ServeJSON()
  4376. }()
  4377. sysUser := this.SysUser
  4378. if sysUser == nil {
  4379. br.Msg = "请登录"
  4380. br.ErrMsg = "请登录,SysUser Is Empty"
  4381. br.Ret = 408
  4382. return
  4383. }
  4384. var req data_manage.SetEdbDataInsertConfigReq
  4385. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4386. if err != nil {
  4387. br.Msg = "参数解析异常!"
  4388. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4389. return
  4390. }
  4391. dateStr := req.Date
  4392. if dateStr == `` {
  4393. br.Msg = "请选择日期"
  4394. br.IsSendEmail = false
  4395. return
  4396. }
  4397. date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
  4398. if err != nil {
  4399. br.Msg = "日期异常"
  4400. br.ErrMsg = "日期异常,err:" + err.Error()
  4401. br.IsSendEmail = false
  4402. return
  4403. }
  4404. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  4405. if err != nil {
  4406. br.Msg = "获取指标信息失败"
  4407. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  4408. return
  4409. }
  4410. err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
  4411. if err != nil {
  4412. br.Msg = "设置失败"
  4413. if errMsg != `` {
  4414. br.Msg = errMsg
  4415. }
  4416. br.ErrMsg = "修改失败,Err:" + err.Error()
  4417. br.IsSendEmail = isSendEmail
  4418. return
  4419. }
  4420. //新增操作日志
  4421. {
  4422. edbLog := new(data_manage.EdbInfoLog)
  4423. edbLog.EdbInfoId = edbInfo.EdbInfoId
  4424. edbLog.SourceName = edbInfo.SourceName
  4425. edbLog.Source = edbInfo.Source
  4426. edbLog.EdbCode = edbInfo.EdbCode
  4427. edbLog.EdbName = edbInfo.EdbName
  4428. edbLog.ClassifyId = edbInfo.ClassifyId
  4429. edbLog.SysUserId = sysUser.AdminId
  4430. edbLog.SysUserRealName = sysUser.RealName
  4431. edbLog.CreateTime = time.Now()
  4432. edbLog.Content = string(this.Ctx.Input.RequestBody)
  4433. edbLog.Status = "设置插入值"
  4434. edbLog.Method = this.Ctx.Input.URI()
  4435. go data_manage.AddEdbInfoLog(edbLog)
  4436. }
  4437. br.Ret = 200
  4438. br.Success = true
  4439. br.Msg = "保存成功"
  4440. br.IsAddLog = true
  4441. }
  4442. // TraceEdbInfo
  4443. // @Title 指标溯源接口
  4444. // @Description 指标溯源接口
  4445. // @Param UniqueCode query int true "指标唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  4446. // @Success 200 {object} data_manage.ChartListResp
  4447. // @router /edb_info/trace [get]
  4448. func (this *EdbInfoController) TraceEdbInfo() {
  4449. br := new(models.BaseResponse).Init()
  4450. defer func() {
  4451. this.Data["json"] = br
  4452. this.ServeJSON()
  4453. }()
  4454. sysUser := this.SysUser
  4455. if sysUser == nil {
  4456. br.Msg = "请登录"
  4457. br.ErrMsg = "请登录,SysUser Is Empty"
  4458. br.Ret = 408
  4459. return
  4460. }
  4461. //edbInfoId, _ := this.GetInt("EdbInfoId")
  4462. //if edbInfoId <= 0 {
  4463. // br.Msg = "参数错误"
  4464. // br.ErrMsg = "参数错误"
  4465. // return
  4466. //}
  4467. uniqueCode := this.GetString("UniqueCode")
  4468. if uniqueCode == `` {
  4469. br.Msg = "参数错误"
  4470. br.ErrMsg = "参数错误"
  4471. return
  4472. }
  4473. // 根据UniqueCode获取指标信息
  4474. edbInfo, err := data_manage.GetEdbInfoByUniqueCode(uniqueCode)
  4475. if err != nil {
  4476. br.Msg = "获取失败"
  4477. br.Msg = "获取失败,Err:" + err.Error()
  4478. if err.Error() == utils.ErrNoRow() {
  4479. br.Msg = "指标不存在"
  4480. }
  4481. return
  4482. }
  4483. resp, err := data.TraceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, this.SysUser.AdminId)
  4484. if err != nil {
  4485. br.Msg = "获取失败"
  4486. br.Msg = "获取失败,Err:" + err.Error()
  4487. return
  4488. }
  4489. br.Ret = 200
  4490. br.Data = resp
  4491. br.Success = true
  4492. br.Msg = "刷新成功"
  4493. }
  4494. // AllEdbInfoByEs
  4495. // @Title 所有指标筛选接口
  4496. // @Description 所有指标筛选接口
  4497. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  4498. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  4499. // @Param Frequency query string false "频度"
  4500. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  4501. // @Param PageSize query int true "每页数据条数"
  4502. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4503. // @Success 200 {object} data_manage.EdbInfoList
  4504. // @router /edb_info/filter_by_es/all [get]
  4505. func (this *EdbInfoController) AllEdbInfoByEs() {
  4506. br := new(models.BaseResponse).Init()
  4507. defer func() {
  4508. this.Data["json"] = br
  4509. this.ServeJSON()
  4510. }()
  4511. pageSize, _ := this.GetInt("PageSize")
  4512. currentIndex, _ := this.GetInt("CurrentIndex")
  4513. var total int64
  4514. var startSize int
  4515. if pageSize <= 0 {
  4516. pageSize = utils.PageSize20
  4517. }
  4518. if currentIndex <= 0 {
  4519. currentIndex = 1
  4520. }
  4521. startSize = paging.StartIndex(currentIndex, pageSize)
  4522. keyWord := this.GetString("KeyWord")
  4523. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  4524. filterSource, _ := this.GetInt("FilterSource")
  4525. if filterSource <= 0 {
  4526. filterSource = 1
  4527. }
  4528. //指标来源
  4529. source, _ := this.GetInt("Source")
  4530. frequency := this.GetString("Frequency") //频度
  4531. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  4532. var edbInfoList []*data_manage.EdbInfoList
  4533. var err error
  4534. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  4535. // 获取当前账号的不可见指标
  4536. {
  4537. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4538. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4539. if err != nil && err.Error() != utils.ErrNoRow() {
  4540. br.Msg = "获取失败"
  4541. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  4542. return
  4543. }
  4544. for _, v := range confList {
  4545. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  4546. }
  4547. }
  4548. // 是否走ES
  4549. isEs := false
  4550. if keyWord != "" {
  4551. var keyWordArr []string
  4552. keyWordArr = append(keyWordArr, keyWord)
  4553. newKeyWord := strings.Split(keyWord, " ")
  4554. keyWordArr = append(keyWordArr, newKeyWord...)
  4555. // 普通的搜索
  4556. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, frequency, noPermissionEdbInfoIdList)
  4557. isEs = true
  4558. } else {
  4559. var condition string
  4560. var pars []interface{}
  4561. // 普通指标
  4562. condition += ` AND edb_info_type = ? `
  4563. pars = append(pars, 0)
  4564. // 无权限指标id
  4565. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  4566. if lenNoPermissionEdbInfoIdList > 0 {
  4567. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  4568. pars = append(pars, noPermissionEdbInfoIdList)
  4569. }
  4570. switch filterSource {
  4571. case 2:
  4572. condition += ` AND frequency='月度' `
  4573. case 3:
  4574. condition += ` AND frequency <> '日度' `
  4575. case 4:
  4576. condition += ` AND edb_type = 1 `
  4577. case 5:
  4578. condition += ` AND source = 6 ` //来源(同比值)
  4579. case 6:
  4580. condition += ` AND frequency != ? `
  4581. pars = append(pars, "年度")
  4582. }
  4583. //频度
  4584. if frequency != "" {
  4585. condition += ` AND frequency = ? `
  4586. pars = append(pars, frequency)
  4587. }
  4588. // 查询只允许添加预测指标的搜索
  4589. if isAddPredictEdb {
  4590. condition += ` AND frequency in ("日度","周度","月度") `
  4591. }
  4592. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  4593. }
  4594. if err != nil {
  4595. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  4596. }
  4597. page := paging.GetPaging(currentIndex, pageSize, int(total))
  4598. edbInfoListLen := len(edbInfoList)
  4599. classifyIdList := make([]int, 0)
  4600. for i := 0; i < edbInfoListLen; i++ {
  4601. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  4602. classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
  4603. }
  4604. // 当前列表中的分类map
  4605. classifyMap := make(map[int]*data_manage.EdbClassify)
  4606. if edbInfoListLen > 0 {
  4607. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4608. if err != nil {
  4609. br.Msg = "获取失败"
  4610. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4611. return
  4612. }
  4613. for _, v := range classifyList {
  4614. classifyMap[v.ClassifyId] = v
  4615. }
  4616. // 获取所有有权限的指标和分类
  4617. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4618. if err != nil {
  4619. br.Msg = "获取失败"
  4620. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4621. return
  4622. }
  4623. // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  4624. if isEs {
  4625. edbInfoIdList := make([]int, 0)
  4626. for i := 0; i < edbInfoListLen; i++ {
  4627. edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
  4628. tmpEdbInfo := edbInfoList[i]
  4629. if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
  4630. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4631. }
  4632. }
  4633. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  4634. if err != nil {
  4635. br.Msg = "获取失败"
  4636. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4637. return
  4638. }
  4639. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  4640. for _, v := range tmpEdbList {
  4641. edbInfoMap[v.EdbInfoId] = v
  4642. }
  4643. for i := 0; i < edbInfoListLen; i++ {
  4644. tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
  4645. if !ok {
  4646. continue
  4647. }
  4648. edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
  4649. }
  4650. }
  4651. // 权限校验
  4652. for i := 0; i < edbInfoListLen; i++ {
  4653. tmpEdbInfoItem := edbInfoList[i]
  4654. if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
  4655. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4656. }
  4657. }
  4658. }
  4659. for i := 0; i < edbInfoListLen; i++ {
  4660. for j := 0; j < edbInfoListLen; j++ {
  4661. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  4662. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  4663. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  4664. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  4665. }
  4666. }
  4667. }
  4668. //新增搜索词记录
  4669. {
  4670. searchKeyword := new(data_manage.SearchKeyword)
  4671. searchKeyword.KeyWord = keyWord
  4672. searchKeyword.CreateTime = time.Now()
  4673. go data_manage.AddSearchKeyword(searchKeyword)
  4674. }
  4675. resp := data_manage.EdbInfoFilterDataResp{
  4676. Paging: page,
  4677. List: edbInfoList,
  4678. }
  4679. br.Ret = 200
  4680. br.Success = true
  4681. br.Msg = "获取成功"
  4682. br.Data = resp
  4683. }
  4684. // GetEdbDateData
  4685. // @Title 根据指标ID和具体日期获取对应日期的数据值
  4686. // @Description 根据指标ID和具体日期获取对应日期的数据值
  4687. // @Param EdbInfoId query int false "指标id"
  4688. // @Param Date query string false "日期"
  4689. // @Success 200 {object} data_manage.EdbInfoList
  4690. // @router /edb_info/date_data [get]
  4691. func (this *EdbInfoController) GetEdbDateData() {
  4692. br := new(models.BaseResponse).Init()
  4693. defer func() {
  4694. this.Data["json"] = br
  4695. this.ServeJSON()
  4696. }()
  4697. edbInfoId, _ := this.GetInt("EdbInfoId")
  4698. date := this.GetString("Date")
  4699. if edbInfoId <= 0 {
  4700. br.Msg = "请选择指标"
  4701. br.IsSendEmail = false
  4702. return
  4703. }
  4704. if date == `` {
  4705. br.Msg = "请选择日期"
  4706. br.IsSendEmail = false
  4707. return
  4708. }
  4709. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4710. if err != nil {
  4711. br.Msg = "获取失败"
  4712. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4713. return
  4714. }
  4715. startDate := date
  4716. endDate := date
  4717. dateType := "day"
  4718. //如果填写的是月度日期
  4719. if strings.Count(date, "-") == 1 {
  4720. startDate = date + "-01"
  4721. endDate = ``
  4722. dateType = "month"
  4723. }
  4724. dataItem, err := data.GetDateData(edbInfo, startDate, endDate)
  4725. if err != nil {
  4726. br.Msg = "获取失败"
  4727. br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
  4728. return
  4729. }
  4730. val := ``
  4731. if dataItem != nil {
  4732. switch dateType {
  4733. case "month":
  4734. dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local)
  4735. dateTimeStr := dateTime.Format(utils.FormatYearMonthDate)
  4736. if dateTimeStr != date {
  4737. val = ``
  4738. }
  4739. }
  4740. val = fmt.Sprint(dataItem.Value)
  4741. }
  4742. br.Ret = 200
  4743. br.Success = true
  4744. br.Msg = "获取成功"
  4745. br.Data = val
  4746. }
  4747. // GetEdbBeforeAndAfterDateData
  4748. // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4749. // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4750. // @Param EdbInfoId query int false "指标id"
  4751. // @Param Date query string false "日期"
  4752. // @Param Num query int false "前后几期数据"
  4753. // @Success 200 {object} data_manage.EdbInfoList
  4754. // @router /edb_info/date_data/before_after [post]
  4755. func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
  4756. br := new(models.BaseResponse).Init()
  4757. defer func() {
  4758. this.Data["json"] = br
  4759. this.ServeJSON()
  4760. }()
  4761. requestBody := string(this.Ctx.Input.RequestBody)
  4762. var req request2.DateDataBeforeAfterReq
  4763. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4764. if err != nil {
  4765. br.Msg = "参数解析异常!"
  4766. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4767. return
  4768. }
  4769. edbInfoId := req.EdbInfoId
  4770. currDate := req.Date
  4771. num := req.Num
  4772. // 默认2期数据
  4773. if num <= 0 {
  4774. num = 2
  4775. }
  4776. if edbInfoId <= 0 {
  4777. br.Msg = "请选择指标"
  4778. br.IsSendEmail = false
  4779. return
  4780. }
  4781. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4782. if err != nil {
  4783. br.Msg = "获取失败"
  4784. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4785. return
  4786. }
  4787. dataList := make([]*data_manage.EdbDataList, 0)
  4788. switch edbInfo.EdbInfoType {
  4789. case 0:
  4790. dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
  4791. case 1:
  4792. _, dataList, _, _, _, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  4793. default:
  4794. br.Msg = "指标类型异常!"
  4795. br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType)
  4796. return
  4797. }
  4798. if currDate == `` {
  4799. currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList)
  4800. if err != nil {
  4801. br.Msg = "日期前移失败"
  4802. br.ErrMsg = "日期前移失败,Err:" + err.Error()
  4803. return
  4804. }
  4805. } else {
  4806. if strings.Count(currDate, "-") == 1 {
  4807. currDate = currDate + "-01"
  4808. // 查找这个月早的时间作为起始时间
  4809. for _, v := range dataList {
  4810. if v.DataTime >= currDate {
  4811. currDate = v.DataTime
  4812. break
  4813. }
  4814. }
  4815. }
  4816. }
  4817. currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody)
  4818. if err != nil {
  4819. br.Msg = "日期变换失败"
  4820. br.ErrMsg = "日期变换失败,Err:" + err.Error()
  4821. return
  4822. }
  4823. list := make([]*data_manage.EdbDataList, 5)
  4824. list, err = data.GetEdbBeforeAndAfterDateData(currDate, dataList)
  4825. if err != nil {
  4826. br.Msg = "获取失败"
  4827. br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
  4828. return
  4829. }
  4830. // 这个日期不存在的话直接返回空数组
  4831. resp := data_manage.BeforeAndAfterDateDataResp{
  4832. List: list,
  4833. Date: currDate,
  4834. }
  4835. br.Ret = 200
  4836. br.Success = true
  4837. br.Msg = "获取成功"
  4838. br.Data = resp
  4839. }
  4840. // EdbChartAdminList
  4841. // @Title 获取创建人员分组
  4842. // @Description 获取创建人员分组
  4843. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  4844. // @Success 200 {object} company.DepartmentGroupSellersResp
  4845. // @router /edb_chart/adminList [get]
  4846. func (this *EdbInfoController) EdbChartAdminList() {
  4847. br := new(models.BaseResponse).Init()
  4848. defer func() {
  4849. this.Data["json"] = br
  4850. this.ServeJSON()
  4851. }()
  4852. sysUser := this.SysUser
  4853. if sysUser == nil {
  4854. br.Msg = "请登录"
  4855. br.ErrMsg = "请登录,SysUser Is Empty"
  4856. br.Ret = 408
  4857. return
  4858. }
  4859. source, _ := this.GetInt("Source", 0)
  4860. if source <= 0 || source > 5 {
  4861. br.Msg = "错误的来源"
  4862. br.IsSendEmail = false
  4863. return
  4864. }
  4865. idList, err := data.GetEdbChartAdminList(source)
  4866. if err != nil {
  4867. //br.Success = true
  4868. br.Msg = "获取失败"
  4869. br.ErrMsg = "获取失败,Err:" + err.Error()
  4870. return
  4871. }
  4872. fmt.Println("idlist:", idList)
  4873. systemAdminMap := make(map[int]*system.Admin)
  4874. departmentMap := make(map[string]string)
  4875. departmentAdminMap := make(map[int]string)
  4876. groupMap := make(map[string]string)
  4877. systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList)
  4878. if err != nil {
  4879. br.Msg = "获取用户列表失败"
  4880. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  4881. return
  4882. }
  4883. for _, v := range systemAdminList {
  4884. systemAdminMap[v.AdminId] = v
  4885. departmentMap[v.DepartmentName] = v.DepartmentName
  4886. departmentAdminMap[v.AdminId] = v.DepartmentName
  4887. groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName
  4888. }
  4889. depList := make([]company.DepartmentGroupAdmins, 0)
  4890. i := 1
  4891. for _, v := range departmentMap {
  4892. item := company.DepartmentGroupAdmins{
  4893. AdminId: "dep_" + strconv.Itoa(i),
  4894. RealName: v,
  4895. }
  4896. i++
  4897. depList = append(depList, item)
  4898. }
  4899. for k := 0; k < len(depList); k++ {
  4900. for k1, v1 := range groupMap {
  4901. if v1 == depList[k].RealName && v1 != "" {
  4902. item := &company.DepartmentGroupAdmins{
  4903. AdminId: "group_" + strconv.Itoa(k),
  4904. RealName: strings.Replace(k1, v1, "", -1),
  4905. }
  4906. depList[k].ChildrenList = append(depList[k].ChildrenList, item)
  4907. }
  4908. }
  4909. }
  4910. for _, admin := range systemAdminList {
  4911. for i, v := range depList {
  4912. for k, group := range v.ChildrenList {
  4913. if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName {
  4914. item := &company.DepartmentGroupAdmins{
  4915. AdminId: strconv.Itoa(admin.AdminId),
  4916. RealName: admin.RealName,
  4917. RoleTypeCode: admin.RoleTypeCode,
  4918. Authority: admin.Authority,
  4919. }
  4920. if group.RealName != "" {
  4921. depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item)
  4922. } else {
  4923. depList[i].ChildrenList = append(depList[i].ChildrenList, item)
  4924. }
  4925. }
  4926. }
  4927. }
  4928. }
  4929. for i, groupList := range depList {
  4930. for k, v := range groupList.ChildrenList {
  4931. if v.RealName == "" {
  4932. newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...)
  4933. depList[i].ChildrenList = newChildrenList
  4934. }
  4935. }
  4936. }
  4937. br.Ret = 200
  4938. br.Success = true
  4939. br.Msg = "获取成功"
  4940. br.Data = depList
  4941. }
  4942. // EdbSourceList
  4943. // @Title 指标来源列表
  4944. // @Description 指标来源列表
  4945. // @Param IsBase query int false "是否为基础指标: 1-是"
  4946. // @Success 200 {object} data_manage.EdbInfoListResp
  4947. // @router /edb_source/list [get]
  4948. func (this *EdbInfoController) EdbSourceList() {
  4949. br := new(models.BaseResponse).Init()
  4950. defer func() {
  4951. if br.ErrMsg == "" {
  4952. br.IsSendEmail = false
  4953. }
  4954. this.Data["json"] = br
  4955. this.ServeJSON()
  4956. }()
  4957. isBase, _ := this.GetInt("IsBase", 0)
  4958. cond := ``
  4959. if isBase > 0 {
  4960. cond = ` AND is_base = 1`
  4961. }
  4962. pars := make([]interface{}, 0)
  4963. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4964. if e != nil {
  4965. br.Msg = "获取失败"
  4966. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4967. return
  4968. }
  4969. br.Data = list
  4970. br.Ret = 200
  4971. br.Success = true
  4972. br.Msg = "获取成功"
  4973. }
  4974. // EdbSourceListByPython
  4975. // @Title 指标来源列表
  4976. // @Description 指标来源列表
  4977. // @Param IsBase query int false "是否为基础指标: 1-是"
  4978. // @Success 200 {object} data_manage.EdbInfoListResp
  4979. // @router /edb_source/list/python [get]
  4980. func (this *EdbInfoController) EdbSourceListByPython() {
  4981. br := new(models.BaseResponse).Init()
  4982. defer func() {
  4983. if br.ErrMsg == "" {
  4984. br.IsSendEmail = false
  4985. }
  4986. this.Data["json"] = br
  4987. this.ServeJSON()
  4988. }()
  4989. isBase, _ := this.GetInt("IsBase", 0)
  4990. cond := ``
  4991. if isBase > 0 {
  4992. cond = ` AND is_base = 1`
  4993. }
  4994. pars := make([]interface{}, 0)
  4995. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4996. if e != nil {
  4997. br.Msg = "获取失败"
  4998. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4999. return
  5000. }
  5001. baseEdbList := make([]data_manage.EdbSourceChild, 0)
  5002. calEdbList := make([]data_manage.EdbSourceChild, 0)
  5003. for _, v := range list {
  5004. switch v.IsBase {
  5005. case 1:
  5006. baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{
  5007. EdbSourceId: v.EdbSourceId,
  5008. SourceName: v.SourceName,
  5009. IsBase: v.IsBase,
  5010. TableName: v.TableName,
  5011. Child: []data_manage.EdbSourceChild{},
  5012. })
  5013. case 2:
  5014. calEdbList = append(calEdbList, data_manage.EdbSourceChild{
  5015. EdbSourceId: v.EdbSourceId,
  5016. SourceName: v.SourceName,
  5017. IsBase: v.IsBase,
  5018. TableName: v.TableName,
  5019. Child: []data_manage.EdbSourceChild{},
  5020. })
  5021. }
  5022. }
  5023. resp := []data_manage.EdbSourceChild{
  5024. {
  5025. EdbSourceId: 0,
  5026. SourceName: "基础指标",
  5027. IsBase: 1,
  5028. Child: baseEdbList,
  5029. },
  5030. {
  5031. EdbSourceId: 0,
  5032. SourceName: "计算指标",
  5033. IsBase: 1,
  5034. Child: calEdbList,
  5035. },
  5036. }
  5037. br.Data = resp
  5038. br.Ret = 200
  5039. br.Success = true
  5040. br.Msg = "获取成功"
  5041. }
  5042. // EdbChartList
  5043. // @Title 指标缩略图列表接口
  5044. // @Description 指标缩略图列表接口
  5045. // @Param PageSize query int true "每页数据条数"
  5046. // @Param CurrentIndex query int true "当前页页码,从1开始"
  5047. // @Param ClassifyId query int true "分类id"
  5048. // @Param AdminId query int false "创建人id"
  5049. // @Param IsOnlyMe query bool false "是否只看我的"
  5050. // @Success 200 {object} response.EdbInfoChartListResp
  5051. // @router /edb_info/chart/list [get]
  5052. func (this *EdbInfoController) EdbChartList() {
  5053. br := new(models.BaseResponse).Init()
  5054. defer func() {
  5055. if br.ErrMsg == "" {
  5056. br.IsSendEmail = false
  5057. }
  5058. this.Data["json"] = br
  5059. this.ServeJSON()
  5060. }()
  5061. sysUser := this.SysUser
  5062. if sysUser == nil {
  5063. br.Msg = "请登录"
  5064. br.ErrMsg = "请登录,SysUser Is Empty"
  5065. br.Ret = 408
  5066. return
  5067. }
  5068. // 分页
  5069. pageSize, _ := this.GetInt("PageSize")
  5070. currentIndex, _ := this.GetInt("CurrentIndex")
  5071. var total int
  5072. page := paging.GetPaging(currentIndex, pageSize, total)
  5073. var startSize int
  5074. if pageSize <= 0 {
  5075. pageSize = utils.PageSize20
  5076. }
  5077. if currentIndex <= 0 {
  5078. currentIndex = 1
  5079. }
  5080. startSize = paging.StartIndex(currentIndex, pageSize)
  5081. // 基础指标
  5082. var condition string
  5083. var pars []interface{}
  5084. condition += ` AND edb_info_type = ? `
  5085. pars = append(pars, 0)
  5086. // 分类筛选
  5087. classifyId, _ := this.GetInt("ClassifyId")
  5088. if classifyId > 0 {
  5089. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  5090. if e != nil && e.Error() != utils.ErrNoRow() {
  5091. br.Msg = "获取失败"
  5092. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  5093. return
  5094. }
  5095. var classifyIds []int
  5096. for _, v := range childClassify {
  5097. classifyIds = append(classifyIds, v.ClassifyId)
  5098. }
  5099. condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  5100. pars = append(pars, classifyIds)
  5101. }
  5102. // 创建人
  5103. adminId, _ := this.GetInt("AdminId")
  5104. if adminId > 0 {
  5105. condition += ` AND sys_user_id = ? `
  5106. pars = append(pars, adminId)
  5107. }
  5108. // 只看我的
  5109. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  5110. if isOnlyMe {
  5111. condition += ` AND sys_user_id = ? `
  5112. pars = append(pars, sysUser.AdminId)
  5113. }
  5114. // 获取当前账号的不可见指标
  5115. obj := data_manage.EdbInfoNoPermissionAdmin{}
  5116. confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
  5117. if e != nil {
  5118. br.Msg = "获取失败"
  5119. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
  5120. return
  5121. }
  5122. noPermissionEdbInfoIdList := make([]int, 0)
  5123. for _, v := range confList {
  5124. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  5125. }
  5126. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  5127. if noPermissionEdbInfoIdNum > 0 {
  5128. condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  5129. pars = append(pars, noPermissionEdbInfoIdList)
  5130. }
  5131. // 获取指标信息
  5132. dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  5133. if e != nil {
  5134. br.Msg = "获取失败"
  5135. br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
  5136. return
  5137. }
  5138. if len(list) == 0 {
  5139. list = make([]*data_manage.EdbInfoList, 0)
  5140. } else {
  5141. classifyIdList := make([]int, 0)
  5142. for _, v := range list {
  5143. classifyIdList = append(classifyIdList, v.ClassifyId)
  5144. }
  5145. // 指标权限
  5146. {
  5147. // 当前的分类
  5148. classifyMap := make(map[int]*data_manage.EdbClassify)
  5149. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  5150. if err != nil {
  5151. if err != nil {
  5152. br.Msg = "获取失败"
  5153. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  5154. return
  5155. }
  5156. }
  5157. for _, v := range classifyList {
  5158. classifyMap[v.ClassifyId] = v
  5159. }
  5160. // 获取所有有权限的指标和分类
  5161. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  5162. if err != nil {
  5163. br.Msg = "获取失败"
  5164. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  5165. return
  5166. }
  5167. issSupplierStopIndexCodeMap := make(map[string]bool)
  5168. {
  5169. tmpEdbCodeList := make([]string, 0)
  5170. for _, v := range list {
  5171. if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  5172. tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode)
  5173. }
  5174. }
  5175. if len(tmpEdbCodeList) > 0 {
  5176. notIsSupplierStopIndexList, e := data_manage.GetNotIsSupplierStopIndexByCodeList(tmpEdbCodeList, 1)
  5177. if e != nil {
  5178. br.Msg = "获取失败"
  5179. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  5180. return
  5181. }
  5182. // 已被供应商暂停的指标编码
  5183. for _, v := range notIsSupplierStopIndexList {
  5184. issSupplierStopIndexCodeMap[v.IndexCode] = true
  5185. }
  5186. }
  5187. }
  5188. for _, v := range list {
  5189. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  5190. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  5191. v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType, v.HaveOperaAuth)
  5192. }
  5193. // 供应商停用
  5194. if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  5195. if _, ok := issSupplierStopIndexCodeMap[v.EdbCode]; ok {
  5196. v.IsSupplierStop = 1
  5197. }
  5198. }
  5199. }
  5200. }
  5201. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  5202. }
  5203. resp := response.EdbInfoChartListResp{
  5204. Paging: page,
  5205. List: list,
  5206. }
  5207. br.Ret = 200
  5208. br.Success = true
  5209. br.Msg = "获取成功"
  5210. br.Data = resp
  5211. }
  5212. // Modify
  5213. // @Title 修改指标信息接口
  5214. // @Description 编辑指标接口
  5215. // @Success 200 string "操作成功"
  5216. // @router /edb_info/modify [post]
  5217. func (this *EdbInfoController) Modify() {
  5218. br := new(models.BaseResponse).Init()
  5219. defer func() {
  5220. if br.ErrMsg == "" {
  5221. br.IsSendEmail = false
  5222. }
  5223. this.Data["json"] = br
  5224. this.ServeJSON()
  5225. }()
  5226. sysUser := this.SysUser
  5227. if sysUser == nil {
  5228. br.Msg = "请登录"
  5229. br.ErrMsg = "请登录,SysUser Is Empty"
  5230. br.Ret = 408
  5231. return
  5232. }
  5233. var req request.ModifyEdbInfoReq
  5234. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5235. if err != nil {
  5236. br.Msg = "参数解析异常!"
  5237. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5238. return
  5239. }
  5240. edbInfoId := req.EdbInfoId
  5241. if edbInfoId <= 0 {
  5242. br.Msg = "请选择指标"
  5243. br.IsSendEmail = false
  5244. return
  5245. }
  5246. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5247. if e != nil {
  5248. br.Msg = "操作失败"
  5249. br.ErrMsg = "获取指标信息失败, Err:" + err.Error()
  5250. return
  5251. }
  5252. var haveOperaAuth bool
  5253. // 权限校验
  5254. {
  5255. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
  5256. if err != nil {
  5257. br.Msg = err.Error()
  5258. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  5259. return
  5260. }
  5261. }
  5262. // 编辑权限校验
  5263. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  5264. if !button.OpButton {
  5265. br.Msg = "无权限操作"
  5266. return
  5267. }
  5268. edbInfo.MaxValue = req.MaxValue
  5269. edbInfo.MinValue = req.MinValue
  5270. edbInfo.ManualSave = 1
  5271. edbInfo.ModifyTime = time.Now()
  5272. err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"})
  5273. if err != nil {
  5274. br.Msg = "获取失败"
  5275. br.ErrMsg = "获取失败,Err:" + err.Error()
  5276. return
  5277. }
  5278. //修改es
  5279. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  5280. br.Ret = 200
  5281. br.Success = true
  5282. br.Msg = "修改成功"
  5283. br.IsAddLog = true
  5284. }
  5285. // ChartImageSet
  5286. // @Title 设置指标的图表图片
  5287. // @Description 设置指标的图表图片接口
  5288. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  5289. // @Success Ret=200 保存成功
  5290. // @router /edb_info/image/set [post]
  5291. func (this *EdbInfoController) ChartImageSet() {
  5292. br := new(models.BaseResponse).Init()
  5293. defer func() {
  5294. if br.ErrMsg == "" {
  5295. br.IsSendEmail = false
  5296. }
  5297. this.Data["json"] = br
  5298. this.ServeJSON()
  5299. }()
  5300. sysUser := this.SysUser
  5301. if sysUser == nil {
  5302. br.Msg = "请登录"
  5303. br.ErrMsg = "请登录,SysUser Is Empty"
  5304. br.Ret = 408
  5305. return
  5306. }
  5307. var req data_manage.SetEdbInfoImageReq
  5308. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  5309. br.Msg = "参数解析异常!"
  5310. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  5311. return
  5312. }
  5313. if req.EdbInfoId <= 0 || req.ImageUrl == "" {
  5314. br.Ret = 200
  5315. br.Success = true
  5316. br.Msg = "保存成功"
  5317. return
  5318. }
  5319. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5320. if e != nil {
  5321. if e.Error() == utils.ErrNoRow() {
  5322. br.Msg = "找不到该指标"
  5323. return
  5324. }
  5325. br.Msg = "保存失败"
  5326. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  5327. return
  5328. }
  5329. edbInfo.ChartImage = req.ImageUrl
  5330. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  5331. br.Msg = "保存失败"
  5332. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  5333. return
  5334. }
  5335. // 修改es数据
  5336. go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  5337. br.Ret = 200
  5338. br.Success = true
  5339. br.Msg = "保存成功"
  5340. }
  5341. // EdbInfoExistCheck
  5342. // @Title 新增指标-检验指标是否存在接口
  5343. // @Description 新增指标-检验指标是否存在接口
  5344. // @Param Source query int true "来源:1:同花顺,2:wind"
  5345. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5346. // @Param EdbCode query string false "指标编码/指标代码"
  5347. // @Param StockCode query string false "证券代码"
  5348. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5349. // @router /edb_info/exist/check [get]
  5350. func (this *EdbInfoController) EdbInfoExistCheck() {
  5351. br := new(models.BaseResponse).Init()
  5352. defer func() {
  5353. this.Data["json"] = br
  5354. this.ServeJSON()
  5355. }()
  5356. source, _ := this.GetInt("Source")
  5357. edbCode := this.GetString("EdbCode")
  5358. edbCode = strings.Trim(edbCode, "\t")
  5359. edbCode = strings.Trim(edbCode, " ")
  5360. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5361. subSource, _ := this.GetInt("SubSource")
  5362. stockCode := this.GetString("StockCode")
  5363. if source <= 0 {
  5364. br.Msg = "无效的数据来源"
  5365. return
  5366. }
  5367. if edbCode == "" {
  5368. br.Msg = "请输入指标ID"
  5369. return
  5370. }
  5371. if source != utils.DATA_SOURCE_WIND && source != utils.DATA_SOURCE_THS {
  5372. br.Msg = "无效的数据来源"
  5373. return
  5374. }
  5375. if subSource != utils.DATA_SUB_SOURCE_DATE {
  5376. br.Msg = "无效的数据库来源"
  5377. return
  5378. }
  5379. var indexCodeArr []string
  5380. edbCodeArr := strings.Split(edbCode, ",")
  5381. stockCodeArr := strings.Split(stockCode, ",")
  5382. var prefix string
  5383. if source == utils.DATA_SOURCE_WIND {
  5384. prefix = utils.WindDbWsd
  5385. } else if source == utils.DATA_SOURCE_THS {
  5386. prefix = utils.ThsDs
  5387. } else {
  5388. br.Msg = "来源错误"
  5389. br.ErrMsg = "来源错误"
  5390. return
  5391. }
  5392. for _, sv := range stockCodeArr {
  5393. for _, ev := range edbCodeArr {
  5394. indexCode := prefix + sv + ev
  5395. indexCodeArr = append(indexCodeArr, indexCode)
  5396. }
  5397. }
  5398. indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr)
  5399. if err != nil && err.Error() != utils.ErrNoRow() {
  5400. br.Msg = "校验指标是否存在失败"
  5401. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5402. return
  5403. }
  5404. var existStockCodeArr []string
  5405. var existEdbCodeArr []string
  5406. var existClassifyId []int
  5407. var existIndexId []int
  5408. for _, indexItem := range indexList {
  5409. for _, sv := range stockCodeArr {
  5410. for _, ev := range edbCodeArr {
  5411. if strings.Contains(indexItem.EdbCode, sv) {
  5412. existStockCodeArr = append(existStockCodeArr, sv)
  5413. }
  5414. if strings.Contains(indexItem.EdbCode, ev) {
  5415. existEdbCodeArr = append(existEdbCodeArr, ev)
  5416. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5417. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5418. }
  5419. }
  5420. }
  5421. }
  5422. resp := new(data_manage.EdbInfoExistCheckResp)
  5423. if len(indexList) > 0 {
  5424. resp.IndexExist = true
  5425. }
  5426. resp.ExistEdbCodeArr = existEdbCodeArr
  5427. resp.ExistStockCodeArr = existStockCodeArr
  5428. resp.ExistClassifyId = existClassifyId
  5429. resp.ExistIndexId = existIndexId
  5430. resp.ExistEdbInfo = indexList
  5431. br.Ret = 200
  5432. br.Success = true
  5433. br.Msg = "获取成功"
  5434. br.Data = resp
  5435. }
  5436. // EdbInfoAdd
  5437. // @Title 指标批量保存接口
  5438. // @Description 指标批量保存接口
  5439. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  5440. // @Success Ret=200 保存成功
  5441. // @router /edb_info/batch/add [post]
  5442. func (this *EdbInfoController) EdbInfoBatchAdd() {
  5443. br := new(models.BaseResponse).Init()
  5444. defer func() {
  5445. this.Data["json"] = br
  5446. this.ServeJSON()
  5447. }()
  5448. sysUser := this.SysUser
  5449. if sysUser == nil {
  5450. br.Msg = "请登录"
  5451. br.ErrMsg = "请登录,SysUser Is Empty"
  5452. br.Ret = 408
  5453. return
  5454. }
  5455. deleteCache := true
  5456. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  5457. defer func() {
  5458. if deleteCache {
  5459. utils.Rc.Delete(cacheKey)
  5460. }
  5461. }()
  5462. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  5463. deleteCache = false
  5464. br.Msg = "系统处理中,请稍后重试!"
  5465. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  5466. return
  5467. }
  5468. var req data_manage.BatchAddEdbInfoReq
  5469. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5470. if err != nil {
  5471. br.Msg = "参数解析异常!"
  5472. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5473. return
  5474. }
  5475. resp := new(data_manage.AddEdbInfoResp)
  5476. var edbNames string
  5477. for _, v := range req.BatchList {
  5478. edbNames += "'" + v.EdbName + "',"
  5479. }
  5480. edbNames = strings.Trim(edbNames, ",")
  5481. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  5482. if err != nil {
  5483. br.Msg = "查询指标名称重复错误!"
  5484. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  5485. return
  5486. }
  5487. if len(infoList) > 0 {
  5488. for _, v := range infoList {
  5489. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  5490. }
  5491. br.Data = resp
  5492. br.Msg = "指标名称重复!"
  5493. br.ErrMsg = "指标名称重复"
  5494. return
  5495. }
  5496. for k, v := range req.BatchList {
  5497. v.EdbName = strings.Trim(v.EdbName, " ")
  5498. v.EdbCode = strings.Trim(v.EdbCode, " ")
  5499. v.StockCode = strings.Trim(v.StockCode, " ")
  5500. if v.Source <= 0 {
  5501. br.Msg = "无效的数据来源"
  5502. return
  5503. }
  5504. if v.EdbCode == "" {
  5505. br.Msg = "指标ID不能为空"
  5506. return
  5507. }
  5508. if v.StockCode == "" {
  5509. br.Msg = "证券代码不能为空"
  5510. return
  5511. }
  5512. if v.EdbName == "" {
  5513. br.Msg = "指标名称不能为空"
  5514. return
  5515. }
  5516. if v.Frequency == "" {
  5517. br.Msg = "频率不能为空"
  5518. return
  5519. }
  5520. if v.ClassifyId <= 0 {
  5521. br.Msg = "请选择分类"
  5522. return
  5523. }
  5524. terminalCode, serverUrl, _, e := data.GetEdbTerminalCodeBySource(v.Source, v.EdbCode, v.StockCode)
  5525. if e != nil {
  5526. br.Msg = "获取可以使用的终端地址失败"
  5527. br.ErrMsg = "获取可以使用的终端地址失败,Err:" + e.Error()
  5528. return
  5529. }
  5530. edbInfoItem := new(data_manage.EdbInfo)
  5531. edbInfoItem.Source = v.Source
  5532. switch v.Source {
  5533. case utils.DATA_SOURCE_WIND:
  5534. edbInfoItem.SourceName = "wind"
  5535. edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
  5536. case utils.DATA_SOURCE_THS:
  5537. edbInfoItem.SourceName = "ths"
  5538. edbInfoItem.EdbCode = utils.ThsDs + v.StockCode + v.EdbCode
  5539. }
  5540. edbInfoItem.SubSource = utils.DATA_SUB_SOURCE_DATE
  5541. edbInfoItem.SubSourceName = "日期序列"
  5542. edbInfoItem.EdbName = v.EdbName
  5543. edbInfoItem.EdbNameSource = v.EdbName
  5544. edbInfoItem.EdbNameEn = v.EdbName
  5545. edbInfoItem.Frequency = v.Frequency
  5546. edbInfoItem.Unit = v.Unit
  5547. edbInfoItem.UnitEn = v.Unit
  5548. edbInfoItem.ClassifyId = v.ClassifyId
  5549. edbInfoItem.SysUserId = sysUser.AdminId
  5550. edbInfoItem.SysUserRealName = sysUser.RealName
  5551. edbInfoItem.IndicatorCode = v.EdbCode
  5552. edbInfoItem.StockCode = v.StockCode
  5553. edbInfoItem.TerminalCode = terminalCode
  5554. edbInfoItem.ServerUrl = serverUrl
  5555. var extra data_manage.EdbInfoExtra
  5556. if v.ApiExtraPars != "" {
  5557. extra.ApiExtraPars = v.ApiExtraPars
  5558. b, e := json.Marshal(extra)
  5559. if e != nil {
  5560. br.Msg = "保存失败"
  5561. br.ErrMsg = fmt.Sprintf("额外参数JSON格式化失败, %v", e)
  5562. return
  5563. }
  5564. edbInfoItem.Extra = string(b)
  5565. }
  5566. // 指标入库
  5567. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  5568. if err != nil {
  5569. br.Msg = "保存失败"
  5570. if errMsg != `` {
  5571. br.Msg = errMsg
  5572. }
  5573. br.ErrMsg = err.Error()
  5574. br.IsSendEmail = isSendEmail
  5575. return
  5576. }
  5577. //新增操作日志
  5578. {
  5579. edbLog := new(data_manage.EdbInfoLog)
  5580. edbLog.EdbInfoId = edbInfo.EdbInfoId
  5581. edbLog.SourceName = edbInfo.SourceName
  5582. edbLog.Source = edbInfo.Source
  5583. edbLog.EdbCode = edbInfo.EdbCode
  5584. edbLog.EdbName = edbInfo.EdbName
  5585. edbLog.ClassifyId = edbInfo.ClassifyId
  5586. edbLog.SysUserId = sysUser.AdminId
  5587. edbLog.SysUserRealName = sysUser.RealName
  5588. edbLog.CreateTime = time.Now()
  5589. edbLog.Content = string(this.Ctx.Input.RequestBody)
  5590. edbLog.Status = "新增指标"
  5591. edbLog.Method = this.Ctx.Input.URI()
  5592. go data_manage.AddEdbInfoLog(edbLog)
  5593. }
  5594. if k <= 0 {
  5595. resp.EdbInfoId = edbInfo.EdbInfoId
  5596. resp.UniqueCode = edbInfo.UniqueCode
  5597. }
  5598. }
  5599. // 试用平台更新用户累计新增指标数
  5600. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  5601. if e != nil {
  5602. br.Msg = "操作失败"
  5603. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  5604. return
  5605. }
  5606. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  5607. go func() {
  5608. var r etaTrialService.EtaTrialUserReq
  5609. r.Mobile = adminItem.Mobile
  5610. _, _ = etaTrialService.UpdateUserIndexNum(r)
  5611. }()
  5612. }
  5613. br.Ret = 200
  5614. br.Success = true
  5615. br.Msg = "保存成功"
  5616. br.Data = resp
  5617. br.IsAddLog = true
  5618. }
  5619. // SmmExistCheck
  5620. // @Title 新增指标-检验指标是否存在接口-smm
  5621. // @Description 新增指标-检验指标是否存在接口-smm
  5622. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5623. // @Param EdbCode query string false "指标编码/指标代码"
  5624. // @Param StockCode query string false "证券代码"
  5625. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5626. // @router /edb_info/smm/exist/check [post]
  5627. func (this *EdbInfoController) SmmExistCheck() {
  5628. br := new(models.BaseResponse).Init()
  5629. defer func() {
  5630. this.Data["json"] = br
  5631. this.ServeJSON()
  5632. }()
  5633. var req data_manage.SmmIndexExistCheckReq
  5634. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5635. if err != nil {
  5636. br.Msg = "参数解析异常!"
  5637. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5638. return
  5639. }
  5640. types := req.Types
  5641. frequency := req.Frequency
  5642. dataState := req.DataState
  5643. selectAll := req.SelectAll
  5644. keyword := req.Keyword
  5645. edbCode := req.EdbCode
  5646. edbCode = strings.Trim(edbCode, "\t")
  5647. edbCode = strings.Trim(edbCode, " ")
  5648. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5649. var edbCodeArr []string
  5650. var codeArr []string
  5651. if selectAll {
  5652. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5653. var condition string
  5654. var pars []interface{}
  5655. if len(types) > 0 {
  5656. condition += " AND ( "
  5657. for _, v := range types {
  5658. typeArr := strings.Split(v, ",")
  5659. for i, v := range typeArr {
  5660. if i == 0 {
  5661. condition += " ( "
  5662. }
  5663. typeStr := "type_"
  5664. typeStr += fmt.Sprintf("%d", i+1)
  5665. condition += typeStr + " =? "
  5666. pars = append(pars, v)
  5667. if i == len(typeArr)-1 {
  5668. condition += " ) "
  5669. } else {
  5670. condition += " AND "
  5671. }
  5672. }
  5673. condition += " OR "
  5674. }
  5675. condition = strings.Trim(condition, "OR ")
  5676. condition += " ) "
  5677. }
  5678. if frequency != "" {
  5679. frequencyArr := strings.Split(frequency, ",")
  5680. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5681. pars = append(pars, frequencyArr)
  5682. }
  5683. if dataState != "" {
  5684. stateArr := strings.Split(dataState, ",")
  5685. if strings.Contains(dataState, "normal") {
  5686. stateArr = append(stateArr, "")
  5687. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5688. pars = append(pars, stateArr)
  5689. } else {
  5690. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5691. pars = append(pars, stateArr)
  5692. }
  5693. }
  5694. if keyword != "" {
  5695. keyWordArr := strings.Split(keyword, " ")
  5696. if len(keyWordArr) > 0 {
  5697. condition += " AND ( "
  5698. for _, v := range keyWordArr {
  5699. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5700. }
  5701. condition = strings.TrimRight(condition, "OR")
  5702. condition += " ) "
  5703. }
  5704. }
  5705. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5706. if err != nil {
  5707. br.Msg = "获取指标列表失败"
  5708. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5709. return
  5710. }
  5711. for _, v := range indexList {
  5712. codeArr = append(codeArr, v.IndexCode)
  5713. }
  5714. noUseCodeArr := strings.Split(edbCode, ",")
  5715. for _, code := range codeArr {
  5716. // 检查code是否在noUseCodeArr数组中
  5717. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5718. // 如果不在,将其添加到结果数组中
  5719. edbCodeArr = append(edbCodeArr, code)
  5720. }
  5721. }
  5722. } else {
  5723. //未勾选全选EdbCode就是需要的code
  5724. edbCodeArr = strings.Split(edbCode, ",")
  5725. }
  5726. if len(edbCodeArr) > 30 {
  5727. br.Msg = "最多只能选择30个指标"
  5728. return
  5729. }
  5730. if len(edbCodeArr) <= 0 {
  5731. br.Msg = "无符合指标或指标代码错误"
  5732. return
  5733. }
  5734. indexList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_YS, edbCodeArr)
  5735. if err != nil && err.Error() != utils.ErrNoRow() {
  5736. br.Msg = "校验指标是否存在失败"
  5737. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5738. return
  5739. }
  5740. var existEdbCodeArr []string
  5741. var existClassifyId []int
  5742. var existIndexId []int
  5743. for _, indexItem := range indexList {
  5744. for _, ev := range edbCodeArr {
  5745. if strings.Contains(indexItem.EdbCode, ev) {
  5746. existEdbCodeArr = append(existEdbCodeArr, ev)
  5747. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5748. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5749. }
  5750. }
  5751. }
  5752. resp := new(data_manage.EdbInfoSmmExistCheckResp)
  5753. if len(indexList) > 0 {
  5754. resp.IndexExist = true
  5755. }
  5756. if len(existEdbCodeArr) == len(edbCodeArr) {
  5757. resp.ExistAll = true
  5758. }
  5759. resp.ExistEdbCodeArr = existEdbCodeArr
  5760. resp.ExistClassifyId = existClassifyId
  5761. resp.ExistIndexId = existIndexId
  5762. resp.ExistEdbInfo = indexList
  5763. br.Ret = 200
  5764. br.Success = true
  5765. br.Msg = "获取成功"
  5766. br.Data = resp
  5767. }
  5768. // EdbInfoSearch
  5769. // @Title 新增指标-查询指标信息接口-smm
  5770. // @Description 新增指标-查询指标信息接口-smm
  5771. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  5772. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5773. // @Param EdbCode query string false "指标编码/指标代码"
  5774. // @Param StockCode query string false "证券代码"
  5775. // @Success 200 {object} data_manage.EdbInfoSearchResp
  5776. // @router /edb_info/smm/search [post]
  5777. func (this *EdbInfoController) EdbInfoSmmSearch() {
  5778. br := new(models.BaseResponse).Init()
  5779. defer func() {
  5780. this.Data["json"] = br
  5781. this.ServeJSON()
  5782. }()
  5783. var req data_manage.SmmIndexExistCheckReq
  5784. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5785. if err != nil {
  5786. br.Msg = "参数解析异常!"
  5787. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5788. return
  5789. }
  5790. types := req.Types
  5791. frequency := req.Frequency
  5792. dataState := req.DataState
  5793. selectAll := req.SelectAll
  5794. keyword := req.Keyword
  5795. edbCode := req.EdbCode
  5796. edbCode = strings.Trim(edbCode, "\t")
  5797. edbCode = strings.Trim(edbCode, " ")
  5798. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5799. var edbCodeArr []string
  5800. var codeArr []string
  5801. if selectAll {
  5802. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5803. var condition string
  5804. var pars []interface{}
  5805. if len(types) > 0 {
  5806. condition += " AND ( "
  5807. for _, v := range types {
  5808. typeArr := strings.Split(v, ",")
  5809. for i, v := range typeArr {
  5810. if i == 0 {
  5811. condition += " ( "
  5812. }
  5813. typeStr := "type_"
  5814. typeStr += fmt.Sprintf("%d", i+1)
  5815. condition += typeStr + " =? "
  5816. pars = append(pars, v)
  5817. if i == len(typeArr)-1 {
  5818. condition += " ) "
  5819. } else {
  5820. condition += " AND "
  5821. }
  5822. }
  5823. condition += " OR "
  5824. }
  5825. condition = strings.Trim(condition, "OR ")
  5826. condition += " ) "
  5827. }
  5828. if frequency != "" {
  5829. frequencyArr := strings.Split(frequency, ",")
  5830. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5831. pars = append(pars, frequencyArr)
  5832. }
  5833. if dataState != "" {
  5834. stateArr := strings.Split(dataState, ",")
  5835. if strings.Contains(dataState, "normal") {
  5836. stateArr = append(stateArr, "")
  5837. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5838. pars = append(pars, stateArr)
  5839. } else {
  5840. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5841. pars = append(pars, stateArr)
  5842. }
  5843. }
  5844. if keyword != "" {
  5845. keyWordArr := strings.Split(keyword, " ")
  5846. if len(keyWordArr) > 0 {
  5847. condition += " AND ( "
  5848. for _, v := range keyWordArr {
  5849. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5850. }
  5851. condition = strings.TrimRight(condition, "OR")
  5852. condition += " ) "
  5853. }
  5854. }
  5855. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5856. if err != nil {
  5857. br.Msg = "获取指标列表失败"
  5858. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5859. return
  5860. }
  5861. for _, v := range indexList {
  5862. codeArr = append(codeArr, v.IndexCode)
  5863. }
  5864. noUseCodeArr := strings.Split(edbCode, ",")
  5865. for _, code := range codeArr {
  5866. // 检查code是否在noUseCodeArr数组中
  5867. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5868. // 如果不在,将其添加到结果数组中
  5869. edbCodeArr = append(edbCodeArr, code)
  5870. }
  5871. }
  5872. } else {
  5873. //未勾选全选EdbCode就是需要的code
  5874. edbCodeArr = strings.Split(edbCode, ",")
  5875. }
  5876. if len(edbCodeArr) > 30 {
  5877. br.Msg = "最多只能选择30个指标"
  5878. return
  5879. }
  5880. if len(edbCodeArr) <= 0 {
  5881. br.Msg = "无符合指标或指标代码错误"
  5882. return
  5883. }
  5884. edbCodeStr := ""
  5885. for i, _ := range edbCodeArr {
  5886. edbCodeStr += "'" + edbCodeArr[i] + "'" + ","
  5887. }
  5888. edbCodeStr = strings.Trim(edbCodeStr, ",")
  5889. smmInfoList, err := data_manage.GetBaseFromSmmIndexByIndexCodes(edbCodeStr)
  5890. if err != nil && err.Error() != utils.ErrNoRow() {
  5891. br.Msg = "获取失败"
  5892. br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
  5893. return
  5894. }
  5895. smmInfoMap := make(map[string]*data_manage.BaseFromSmmIndex)
  5896. for _, v := range smmInfoList {
  5897. smmInfoMap[v.IndexCode] = v
  5898. }
  5899. searchItemList := make([]*data_manage.EdbInfoSearch, 0)
  5900. resp := new(data_manage.EdbInfoSearchResp)
  5901. needAddCodeArr := make([]string, 0)
  5902. noNeedAddCodeMap := make(map[string]string, 0)
  5903. for _, edbCode := range edbCodeArr {
  5904. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  5905. if err != nil && err.Error() != utils.ErrNoRow() {
  5906. br.Msg = "获取失败"
  5907. br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
  5908. return
  5909. }
  5910. fmt.Println("dataItems:", len(dataItems))
  5911. if len(dataItems) > 0 {
  5912. searchItem := new(data_manage.EdbInfoSearch)
  5913. searchItem.EdbCode = edbCode
  5914. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  5915. if err != nil {
  5916. br.Msg = "获取失败"
  5917. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  5918. return
  5919. }
  5920. searchItem.DataList = dataItems
  5921. searchItem.StartDate = minDate
  5922. searchItem.EndDate = maxDate
  5923. searchItem.Frequency = smmInfoMap[edbCode].Frequency
  5924. searchItem.Unit = smmInfoMap[edbCode].Unit
  5925. searchItem.EdbName = smmInfoMap[edbCode].IndexName
  5926. searchItem.EdbCode = smmInfoMap[edbCode].IndexCode
  5927. searchItemList = append(searchItemList, searchItem)
  5928. noNeedAddCodeMap[edbCode] = edbCode
  5929. } else {
  5930. // 把需要新加的code添加到needAddCodeArr数组中,一起批量请求
  5931. needAddCodeArr = append(needAddCodeArr, edbCode)
  5932. }
  5933. }
  5934. if len(needAddCodeArr) > 0 {
  5935. edbCode = strings.Join(needAddCodeArr, ",")
  5936. respItem, err := data.AddEdbData(utils.DATA_SOURCE_YS, edbCode, "")
  5937. if err != nil {
  5938. br.Msg = "获取失败"
  5939. br.ErrMsg = "获取失败,Err:" + err.Error()
  5940. return
  5941. }
  5942. if respItem.Ret != 200 {
  5943. if respItem.Ret == 421 {
  5944. br.Msg = "该渠道已超过添加上限"
  5945. } else if respItem.Ret == 4052 {
  5946. br.Msg = "该指标已下架"
  5947. } else {
  5948. br.Msg = "未搜索到该指标"
  5949. }
  5950. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  5951. return
  5952. }
  5953. }
  5954. for _, smmInfo := range smmInfoList {
  5955. if smmInfo != nil {
  5956. if _, ok := noNeedAddCodeMap[smmInfo.IndexCode]; !ok {
  5957. searchItem := new(data_manage.EdbInfoSearch)
  5958. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(smmInfo.IndexCode)
  5959. if err != nil {
  5960. br.Msg = "获取失败"
  5961. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  5962. return
  5963. }
  5964. searchItem.StartDate = minDate
  5965. searchItem.EndDate = maxDate
  5966. searchItem.Frequency = smmInfo.Frequency
  5967. searchItem.Unit = smmInfo.Unit
  5968. searchItem.EdbName = smmInfo.IndexName
  5969. searchItem.EdbCode = smmInfo.IndexCode
  5970. dataList, err := data_manage.GetEdbDataAllByEdbCode(smmInfo.IndexCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  5971. if err != nil && err.Error() != utils.ErrNoRow() {
  5972. br.Msg = "获取失败"
  5973. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  5974. return
  5975. }
  5976. searchItem.DataList = dataList
  5977. searchItemList = append(searchItemList, searchItem)
  5978. }
  5979. }
  5980. }
  5981. resp.Status = 2
  5982. resp.StockSearchList = searchItemList
  5983. br.Ret = 200
  5984. br.Success = true
  5985. br.Msg = "获取成功"
  5986. br.Data = resp
  5987. }
  5988. // SmmEdbInfoBatchAdd
  5989. // @Title 指标批量保存接口-smm
  5990. // @Description 指标批量保存接口-smm
  5991. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  5992. // @Success Ret=200 保存成功
  5993. // @router /edb_info/smm/batch/add [post]
  5994. func (this *EdbInfoController) SmmEdbInfoBatchAdd() {
  5995. br := new(models.BaseResponse).Init()
  5996. defer func() {
  5997. this.Data["json"] = br
  5998. this.ServeJSON()
  5999. }()
  6000. sysUser := this.SysUser
  6001. if sysUser == nil {
  6002. br.Msg = "请登录"
  6003. br.ErrMsg = "请登录,SysUser Is Empty"
  6004. br.Ret = 408
  6005. return
  6006. }
  6007. deleteCache := true
  6008. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  6009. defer func() {
  6010. if deleteCache {
  6011. utils.Rc.Delete(cacheKey)
  6012. }
  6013. }()
  6014. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  6015. deleteCache = false
  6016. br.Msg = "系统处理中,请稍后重试!"
  6017. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  6018. return
  6019. }
  6020. var req data_manage.BatchAddEdbInfoReq
  6021. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  6022. if err != nil {
  6023. br.Msg = "参数解析异常!"
  6024. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  6025. return
  6026. }
  6027. resp := new(data_manage.AddEdbInfoResp)
  6028. var edbNames string
  6029. for _, v := range req.BatchList {
  6030. edbNames += "'" + v.EdbName + "',"
  6031. }
  6032. edbNames = strings.Trim(edbNames, ",")
  6033. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  6034. if err != nil {
  6035. br.Msg = "查询指标名称重复错误!"
  6036. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  6037. return
  6038. }
  6039. if len(infoList) > 0 {
  6040. for _, v := range infoList {
  6041. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  6042. }
  6043. br.Data = resp
  6044. br.Msg = "指标名称重复!"
  6045. br.ErrMsg = "指标名称重复"
  6046. return
  6047. }
  6048. for k, v := range req.BatchList {
  6049. v.EdbName = strings.Trim(v.EdbName, " ")
  6050. v.EdbCode = strings.Trim(v.EdbCode, " ")
  6051. if v.Source <= 0 {
  6052. br.Msg = "无效的数据来源"
  6053. return
  6054. }
  6055. if v.EdbCode == "" {
  6056. br.Msg = "指标ID不能为空"
  6057. return
  6058. }
  6059. if v.EdbName == "" {
  6060. br.Msg = "指标名称不能为空"
  6061. return
  6062. }
  6063. if v.Frequency == "" {
  6064. br.Msg = "频率不能为空"
  6065. return
  6066. }
  6067. if v.ClassifyId <= 0 {
  6068. br.Msg = "请选择分类"
  6069. return
  6070. }
  6071. edbInfoItem := new(data_manage.EdbInfo)
  6072. edbInfoItem.Source = v.Source
  6073. edbInfoItem.SourceName = "SMM"
  6074. edbInfoItem.EdbCode = v.EdbCode
  6075. edbInfoItem.SubSource = 0
  6076. edbInfoItem.SubSourceName = ""
  6077. edbInfoItem.EdbName = v.EdbName
  6078. edbInfoItem.EdbNameSource = v.EdbName
  6079. edbInfoItem.EdbNameEn = v.EdbName
  6080. edbInfoItem.Frequency = v.Frequency
  6081. edbInfoItem.Unit = v.Unit
  6082. edbInfoItem.UnitEn = v.Unit
  6083. edbInfoItem.ClassifyId = v.ClassifyId
  6084. edbInfoItem.SysUserId = sysUser.AdminId
  6085. edbInfoItem.SysUserRealName = sysUser.RealName
  6086. edbInfoItem.IndicatorCode = ""
  6087. edbInfoItem.StockCode = ""
  6088. // 指标入库
  6089. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  6090. if err != nil {
  6091. br.Msg = "保存失败"
  6092. if errMsg != `` {
  6093. br.Msg = errMsg
  6094. }
  6095. br.ErrMsg = err.Error()
  6096. br.IsSendEmail = isSendEmail
  6097. return
  6098. }
  6099. //新增操作日志
  6100. {
  6101. edbLog := new(data_manage.EdbInfoLog)
  6102. edbLog.EdbInfoId = edbInfo.EdbInfoId
  6103. edbLog.SourceName = edbInfo.SourceName
  6104. edbLog.Source = edbInfo.Source
  6105. edbLog.EdbCode = edbInfo.EdbCode
  6106. edbLog.EdbName = edbInfo.EdbName
  6107. edbLog.ClassifyId = edbInfo.ClassifyId
  6108. edbLog.SysUserId = sysUser.AdminId
  6109. edbLog.SysUserRealName = sysUser.RealName
  6110. edbLog.CreateTime = time.Now()
  6111. edbLog.Content = string(this.Ctx.Input.RequestBody)
  6112. edbLog.Status = "新增指标"
  6113. edbLog.Method = this.Ctx.Input.URI()
  6114. go data_manage.AddEdbInfoLog(edbLog)
  6115. }
  6116. if k <= 0 {
  6117. resp.EdbInfoId = edbInfo.EdbInfoId
  6118. resp.UniqueCode = edbInfo.UniqueCode
  6119. }
  6120. }
  6121. br.Ret = 200
  6122. br.Success = true
  6123. br.Msg = "保存成功"
  6124. br.Data = resp
  6125. br.IsAddLog = true
  6126. }
  6127. // ChartImageSetBySvg
  6128. // @Title 设置指标的图表图片
  6129. // @Description 设置指标的图表图片接口
  6130. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  6131. // @Success Ret=200 保存成功
  6132. // @router /edb_info/image/set_by_svg [post]
  6133. func (this *EdbInfoController) ChartImageSetBySvg() {
  6134. br := new(models.BaseResponse).Init()
  6135. defer func() {
  6136. if br.ErrMsg == "" {
  6137. br.IsSendEmail = false
  6138. }
  6139. this.Data["json"] = br
  6140. this.ServeJSON()
  6141. }()
  6142. sysUser := this.SysUser
  6143. if sysUser == nil {
  6144. br.Msg = "请登录"
  6145. br.ErrMsg = "请登录,SysUser Is Empty"
  6146. br.Ret = 408
  6147. return
  6148. }
  6149. imgData := this.GetString("Img")
  6150. if imgData == "" {
  6151. br.Msg = "图片参数错误"
  6152. br.ErrMsg = "图片参数错误,Img Is Empty"
  6153. return
  6154. }
  6155. edbInfoId, _ := this.GetInt("EdbInfoId", 0)
  6156. if edbInfoId <= 0 {
  6157. br.Msg = "指标参数错误"
  6158. br.ErrMsg = "指标参数错误,EdbInfoId Is Empty"
  6159. return
  6160. }
  6161. // 通过svg图片生成图片资源地址
  6162. resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData)
  6163. if err != nil {
  6164. br.Msg = errMsg
  6165. br.ErrMsg = err.Error()
  6166. return
  6167. }
  6168. if edbInfoId <= 0 || resourceUrl == "" {
  6169. br.Ret = 200
  6170. br.Success = true
  6171. br.Msg = "保存成功"
  6172. return
  6173. }
  6174. edbInfo, e := data_manage.GetEdbInfoById(edbInfoId)
  6175. if e != nil {
  6176. if e.Error() == utils.ErrNoRow() {
  6177. br.Msg = "找不到该指标"
  6178. return
  6179. }
  6180. br.Msg = "保存失败"
  6181. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  6182. return
  6183. }
  6184. edbInfo.ChartImage = resourceUrl
  6185. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  6186. br.Msg = "保存失败"
  6187. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  6188. return
  6189. }
  6190. // 修改es数据
  6191. go data.AddOrEditEdbInfoToEs(edbInfoId)
  6192. br.Ret = 200
  6193. br.Success = true
  6194. br.Msg = "保存成功"
  6195. }