edb_info.go 189 KB

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