edb_info.go 197 KB

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