edb_info.go 203 KB

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