edb_info.go 196 KB

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