edb_info.go 188 KB

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