edb_info.go 188 KB

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