1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/company"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_manage/cross_variety"
- request2 "eta/eta_api/models/data_manage/excel/request"
- "eta/eta_api/models/data_manage/request"
- "eta/eta_api/models/data_manage/response"
- "eta/eta_api/models/system"
- "eta/eta_api/services"
- "eta/eta_api/services/alarm_msg"
- "eta/eta_api/services/data"
- "eta/eta_api/services/data/data_manage_permission"
- excel2 "eta/eta_api/services/data/excel"
- "eta/eta_api/services/data_stat"
- "eta/eta_api/services/elastic"
- etaTrialService "eta/eta_api/services/eta_trial"
- "eta/eta_api/utils"
- "fmt"
- "strconv"
- "strings"
- "sync"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // EdbInfoController 数据管理
- type EdbInfoController struct {
- controllers.BaseAuthController
- }
- // EdbInfoSearch
- // @Title 新增指标-查询指标信息接口
- // @Description 新增指标-查询指标信息接口
- // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
- // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
- // @Param EdbCode query string false "指标编码/指标代码"
- // @Param StockCode query string false "证券代码"
- // @Param Frequency query string false "频度"
- // @Success 200 {object} data_manage.EdbInfoSearchResp
- // @router /edb_info/search [get]
- func (this *EdbInfoController) EdbInfoSearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source, _ := this.GetInt("Source")
- edbCode := this.GetString("EdbCode")
- edbCode = strings.Trim(edbCode, "\t")
- edbCode = strings.Trim(edbCode, " ")
- edbCode = strings.Replace(edbCode, "\t", "", -1)
- subSource, _ := this.GetInt("SubSource")
- stockCode := this.GetString("StockCode")
- frequency := this.GetString("Frequency")
- extraPars := this.GetString("ExtraPars")
- extraPars = strings.TrimSpace(extraPars)
- if source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- if edbCode == "" {
- br.Msg = "请输入指标ID"
- return
- }
- //如果是彭博财务指标,那么需要传入客户code
- if source == utils.DATA_SOURCE_PB_FINANCE {
- companyCode := this.GetString("CompanyCode")
- companyCode = strings.Trim(companyCode, "\t")
- companyCode = strings.Trim(companyCode, " ")
- companyCode = strings.Replace(companyCode, "\t", "", -1)
- // 如果财务数据,那么需要拼接上客户code
- edbCode = companyCode + "&&" + edbCode
- }
- resp := new(data_manage.EdbInfoSearchResp)
- //判断指标是否存在
- var item *data_manage.EdbInfo
- var err error
- if source == utils.DATA_SOURCE_GL {
- // 如果是钢联的话,那么就先判断是不是存在钢联化工
- item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, edbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- err = nil
- if item != nil {
- source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- } else {
- // 判断是不是已经在钢联这边已经存在了
- item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_GL, edbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- err = nil
- // 如果在钢联来源也没找到,那么就需要再判断下是否处于 《钢联化工》 数据源里面
- if item == nil {
- tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- err = nil
- if tmpInfo != nil {
- source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- }
- }
- }
- }
- if item == nil {
- item, err = data_manage.GetEdbInfoByEdbCode(source, edbCode)
- }
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- var isAdd bool
- var isInEdb bool //是否在指标库中
- if item != nil && item.EdbInfoId > 0 {
- isInEdb = true //在指标库中
- resp.Status = 1
- searchItem := new(data_manage.EdbInfoSearch)
- searchItem.EdbCode = item.EdbCode
- searchItem.StartDate = item.StartDate
- searchItem.EndDate = item.EndDate
- searchItem.EdbName = item.EdbName
- resp.SearchItem = searchItem
- //查询目录
- resultList, _ := data_manage.GetClassifyAllByClassifyId(item.ClassifyId)
- resp.ClassifyList = resultList
- // 查询该指标是否有权限
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, item.EdbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
- return
- }
- if conf != nil {
- resp.Status = 3
- }
- } else {
- //dateNow := time.Now()
- //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDate)
- searchItem := new(data_manage.EdbInfoSearch)
- if source == utils.DATA_SOURCE_THS {
- fmt.Println("subSource:", subSource)
- if subSource == utils.DATA_SUB_SOURCE_EDB {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("ths len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("ths data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data.GetEdbDataByThs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if subSource == utils.DATA_SUB_SOURCE_DATE {
- if stockCode == "" {
- br.Msg = "请输入证券代码"
- return
- }
- if edbCode == "" {
- br.Msg = "请输入指标代码"
- return
- }
- respItem, err := data.AddEdbDataThsDs(source, stockCode, edbCode, extraPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- if respItem.Ret == 421 {
- br.Msg = "该渠道已超过添加上限"
- } else if respItem.Ret == 4052 {
- br.Msg = "该指标已下架"
- } else {
- br.Msg = "未搜索到该指标"
- }
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- } else {
- br.Msg = "无效的渠道来源"
- return
- }
- } else if source == utils.DATA_SOURCE_WIND {
- fmt.Println("subSource:", subSource)
- if subSource == utils.DATA_SUB_SOURCE_EDB {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_WIND, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Wind已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("wind dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataWindMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取wind日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.Format(utils.FormatDate)
- //searchItem, err = data.GetEdbDataByWind(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "wind 获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- if respItem.Ret == 421 {
- br.Msg = "该渠道已超过添加上限"
- } else if respItem.Ret == 4052 {
- br.Msg = "该指标已下架"
- } else {
- br.Msg = "未搜索到该指标"
- }
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if subSource == utils.DATA_SUB_SOURCE_DATE {
- if stockCode == "" {
- br.Msg = "请输入证券代码"
- return
- }
- if edbCode == "" {
- br.Msg = "请输入指标代码"
- return
- }
- respItem, err := data.AddEdbDataWindWsd(source, stockCode, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- if respItem.Ret == 421 {
- br.Msg = "该渠道已超过添加上限"
- } else if respItem.Ret == 4052 {
- br.Msg = "该指标已下架"
- } else {
- br.Msg = "未搜索到该指标"
- }
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- } else {
- br.Msg = "无效的渠道来源"
- return
- }
- } else if source == utils.DATA_SOURCE_PB || source == utils.DATA_SOURCE_PB_FINANCE {
- fmt.Println("pb data exist")
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Pb已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("pb dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Pb日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDateUnSpace)
- //searchItem, err = data.GetEdbDataByPb(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "彭博数据获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_MANUAL { //手工数据指标
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_MANUAL, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("ths len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("ths data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataManualMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByManual(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- manualInfo, err := models.GetEdbinfoByTradeCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
- return
- }
- if manualInfo != nil {
- searchItem.Frequency = manualInfo.Frequency
- searchItem.Unit = manualInfo.Unit
- searchItem.EdbName = manualInfo.SecName
- }
- } else if source == utils.DATA_SOURCE_LZ {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LZ, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("ths len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("ths data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataLzMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByLz(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取隆众数据失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- lzInfo, err := data_manage.GetLongzhongSurveyProductByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
- return
- }
- if lzInfo != nil {
- frequency := lzInfo.Frequency
- var frequencyStr string
- if frequency == 1 {
- frequencyStr = "日度"
- } else if frequency == 2 {
- frequencyStr = "周度"
- } else if frequency == 3 {
- frequencyStr = "月度"
- } else if frequency == 4 {
- frequencyStr = "季度"
- } else if frequency == 5 {
- frequencyStr = "年度"
- } else if frequency == 99 {
- frequencyStr = "无固定频率"
- }
- searchItem.Frequency = frequencyStr
- searchItem.Unit = lzInfo.UnitName
- searchItem.EdbName = lzInfo.SampleName + lzInfo.BreedName + lzInfo.QuotaName
- }
- } else if source == utils.DATA_SOURCE_YS { //有色网
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- smmInfo, err := data_manage.GetBaseFromSmmIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
- return
- }
- if smmInfo != nil {
- searchItem.Frequency = smmInfo.Frequency
- searchItem.Unit = smmInfo.Unit
- searchItem.EdbName = smmInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_GL { //钢联
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataGlMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- glInfo, err := data_manage.GetGlIndexByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if glInfo != nil {
- searchItem.Frequency = glInfo.FrequencyName
- searchItem.Unit = glInfo.UnitName
- searchItem.EdbName = glInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_ZZ { //郑商所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取郑商所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取郑商所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByZz(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByZz Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromZhengzhouByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取郑商所指标详情失败,Err:" + err.Error()
- return
- }
- var zzInfo *data_manage.BaseInfoFromZz
- if allInfo != nil {
- zzInfo = allInfo[0]
- }
- if zzInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = zzInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = zzInfo.BuyName
- } else {
- searchItem.EdbName = zzInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_DL { //大商所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取大商所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取大商所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByDl(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByDl Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromDalianByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取大商所指标详情失败,Err:" + err.Error()
- return
- }
- var dlInfo *data_manage.BaseInfoFromDl
- if allInfo != nil {
- dlInfo = allInfo[0]
- }
- if dlInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = dlInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = dlInfo.BuyName
- } else {
- searchItem.EdbName = dlInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_SH { //上期所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataBySh(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataBySh Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromShByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- var shInfo *data_manage.BaseInfoFromSh
- if allInfo != nil {
- shInfo = allInfo[0]
- }
- if shInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = shInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = shInfo.BuyName
- } else {
- searchItem.EdbName = shInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_CFFEX { //中金所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中金所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中金所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromCffexByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中金所指标详情失败,Err:" + err.Error()
- return
- }
- var cffexInfo *data_manage.BaseInfoFromCffex
- if allInfo != nil {
- cffexInfo = allInfo[0]
- }
- if cffexInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = cffexInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = cffexInfo.BuyName
- } else {
- searchItem.EdbName = cffexInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_SHFE { //上期能源
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期能源已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期能源日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByShfe(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByShfe Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromShfeByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期能源指标详情失败,Err:" + err.Error()
- return
- }
- var shfeInfo *data_manage.BaseInfoFromShfe
- if allInfo != nil {
- shfeInfo = allInfo[0]
- }
- if shfeInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = shfeInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = shfeInfo.BuyName
- } else {
- searchItem.EdbName = shfeInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_GIE { //欧洲天然气
- var suffix string
- l := len(edbCode)
- if strings.Contains(edbCode[l-2:], "GS") {
- suffix = "GS"
- } else if strings.Contains(edbCode[l-2:], "CF") {
- suffix = "CF"
- } else if strings.Contains(edbCode[l-1:], "T") {
- suffix = "T"
- } else if strings.Contains(edbCode[l-2:], "In") {
- suffix = "In"
- } else if strings.Contains(edbCode[l-3:], "Out") {
- suffix = "Out"
- } else if strings.Contains(edbCode[l-3:], "WGV") {
- suffix = "WGV"
- } else if strings.Contains(edbCode[l-2:], "IC") {
- suffix = "IC"
- } else if strings.Contains(edbCode[l-2:], "WC") {
- suffix = "WC"
- } else if strings.Contains(edbCode[l-1:], "F") {
- suffix = "F"
- } else if strings.Contains(edbCode[l-1:], "C") {
- suffix = "C"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取欧洲天然气已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取欧洲天然气日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByGie(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByGie Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseFromEicDataAllByIndexCodeV2(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取欧洲天然气指标详情失败,Err:" + err.Error()
- return
- }
- var eicInfo *data_manage.BaseFromTradeEicIndexV2
- if allInfo != nil {
- eicInfo = allInfo[0]
- }
- var name string
- if eicInfo != nil {
- searchItem.Frequency = "日度"
- if suffix == "GS" {
- name = eicInfo.Name + "_gas_in_storage"
- searchItem.EdbName = name
- searchItem.Unit = "TWh"
- } else if suffix == "C" {
- name = eicInfo.Name + "_consumption"
- searchItem.EdbName = name
- searchItem.Unit = "TWh"
- } else if suffix == "CF" {
- name = eicInfo.Name + "_consumption_full"
- searchItem.EdbName = name
- searchItem.Unit = "百分比"
- } else if suffix == "F" {
- name = eicInfo.Name + "_full"
- searchItem.EdbName = name
- searchItem.Unit = "百分比"
- } else if suffix == "T" {
- name = eicInfo.Name + "_trend"
- searchItem.EdbName = name
- searchItem.Unit = "百分比"
- } else if suffix == "In" {
- name = eicInfo.Name + "_injection"
- searchItem.EdbName = name
- searchItem.Unit = "GWH/d"
- } else if suffix == "Out" {
- name = eicInfo.Name + "_withdrawal"
- searchItem.EdbName = name
- searchItem.Unit = "GWH/d"
- } else if suffix == "WGV" {
- name = eicInfo.Name + "_working_gas_volume"
- searchItem.EdbName = name
- searchItem.Unit = "TWh"
- } else if suffix == "IC" {
- name = eicInfo.Name + "_injection_capacity"
- searchItem.EdbName = name
- searchItem.Unit = "GWh/d"
- } else if suffix == "WC" {
- name = eicInfo.Name + "_withdrawal_capacity"
- searchItem.EdbName = name
- searchItem.Unit = "GWh/d"
- }
- }
- } else if source == utils.DATA_SOURCE_LT {
- fmt.Println("lt data exist")
- if strings.Contains(edbCode, "=") {
- br.Msg = "暂不支持编码中含有=的指标"
- br.ErrMsg = "暂不支持编码中含有=的指标"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LT, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取 lt 已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("lt dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取lt日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
- searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
- } else {
- //endDate := dateNow.Format(utils.FormatDate)
- //searchItem, err = data.GetEdbDataByLt(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "lt 获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_COAL { //中国煤炭市场网
- var suffix string
- if strings.Contains(edbCode, "jsm") {
- suffix = "jsm_index"
- } else if strings.Contains(edbCode, "company") {
- suffix = "company_index"
- } else if strings.Contains(edbCode, "firm") {
- suffix = "firm_index"
- } else if strings.Contains(edbCode, "coastal") {
- suffix = "coastal_index"
- } else if strings.Contains(edbCode, "inland") {
- suffix = "inland_index"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataCoalMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromCoalByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网指标详情失败,Err:" + err.Error()
- return
- }
- var coalInfo *data_manage.BaseInfoFromCoal
- if allInfo != nil {
- coalInfo = allInfo[0]
- }
- if coalInfo != nil {
- searchItem.Frequency = coalInfo.Frequency
- searchItem.Unit = coalInfo.Unit
- searchItem.EdbName = coalInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_GOOGLE_TRAVEL { //谷歌出行数据
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
- return
- }
- if item != nil {
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- }
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL { //钢联化工
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataMysteelChemicalMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- glInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if glInfo != nil {
- searchItem.Frequency = glInfo.Frequency
- searchItem.Unit = glInfo.Unit
- searchItem.EdbName = glInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_EIA_STEO { //eia steo报告
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取eia steo日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- eiasteoInfo, err := data_manage.GetBaseFromEiaSteoIndexByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if eiasteoInfo != nil {
- searchItem.Frequency = eiasteoInfo.Frequency
- searchItem.Unit = eiasteoInfo.Unit
- searchItem.EdbName = eiasteoInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_COM_TRADE { // un数据源
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取联合国商品贸易数据已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取联合国商品贸易数据日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- eiasteoInfo, err := data_manage.GetComTradeIndex(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if eiasteoInfo != nil {
- //eiasteoInfo.
- if eiasteoInfo.Type <= 2 {
- searchItem.Frequency = `年度`
- } else {
- searchItem.Frequency = `月度`
- }
- if eiasteoInfo.Type == 1 || eiasteoInfo.Type == 3 {
- searchItem.Unit = "美元"
- } else {
- searchItem.Unit = "千克"
- }
- searchItem.EdbName = eiasteoInfo.Name
- }
- } else if source == utils.DATA_SOURCE_SCI { //卓创数据(红桃三)
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCI已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataSciMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCI日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- smmInfo, err := data_manage.GetBaseFromSciIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Sci指标详情失败,Err:" + err.Error()
- return
- }
- if smmInfo != nil {
- searchItem.Frequency = smmInfo.Frequency
- searchItem.Unit = smmInfo.Unit
- searchItem.EdbName = smmInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_BAIINFO { //百川盈孚
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取BAIINFO已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataBaiinfoMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取BAIINFO日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- baiInfo, err := data_manage.GetBaseFromBaiinfoIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Baiinfo指标详情失败,Err:" + err.Error()
- return
- }
- if baiInfo != nil {
- searchItem.Frequency = baiInfo.Frequency
- searchItem.Unit = baiInfo.Unit
- searchItem.EdbName = baiInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_NATIONAL_STATISTICS { // 国家统计局
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取国家统计局已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取国家统计局日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- nationalInfo, err := data_manage.GetBaseFromNationalStatisticsIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取国家统计局详情失败,Err:" + err.Error()
- return
- }
- if nationalInfo != nil {
- searchItem.Frequency = nationalInfo.Frequency
- searchItem.Unit = nationalInfo.Unit
- searchItem.EdbName = fmt.Sprintf("%s%s", nationalInfo.Reg, nationalInfo.IndexName)
- }
- } else if source == utils.DATA_SOURCE_FUBAO { //数宝
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_FUBAO, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Fubao已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("fubao len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("fubao data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataFubaoMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败," + respItem.Msg
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标," + respItem.Msg
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_GFEX { //广州期货交易所
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataGzMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- indexInfo, err := data_manage.GetBaseInfoFromGzByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- if indexInfo != nil {
- searchItem.Frequency = indexInfo.Frequency
- searchItem.Unit = indexInfo.Unit
- searchItem.EdbName = indexInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_ICPI { //消费者指数
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataIcpiMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- indexInfo, err := data_manage.GetBaseInfoFromIcpiByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- if indexInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "%"
- searchItem.EdbName = indexInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_BUSINESS { //自有数据
- indexObj := data_manage.BaseFromBusinessIndex{}
- indexInfo, err := indexObj.GetDetailByEdbCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取自有数据指标信息失败,Err:" + err.Error()
- return
- }
- _, tmpDataList, err := data.GetPageBaseBusinessIndexData(edbCode, 1, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取自有数据已存在信息失败,Err:" + err.Error()
- return
- }
- dataItems := make([]*data_manage.EdbInfoSearchData, 0)
- for _, v := range tmpDataList {
- dataItems = append(dataItems, &data_manage.EdbInfoSearchData{
- DataTime: v.DataTime,
- Value: v.Value,
- })
- }
- searchItem.EdbCode = edbCode
- searchItem.DataList = dataItems
- searchItem.StartDate = indexInfo.StartDate.Format(utils.FormatDate)
- searchItem.EndDate = indexInfo.EndDate.Format(utils.FormatDate)
- searchItem.Frequency = indexInfo.Frequency
- searchItem.Unit = indexInfo.Unit
- searchItem.EdbName = indexInfo.IndexName
- } else if source == utils.DATA_SOURCE_SCI99 { //卓创资讯
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataSci99MaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- indexInfo, err := data_manage.GetBaseInfoFromSci99ByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- if indexInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "元/吨"
- searchItem.EdbName = indexInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_SCI_HQ {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCIHQ已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataSciHqMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCIHQ日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- sciHqInfo, err := data_manage.GetSciHqIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SciHq指标详情失败,Err:" + err.Error()
- return
- }
- if sciHqInfo != nil {
- searchItem.Frequency = sciHqInfo.Frequency
- searchItem.Unit = sciHqInfo.Unit
- searchItem.EdbName = sciHqInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_OILCHEM { //隆众资讯
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众资讯已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataOilchemMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode, frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- indexInfo, err := data_manage.GetBaseInfoFromOilchemByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- if indexInfo != nil {
- searchItem.Frequency = indexInfo.Frequency
- searchItem.Unit = indexInfo.Unit
- searchItem.EdbName = indexInfo.IndexName
- }
- } else {
- // 代码中没有的来源那么从edb_source中找是否有对应的
- sourceItem := data_manage.EdbSourceIdMap[source]
- if sourceItem == nil {
- br.Msg = "无效指标来源"
- return
- }
- // 获取指标数据
- dataList, e := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标数据失败, Err: " + e.Error()
- return
- }
- if len(dataList) > 0 {
- searchItem.EdbCode = edbCode
- searchItem.DataList = dataList
- // 获取最大最小值
- edbInfoMaxAndMinInfo, e := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败, GetEdbInfoMaxAndMinInfo Err:" + e.Error()
- return
- }
- if edbInfoMaxAndMinInfo != nil {
- searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
- searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
- }
- } else {
- // 新增指标数据
- addRes, e := data.AddEdbData(source, edbCode, frequency)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + e.Error()
- return
- }
- if addRes == nil {
- br.Msg = "获取失败"
- br.ErrMsg = "新增指标数据失败, addRes nil"
- return
- }
- if addRes.Ret != 200 {
- br.Msg = "未搜索到该指标, " + addRes.Msg
- //br.ErrMsg = addRes.ErrMsg + ";EdbCode:" + edbCode
- br.Success = true
- return
- }
- isAdd = true
- }
- // 查询基本信息
- baseIndexInfo, tErr := data_manage.GetBaseIndexInfoByEdbCode(edbCode, source)
- if tErr == nil {
- searchItem.EdbName = baseIndexInfo.IndexName
- searchItem.Frequency = baseIndexInfo.Frequency
- searchItem.Unit = baseIndexInfo.Unit
- }
- // 指标来源于桥接服务: 桥接服务获取指标取频度信息等
- if sourceItem.BridgeFlag != "" {
- bridgeOb := data.InitBridgeOB(sourceItem.BridgeFlag)
- if bridgeOb != nil {
- var r data.GetIndexFromBridgeReq
- r.IndexCode = edbCode
- r.Source = sourceItem.EdbSourceId
- r.SourceExtend = sourceItem.SourceExtend
- r.IndexCodeRequired = sourceItem.EdbCodeRequired
- bridgeIndex, e := bridgeOb.GetIndex(r)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "桥接服务获取指标信息失败, Err: " + e.Error()
- return
- }
- searchItem.EdbName = bridgeIndex.IndexName
- searchItem.Frequency = bridgeIndex.Frequency
- searchItem.Unit = bridgeIndex.Unit
- }
- }
- }
- if isAdd {
- if subSource == utils.DATA_SUB_SOURCE_DATE {
- if source == utils.DATA_SOURCE_WIND {
- //wsdData := windWsdRespItem.Data
- //var buf bytes.Buffer
- //// 创建一个encoder并指定目标为buf
- //enc := gob.NewEncoder(&buf)
- //
- //// 将data编码到buf中
- //err = enc.Encode(wsdData)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error()
- // return
- //}
- //
- //wsdDataMap := make(map[string]map[string]interface{})
- //err = json.Unmarshal(buf.Bytes(), &wsdDataMap)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error()
- // return
- //}
- //
- //stockList := make([]*data_manage.StockInfo, 0)
- //
- //dataList := make([]*data_manage.EdbInfoSearchData, 0)
- //for wk, wv := range wsdDataMap {
- // for vk, vv := range wv {
- // wkInt, err := strconv.ParseInt(wk, 10, 64)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error()
- // return
- // }
- //
- // vk = strings.ToLower(vk)
- // wkInt = wkInt / 1000
- // t := time.Unix(wkInt, 0)
- // dateTime := t.Format(utils.FormatDate)
- // //saveVal := utils.SubFloatToString(val, 20)
- // if vv == nil {
- // continue
- // }
- // var saveVal string
- // switch vt := vv.(type) {
- // case int:
- // saveVal = strconv.Itoa(vt)
- // case float64:
- // saveVal = utils.SubFloatToFloatStr(vt, 20)
- // case string:
- // saveVal = vt
- // }
- //
- // dataItem := new(data_manage.EdbInfoSearchData)
- // dataItem.Value = saveVal
- // dataItem.DataTime = dateTime
- // dataList = append(dataList, dataItem)
- // if len(dataList) >= 10 {
- // break
- // }
- // }
- //}
- //searchItem.StockList = stockList
- stockList := make([]*data_manage.StockInfo, 0)
- edbCodeArr := strings.Split(edbCode, ",")
- for _, v := range edbCodeArr {
- indexCode := utils.WindDbWsd + stockCode + v
- dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
- return
- }
- stockInfo := new(data_manage.StockInfo)
- stockInfo.StockCode = stockCode
- stockInfo.EdbCode = v
- stockInfo.DataList = dataList
- stockList = append(stockList, stockInfo)
- }
- searchItem.StockList = stockList
- } else if source == utils.DATA_SOURCE_THS {
- stockList := make([]*data_manage.StockInfo, 0)
- edbCodeArr := strings.Split(edbCode, ",")
- for _, v := range edbCodeArr {
- indexCode := utils.ThsDs + stockCode + v
- dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
- return
- }
- stockInfo := new(data_manage.StockInfo)
- stockInfo.StockCode = stockCode
- stockInfo.EdbCode = v
- stockInfo.DataList = dataList
- stockList = append(stockList, stockInfo)
- }
- searchItem.StockList = stockList
- } else {
- br.Msg = "来源错误"
- br.ErrMsg = "来源错误"
- return
- }
- } else {
- dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
- return
- }
- searchItem.DataList = dataList
- edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
- return
- }
- searchItem.EdbCode = edbCode
- searchItem.DataList = dataList
- if edbInfoMaxAndMinInfo != nil {
- searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
- searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
- }
- //edb指标信息
- edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode)
- if edbInfoItem != nil {
- searchItem.EdbName = edbInfoItem.EdbName
- }
- }
- }
- resp.Status = 2
- resp.SearchItem = searchItem
- }
- //如果不在指标库中,且不是新增
- if !isInEdb && !isAdd {
- if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 {
- br.Msg = "目标指标无有效值,请重新搜索"
- br.Data = resp
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoList
- // @Title 指标列表接口
- // @Description 指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Success 200 {object} data_manage.EdbInfoListResp
- // @router /edb_info/list [get]
- func (this *EdbInfoController) EdbInfoList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoId, _ := this.GetInt("EdbInfoId")
- keyWord := this.GetString("KeyWord")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //if edbInfoId <= 0 && keyWord == "" {
- // br.Msg = "参数错误"
- // return
- //}
- // 指标类型,0:普通指标,1:预测指标
- condition += " AND edb_info_type=? "
- pars = append(pars, 0)
- if edbInfoId > 0 {
- condition += " AND edb_info_id=? "
- pars = append(pars, edbInfoId)
- // 获取当前账号的不可见指标配置
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
- return
- }
- if conf != nil {
- br.Msg = "无权限,请联系管理员"
- br.IsSendEmail = false
- return
- }
- }
- if keyWord != "" {
- condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
- //pars = append(pars, keyWord)
- //pars = append(pars, keyWord)
- }
- resp := new(data_manage.EdbInfoListResp)
- if condition == "" {
- item := new(data_manage.EdbInfoList)
- resp.Paging = page
- resp.Item = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- //获取指标信息
- edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
- item := new(data_manage.EdbInfoList)
- resp.Paging = page
- resp.Item = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- //获取英文频度
- edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
- // 获取是否供应商停更
- edbInfoItem.IsSupplierStop = data.GetIsSupplierStop(edbInfoItem.Source, edbInfoItem.EdbCode)
- //查询目录
- classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- // 权限校验
- {
- var currClassify *data_manage.EdbClassifyIdItems
- for _, v := range classifyList {
- if edbInfoItem.ClassifyId == v.ClassifyId {
- currClassify = v
- break
- }
- }
- if currClassify != nil {
- edbInfoItem.HaveOperaAuth, err = data_manage_permission.CheckEdbPermission(edbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfoItem.EdbInfoId, edbInfoItem.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- }
- // 按钮校验
- button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType, edbInfoItem.HaveOperaAuth)
- button.AddButton = false
- edbInfoItem.Button = button
- edbInfoItem.DataList = make([]*data_manage.EdbData, 0)
- // 如果有数据权限,那么就去获取指标数据
- if edbInfoItem.HaveOperaAuth {
- dataCount, dataList, err := data.GetPageData(edbInfoItem.EdbInfoId, edbInfoItem.Source, edbInfoItem.SubSource, "", startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- edbInfoItem.DataList = dataList
- }
- // 获取指标插入配置
- {
- edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if edbDataInsertConfig != nil {
- edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate)
- edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate)
- edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value
- }
- }
- //是否展示英文标识
- edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn)
- resp.Paging = page
- resp.Item = edbInfoItem
- resp.ClassifyList = classifyList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoAdd
- // @Title 新增指标接口
- // @Description 新增指标接口
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/add [post]
- func (this *EdbInfoController) EdbInfoAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req data_manage.AddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- source := req.Source
- if source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- req.EdbCode = strings.Trim(req.EdbCode, " ")
- if req.EdbCode == "" {
- br.Msg = "指标ID不能为空"
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if req.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if req.Unit == "" {
- br.Msg = "单位不能为空"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- //if req.StartDate == "" || req.EndDate == "" {
- // br.Msg = "日期不能为空"
- // return
- //}
- // 兼容钢联与钢联化工数据
- if source == utils.DATA_SOURCE_GL {
- // 如果是钢联的话,那么就先判断是不是存在钢联化工
- tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- if tmpInfo != nil {
- source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- req.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- }
- }
- // 指标入库
- 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)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- // 试用平台更新用户累计新增指标数
- adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
- return
- }
- if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
- go func() {
- var r etaTrialService.EtaTrialUserReq
- r.Mobile = adminItem.Mobile
- _, _ = etaTrialService.UpdateUserIndexNum(r)
- }()
- }
- //新增操作日志
- {
- // 添加钢联指标更新日志
- if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
- }
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- // 更新es
- go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
- resp := new(data_manage.AddEdbInfoResp)
- resp.EdbInfoId = edbInfo.EdbInfoId
- resp.UniqueCode = edbInfo.UniqueCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // EdbInfoEdit
- // @Title 编辑指标接口
- // @Description 编辑指标接口
- // @Success 200 {object} data_manage.EditEdbInfoReq
- // @router /edb_info/edit [post]
- func (this *EdbInfoController) EdbInfoEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.EditEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if req.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if req.Unit == "" {
- br.Msg = "单位不能为空"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- // 记录旧的指标基本信息
- oldEdbName := edbInfo.EdbName
- oldFrequency := edbInfo.Frequency
- oldUnit := edbInfo.Unit
- var haveOperaAuth bool
- // 权限校验
- {
- haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- // 编辑权限校验
- button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无权限操作"
- br.IsSendEmail = false
- return
- }
- //判断指标名称是否存在
- var condition string
- var pars []interface{}
- condition += " AND edb_info_id<>? "
- pars = append(pars, req.EdbInfoId)
- //condition += " AND source=? "
- //pars = append(pars, edbInfo.Source)
- updateCols := make([]string, 0)
- switch this.Lang {
- case utils.EnLangVersion:
- condition += " AND edb_name_en = ? "
- edbInfo.EdbNameEn = req.EdbName
- edbInfo.Frequency = req.Frequency
- edbInfo.UnitEn = req.Unit
- edbInfo.ClassifyId = req.ClassifyId
- updateCols = append(updateCols, "EdbNameEn", "Frequency", "UnitEn", "ClassifyId")
- default:
- condition += " AND edb_name=? "
- edbInfo.EdbName = req.EdbName
- edbInfo.EdbNameSource = req.EdbName
- edbInfo.Frequency = req.Frequency
- edbInfo.Unit = req.Unit
- edbInfo.ClassifyId = req.ClassifyId
- updateCols = append(updateCols, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId")
- }
- pars = append(pars, req.EdbName)
- count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "判断指标名称是否存在失败"
- br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "指标名称已存在,请重新填写"
- br.ErrMsg = "指标名称已存在,请重新填写"
- br.IsSendEmail = false
- return
- }
- if len(updateCols) > 0 {
- err = edbInfo.Update(updateCols)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- //处理同名指标
- //{
- // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName)
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- // return
- // }
- // if len(edbNameList) >= 2 {
- // for _, v := range edbNameList {
- // edbName := v.EdbName + "(" + v.SourceName + ")"
- // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "修改指标名称失败,Err:" + err.Error()
- // return
- // }
- // }
- // }
- //}
- // 新增保存记录日志
- oldEdbInfo := new(data_manage.EdbInfo)
- oldEdbInfo.EdbInfoId = edbInfo.EdbInfoId
- oldEdbInfo.EdbName = oldEdbName
- oldEdbInfo.Frequency = oldFrequency
- oldEdbInfo.Unit = oldUnit
- newEdbInfoRecord := new(data_manage.EdbInfoEditRecord)
- newEdbInfoRecord.EdbName = req.EdbName
- newEdbInfoRecord.Frequency = req.Frequency
- newEdbInfoRecord.Unit = req.Unit
- newEdbInfoRecord.OperateUserId = sysUser.AdminId
- newEdbInfoRecord.OperateUserRealName = sysUser.RealName
- go data.AddEditEdbInfoRcord(oldEdbInfo, newEdbInfoRecord)
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- switch this.Lang {
- case utils.EnLangVersion:
- // 修改关联的预测指标基础信息
- go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
- default:
- // 修改关联的预测指标基础信息
- go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, req.Frequency, req.Unit)
- }
- // 添加钢联指标更新日志
- if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- if edbInfo.EdbName != req.EdbName || edbInfo.Frequency != req.Frequency || edbInfo.Unit != req.Unit {
- go data_stat.AddEdbInfoUpdateLog(req.EdbInfoId, 1, "", sysUser, 1)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // EdbEnInfoEdit
- // @Title 编辑指标英文信息接口
- // @Description 编辑指标英文信息接口
- // @Success 200 {object} data_manage.EditEdbEnInfoReq
- // @router /edb_info/en/edit [post]
- func (this *EdbInfoController) EdbEnInfoEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.EditEdbEnInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbNameEn = strings.Trim(req.EdbNameEn, " ")
- req.UnitEn = strings.Trim(req.UnitEn, " ")
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if req.EdbNameEn != "" {
- //判断指标名称是否存在
- var condition string
- var pars []interface{}
- condition += " AND edb_info_id<>? "
- pars = append(pars, req.EdbInfoId)
- /*condition += " AND source=? "
- pars = append(pars, edbInfo.Source)*/
- condition += " AND edb_name_en=? "
- pars = append(pars, req.EdbNameEn)
- edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "判断英文指标名称是否存在失败"
- br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
- return
- }
- }
- if err == nil && edbExist.EdbInfoId > 0 {
- br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在"
- br.ErrMsg = "英文指标名称已存在,请重新填写"
- br.IsSendEmail = false
- return
- }
- }
- err = data_manage.ModifyEdbEnInfo(&req)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑指标英文信息"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- // 修改关联的预测指标基础信息
- if edbInfo.EdbInfoType == 0 {
- go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.UnitEn)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // EdbInfoBaseEdit
- // @Title 编辑指标基础信息接口
- // @Description 编辑指标基础信息接口
- // @Success 200 {object} data_manage.EditEdbBaseInfoReq
- // @router /edb_info/base/edit [post]
- func (this *EdbInfoController) EdbInfoBaseEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.EditEdbBaseInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- req.Unit = strings.Trim(req.Unit, " ")
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- updateCols := make([]string, 0)
- if req.EdbName != "" {
- //判断指标名称是否存在
- var condition string
- var pars []interface{}
- condition += " AND edb_info_id<>? "
- pars = append(pars, req.EdbInfoId)
- /*condition += " AND source=? "
- pars = append(pars, edbInfo.Source)*/
- switch this.Lang {
- case utils.EnLangVersion:
- condition += " AND edb_name_en = ? "
- edbInfo.EdbNameEn = req.EdbName
- edbInfo.UnitEn = req.Unit
- edbInfo.ModifyTime = time.Now()
- updateCols = append(updateCols, "EdbNameEn", "UnitEn", "ModifyTime")
- default:
- condition += " AND edb_name = ? "
- edbInfo.EdbName = req.EdbName
- edbInfo.EdbNameSource = req.EdbName
- edbInfo.Unit = req.Unit
- edbInfo.ModifyTime = time.Now()
- updateCols = append(updateCols, "EdbName", "EdbNameSource", "Unit", "ModifyTime")
- }
- pars = append(pars, req.EdbName)
- edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "判断英文指标名称是否存在失败"
- br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
- return
- }
- }
- if err == nil && edbExist.EdbInfoId > 0 {
- br.Msg = edbExist.EdbName + ":" + req.EdbName + "指标名称已存在"
- br.ErrMsg = "英文指标名称已存在,请重新填写"
- br.IsSendEmail = false
- return
- }
- }
- if len(updateCols) > 0 {
- err = edbInfo.Update(updateCols)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑指标英文信息"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- // 修改关联的预测指标基础信息
- if edbInfo.EdbInfoType == 0 {
- switch this.Lang {
- case utils.EnLangVersion:
- go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
- default:
- go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, edbInfo.Frequency, req.Unit)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // EdbInfoNewest
- // @Title 获取最新指标接口
- // @Description 获取最新指标接口
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/newest [get]
- func (this *EdbInfoController) EdbInfoNewest() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- item, err := data_manage.GetEdbInfoByNewest()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取最新指标失败"
- br.ErrMsg = "获取最新指标失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = item
- }
- // EdbInfoRefresh
- // @Title 指标刷新接口
- // @Description 指标刷新接口
- // @Param EdbInfoId query int true "指标id"
- // @Success Ret=200 刷新成功
- // @router /edb_info/refresh [get]
- func (this *EdbInfoController) EdbInfoRefresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- _, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "数据已被删除,请刷新页面"
- br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
- return
- }
- br.Msg = "刷新失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false, false)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Msg = "刷新成功"
- if isAsync {
- br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
- }
- br.Success = true
- br.IsAddLog = true
- }
- // EdbInfoMove
- // @Title 移动指标接口
- // @Description 移动指标接口
- // @Success 200 {object} data_manage.MoveEdbInfoReq
- // @router /edb_info/move [post]
- func (this *EdbInfoController) EdbInfoMove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.MoveEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- //判断分类是否存在
- count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId)
- if count <= 0 {
- br.Msg = "分类已被删除,不可移动,请刷新页面"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- var haveOperaAuth bool
- // 权限校验
- {
- haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.IsJoinPermission, edbInfo.EdbInfoId, edbInfo.ClassifyId, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- // 移动权限校验
- button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
- if !button.MoveButton {
- br.Msg = "无权限操作"
- br.IsSendEmail = false
- return
- }
- //如果改变了分类,那么移动该指标数据
- if edbInfo.ClassifyId != req.ClassifyId {
- err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "移动指标失败,Err:" + err.Error()
- return
- }
- }
- updateCol := make([]string, 0)
- //如果有传入 上一个兄弟节点分类id
- if req.PrevEdbInfoId > 0 {
- prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextEdbInfoId > 0 {
- //下一个兄弟节点
- nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
- if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
- } else {
- //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
- if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
- }
- }
- }
- edbInfo.Sort = prevEdbInfo.Sort + 1
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "移动失败"
- br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
- return
- }
- //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
- if firstClassify != nil && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr)
- }
- edbInfo.Sort = 0 //那就是排在第一位
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- //更新
- if len(updateCol) > 0 {
- err = edbInfo.Update(updateCol)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- }
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "移动指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- }
- // EdbInfoDetail
- // @Title 获取指标详情
- // @Description 获取指标详情接口
- // @Param EdbInfoId query int true "指标id"
- // @Success 200 {object} data_manage.EdbInfo
- // @router /edb_info/detail [get]
- func (this *EdbInfoController) EdbInfoDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- var resp data_manage.EdbInfoFullClassify
- classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- // 权限校验
- {
- classifyMap := make(map[int]*data_manage.EdbClassifyIdItems)
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- if currClassify, ok := classifyMap[edbInfo.ClassifyId]; ok {
- haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- resp.HaveOperaAuth = haveOperaAuth
- }
- }
- resp.EdbInfo = edbInfo
- resp.ClassifyList = classifyList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoFilter
- // @Title 指标筛选接口
- // @Description 指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/filter [get]
- func (this *EdbInfoController) EdbInfoFilter() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- var pars []interface{}
- noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
- // 获取当前账号的不可见指标
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- }
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- if keyWord != "" {
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- }
- //var err error
- edbInfoList := make([]*data_manage.EdbInfoList, 0)
- //if keyWord == "" {
- // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Success = true
- // br.Msg = "获取指标信息失败"
- // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- // return
- // }
- //} else {
- // //获取指标信息
- // indexName := utils.DATA_INDEX_NAME
- // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Success = true
- // br.Msg = "获取指标信息失败"
- // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- // return
- // }
- //}
- var baseCondition string
- // 无权限指标id
- lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
- if lenNoPermissionEdbInfoIdList > 0 {
- baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- existMap := make(map[int]string)
- for _, v := range keyWordArr {
- v = strings.Replace(v, " ", "%", -1)
- var condition string
- if filterSource == 2 {
- condition += ` AND frequency='月度' `
- }
- if filterSource == 3 {
- condition += ` AND frequency <> '日度' `
- }
- if filterSource == 4 {
- condition += ` AND edb_type = 1 `
- }
- conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
- condition += conditionWhere + baseCondition
- newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- for _, nv := range newEdbInfoList {
- if _, ok := existMap[nv.EdbInfoId]; !ok {
- edbInfoList = append(edbInfoList, nv)
- }
- existMap[nv.EdbInfoId] = nv.EdbCode
- }
- }
- if edbInfoList == nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- edbInfoListLen := len(edbInfoList)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = edbInfoList
- }
- // EdbInfoFilterByEs
- // @Title 指标筛选接口
- // @Description 指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
- // @Param Frequency query string false "频度"
- // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/filter_by_es [get]
- func (this *EdbInfoController) EdbInfoFilterByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int64
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- //指标来源
- source, _ := this.GetInt("Source")
- frequency := this.GetString("Frequency") //频度
- isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
- var edbInfoList []*data_manage.EdbInfoList
- var err error
- noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
- // 获取当前账号的不可见指标
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- }
- // 是否走ES
- isEs := false
- if keyWord != "" {
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- // 普通的搜索
- if !isAddPredictEdb {
- total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
- } else {
- // 允许添加预测指标的搜索
- total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize)
- }
- isEs = true
- } else {
- var condition string
- var pars []interface{}
- // 普通指标
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 0)
- // 无权限指标id
- lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
- if lenNoPermissionEdbInfoIdList > 0 {
- condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- switch filterSource {
- case 2:
- condition += ` AND frequency='月度' `
- case 3:
- condition += ` AND frequency <> '日度' `
- case 4:
- condition += ` AND edb_type = 1 `
- case 5:
- condition += ` AND source = 6 ` //来源(同比值)
- case 6:
- condition += ` AND frequency != ? `
- pars = append(pars, "年度")
- }
- //频度
- if frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, frequency)
- }
- if source > 0 && filterSource != 5 {
- condition += ` AND source = ? `
- pars = append(pars, source)
- }
- // 查询只允许添加预测指标的搜索
- if isAddPredictEdb {
- condition += ` AND frequency in ("日度","周度","月度") `
- }
- total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
- }
- if err != nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- edbInfoListLen := len(edbInfoList)
- classifyIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
- }
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.EdbClassify)
- if edbInfoListLen > 0 {
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
- if isEs {
- edbInfoIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
- tmpEdbInfo := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
- return
- }
- edbInfoMap := make(map[int]*data_manage.EdbInfo)
- for _, v := range tmpEdbList {
- edbInfoMap[v.EdbInfoId] = v
- }
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
- if !ok {
- continue
- }
- edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
- }
- }
- // 权限校验
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfoItem := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- resp := data_manage.EdbInfoFilterDataResp{
- Paging: page,
- List: edbInfoList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *EdbInfoController) EdbInfoFilter2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- var pars []interface{}
- //if keyWord != "" {
- // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
- //}
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- if keyWord != "" {
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- }
- keywordLen := len(keyWordArr)
- ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen)
- searchWait := sync.WaitGroup{}
- searchWait.Add(keywordLen)
- for index, v := range keyWordArr {
- v = strings.Replace(v, " ", "%", -1)
- var condition string
- if filterSource == 2 {
- condition += ` AND frequency='月度' `
- }
- if filterSource == 3 {
- condition += ` AND frequency <> '日度' `
- }
- if filterSource == 4 {
- condition += ` AND edb_type = 1 `
- }
- conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
- condition += conditionWhere
- go searchEdbInfoFilter(condition, pars, index, ch, &searchWait)
- }
- searchWait.Wait()
- newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList)
- i := 0
- for tmpEdbInfoList := range ch {
- i++
- for k, v := range tmpEdbInfoList {
- newEdbInfoListMap[k] = v
- }
- if i == keywordLen {
- break
- }
- }
- close(ch)
- edbInfoList := make([]*data_manage.EdbInfoList, 0)
- existMap := make(map[int]string)
- for i := 0; i < keywordLen; i++ {
- if newEdbInfoList, ok := newEdbInfoListMap[i]; ok {
- for _, nv := range newEdbInfoList {
- if _, ok := existMap[nv.EdbInfoId]; !ok {
- edbInfoList = append(edbInfoList, nv)
- }
- existMap[nv.EdbInfoId] = nv.EdbCode
- }
- }
- }
- if edbInfoList == nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- edbInfoListLen := len(edbInfoList)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = edbInfoList
- }
- 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) {
- newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList)
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
- }
- ch <- newEdbInfoListMap
- searchWait.Done()
- }()
- newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
- newEdbInfoListMap[i] = newEdbInfoList
- return
- }
- // EdbInfoAllRefresh
- // @Title 指标全部刷新接口
- // @Description 指标全部刷新接口
- // @Param EdbInfoId query int true "指标id"
- // @Success Ret=200 全部刷新成功
- // @router /edb_info/refresh/all [get]
- func (this *EdbInfoController) EdbInfoAllRefresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "数据已被删除,请刷新页面"
- br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
- return
- }
- br.Msg = "刷新失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if edbInfo == nil {
- br.Msg = "数据已被删除,请刷新页面"
- br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
- return
- }
- err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true, false)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- if isAsync {
- br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
- }
- }
- // EdbInfoData
- // @Title 获取指标数据
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/data [get]
- func (this *ChartInfoController) EdbInfoData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- fullEdb := new(data_manage.EdbInfoFullClassify)
- resp := new(data_manage.EdbInfoDataFullClassifyResp)
- dataList := make([]*data_manage.EdbDataList, 0)
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- return
- }
- dateType, _ := this.GetInt("DateType")
- if dateType <= 0 {
- dateType = 3
- }
- edbInfoType, _ := this.GetInt("EdbInfoType")
- if edbInfoType < 0 {
- edbInfoType = 1
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- startYear, _ := this.GetInt("StartYear")
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Ret = 200
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- // 分类
- classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = errMsg
- return
- }
- fullEdb.EdbInfo = edbInfo
- // 是否供应商停更
- fullEdb.IsSupplierStop = data.GetIsSupplierStop(edbInfo.Source, edbInfo.EdbCode)
- fullEdb.ClassifyList = classifyList
- var currClassifyItem *data_manage.EdbClassifyIdItems
- for _, v := range classifyList {
- if v.ClassifyId == edbInfo.ClassifyId {
- currClassifyItem = v
- }
- }
- if currClassifyItem != nil {
- haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassifyItem.IsJoinPermission, sysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- fullEdb.HaveOperaAuth = haveOperaAuth
- }
- resp.EdbInfo = fullEdb
- resp.DataList = make([]*data_manage.EdbDataList, 0)
- // 数据获取
- if fullEdb.HaveOperaAuth { // 有权限才获取数据
- maxYear := 0
- if edbInfo.LatestDate != "" {
- latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
- maxYear = latestDateT.Year()
- }
- startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
- dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp.DataList = dataList
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoReplaceCheck
- // @Title 指标一键刷新接口
- // @Description 指标一键刷新接口
- // @Success Ret=200 更新成功
- // @router /edb_info/replace/check [post]
- func (this *EdbInfoController) EdbInfoReplaceCheck() {
- br := new(models.BaseResponse).Init()
- setNxKey := "EDB_INFO_REPLACE"
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- status := 0
- if utils.Rc.IsExist(setNxKey) {
- status = 1
- } else {
- status = 2
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "检测成功"
- br.Data = status
- }
- // EdbInfoReplace
- // @Title 替换指标
- // @Description 替换指标
- // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/replace [post]
- func (this *ChartInfoController) EdbInfoReplace() {
- br := new(models.BaseResponse).Init()
- setNxKey := "EDB_INFO_REPLACE"
- deleteCache := true
- defer func() {
- if deleteCache {
- utils.Rc.Delete(setNxKey)
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
- deleteCache = false
- br.Msg = "当前正在替换中,请耐心等待!"
- br.IsSendEmail = false
- return
- }
- var req data_manage.EdbInfoReplaceReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "参数错误,指标id为0"
- return
- }
- oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
- if err != nil {
- br.Msg = "替换失败!"
- br.ErrMsg = "获取原指标失败,Err:" + err.Error()
- return
- }
- newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
- if err != nil {
- br.Msg = "替换失败!"
- br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
- return
- }
- //if oldEdbInfo.EdbType != 1 {
- // br.Msg = "原指标为计算指标,不可替换!"
- // br.ErrMsg = "原指标为计算指标,不可替换!"
- // return
- //}
- //
- //if newEdbInfo.EdbType != 1 {
- // br.Msg = "替换指标为计算指标,不可替换!"
- // br.ErrMsg = "替换指标为计算指标,不可替换!"
- // return
- //}
- if oldEdbInfo.Frequency != newEdbInfo.Frequency {
- br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
- br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
- return
- }
- sysAdminId := sysUser.AdminId
- //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
- _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
- //msgContent := ``
- if err != nil {
- br.Msg = "替换失败"
- br.ErrMsg = "替换失败 replace err:" + err.Error()
- return
- }
- br.Msg = "替换成功"
- br.ErrMsg = "替换成功"
- br.Ret = 200
- br.IsAddLog = true
- return
- }
- // RelationChartList
- // @Title 获取ETA指标关联的图表列表接口
- // @Description 获取ETA指标关联的图表列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/relation/chart_list [get]
- func (this *EdbInfoController) RelationChartList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- resp := data_manage.ChartListResp{}
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- /*// 关联指标
- condition += ` AND b.edb_info_id = ? `
- pars = append(pars, edbInfoId)*/
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- if isShowMe {
- condition += ` AND a.sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- chartIds := make([]int, 0)
- chartIdMap := make(map[int]bool)
- // 查询指标绑定的图表
- edbListTemp, err := data_manage.GetEdbMappingListByEdbInfoId(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- for _, v := range edbListTemp {
- if _, ok := chartIdMap[v.ChartInfoId]; !ok {
- chartIdMap[v.ChartInfoId] = true
- }
- }
- // 查询跨品种的图表
- tagXList, err := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- for _, v := range tagXList {
- if _, ok := chartIdMap[v.ChartInfoId]; !ok {
- chartIdMap[v.ChartInfoId] = true
- }
- }
- tagYList, err := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- for _, v := range tagYList {
- if _, ok := chartIdMap[v.ChartInfoId]; !ok {
- chartIdMap[v.ChartInfoId] = true
- }
- }
- // 获取当前账号的不可见图表
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- if _, ok := chartIdMap[v.ChartInfoId]; ok {
- delete(chartIdMap, v.ChartInfoId)
- }
- }
- }
- for k, _ := range chartIdMap {
- chartIds = append(chartIds, k)
- }
- // 关联指标
- if len(chartIds) > 0 {
- condition += ` AND a.chart_info_id in (` + utils.GetOrmInReplace(len(chartIds)) + `)`
- pars = append(pars, chartIds)
- } else {
- items := make([]*data_manage.ChartInfoView, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 得到图表ID
- //获取关联图表列表
- list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.ChartInfoView, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 获取关联图表总数
- dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- // 获取MY ETA 图表,用来判断是否加入我的图库
- myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
- return
- }
- myChartMap := make(map[int]*data_manage.MyChartView)
- for _, v := range myChartList {
- myChartMap[v.ChartInfoId] = v
- }
- listLen := len(list)
- if listLen > 0 {
- // 分类id
- classifyIdList := make([]int, 0)
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.ChartClassify)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ChartClassifyId)
- }
- classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ChartClassifyId] = v
- }
- // 已授权分类id
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- if existItem, ok := myChartMap[v.ChartInfoId]; ok {
- v.IsAdd = true
- v.MyChartId = existItem.MyChartId
- v.MyChartClassifyId = existItem.MyChartClassifyId
- }
- // 权限
- if currClassify, ok := classifyMap[v.ChartClassifyId]; ok {
- v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- }
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // RelationEdbList
- // @Title 获取ETA指标关联的指标列表接口
- // @Description 获取ETA指标关联的指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/relation/edbinfo_list [get]
- func (this *EdbInfoController) RelationEdbList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- resp := data_manage.RelationEdbInfoListResp{}
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- // 关联指标
- condition += ` AND b.from_edb_info_id = ? `
- pars = append(pars, edbInfoId)
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- if isShowMe {
- condition += ` AND a.sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- // 获取当前账号的不可见图表
- noPermissionEdbIdList := make([]int, 0)
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
- }
- }
- noPermissionEdbIdNum := len(noPermissionEdbIdList)
- if noPermissionEdbIdNum > 0 {
- condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
- pars = append(pars, noPermissionEdbIdList)
- }
- //获取关联图表列表
- list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.ChartEdbInfoMapping, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 获取关联图表总数
- dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
- if len(list) > 0 {
- // 当前的分类
- classifyMap := make(map[int]*data_manage.EdbClassify)
- {
- classifyIdList := make([]int, 0)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ClassifyId)
- }
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- item := new(data_manage.ChartEdbInfoMapping)
- item.EdbInfoId = v.EdbInfoId
- item.SourceName = v.SourceName
- item.Source = v.Source
- item.EdbCode = v.EdbCode
- item.EdbName = v.EdbName
- item.EdbNameEn = v.EdbNameEn
- item.Frequency = v.Frequency
- item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
- if v.Unit != `无` {
- item.Unit = v.Unit
- }
- item.UnitEn = v.UnitEn
- item.StartDate = v.StartDate
- item.EndDate = v.EndDate
- item.ModifyTime = v.ModifyTime
- item.IsAxis = 1
- item.LeadValue = 0
- item.LeadUnit = ""
- item.ChartEdbMappingId = 0
- item.ChartInfoId = 0
- item.IsOrder = false
- item.EdbInfoType = v.EdbInfoType
- item.EdbInfoCategoryType = v.EdbInfoType
- item.ChartStyle = ""
- item.ChartColor = ""
- item.ChartWidth = 0
- item.MaxData = v.MaxValue
- item.MinData = v.MinValue
- item.LatestValue = v.LatestValue
- item.LatestDate = v.LatestDate
- item.UniqueCode = v.UniqueCode
- item.ClassifyId = v.ClassifyId
- dataList := make([]*data_manage.EdbDataList, 0)
- // 指标权限
- if currClassify, ok := classifyMap[v.ClassifyId]; ok {
- item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- // 有权限则获取数据
- if item.HaveOperaAuth {
- if v.EdbInfoType == 0 {
- dataList, err = data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, "", "")
- } else {
- _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
- }
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- }
- item.DataList = dataList
- edbList = append(edbList, item)
- }
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- resp.Paging = page
- resp.List = edbList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoDataTb
- // @Title 获取指标数据同比值
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/data/tb [get]
- func (this *ChartInfoController) EdbInfoDataTb() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- return
- }
- dateType, _ := this.GetInt("DateType")
- if dateType <= 0 {
- dateType = 3
- }
- edbInfoType, _ := this.GetInt("EdbInfoType")
- if edbInfoType < 0 {
- edbInfoType = 1
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- startYear, _ := this.GetInt("StartYear")
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- maxYear := 0
- if edbInfo.LatestDate != "" {
- latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
- maxYear = latestDateT.Year()
- }
- startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
- var startDateTime time.Time
- if startDate != `` {
- startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- if err != nil {
- br.Msg = "开始日期异常"
- br.Msg = "开始日期异常,Err:" + err.Error()
- return
- }
- //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
- startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
- }
- tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- // 计算同比值
- dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "计算同比值失败,Err:" + err.Error()
- return
- }
- edbInfo.MaxValue = maxValue
- edbInfo.MinValue = minValue
- resp := new(data_manage.EdbInfoDataResp)
- resp.EdbInfo = edbInfo
- resp.DataList = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoDataSeasonal
- // @Title 获取指标数据(季节性)
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Param Calendar query string true "公历/农历"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/data/seasonal [get]
- func (this *ChartInfoController) EdbInfoDataSeasonal() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- dateType, _ := this.GetInt("DateType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- startYear, _ := this.GetInt("StartYear")
- edbInfoIdStr := this.GetString("EdbInfoId")
- edbInfoId, err := strconv.Atoi(edbInfoIdStr)
- if err != nil {
- br.Msg = "指标id异常"
- br.Msg = "指标id转换异常,Err:" + err.Error()
- return
- }
- fmt.Println("startDate:", startDate)
- fmt.Println("endDate:", endDate)
- calendar := this.GetString("Calendar")
- if calendar == "" {
- calendar = "公历"
- }
- if dateType == 0 {
- if startDate == "" {
- dateType = utils.DateTypeNYears
- } else {
- dateType = 5
- }
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- maxYear := 0
- if edbInfo.LatestDate != "" {
- latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
- maxYear = latestDateT.Year()
- }
- startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
- dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.EdbInfoDataSeasonalResp)
- resp.EdbInfo = edbInfo
- resp.DataList = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SetEdbDataInsertConfig 设置插入值
- // @Title 设置插入值接口
- // @Description 设置插入值接口
- // @Success 200 {object} data_manage.EditEdbEnInfoReq
- // @router /edb_info/insert_config/set [post]
- func (this *EdbInfoController) SetEdbDataInsertConfig() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.SetEdbDataInsertConfigReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- dateStr := req.Date
- if dateStr == `` {
- br.Msg = "请选择日期"
- br.IsSendEmail = false
- return
- }
- date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
- if err != nil {
- br.Msg = "日期异常"
- br.ErrMsg = "日期异常,err:" + err.Error()
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
- if err != nil {
- br.Msg = "设置失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "修改失败,Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "设置插入值"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // TraceEdbInfo
- // @Title 指标溯源接口
- // @Description 指标溯源接口
- // @Param UniqueCode query int true "指标唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/trace [get]
- func (this *EdbInfoController) TraceEdbInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- //edbInfoId, _ := this.GetInt("EdbInfoId")
- //if edbInfoId <= 0 {
- // br.Msg = "参数错误"
- // br.ErrMsg = "参数错误"
- // return
- //}
- uniqueCode := this.GetString("UniqueCode")
- if uniqueCode == `` {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- // 根据UniqueCode获取指标信息
- edbInfo, err := data_manage.GetEdbInfoByUniqueCode(uniqueCode)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "指标不存在"
- }
- return
- }
- resp, err := data.TraceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Data = resp
- br.Success = true
- br.Msg = "刷新成功"
- }
- // AllEdbInfoByEs
- // @Title 所有指标筛选接口
- // @Description 所有指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
- // @Param Frequency query string false "频度"
- // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/filter_by_es/all [get]
- func (this *EdbInfoController) AllEdbInfoByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int64
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- //指标来源
- source, _ := this.GetInt("Source")
- frequency := this.GetString("Frequency") //频度
- isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
- var edbInfoList []*data_manage.EdbInfoList
- var err error
- noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
- // 获取当前账号的不可见指标
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- }
- // 是否走ES
- isEs := false
- if keyWord != "" {
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- // 普通的搜索
- total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, frequency, noPermissionEdbInfoIdList)
- isEs = true
- } else {
- var condition string
- var pars []interface{}
- // 普通指标
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 0)
- // 无权限指标id
- lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
- if lenNoPermissionEdbInfoIdList > 0 {
- condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- switch filterSource {
- case 2:
- condition += ` AND frequency='月度' `
- case 3:
- condition += ` AND frequency <> '日度' `
- case 4:
- condition += ` AND edb_type = 1 `
- case 5:
- condition += ` AND source = 6 ` //来源(同比值)
- case 6:
- condition += ` AND frequency != ? `
- pars = append(pars, "年度")
- }
- //频度
- if frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, frequency)
- }
- // 查询只允许添加预测指标的搜索
- if isAddPredictEdb {
- condition += ` AND frequency in ("日度","周度","月度") `
- }
- total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
- }
- if err != nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- edbInfoListLen := len(edbInfoList)
- classifyIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
- }
- // 当前列表中的分类map
- classifyMap := make(map[int]*data_manage.EdbClassify)
- if edbInfoListLen > 0 {
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
- if isEs {
- edbInfoIdList := make([]int, 0)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
- tmpEdbInfo := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- edbInfoMap := make(map[int]*data_manage.EdbInfo)
- for _, v := range tmpEdbList {
- edbInfoMap[v.EdbInfoId] = v
- }
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
- if !ok {
- continue
- }
- edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
- }
- }
- // 权限校验
- for i := 0; i < edbInfoListLen; i++ {
- tmpEdbInfoItem := edbInfoList[i]
- if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
- edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- resp := data_manage.EdbInfoFilterDataResp{
- Paging: page,
- List: edbInfoList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetEdbDateData
- // @Title 根据指标ID和具体日期获取对应日期的数据值
- // @Description 根据指标ID和具体日期获取对应日期的数据值
- // @Param EdbInfoId query int false "指标id"
- // @Param Date query string false "日期"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/date_data [get]
- func (this *EdbInfoController) GetEdbDateData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoId, _ := this.GetInt("EdbInfoId")
- date := this.GetString("Date")
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- if date == `` {
- br.Msg = "请选择日期"
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
- return
- }
- startDate := date
- endDate := date
- dateType := "day"
- //如果填写的是月度日期
- if strings.Count(date, "-") == 1 {
- startDate = date + "-01"
- endDate = ``
- dateType = "month"
- }
- dataItem, err := data.GetDateData(edbInfo, startDate, endDate)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
- return
- }
- val := ``
- if dataItem != nil {
- switch dateType {
- case "month":
- dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local)
- dateTimeStr := dateTime.Format(utils.FormatYearMonthDate)
- if dateTimeStr != date {
- val = ``
- }
- }
- val = fmt.Sprint(dataItem.Value)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = val
- }
- // GetEdbBeforeAndAfterDateData
- // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期
- // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期
- // @Param EdbInfoId query int false "指标id"
- // @Param Date query string false "日期"
- // @Param Num query int false "前后几期数据"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/date_data/before_after [post]
- func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- requestBody := string(this.Ctx.Input.RequestBody)
- var req request2.DateDataBeforeAfterReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- edbInfoId := req.EdbInfoId
- currDate := req.Date
- num := req.Num
- // 默认2期数据
- if num <= 0 {
- num = 2
- }
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
- return
- }
- dataList := make([]*data_manage.EdbDataList, 0)
- switch edbInfo.EdbInfoType {
- case 0:
- dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
- case 1:
- _, dataList, _, _, _, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
- default:
- br.Msg = "指标类型异常!"
- br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType)
- return
- }
- if currDate == `` {
- currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList)
- if err != nil {
- br.Msg = "日期前移失败"
- br.ErrMsg = "日期前移失败,Err:" + err.Error()
- return
- }
- } else {
- if strings.Count(currDate, "-") == 1 {
- currDate = currDate + "-01"
- // 查找这个月早的时间作为起始时间
- for _, v := range dataList {
- if v.DataTime >= currDate {
- currDate = v.DataTime
- break
- }
- }
- }
- }
- currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody)
- if err != nil {
- br.Msg = "日期变换失败"
- br.ErrMsg = "日期变换失败,Err:" + err.Error()
- return
- }
- list := make([]*data_manage.EdbDataList, 5)
- list, err = data.GetEdbBeforeAndAfterDateData(currDate, dataList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
- return
- }
- // 这个日期不存在的话直接返回空数组
- resp := data_manage.BeforeAndAfterDateDataResp{
- List: list,
- Date: currDate,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbChartAdminList
- // @Title 获取创建人员分组
- // @Description 获取创建人员分组
- // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
- // @Success 200 {object} company.DepartmentGroupSellersResp
- // @router /edb_chart/adminList [get]
- func (this *EdbInfoController) EdbChartAdminList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- source, _ := this.GetInt("Source", 0)
- if source <= 0 || source > 5 {
- br.Msg = "错误的来源"
- br.IsSendEmail = false
- return
- }
- idList, err := data.GetEdbChartAdminList(source)
- if err != nil {
- //br.Success = true
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- fmt.Println("idlist:", idList)
- systemAdminMap := make(map[int]*system.Admin)
- departmentMap := make(map[string]string)
- departmentAdminMap := make(map[int]string)
- groupMap := make(map[string]string)
- systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList)
- if err != nil {
- br.Msg = "获取用户列表失败"
- br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
- return
- }
- for _, v := range systemAdminList {
- systemAdminMap[v.AdminId] = v
- departmentMap[v.DepartmentName] = v.DepartmentName
- departmentAdminMap[v.AdminId] = v.DepartmentName
- groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName
- }
- depList := make([]company.DepartmentGroupAdmins, 0)
- i := 1
- for _, v := range departmentMap {
- item := company.DepartmentGroupAdmins{
- AdminId: "dep_" + strconv.Itoa(i),
- RealName: v,
- }
- i++
- depList = append(depList, item)
- }
- for k := 0; k < len(depList); k++ {
- for k1, v1 := range groupMap {
- if v1 == depList[k].RealName && v1 != "" {
- item := &company.DepartmentGroupAdmins{
- AdminId: "group_" + strconv.Itoa(k),
- RealName: strings.Replace(k1, v1, "", -1),
- }
- depList[k].ChildrenList = append(depList[k].ChildrenList, item)
- }
- }
- }
- for _, admin := range systemAdminList {
- for i, v := range depList {
- for k, group := range v.ChildrenList {
- if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName {
- item := &company.DepartmentGroupAdmins{
- AdminId: strconv.Itoa(admin.AdminId),
- RealName: admin.RealName,
- RoleTypeCode: admin.RoleTypeCode,
- Authority: admin.Authority,
- }
- if group.RealName != "" {
- depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item)
- } else {
- depList[i].ChildrenList = append(depList[i].ChildrenList, item)
- }
- }
- }
- }
- }
- for i, groupList := range depList {
- for k, v := range groupList.ChildrenList {
- if v.RealName == "" {
- newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...)
- depList[i].ChildrenList = newChildrenList
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = depList
- }
- // EdbSourceList
- // @Title 指标来源列表
- // @Description 指标来源列表
- // @Param IsBase query int false "是否为基础指标: 1-是"
- // @Success 200 {object} data_manage.EdbInfoListResp
- // @router /edb_source/list [get]
- func (this *EdbInfoController) EdbSourceList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- isBase, _ := this.GetInt("IsBase", 0)
- cond := ``
- if isBase > 0 {
- cond = ` AND is_base = 1`
- }
- pars := make([]interface{}, 0)
- list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
- return
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // EdbSourceListByPython
- // @Title 指标来源列表
- // @Description 指标来源列表
- // @Param IsBase query int false "是否为基础指标: 1-是"
- // @Success 200 {object} data_manage.EdbInfoListResp
- // @router /edb_source/list/python [get]
- func (this *EdbInfoController) EdbSourceListByPython() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- isBase, _ := this.GetInt("IsBase", 0)
- cond := ``
- if isBase > 0 {
- cond = ` AND is_base = 1`
- }
- pars := make([]interface{}, 0)
- list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
- return
- }
- baseEdbList := make([]data_manage.EdbSourceChild, 0)
- calEdbList := make([]data_manage.EdbSourceChild, 0)
- for _, v := range list {
- switch v.IsBase {
- case 1:
- baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{
- EdbSourceId: v.EdbSourceId,
- SourceName: v.SourceName,
- IsBase: v.IsBase,
- TableName: v.TableName,
- Child: []data_manage.EdbSourceChild{},
- })
- case 2:
- calEdbList = append(calEdbList, data_manage.EdbSourceChild{
- EdbSourceId: v.EdbSourceId,
- SourceName: v.SourceName,
- IsBase: v.IsBase,
- TableName: v.TableName,
- Child: []data_manage.EdbSourceChild{},
- })
- }
- }
- resp := []data_manage.EdbSourceChild{
- {
- EdbSourceId: 0,
- SourceName: "基础指标",
- IsBase: 1,
- Child: baseEdbList,
- },
- {
- EdbSourceId: 0,
- SourceName: "计算指标",
- IsBase: 1,
- Child: calEdbList,
- },
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // EdbChartList
- // @Title 指标缩略图列表接口
- // @Description 指标缩略图列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query int true "分类id"
- // @Param AdminId query int false "创建人id"
- // @Param IsOnlyMe query bool false "是否只看我的"
- // @Success 200 {object} response.EdbInfoChartListResp
- // @router /edb_info/chart/list [get]
- func (this *EdbInfoController) EdbChartList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- // 分页
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- // 基础指标
- var condition string
- var pars []interface{}
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 0)
- // 分类筛选
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId > 0 {
- childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
- return
- }
- var classifyIds []int
- for _, v := range childClassify {
- classifyIds = append(classifyIds, v.ClassifyId)
- }
- condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
- pars = append(pars, classifyIds)
- }
- // 创建人
- adminId, _ := this.GetInt("AdminId")
- if adminId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, adminId)
- }
- // 只看我的
- isOnlyMe, _ := this.GetBool("IsOnlyMe")
- if isOnlyMe {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- // 获取当前账号的不可见指标
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
- return
- }
- noPermissionEdbInfoIdList := make([]int, 0)
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
- if noPermissionEdbInfoIdNum > 0 {
- condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- // 获取指标信息
- dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
- return
- }
- if len(list) == 0 {
- list = make([]*data_manage.EdbInfoList, 0)
- } else {
- classifyIdList := make([]int, 0)
- for _, v := range list {
- classifyIdList = append(classifyIdList, v.ClassifyId)
- }
- // 指标权限
- {
- // 当前的分类
- classifyMap := make(map[int]*data_manage.EdbClassify)
- classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if err != nil {
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
- return
- }
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- issSupplierStopIndexCodeMap := make(map[string]bool)
- {
- tmpEdbCodeList := make([]string, 0)
- for _, v := range list {
- if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode)
- }
- }
- if len(tmpEdbCodeList) > 0 {
- notIsSupplierStopIndexList, e := data_manage.GetNotIsSupplierStopIndexByCodeList(tmpEdbCodeList, 1)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + e.Error()
- return
- }
- // 已被供应商暂停的指标编码
- for _, v := range notIsSupplierStopIndexList {
- issSupplierStopIndexCodeMap[v.IndexCode] = true
- }
- }
- }
- for _, v := range list {
- if currClassify, ok := classifyMap[v.ClassifyId]; ok {
- v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType, v.HaveOperaAuth)
- }
- // 供应商停用
- if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- if _, ok := issSupplierStopIndexCodeMap[v.EdbCode]; ok {
- v.IsSupplierStop = 1
- }
- }
- }
- }
- page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
- }
- resp := response.EdbInfoChartListResp{
- Paging: page,
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Modify
- // @Title 修改指标信息接口
- // @Description 编辑指标接口
- // @Success 200 string "操作成功"
- // @router /edb_info/modify [post]
- func (this *EdbInfoController) Modify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.ModifyEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- edbInfoId := req.EdbInfoId
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取指标信息失败, Err:" + err.Error()
- return
- }
- var haveOperaAuth bool
- // 权限校验
- {
- haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
- if err != nil {
- br.Msg = err.Error()
- br.ErrMsg = "校验指标权限失败,err:" + err.Error()
- return
- }
- }
- // 编辑权限校验
- button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无权限操作"
- return
- }
- edbInfo.MaxValue = req.MaxValue
- edbInfo.MinValue = req.MinValue
- edbInfo.ManualSave = 1
- edbInfo.ModifyTime = time.Now()
- err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //修改es
- data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "修改成功"
- br.IsAddLog = true
- }
- // ChartImageSet
- // @Title 设置指标的图表图片
- // @Description 设置指标的图表图片接口
- // @Param request body data_manage.SetChartInfoImageReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/image/set [post]
- func (this *EdbInfoController) ChartImageSet() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.SetEdbInfoImageReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.EdbInfoId <= 0 || req.ImageUrl == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- return
- }
- edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "找不到该指标"
- return
- }
- br.Msg = "保存失败"
- br.ErrMsg = "获取指标失败, Err:" + e.Error()
- return
- }
- edbInfo.ChartImage = req.ImageUrl
- if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
- return
- }
- // 修改es数据
- go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // EdbInfoExistCheck
- // @Title 新增指标-检验指标是否存在接口
- // @Description 新增指标-检验指标是否存在接口
- // @Param Source query int true "来源:1:同花顺,2:wind"
- // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
- // @Param EdbCode query string false "指标编码/指标代码"
- // @Param StockCode query string false "证券代码"
- // @Success 200 {object} data_manage.EdbInfoExistCheckResp
- // @router /edb_info/exist/check [get]
- func (this *EdbInfoController) EdbInfoExistCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source, _ := this.GetInt("Source")
- edbCode := this.GetString("EdbCode")
- edbCode = strings.Trim(edbCode, "\t")
- edbCode = strings.Trim(edbCode, " ")
- edbCode = strings.Replace(edbCode, "\t", "", -1)
- subSource, _ := this.GetInt("SubSource")
- stockCode := this.GetString("StockCode")
- if source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- if edbCode == "" {
- br.Msg = "请输入指标ID"
- return
- }
- if source != utils.DATA_SOURCE_WIND && source != utils.DATA_SOURCE_THS {
- br.Msg = "无效的数据来源"
- return
- }
- if subSource != utils.DATA_SUB_SOURCE_DATE {
- br.Msg = "无效的数据库来源"
- return
- }
- var indexCodeArr []string
- edbCodeArr := strings.Split(edbCode, ",")
- stockCodeArr := strings.Split(stockCode, ",")
- var prefix string
- if source == utils.DATA_SOURCE_WIND {
- prefix = utils.WindDbWsd
- } else if source == utils.DATA_SOURCE_THS {
- prefix = utils.ThsDs
- } else {
- br.Msg = "来源错误"
- br.ErrMsg = "来源错误"
- return
- }
- for _, sv := range stockCodeArr {
- for _, ev := range edbCodeArr {
- indexCode := prefix + sv + ev
- indexCodeArr = append(indexCodeArr, indexCode)
- }
- }
- indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验指标是否存在失败"
- br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
- return
- }
- var existStockCodeArr []string
- var existEdbCodeArr []string
- var existClassifyId []int
- var existIndexId []int
- for _, indexItem := range indexList {
- for _, sv := range stockCodeArr {
- for _, ev := range edbCodeArr {
- if strings.Contains(indexItem.EdbCode, sv) {
- existStockCodeArr = append(existStockCodeArr, sv)
- }
- if strings.Contains(indexItem.EdbCode, ev) {
- existEdbCodeArr = append(existEdbCodeArr, ev)
- existClassifyId = append(existClassifyId, indexItem.ClassifyId)
- existIndexId = append(existIndexId, indexItem.EdbInfoId)
- }
- }
- }
- }
- resp := new(data_manage.EdbInfoExistCheckResp)
- if len(indexList) > 0 {
- resp.IndexExist = true
- }
- resp.ExistEdbCodeArr = existEdbCodeArr
- resp.ExistStockCodeArr = existStockCodeArr
- resp.ExistClassifyId = existClassifyId
- resp.ExistIndexId = existIndexId
- resp.ExistEdbInfo = indexList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoAdd
- // @Title 指标批量保存接口
- // @Description 指标批量保存接口
- // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/batch/add [post]
- func (this *EdbInfoController) EdbInfoBatchAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req data_manage.BatchAddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.AddEdbInfoResp)
- var edbNames string
- for _, v := range req.BatchList {
- edbNames += "'" + v.EdbName + "',"
- }
- edbNames = strings.Trim(edbNames, ",")
- infoList, err := data_manage.GetEdbInfoByNames(edbNames)
- if err != nil {
- br.Msg = "查询指标名称重复错误!"
- br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
- return
- }
- if len(infoList) > 0 {
- for _, v := range infoList {
- resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
- }
- br.Data = resp
- br.Msg = "指标名称重复!"
- br.ErrMsg = "指标名称重复"
- return
- }
- for k, v := range req.BatchList {
- v.EdbName = strings.Trim(v.EdbName, " ")
- v.EdbCode = strings.Trim(v.EdbCode, " ")
- v.StockCode = strings.Trim(v.StockCode, " ")
- if v.Source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- if v.EdbCode == "" {
- br.Msg = "指标ID不能为空"
- return
- }
- if v.StockCode == "" {
- br.Msg = "证券代码不能为空"
- return
- }
- if v.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if v.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if v.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- terminalCode, serverUrl, _, e := data.GetEdbTerminalCodeBySource(v.Source, v.EdbCode, v.StockCode)
- if e != nil {
- br.Msg = "获取可以使用的终端地址失败"
- br.ErrMsg = "获取可以使用的终端地址失败,Err:" + e.Error()
- return
- }
- edbInfoItem := new(data_manage.EdbInfo)
- edbInfoItem.Source = v.Source
- switch v.Source {
- case utils.DATA_SOURCE_WIND:
- edbInfoItem.SourceName = "wind"
- edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
- case utils.DATA_SOURCE_THS:
- edbInfoItem.SourceName = "ths"
- edbInfoItem.EdbCode = utils.ThsDs + v.StockCode + v.EdbCode
- }
- edbInfoItem.SubSource = utils.DATA_SUB_SOURCE_DATE
- edbInfoItem.SubSourceName = "日期序列"
- edbInfoItem.EdbName = v.EdbName
- edbInfoItem.EdbNameSource = v.EdbName
- edbInfoItem.EdbNameEn = v.EdbName
- edbInfoItem.Frequency = v.Frequency
- edbInfoItem.Unit = v.Unit
- edbInfoItem.UnitEn = v.Unit
- edbInfoItem.ClassifyId = v.ClassifyId
- edbInfoItem.SysUserId = sysUser.AdminId
- edbInfoItem.SysUserRealName = sysUser.RealName
- edbInfoItem.IndicatorCode = v.EdbCode
- edbInfoItem.StockCode = v.StockCode
- edbInfoItem.TerminalCode = terminalCode
- edbInfoItem.ServerUrl = serverUrl
- var extra data_manage.EdbInfoExtra
- if v.ApiExtraPars != "" {
- extra.ApiExtraPars = v.ApiExtraPars
- b, e := json.Marshal(extra)
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = fmt.Sprintf("额外参数JSON格式化失败, %v", e)
- return
- }
- edbInfoItem.Extra = string(b)
- }
- // 指标入库
- edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- if k <= 0 {
- resp.EdbInfoId = edbInfo.EdbInfoId
- resp.UniqueCode = edbInfo.UniqueCode
- }
- }
- // 试用平台更新用户累计新增指标数
- adminItem, e := system.GetSysAdminById(sysUser.AdminId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
- return
- }
- if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
- go func() {
- var r etaTrialService.EtaTrialUserReq
- r.Mobile = adminItem.Mobile
- _, _ = etaTrialService.UpdateUserIndexNum(r)
- }()
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // SmmExistCheck
- // @Title 新增指标-检验指标是否存在接口-smm
- // @Description 新增指标-检验指标是否存在接口-smm
- // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
- // @Param EdbCode query string false "指标编码/指标代码"
- // @Param StockCode query string false "证券代码"
- // @Success 200 {object} data_manage.EdbInfoExistCheckResp
- // @router /edb_info/smm/exist/check [post]
- func (this *EdbInfoController) SmmExistCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req data_manage.SmmIndexExistCheckReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- types := req.Types
- frequency := req.Frequency
- dataState := req.DataState
- selectAll := req.SelectAll
- keyword := req.Keyword
- edbCode := req.EdbCode
- edbCode = strings.Trim(edbCode, "\t")
- edbCode = strings.Trim(edbCode, " ")
- edbCode = strings.Replace(edbCode, "\t", "", -1)
- var edbCodeArr []string
- var codeArr []string
- if selectAll {
- // 如果勾了列表全选,那么EdbCode传的就是排除的code
- var condition string
- var pars []interface{}
- if len(types) > 0 {
- condition += " AND ( "
- for _, v := range types {
- typeArr := strings.Split(v, ",")
- for i, v := range typeArr {
- if i == 0 {
- condition += " ( "
- }
- typeStr := "type_"
- typeStr += fmt.Sprintf("%d", i+1)
- condition += typeStr + " =? "
- pars = append(pars, v)
- if i == len(typeArr)-1 {
- condition += " ) "
- } else {
- condition += " AND "
- }
- }
- condition += " OR "
- }
- condition = strings.Trim(condition, "OR ")
- condition += " ) "
- }
- if frequency != "" {
- frequencyArr := strings.Split(frequency, ",")
- condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
- pars = append(pars, frequencyArr)
- }
- if dataState != "" {
- stateArr := strings.Split(dataState, ",")
- if strings.Contains(dataState, "normal") {
- stateArr = append(stateArr, "")
- condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
- pars = append(pars, stateArr)
- } else {
- condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
- pars = append(pars, stateArr)
- }
- }
- if keyword != "" {
- keyWordArr := strings.Split(keyword, " ")
- if len(keyWordArr) > 0 {
- condition += " AND ( "
- for _, v := range keyWordArr {
- condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
- }
- condition = strings.TrimRight(condition, "OR")
- condition += " ) "
- }
- }
- indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
- if err != nil {
- br.Msg = "获取指标列表失败"
- br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
- return
- }
- for _, v := range indexList {
- codeArr = append(codeArr, v.IndexCode)
- }
- noUseCodeArr := strings.Split(edbCode, ",")
- for _, code := range codeArr {
- // 检查code是否在noUseCodeArr数组中
- if !utils.ArrContainsStr(noUseCodeArr, code) {
- // 如果不在,将其添加到结果数组中
- edbCodeArr = append(edbCodeArr, code)
- }
- }
- } else {
- //未勾选全选EdbCode就是需要的code
- edbCodeArr = strings.Split(edbCode, ",")
- }
- if len(edbCodeArr) > 30 {
- br.Msg = "最多只能选择30个指标"
- return
- }
- if len(edbCodeArr) <= 0 {
- br.Msg = "无符合指标或指标代码错误"
- return
- }
- indexList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_YS, edbCodeArr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "校验指标是否存在失败"
- br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
- return
- }
- var existEdbCodeArr []string
- var existClassifyId []int
- var existIndexId []int
- for _, indexItem := range indexList {
- for _, ev := range edbCodeArr {
- if strings.Contains(indexItem.EdbCode, ev) {
- existEdbCodeArr = append(existEdbCodeArr, ev)
- existClassifyId = append(existClassifyId, indexItem.ClassifyId)
- existIndexId = append(existIndexId, indexItem.EdbInfoId)
- }
- }
- }
- resp := new(data_manage.EdbInfoSmmExistCheckResp)
- if len(indexList) > 0 {
- resp.IndexExist = true
- }
- if len(existEdbCodeArr) == len(edbCodeArr) {
- resp.ExistAll = true
- }
- resp.ExistEdbCodeArr = existEdbCodeArr
- resp.ExistClassifyId = existClassifyId
- resp.ExistIndexId = existIndexId
- resp.ExistEdbInfo = indexList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoSearch
- // @Title 新增指标-查询指标信息接口-smm
- // @Description 新增指标-查询指标信息接口-smm
- // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
- // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
- // @Param EdbCode query string false "指标编码/指标代码"
- // @Param StockCode query string false "证券代码"
- // @Success 200 {object} data_manage.EdbInfoSearchResp
- // @router /edb_info/smm/search [post]
- func (this *EdbInfoController) EdbInfoSmmSearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req data_manage.SmmIndexExistCheckReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- types := req.Types
- frequency := req.Frequency
- dataState := req.DataState
- selectAll := req.SelectAll
- keyword := req.Keyword
- edbCode := req.EdbCode
- edbCode = strings.Trim(edbCode, "\t")
- edbCode = strings.Trim(edbCode, " ")
- edbCode = strings.Replace(edbCode, "\t", "", -1)
- var edbCodeArr []string
- var codeArr []string
- if selectAll {
- // 如果勾了列表全选,那么EdbCode传的就是排除的code
- var condition string
- var pars []interface{}
- if len(types) > 0 {
- condition += " AND ( "
- for _, v := range types {
- typeArr := strings.Split(v, ",")
- for i, v := range typeArr {
- if i == 0 {
- condition += " ( "
- }
- typeStr := "type_"
- typeStr += fmt.Sprintf("%d", i+1)
- condition += typeStr + " =? "
- pars = append(pars, v)
- if i == len(typeArr)-1 {
- condition += " ) "
- } else {
- condition += " AND "
- }
- }
- condition += " OR "
- }
- condition = strings.Trim(condition, "OR ")
- condition += " ) "
- }
- if frequency != "" {
- frequencyArr := strings.Split(frequency, ",")
- condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
- pars = append(pars, frequencyArr)
- }
- if dataState != "" {
- stateArr := strings.Split(dataState, ",")
- if strings.Contains(dataState, "normal") {
- stateArr = append(stateArr, "")
- condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
- pars = append(pars, stateArr)
- } else {
- condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
- pars = append(pars, stateArr)
- }
- }
- if keyword != "" {
- keyWordArr := strings.Split(keyword, " ")
- if len(keyWordArr) > 0 {
- condition += " AND ( "
- for _, v := range keyWordArr {
- condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
- }
- condition = strings.TrimRight(condition, "OR")
- condition += " ) "
- }
- }
- indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
- if err != nil {
- br.Msg = "获取指标列表失败"
- br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
- return
- }
- for _, v := range indexList {
- codeArr = append(codeArr, v.IndexCode)
- }
- noUseCodeArr := strings.Split(edbCode, ",")
- for _, code := range codeArr {
- // 检查code是否在noUseCodeArr数组中
- if !utils.ArrContainsStr(noUseCodeArr, code) {
- // 如果不在,将其添加到结果数组中
- edbCodeArr = append(edbCodeArr, code)
- }
- }
- } else {
- //未勾选全选EdbCode就是需要的code
- edbCodeArr = strings.Split(edbCode, ",")
- }
- if len(edbCodeArr) > 30 {
- br.Msg = "最多只能选择30个指标"
- return
- }
- if len(edbCodeArr) <= 0 {
- br.Msg = "无符合指标或指标代码错误"
- return
- }
- edbCodeStr := ""
- for i, _ := range edbCodeArr {
- edbCodeStr += "'" + edbCodeArr[i] + "'" + ","
- }
- edbCodeStr = strings.Trim(edbCodeStr, ",")
- smmInfoList, err := data_manage.GetBaseFromSmmIndexByIndexCodes(edbCodeStr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
- return
- }
- smmInfoMap := make(map[string]*data_manage.BaseFromSmmIndex)
- for _, v := range smmInfoList {
- smmInfoMap[v.IndexCode] = v
- }
- searchItemList := make([]*data_manage.EdbInfoSearch, 0)
- resp := new(data_manage.EdbInfoSearchResp)
- needAddCodeArr := make([]string, 0)
- noNeedAddCodeMap := make(map[string]string, 0)
- for _, edbCode := range edbCodeArr {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem := new(data_manage.EdbInfoSearch)
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- searchItem.Frequency = smmInfoMap[edbCode].Frequency
- searchItem.Unit = smmInfoMap[edbCode].Unit
- searchItem.EdbName = smmInfoMap[edbCode].IndexName
- searchItem.EdbCode = smmInfoMap[edbCode].IndexCode
- searchItemList = append(searchItemList, searchItem)
- noNeedAddCodeMap[edbCode] = edbCode
- } else {
- // 把需要新加的code添加到needAddCodeArr数组中,一起批量请求
- needAddCodeArr = append(needAddCodeArr, edbCode)
- }
- }
- if len(needAddCodeArr) > 0 {
- edbCode = strings.Join(needAddCodeArr, ",")
- respItem, err := data.AddEdbData(utils.DATA_SOURCE_YS, edbCode, "")
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- if respItem.Ret == 421 {
- br.Msg = "该渠道已超过添加上限"
- } else if respItem.Ret == 4052 {
- br.Msg = "该指标已下架"
- } else {
- br.Msg = "未搜索到该指标"
- }
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- }
- for _, smmInfo := range smmInfoList {
- if smmInfo != nil {
- if _, ok := noNeedAddCodeMap[smmInfo.IndexCode]; !ok {
- searchItem := new(data_manage.EdbInfoSearch)
- minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(smmInfo.IndexCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- searchItem.Frequency = smmInfo.Frequency
- searchItem.Unit = smmInfo.Unit
- searchItem.EdbName = smmInfo.IndexName
- searchItem.EdbCode = smmInfo.IndexCode
- dataList, err := data_manage.GetEdbDataAllByEdbCode(smmInfo.IndexCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
- return
- }
- searchItem.DataList = dataList
- searchItemList = append(searchItemList, searchItem)
- }
- }
- }
- resp.Status = 2
- resp.StockSearchList = searchItemList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SmmEdbInfoBatchAdd
- // @Title 指标批量保存接口-smm
- // @Description 指标批量保存接口-smm
- // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/smm/batch/add [post]
- func (this *EdbInfoController) SmmEdbInfoBatchAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req data_manage.BatchAddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.AddEdbInfoResp)
- var edbNames string
- for _, v := range req.BatchList {
- edbNames += "'" + v.EdbName + "',"
- }
- edbNames = strings.Trim(edbNames, ",")
- infoList, err := data_manage.GetEdbInfoByNames(edbNames)
- if err != nil {
- br.Msg = "查询指标名称重复错误!"
- br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
- return
- }
- if len(infoList) > 0 {
- for _, v := range infoList {
- resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
- }
- br.Data = resp
- br.Msg = "指标名称重复!"
- br.ErrMsg = "指标名称重复"
- return
- }
- for k, v := range req.BatchList {
- v.EdbName = strings.Trim(v.EdbName, " ")
- v.EdbCode = strings.Trim(v.EdbCode, " ")
- if v.Source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- if v.EdbCode == "" {
- br.Msg = "指标ID不能为空"
- return
- }
- if v.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if v.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if v.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- edbInfoItem := new(data_manage.EdbInfo)
- edbInfoItem.Source = v.Source
- edbInfoItem.SourceName = "SMM"
- edbInfoItem.EdbCode = v.EdbCode
- edbInfoItem.SubSource = 0
- edbInfoItem.SubSourceName = ""
- edbInfoItem.EdbName = v.EdbName
- edbInfoItem.EdbNameSource = v.EdbName
- edbInfoItem.EdbNameEn = v.EdbName
- edbInfoItem.Frequency = v.Frequency
- edbInfoItem.Unit = v.Unit
- edbInfoItem.UnitEn = v.Unit
- edbInfoItem.ClassifyId = v.ClassifyId
- edbInfoItem.SysUserId = sysUser.AdminId
- edbInfoItem.SysUserRealName = sysUser.RealName
- edbInfoItem.IndicatorCode = ""
- edbInfoItem.StockCode = ""
- // 指标入库
- edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- if k <= 0 {
- resp.EdbInfoId = edbInfo.EdbInfoId
- resp.UniqueCode = edbInfo.UniqueCode
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // ChartImageSetBySvg
- // @Title 设置指标的图表图片
- // @Description 设置指标的图表图片接口
- // @Param request body data_manage.SetChartInfoImageReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/image/set_by_svg [post]
- func (this *EdbInfoController) ChartImageSetBySvg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- imgData := this.GetString("Img")
- if imgData == "" {
- br.Msg = "图片参数错误"
- br.ErrMsg = "图片参数错误,Img Is Empty"
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId", 0)
- if edbInfoId <= 0 {
- br.Msg = "指标参数错误"
- br.ErrMsg = "指标参数错误,EdbInfoId Is Empty"
- return
- }
- // 通过svg图片生成图片资源地址
- resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- if edbInfoId <= 0 || resourceUrl == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- return
- }
- edbInfo, e := data_manage.GetEdbInfoById(edbInfoId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "找不到该指标"
- return
- }
- br.Msg = "保存失败"
- br.ErrMsg = "获取指标失败, Err:" + e.Error()
- return
- }
- edbInfo.ChartImage = resourceUrl
- if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
- return
- }
- // 修改es数据
- go data.AddOrEditEdbInfoToEs(edbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
|