edb_info.go 188 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403
  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.DataList = dataItems
  1698. searchItem.StartDate = indexInfo.StartDate.Format(utils.FormatDate)
  1699. searchItem.EndDate = indexInfo.EndDate.Format(utils.FormatDate)
  1700. searchItem.Frequency = indexInfo.Frequency
  1701. searchItem.Unit = indexInfo.Unit
  1702. searchItem.EdbName = indexInfo.IndexName
  1703. } else {
  1704. // 代码中没有的来源那么从edb_source中找是否有对应的
  1705. sourceItem := data_manage.EdbSourceIdMap[source]
  1706. if sourceItem == nil {
  1707. br.Msg = "无效指标来源"
  1708. return
  1709. }
  1710. // 获取指标数据
  1711. dataList, e := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1712. if e != nil {
  1713. br.Msg = "获取失败"
  1714. br.ErrMsg = "获取指标数据失败, Err: " + e.Error()
  1715. return
  1716. }
  1717. if len(dataList) > 0 {
  1718. searchItem.EdbCode = edbCode
  1719. searchItem.DataList = dataList
  1720. // 获取最大最小值
  1721. edbInfoMaxAndMinInfo, e := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1722. if e != nil && e.Error() != utils.ErrNoRow() {
  1723. br.Msg = "获取失败"
  1724. br.ErrMsg = "获取数据失败, GetEdbInfoMaxAndMinInfo Err:" + e.Error()
  1725. return
  1726. }
  1727. if edbInfoMaxAndMinInfo != nil {
  1728. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1729. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1730. }
  1731. } else {
  1732. // 新增指标数据
  1733. addRes, e := data.AddEdbData(source, edbCode, frequency)
  1734. if e != nil {
  1735. br.Msg = "获取失败"
  1736. br.ErrMsg = "获取失败,Err:" + e.Error()
  1737. return
  1738. }
  1739. if addRes == nil {
  1740. br.Msg = "获取失败"
  1741. br.ErrMsg = "新增指标数据失败, addRes nil"
  1742. return
  1743. }
  1744. if addRes.Ret != 200 {
  1745. br.Msg = "未搜索到该指标, " + addRes.Msg
  1746. //br.ErrMsg = addRes.ErrMsg + ";EdbCode:" + edbCode
  1747. br.Success = true
  1748. return
  1749. }
  1750. isAdd = true
  1751. }
  1752. // 查询基本信息
  1753. baseIndexInfo, tErr := data_manage.GetBaseIndexInfoByEdbCode(edbCode, source)
  1754. if tErr == nil {
  1755. searchItem.EdbName = baseIndexInfo.IndexName
  1756. searchItem.Frequency = baseIndexInfo.Frequency
  1757. searchItem.Unit = baseIndexInfo.Unit
  1758. }
  1759. // 指标来源于桥接服务: 桥接服务获取指标取频度信息等
  1760. if sourceItem.BridgeFlag != "" {
  1761. bridgeOb := data.InitBridgeOB(sourceItem.BridgeFlag)
  1762. if bridgeOb != nil {
  1763. var r data.GetIndexFromBridgeReq
  1764. r.IndexCode = edbCode
  1765. r.Source = sourceItem.EdbSourceId
  1766. r.SourceExtend = sourceItem.SourceExtend
  1767. r.IndexCodeRequired = sourceItem.EdbCodeRequired
  1768. bridgeIndex, e := bridgeOb.GetIndex(r)
  1769. if e != nil {
  1770. br.Msg = "获取失败"
  1771. br.ErrMsg = "桥接服务获取指标信息失败, Err: " + e.Error()
  1772. return
  1773. }
  1774. searchItem.EdbName = bridgeIndex.IndexName
  1775. searchItem.Frequency = bridgeIndex.Frequency
  1776. searchItem.Unit = bridgeIndex.Unit
  1777. }
  1778. }
  1779. }
  1780. if isAdd {
  1781. if subSource == utils.DATA_SUB_SOURCE_DATE {
  1782. if source == utils.DATA_SOURCE_WIND {
  1783. //wsdData := windWsdRespItem.Data
  1784. //var buf bytes.Buffer
  1785. //// 创建一个encoder并指定目标为buf
  1786. //enc := gob.NewEncoder(&buf)
  1787. //
  1788. //// 将data编码到buf中
  1789. //err = enc.Encode(wsdData)
  1790. //if err != nil {
  1791. // br.Msg = "获取失败"
  1792. // br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error()
  1793. // return
  1794. //}
  1795. //
  1796. //wsdDataMap := make(map[string]map[string]interface{})
  1797. //err = json.Unmarshal(buf.Bytes(), &wsdDataMap)
  1798. //if err != nil {
  1799. // br.Msg = "获取失败"
  1800. // br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error()
  1801. // return
  1802. //}
  1803. //
  1804. //stockList := make([]*data_manage.StockInfo, 0)
  1805. //
  1806. //dataList := make([]*data_manage.EdbInfoSearchData, 0)
  1807. //for wk, wv := range wsdDataMap {
  1808. // for vk, vv := range wv {
  1809. // wkInt, err := strconv.ParseInt(wk, 10, 64)
  1810. // if err != nil {
  1811. // br.Msg = "获取失败"
  1812. // br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error()
  1813. // return
  1814. // }
  1815. //
  1816. // vk = strings.ToLower(vk)
  1817. // wkInt = wkInt / 1000
  1818. // t := time.Unix(wkInt, 0)
  1819. // dateTime := t.Format(utils.FormatDate)
  1820. // //saveVal := utils.SubFloatToString(val, 20)
  1821. // if vv == nil {
  1822. // continue
  1823. // }
  1824. // var saveVal string
  1825. // switch vt := vv.(type) {
  1826. // case int:
  1827. // saveVal = strconv.Itoa(vt)
  1828. // case float64:
  1829. // saveVal = utils.SubFloatToFloatStr(vt, 20)
  1830. // case string:
  1831. // saveVal = vt
  1832. // }
  1833. //
  1834. // dataItem := new(data_manage.EdbInfoSearchData)
  1835. // dataItem.Value = saveVal
  1836. // dataItem.DataTime = dateTime
  1837. // dataList = append(dataList, dataItem)
  1838. // if len(dataList) >= 10 {
  1839. // break
  1840. // }
  1841. // }
  1842. //}
  1843. //searchItem.StockList = stockList
  1844. stockList := make([]*data_manage.StockInfo, 0)
  1845. edbCodeArr := strings.Split(edbCode, ",")
  1846. for _, v := range edbCodeArr {
  1847. indexCode := utils.WindDbWsd + stockCode + v
  1848. dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
  1849. if err != nil && err.Error() != utils.ErrNoRow() {
  1850. br.Msg = "获取失败"
  1851. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  1852. return
  1853. }
  1854. stockInfo := new(data_manage.StockInfo)
  1855. stockInfo.StockCode = stockCode
  1856. stockInfo.EdbCode = v
  1857. stockInfo.DataList = dataList
  1858. stockList = append(stockList, stockInfo)
  1859. }
  1860. searchItem.StockList = stockList
  1861. } else if source == utils.DATA_SOURCE_THS {
  1862. stockList := make([]*data_manage.StockInfo, 0)
  1863. edbCodeArr := strings.Split(edbCode, ",")
  1864. for _, v := range edbCodeArr {
  1865. indexCode := utils.ThsDs + stockCode + v
  1866. dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT)
  1867. if err != nil && err.Error() != utils.ErrNoRow() {
  1868. br.Msg = "获取失败"
  1869. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  1870. return
  1871. }
  1872. stockInfo := new(data_manage.StockInfo)
  1873. stockInfo.StockCode = stockCode
  1874. stockInfo.EdbCode = v
  1875. stockInfo.DataList = dataList
  1876. stockList = append(stockList, stockInfo)
  1877. }
  1878. searchItem.StockList = stockList
  1879. } else {
  1880. br.Msg = "来源错误"
  1881. br.ErrMsg = "来源错误"
  1882. return
  1883. }
  1884. } else {
  1885. dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT)
  1886. if err != nil && err.Error() != utils.ErrNoRow() {
  1887. br.Msg = "获取失败"
  1888. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  1889. return
  1890. }
  1891. searchItem.DataList = dataList
  1892. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1893. if err != nil && err.Error() != utils.ErrNoRow() {
  1894. br.Msg = "获取失败"
  1895. br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
  1896. return
  1897. }
  1898. searchItem.EdbCode = edbCode
  1899. searchItem.DataList = dataList
  1900. if edbInfoMaxAndMinInfo != nil {
  1901. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1902. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1903. }
  1904. //edb指标信息
  1905. edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode)
  1906. if edbInfoItem != nil {
  1907. searchItem.EdbName = edbInfoItem.EdbName
  1908. }
  1909. }
  1910. }
  1911. resp.Status = 2
  1912. resp.SearchItem = searchItem
  1913. }
  1914. //如果不在指标库中,且不是新增
  1915. if !isInEdb && !isAdd {
  1916. if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 {
  1917. br.Msg = "目标指标无有效值,请重新搜索"
  1918. br.Data = resp
  1919. return
  1920. }
  1921. }
  1922. br.Ret = 200
  1923. br.Success = true
  1924. br.Msg = "获取成功"
  1925. br.Data = resp
  1926. }
  1927. // EdbInfoList
  1928. // @Title 指标列表接口
  1929. // @Description 指标列表接口
  1930. // @Param PageSize query int true "每页数据条数"
  1931. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1932. // @Param EdbInfoId query int true "指标id"
  1933. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  1934. // @Success 200 {object} data_manage.EdbInfoListResp
  1935. // @router /edb_info/list [get]
  1936. func (this *EdbInfoController) EdbInfoList() {
  1937. br := new(models.BaseResponse).Init()
  1938. defer func() {
  1939. this.Data["json"] = br
  1940. this.ServeJSON()
  1941. }()
  1942. edbInfoId, _ := this.GetInt("EdbInfoId")
  1943. keyWord := this.GetString("KeyWord")
  1944. pageSize, _ := this.GetInt("PageSize")
  1945. currentIndex, _ := this.GetInt("CurrentIndex")
  1946. var total int
  1947. page := paging.GetPaging(currentIndex, pageSize, total)
  1948. var startSize int
  1949. if pageSize <= 0 {
  1950. pageSize = utils.PageSize20
  1951. }
  1952. if currentIndex <= 0 {
  1953. currentIndex = 1
  1954. }
  1955. startSize = paging.StartIndex(currentIndex, pageSize)
  1956. var condition string
  1957. var pars []interface{}
  1958. //if edbInfoId <= 0 && keyWord == "" {
  1959. // br.Msg = "参数错误"
  1960. // return
  1961. //}
  1962. // 指标类型,0:普通指标,1:预测指标
  1963. condition += " AND edb_info_type=? "
  1964. pars = append(pars, 0)
  1965. if edbInfoId > 0 {
  1966. condition += " AND edb_info_id=? "
  1967. pars = append(pars, edbInfoId)
  1968. // 获取当前账号的不可见指标配置
  1969. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1970. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId)
  1971. if err != nil && err.Error() != utils.ErrNoRow() {
  1972. br.Msg = "获取失败"
  1973. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  1974. return
  1975. }
  1976. if conf != nil {
  1977. br.Msg = "无权限,请联系管理员"
  1978. br.IsSendEmail = false
  1979. return
  1980. }
  1981. }
  1982. if keyWord != "" {
  1983. condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  1984. //pars = append(pars, keyWord)
  1985. //pars = append(pars, keyWord)
  1986. }
  1987. resp := new(data_manage.EdbInfoListResp)
  1988. if condition == "" {
  1989. item := new(data_manage.EdbInfoList)
  1990. resp.Paging = page
  1991. resp.Item = item
  1992. br.Ret = 200
  1993. br.Success = true
  1994. br.Msg = "获取成功"
  1995. return
  1996. }
  1997. //获取指标信息
  1998. edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
  1999. if err != nil && err.Error() != utils.ErrNoRow() {
  2000. br.Success = true
  2001. br.Msg = "获取指标信息失败"
  2002. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2003. return
  2004. }
  2005. if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  2006. item := new(data_manage.EdbInfoList)
  2007. resp.Paging = page
  2008. resp.Item = item
  2009. br.Ret = 200
  2010. br.Success = true
  2011. br.Msg = "获取成功"
  2012. return
  2013. }
  2014. //获取英文频度
  2015. edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
  2016. //查询目录
  2017. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId)
  2018. if err != nil {
  2019. br.Msg = err.Error()
  2020. br.ErrMsg = errMsg
  2021. return
  2022. }
  2023. // 权限校验
  2024. {
  2025. var currClassify *data_manage.EdbClassifyIdItems
  2026. for _, v := range classifyList {
  2027. if edbInfoItem.ClassifyId == v.ClassifyId {
  2028. currClassify = v
  2029. break
  2030. }
  2031. }
  2032. if currClassify != nil {
  2033. edbInfoItem.HaveOperaAuth, err = data_manage_permission.CheckEdbPermission(edbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfoItem.EdbInfoId, edbInfoItem.ClassifyId)
  2034. if err != nil {
  2035. br.Msg = err.Error()
  2036. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2037. return
  2038. }
  2039. }
  2040. }
  2041. // 按钮校验
  2042. button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType, edbInfoItem.HaveOperaAuth)
  2043. button.AddButton = false
  2044. edbInfoItem.Button = button
  2045. edbInfoItem.DataList = make([]*data_manage.EdbData, 0)
  2046. // 如果有数据权限,那么就去获取指标数据
  2047. if edbInfoItem.HaveOperaAuth {
  2048. var dataCondition string
  2049. var dataPars []interface{}
  2050. dataCondition += ` AND edb_info_id=? `
  2051. dataPars = append(dataPars, edbInfoItem.EdbInfoId)
  2052. if edbInfoItem.SubSource == utils.DATA_SUB_SOURCE_DATE {
  2053. if edbInfoItem.Source == utils.DATA_SOURCE_WIND {
  2054. dataCount, err := data_manage.GetEdbWsdDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
  2055. if err != nil && err.Error() != utils.ErrNoRow() {
  2056. br.Msg = "获取指标信息失败"
  2057. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  2058. return
  2059. }
  2060. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  2061. dataList, err := data_manage.GetEdbWsdDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
  2062. if err != nil {
  2063. br.Msg = "获取指标信息失败"
  2064. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2065. return
  2066. }
  2067. edbInfoItem.DataList = dataList
  2068. } else if edbInfoItem.Source == utils.DATA_SOURCE_THS {
  2069. dataCount, err := data_manage.GetTHsDsDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
  2070. if err != nil && err.Error() != utils.ErrNoRow() {
  2071. br.Msg = "获取指标信息失败"
  2072. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  2073. return
  2074. }
  2075. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  2076. dataList, err := data_manage.GetThsDsDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
  2077. if err != nil {
  2078. br.Msg = "获取指标信息失败"
  2079. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2080. return
  2081. }
  2082. edbInfoItem.DataList = dataList
  2083. } else {
  2084. br.Msg = "指标数据源id错误"
  2085. br.ErrMsg = "指标数据源id错误"
  2086. return
  2087. }
  2088. } else {
  2089. dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source, edbInfoItem.SubSource)
  2090. if err != nil && err.Error() != utils.ErrNoRow() {
  2091. br.Msg = "获取指标信息失败"
  2092. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  2093. return
  2094. }
  2095. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  2096. dataList, err := data_manage.GetEdbDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, edbInfoItem.SubSource, pageSize, startSize)
  2097. if err != nil {
  2098. br.Msg = "获取指标信息失败"
  2099. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2100. return
  2101. }
  2102. edbInfoItem.DataList = dataList
  2103. }
  2104. }
  2105. // 获取指标插入配置
  2106. {
  2107. edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId)
  2108. if err != nil && err.Error() != utils.ErrNoRow() {
  2109. br.Msg = "获取指标信息失败"
  2110. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2111. return
  2112. }
  2113. if edbDataInsertConfig != nil {
  2114. edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate)
  2115. edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate)
  2116. edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value
  2117. }
  2118. }
  2119. //是否展示英文标识
  2120. edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn)
  2121. resp.Paging = page
  2122. resp.Item = edbInfoItem
  2123. resp.ClassifyList = classifyList
  2124. br.Ret = 200
  2125. br.Success = true
  2126. br.Msg = "获取成功"
  2127. br.Data = resp
  2128. }
  2129. // EdbInfoAdd
  2130. // @Title 新增指标接口
  2131. // @Description 新增指标接口
  2132. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  2133. // @Success Ret=200 保存成功
  2134. // @router /edb_info/add [post]
  2135. func (this *EdbInfoController) EdbInfoAdd() {
  2136. br := new(models.BaseResponse).Init()
  2137. defer func() {
  2138. this.Data["json"] = br
  2139. this.ServeJSON()
  2140. }()
  2141. sysUser := this.SysUser
  2142. if sysUser == nil {
  2143. br.Msg = "请登录"
  2144. br.ErrMsg = "请登录,SysUser Is Empty"
  2145. br.Ret = 408
  2146. return
  2147. }
  2148. deleteCache := true
  2149. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  2150. defer func() {
  2151. if deleteCache {
  2152. utils.Rc.Delete(cacheKey)
  2153. }
  2154. }()
  2155. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  2156. deleteCache = false
  2157. br.Msg = "系统处理中,请稍后重试!"
  2158. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  2159. return
  2160. }
  2161. var req data_manage.AddEdbInfoReq
  2162. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2163. if err != nil {
  2164. br.Msg = "参数解析异常!"
  2165. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2166. return
  2167. }
  2168. source := req.Source
  2169. if source <= 0 {
  2170. br.Msg = "无效的数据来源"
  2171. return
  2172. }
  2173. req.EdbName = strings.Trim(req.EdbName, " ")
  2174. req.EdbCode = strings.Trim(req.EdbCode, " ")
  2175. if req.EdbCode == "" {
  2176. br.Msg = "指标ID不能为空"
  2177. return
  2178. }
  2179. if req.EdbName == "" {
  2180. br.Msg = "指标名称不能为空"
  2181. return
  2182. }
  2183. if req.Frequency == "" {
  2184. br.Msg = "频率不能为空"
  2185. return
  2186. }
  2187. if req.Unit == "" {
  2188. br.Msg = "单位不能为空"
  2189. return
  2190. }
  2191. if req.ClassifyId <= 0 {
  2192. br.Msg = "请选择分类"
  2193. return
  2194. }
  2195. //if req.StartDate == "" || req.EndDate == "" {
  2196. // br.Msg = "日期不能为空"
  2197. // return
  2198. //}
  2199. // 兼容钢联与钢联化工数据
  2200. if source == utils.DATA_SOURCE_GL {
  2201. // 如果是钢联的话,那么就先判断是不是存在钢联化工
  2202. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
  2203. if err != nil {
  2204. if err.Error() != utils.ErrNoRow() {
  2205. br.Msg = "获取失败"
  2206. br.ErrMsg = "获取失败,Err:" + err.Error()
  2207. return
  2208. }
  2209. }
  2210. if tmpInfo != nil {
  2211. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  2212. req.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  2213. }
  2214. }
  2215. // 指标入库
  2216. 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)
  2217. if err != nil {
  2218. br.Msg = "保存失败"
  2219. if errMsg != `` {
  2220. br.Msg = errMsg
  2221. }
  2222. br.ErrMsg = err.Error()
  2223. br.IsSendEmail = isSendEmail
  2224. return
  2225. }
  2226. // 试用平台更新用户累计新增指标数
  2227. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  2228. if e != nil {
  2229. br.Msg = "操作失败"
  2230. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  2231. return
  2232. }
  2233. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  2234. go func() {
  2235. var r etaTrialService.EtaTrialUserReq
  2236. r.Mobile = adminItem.Mobile
  2237. _, _ = etaTrialService.UpdateUserIndexNum(r)
  2238. }()
  2239. }
  2240. //新增操作日志
  2241. {
  2242. // 添加钢联指标更新日志
  2243. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2244. go data_stat.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", sysUser, 2)
  2245. }
  2246. edbLog := new(data_manage.EdbInfoLog)
  2247. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2248. edbLog.SourceName = edbInfo.SourceName
  2249. edbLog.Source = edbInfo.Source
  2250. edbLog.EdbCode = edbInfo.EdbCode
  2251. edbLog.EdbName = edbInfo.EdbName
  2252. edbLog.ClassifyId = edbInfo.ClassifyId
  2253. edbLog.SysUserId = sysUser.AdminId
  2254. edbLog.SysUserRealName = sysUser.RealName
  2255. edbLog.CreateTime = time.Now()
  2256. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2257. edbLog.Status = "新增指标"
  2258. edbLog.Method = this.Ctx.Input.URI()
  2259. go data_manage.AddEdbInfoLog(edbLog)
  2260. }
  2261. // 更新es
  2262. go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  2263. resp := new(data_manage.AddEdbInfoResp)
  2264. resp.EdbInfoId = edbInfo.EdbInfoId
  2265. resp.UniqueCode = edbInfo.UniqueCode
  2266. br.Ret = 200
  2267. br.Success = true
  2268. br.Msg = "保存成功"
  2269. br.Data = resp
  2270. br.IsAddLog = true
  2271. }
  2272. // EdbInfoEdit
  2273. // @Title 编辑指标接口
  2274. // @Description 编辑指标接口
  2275. // @Success 200 {object} data_manage.EditEdbInfoReq
  2276. // @router /edb_info/edit [post]
  2277. func (this *EdbInfoController) EdbInfoEdit() {
  2278. br := new(models.BaseResponse).Init()
  2279. defer func() {
  2280. this.Data["json"] = br
  2281. this.ServeJSON()
  2282. }()
  2283. sysUser := this.SysUser
  2284. if sysUser == nil {
  2285. br.Msg = "请登录"
  2286. br.ErrMsg = "请登录,SysUser Is Empty"
  2287. br.Ret = 408
  2288. return
  2289. }
  2290. var req data_manage.EditEdbInfoReq
  2291. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2292. if err != nil {
  2293. br.Msg = "参数解析异常!"
  2294. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2295. return
  2296. }
  2297. req.EdbName = strings.Trim(req.EdbName, " ")
  2298. if req.EdbInfoId <= 0 {
  2299. br.Msg = "参数错误"
  2300. br.ErrMsg = "指标id小于等于0"
  2301. return
  2302. }
  2303. if req.EdbName == "" {
  2304. br.Msg = "指标名称不能为空"
  2305. return
  2306. }
  2307. if req.Frequency == "" {
  2308. br.Msg = "频率不能为空"
  2309. return
  2310. }
  2311. if req.Unit == "" {
  2312. br.Msg = "单位不能为空"
  2313. return
  2314. }
  2315. if req.ClassifyId <= 0 {
  2316. br.Msg = "请选择分类"
  2317. return
  2318. }
  2319. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2320. if err != nil {
  2321. br.Msg = "修改失败"
  2322. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2323. return
  2324. }
  2325. // 记录旧的指标基本信息
  2326. oldEdbName := edbInfo.EdbName
  2327. oldFrequency := edbInfo.Frequency
  2328. oldUnit := edbInfo.Unit
  2329. var haveOperaAuth bool
  2330. // 权限校验
  2331. {
  2332. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
  2333. if err != nil {
  2334. br.Msg = err.Error()
  2335. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2336. return
  2337. }
  2338. }
  2339. // 编辑权限校验
  2340. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  2341. if !button.OpButton {
  2342. br.Msg = "无权限操作"
  2343. br.IsSendEmail = false
  2344. return
  2345. }
  2346. //判断指标名称是否存在
  2347. var condition string
  2348. var pars []interface{}
  2349. condition += " AND edb_info_id<>? "
  2350. pars = append(pars, req.EdbInfoId)
  2351. //condition += " AND source=? "
  2352. //pars = append(pars, edbInfo.Source)
  2353. updateCols := make([]string, 0)
  2354. switch this.Lang {
  2355. case utils.EnLangVersion:
  2356. condition += " AND edb_name_en = ? "
  2357. edbInfo.EdbNameEn = req.EdbName
  2358. edbInfo.Frequency = req.Frequency
  2359. edbInfo.UnitEn = req.Unit
  2360. edbInfo.ClassifyId = req.ClassifyId
  2361. updateCols = append(updateCols, "EdbNameEn", "Frequency", "UnitEn", "ClassifyId")
  2362. default:
  2363. condition += " AND edb_name=? "
  2364. edbInfo.EdbName = req.EdbName
  2365. edbInfo.EdbNameSource = req.EdbName
  2366. edbInfo.Frequency = req.Frequency
  2367. edbInfo.Unit = req.Unit
  2368. edbInfo.ClassifyId = req.ClassifyId
  2369. updateCols = append(updateCols, "EdbNameEn", "EdbNameSource", "Frequency", "UnitEn", "ClassifyId")
  2370. }
  2371. pars = append(pars, req.EdbName)
  2372. count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
  2373. if err != nil {
  2374. br.Msg = "判断指标名称是否存在失败"
  2375. br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error()
  2376. return
  2377. }
  2378. if count > 0 {
  2379. br.Msg = "指标名称已存在,请重新填写"
  2380. br.ErrMsg = "指标名称已存在,请重新填写"
  2381. br.IsSendEmail = false
  2382. return
  2383. }
  2384. if len(updateCols) > 0 {
  2385. err = edbInfo.Update(updateCols)
  2386. if err != nil {
  2387. br.Msg = "保存失败"
  2388. br.ErrMsg = "修改失败,Err:" + err.Error()
  2389. return
  2390. }
  2391. }
  2392. //处理同名指标
  2393. //{
  2394. // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName)
  2395. // if err != nil {
  2396. // br.Msg = "保存失败"
  2397. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2398. // return
  2399. // }
  2400. // if len(edbNameList) >= 2 {
  2401. // for _, v := range edbNameList {
  2402. // edbName := v.EdbName + "(" + v.SourceName + ")"
  2403. // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
  2404. // if err != nil {
  2405. // br.Msg = "保存失败"
  2406. // br.ErrMsg = "修改指标名称失败,Err:" + err.Error()
  2407. // return
  2408. // }
  2409. // }
  2410. // }
  2411. //}
  2412. // 新增保存记录日志
  2413. oldEdbInfo := new(data_manage.EdbInfo)
  2414. oldEdbInfo.EdbInfoId = edbInfo.EdbInfoId
  2415. oldEdbInfo.EdbName = oldEdbName
  2416. oldEdbInfo.Frequency = oldFrequency
  2417. oldEdbInfo.Unit = oldUnit
  2418. newEdbInfoRecord := new(data_manage.EdbInfoEditRecord)
  2419. newEdbInfoRecord.EdbName = req.EdbName
  2420. newEdbInfoRecord.Frequency = req.Frequency
  2421. newEdbInfoRecord.Unit = req.Unit
  2422. newEdbInfoRecord.OperateUserId = sysUser.AdminId
  2423. newEdbInfoRecord.OperateUserRealName = sysUser.RealName
  2424. go data.AddEditEdbInfoRcord(oldEdbInfo, newEdbInfoRecord)
  2425. //新增操作日志
  2426. {
  2427. edbLog := new(data_manage.EdbInfoLog)
  2428. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2429. edbLog.SourceName = edbInfo.SourceName
  2430. edbLog.Source = edbInfo.Source
  2431. edbLog.EdbCode = edbInfo.EdbCode
  2432. edbLog.EdbName = edbInfo.EdbName
  2433. edbLog.ClassifyId = edbInfo.ClassifyId
  2434. edbLog.SysUserId = sysUser.AdminId
  2435. edbLog.SysUserRealName = sysUser.RealName
  2436. edbLog.CreateTime = time.Now()
  2437. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2438. edbLog.Status = "编辑指标"
  2439. edbLog.Method = this.Ctx.Input.URI()
  2440. go data_manage.AddEdbInfoLog(edbLog)
  2441. }
  2442. //添加es
  2443. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2444. switch this.Lang {
  2445. case utils.EnLangVersion:
  2446. // 修改关联的预测指标基础信息
  2447. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
  2448. default:
  2449. // 修改关联的预测指标基础信息
  2450. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, req.Frequency, req.Unit)
  2451. }
  2452. // 添加钢联指标更新日志
  2453. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2454. if edbInfo.EdbName != req.EdbName || edbInfo.Frequency != req.Frequency || edbInfo.Unit != req.Unit {
  2455. go data_stat.AddEdbInfoUpdateLog(req.EdbInfoId, 1, "", sysUser, 1)
  2456. }
  2457. }
  2458. br.Ret = 200
  2459. br.Success = true
  2460. br.Msg = "保存成功"
  2461. br.IsAddLog = true
  2462. }
  2463. // EdbEnInfoEdit
  2464. // @Title 编辑指标英文信息接口
  2465. // @Description 编辑指标英文信息接口
  2466. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  2467. // @router /edb_info/en/edit [post]
  2468. func (this *EdbInfoController) EdbEnInfoEdit() {
  2469. br := new(models.BaseResponse).Init()
  2470. defer func() {
  2471. this.Data["json"] = br
  2472. this.ServeJSON()
  2473. }()
  2474. sysUser := this.SysUser
  2475. if sysUser == nil {
  2476. br.Msg = "请登录"
  2477. br.ErrMsg = "请登录,SysUser Is Empty"
  2478. br.Ret = 408
  2479. return
  2480. }
  2481. var req data_manage.EditEdbEnInfoReq
  2482. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2483. if err != nil {
  2484. br.Msg = "参数解析异常!"
  2485. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2486. return
  2487. }
  2488. req.EdbNameEn = strings.Trim(req.EdbNameEn, " ")
  2489. req.UnitEn = strings.Trim(req.UnitEn, " ")
  2490. if req.EdbInfoId <= 0 {
  2491. br.Msg = "参数错误"
  2492. br.ErrMsg = "指标id小于等于0"
  2493. return
  2494. }
  2495. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2496. if err != nil {
  2497. br.Msg = "获取指标信息失败"
  2498. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2499. return
  2500. }
  2501. if req.EdbNameEn != "" {
  2502. //判断指标名称是否存在
  2503. var condition string
  2504. var pars []interface{}
  2505. condition += " AND edb_info_id<>? "
  2506. pars = append(pars, req.EdbInfoId)
  2507. /*condition += " AND source=? "
  2508. pars = append(pars, edbInfo.Source)*/
  2509. condition += " AND edb_name_en=? "
  2510. pars = append(pars, req.EdbNameEn)
  2511. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2512. if err != nil {
  2513. if err.Error() != utils.ErrNoRow() {
  2514. br.Msg = "判断英文指标名称是否存在失败"
  2515. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2516. return
  2517. }
  2518. }
  2519. if err == nil && edbExist.EdbInfoId > 0 {
  2520. br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在"
  2521. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2522. br.IsSendEmail = false
  2523. return
  2524. }
  2525. }
  2526. err = data_manage.ModifyEdbEnInfo(&req)
  2527. if err != nil {
  2528. br.Msg = "保存失败"
  2529. br.ErrMsg = "修改失败,Err:" + err.Error()
  2530. return
  2531. }
  2532. //新增操作日志
  2533. {
  2534. edbLog := new(data_manage.EdbInfoLog)
  2535. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2536. edbLog.SourceName = edbInfo.SourceName
  2537. edbLog.Source = edbInfo.Source
  2538. edbLog.EdbCode = edbInfo.EdbCode
  2539. edbLog.EdbName = edbInfo.EdbName
  2540. edbLog.ClassifyId = edbInfo.ClassifyId
  2541. edbLog.SysUserId = sysUser.AdminId
  2542. edbLog.SysUserRealName = sysUser.RealName
  2543. edbLog.CreateTime = time.Now()
  2544. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2545. edbLog.Status = "编辑指标英文信息"
  2546. edbLog.Method = this.Ctx.Input.URI()
  2547. go data_manage.AddEdbInfoLog(edbLog)
  2548. }
  2549. //添加es
  2550. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2551. // 修改关联的预测指标基础信息
  2552. if edbInfo.EdbInfoType == 0 {
  2553. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.UnitEn)
  2554. }
  2555. br.Ret = 200
  2556. br.Success = true
  2557. br.Msg = "保存成功"
  2558. br.IsAddLog = true
  2559. }
  2560. // EdbInfoBaseEdit
  2561. // @Title 编辑指标基础信息接口
  2562. // @Description 编辑指标基础信息接口
  2563. // @Success 200 {object} data_manage.EditEdbBaseInfoReq
  2564. // @router /edb_info/base/edit [post]
  2565. func (this *EdbInfoController) EdbInfoBaseEdit() {
  2566. br := new(models.BaseResponse).Init()
  2567. defer func() {
  2568. this.Data["json"] = br
  2569. this.ServeJSON()
  2570. }()
  2571. sysUser := this.SysUser
  2572. if sysUser == nil {
  2573. br.Msg = "请登录"
  2574. br.ErrMsg = "请登录,SysUser Is Empty"
  2575. br.Ret = 408
  2576. return
  2577. }
  2578. var req data_manage.EditEdbBaseInfoReq
  2579. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2580. if err != nil {
  2581. br.Msg = "参数解析异常!"
  2582. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2583. return
  2584. }
  2585. req.EdbName = strings.Trim(req.EdbName, " ")
  2586. req.Unit = strings.Trim(req.Unit, " ")
  2587. if req.EdbInfoId <= 0 {
  2588. br.Msg = "参数错误"
  2589. br.ErrMsg = "指标id小于等于0"
  2590. return
  2591. }
  2592. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2593. if err != nil {
  2594. br.Msg = "获取指标信息失败"
  2595. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2596. return
  2597. }
  2598. updateCols := make([]string, 0)
  2599. if req.EdbName != "" {
  2600. //判断指标名称是否存在
  2601. var condition string
  2602. var pars []interface{}
  2603. condition += " AND edb_info_id<>? "
  2604. pars = append(pars, req.EdbInfoId)
  2605. /*condition += " AND source=? "
  2606. pars = append(pars, edbInfo.Source)*/
  2607. switch this.Lang {
  2608. case utils.EnLangVersion:
  2609. condition += " AND edb_name_en = ? "
  2610. edbInfo.EdbNameEn = req.EdbName
  2611. edbInfo.UnitEn = req.Unit
  2612. edbInfo.ModifyTime = time.Now()
  2613. updateCols = append(updateCols, "EdbNameEn", "UnitEn", "ModifyTime")
  2614. default:
  2615. condition += " AND edb_name = ? "
  2616. edbInfo.EdbName = req.EdbName
  2617. edbInfo.EdbNameSource = req.EdbName
  2618. edbInfo.Unit = req.Unit
  2619. edbInfo.ModifyTime = time.Now()
  2620. updateCols = append(updateCols, "EdbName", "EdbNameSource", "Unit", "ModifyTime")
  2621. }
  2622. pars = append(pars, req.EdbName)
  2623. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2624. if err != nil {
  2625. if err.Error() != utils.ErrNoRow() {
  2626. br.Msg = "判断英文指标名称是否存在失败"
  2627. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2628. return
  2629. }
  2630. }
  2631. if err == nil && edbExist.EdbInfoId > 0 {
  2632. br.Msg = edbExist.EdbName + ":" + req.EdbName + "指标名称已存在"
  2633. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2634. br.IsSendEmail = false
  2635. return
  2636. }
  2637. }
  2638. if len(updateCols) > 0 {
  2639. err = edbInfo.Update(updateCols)
  2640. if err != nil {
  2641. br.Msg = "保存失败"
  2642. br.ErrMsg = "修改失败,Err:" + err.Error()
  2643. return
  2644. }
  2645. }
  2646. //新增操作日志
  2647. {
  2648. edbLog := new(data_manage.EdbInfoLog)
  2649. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2650. edbLog.SourceName = edbInfo.SourceName
  2651. edbLog.Source = edbInfo.Source
  2652. edbLog.EdbCode = edbInfo.EdbCode
  2653. edbLog.EdbName = edbInfo.EdbName
  2654. edbLog.ClassifyId = edbInfo.ClassifyId
  2655. edbLog.SysUserId = sysUser.AdminId
  2656. edbLog.SysUserRealName = sysUser.RealName
  2657. edbLog.CreateTime = time.Now()
  2658. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2659. edbLog.Status = "编辑指标英文信息"
  2660. edbLog.Method = this.Ctx.Input.URI()
  2661. go data_manage.AddEdbInfoLog(edbLog)
  2662. }
  2663. //添加es
  2664. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2665. // 修改关联的预测指标基础信息
  2666. if edbInfo.EdbInfoType == 0 {
  2667. switch this.Lang {
  2668. case utils.EnLangVersion:
  2669. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
  2670. default:
  2671. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, edbInfo.Frequency, req.Unit)
  2672. }
  2673. }
  2674. br.Ret = 200
  2675. br.Success = true
  2676. br.Msg = "保存成功"
  2677. br.IsAddLog = true
  2678. }
  2679. // EdbInfoNewest
  2680. // @Title 获取最新指标接口
  2681. // @Description 获取最新指标接口
  2682. // @Success 200 {object} data_manage.EdbInfoList
  2683. // @router /edb_info/newest [get]
  2684. func (this *EdbInfoController) EdbInfoNewest() {
  2685. br := new(models.BaseResponse).Init()
  2686. defer func() {
  2687. this.Data["json"] = br
  2688. this.ServeJSON()
  2689. }()
  2690. item, err := data_manage.GetEdbInfoByNewest()
  2691. if err != nil && err.Error() != utils.ErrNoRow() {
  2692. br.Msg = "获取最新指标失败"
  2693. br.ErrMsg = "获取最新指标失败,Err:" + err.Error()
  2694. return
  2695. }
  2696. br.Ret = 200
  2697. br.Success = true
  2698. br.Msg = "获取成功"
  2699. br.Data = item
  2700. }
  2701. // EdbInfoRefresh
  2702. // @Title 指标刷新接口
  2703. // @Description 指标刷新接口
  2704. // @Param EdbInfoId query int true "指标id"
  2705. // @Success Ret=200 刷新成功
  2706. // @router /edb_info/refresh [get]
  2707. func (this *EdbInfoController) EdbInfoRefresh() {
  2708. br := new(models.BaseResponse).Init()
  2709. defer func() {
  2710. this.Data["json"] = br
  2711. this.ServeJSON()
  2712. }()
  2713. sysUser := this.SysUser
  2714. if sysUser == nil {
  2715. br.Msg = "请登录"
  2716. br.ErrMsg = "请登录,SysUser Is Empty"
  2717. br.Ret = 408
  2718. return
  2719. }
  2720. edbInfoId, _ := this.GetInt("EdbInfoId")
  2721. if edbInfoId <= 0 {
  2722. br.Msg = "参数错误"
  2723. br.ErrMsg = "参数错误"
  2724. return
  2725. }
  2726. _, err := data_manage.GetEdbInfoById(edbInfoId)
  2727. if err != nil {
  2728. if err.Error() == utils.ErrNoRow() {
  2729. br.Msg = "数据已被删除,请刷新页面"
  2730. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2731. return
  2732. }
  2733. br.Msg = "刷新失败"
  2734. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2735. return
  2736. }
  2737. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false, false)
  2738. if err != nil {
  2739. br.Msg = "刷新失败"
  2740. br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error()
  2741. return
  2742. }
  2743. br.Ret = 200
  2744. br.Msg = "刷新成功"
  2745. if isAsync {
  2746. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  2747. }
  2748. br.Success = true
  2749. br.IsAddLog = true
  2750. }
  2751. // EdbInfoMove
  2752. // @Title 移动指标接口
  2753. // @Description 移动指标接口
  2754. // @Success 200 {object} data_manage.MoveEdbInfoReq
  2755. // @router /edb_info/move [post]
  2756. func (this *EdbInfoController) EdbInfoMove() {
  2757. br := new(models.BaseResponse).Init()
  2758. defer func() {
  2759. this.Data["json"] = br
  2760. this.ServeJSON()
  2761. }()
  2762. sysUser := this.SysUser
  2763. if sysUser == nil {
  2764. br.Msg = "请登录"
  2765. br.ErrMsg = "请登录,SysUser Is Empty"
  2766. br.Ret = 408
  2767. return
  2768. }
  2769. var req data_manage.MoveEdbInfoReq
  2770. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2771. if err != nil {
  2772. br.Msg = "参数解析异常!"
  2773. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2774. return
  2775. }
  2776. if req.EdbInfoId <= 0 {
  2777. br.Msg = "参数错误"
  2778. br.ErrMsg = "指标id小于等于0"
  2779. return
  2780. }
  2781. if req.ClassifyId <= 0 {
  2782. br.Msg = "请选择分类"
  2783. return
  2784. }
  2785. //判断分类是否存在
  2786. count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId)
  2787. if count <= 0 {
  2788. br.Msg = "分类已被删除,不可移动,请刷新页面"
  2789. return
  2790. }
  2791. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2792. if err != nil {
  2793. br.Msg = "移动失败"
  2794. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2795. return
  2796. }
  2797. var haveOperaAuth bool
  2798. // 权限校验
  2799. {
  2800. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.IsJoinPermission, edbInfo.EdbInfoId, edbInfo.ClassifyId, this.SysUser.AdminId)
  2801. if err != nil {
  2802. br.Msg = err.Error()
  2803. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2804. return
  2805. }
  2806. }
  2807. // 移动权限校验
  2808. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  2809. if !button.MoveButton {
  2810. br.Msg = "无权限操作"
  2811. br.IsSendEmail = false
  2812. return
  2813. }
  2814. //如果改变了分类,那么移动该指标数据
  2815. if edbInfo.ClassifyId != req.ClassifyId {
  2816. err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId)
  2817. if err != nil {
  2818. br.Msg = "移动失败"
  2819. br.ErrMsg = "移动指标失败,Err:" + err.Error()
  2820. return
  2821. }
  2822. }
  2823. updateCol := make([]string, 0)
  2824. //如果有传入 上一个兄弟节点分类id
  2825. if req.PrevEdbInfoId > 0 {
  2826. prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId)
  2827. if err != nil {
  2828. br.Msg = "移动失败"
  2829. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  2830. return
  2831. }
  2832. //如果是移动在两个兄弟节点之间
  2833. if req.NextEdbInfoId > 0 {
  2834. //下一个兄弟节点
  2835. nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId)
  2836. if err != nil {
  2837. br.Msg = "移动失败"
  2838. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  2839. return
  2840. }
  2841. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  2842. if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort {
  2843. //变更兄弟节点的排序
  2844. updateSortStr := `sort + 2`
  2845. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2846. } else {
  2847. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  2848. if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 {
  2849. //变更兄弟节点的排序
  2850. updateSortStr := `sort + 1`
  2851. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2852. }
  2853. }
  2854. }
  2855. edbInfo.Sort = prevEdbInfo.Sort + 1
  2856. edbInfo.ModifyTime = time.Now()
  2857. updateCol = append(updateCol, "Sort", "ModifyTime")
  2858. } else {
  2859. firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId)
  2860. if err != nil && err.Error() != utils.ErrNoRow() {
  2861. br.Msg = "移动失败"
  2862. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2863. return
  2864. }
  2865. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2866. if firstClassify != nil && firstClassify.Sort == 0 {
  2867. updateSortStr := ` sort + 1 `
  2868. _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr)
  2869. }
  2870. edbInfo.Sort = 0 //那就是排在第一位
  2871. edbInfo.ModifyTime = time.Now()
  2872. updateCol = append(updateCol, "Sort", "ModifyTime")
  2873. }
  2874. //更新
  2875. if len(updateCol) > 0 {
  2876. err = edbInfo.Update(updateCol)
  2877. if err != nil {
  2878. br.Msg = "移动失败"
  2879. br.ErrMsg = "修改失败,Err:" + err.Error()
  2880. return
  2881. }
  2882. }
  2883. if err != nil {
  2884. br.Msg = "移动失败"
  2885. br.ErrMsg = "修改失败,Err:" + err.Error()
  2886. return
  2887. }
  2888. //新增操作日志
  2889. {
  2890. edbLog := new(data_manage.EdbInfoLog)
  2891. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2892. edbLog.SourceName = edbInfo.SourceName
  2893. edbLog.Source = edbInfo.Source
  2894. edbLog.EdbCode = edbInfo.EdbCode
  2895. edbLog.EdbName = edbInfo.EdbName
  2896. edbLog.ClassifyId = edbInfo.ClassifyId
  2897. edbLog.SysUserId = sysUser.AdminId
  2898. edbLog.SysUserRealName = sysUser.RealName
  2899. edbLog.CreateTime = time.Now()
  2900. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2901. edbLog.Status = "移动指标"
  2902. edbLog.Method = this.Ctx.Input.URI()
  2903. go data_manage.AddEdbInfoLog(edbLog)
  2904. }
  2905. br.Ret = 200
  2906. br.Success = true
  2907. br.Msg = "移动成功"
  2908. }
  2909. // EdbInfoDetail
  2910. // @Title 获取指标详情
  2911. // @Description 获取指标详情接口
  2912. // @Param EdbInfoId query int true "指标id"
  2913. // @Success 200 {object} data_manage.EdbInfo
  2914. // @router /edb_info/detail [get]
  2915. func (this *EdbInfoController) EdbInfoDetail() {
  2916. br := new(models.BaseResponse).Init()
  2917. defer func() {
  2918. this.Data["json"] = br
  2919. this.ServeJSON()
  2920. }()
  2921. sysUser := this.SysUser
  2922. if sysUser == nil {
  2923. br.Msg = "请登录"
  2924. br.ErrMsg = "请登录,SysUser Is Empty"
  2925. br.Ret = 408
  2926. return
  2927. }
  2928. edbInfoId, _ := this.GetInt("EdbInfoId")
  2929. if edbInfoId <= 0 {
  2930. br.Msg = "参数错误"
  2931. br.ErrMsg = "参数错误"
  2932. return
  2933. }
  2934. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  2935. if err != nil {
  2936. br.Msg = "获取失败"
  2937. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2938. return
  2939. }
  2940. var resp data_manage.EdbInfoFullClassify
  2941. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  2942. if err != nil {
  2943. br.Msg = err.Error()
  2944. br.ErrMsg = errMsg
  2945. return
  2946. }
  2947. // 权限校验
  2948. {
  2949. classifyMap := make(map[int]*data_manage.EdbClassifyIdItems)
  2950. for _, v := range classifyList {
  2951. classifyMap[v.ClassifyId] = v
  2952. }
  2953. if currClassify, ok := classifyMap[edbInfo.ClassifyId]; ok {
  2954. haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
  2955. if err != nil {
  2956. br.Msg = err.Error()
  2957. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  2958. return
  2959. }
  2960. resp.HaveOperaAuth = haveOperaAuth
  2961. }
  2962. }
  2963. resp.EdbInfo = edbInfo
  2964. resp.ClassifyList = classifyList
  2965. br.Ret = 200
  2966. br.Success = true
  2967. br.Msg = "获取成功"
  2968. br.Data = resp
  2969. }
  2970. // EdbInfoFilter
  2971. // @Title 指标筛选接口
  2972. // @Description 指标筛选接口
  2973. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  2974. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标"
  2975. // @Param PageSize query int true "每页数据条数"
  2976. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2977. // @Success 200 {object} data_manage.EdbInfoList
  2978. // @router /edb_info/filter [get]
  2979. func (this *EdbInfoController) EdbInfoFilter() {
  2980. br := new(models.BaseResponse).Init()
  2981. defer func() {
  2982. this.Data["json"] = br
  2983. this.ServeJSON()
  2984. }()
  2985. keyWord := this.GetString("KeyWord")
  2986. filterSource, _ := this.GetInt("FilterSource")
  2987. if filterSource <= 0 {
  2988. filterSource = 1
  2989. }
  2990. var pars []interface{}
  2991. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  2992. // 获取当前账号的不可见指标
  2993. {
  2994. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2995. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  2996. if err != nil && err.Error() != utils.ErrNoRow() {
  2997. br.Msg = "获取失败"
  2998. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  2999. return
  3000. }
  3001. for _, v := range confList {
  3002. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3003. }
  3004. }
  3005. var keyWordArr []string
  3006. keyWordArr = append(keyWordArr, keyWord)
  3007. if keyWord != "" {
  3008. newKeyWord := strings.Split(keyWord, " ")
  3009. keyWordArr = append(keyWordArr, newKeyWord...)
  3010. }
  3011. //var err error
  3012. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  3013. //if keyWord == "" {
  3014. // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars)
  3015. // if err != nil && err.Error() != utils.ErrNoRow() {
  3016. // br.Success = true
  3017. // br.Msg = "获取指标信息失败"
  3018. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3019. // return
  3020. // }
  3021. //} else {
  3022. // //获取指标信息
  3023. // indexName := utils.DATA_INDEX_NAME
  3024. // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource)
  3025. // if err != nil && err.Error() != utils.ErrNoRow() {
  3026. // br.Success = true
  3027. // br.Msg = "获取指标信息失败"
  3028. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3029. // return
  3030. // }
  3031. //}
  3032. var baseCondition string
  3033. // 无权限指标id
  3034. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3035. if lenNoPermissionEdbInfoIdList > 0 {
  3036. baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3037. pars = append(pars, noPermissionEdbInfoIdList)
  3038. }
  3039. existMap := make(map[int]string)
  3040. for _, v := range keyWordArr {
  3041. v = strings.Replace(v, " ", "%", -1)
  3042. var condition string
  3043. if filterSource == 2 {
  3044. condition += ` AND frequency='月度' `
  3045. }
  3046. if filterSource == 3 {
  3047. condition += ` AND frequency <> '日度' `
  3048. }
  3049. if filterSource == 4 {
  3050. condition += ` AND edb_type = 1 `
  3051. }
  3052. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  3053. condition += conditionWhere + baseCondition
  3054. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  3055. if err != nil && err.Error() != utils.ErrNoRow() {
  3056. br.Success = true
  3057. br.Msg = "获取指标信息失败"
  3058. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3059. return
  3060. }
  3061. for _, nv := range newEdbInfoList {
  3062. if _, ok := existMap[nv.EdbInfoId]; !ok {
  3063. edbInfoList = append(edbInfoList, nv)
  3064. }
  3065. existMap[nv.EdbInfoId] = nv.EdbCode
  3066. }
  3067. }
  3068. if edbInfoList == nil {
  3069. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3070. }
  3071. edbInfoListLen := len(edbInfoList)
  3072. for i := 0; i < edbInfoListLen; i++ {
  3073. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3074. }
  3075. for i := 0; i < edbInfoListLen; i++ {
  3076. for j := 0; j < edbInfoListLen; j++ {
  3077. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3078. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3079. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3080. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3081. }
  3082. }
  3083. }
  3084. //新增搜索词记录
  3085. {
  3086. searchKeyword := new(data_manage.SearchKeyword)
  3087. searchKeyword.KeyWord = keyWord
  3088. searchKeyword.CreateTime = time.Now()
  3089. go data_manage.AddSearchKeyword(searchKeyword)
  3090. }
  3091. br.Ret = 200
  3092. br.Success = true
  3093. br.Msg = "获取成功"
  3094. br.Data = edbInfoList
  3095. }
  3096. // EdbInfoFilterByEs
  3097. // @Title 指标筛选接口
  3098. // @Description 指标筛选接口
  3099. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  3100. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  3101. // @Param Frequency query string false "频度"
  3102. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  3103. // @Param PageSize query int true "每页数据条数"
  3104. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3105. // @Success 200 {object} data_manage.EdbInfoList
  3106. // @router /edb_info/filter_by_es [get]
  3107. func (this *EdbInfoController) EdbInfoFilterByEs() {
  3108. br := new(models.BaseResponse).Init()
  3109. defer func() {
  3110. this.Data["json"] = br
  3111. this.ServeJSON()
  3112. }()
  3113. pageSize, _ := this.GetInt("PageSize")
  3114. currentIndex, _ := this.GetInt("CurrentIndex")
  3115. var total int64
  3116. var startSize int
  3117. if pageSize <= 0 {
  3118. pageSize = utils.PageSize20
  3119. }
  3120. if currentIndex <= 0 {
  3121. currentIndex = 1
  3122. }
  3123. startSize = paging.StartIndex(currentIndex, pageSize)
  3124. keyWord := this.GetString("KeyWord")
  3125. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3126. filterSource, _ := this.GetInt("FilterSource")
  3127. if filterSource <= 0 {
  3128. filterSource = 1
  3129. }
  3130. //指标来源
  3131. source, _ := this.GetInt("Source")
  3132. frequency := this.GetString("Frequency") //频度
  3133. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  3134. var edbInfoList []*data_manage.EdbInfoList
  3135. var err error
  3136. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  3137. // 获取当前账号的不可见指标
  3138. {
  3139. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3140. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3141. if err != nil && err.Error() != utils.ErrNoRow() {
  3142. br.Msg = "获取失败"
  3143. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3144. return
  3145. }
  3146. for _, v := range confList {
  3147. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3148. }
  3149. }
  3150. // 是否走ES
  3151. isEs := false
  3152. if keyWord != "" {
  3153. var keyWordArr []string
  3154. keyWordArr = append(keyWordArr, keyWord)
  3155. newKeyWord := strings.Split(keyWord, " ")
  3156. keyWordArr = append(keyWordArr, newKeyWord...)
  3157. // 普通的搜索
  3158. if !isAddPredictEdb {
  3159. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
  3160. } else {
  3161. // 允许添加预测指标的搜索
  3162. total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize)
  3163. }
  3164. isEs = true
  3165. } else {
  3166. var condition string
  3167. var pars []interface{}
  3168. // 普通指标
  3169. condition += ` AND edb_info_type = ? `
  3170. pars = append(pars, 0)
  3171. // 无权限指标id
  3172. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3173. if lenNoPermissionEdbInfoIdList > 0 {
  3174. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3175. pars = append(pars, noPermissionEdbInfoIdList)
  3176. }
  3177. switch filterSource {
  3178. case 2:
  3179. condition += ` AND frequency='月度' `
  3180. case 3:
  3181. condition += ` AND frequency <> '日度' `
  3182. case 4:
  3183. condition += ` AND edb_type = 1 `
  3184. case 5:
  3185. condition += ` AND source = 6 ` //来源(同比值)
  3186. case 6:
  3187. condition += ` AND frequency != ? `
  3188. pars = append(pars, "年度")
  3189. }
  3190. //频度
  3191. if frequency != "" {
  3192. condition += ` AND frequency = ? `
  3193. pars = append(pars, frequency)
  3194. }
  3195. // 查询只允许添加预测指标的搜索
  3196. if isAddPredictEdb {
  3197. condition += ` AND frequency in ("日度","周度","月度") `
  3198. }
  3199. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  3200. }
  3201. if err != nil {
  3202. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3203. }
  3204. page := paging.GetPaging(currentIndex, pageSize, int(total))
  3205. edbInfoListLen := len(edbInfoList)
  3206. classifyIdList := make([]int, 0)
  3207. for i := 0; i < edbInfoListLen; i++ {
  3208. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3209. classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
  3210. }
  3211. // 当前列表中的分类map
  3212. classifyMap := make(map[int]*data_manage.EdbClassify)
  3213. if edbInfoListLen > 0 {
  3214. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  3215. if err != nil {
  3216. br.Msg = "获取失败"
  3217. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  3218. return
  3219. }
  3220. for _, v := range classifyList {
  3221. classifyMap[v.ClassifyId] = v
  3222. }
  3223. // 获取所有有权限的指标和分类
  3224. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  3225. if err != nil {
  3226. br.Msg = "获取失败"
  3227. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  3228. return
  3229. }
  3230. // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  3231. if isEs {
  3232. edbInfoIdList := make([]int, 0)
  3233. for i := 0; i < edbInfoListLen; i++ {
  3234. edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
  3235. tmpEdbInfo := edbInfoList[i]
  3236. if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
  3237. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  3238. }
  3239. }
  3240. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  3241. if err != nil {
  3242. br.Msg = "获取失败"
  3243. br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
  3244. return
  3245. }
  3246. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  3247. for _, v := range tmpEdbList {
  3248. edbInfoMap[v.EdbInfoId] = v
  3249. }
  3250. for i := 0; i < edbInfoListLen; i++ {
  3251. tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
  3252. if !ok {
  3253. continue
  3254. }
  3255. edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
  3256. }
  3257. }
  3258. // 权限校验
  3259. for i := 0; i < edbInfoListLen; i++ {
  3260. tmpEdbInfoItem := edbInfoList[i]
  3261. if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
  3262. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  3263. }
  3264. }
  3265. }
  3266. for i := 0; i < edbInfoListLen; i++ {
  3267. for j := 0; j < edbInfoListLen; j++ {
  3268. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3269. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3270. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3271. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3272. }
  3273. }
  3274. }
  3275. //新增搜索词记录
  3276. {
  3277. searchKeyword := new(data_manage.SearchKeyword)
  3278. searchKeyword.KeyWord = keyWord
  3279. searchKeyword.CreateTime = time.Now()
  3280. go data_manage.AddSearchKeyword(searchKeyword)
  3281. }
  3282. resp := data_manage.EdbInfoFilterDataResp{
  3283. Paging: page,
  3284. List: edbInfoList,
  3285. }
  3286. br.Ret = 200
  3287. br.Success = true
  3288. br.Msg = "获取成功"
  3289. br.Data = resp
  3290. }
  3291. func (this *EdbInfoController) EdbInfoFilter2() {
  3292. br := new(models.BaseResponse).Init()
  3293. defer func() {
  3294. this.Data["json"] = br
  3295. this.ServeJSON()
  3296. }()
  3297. keyWord := this.GetString("KeyWord")
  3298. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3299. filterSource, _ := this.GetInt("FilterSource")
  3300. if filterSource <= 0 {
  3301. filterSource = 1
  3302. }
  3303. var pars []interface{}
  3304. //if keyWord != "" {
  3305. // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  3306. //}
  3307. var keyWordArr []string
  3308. keyWordArr = append(keyWordArr, keyWord)
  3309. if keyWord != "" {
  3310. newKeyWord := strings.Split(keyWord, " ")
  3311. keyWordArr = append(keyWordArr, newKeyWord...)
  3312. }
  3313. keywordLen := len(keyWordArr)
  3314. ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen)
  3315. searchWait := sync.WaitGroup{}
  3316. searchWait.Add(keywordLen)
  3317. for index, v := range keyWordArr {
  3318. v = strings.Replace(v, " ", "%", -1)
  3319. var condition string
  3320. if filterSource == 2 {
  3321. condition += ` AND frequency='月度' `
  3322. }
  3323. if filterSource == 3 {
  3324. condition += ` AND frequency <> '日度' `
  3325. }
  3326. if filterSource == 4 {
  3327. condition += ` AND edb_type = 1 `
  3328. }
  3329. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  3330. condition += conditionWhere
  3331. go searchEdbInfoFilter(condition, pars, index, ch, &searchWait)
  3332. }
  3333. searchWait.Wait()
  3334. newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList)
  3335. i := 0
  3336. for tmpEdbInfoList := range ch {
  3337. i++
  3338. for k, v := range tmpEdbInfoList {
  3339. newEdbInfoListMap[k] = v
  3340. }
  3341. if i == keywordLen {
  3342. break
  3343. }
  3344. }
  3345. close(ch)
  3346. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  3347. existMap := make(map[int]string)
  3348. for i := 0; i < keywordLen; i++ {
  3349. if newEdbInfoList, ok := newEdbInfoListMap[i]; ok {
  3350. for _, nv := range newEdbInfoList {
  3351. if _, ok := existMap[nv.EdbInfoId]; !ok {
  3352. edbInfoList = append(edbInfoList, nv)
  3353. }
  3354. existMap[nv.EdbInfoId] = nv.EdbCode
  3355. }
  3356. }
  3357. }
  3358. if edbInfoList == nil {
  3359. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3360. }
  3361. edbInfoListLen := len(edbInfoList)
  3362. for i := 0; i < edbInfoListLen; i++ {
  3363. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3364. }
  3365. for i := 0; i < edbInfoListLen; i++ {
  3366. for j := 0; j < edbInfoListLen; j++ {
  3367. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3368. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3369. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3370. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3371. }
  3372. }
  3373. }
  3374. //新增搜索词记录
  3375. {
  3376. searchKeyword := new(data_manage.SearchKeyword)
  3377. searchKeyword.KeyWord = keyWord
  3378. searchKeyword.CreateTime = time.Now()
  3379. go data_manage.AddSearchKeyword(searchKeyword)
  3380. }
  3381. br.Ret = 200
  3382. br.Success = true
  3383. br.Msg = "获取成功"
  3384. br.Data = edbInfoList
  3385. }
  3386. 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) {
  3387. newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList)
  3388. defer func() {
  3389. if err != nil {
  3390. go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3)
  3391. //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  3392. }
  3393. ch <- newEdbInfoListMap
  3394. searchWait.Done()
  3395. }()
  3396. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  3397. newEdbInfoListMap[i] = newEdbInfoList
  3398. return
  3399. }
  3400. // EdbInfoAllRefresh
  3401. // @Title 指标全部刷新接口
  3402. // @Description 指标全部刷新接口
  3403. // @Param EdbInfoId query int true "指标id"
  3404. // @Success Ret=200 全部刷新成功
  3405. // @router /edb_info/refresh/all [get]
  3406. func (this *EdbInfoController) EdbInfoAllRefresh() {
  3407. br := new(models.BaseResponse).Init()
  3408. defer func() {
  3409. this.Data["json"] = br
  3410. this.ServeJSON()
  3411. }()
  3412. sysUser := this.SysUser
  3413. if sysUser == nil {
  3414. br.Msg = "请登录"
  3415. br.ErrMsg = "请登录,SysUser Is Empty"
  3416. br.Ret = 408
  3417. return
  3418. }
  3419. edbInfoId, _ := this.GetInt("EdbInfoId")
  3420. if edbInfoId <= 0 {
  3421. br.Msg = "参数错误"
  3422. br.ErrMsg = "参数错误"
  3423. return
  3424. }
  3425. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3426. if err != nil {
  3427. if err.Error() == utils.ErrNoRow() {
  3428. br.Msg = "数据已被删除,请刷新页面"
  3429. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  3430. return
  3431. }
  3432. br.Msg = "刷新失败"
  3433. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3434. return
  3435. }
  3436. if edbInfo == nil {
  3437. br.Msg = "数据已被删除,请刷新页面"
  3438. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  3439. return
  3440. }
  3441. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true, false)
  3442. if err != nil {
  3443. br.Msg = "刷新失败"
  3444. br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error()
  3445. return
  3446. }
  3447. br.Ret = 200
  3448. br.Success = true
  3449. br.Msg = "刷新成功"
  3450. if isAsync {
  3451. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  3452. }
  3453. }
  3454. // EdbInfoData
  3455. // @Title 获取指标数据
  3456. // @Description 获取指标数据
  3457. // @Param EdbInfoId query int true "指标ID"
  3458. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  3459. // @Param StartDate query string true "自定义开始日期"
  3460. // @Param EndDate query string true "自定义结束日期"
  3461. // @Success 200 {object} data_manage.EdbInfoDataResp
  3462. // @router /edb_info/data [get]
  3463. func (this *ChartInfoController) EdbInfoData() {
  3464. br := new(models.BaseResponse).Init()
  3465. defer func() {
  3466. this.Data["json"] = br
  3467. this.ServeJSON()
  3468. }()
  3469. sysUser := this.SysUser
  3470. if sysUser == nil {
  3471. br.Msg = "请登录"
  3472. br.ErrMsg = "请登录,SysUser Is Empty"
  3473. br.Ret = 408
  3474. return
  3475. }
  3476. fullEdb := new(data_manage.EdbInfoFullClassify)
  3477. resp := new(data_manage.EdbInfoDataFullClassifyResp)
  3478. dataList := make([]*data_manage.EdbDataList, 0)
  3479. edbInfoId, _ := this.GetInt("EdbInfoId")
  3480. if edbInfoId <= 0 {
  3481. br.Msg = "参数错误"
  3482. return
  3483. }
  3484. dateType, _ := this.GetInt("DateType")
  3485. if dateType <= 0 {
  3486. dateType = 3
  3487. }
  3488. edbInfoType, _ := this.GetInt("EdbInfoType")
  3489. if edbInfoType < 0 {
  3490. edbInfoType = 1
  3491. }
  3492. startDate := this.GetString("StartDate")
  3493. endDate := this.GetString("EndDate")
  3494. startYear, _ := this.GetInt("StartYear")
  3495. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3496. if err != nil {
  3497. if err.Error() == utils.ErrNoRow() {
  3498. br.Ret = 200
  3499. return
  3500. }
  3501. br.Msg = "获取失败"
  3502. br.ErrMsg = "获取失败,Err:" + err.Error()
  3503. return
  3504. }
  3505. // 分类
  3506. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  3507. if err != nil {
  3508. br.Msg = err.Error()
  3509. br.ErrMsg = errMsg
  3510. return
  3511. }
  3512. fullEdb.EdbInfo = edbInfo
  3513. fullEdb.ClassifyList = classifyList
  3514. var currClassifyItem *data_manage.EdbClassifyIdItems
  3515. for _, v := range classifyList {
  3516. if v.ClassifyId == edbInfo.ClassifyId {
  3517. currClassifyItem = v
  3518. }
  3519. }
  3520. if currClassifyItem != nil {
  3521. haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassifyItem.IsJoinPermission, sysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
  3522. if err != nil {
  3523. br.Msg = err.Error()
  3524. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  3525. return
  3526. }
  3527. fullEdb.HaveOperaAuth = haveOperaAuth
  3528. }
  3529. resp.EdbInfo = fullEdb
  3530. resp.DataList = make([]*data_manage.EdbDataList, 0)
  3531. // 数据获取
  3532. if fullEdb.HaveOperaAuth { // 有权限才获取数据
  3533. maxYear := 0
  3534. if edbInfo.LatestDate != "" {
  3535. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3536. maxYear = latestDateT.Year()
  3537. }
  3538. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  3539. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  3540. if err != nil {
  3541. br.Msg = "获取失败"
  3542. br.ErrMsg = "获取失败,Err:" + err.Error()
  3543. return
  3544. }
  3545. resp.DataList = dataList
  3546. }
  3547. br.Ret = 200
  3548. br.Success = true
  3549. br.Msg = "获取成功"
  3550. br.Data = resp
  3551. }
  3552. // EdbInfoReplaceCheck
  3553. // @Title 指标一键刷新接口
  3554. // @Description 指标一键刷新接口
  3555. // @Success Ret=200 更新成功
  3556. // @router /edb_info/replace/check [post]
  3557. func (this *EdbInfoController) EdbInfoReplaceCheck() {
  3558. br := new(models.BaseResponse).Init()
  3559. setNxKey := "EDB_INFO_REPLACE"
  3560. defer func() {
  3561. this.Data["json"] = br
  3562. this.ServeJSON()
  3563. }()
  3564. status := 0
  3565. if utils.Rc.IsExist(setNxKey) {
  3566. status = 1
  3567. } else {
  3568. status = 2
  3569. }
  3570. br.Ret = 200
  3571. br.Success = true
  3572. br.Msg = "检测成功"
  3573. br.Data = status
  3574. }
  3575. // EdbInfoReplace
  3576. // @Title 替换指标
  3577. // @Description 替换指标
  3578. // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
  3579. // @Success 200 {object} data_manage.EdbInfoDataResp
  3580. // @router /edb_info/replace [post]
  3581. func (this *ChartInfoController) EdbInfoReplace() {
  3582. br := new(models.BaseResponse).Init()
  3583. setNxKey := "EDB_INFO_REPLACE"
  3584. deleteCache := true
  3585. defer func() {
  3586. if deleteCache {
  3587. utils.Rc.Delete(setNxKey)
  3588. }
  3589. this.Data["json"] = br
  3590. this.ServeJSON()
  3591. }()
  3592. sysUser := this.SysUser
  3593. if sysUser == nil {
  3594. br.Msg = "请登录"
  3595. br.ErrMsg = "请登录,SysUser Is Empty"
  3596. br.Ret = 408
  3597. return
  3598. }
  3599. if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
  3600. deleteCache = false
  3601. br.Msg = "当前正在替换中,请耐心等待!"
  3602. br.IsSendEmail = false
  3603. return
  3604. }
  3605. var req data_manage.EdbInfoReplaceReq
  3606. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3607. if err != nil {
  3608. br.Msg = "参数解析异常!"
  3609. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3610. return
  3611. }
  3612. if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
  3613. br.Msg = "参数错误!"
  3614. br.ErrMsg = "参数错误,指标id为0"
  3615. return
  3616. }
  3617. oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
  3618. if err != nil {
  3619. br.Msg = "替换失败!"
  3620. br.ErrMsg = "获取原指标失败,Err:" + err.Error()
  3621. return
  3622. }
  3623. newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
  3624. if err != nil {
  3625. br.Msg = "替换失败!"
  3626. br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
  3627. return
  3628. }
  3629. //if oldEdbInfo.EdbType != 1 {
  3630. // br.Msg = "原指标为计算指标,不可替换!"
  3631. // br.ErrMsg = "原指标为计算指标,不可替换!"
  3632. // return
  3633. //}
  3634. //
  3635. //if newEdbInfo.EdbType != 1 {
  3636. // br.Msg = "替换指标为计算指标,不可替换!"
  3637. // br.ErrMsg = "替换指标为计算指标,不可替换!"
  3638. // return
  3639. //}
  3640. if oldEdbInfo.Frequency != newEdbInfo.Frequency {
  3641. br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3642. br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3643. return
  3644. }
  3645. sysAdminId := sysUser.AdminId
  3646. //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3647. _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3648. //msgContent := ``
  3649. isFail := false
  3650. var errmsg string
  3651. if err != nil {
  3652. //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换失败,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n " + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
  3653. isFail = true
  3654. errmsg = "replace err:" + err.Error()
  3655. } else {
  3656. //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换成功,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n" + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
  3657. isFail = false
  3658. }
  3659. // 添加站内信息
  3660. //{
  3661. // msgItem := new(company.CompanyApprovalMessage)
  3662. // msgItem.CreateUserId = sysAdminId
  3663. // msgItem.ReceiveUserId = sysAdminId
  3664. // msgItem.MessageStatus = 0
  3665. // msgItem.Remark = "指标替换"
  3666. // msgItem.OperationStatus = 1
  3667. // msgItem.Content = msgContent
  3668. // msgItem.CreateTime = time.Now()
  3669. // msgItem.ModifyTime = time.Now()
  3670. // msgItem.MessageType = 3 //1:申请消息,2:审批结果,3:文字消息
  3671. // msgItem.SourceType = 4 //消息来源
  3672. // err = company.AddCompanyApprovalMessage(msgItem)
  3673. //}
  3674. if isFail {
  3675. br.Msg = "替换失败"
  3676. br.ErrMsg = "替换失败 err:" + errmsg
  3677. } else {
  3678. br.Msg = "替换成功"
  3679. br.ErrMsg = "替换成功"
  3680. br.Ret = 200
  3681. }
  3682. br.IsAddLog = true
  3683. return
  3684. }
  3685. // RelationChartList
  3686. // @Title 获取ETA指标关联的图表列表接口
  3687. // @Description 获取ETA指标关联的图表列表接口
  3688. // @Param PageSize query int true "每页数据条数"
  3689. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3690. // @Param EdbInfoId query int true "指标id"
  3691. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3692. // @Success 200 {object} data_manage.ChartListResp
  3693. // @router /edb_info/relation/chart_list [get]
  3694. func (this *EdbInfoController) RelationChartList() {
  3695. br := new(models.BaseResponse).Init()
  3696. defer func() {
  3697. this.Data["json"] = br
  3698. this.ServeJSON()
  3699. }()
  3700. sysUser := this.SysUser
  3701. if sysUser == nil {
  3702. br.Msg = "请登录"
  3703. br.ErrMsg = "请登录,SysUser Is Empty"
  3704. br.Ret = 408
  3705. return
  3706. }
  3707. edbInfoId, _ := this.GetInt("EdbInfoId")
  3708. pageSize, _ := this.GetInt("PageSize")
  3709. currentIndex, _ := this.GetInt("CurrentIndex")
  3710. resp := data_manage.ChartListResp{}
  3711. var total int
  3712. page := paging.GetPaging(currentIndex, pageSize, total)
  3713. var startSize int
  3714. if pageSize <= 0 {
  3715. pageSize = utils.PageSize20
  3716. }
  3717. if currentIndex <= 0 {
  3718. currentIndex = 1
  3719. }
  3720. startSize = paging.StartIndex(currentIndex, pageSize)
  3721. var condition string
  3722. var pars []interface{}
  3723. if edbInfoId <= 0 {
  3724. br.Msg = "请选择指标"
  3725. br.ErrMsg = "请选择指标"
  3726. br.IsSendEmail = false
  3727. return
  3728. }
  3729. // 关联指标
  3730. condition += ` AND b.edb_info_id = ? `
  3731. pars = append(pars, edbInfoId)
  3732. //只看我的
  3733. isShowMe, _ := this.GetBool("IsShowMe")
  3734. if isShowMe {
  3735. condition += ` AND a.sys_user_id = ? `
  3736. pars = append(pars, sysUser.AdminId)
  3737. }
  3738. // 获取当前账号的不可见图表
  3739. noPermissionChartIdList := make([]int, 0)
  3740. {
  3741. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3742. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  3743. if err != nil && err.Error() != utils.ErrNoRow() {
  3744. br.Msg = "获取失败"
  3745. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3746. return
  3747. }
  3748. for _, v := range confList {
  3749. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  3750. }
  3751. }
  3752. noPermissionChartIdNum := len(noPermissionChartIdList)
  3753. if noPermissionChartIdNum > 0 {
  3754. condition += ` AND a.chart_info_id not in (` + utils.GetOrmInReplace(noPermissionChartIdNum) + `) `
  3755. pars = append(pars, noPermissionChartIdList)
  3756. }
  3757. //获取关联图表列表
  3758. list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
  3759. if err != nil && err.Error() != utils.ErrNoRow() {
  3760. br.Success = true
  3761. br.Msg = "获取图表信息失败"
  3762. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3763. return
  3764. }
  3765. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3766. items := make([]*data_manage.ChartInfoView, 0)
  3767. resp.Paging = page
  3768. resp.List = items
  3769. br.Ret = 200
  3770. br.Success = true
  3771. br.Msg = "获取成功"
  3772. return
  3773. }
  3774. // 获取关联图表总数
  3775. dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
  3776. if err != nil && err.Error() != utils.ErrNoRow() {
  3777. br.Msg = "获取指标信息失败"
  3778. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3779. return
  3780. }
  3781. // 获取MY ETA 图表,用来判断是否加入我的图库
  3782. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  3783. if err != nil && err.Error() != utils.ErrNoRow() {
  3784. br.Msg = "获取图表信息失败"
  3785. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  3786. return
  3787. }
  3788. myChartMap := make(map[int]*data_manage.MyChartView)
  3789. for _, v := range myChartList {
  3790. myChartMap[v.ChartInfoId] = v
  3791. }
  3792. listLen := len(list)
  3793. if listLen > 0 {
  3794. // 分类id
  3795. classifyIdList := make([]int, 0)
  3796. // 当前列表中的分类map
  3797. classifyMap := make(map[int]*data_manage.ChartClassify)
  3798. for _, v := range list {
  3799. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  3800. }
  3801. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  3802. if err != nil {
  3803. br.Msg = "获取失败"
  3804. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  3805. return
  3806. }
  3807. for _, v := range classifyList {
  3808. classifyMap[v.ChartClassifyId] = v
  3809. }
  3810. // 已授权分类id
  3811. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  3812. if err != nil {
  3813. br.Msg = "获取失败"
  3814. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  3815. return
  3816. }
  3817. for _, v := range list {
  3818. if existItem, ok := myChartMap[v.ChartInfoId]; ok {
  3819. v.IsAdd = true
  3820. v.MyChartId = existItem.MyChartId
  3821. v.MyChartClassifyId = existItem.MyChartClassifyId
  3822. }
  3823. // 权限
  3824. if currClassify, ok := classifyMap[v.ChartClassifyId]; ok {
  3825. v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  3826. }
  3827. }
  3828. }
  3829. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  3830. resp.Paging = page
  3831. resp.List = list
  3832. br.Ret = 200
  3833. br.Success = true
  3834. br.Msg = "获取成功"
  3835. br.Data = resp
  3836. }
  3837. // RelationEdbList
  3838. // @Title 获取ETA指标关联的指标列表接口
  3839. // @Description 获取ETA指标关联的指标列表接口
  3840. // @Param PageSize query int true "每页数据条数"
  3841. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3842. // @Param EdbInfoId query int true "指标id"
  3843. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3844. // @Success 200 {object} data_manage.ChartListResp
  3845. // @router /edb_info/relation/edbinfo_list [get]
  3846. func (this *EdbInfoController) RelationEdbList() {
  3847. br := new(models.BaseResponse).Init()
  3848. defer func() {
  3849. this.Data["json"] = br
  3850. this.ServeJSON()
  3851. }()
  3852. sysUser := this.SysUser
  3853. if sysUser == nil {
  3854. br.Msg = "请登录"
  3855. br.ErrMsg = "请登录,SysUser Is Empty"
  3856. br.Ret = 408
  3857. return
  3858. }
  3859. edbInfoId, _ := this.GetInt("EdbInfoId")
  3860. pageSize, _ := this.GetInt("PageSize")
  3861. currentIndex, _ := this.GetInt("CurrentIndex")
  3862. resp := data_manage.RelationEdbInfoListResp{}
  3863. var total int
  3864. page := paging.GetPaging(currentIndex, pageSize, total)
  3865. var startSize int
  3866. if pageSize <= 0 {
  3867. pageSize = utils.PageSize20
  3868. }
  3869. if currentIndex <= 0 {
  3870. currentIndex = 1
  3871. }
  3872. startSize = paging.StartIndex(currentIndex, pageSize)
  3873. var condition string
  3874. var pars []interface{}
  3875. if edbInfoId <= 0 {
  3876. br.Msg = "请选择指标"
  3877. br.ErrMsg = "请选择指标"
  3878. br.IsSendEmail = false
  3879. return
  3880. }
  3881. // 关联指标
  3882. condition += ` AND b.from_edb_info_id = ? `
  3883. pars = append(pars, edbInfoId)
  3884. //只看我的
  3885. isShowMe, _ := this.GetBool("IsShowMe")
  3886. if isShowMe {
  3887. condition += ` AND a.sys_user_id = ? `
  3888. pars = append(pars, sysUser.AdminId)
  3889. }
  3890. // 获取当前账号的不可见图表
  3891. noPermissionEdbIdList := make([]int, 0)
  3892. {
  3893. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3894. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3895. if err != nil && err.Error() != utils.ErrNoRow() {
  3896. br.Msg = "获取失败"
  3897. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3898. return
  3899. }
  3900. for _, v := range confList {
  3901. noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
  3902. }
  3903. }
  3904. noPermissionEdbIdNum := len(noPermissionEdbIdList)
  3905. if noPermissionEdbIdNum > 0 {
  3906. condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
  3907. pars = append(pars, noPermissionEdbIdList)
  3908. }
  3909. //获取关联图表列表
  3910. list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
  3911. if err != nil && err.Error() != utils.ErrNoRow() {
  3912. br.Success = true
  3913. br.Msg = "获取图表信息失败"
  3914. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3915. return
  3916. }
  3917. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3918. items := make([]*data_manage.ChartEdbInfoMapping, 0)
  3919. resp.Paging = page
  3920. resp.List = items
  3921. br.Ret = 200
  3922. br.Success = true
  3923. br.Msg = "获取成功"
  3924. return
  3925. }
  3926. // 获取关联图表总数
  3927. dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
  3928. if err != nil && err.Error() != utils.ErrNoRow() {
  3929. br.Msg = "获取指标信息失败"
  3930. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3931. return
  3932. }
  3933. if err != nil {
  3934. br.Msg = "获取失败"
  3935. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3936. return
  3937. }
  3938. edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
  3939. if len(list) > 0 {
  3940. // 当前的分类
  3941. classifyMap := make(map[int]*data_manage.EdbClassify)
  3942. {
  3943. classifyIdList := make([]int, 0)
  3944. for _, v := range list {
  3945. classifyIdList = append(classifyIdList, v.ClassifyId)
  3946. }
  3947. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  3948. if err != nil {
  3949. if err != nil {
  3950. br.Msg = "获取失败"
  3951. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  3952. return
  3953. }
  3954. }
  3955. for _, v := range classifyList {
  3956. classifyMap[v.ClassifyId] = v
  3957. }
  3958. }
  3959. // 获取所有有权限的指标和分类
  3960. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  3961. if err != nil {
  3962. br.Msg = "获取失败"
  3963. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  3964. return
  3965. }
  3966. for _, v := range list {
  3967. item := new(data_manage.ChartEdbInfoMapping)
  3968. item.EdbInfoId = v.EdbInfoId
  3969. item.SourceName = v.SourceName
  3970. item.Source = v.Source
  3971. item.EdbCode = v.EdbCode
  3972. item.EdbName = v.EdbName
  3973. item.EdbNameEn = v.EdbNameEn
  3974. item.Frequency = v.Frequency
  3975. item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
  3976. if v.Unit != `无` {
  3977. item.Unit = v.Unit
  3978. }
  3979. item.UnitEn = v.UnitEn
  3980. item.StartDate = v.StartDate
  3981. item.EndDate = v.EndDate
  3982. item.ModifyTime = v.ModifyTime
  3983. item.IsAxis = 1
  3984. item.LeadValue = 0
  3985. item.LeadUnit = ""
  3986. item.ChartEdbMappingId = 0
  3987. item.ChartInfoId = 0
  3988. item.IsOrder = false
  3989. item.EdbInfoType = v.EdbInfoType
  3990. item.EdbInfoCategoryType = v.EdbInfoType
  3991. item.ChartStyle = ""
  3992. item.ChartColor = ""
  3993. item.ChartWidth = 0
  3994. item.MaxData = v.MaxValue
  3995. item.MinData = v.MinValue
  3996. item.LatestValue = v.LatestValue
  3997. item.LatestDate = v.LatestDate
  3998. item.UniqueCode = v.UniqueCode
  3999. item.ClassifyId = v.ClassifyId
  4000. dataList := make([]*data_manage.EdbDataList, 0)
  4001. // 指标权限
  4002. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  4003. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4004. }
  4005. // 有权限则获取数据
  4006. if item.HaveOperaAuth {
  4007. if v.EdbInfoType == 0 {
  4008. dataList, err = data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, "", "")
  4009. } else {
  4010. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
  4011. }
  4012. if err != nil {
  4013. br.Msg = "获取失败"
  4014. br.Msg = "获取失败,Err:" + err.Error()
  4015. return
  4016. }
  4017. }
  4018. item.DataList = dataList
  4019. edbList = append(edbList, item)
  4020. }
  4021. }
  4022. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  4023. resp.Paging = page
  4024. resp.List = edbList
  4025. br.Ret = 200
  4026. br.Success = true
  4027. br.Msg = "获取成功"
  4028. br.Data = resp
  4029. }
  4030. // EdbInfoDataTb
  4031. // @Title 获取指标数据同比值
  4032. // @Description 获取指标数据
  4033. // @Param EdbInfoId query int true "指标ID"
  4034. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4035. // @Param StartDate query string true "自定义开始日期"
  4036. // @Param EndDate query string true "自定义结束日期"
  4037. // @Success 200 {object} data_manage.EdbInfoDataResp
  4038. // @router /edb_info/data/tb [get]
  4039. func (this *ChartInfoController) EdbInfoDataTb() {
  4040. br := new(models.BaseResponse).Init()
  4041. defer func() {
  4042. this.Data["json"] = br
  4043. this.ServeJSON()
  4044. }()
  4045. sysUser := this.SysUser
  4046. if sysUser == nil {
  4047. br.Msg = "请登录"
  4048. br.ErrMsg = "请登录,SysUser Is Empty"
  4049. br.Ret = 408
  4050. return
  4051. }
  4052. edbInfoId, _ := this.GetInt("EdbInfoId")
  4053. if edbInfoId <= 0 {
  4054. br.Msg = "参数错误"
  4055. return
  4056. }
  4057. dateType, _ := this.GetInt("DateType")
  4058. if dateType <= 0 {
  4059. dateType = 3
  4060. }
  4061. edbInfoType, _ := this.GetInt("EdbInfoType")
  4062. if edbInfoType < 0 {
  4063. edbInfoType = 1
  4064. }
  4065. startDate := this.GetString("StartDate")
  4066. endDate := this.GetString("EndDate")
  4067. startYear, _ := this.GetInt("StartYear")
  4068. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4069. if err != nil {
  4070. br.Msg = "获取失败"
  4071. br.Msg = "获取失败,Err:" + err.Error()
  4072. return
  4073. }
  4074. maxYear := 0
  4075. if edbInfo.LatestDate != "" {
  4076. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4077. maxYear = latestDateT.Year()
  4078. }
  4079. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  4080. var startDateTime time.Time
  4081. if startDate != `` {
  4082. startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  4083. if err != nil {
  4084. br.Msg = "开始日期异常"
  4085. br.Msg = "开始日期异常,Err:" + err.Error()
  4086. return
  4087. }
  4088. //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
  4089. startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
  4090. }
  4091. tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  4092. if err != nil {
  4093. br.Msg = "获取失败"
  4094. br.Msg = "获取失败,Err:" + err.Error()
  4095. return
  4096. }
  4097. // 计算同比值
  4098. dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
  4099. if err != nil {
  4100. br.Msg = "获取失败"
  4101. br.Msg = "计算同比值失败,Err:" + err.Error()
  4102. return
  4103. }
  4104. edbInfo.MaxValue = maxValue
  4105. edbInfo.MinValue = minValue
  4106. resp := new(data_manage.EdbInfoDataResp)
  4107. resp.EdbInfo = edbInfo
  4108. resp.DataList = dataList
  4109. br.Ret = 200
  4110. br.Success = true
  4111. br.Msg = "获取成功"
  4112. br.Data = resp
  4113. }
  4114. // EdbInfoDataSeasonal
  4115. // @Title 获取指标数据(季节性)
  4116. // @Description 获取指标数据
  4117. // @Param EdbInfoId query int true "指标ID"
  4118. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4119. // @Param StartDate query string true "自定义开始日期"
  4120. // @Param EndDate query string true "自定义结束日期"
  4121. // @Param Calendar query string true "公历/农历"
  4122. // @Success 200 {object} data_manage.EdbInfoDataResp
  4123. // @router /edb_info/data/seasonal [get]
  4124. func (this *ChartInfoController) EdbInfoDataSeasonal() {
  4125. br := new(models.BaseResponse).Init()
  4126. defer func() {
  4127. this.Data["json"] = br
  4128. this.ServeJSON()
  4129. }()
  4130. sysUser := this.SysUser
  4131. if sysUser == nil {
  4132. br.Msg = "请登录"
  4133. br.ErrMsg = "请登录,SysUser Is Empty"
  4134. br.Ret = 408
  4135. return
  4136. }
  4137. dateType, _ := this.GetInt("DateType")
  4138. startDate := this.GetString("StartDate")
  4139. endDate := this.GetString("EndDate")
  4140. startYear, _ := this.GetInt("StartYear")
  4141. edbInfoIdStr := this.GetString("EdbInfoId")
  4142. edbInfoId, err := strconv.Atoi(edbInfoIdStr)
  4143. if err != nil {
  4144. br.Msg = "指标id异常"
  4145. br.Msg = "指标id转换异常,Err:" + err.Error()
  4146. return
  4147. }
  4148. fmt.Println("startDate:", startDate)
  4149. fmt.Println("endDate:", endDate)
  4150. calendar := this.GetString("Calendar")
  4151. if calendar == "" {
  4152. calendar = "公历"
  4153. }
  4154. if dateType == 0 {
  4155. if startDate == "" {
  4156. dateType = utils.DateTypeNYears
  4157. } else {
  4158. dateType = 5
  4159. }
  4160. }
  4161. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4162. if err != nil {
  4163. br.Msg = "获取失败"
  4164. br.Msg = "获取失败,Err:" + err.Error()
  4165. return
  4166. }
  4167. maxYear := 0
  4168. if edbInfo.LatestDate != "" {
  4169. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4170. maxYear = latestDateT.Year()
  4171. }
  4172. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  4173. dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
  4174. if err != nil {
  4175. br.Msg = "获取失败"
  4176. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  4177. return
  4178. }
  4179. resp := new(data_manage.EdbInfoDataSeasonalResp)
  4180. resp.EdbInfo = edbInfo
  4181. resp.DataList = dataList
  4182. br.Ret = 200
  4183. br.Success = true
  4184. br.Msg = "获取成功"
  4185. br.Data = resp
  4186. }
  4187. // SetEdbDataInsertConfig 设置插入值
  4188. // @Title 设置插入值接口
  4189. // @Description 设置插入值接口
  4190. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  4191. // @router /edb_info/insert_config/set [post]
  4192. func (this *EdbInfoController) SetEdbDataInsertConfig() {
  4193. br := new(models.BaseResponse).Init()
  4194. defer func() {
  4195. this.Data["json"] = br
  4196. this.ServeJSON()
  4197. }()
  4198. sysUser := this.SysUser
  4199. if sysUser == nil {
  4200. br.Msg = "请登录"
  4201. br.ErrMsg = "请登录,SysUser Is Empty"
  4202. br.Ret = 408
  4203. return
  4204. }
  4205. var req data_manage.SetEdbDataInsertConfigReq
  4206. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4207. if err != nil {
  4208. br.Msg = "参数解析异常!"
  4209. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4210. return
  4211. }
  4212. dateStr := req.Date
  4213. if dateStr == `` {
  4214. br.Msg = "请选择日期"
  4215. br.IsSendEmail = false
  4216. return
  4217. }
  4218. date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
  4219. if err != nil {
  4220. br.Msg = "日期异常"
  4221. br.ErrMsg = "日期异常,err:" + err.Error()
  4222. br.IsSendEmail = false
  4223. return
  4224. }
  4225. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  4226. if err != nil {
  4227. br.Msg = "获取指标信息失败"
  4228. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  4229. return
  4230. }
  4231. err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
  4232. if err != nil {
  4233. br.Msg = "设置失败"
  4234. if errMsg != `` {
  4235. br.Msg = errMsg
  4236. }
  4237. br.ErrMsg = "修改失败,Err:" + err.Error()
  4238. br.IsSendEmail = isSendEmail
  4239. return
  4240. }
  4241. //新增操作日志
  4242. {
  4243. edbLog := new(data_manage.EdbInfoLog)
  4244. edbLog.EdbInfoId = edbInfo.EdbInfoId
  4245. edbLog.SourceName = edbInfo.SourceName
  4246. edbLog.Source = edbInfo.Source
  4247. edbLog.EdbCode = edbInfo.EdbCode
  4248. edbLog.EdbName = edbInfo.EdbName
  4249. edbLog.ClassifyId = edbInfo.ClassifyId
  4250. edbLog.SysUserId = sysUser.AdminId
  4251. edbLog.SysUserRealName = sysUser.RealName
  4252. edbLog.CreateTime = time.Now()
  4253. edbLog.Content = string(this.Ctx.Input.RequestBody)
  4254. edbLog.Status = "设置插入值"
  4255. edbLog.Method = this.Ctx.Input.URI()
  4256. go data_manage.AddEdbInfoLog(edbLog)
  4257. }
  4258. br.Ret = 200
  4259. br.Success = true
  4260. br.Msg = "保存成功"
  4261. br.IsAddLog = true
  4262. }
  4263. // TraceEdbInfo
  4264. // @Title 指标溯源接口
  4265. // @Description 指标溯源接口
  4266. // @Param UniqueCode query int true "指标唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  4267. // @Success 200 {object} data_manage.ChartListResp
  4268. // @router /edb_info/trace [get]
  4269. func (this *EdbInfoController) TraceEdbInfo() {
  4270. br := new(models.BaseResponse).Init()
  4271. defer func() {
  4272. this.Data["json"] = br
  4273. this.ServeJSON()
  4274. }()
  4275. sysUser := this.SysUser
  4276. if sysUser == nil {
  4277. br.Msg = "请登录"
  4278. br.ErrMsg = "请登录,SysUser Is Empty"
  4279. br.Ret = 408
  4280. return
  4281. }
  4282. //edbInfoId, _ := this.GetInt("EdbInfoId")
  4283. //if edbInfoId <= 0 {
  4284. // br.Msg = "参数错误"
  4285. // br.ErrMsg = "参数错误"
  4286. // return
  4287. //}
  4288. uniqueCode := this.GetString("UniqueCode")
  4289. if uniqueCode == `` {
  4290. br.Msg = "参数错误"
  4291. br.ErrMsg = "参数错误"
  4292. return
  4293. }
  4294. // 根据UniqueCode获取指标信息
  4295. edbInfo, err := data_manage.GetEdbInfoByUniqueCode(uniqueCode)
  4296. if err != nil {
  4297. br.Msg = "获取失败"
  4298. br.Msg = "获取失败,Err:" + err.Error()
  4299. if err.Error() == utils.ErrNoRow() {
  4300. br.Msg = "指标不存在"
  4301. }
  4302. return
  4303. }
  4304. resp, err := data.TraceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, this.SysUser.AdminId)
  4305. if err != nil {
  4306. br.Msg = "获取失败"
  4307. br.Msg = "获取失败,Err:" + err.Error()
  4308. return
  4309. }
  4310. br.Ret = 200
  4311. br.Data = resp
  4312. br.Success = true
  4313. br.Msg = "刷新成功"
  4314. }
  4315. // AllEdbInfoByEs
  4316. // @Title 所有指标筛选接口
  4317. // @Description 所有指标筛选接口
  4318. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  4319. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  4320. // @Param Frequency query string false "频度"
  4321. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  4322. // @Param PageSize query int true "每页数据条数"
  4323. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4324. // @Success 200 {object} data_manage.EdbInfoList
  4325. // @router /edb_info/filter_by_es/all [get]
  4326. func (this *EdbInfoController) AllEdbInfoByEs() {
  4327. br := new(models.BaseResponse).Init()
  4328. defer func() {
  4329. this.Data["json"] = br
  4330. this.ServeJSON()
  4331. }()
  4332. pageSize, _ := this.GetInt("PageSize")
  4333. currentIndex, _ := this.GetInt("CurrentIndex")
  4334. var total int64
  4335. var startSize int
  4336. if pageSize <= 0 {
  4337. pageSize = utils.PageSize20
  4338. }
  4339. if currentIndex <= 0 {
  4340. currentIndex = 1
  4341. }
  4342. startSize = paging.StartIndex(currentIndex, pageSize)
  4343. keyWord := this.GetString("KeyWord")
  4344. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  4345. filterSource, _ := this.GetInt("FilterSource")
  4346. if filterSource <= 0 {
  4347. filterSource = 1
  4348. }
  4349. //指标来源
  4350. source, _ := this.GetInt("Source")
  4351. frequency := this.GetString("Frequency") //频度
  4352. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  4353. var edbInfoList []*data_manage.EdbInfoList
  4354. var err error
  4355. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  4356. // 获取当前账号的不可见指标
  4357. {
  4358. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4359. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4360. if err != nil && err.Error() != utils.ErrNoRow() {
  4361. br.Msg = "获取失败"
  4362. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  4363. return
  4364. }
  4365. for _, v := range confList {
  4366. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  4367. }
  4368. }
  4369. // 是否走ES
  4370. isEs := false
  4371. if keyWord != "" {
  4372. var keyWordArr []string
  4373. keyWordArr = append(keyWordArr, keyWord)
  4374. newKeyWord := strings.Split(keyWord, " ")
  4375. keyWordArr = append(keyWordArr, newKeyWord...)
  4376. // 普通的搜索
  4377. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, frequency, noPermissionEdbInfoIdList)
  4378. isEs = true
  4379. } else {
  4380. var condition string
  4381. var pars []interface{}
  4382. // 普通指标
  4383. condition += ` AND edb_info_type = ? `
  4384. pars = append(pars, 0)
  4385. // 无权限指标id
  4386. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  4387. if lenNoPermissionEdbInfoIdList > 0 {
  4388. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  4389. pars = append(pars, noPermissionEdbInfoIdList)
  4390. }
  4391. switch filterSource {
  4392. case 2:
  4393. condition += ` AND frequency='月度' `
  4394. case 3:
  4395. condition += ` AND frequency <> '日度' `
  4396. case 4:
  4397. condition += ` AND edb_type = 1 `
  4398. case 5:
  4399. condition += ` AND source = 6 ` //来源(同比值)
  4400. case 6:
  4401. condition += ` AND frequency != ? `
  4402. pars = append(pars, "年度")
  4403. }
  4404. //频度
  4405. if frequency != "" {
  4406. condition += ` AND frequency = ? `
  4407. pars = append(pars, frequency)
  4408. }
  4409. // 查询只允许添加预测指标的搜索
  4410. if isAddPredictEdb {
  4411. condition += ` AND frequency in ("日度","周度","月度") `
  4412. }
  4413. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  4414. }
  4415. if err != nil {
  4416. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  4417. }
  4418. page := paging.GetPaging(currentIndex, pageSize, int(total))
  4419. edbInfoListLen := len(edbInfoList)
  4420. classifyIdList := make([]int, 0)
  4421. for i := 0; i < edbInfoListLen; i++ {
  4422. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  4423. classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
  4424. }
  4425. // 当前列表中的分类map
  4426. classifyMap := make(map[int]*data_manage.EdbClassify)
  4427. if edbInfoListLen > 0 {
  4428. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4429. if err != nil {
  4430. br.Msg = "获取失败"
  4431. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4432. return
  4433. }
  4434. for _, v := range classifyList {
  4435. classifyMap[v.ClassifyId] = v
  4436. }
  4437. // 获取所有有权限的指标和分类
  4438. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4439. if err != nil {
  4440. br.Msg = "获取失败"
  4441. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4442. return
  4443. }
  4444. // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  4445. if isEs {
  4446. edbInfoIdList := make([]int, 0)
  4447. for i := 0; i < edbInfoListLen; i++ {
  4448. edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
  4449. tmpEdbInfo := edbInfoList[i]
  4450. if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
  4451. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4452. }
  4453. }
  4454. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  4455. if err != nil {
  4456. br.Msg = "获取失败"
  4457. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4458. return
  4459. }
  4460. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  4461. for _, v := range tmpEdbList {
  4462. edbInfoMap[v.EdbInfoId] = v
  4463. }
  4464. for i := 0; i < edbInfoListLen; i++ {
  4465. tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
  4466. if !ok {
  4467. continue
  4468. }
  4469. edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
  4470. }
  4471. }
  4472. // 权限校验
  4473. for i := 0; i < edbInfoListLen; i++ {
  4474. tmpEdbInfoItem := edbInfoList[i]
  4475. if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
  4476. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4477. }
  4478. }
  4479. }
  4480. for i := 0; i < edbInfoListLen; i++ {
  4481. for j := 0; j < edbInfoListLen; j++ {
  4482. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  4483. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  4484. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  4485. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  4486. }
  4487. }
  4488. }
  4489. //新增搜索词记录
  4490. {
  4491. searchKeyword := new(data_manage.SearchKeyword)
  4492. searchKeyword.KeyWord = keyWord
  4493. searchKeyword.CreateTime = time.Now()
  4494. go data_manage.AddSearchKeyword(searchKeyword)
  4495. }
  4496. resp := data_manage.EdbInfoFilterDataResp{
  4497. Paging: page,
  4498. List: edbInfoList,
  4499. }
  4500. br.Ret = 200
  4501. br.Success = true
  4502. br.Msg = "获取成功"
  4503. br.Data = resp
  4504. }
  4505. // GetEdbDateData
  4506. // @Title 根据指标ID和具体日期获取对应日期的数据值
  4507. // @Description 根据指标ID和具体日期获取对应日期的数据值
  4508. // @Param EdbInfoId query int false "指标id"
  4509. // @Param Date query string false "日期"
  4510. // @Success 200 {object} data_manage.EdbInfoList
  4511. // @router /edb_info/date_data [get]
  4512. func (this *EdbInfoController) GetEdbDateData() {
  4513. br := new(models.BaseResponse).Init()
  4514. defer func() {
  4515. this.Data["json"] = br
  4516. this.ServeJSON()
  4517. }()
  4518. edbInfoId, _ := this.GetInt("EdbInfoId")
  4519. date := this.GetString("Date")
  4520. if edbInfoId <= 0 {
  4521. br.Msg = "请选择指标"
  4522. br.IsSendEmail = false
  4523. return
  4524. }
  4525. if date == `` {
  4526. br.Msg = "请选择日期"
  4527. br.IsSendEmail = false
  4528. return
  4529. }
  4530. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4531. if err != nil {
  4532. br.Msg = "获取失败"
  4533. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4534. return
  4535. }
  4536. startDate := date
  4537. endDate := date
  4538. dateType := "day"
  4539. //如果填写的是月度日期
  4540. if strings.Count(date, "-") == 1 {
  4541. startDate = date + "-01"
  4542. endDate = ``
  4543. dateType = "month"
  4544. }
  4545. dataItem, err := data.GetDateData(edbInfo, startDate, endDate)
  4546. if err != nil {
  4547. br.Msg = "获取失败"
  4548. br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
  4549. return
  4550. }
  4551. val := ``
  4552. if dataItem != nil {
  4553. switch dateType {
  4554. case "month":
  4555. dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local)
  4556. dateTimeStr := dateTime.Format(utils.FormatYearMonthDate)
  4557. if dateTimeStr != date {
  4558. val = ``
  4559. }
  4560. }
  4561. val = fmt.Sprint(dataItem.Value)
  4562. }
  4563. br.Ret = 200
  4564. br.Success = true
  4565. br.Msg = "获取成功"
  4566. br.Data = val
  4567. }
  4568. // GetEdbBeforeAndAfterDateData
  4569. // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4570. // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4571. // @Param EdbInfoId query int false "指标id"
  4572. // @Param Date query string false "日期"
  4573. // @Param Num query int false "前后几期数据"
  4574. // @Success 200 {object} data_manage.EdbInfoList
  4575. // @router /edb_info/date_data/before_after [post]
  4576. func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
  4577. br := new(models.BaseResponse).Init()
  4578. defer func() {
  4579. this.Data["json"] = br
  4580. this.ServeJSON()
  4581. }()
  4582. requestBody := string(this.Ctx.Input.RequestBody)
  4583. var req request2.DateDataBeforeAfterReq
  4584. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4585. if err != nil {
  4586. br.Msg = "参数解析异常!"
  4587. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4588. return
  4589. }
  4590. edbInfoId := req.EdbInfoId
  4591. currDate := req.Date
  4592. num := req.Num
  4593. // 默认2期数据
  4594. if num <= 0 {
  4595. num = 2
  4596. }
  4597. if edbInfoId <= 0 {
  4598. br.Msg = "请选择指标"
  4599. br.IsSendEmail = false
  4600. return
  4601. }
  4602. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4603. if err != nil {
  4604. br.Msg = "获取失败"
  4605. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4606. return
  4607. }
  4608. dataList := make([]*data_manage.EdbDataList, 0)
  4609. switch edbInfo.EdbInfoType {
  4610. case 0:
  4611. dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
  4612. case 1:
  4613. _, dataList, _, _, _, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  4614. default:
  4615. br.Msg = "指标类型异常!"
  4616. br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType)
  4617. return
  4618. }
  4619. if currDate == `` {
  4620. currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList)
  4621. if err != nil {
  4622. br.Msg = "日期前移失败"
  4623. br.ErrMsg = "日期前移失败,Err:" + err.Error()
  4624. return
  4625. }
  4626. } else {
  4627. if strings.Count(currDate, "-") == 1 {
  4628. currDate = currDate + "-01"
  4629. // 查找这个月早的时间作为起始时间
  4630. for _, v := range dataList {
  4631. if v.DataTime >= currDate {
  4632. currDate = v.DataTime
  4633. break
  4634. }
  4635. }
  4636. }
  4637. }
  4638. currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody)
  4639. if err != nil {
  4640. br.Msg = "日期变换失败"
  4641. br.ErrMsg = "日期变换失败,Err:" + err.Error()
  4642. return
  4643. }
  4644. list := make([]*data_manage.EdbDataList, 5)
  4645. list, err = data.GetEdbBeforeAndAfterDateData(currDate, dataList)
  4646. if err != nil {
  4647. br.Msg = "获取失败"
  4648. br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
  4649. return
  4650. }
  4651. // 这个日期不存在的话直接返回空数组
  4652. resp := data_manage.BeforeAndAfterDateDataResp{
  4653. List: list,
  4654. Date: currDate,
  4655. }
  4656. br.Ret = 200
  4657. br.Success = true
  4658. br.Msg = "获取成功"
  4659. br.Data = resp
  4660. }
  4661. // EdbChartAdminList
  4662. // @Title 获取创建人员分组
  4663. // @Description 获取创建人员分组
  4664. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  4665. // @Success 200 {object} company.DepartmentGroupSellersResp
  4666. // @router /edb_chart/adminList [get]
  4667. func (this *EdbInfoController) EdbChartAdminList() {
  4668. br := new(models.BaseResponse).Init()
  4669. defer func() {
  4670. this.Data["json"] = br
  4671. this.ServeJSON()
  4672. }()
  4673. sysUser := this.SysUser
  4674. if sysUser == nil {
  4675. br.Msg = "请登录"
  4676. br.ErrMsg = "请登录,SysUser Is Empty"
  4677. br.Ret = 408
  4678. return
  4679. }
  4680. source, _ := this.GetInt("Source", 0)
  4681. if source <= 0 || source > 5 {
  4682. br.Msg = "错误的来源"
  4683. br.IsSendEmail = false
  4684. return
  4685. }
  4686. idList, err := data.GetEdbChartAdminList(source)
  4687. if err != nil {
  4688. //br.Success = true
  4689. br.Msg = "获取失败"
  4690. br.ErrMsg = "获取失败,Err:" + err.Error()
  4691. return
  4692. }
  4693. fmt.Println("idlist:", idList)
  4694. systemAdminMap := make(map[int]*system.Admin)
  4695. departmentMap := make(map[string]string)
  4696. departmentAdminMap := make(map[int]string)
  4697. groupMap := make(map[string]string)
  4698. systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList)
  4699. if err != nil {
  4700. br.Msg = "获取用户列表失败"
  4701. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  4702. return
  4703. }
  4704. for _, v := range systemAdminList {
  4705. systemAdminMap[v.AdminId] = v
  4706. departmentMap[v.DepartmentName] = v.DepartmentName
  4707. departmentAdminMap[v.AdminId] = v.DepartmentName
  4708. groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName
  4709. }
  4710. depList := make([]company.DepartmentGroupAdmins, 0)
  4711. i := 1
  4712. for _, v := range departmentMap {
  4713. item := company.DepartmentGroupAdmins{
  4714. AdminId: "dep_" + strconv.Itoa(i),
  4715. RealName: v,
  4716. }
  4717. i++
  4718. depList = append(depList, item)
  4719. }
  4720. for k := 0; k < len(depList); k++ {
  4721. for k1, v1 := range groupMap {
  4722. if v1 == depList[k].RealName && v1 != "" {
  4723. item := &company.DepartmentGroupAdmins{
  4724. AdminId: "group_" + strconv.Itoa(k),
  4725. RealName: strings.Replace(k1, v1, "", -1),
  4726. }
  4727. depList[k].ChildrenList = append(depList[k].ChildrenList, item)
  4728. }
  4729. }
  4730. }
  4731. for _, admin := range systemAdminList {
  4732. for i, v := range depList {
  4733. for k, group := range v.ChildrenList {
  4734. if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName {
  4735. item := &company.DepartmentGroupAdmins{
  4736. AdminId: strconv.Itoa(admin.AdminId),
  4737. RealName: admin.RealName,
  4738. RoleTypeCode: admin.RoleTypeCode,
  4739. Authority: admin.Authority,
  4740. }
  4741. if group.RealName != "" {
  4742. depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item)
  4743. } else {
  4744. depList[i].ChildrenList = append(depList[i].ChildrenList, item)
  4745. }
  4746. }
  4747. }
  4748. }
  4749. }
  4750. for i, groupList := range depList {
  4751. for k, v := range groupList.ChildrenList {
  4752. if v.RealName == "" {
  4753. newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...)
  4754. depList[i].ChildrenList = newChildrenList
  4755. }
  4756. }
  4757. }
  4758. br.Ret = 200
  4759. br.Success = true
  4760. br.Msg = "获取成功"
  4761. br.Data = depList
  4762. }
  4763. // EdbSourceList
  4764. // @Title 指标来源列表
  4765. // @Description 指标来源列表
  4766. // @Param IsBase query int false "是否为基础指标: 1-是"
  4767. // @Success 200 {object} data_manage.EdbInfoListResp
  4768. // @router /edb_source/list [get]
  4769. func (this *EdbInfoController) EdbSourceList() {
  4770. br := new(models.BaseResponse).Init()
  4771. defer func() {
  4772. if br.ErrMsg == "" {
  4773. br.IsSendEmail = false
  4774. }
  4775. this.Data["json"] = br
  4776. this.ServeJSON()
  4777. }()
  4778. isBase, _ := this.GetInt("IsBase", 0)
  4779. cond := ``
  4780. if isBase > 0 {
  4781. cond = ` AND is_base = 1`
  4782. }
  4783. pars := make([]interface{}, 0)
  4784. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4785. if e != nil {
  4786. br.Msg = "获取失败"
  4787. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4788. return
  4789. }
  4790. br.Data = list
  4791. br.Ret = 200
  4792. br.Success = true
  4793. br.Msg = "获取成功"
  4794. }
  4795. // EdbSourceListByPython
  4796. // @Title 指标来源列表
  4797. // @Description 指标来源列表
  4798. // @Param IsBase query int false "是否为基础指标: 1-是"
  4799. // @Success 200 {object} data_manage.EdbInfoListResp
  4800. // @router /edb_source/list/python [get]
  4801. func (this *EdbInfoController) EdbSourceListByPython() {
  4802. br := new(models.BaseResponse).Init()
  4803. defer func() {
  4804. if br.ErrMsg == "" {
  4805. br.IsSendEmail = false
  4806. }
  4807. this.Data["json"] = br
  4808. this.ServeJSON()
  4809. }()
  4810. isBase, _ := this.GetInt("IsBase", 0)
  4811. cond := ``
  4812. if isBase > 0 {
  4813. cond = ` AND is_base = 1`
  4814. }
  4815. pars := make([]interface{}, 0)
  4816. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4817. if e != nil {
  4818. br.Msg = "获取失败"
  4819. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4820. return
  4821. }
  4822. baseEdbList := make([]data_manage.EdbSourceChild, 0)
  4823. calEdbList := make([]data_manage.EdbSourceChild, 0)
  4824. for _, v := range list {
  4825. switch v.IsBase {
  4826. case 1:
  4827. baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{
  4828. EdbSourceId: v.EdbSourceId,
  4829. SourceName: v.SourceName,
  4830. IsBase: v.IsBase,
  4831. TableName: v.TableName,
  4832. Child: []data_manage.EdbSourceChild{},
  4833. })
  4834. case 2:
  4835. calEdbList = append(calEdbList, data_manage.EdbSourceChild{
  4836. EdbSourceId: v.EdbSourceId,
  4837. SourceName: v.SourceName,
  4838. IsBase: v.IsBase,
  4839. TableName: v.TableName,
  4840. Child: []data_manage.EdbSourceChild{},
  4841. })
  4842. }
  4843. }
  4844. resp := []data_manage.EdbSourceChild{
  4845. {
  4846. EdbSourceId: 0,
  4847. SourceName: "基础指标",
  4848. IsBase: 1,
  4849. Child: baseEdbList,
  4850. },
  4851. {
  4852. EdbSourceId: 0,
  4853. SourceName: "计算指标",
  4854. IsBase: 1,
  4855. Child: calEdbList,
  4856. },
  4857. }
  4858. br.Data = resp
  4859. br.Ret = 200
  4860. br.Success = true
  4861. br.Msg = "获取成功"
  4862. }
  4863. // EdbChartList
  4864. // @Title 指标缩略图列表接口
  4865. // @Description 指标缩略图列表接口
  4866. // @Param PageSize query int true "每页数据条数"
  4867. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4868. // @Param ClassifyId query int true "分类id"
  4869. // @Param AdminId query int false "创建人id"
  4870. // @Param IsOnlyMe query bool false "是否只看我的"
  4871. // @Success 200 {object} response.EdbInfoChartListResp
  4872. // @router /edb_info/chart/list [get]
  4873. func (this *EdbInfoController) EdbChartList() {
  4874. br := new(models.BaseResponse).Init()
  4875. defer func() {
  4876. if br.ErrMsg == "" {
  4877. br.IsSendEmail = false
  4878. }
  4879. this.Data["json"] = br
  4880. this.ServeJSON()
  4881. }()
  4882. sysUser := this.SysUser
  4883. if sysUser == nil {
  4884. br.Msg = "请登录"
  4885. br.ErrMsg = "请登录,SysUser Is Empty"
  4886. br.Ret = 408
  4887. return
  4888. }
  4889. // 分页
  4890. pageSize, _ := this.GetInt("PageSize")
  4891. currentIndex, _ := this.GetInt("CurrentIndex")
  4892. var total int
  4893. page := paging.GetPaging(currentIndex, pageSize, total)
  4894. var startSize int
  4895. if pageSize <= 0 {
  4896. pageSize = utils.PageSize20
  4897. }
  4898. if currentIndex <= 0 {
  4899. currentIndex = 1
  4900. }
  4901. startSize = paging.StartIndex(currentIndex, pageSize)
  4902. // 基础指标
  4903. var condition string
  4904. var pars []interface{}
  4905. condition += ` AND edb_info_type = ? `
  4906. pars = append(pars, 0)
  4907. // 分类筛选
  4908. classifyId, _ := this.GetInt("ClassifyId")
  4909. if classifyId > 0 {
  4910. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  4911. if e != nil && e.Error() != utils.ErrNoRow() {
  4912. br.Msg = "获取失败"
  4913. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  4914. return
  4915. }
  4916. var classifyIds []int
  4917. for _, v := range childClassify {
  4918. classifyIds = append(classifyIds, v.ClassifyId)
  4919. }
  4920. condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  4921. pars = append(pars, classifyIds)
  4922. }
  4923. // 创建人
  4924. adminId, _ := this.GetInt("AdminId")
  4925. if adminId > 0 {
  4926. condition += ` AND sys_user_id = ? `
  4927. pars = append(pars, adminId)
  4928. }
  4929. // 只看我的
  4930. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  4931. if isOnlyMe {
  4932. condition += ` AND sys_user_id = ? `
  4933. pars = append(pars, sysUser.AdminId)
  4934. }
  4935. // 获取当前账号的不可见指标
  4936. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4937. confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4938. if e != nil {
  4939. br.Msg = "获取失败"
  4940. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
  4941. return
  4942. }
  4943. noPermissionEdbInfoIdList := make([]int, 0)
  4944. for _, v := range confList {
  4945. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  4946. }
  4947. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  4948. if noPermissionEdbInfoIdNum > 0 {
  4949. condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  4950. pars = append(pars, noPermissionEdbInfoIdList)
  4951. }
  4952. // 获取指标信息
  4953. dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  4954. if e != nil {
  4955. br.Msg = "获取失败"
  4956. br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
  4957. return
  4958. }
  4959. if len(list) == 0 {
  4960. list = make([]*data_manage.EdbInfoList, 0)
  4961. } else {
  4962. classifyIdList := make([]int, 0)
  4963. for _, v := range list {
  4964. classifyIdList = append(classifyIdList, v.ClassifyId)
  4965. }
  4966. // 指标权限
  4967. {
  4968. // 当前的分类
  4969. classifyMap := make(map[int]*data_manage.EdbClassify)
  4970. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4971. if err != nil {
  4972. if err != nil {
  4973. br.Msg = "获取失败"
  4974. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4975. return
  4976. }
  4977. }
  4978. for _, v := range classifyList {
  4979. classifyMap[v.ClassifyId] = v
  4980. }
  4981. // 获取所有有权限的指标和分类
  4982. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4983. if err != nil {
  4984. br.Msg = "获取失败"
  4985. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4986. return
  4987. }
  4988. for _, v := range list {
  4989. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  4990. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4991. v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType, v.HaveOperaAuth)
  4992. }
  4993. }
  4994. }
  4995. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  4996. }
  4997. resp := response.EdbInfoChartListResp{
  4998. Paging: page,
  4999. List: list,
  5000. }
  5001. br.Ret = 200
  5002. br.Success = true
  5003. br.Msg = "获取成功"
  5004. br.Data = resp
  5005. }
  5006. // Modify
  5007. // @Title 修改指标信息接口
  5008. // @Description 编辑指标接口
  5009. // @Success 200 string "操作成功"
  5010. // @router /edb_info/modify [post]
  5011. func (this *EdbInfoController) Modify() {
  5012. br := new(models.BaseResponse).Init()
  5013. defer func() {
  5014. if br.ErrMsg == "" {
  5015. br.IsSendEmail = false
  5016. }
  5017. this.Data["json"] = br
  5018. this.ServeJSON()
  5019. }()
  5020. sysUser := this.SysUser
  5021. if sysUser == nil {
  5022. br.Msg = "请登录"
  5023. br.ErrMsg = "请登录,SysUser Is Empty"
  5024. br.Ret = 408
  5025. return
  5026. }
  5027. var req request.ModifyEdbInfoReq
  5028. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5029. if err != nil {
  5030. br.Msg = "参数解析异常!"
  5031. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5032. return
  5033. }
  5034. edbInfoId := req.EdbInfoId
  5035. if edbInfoId <= 0 {
  5036. br.Msg = "请选择指标"
  5037. br.IsSendEmail = false
  5038. return
  5039. }
  5040. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5041. if e != nil {
  5042. br.Msg = "操作失败"
  5043. br.ErrMsg = "获取指标信息失败, Err:" + err.Error()
  5044. return
  5045. }
  5046. var haveOperaAuth bool
  5047. // 权限校验
  5048. {
  5049. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
  5050. if err != nil {
  5051. br.Msg = err.Error()
  5052. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  5053. return
  5054. }
  5055. }
  5056. // 编辑权限校验
  5057. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  5058. if !button.OpButton {
  5059. br.Msg = "无权限操作"
  5060. return
  5061. }
  5062. edbInfo.MaxValue = req.MaxValue
  5063. edbInfo.MinValue = req.MinValue
  5064. edbInfo.ManualSave = 1
  5065. edbInfo.ModifyTime = time.Now()
  5066. err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"})
  5067. if err != nil {
  5068. br.Msg = "获取失败"
  5069. br.ErrMsg = "获取失败,Err:" + err.Error()
  5070. return
  5071. }
  5072. //修改es
  5073. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  5074. br.Ret = 200
  5075. br.Success = true
  5076. br.Msg = "修改成功"
  5077. br.IsAddLog = true
  5078. }
  5079. // ChartImageSet
  5080. // @Title 设置指标的图表图片
  5081. // @Description 设置指标的图表图片接口
  5082. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  5083. // @Success Ret=200 保存成功
  5084. // @router /edb_info/image/set [post]
  5085. func (this *EdbInfoController) ChartImageSet() {
  5086. br := new(models.BaseResponse).Init()
  5087. defer func() {
  5088. if br.ErrMsg == "" {
  5089. br.IsSendEmail = false
  5090. }
  5091. this.Data["json"] = br
  5092. this.ServeJSON()
  5093. }()
  5094. sysUser := this.SysUser
  5095. if sysUser == nil {
  5096. br.Msg = "请登录"
  5097. br.ErrMsg = "请登录,SysUser Is Empty"
  5098. br.Ret = 408
  5099. return
  5100. }
  5101. var req data_manage.SetEdbInfoImageReq
  5102. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  5103. br.Msg = "参数解析异常!"
  5104. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  5105. return
  5106. }
  5107. if req.EdbInfoId <= 0 || req.ImageUrl == "" {
  5108. br.Ret = 200
  5109. br.Success = true
  5110. br.Msg = "保存成功"
  5111. return
  5112. }
  5113. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5114. if e != nil {
  5115. if e.Error() == utils.ErrNoRow() {
  5116. br.Msg = "找不到该指标"
  5117. return
  5118. }
  5119. br.Msg = "保存失败"
  5120. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  5121. return
  5122. }
  5123. edbInfo.ChartImage = req.ImageUrl
  5124. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  5125. br.Msg = "保存失败"
  5126. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  5127. return
  5128. }
  5129. // 修改es数据
  5130. go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  5131. br.Ret = 200
  5132. br.Success = true
  5133. br.Msg = "保存成功"
  5134. }
  5135. // EdbInfoExistCheck
  5136. // @Title 新增指标-检验指标是否存在接口
  5137. // @Description 新增指标-检验指标是否存在接口
  5138. // @Param Source query int true "来源:1:同花顺,2:wind"
  5139. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5140. // @Param EdbCode query string false "指标编码/指标代码"
  5141. // @Param StockCode query string false "证券代码"
  5142. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5143. // @router /edb_info/exist/check [get]
  5144. func (this *EdbInfoController) EdbInfoExistCheck() {
  5145. br := new(models.BaseResponse).Init()
  5146. defer func() {
  5147. this.Data["json"] = br
  5148. this.ServeJSON()
  5149. }()
  5150. source, _ := this.GetInt("Source")
  5151. edbCode := this.GetString("EdbCode")
  5152. edbCode = strings.Trim(edbCode, "\t")
  5153. edbCode = strings.Trim(edbCode, " ")
  5154. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5155. subSource, _ := this.GetInt("SubSource")
  5156. stockCode := this.GetString("StockCode")
  5157. if source <= 0 {
  5158. br.Msg = "无效的数据来源"
  5159. return
  5160. }
  5161. if edbCode == "" {
  5162. br.Msg = "请输入指标ID"
  5163. return
  5164. }
  5165. if source != utils.DATA_SOURCE_WIND && source != utils.DATA_SOURCE_THS {
  5166. br.Msg = "无效的数据来源"
  5167. return
  5168. }
  5169. if subSource != utils.DATA_SUB_SOURCE_DATE {
  5170. br.Msg = "无效的数据库来源"
  5171. return
  5172. }
  5173. var indexCodeArr []string
  5174. edbCodeArr := strings.Split(edbCode, ",")
  5175. stockCodeArr := strings.Split(stockCode, ",")
  5176. var prefix string
  5177. if source == utils.DATA_SOURCE_WIND {
  5178. prefix = utils.WindDbWsd
  5179. } else if source == utils.DATA_SOURCE_THS {
  5180. prefix = utils.ThsDs
  5181. } else {
  5182. br.Msg = "来源错误"
  5183. br.ErrMsg = "来源错误"
  5184. return
  5185. }
  5186. for _, sv := range stockCodeArr {
  5187. for _, ev := range edbCodeArr {
  5188. indexCode := prefix + sv + ev
  5189. indexCodeArr = append(indexCodeArr, indexCode)
  5190. }
  5191. }
  5192. indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr)
  5193. if err != nil && err.Error() != utils.ErrNoRow() {
  5194. br.Msg = "校验指标是否存在失败"
  5195. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5196. return
  5197. }
  5198. var existStockCodeArr []string
  5199. var existEdbCodeArr []string
  5200. var existClassifyId []int
  5201. var existIndexId []int
  5202. for _, indexItem := range indexList {
  5203. for _, sv := range stockCodeArr {
  5204. for _, ev := range edbCodeArr {
  5205. if strings.Contains(indexItem.EdbCode, sv) {
  5206. existStockCodeArr = append(existStockCodeArr, sv)
  5207. }
  5208. if strings.Contains(indexItem.EdbCode, ev) {
  5209. existEdbCodeArr = append(existEdbCodeArr, ev)
  5210. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5211. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5212. }
  5213. }
  5214. }
  5215. }
  5216. resp := new(data_manage.EdbInfoExistCheckResp)
  5217. if len(indexList) > 0 {
  5218. resp.IndexExist = true
  5219. }
  5220. resp.ExistEdbCodeArr = existEdbCodeArr
  5221. resp.ExistStockCodeArr = existStockCodeArr
  5222. resp.ExistClassifyId = existClassifyId
  5223. resp.ExistIndexId = existIndexId
  5224. resp.ExistEdbInfo = indexList
  5225. br.Ret = 200
  5226. br.Success = true
  5227. br.Msg = "获取成功"
  5228. br.Data = resp
  5229. }
  5230. // EdbInfoAdd
  5231. // @Title 指标批量保存接口
  5232. // @Description 指标批量保存接口
  5233. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  5234. // @Success Ret=200 保存成功
  5235. // @router /edb_info/batch/add [post]
  5236. func (this *EdbInfoController) EdbInfoBatchAdd() {
  5237. br := new(models.BaseResponse).Init()
  5238. defer func() {
  5239. this.Data["json"] = br
  5240. this.ServeJSON()
  5241. }()
  5242. sysUser := this.SysUser
  5243. if sysUser == nil {
  5244. br.Msg = "请登录"
  5245. br.ErrMsg = "请登录,SysUser Is Empty"
  5246. br.Ret = 408
  5247. return
  5248. }
  5249. deleteCache := true
  5250. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  5251. defer func() {
  5252. if deleteCache {
  5253. utils.Rc.Delete(cacheKey)
  5254. }
  5255. }()
  5256. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  5257. deleteCache = false
  5258. br.Msg = "系统处理中,请稍后重试!"
  5259. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  5260. return
  5261. }
  5262. var req data_manage.BatchAddEdbInfoReq
  5263. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5264. if err != nil {
  5265. br.Msg = "参数解析异常!"
  5266. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5267. return
  5268. }
  5269. resp := new(data_manage.AddEdbInfoResp)
  5270. var edbNames string
  5271. for _, v := range req.BatchList {
  5272. edbNames += "'" + v.EdbName + "',"
  5273. }
  5274. edbNames = strings.Trim(edbNames, ",")
  5275. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  5276. if err != nil {
  5277. br.Msg = "查询指标名称重复错误!"
  5278. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  5279. return
  5280. }
  5281. if len(infoList) > 0 {
  5282. for _, v := range infoList {
  5283. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  5284. }
  5285. br.Data = resp
  5286. br.Msg = "指标名称重复!"
  5287. br.ErrMsg = "指标名称重复"
  5288. return
  5289. }
  5290. for k, v := range req.BatchList {
  5291. v.EdbName = strings.Trim(v.EdbName, " ")
  5292. v.EdbCode = strings.Trim(v.EdbCode, " ")
  5293. v.StockCode = strings.Trim(v.StockCode, " ")
  5294. if v.Source <= 0 {
  5295. br.Msg = "无效的数据来源"
  5296. return
  5297. }
  5298. if v.EdbCode == "" {
  5299. br.Msg = "指标ID不能为空"
  5300. return
  5301. }
  5302. if v.StockCode == "" {
  5303. br.Msg = "证券代码不能为空"
  5304. return
  5305. }
  5306. if v.EdbName == "" {
  5307. br.Msg = "指标名称不能为空"
  5308. return
  5309. }
  5310. if v.Frequency == "" {
  5311. br.Msg = "频率不能为空"
  5312. return
  5313. }
  5314. if v.ClassifyId <= 0 {
  5315. br.Msg = "请选择分类"
  5316. return
  5317. }
  5318. terminalCode, serverUrl, _, e := data.GetEdbTerminalCodeBySource(v.Source, v.EdbCode, v.StockCode)
  5319. if e != nil {
  5320. br.Msg = "获取可以使用的终端地址失败"
  5321. br.ErrMsg = "获取可以使用的终端地址失败,Err:" + e.Error()
  5322. return
  5323. }
  5324. edbInfoItem := new(data_manage.EdbInfo)
  5325. edbInfoItem.Source = v.Source
  5326. switch v.Source {
  5327. case utils.DATA_SOURCE_WIND:
  5328. edbInfoItem.SourceName = "wind"
  5329. edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
  5330. case utils.DATA_SOURCE_THS:
  5331. edbInfoItem.SourceName = "ths"
  5332. edbInfoItem.EdbCode = utils.ThsDs + v.StockCode + v.EdbCode
  5333. }
  5334. edbInfoItem.SubSource = 1
  5335. edbInfoItem.SubSourceName = "日期序列"
  5336. edbInfoItem.EdbName = v.EdbName
  5337. edbInfoItem.Frequency = v.Frequency
  5338. edbInfoItem.Unit = v.Unit
  5339. edbInfoItem.ClassifyId = v.ClassifyId
  5340. edbInfoItem.SysUserId = sysUser.AdminId
  5341. edbInfoItem.SysUserRealName = sysUser.RealName
  5342. edbInfoItem.IndicatorCode = v.EdbCode
  5343. edbInfoItem.StockCode = v.StockCode
  5344. edbInfoItem.TerminalCode = terminalCode
  5345. edbInfoItem.ServerUrl = serverUrl
  5346. // 指标入库
  5347. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  5348. if err != nil {
  5349. br.Msg = "保存失败"
  5350. if errMsg != `` {
  5351. br.Msg = errMsg
  5352. }
  5353. br.ErrMsg = err.Error()
  5354. br.IsSendEmail = isSendEmail
  5355. return
  5356. }
  5357. //新增操作日志
  5358. {
  5359. edbLog := new(data_manage.EdbInfoLog)
  5360. edbLog.EdbInfoId = edbInfo.EdbInfoId
  5361. edbLog.SourceName = edbInfo.SourceName
  5362. edbLog.Source = edbInfo.Source
  5363. edbLog.EdbCode = edbInfo.EdbCode
  5364. edbLog.EdbName = edbInfo.EdbName
  5365. edbLog.ClassifyId = edbInfo.ClassifyId
  5366. edbLog.SysUserId = sysUser.AdminId
  5367. edbLog.SysUserRealName = sysUser.RealName
  5368. edbLog.CreateTime = time.Now()
  5369. edbLog.Content = string(this.Ctx.Input.RequestBody)
  5370. edbLog.Status = "新增指标"
  5371. edbLog.Method = this.Ctx.Input.URI()
  5372. go data_manage.AddEdbInfoLog(edbLog)
  5373. }
  5374. if k <= 0 {
  5375. resp.EdbInfoId = edbInfo.EdbInfoId
  5376. resp.UniqueCode = edbInfo.UniqueCode
  5377. }
  5378. }
  5379. // 试用平台更新用户累计新增指标数
  5380. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  5381. if e != nil {
  5382. br.Msg = "操作失败"
  5383. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  5384. return
  5385. }
  5386. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  5387. go func() {
  5388. var r etaTrialService.EtaTrialUserReq
  5389. r.Mobile = adminItem.Mobile
  5390. _, _ = etaTrialService.UpdateUserIndexNum(r)
  5391. }()
  5392. }
  5393. br.Ret = 200
  5394. br.Success = true
  5395. br.Msg = "保存成功"
  5396. br.Data = resp
  5397. br.IsAddLog = true
  5398. }
  5399. // SmmExistCheck
  5400. // @Title 新增指标-检验指标是否存在接口-smm
  5401. // @Description 新增指标-检验指标是否存在接口-smm
  5402. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5403. // @Param EdbCode query string false "指标编码/指标代码"
  5404. // @Param StockCode query string false "证券代码"
  5405. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5406. // @router /edb_info/smm/exist/check [post]
  5407. func (this *EdbInfoController) SmmExistCheck() {
  5408. br := new(models.BaseResponse).Init()
  5409. defer func() {
  5410. this.Data["json"] = br
  5411. this.ServeJSON()
  5412. }()
  5413. var req data_manage.SmmIndexExistCheckReq
  5414. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5415. if err != nil {
  5416. br.Msg = "参数解析异常!"
  5417. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5418. return
  5419. }
  5420. types := req.Types
  5421. frequency := req.Frequency
  5422. dataState := req.DataState
  5423. selectAll := req.SelectAll
  5424. keyword := req.Keyword
  5425. edbCode := req.EdbCode
  5426. edbCode = strings.Trim(edbCode, "\t")
  5427. edbCode = strings.Trim(edbCode, " ")
  5428. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5429. var edbCodeArr []string
  5430. var codeArr []string
  5431. if selectAll {
  5432. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5433. var condition string
  5434. var pars []interface{}
  5435. if len(types) > 0 {
  5436. condition += " AND ( "
  5437. for _, v := range types {
  5438. typeArr := strings.Split(v, ",")
  5439. for i, v := range typeArr {
  5440. if i == 0 {
  5441. condition += " ( "
  5442. }
  5443. typeStr := "type_"
  5444. typeStr += fmt.Sprintf("%d", i+1)
  5445. condition += typeStr + " =? "
  5446. pars = append(pars, v)
  5447. if i == len(typeArr)-1 {
  5448. condition += " ) "
  5449. } else {
  5450. condition += " AND "
  5451. }
  5452. }
  5453. condition += " OR "
  5454. }
  5455. condition = strings.Trim(condition, "OR ")
  5456. condition += " ) "
  5457. }
  5458. if frequency != "" {
  5459. frequencyArr := strings.Split(frequency, ",")
  5460. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5461. pars = append(pars, frequencyArr)
  5462. }
  5463. if dataState != "" {
  5464. stateArr := strings.Split(dataState, ",")
  5465. if strings.Contains(dataState, "normal") {
  5466. stateArr = append(stateArr, "")
  5467. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5468. pars = append(pars, stateArr)
  5469. } else {
  5470. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5471. pars = append(pars, stateArr)
  5472. }
  5473. }
  5474. if keyword != "" {
  5475. keyWordArr := strings.Split(keyword, " ")
  5476. if len(keyWordArr) > 0 {
  5477. condition += " AND ( "
  5478. for _, v := range keyWordArr {
  5479. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5480. }
  5481. condition = strings.TrimRight(condition, "OR")
  5482. condition += " ) "
  5483. }
  5484. }
  5485. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5486. if err != nil {
  5487. br.Msg = "获取指标列表失败"
  5488. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5489. return
  5490. }
  5491. for _, v := range indexList {
  5492. codeArr = append(codeArr, v.IndexCode)
  5493. }
  5494. noUseCodeArr := strings.Split(edbCode, ",")
  5495. for _, code := range codeArr {
  5496. // 检查code是否在noUseCodeArr数组中
  5497. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5498. // 如果不在,将其添加到结果数组中
  5499. edbCodeArr = append(edbCodeArr, code)
  5500. }
  5501. }
  5502. } else {
  5503. //未勾选全选EdbCode就是需要的code
  5504. edbCodeArr = strings.Split(edbCode, ",")
  5505. }
  5506. if len(edbCodeArr) > 30 {
  5507. br.Msg = "最多只能选择30个指标"
  5508. return
  5509. }
  5510. if len(edbCodeArr) <= 0 {
  5511. br.Msg = "无符合指标或指标代码错误"
  5512. return
  5513. }
  5514. indexList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_YS, edbCodeArr)
  5515. if err != nil && err.Error() != utils.ErrNoRow() {
  5516. br.Msg = "校验指标是否存在失败"
  5517. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5518. return
  5519. }
  5520. var existEdbCodeArr []string
  5521. var existClassifyId []int
  5522. var existIndexId []int
  5523. for _, indexItem := range indexList {
  5524. for _, ev := range edbCodeArr {
  5525. if strings.Contains(indexItem.EdbCode, ev) {
  5526. existEdbCodeArr = append(existEdbCodeArr, ev)
  5527. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5528. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5529. }
  5530. }
  5531. }
  5532. resp := new(data_manage.EdbInfoSmmExistCheckResp)
  5533. if len(indexList) > 0 {
  5534. resp.IndexExist = true
  5535. }
  5536. if len(existEdbCodeArr) == len(edbCodeArr) {
  5537. resp.ExistAll = true
  5538. }
  5539. resp.ExistEdbCodeArr = existEdbCodeArr
  5540. resp.ExistClassifyId = existClassifyId
  5541. resp.ExistIndexId = existIndexId
  5542. resp.ExistEdbInfo = indexList
  5543. br.Ret = 200
  5544. br.Success = true
  5545. br.Msg = "获取成功"
  5546. br.Data = resp
  5547. }
  5548. // EdbInfoSearch
  5549. // @Title 新增指标-查询指标信息接口-smm
  5550. // @Description 新增指标-查询指标信息接口-smm
  5551. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  5552. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5553. // @Param EdbCode query string false "指标编码/指标代码"
  5554. // @Param StockCode query string false "证券代码"
  5555. // @Success 200 {object} data_manage.EdbInfoSearchResp
  5556. // @router /edb_info/smm/search [post]
  5557. func (this *EdbInfoController) EdbInfoSmmSearch() {
  5558. br := new(models.BaseResponse).Init()
  5559. defer func() {
  5560. this.Data["json"] = br
  5561. this.ServeJSON()
  5562. }()
  5563. var req data_manage.SmmIndexExistCheckReq
  5564. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5565. if err != nil {
  5566. br.Msg = "参数解析异常!"
  5567. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5568. return
  5569. }
  5570. types := req.Types
  5571. frequency := req.Frequency
  5572. dataState := req.DataState
  5573. selectAll := req.SelectAll
  5574. keyword := req.Keyword
  5575. edbCode := req.EdbCode
  5576. edbCode = strings.Trim(edbCode, "\t")
  5577. edbCode = strings.Trim(edbCode, " ")
  5578. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5579. var edbCodeArr []string
  5580. var codeArr []string
  5581. if selectAll {
  5582. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5583. var condition string
  5584. var pars []interface{}
  5585. if len(types) > 0 {
  5586. condition += " AND ( "
  5587. for _, v := range types {
  5588. typeArr := strings.Split(v, ",")
  5589. for i, v := range typeArr {
  5590. if i == 0 {
  5591. condition += " ( "
  5592. }
  5593. typeStr := "type_"
  5594. typeStr += fmt.Sprintf("%d", i+1)
  5595. condition += typeStr + " =? "
  5596. pars = append(pars, v)
  5597. if i == len(typeArr)-1 {
  5598. condition += " ) "
  5599. } else {
  5600. condition += " AND "
  5601. }
  5602. }
  5603. condition += " OR "
  5604. }
  5605. condition = strings.Trim(condition, "OR ")
  5606. condition += " ) "
  5607. }
  5608. if frequency != "" {
  5609. frequencyArr := strings.Split(frequency, ",")
  5610. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5611. pars = append(pars, frequencyArr)
  5612. }
  5613. if dataState != "" {
  5614. stateArr := strings.Split(dataState, ",")
  5615. if strings.Contains(dataState, "normal") {
  5616. stateArr = append(stateArr, "")
  5617. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5618. pars = append(pars, stateArr)
  5619. } else {
  5620. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5621. pars = append(pars, stateArr)
  5622. }
  5623. }
  5624. if keyword != "" {
  5625. keyWordArr := strings.Split(keyword, " ")
  5626. if len(keyWordArr) > 0 {
  5627. condition += " AND ( "
  5628. for _, v := range keyWordArr {
  5629. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5630. }
  5631. condition = strings.TrimRight(condition, "OR")
  5632. condition += " ) "
  5633. }
  5634. }
  5635. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5636. if err != nil {
  5637. br.Msg = "获取指标列表失败"
  5638. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5639. return
  5640. }
  5641. for _, v := range indexList {
  5642. codeArr = append(codeArr, v.IndexCode)
  5643. }
  5644. noUseCodeArr := strings.Split(edbCode, ",")
  5645. for _, code := range codeArr {
  5646. // 检查code是否在noUseCodeArr数组中
  5647. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5648. // 如果不在,将其添加到结果数组中
  5649. edbCodeArr = append(edbCodeArr, code)
  5650. }
  5651. }
  5652. } else {
  5653. //未勾选全选EdbCode就是需要的code
  5654. edbCodeArr = strings.Split(edbCode, ",")
  5655. }
  5656. if len(edbCodeArr) > 30 {
  5657. br.Msg = "最多只能选择30个指标"
  5658. return
  5659. }
  5660. if len(edbCodeArr) <= 0 {
  5661. br.Msg = "无符合指标或指标代码错误"
  5662. return
  5663. }
  5664. edbCodeStr := ""
  5665. for i, _ := range edbCodeArr {
  5666. edbCodeStr += "'" + edbCodeArr[i] + "'" + ","
  5667. }
  5668. edbCodeStr = strings.Trim(edbCodeStr, ",")
  5669. smmInfoList, err := data_manage.GetBaseFromSmmIndexByIndexCodes(edbCodeStr)
  5670. if err != nil && err.Error() != utils.ErrNoRow() {
  5671. br.Msg = "获取失败"
  5672. br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
  5673. return
  5674. }
  5675. smmInfoMap := make(map[string]*data_manage.BaseFromSmmIndex)
  5676. for _, v := range smmInfoList {
  5677. smmInfoMap[v.IndexCode] = v
  5678. }
  5679. searchItemList := make([]*data_manage.EdbInfoSearch, 0)
  5680. resp := new(data_manage.EdbInfoSearchResp)
  5681. needAddCodeArr := make([]string, 0)
  5682. noNeedAddCodeMap := make(map[string]string, 0)
  5683. for _, edbCode := range edbCodeArr {
  5684. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  5685. if err != nil && err.Error() != utils.ErrNoRow() {
  5686. br.Msg = "获取失败"
  5687. br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
  5688. return
  5689. }
  5690. fmt.Println("dataItems:", len(dataItems))
  5691. if len(dataItems) > 0 {
  5692. searchItem := new(data_manage.EdbInfoSearch)
  5693. searchItem.EdbCode = edbCode
  5694. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  5695. if err != nil {
  5696. br.Msg = "获取失败"
  5697. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  5698. return
  5699. }
  5700. searchItem.DataList = dataItems
  5701. searchItem.StartDate = minDate
  5702. searchItem.EndDate = maxDate
  5703. searchItem.Frequency = smmInfoMap[edbCode].Frequency
  5704. searchItem.Unit = smmInfoMap[edbCode].Unit
  5705. searchItem.EdbName = smmInfoMap[edbCode].IndexName
  5706. searchItem.EdbCode = smmInfoMap[edbCode].IndexCode
  5707. searchItemList = append(searchItemList, searchItem)
  5708. noNeedAddCodeMap[edbCode] = edbCode
  5709. } else {
  5710. // 把需要新加的code添加到needAddCodeArr数组中,一起批量请求
  5711. needAddCodeArr = append(needAddCodeArr, edbCode)
  5712. }
  5713. }
  5714. if len(needAddCodeArr) > 0 {
  5715. edbCode = strings.Join(needAddCodeArr, ",")
  5716. respItem, err := data.AddEdbData(utils.DATA_SOURCE_YS, edbCode, "")
  5717. if err != nil {
  5718. br.Msg = "获取失败"
  5719. br.ErrMsg = "获取失败,Err:" + err.Error()
  5720. return
  5721. }
  5722. if respItem.Ret != 200 {
  5723. if respItem.Ret == 421 {
  5724. br.Msg = "该渠道已超过添加上限"
  5725. } else if respItem.Ret == 4052 {
  5726. br.Msg = "该指标已下架"
  5727. } else {
  5728. br.Msg = "未搜索到该指标"
  5729. }
  5730. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  5731. return
  5732. }
  5733. }
  5734. for _, smmInfo := range smmInfoList {
  5735. if smmInfo != nil {
  5736. if _, ok := noNeedAddCodeMap[smmInfo.IndexCode]; !ok {
  5737. searchItem := new(data_manage.EdbInfoSearch)
  5738. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(smmInfo.IndexCode)
  5739. if err != nil {
  5740. br.Msg = "获取失败"
  5741. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  5742. return
  5743. }
  5744. searchItem.StartDate = minDate
  5745. searchItem.EndDate = maxDate
  5746. searchItem.Frequency = smmInfo.Frequency
  5747. searchItem.Unit = smmInfo.Unit
  5748. searchItem.EdbName = smmInfo.IndexName
  5749. searchItem.EdbCode = smmInfo.IndexCode
  5750. dataList, err := data_manage.GetEdbDataAllByEdbCode(smmInfo.IndexCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  5751. if err != nil && err.Error() != utils.ErrNoRow() {
  5752. br.Msg = "获取失败"
  5753. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  5754. return
  5755. }
  5756. searchItem.DataList = dataList
  5757. searchItemList = append(searchItemList, searchItem)
  5758. }
  5759. }
  5760. }
  5761. resp.Status = 2
  5762. resp.StockSearchList = searchItemList
  5763. br.Ret = 200
  5764. br.Success = true
  5765. br.Msg = "获取成功"
  5766. br.Data = resp
  5767. }
  5768. // SmmEdbInfoBatchAdd
  5769. // @Title 指标批量保存接口-smm
  5770. // @Description 指标批量保存接口-smm
  5771. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  5772. // @Success Ret=200 保存成功
  5773. // @router /edb_info/smm/batch/add [post]
  5774. func (this *EdbInfoController) SmmEdbInfoBatchAdd() {
  5775. br := new(models.BaseResponse).Init()
  5776. defer func() {
  5777. this.Data["json"] = br
  5778. this.ServeJSON()
  5779. }()
  5780. sysUser := this.SysUser
  5781. if sysUser == nil {
  5782. br.Msg = "请登录"
  5783. br.ErrMsg = "请登录,SysUser Is Empty"
  5784. br.Ret = 408
  5785. return
  5786. }
  5787. deleteCache := true
  5788. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  5789. defer func() {
  5790. if deleteCache {
  5791. utils.Rc.Delete(cacheKey)
  5792. }
  5793. }()
  5794. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  5795. deleteCache = false
  5796. br.Msg = "系统处理中,请稍后重试!"
  5797. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  5798. return
  5799. }
  5800. var req data_manage.BatchAddEdbInfoReq
  5801. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5802. if err != nil {
  5803. br.Msg = "参数解析异常!"
  5804. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5805. return
  5806. }
  5807. resp := new(data_manage.AddEdbInfoResp)
  5808. var edbNames string
  5809. for _, v := range req.BatchList {
  5810. edbNames += "'" + v.EdbName + "',"
  5811. }
  5812. edbNames = strings.Trim(edbNames, ",")
  5813. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  5814. if err != nil {
  5815. br.Msg = "查询指标名称重复错误!"
  5816. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  5817. return
  5818. }
  5819. if len(infoList) > 0 {
  5820. for _, v := range infoList {
  5821. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  5822. }
  5823. br.Data = resp
  5824. br.Msg = "指标名称重复!"
  5825. br.ErrMsg = "指标名称重复"
  5826. return
  5827. }
  5828. for k, v := range req.BatchList {
  5829. v.EdbName = strings.Trim(v.EdbName, " ")
  5830. v.EdbCode = strings.Trim(v.EdbCode, " ")
  5831. if v.Source <= 0 {
  5832. br.Msg = "无效的数据来源"
  5833. return
  5834. }
  5835. if v.EdbCode == "" {
  5836. br.Msg = "指标ID不能为空"
  5837. return
  5838. }
  5839. if v.EdbName == "" {
  5840. br.Msg = "指标名称不能为空"
  5841. return
  5842. }
  5843. if v.Frequency == "" {
  5844. br.Msg = "频率不能为空"
  5845. return
  5846. }
  5847. if v.ClassifyId <= 0 {
  5848. br.Msg = "请选择分类"
  5849. return
  5850. }
  5851. edbInfoItem := new(data_manage.EdbInfo)
  5852. edbInfoItem.Source = v.Source
  5853. edbInfoItem.SourceName = "SMM"
  5854. edbInfoItem.EdbCode = v.EdbCode
  5855. edbInfoItem.SubSource = 0
  5856. edbInfoItem.SubSourceName = ""
  5857. edbInfoItem.EdbName = v.EdbName
  5858. edbInfoItem.Frequency = v.Frequency
  5859. edbInfoItem.Unit = v.Unit
  5860. edbInfoItem.ClassifyId = v.ClassifyId
  5861. edbInfoItem.SysUserId = sysUser.AdminId
  5862. edbInfoItem.SysUserRealName = sysUser.RealName
  5863. edbInfoItem.IndicatorCode = ""
  5864. edbInfoItem.StockCode = ""
  5865. // 指标入库
  5866. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  5867. if err != nil {
  5868. br.Msg = "保存失败"
  5869. if errMsg != `` {
  5870. br.Msg = errMsg
  5871. }
  5872. br.ErrMsg = err.Error()
  5873. br.IsSendEmail = isSendEmail
  5874. return
  5875. }
  5876. //新增操作日志
  5877. {
  5878. edbLog := new(data_manage.EdbInfoLog)
  5879. edbLog.EdbInfoId = edbInfo.EdbInfoId
  5880. edbLog.SourceName = edbInfo.SourceName
  5881. edbLog.Source = edbInfo.Source
  5882. edbLog.EdbCode = edbInfo.EdbCode
  5883. edbLog.EdbName = edbInfo.EdbName
  5884. edbLog.ClassifyId = edbInfo.ClassifyId
  5885. edbLog.SysUserId = sysUser.AdminId
  5886. edbLog.SysUserRealName = sysUser.RealName
  5887. edbLog.CreateTime = time.Now()
  5888. edbLog.Content = string(this.Ctx.Input.RequestBody)
  5889. edbLog.Status = "新增指标"
  5890. edbLog.Method = this.Ctx.Input.URI()
  5891. go data_manage.AddEdbInfoLog(edbLog)
  5892. }
  5893. if k <= 0 {
  5894. resp.EdbInfoId = edbInfo.EdbInfoId
  5895. resp.UniqueCode = edbInfo.UniqueCode
  5896. }
  5897. }
  5898. br.Ret = 200
  5899. br.Success = true
  5900. br.Msg = "保存成功"
  5901. br.Data = resp
  5902. br.IsAddLog = true
  5903. }