edb_info.go 192 KB

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