edb_info.go 189 KB

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