edb_info.go 204 KB

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