edb_info.go 204 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973
  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 !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  118. br.Msg = "获取失败"
  119. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  120. return
  121. }
  122. if conf != nil && conf.EdbInfoId > 0 {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  610. br.Msg = "获取失败"
  611. br.ErrMsg = "获取郑商所指标详情失败,Err:" + err.Error()
  612. return
  613. }
  614. var zzInfo *data_manage.BaseInfoFromZz
  615. if allInfo != nil && len(allInfo) > 0 {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  687. br.Msg = "获取失败"
  688. br.ErrMsg = "获取大商所指标详情失败,Err:" + err.Error()
  689. return
  690. }
  691. var dlInfo *data_manage.BaseInfoFromDl
  692. if allInfo != nil && len(allInfo) > 0 {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  764. br.Msg = "获取失败"
  765. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  766. return
  767. }
  768. var shInfo *data_manage.BaseInfoFromSh
  769. if allInfo != nil && len(allInfo) > 0 {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  841. br.Msg = "获取失败"
  842. br.ErrMsg = "获取中金所指标详情失败,Err:" + err.Error()
  843. return
  844. }
  845. var cffexInfo *data_manage.BaseInfoFromCffex
  846. if allInfo != nil && len(allInfo) > 0 {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  918. br.Msg = "获取失败"
  919. br.ErrMsg = "获取上期能源指标详情失败,Err:" + err.Error()
  920. return
  921. }
  922. var shfeInfo *data_manage.BaseInfoFromShfe
  923. if allInfo != nil && len(allInfo) > 0 {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  1010. br.Msg = "获取失败"
  1011. br.ErrMsg = "获取欧洲天然气指标详情失败,Err:" + err.Error()
  1012. return
  1013. }
  1014. var eicInfo *data_manage.BaseFromTradeEicIndexV2
  1015. if allInfo != nil && len(allInfo) > 0 {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  1171. br.Msg = "获取失败"
  1172. br.ErrMsg = "获取煤炭网指标详情失败,Err:" + err.Error()
  1173. return
  1174. }
  1175. var coalInfo *data_manage.BaseInfoFromCoal
  1176. if allInfo != nil && len(allInfo) > 0 {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(e) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  2120. br.Msg = "获取失败"
  2121. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  2122. return
  2123. }
  2124. if conf != nil && conf.Id > 0 {
  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 && !utils.IsErrNoRow(err) {
  2148. br.Success = true
  2149. br.Msg = "获取指标信息失败"
  2150. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2151. return
  2152. }
  2153. if edbInfoItem == nil || (err != nil && utils.IsErrNoRow(err)) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  2211. br.Msg = "获取指标信息失败"
  2212. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  2213. return
  2214. }
  2215. if edbDataInsertConfig != nil && edbDataInsertConfig.EdbInfoId > 0 {
  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 !utils.IsErrNoRow(err) {
  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 !utils.IsErrNoRow(err) {
  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 !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 && !utils.IsErrNoRow(err) {
  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 utils.IsErrNoRow(err) {
  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 utils.IsErrNoRow(err) {
  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. //是否被引用
  3650. relation, err := data.GetEdbRelationListById(edbInfo.EdbInfoId, edbInfo.Source)
  3651. if err != nil {
  3652. br.Msg = err.Error()
  3653. br.ErrMsg = "获取指标关联关系失败,err:" + err.Error()
  3654. return
  3655. }
  3656. if relation.RelationNum > 0 {
  3657. fullEdb.IsRelation = true
  3658. }
  3659. fullEdb.ClassifyList = classifyList
  3660. var currClassifyItem *data_manage.EdbClassifyIdItems
  3661. for _, v := range classifyList {
  3662. if v.ClassifyId == edbInfo.ClassifyId {
  3663. currClassifyItem = v
  3664. }
  3665. }
  3666. if currClassifyItem != nil {
  3667. haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassifyItem.IsJoinPermission, sysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId)
  3668. if err != nil {
  3669. br.Msg = err.Error()
  3670. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  3671. return
  3672. }
  3673. fullEdb.HaveOperaAuth = haveOperaAuth
  3674. }
  3675. resp.EdbInfo = fullEdb
  3676. resp.DataList = make([]*data_manage.EdbDataList, 0)
  3677. // 数据获取
  3678. if fullEdb.HaveOperaAuth { // 有权限才获取数据
  3679. var latestDateT time.Time
  3680. if edbInfo.LatestDate != "" {
  3681. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3682. }
  3683. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  3684. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  3685. if err != nil {
  3686. br.Msg = "获取失败"
  3687. br.ErrMsg = "获取失败,Err:" + err.Error()
  3688. return
  3689. }
  3690. resp.DataList = dataList
  3691. }
  3692. br.Ret = 200
  3693. br.Success = true
  3694. br.Msg = "获取成功"
  3695. br.Data = resp
  3696. }
  3697. // EdbInfoReplaceCheck
  3698. // @Title 指标一键刷新接口
  3699. // @Description 指标一键刷新接口
  3700. // @Success Ret=200 更新成功
  3701. // @router /edb_info/replace/check [post]
  3702. func (this *EdbInfoController) EdbInfoReplaceCheck() {
  3703. br := new(models.BaseResponse).Init()
  3704. setNxKey := "EDB_INFO_REPLACE"
  3705. defer func() {
  3706. this.Data["json"] = br
  3707. this.ServeJSON()
  3708. }()
  3709. status := 0
  3710. if utils.Rc.IsExist(setNxKey) {
  3711. status = 1
  3712. } else {
  3713. status = 2
  3714. }
  3715. br.Ret = 200
  3716. br.Success = true
  3717. br.Msg = "检测成功"
  3718. br.Data = status
  3719. }
  3720. // EdbInfoReplace
  3721. // @Title 替换指标
  3722. // @Description 替换指标
  3723. // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
  3724. // @Success 200 {object} data_manage.EdbInfoDataResp
  3725. // @router /edb_info/replace [post]
  3726. func (this *ChartInfoController) EdbInfoReplace() {
  3727. br := new(models.BaseResponse).Init()
  3728. setNxKey := "EDB_INFO_REPLACE"
  3729. deleteCache := true
  3730. defer func() {
  3731. if deleteCache {
  3732. utils.Rc.Delete(setNxKey)
  3733. }
  3734. this.Data["json"] = br
  3735. this.ServeJSON()
  3736. }()
  3737. sysUser := this.SysUser
  3738. if sysUser == nil {
  3739. br.Msg = "请登录"
  3740. br.ErrMsg = "请登录,SysUser Is Empty"
  3741. br.Ret = 408
  3742. return
  3743. }
  3744. if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
  3745. deleteCache = false
  3746. br.Msg = "当前正在替换中,请耐心等待!"
  3747. br.IsSendEmail = false
  3748. return
  3749. }
  3750. var req data_manage.EdbInfoReplaceReq
  3751. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3752. if err != nil {
  3753. br.Msg = "参数解析异常!"
  3754. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3755. return
  3756. }
  3757. if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
  3758. br.Msg = "参数错误!"
  3759. br.ErrMsg = "参数错误,指标id为0"
  3760. return
  3761. }
  3762. oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
  3763. if err != nil {
  3764. br.Msg = "替换失败!"
  3765. br.ErrMsg = "获取原指标失败,Err:" + err.Error()
  3766. return
  3767. }
  3768. newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
  3769. if err != nil {
  3770. br.Msg = "替换失败!"
  3771. br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
  3772. return
  3773. }
  3774. //if oldEdbInfo.EdbType != 1 {
  3775. // br.Msg = "原指标为计算指标,不可替换!"
  3776. // br.ErrMsg = "原指标为计算指标,不可替换!"
  3777. // return
  3778. //}
  3779. //
  3780. //if newEdbInfo.EdbType != 1 {
  3781. // br.Msg = "替换指标为计算指标,不可替换!"
  3782. // br.ErrMsg = "替换指标为计算指标,不可替换!"
  3783. // return
  3784. //}
  3785. if oldEdbInfo.Frequency != newEdbInfo.Frequency {
  3786. br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3787. br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3788. return
  3789. }
  3790. if oldEdbInfo.EdbInfoType == 1 || newEdbInfo.EdbInfoType == 1 {
  3791. br.Msg = "预测指标不允许替换"
  3792. br.ErrMsg = "预测指标不允许替换"
  3793. return
  3794. }
  3795. // 判断指标是否循环引用
  3796. if oldEdbInfo.EdbType == 2 {
  3797. // 查询该计算指标的所有相关指标,如果相关指标中包含新指标,则提示
  3798. hasRelation, e := data.CheckTwoEdbInfoRelation(oldEdbInfo, newEdbInfo)
  3799. if e != nil {
  3800. br.Msg = "替换失败!"
  3801. br.ErrMsg = "查询指标引用关系失败,Err:" + e.Error()
  3802. return
  3803. }
  3804. if hasRelation {
  3805. br.Msg = "原指标与替换指标存在引用关系,不允许替换"
  3806. br.ErrMsg = "原指标与替换指标存在引用关系,不允许替换"
  3807. return
  3808. }
  3809. }
  3810. if newEdbInfo.EdbType == 2 {
  3811. // 查询该计算指标的所有相关指标,如果相关指标中包含新指标,则提示
  3812. hasRelation, e := data.CheckTwoEdbInfoRelation(newEdbInfo, oldEdbInfo)
  3813. if e != nil {
  3814. br.Msg = "替换失败!"
  3815. br.ErrMsg = "查询指标引用关系失败,Err:" + e.Error()
  3816. return
  3817. }
  3818. if hasRelation {
  3819. br.Msg = "原指标与替换指标存在引用关系,不允许替换"
  3820. br.ErrMsg = "原指标与替换指标存在引用关系,不允许替换"
  3821. return
  3822. }
  3823. }
  3824. sysAdminId := sysUser.AdminId
  3825. //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3826. _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3827. //msgContent := ``
  3828. if err != nil {
  3829. br.Msg = "替换失败"
  3830. br.ErrMsg = "替换失败 replace err:" + err.Error()
  3831. return
  3832. }
  3833. br.Msg = "替换成功"
  3834. br.ErrMsg = "替换成功"
  3835. br.Ret = 200
  3836. br.IsAddLog = true
  3837. return
  3838. }
  3839. // RelationChartList
  3840. // @Title 获取ETA指标关联的图表列表接口
  3841. // @Description 获取ETA指标关联的图表列表接口
  3842. // @Param PageSize query int true "每页数据条数"
  3843. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3844. // @Param EdbInfoId query int true "指标id"
  3845. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3846. // @Success 200 {object} data_manage.ChartListResp
  3847. // @router /edb_info/relation/chart_list [get]
  3848. func (this *EdbInfoController) RelationChartList() {
  3849. br := new(models.BaseResponse).Init()
  3850. defer func() {
  3851. this.Data["json"] = br
  3852. this.ServeJSON()
  3853. }()
  3854. sysUser := this.SysUser
  3855. if sysUser == nil {
  3856. br.Msg = "请登录"
  3857. br.ErrMsg = "请登录,SysUser Is Empty"
  3858. br.Ret = 408
  3859. return
  3860. }
  3861. edbInfoId, _ := this.GetInt("EdbInfoId")
  3862. pageSize, _ := this.GetInt("PageSize")
  3863. currentIndex, _ := this.GetInt("CurrentIndex")
  3864. resp := data_manage.ChartListResp{}
  3865. var total int
  3866. page := paging.GetPaging(currentIndex, pageSize, total)
  3867. var startSize int
  3868. if pageSize <= 0 {
  3869. pageSize = utils.PageSize20
  3870. }
  3871. if currentIndex <= 0 {
  3872. currentIndex = 1
  3873. }
  3874. startSize = paging.StartIndex(currentIndex, pageSize)
  3875. var condition string
  3876. var pars []interface{}
  3877. if edbInfoId <= 0 {
  3878. br.Msg = "请选择指标"
  3879. br.ErrMsg = "请选择指标"
  3880. br.IsSendEmail = false
  3881. return
  3882. }
  3883. /*// 关联指标
  3884. condition += ` AND b.edb_info_id = ? `
  3885. pars = append(pars, edbInfoId)*/
  3886. //只看我的
  3887. isShowMe, _ := this.GetBool("IsShowMe")
  3888. if isShowMe {
  3889. condition += ` AND a.sys_user_id = ? `
  3890. pars = append(pars, sysUser.AdminId)
  3891. }
  3892. chartIds := make([]int, 0)
  3893. chartIdMap := make(map[int]bool)
  3894. // 查询指标绑定的图表
  3895. edbListTemp, err := data_manage.GetEdbMappingListByEdbInfoId(edbInfoId)
  3896. if err != nil && !utils.IsErrNoRow(err) {
  3897. br.Msg = "获取图表信息失败"
  3898. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3899. return
  3900. }
  3901. for _, v := range edbListTemp {
  3902. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  3903. chartIdMap[v.ChartInfoId] = true
  3904. }
  3905. }
  3906. // 查询相关性的图表
  3907. correlationChart := new(data_manage.ChartInfoCorrelation)
  3908. correlationChartId, err := correlationChart.GetChartInfoIdByEdb(edbInfoId)
  3909. if err != nil && !utils.IsErrNoRow(err) {
  3910. br.Msg = "获取图表信息失败"
  3911. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3912. return
  3913. }
  3914. if correlationChartId > 0 {
  3915. chartIdMap[correlationChartId] = true
  3916. }
  3917. // 查询跨品种的图表
  3918. tagXList, err := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
  3919. if err != nil && !utils.IsErrNoRow(err) {
  3920. br.Msg = "获取图表信息失败"
  3921. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3922. return
  3923. }
  3924. for _, v := range tagXList {
  3925. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  3926. chartIdMap[v.ChartInfoId] = true
  3927. }
  3928. }
  3929. tagYList, err := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
  3930. if err != nil && !utils.IsErrNoRow(err) {
  3931. br.Msg = "获取图表信息失败"
  3932. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3933. return
  3934. }
  3935. for _, v := range tagYList {
  3936. if _, ok := chartIdMap[v.ChartInfoId]; !ok {
  3937. chartIdMap[v.ChartInfoId] = true
  3938. }
  3939. }
  3940. // 获取当前账号的不可见图表
  3941. {
  3942. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3943. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  3944. if err != nil && !utils.IsErrNoRow(err) {
  3945. br.Msg = "获取失败"
  3946. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3947. return
  3948. }
  3949. for _, v := range confList {
  3950. if _, ok := chartIdMap[v.ChartInfoId]; ok {
  3951. delete(chartIdMap, v.ChartInfoId)
  3952. }
  3953. }
  3954. }
  3955. for k, _ := range chartIdMap {
  3956. chartIds = append(chartIds, k)
  3957. }
  3958. // 关联指标
  3959. if len(chartIds) > 0 {
  3960. condition += ` AND a.chart_info_id in (` + utils.GetOrmInReplace(len(chartIds)) + `)`
  3961. pars = append(pars, chartIds)
  3962. } else {
  3963. items := make([]*data_manage.ChartInfoView, 0)
  3964. resp.Paging = page
  3965. resp.List = items
  3966. br.Ret = 200
  3967. br.Success = true
  3968. br.Msg = "获取成功"
  3969. return
  3970. }
  3971. // 得到图表ID
  3972. //获取关联图表列表
  3973. list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
  3974. if err != nil && !utils.IsErrNoRow(err) {
  3975. br.Success = true
  3976. br.Msg = "获取图表信息失败"
  3977. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3978. return
  3979. }
  3980. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  3981. items := make([]*data_manage.ChartInfoView, 0)
  3982. resp.Paging = page
  3983. resp.List = items
  3984. br.Ret = 200
  3985. br.Success = true
  3986. br.Msg = "获取成功"
  3987. return
  3988. }
  3989. // 获取关联图表总数
  3990. dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
  3991. if err != nil && !utils.IsErrNoRow(err) {
  3992. br.Msg = "获取指标信息失败"
  3993. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3994. return
  3995. }
  3996. // 获取MY ETA 图表,用来判断是否加入我的图库
  3997. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  3998. if err != nil && !utils.IsErrNoRow(err) {
  3999. br.Msg = "获取图表信息失败"
  4000. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  4001. return
  4002. }
  4003. myChartMap := make(map[int]*data_manage.MyChartView)
  4004. for _, v := range myChartList {
  4005. myChartMap[v.ChartInfoId] = v
  4006. }
  4007. listLen := len(list)
  4008. if listLen > 0 {
  4009. // 分类id
  4010. classifyIdList := make([]int, 0)
  4011. // 当前列表中的分类map
  4012. classifyMap := make(map[int]*data_manage.ChartClassify)
  4013. for _, v := range list {
  4014. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  4015. }
  4016. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  4017. if err != nil {
  4018. br.Msg = "获取失败"
  4019. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4020. return
  4021. }
  4022. for _, v := range classifyList {
  4023. classifyMap[v.ChartClassifyId] = v
  4024. }
  4025. // 已授权分类id
  4026. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4027. if err != nil {
  4028. br.Msg = "获取失败"
  4029. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  4030. return
  4031. }
  4032. for _, v := range list {
  4033. if existItem, ok := myChartMap[v.ChartInfoId]; ok {
  4034. v.IsAdd = true
  4035. v.MyChartId = existItem.MyChartId
  4036. v.MyChartClassifyId = existItem.MyChartClassifyId
  4037. }
  4038. // 权限
  4039. if currClassify, ok := classifyMap[v.ChartClassifyId]; ok {
  4040. v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  4041. }
  4042. }
  4043. }
  4044. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  4045. resp.Paging = page
  4046. resp.List = list
  4047. br.Ret = 200
  4048. br.Success = true
  4049. br.Msg = "获取成功"
  4050. br.Data = resp
  4051. }
  4052. // RelationEdbList
  4053. // @Title 获取ETA指标关联的指标列表接口
  4054. // @Description 获取ETA指标关联的指标列表接口
  4055. // @Param PageSize query int true "每页数据条数"
  4056. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4057. // @Param EdbInfoId query int true "指标id"
  4058. // @Param IsShowMe query bool true "是否只看我的,true、false"
  4059. // @Success 200 {object} data_manage.ChartListResp
  4060. // @router /edb_info/relation/edbinfo_list [get]
  4061. func (this *EdbInfoController) RelationEdbList() {
  4062. br := new(models.BaseResponse).Init()
  4063. defer func() {
  4064. this.Data["json"] = br
  4065. this.ServeJSON()
  4066. }()
  4067. sysUser := this.SysUser
  4068. if sysUser == nil {
  4069. br.Msg = "请登录"
  4070. br.ErrMsg = "请登录,SysUser Is Empty"
  4071. br.Ret = 408
  4072. return
  4073. }
  4074. edbInfoId, _ := this.GetInt("EdbInfoId")
  4075. pageSize, _ := this.GetInt("PageSize")
  4076. currentIndex, _ := this.GetInt("CurrentIndex")
  4077. resp := data_manage.RelationEdbInfoListResp{}
  4078. var total int
  4079. page := paging.GetPaging(currentIndex, pageSize, total)
  4080. var startSize int
  4081. if pageSize <= 0 {
  4082. pageSize = utils.PageSize20
  4083. }
  4084. if currentIndex <= 0 {
  4085. currentIndex = 1
  4086. }
  4087. startSize = paging.StartIndex(currentIndex, pageSize)
  4088. var condition string
  4089. var pars []interface{}
  4090. if edbInfoId <= 0 {
  4091. br.Msg = "请选择指标"
  4092. br.ErrMsg = "请选择指标"
  4093. br.IsSendEmail = false
  4094. return
  4095. }
  4096. // 关联指标
  4097. condition += ` AND b.from_edb_info_id = ? `
  4098. pars = append(pars, edbInfoId)
  4099. //只看我的
  4100. isShowMe, _ := this.GetBool("IsShowMe")
  4101. if isShowMe {
  4102. condition += ` AND a.sys_user_id = ? `
  4103. pars = append(pars, sysUser.AdminId)
  4104. }
  4105. // 获取当前账号的不可见图表
  4106. noPermissionEdbIdList := make([]int, 0)
  4107. {
  4108. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4109. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4110. if err != nil && !utils.IsErrNoRow(err) {
  4111. br.Msg = "获取失败"
  4112. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  4113. return
  4114. }
  4115. for _, v := range confList {
  4116. noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
  4117. }
  4118. }
  4119. noPermissionEdbIdNum := len(noPermissionEdbIdList)
  4120. if noPermissionEdbIdNum > 0 {
  4121. condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
  4122. pars = append(pars, noPermissionEdbIdList)
  4123. }
  4124. //获取关联图表列表
  4125. list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
  4126. if err != nil && !utils.IsErrNoRow(err) {
  4127. br.Success = true
  4128. br.Msg = "获取指标信息失败"
  4129. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  4130. return
  4131. }
  4132. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  4133. items := make([]*data_manage.ChartEdbInfoMapping, 0)
  4134. resp.Paging = page
  4135. resp.List = items
  4136. br.Ret = 200
  4137. br.Success = true
  4138. br.Msg = "获取成功"
  4139. return
  4140. }
  4141. // 获取关联图表总数
  4142. dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
  4143. if err != nil && !utils.IsErrNoRow(err) {
  4144. br.Msg = "获取指标信息失败"
  4145. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  4146. return
  4147. }
  4148. if err != nil {
  4149. br.Msg = "获取失败"
  4150. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  4151. return
  4152. }
  4153. edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
  4154. if len(list) > 0 {
  4155. // 当前的分类
  4156. classifyMap := make(map[int]*data_manage.EdbClassify)
  4157. {
  4158. classifyIdList := make([]int, 0)
  4159. for _, v := range list {
  4160. classifyIdList = append(classifyIdList, v.ClassifyId)
  4161. }
  4162. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4163. if err != nil {
  4164. if err != nil {
  4165. br.Msg = "获取失败"
  4166. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4167. return
  4168. }
  4169. }
  4170. for _, v := range classifyList {
  4171. classifyMap[v.ClassifyId] = v
  4172. }
  4173. }
  4174. // 获取所有有权限的指标和分类
  4175. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4176. if err != nil {
  4177. br.Msg = "获取失败"
  4178. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4179. return
  4180. }
  4181. for _, v := range list {
  4182. item := new(data_manage.ChartEdbInfoMapping)
  4183. item.EdbInfoId = v.EdbInfoId
  4184. item.SourceName = v.SourceName
  4185. item.Source = v.Source
  4186. item.EdbCode = v.EdbCode
  4187. item.EdbName = v.EdbName
  4188. item.EdbNameEn = v.EdbNameEn
  4189. item.Frequency = v.Frequency
  4190. item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
  4191. if v.Unit != `无` {
  4192. item.Unit = v.Unit
  4193. }
  4194. item.UnitEn = v.UnitEn
  4195. item.StartDate = v.StartDate
  4196. item.EndDate = v.EndDate
  4197. item.ModifyTime = v.ModifyTime
  4198. item.IsAxis = 1
  4199. item.LeadValue = 0
  4200. item.LeadUnit = ""
  4201. item.ChartEdbMappingId = 0
  4202. item.ChartInfoId = 0
  4203. item.IsOrder = false
  4204. item.EdbInfoType = v.EdbInfoType
  4205. item.EdbInfoCategoryType = v.EdbInfoType
  4206. item.ChartStyle = ""
  4207. item.ChartColor = ""
  4208. item.ChartWidth = 0
  4209. item.MaxData = v.MaxValue
  4210. item.MinData = v.MinValue
  4211. item.LatestValue = v.LatestValue
  4212. item.LatestDate = v.LatestDate
  4213. item.UniqueCode = v.UniqueCode
  4214. item.ClassifyId = v.ClassifyId
  4215. dataList := make([]*data_manage.EdbDataList, 0)
  4216. // 指标权限
  4217. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  4218. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4219. }
  4220. // 有权限则获取数据
  4221. if item.HaveOperaAuth {
  4222. if v.EdbInfoType == 0 {
  4223. dataList, err = data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, "", "")
  4224. } else {
  4225. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
  4226. }
  4227. if err != nil {
  4228. br.Msg = "获取失败"
  4229. br.Msg = "获取失败,Err:" + err.Error()
  4230. return
  4231. }
  4232. }
  4233. item.DataList = dataList
  4234. edbList = append(edbList, item)
  4235. }
  4236. }
  4237. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  4238. resp.Paging = page
  4239. resp.List = edbList
  4240. br.Ret = 200
  4241. br.Success = true
  4242. br.Msg = "获取成功"
  4243. br.Data = resp
  4244. }
  4245. // EdbInfoDataTb
  4246. // @Title 获取指标数据同比值
  4247. // @Description 获取指标数据
  4248. // @Param EdbInfoId query int true "指标ID"
  4249. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4250. // @Param StartDate query string true "自定义开始日期"
  4251. // @Param EndDate query string true "自定义结束日期"
  4252. // @Success 200 {object} data_manage.EdbInfoDataResp
  4253. // @router /edb_info/data/tb [get]
  4254. func (this *ChartInfoController) EdbInfoDataTb() {
  4255. br := new(models.BaseResponse).Init()
  4256. defer func() {
  4257. this.Data["json"] = br
  4258. this.ServeJSON()
  4259. }()
  4260. sysUser := this.SysUser
  4261. if sysUser == nil {
  4262. br.Msg = "请登录"
  4263. br.ErrMsg = "请登录,SysUser Is Empty"
  4264. br.Ret = 408
  4265. return
  4266. }
  4267. edbInfoId, _ := this.GetInt("EdbInfoId")
  4268. if edbInfoId <= 0 {
  4269. br.Msg = "参数错误"
  4270. return
  4271. }
  4272. dateType, _ := this.GetInt("DateType")
  4273. if dateType <= 0 {
  4274. dateType = 3
  4275. }
  4276. edbInfoType, _ := this.GetInt("EdbInfoType")
  4277. if edbInfoType < 0 {
  4278. edbInfoType = 1
  4279. }
  4280. startDate := this.GetString("StartDate")
  4281. endDate := this.GetString("EndDate")
  4282. startYear, _ := this.GetInt("StartYear")
  4283. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4284. if err != nil {
  4285. br.Msg = "获取失败"
  4286. br.Msg = "获取失败,Err:" + err.Error()
  4287. return
  4288. }
  4289. var latestDateT time.Time
  4290. if edbInfo.LatestDate != "" {
  4291. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4292. }
  4293. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  4294. var startDateTime time.Time
  4295. if startDate != `` {
  4296. startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  4297. if err != nil {
  4298. br.Msg = "开始日期异常"
  4299. br.Msg = "开始日期异常,Err:" + err.Error()
  4300. return
  4301. }
  4302. //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
  4303. startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
  4304. }
  4305. tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate)
  4306. if err != nil {
  4307. br.Msg = "获取失败"
  4308. br.Msg = "获取失败,Err:" + err.Error()
  4309. return
  4310. }
  4311. // 计算同比值
  4312. dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
  4313. if err != nil {
  4314. br.Msg = "获取失败"
  4315. br.Msg = "计算同比值失败,Err:" + err.Error()
  4316. return
  4317. }
  4318. edbInfo.MaxValue = maxValue
  4319. edbInfo.MinValue = minValue
  4320. resp := new(data_manage.EdbInfoDataResp)
  4321. resp.EdbInfo = edbInfo
  4322. resp.DataList = dataList
  4323. br.Ret = 200
  4324. br.Success = true
  4325. br.Msg = "获取成功"
  4326. br.Data = resp
  4327. }
  4328. // EdbInfoDataSeasonal
  4329. // @Title 获取指标数据(季节性)
  4330. // @Description 获取指标数据
  4331. // @Param EdbInfoId query int true "指标ID"
  4332. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  4333. // @Param StartDate query string true "自定义开始日期"
  4334. // @Param EndDate query string true "自定义结束日期"
  4335. // @Param Calendar query string true "公历/农历"
  4336. // @Success 200 {object} data_manage.EdbInfoDataResp
  4337. // @router /edb_info/data/seasonal [get]
  4338. func (this *ChartInfoController) EdbInfoDataSeasonal() {
  4339. br := new(models.BaseResponse).Init()
  4340. defer func() {
  4341. this.Data["json"] = br
  4342. this.ServeJSON()
  4343. }()
  4344. sysUser := this.SysUser
  4345. if sysUser == nil {
  4346. br.Msg = "请登录"
  4347. br.ErrMsg = "请登录,SysUser Is Empty"
  4348. br.Ret = 408
  4349. return
  4350. }
  4351. dateType, _ := this.GetInt("DateType")
  4352. startDate := this.GetString("StartDate")
  4353. endDate := this.GetString("EndDate")
  4354. startYear, _ := this.GetInt("StartYear")
  4355. edbInfoIdStr := this.GetString("EdbInfoId")
  4356. edbInfoId, err := strconv.Atoi(edbInfoIdStr)
  4357. if err != nil {
  4358. br.Msg = "指标id异常"
  4359. br.Msg = "指标id转换异常,Err:" + err.Error()
  4360. return
  4361. }
  4362. fmt.Println("startDate:", startDate)
  4363. fmt.Println("endDate:", endDate)
  4364. calendar := this.GetString("Calendar")
  4365. if calendar == "" {
  4366. calendar = "公历"
  4367. }
  4368. if dateType == 0 {
  4369. if startDate == "" {
  4370. dateType = utils.DateTypeNYears
  4371. } else {
  4372. dateType = 5
  4373. }
  4374. }
  4375. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4376. if err != nil {
  4377. br.Msg = "获取失败"
  4378. br.Msg = "获取失败,Err:" + err.Error()
  4379. return
  4380. }
  4381. var latestDateT time.Time
  4382. if edbInfo.LatestDate != "" {
  4383. // 季节性图需要特殊处理最近N年数据
  4384. latestDateT, _ = time.Parse(utils.FormatDate, edbInfo.LatestDate)
  4385. latestDateT = time.Date(latestDateT.Year()+1, 1, 1, 0, 0, 0, 0, time.Local)
  4386. }
  4387. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, latestDateT)
  4388. dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
  4389. if err != nil {
  4390. br.Msg = "获取失败"
  4391. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  4392. return
  4393. }
  4394. resp := new(data_manage.EdbInfoDataSeasonalResp)
  4395. resp.EdbInfo = edbInfo
  4396. resp.DataList = dataList
  4397. br.Ret = 200
  4398. br.Success = true
  4399. br.Msg = "获取成功"
  4400. br.Data = resp
  4401. }
  4402. // SetEdbDataInsertConfig 设置插入值
  4403. // @Title 设置插入值接口
  4404. // @Description 设置插入值接口
  4405. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  4406. // @router /edb_info/insert_config/set [post]
  4407. func (this *EdbInfoController) SetEdbDataInsertConfig() {
  4408. br := new(models.BaseResponse).Init()
  4409. defer func() {
  4410. this.Data["json"] = br
  4411. this.ServeJSON()
  4412. }()
  4413. sysUser := this.SysUser
  4414. if sysUser == nil {
  4415. br.Msg = "请登录"
  4416. br.ErrMsg = "请登录,SysUser Is Empty"
  4417. br.Ret = 408
  4418. return
  4419. }
  4420. var req data_manage.SetEdbDataInsertConfigReq
  4421. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4422. if err != nil {
  4423. br.Msg = "参数解析异常!"
  4424. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4425. return
  4426. }
  4427. dateStr := req.Date
  4428. if dateStr == `` {
  4429. br.Msg = "请选择日期"
  4430. br.IsSendEmail = false
  4431. return
  4432. }
  4433. date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
  4434. if err != nil {
  4435. br.Msg = "日期异常"
  4436. br.ErrMsg = "日期异常,err:" + err.Error()
  4437. br.IsSendEmail = false
  4438. return
  4439. }
  4440. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  4441. if err != nil {
  4442. br.Msg = "获取指标信息失败"
  4443. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  4444. return
  4445. }
  4446. err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
  4447. if err != nil {
  4448. br.Msg = "设置失败"
  4449. if errMsg != `` {
  4450. br.Msg = errMsg
  4451. }
  4452. br.ErrMsg = "修改失败,Err:" + err.Error()
  4453. br.IsSendEmail = isSendEmail
  4454. return
  4455. }
  4456. //新增操作日志
  4457. {
  4458. edbLog := new(data_manage.EdbInfoLog)
  4459. edbLog.EdbInfoId = edbInfo.EdbInfoId
  4460. edbLog.SourceName = edbInfo.SourceName
  4461. edbLog.Source = edbInfo.Source
  4462. edbLog.EdbCode = edbInfo.EdbCode
  4463. edbLog.EdbName = edbInfo.EdbName
  4464. edbLog.ClassifyId = edbInfo.ClassifyId
  4465. edbLog.SysUserId = sysUser.AdminId
  4466. edbLog.SysUserRealName = sysUser.RealName
  4467. edbLog.CreateTime = time.Now()
  4468. edbLog.Content = string(this.Ctx.Input.RequestBody)
  4469. edbLog.Status = "设置插入值"
  4470. edbLog.Method = this.Ctx.Input.URI()
  4471. go data_manage.AddEdbInfoLog(edbLog)
  4472. }
  4473. br.Ret = 200
  4474. br.Success = true
  4475. br.Msg = "保存成功"
  4476. br.IsAddLog = true
  4477. }
  4478. // TraceEdbInfo
  4479. // @Title 指标溯源接口
  4480. // @Description 指标溯源接口
  4481. // @Param UniqueCode query int true "指标唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  4482. // @Success 200 {object} data_manage.ChartListResp
  4483. // @router /edb_info/trace [get]
  4484. func (this *EdbInfoController) TraceEdbInfo() {
  4485. br := new(models.BaseResponse).Init()
  4486. defer func() {
  4487. this.Data["json"] = br
  4488. this.ServeJSON()
  4489. }()
  4490. sysUser := this.SysUser
  4491. if sysUser == nil {
  4492. br.Msg = "请登录"
  4493. br.ErrMsg = "请登录,SysUser Is Empty"
  4494. br.Ret = 408
  4495. return
  4496. }
  4497. //edbInfoId, _ := this.GetInt("EdbInfoId")
  4498. //if edbInfoId <= 0 {
  4499. // br.Msg = "参数错误"
  4500. // br.ErrMsg = "参数错误"
  4501. // return
  4502. //}
  4503. uniqueCode := this.GetString("UniqueCode")
  4504. if uniqueCode == `` {
  4505. br.Msg = "参数错误"
  4506. br.ErrMsg = "参数错误"
  4507. return
  4508. }
  4509. // 根据UniqueCode获取指标信息
  4510. edbInfo, err := data_manage.GetEdbInfoByUniqueCode(uniqueCode)
  4511. if err != nil {
  4512. br.Msg = "获取失败"
  4513. br.Msg = "获取失败,Err:" + err.Error()
  4514. if utils.IsErrNoRow(err) {
  4515. br.Msg = "指标不存在"
  4516. }
  4517. return
  4518. }
  4519. resp, err := data.TraceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, this.SysUser.AdminId)
  4520. if err != nil {
  4521. br.Msg = "获取失败"
  4522. br.Msg = "获取失败,Err:" + err.Error()
  4523. return
  4524. }
  4525. br.Ret = 200
  4526. br.Data = resp
  4527. br.Success = true
  4528. br.Msg = "刷新成功"
  4529. }
  4530. // AllEdbInfoByEs
  4531. // @Title 所有指标筛选接口
  4532. // @Description 所有指标筛选接口
  4533. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  4534. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  4535. // @Param Frequency query string false "频度"
  4536. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  4537. // @Param PageSize query int true "每页数据条数"
  4538. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4539. // @Success 200 {object} data_manage.EdbInfoList
  4540. // @router /edb_info/filter_by_es/all [get]
  4541. func (this *EdbInfoController) AllEdbInfoByEs() {
  4542. br := new(models.BaseResponse).Init()
  4543. defer func() {
  4544. this.Data["json"] = br
  4545. this.ServeJSON()
  4546. }()
  4547. pageSize, _ := this.GetInt("PageSize")
  4548. currentIndex, _ := this.GetInt("CurrentIndex")
  4549. var total int64
  4550. var startSize int
  4551. if pageSize <= 0 {
  4552. pageSize = utils.PageSize20
  4553. }
  4554. if currentIndex <= 0 {
  4555. currentIndex = 1
  4556. }
  4557. startSize = paging.StartIndex(currentIndex, pageSize)
  4558. keyWord := this.GetString("KeyWord")
  4559. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  4560. filterSource, _ := this.GetInt("FilterSource")
  4561. if filterSource <= 0 {
  4562. filterSource = 1
  4563. }
  4564. //指标来源
  4565. source, _ := this.GetInt("Source")
  4566. frequency := this.GetString("Frequency") //频度
  4567. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  4568. var edbInfoList []*data_manage.EdbInfoList
  4569. var err error
  4570. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  4571. // 获取当前账号的不可见指标
  4572. {
  4573. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4574. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4575. if err != nil && !utils.IsErrNoRow(err) {
  4576. br.Msg = "获取失败"
  4577. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  4578. return
  4579. }
  4580. for _, v := range confList {
  4581. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  4582. }
  4583. }
  4584. // 只看我的
  4585. mine, _ := this.GetBool("IsShowMe")
  4586. // 是否走ES
  4587. isEs := false
  4588. if keyWord != "" {
  4589. var keyWordArr []string
  4590. keyWordArr = append(keyWordArr, keyWord)
  4591. newKeyWord := strings.Split(keyWord, " ")
  4592. keyWordArr = append(keyWordArr, newKeyWord...)
  4593. // 普通的搜索
  4594. if mine {
  4595. total, edbInfoList, err = elastic.SearchEdbInfoDataByAdminId(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 1, frequency, this.SysUser.AdminId)
  4596. } else {
  4597. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, frequency, noPermissionEdbInfoIdList)
  4598. }
  4599. isEs = true
  4600. } else {
  4601. var condition string
  4602. var pars []interface{}
  4603. // 普通指标
  4604. condition += ` AND edb_info_type = ? `
  4605. pars = append(pars, 0)
  4606. // 无权限指标id
  4607. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  4608. if lenNoPermissionEdbInfoIdList > 0 {
  4609. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  4610. pars = append(pars, noPermissionEdbInfoIdList)
  4611. }
  4612. switch filterSource {
  4613. case 2:
  4614. condition += ` AND frequency='月度' `
  4615. case 3:
  4616. condition += ` AND frequency <> '日度' `
  4617. case 4:
  4618. condition += ` AND edb_type = 1 `
  4619. case 5:
  4620. condition += ` AND source = 6 ` //来源(同比值)
  4621. case 6:
  4622. condition += ` AND frequency != ? `
  4623. pars = append(pars, "年度")
  4624. }
  4625. //频度
  4626. if frequency != "" {
  4627. condition += ` AND frequency = ? `
  4628. pars = append(pars, frequency)
  4629. }
  4630. // 查询只允许添加预测指标的搜索
  4631. if isAddPredictEdb {
  4632. condition += ` AND frequency in ("日度","周度","月度") `
  4633. }
  4634. if mine {
  4635. condition += ` AND sys_user_id = ? `
  4636. pars = append(pars, this.SysUser.AdminId)
  4637. }
  4638. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  4639. }
  4640. if err != nil {
  4641. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  4642. }
  4643. page := paging.GetPaging(currentIndex, pageSize, int(total))
  4644. edbInfoListLen := len(edbInfoList)
  4645. classifyIdList := make([]int, 0)
  4646. for i := 0; i < edbInfoListLen; i++ {
  4647. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  4648. classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
  4649. // 如果没有关键词,那么搜索结果字段取指标名,前端已统一用该字段显示搜索的列表内容
  4650. if keyWord == "" {
  4651. if this.Lang == utils.ZhLangVersion {
  4652. edbInfoList[i].SearchText = edbInfoList[i].EdbName
  4653. }
  4654. if this.Lang == utils.EnLangVersion {
  4655. edbInfoList[i].SearchText = edbInfoList[i].EdbNameEn
  4656. }
  4657. }
  4658. }
  4659. // 当前列表中的分类map
  4660. classifyMap := make(map[int]*data_manage.EdbClassify)
  4661. if edbInfoListLen > 0 {
  4662. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  4663. if err != nil {
  4664. br.Msg = "获取失败"
  4665. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4666. return
  4667. }
  4668. for _, v := range classifyList {
  4669. classifyMap[v.ClassifyId] = v
  4670. }
  4671. // 获取所有有权限的指标和分类
  4672. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4673. if err != nil {
  4674. br.Msg = "获取失败"
  4675. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4676. return
  4677. }
  4678. // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
  4679. if isEs {
  4680. edbInfoIdList := make([]int, 0)
  4681. for i := 0; i < edbInfoListLen; i++ {
  4682. edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
  4683. tmpEdbInfo := edbInfoList[i]
  4684. if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
  4685. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4686. }
  4687. }
  4688. tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  4689. if err != nil {
  4690. br.Msg = "获取失败"
  4691. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  4692. return
  4693. }
  4694. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  4695. for _, v := range tmpEdbList {
  4696. edbInfoMap[v.EdbInfoId] = v
  4697. }
  4698. for i := 0; i < edbInfoListLen; i++ {
  4699. tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
  4700. if !ok {
  4701. continue
  4702. }
  4703. edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
  4704. }
  4705. }
  4706. // 权限校验
  4707. for i := 0; i < edbInfoListLen; i++ {
  4708. tmpEdbInfoItem := edbInfoList[i]
  4709. if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
  4710. edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  4711. }
  4712. }
  4713. }
  4714. for i := 0; i < edbInfoListLen; i++ {
  4715. for j := 0; j < edbInfoListLen; j++ {
  4716. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  4717. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  4718. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  4719. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  4720. }
  4721. }
  4722. }
  4723. //新增搜索词记录
  4724. {
  4725. searchKeyword := new(data_manage.SearchKeyword)
  4726. searchKeyword.KeyWord = keyWord
  4727. searchKeyword.CreateTime = time.Now()
  4728. go data_manage.AddSearchKeyword(searchKeyword)
  4729. }
  4730. resp := data_manage.EdbInfoFilterDataResp{
  4731. Paging: page,
  4732. List: edbInfoList,
  4733. }
  4734. br.Ret = 200
  4735. br.Success = true
  4736. br.Msg = "获取成功"
  4737. br.Data = resp
  4738. }
  4739. // GetEdbDateData
  4740. // @Title 根据指标ID和具体日期获取对应日期的数据值
  4741. // @Description 根据指标ID和具体日期获取对应日期的数据值
  4742. // @Param EdbInfoId query int false "指标id"
  4743. // @Param Date query string false "日期"
  4744. // @Success 200 {object} data_manage.EdbInfoList
  4745. // @router /edb_info/date_data [get]
  4746. func (this *EdbInfoController) GetEdbDateData() {
  4747. br := new(models.BaseResponse).Init()
  4748. defer func() {
  4749. this.Data["json"] = br
  4750. this.ServeJSON()
  4751. }()
  4752. edbInfoId, _ := this.GetInt("EdbInfoId")
  4753. date := this.GetString("Date")
  4754. if edbInfoId <= 0 {
  4755. br.Msg = "请选择指标"
  4756. br.IsSendEmail = false
  4757. return
  4758. }
  4759. if date == `` {
  4760. br.Msg = "请选择日期"
  4761. br.IsSendEmail = false
  4762. return
  4763. }
  4764. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4765. if err != nil {
  4766. br.Msg = "获取失败"
  4767. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4768. return
  4769. }
  4770. startDate := date
  4771. endDate := date
  4772. dateType := "day"
  4773. //如果填写的是月度日期
  4774. if strings.Count(date, "-") == 1 {
  4775. startDate = date + "-01"
  4776. endDate = ``
  4777. dateType = "month"
  4778. }
  4779. dataItem, err := data.GetDateData(edbInfo, startDate, endDate)
  4780. if err != nil {
  4781. br.Msg = "获取失败"
  4782. br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
  4783. return
  4784. }
  4785. val := ``
  4786. if dataItem != nil {
  4787. switch dateType {
  4788. case "month":
  4789. dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local)
  4790. dateTimeStr := dateTime.Format(utils.FormatYearMonthDate)
  4791. if dateTimeStr != date {
  4792. val = ``
  4793. }
  4794. }
  4795. val = fmt.Sprint(dataItem.Value)
  4796. }
  4797. br.Ret = 200
  4798. br.Success = true
  4799. br.Msg = "获取成功"
  4800. br.Data = val
  4801. }
  4802. // GetEdbBeforeAndAfterDateData
  4803. // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4804. // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期
  4805. // @Param EdbInfoId query int false "指标id"
  4806. // @Param Date query string false "日期"
  4807. // @Param Num query int false "前后几期数据"
  4808. // @Success 200 {object} data_manage.EdbInfoList
  4809. // @router /edb_info/date_data/before_after [post]
  4810. func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
  4811. br := new(models.BaseResponse).Init()
  4812. defer func() {
  4813. this.Data["json"] = br
  4814. this.ServeJSON()
  4815. }()
  4816. requestBody := string(this.Ctx.Input.RequestBody)
  4817. var req request2.DateDataBeforeAfterReq
  4818. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4819. if err != nil {
  4820. br.Msg = "参数解析异常!"
  4821. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4822. return
  4823. }
  4824. edbInfoId := req.EdbInfoId
  4825. currDate := req.Date
  4826. num := req.Num
  4827. // 默认2期数据
  4828. if num <= 0 {
  4829. num = 2
  4830. }
  4831. if edbInfoId <= 0 {
  4832. br.Msg = "请选择指标"
  4833. br.IsSendEmail = false
  4834. return
  4835. }
  4836. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4837. if err != nil {
  4838. br.Msg = "获取失败"
  4839. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4840. return
  4841. }
  4842. dataList := make([]*data_manage.EdbDataList, 0)
  4843. switch edbInfo.EdbInfoType {
  4844. case 0:
  4845. dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
  4846. case 1:
  4847. _, dataList, _, _, _, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
  4848. default:
  4849. br.Msg = "指标类型异常!"
  4850. br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType)
  4851. return
  4852. }
  4853. if currDate == `` {
  4854. currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList)
  4855. if err != nil {
  4856. br.Msg = "日期前移失败"
  4857. br.ErrMsg = "日期前移失败,Err:" + err.Error()
  4858. return
  4859. }
  4860. } else {
  4861. if strings.Count(currDate, "-") == 1 {
  4862. currDate = currDate + "-01"
  4863. // 查找这个月早的时间作为起始时间
  4864. for _, v := range dataList {
  4865. if v.DataTime >= currDate {
  4866. currDate = v.DataTime
  4867. break
  4868. }
  4869. }
  4870. }
  4871. }
  4872. currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody)
  4873. if err != nil {
  4874. br.Msg = "日期变换失败"
  4875. br.ErrMsg = "日期变换失败,Err:" + err.Error()
  4876. return
  4877. }
  4878. list := make([]*data_manage.EdbDataList, 5)
  4879. list, err = data.GetEdbBeforeAndAfterDateData(currDate, dataList)
  4880. if err != nil {
  4881. br.Msg = "获取失败"
  4882. br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
  4883. return
  4884. }
  4885. // 这个日期不存在的话直接返回空数组
  4886. resp := data_manage.BeforeAndAfterDateDataResp{
  4887. List: list,
  4888. Date: currDate,
  4889. }
  4890. br.Ret = 200
  4891. br.Success = true
  4892. br.Msg = "获取成功"
  4893. br.Data = resp
  4894. }
  4895. // EdbChartAdminList
  4896. // @Title 获取创建人员分组
  4897. // @Description 获取创建人员分组
  4898. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  4899. // @Success 200 {object} company.DepartmentGroupSellersResp
  4900. // @router /edb_chart/adminList [get]
  4901. func (this *EdbInfoController) EdbChartAdminList() {
  4902. br := new(models.BaseResponse).Init()
  4903. defer func() {
  4904. this.Data["json"] = br
  4905. this.ServeJSON()
  4906. }()
  4907. sysUser := this.SysUser
  4908. if sysUser == nil {
  4909. br.Msg = "请登录"
  4910. br.ErrMsg = "请登录,SysUser Is Empty"
  4911. br.Ret = 408
  4912. return
  4913. }
  4914. source, _ := this.GetInt("Source", 0)
  4915. if source <= 0 || source > 5 {
  4916. br.Msg = "错误的来源"
  4917. br.IsSendEmail = false
  4918. return
  4919. }
  4920. idList, err := data.GetEdbChartAdminList(source)
  4921. if err != nil {
  4922. //br.Success = true
  4923. br.Msg = "获取失败"
  4924. br.ErrMsg = "获取失败,Err:" + err.Error()
  4925. return
  4926. }
  4927. fmt.Println("idlist:", idList)
  4928. systemAdminMap := make(map[int]*system.Admin)
  4929. departmentMap := make(map[string]string)
  4930. departmentAdminMap := make(map[int]string)
  4931. groupMap := make(map[string]string)
  4932. systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList)
  4933. if err != nil {
  4934. br.Msg = "获取用户列表失败"
  4935. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  4936. return
  4937. }
  4938. for _, v := range systemAdminList {
  4939. systemAdminMap[v.AdminId] = v
  4940. departmentMap[v.DepartmentName] = v.DepartmentName
  4941. departmentAdminMap[v.AdminId] = v.DepartmentName
  4942. groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName
  4943. }
  4944. depList := make([]company.DepartmentGroupAdmins, 0)
  4945. i := 1
  4946. for _, v := range departmentMap {
  4947. item := company.DepartmentGroupAdmins{
  4948. AdminId: "dep_" + strconv.Itoa(i),
  4949. RealName: v,
  4950. }
  4951. i++
  4952. depList = append(depList, item)
  4953. }
  4954. for k := 0; k < len(depList); k++ {
  4955. for k1, v1 := range groupMap {
  4956. if v1 == depList[k].RealName && v1 != "" {
  4957. item := &company.DepartmentGroupAdmins{
  4958. AdminId: "group_" + strconv.Itoa(k),
  4959. RealName: strings.Replace(k1, v1, "", -1),
  4960. }
  4961. depList[k].ChildrenList = append(depList[k].ChildrenList, item)
  4962. }
  4963. }
  4964. }
  4965. for _, admin := range systemAdminList {
  4966. for i, v := range depList {
  4967. for k, group := range v.ChildrenList {
  4968. if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName {
  4969. item := &company.DepartmentGroupAdmins{
  4970. AdminId: strconv.Itoa(admin.AdminId),
  4971. RealName: admin.RealName,
  4972. RoleTypeCode: admin.RoleTypeCode,
  4973. Authority: admin.Authority,
  4974. }
  4975. if group.RealName != "" {
  4976. depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item)
  4977. } else {
  4978. depList[i].ChildrenList = append(depList[i].ChildrenList, item)
  4979. }
  4980. }
  4981. }
  4982. }
  4983. }
  4984. for i, groupList := range depList {
  4985. for k, v := range groupList.ChildrenList {
  4986. if v.RealName == "" {
  4987. newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...)
  4988. depList[i].ChildrenList = newChildrenList
  4989. }
  4990. }
  4991. }
  4992. br.Ret = 200
  4993. br.Success = true
  4994. br.Msg = "获取成功"
  4995. br.Data = depList
  4996. }
  4997. // EdbSourceList
  4998. // @Title 指标来源列表
  4999. // @Description 指标来源列表
  5000. // @Param IsBase query int false "是否为基础指标: 1-是"
  5001. // @Success 200 {object} data_manage.EdbInfoListResp
  5002. // @router /edb_source/list [get]
  5003. func (this *EdbInfoController) EdbSourceList() {
  5004. br := new(models.BaseResponse).Init()
  5005. defer func() {
  5006. if br.ErrMsg == "" {
  5007. br.IsSendEmail = false
  5008. }
  5009. this.Data["json"] = br
  5010. this.ServeJSON()
  5011. }()
  5012. isBase, _ := this.GetInt("IsBase", 0)
  5013. cond := ``
  5014. if isBase > 0 {
  5015. cond = ` AND is_base = 1`
  5016. }
  5017. pars := make([]interface{}, 0)
  5018. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  5019. if e != nil {
  5020. br.Msg = "获取失败"
  5021. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  5022. return
  5023. }
  5024. br.Data = list
  5025. br.Ret = 200
  5026. br.Success = true
  5027. br.Msg = "获取成功"
  5028. }
  5029. // EdbSourceListByPython
  5030. // @Title 指标来源列表
  5031. // @Description 指标来源列表
  5032. // @Param IsBase query int false "是否为基础指标: 1-是"
  5033. // @Success 200 {object} data_manage.EdbInfoListResp
  5034. // @router /edb_source/list/python [get]
  5035. func (this *EdbInfoController) EdbSourceListByPython() {
  5036. br := new(models.BaseResponse).Init()
  5037. defer func() {
  5038. if br.ErrMsg == "" {
  5039. br.IsSendEmail = false
  5040. }
  5041. this.Data["json"] = br
  5042. this.ServeJSON()
  5043. }()
  5044. isBase, _ := this.GetInt("IsBase", 0)
  5045. cond := ``
  5046. if isBase > 0 {
  5047. cond = ` AND is_base = 1`
  5048. }
  5049. pars := make([]interface{}, 0)
  5050. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  5051. if e != nil {
  5052. br.Msg = "获取失败"
  5053. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  5054. return
  5055. }
  5056. baseEdbList := make([]data_manage.EdbSourceChild, 0)
  5057. calEdbList := make([]data_manage.EdbSourceChild, 0)
  5058. for _, v := range list {
  5059. switch v.IsBase {
  5060. case 1:
  5061. baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{
  5062. EdbSourceId: v.EdbSourceId,
  5063. SourceName: v.SourceName,
  5064. IsBase: v.IsBase,
  5065. TableName: v.TableName,
  5066. Child: []data_manage.EdbSourceChild{},
  5067. })
  5068. case 2:
  5069. calEdbList = append(calEdbList, data_manage.EdbSourceChild{
  5070. EdbSourceId: v.EdbSourceId,
  5071. SourceName: v.SourceName,
  5072. IsBase: v.IsBase,
  5073. TableName: v.TableName,
  5074. Child: []data_manage.EdbSourceChild{},
  5075. })
  5076. }
  5077. }
  5078. resp := []data_manage.EdbSourceChild{
  5079. {
  5080. EdbSourceId: 0,
  5081. SourceName: "基础指标",
  5082. IsBase: 1,
  5083. Child: baseEdbList,
  5084. },
  5085. {
  5086. EdbSourceId: 0,
  5087. SourceName: "计算指标",
  5088. IsBase: 1,
  5089. Child: calEdbList,
  5090. },
  5091. }
  5092. br.Data = resp
  5093. br.Ret = 200
  5094. br.Success = true
  5095. br.Msg = "获取成功"
  5096. }
  5097. // EdbChartList
  5098. // @Title 指标缩略图列表接口
  5099. // @Description 指标缩略图列表接口
  5100. // @Param PageSize query int true "每页数据条数"
  5101. // @Param CurrentIndex query int true "当前页页码,从1开始"
  5102. // @Param ClassifyId query int true "分类id"
  5103. // @Param AdminId query int false "创建人id"
  5104. // @Param IsOnlyMe query bool false "是否只看我的"
  5105. // @Success 200 {object} response.EdbInfoChartListResp
  5106. // @router /edb_info/chart/list [get]
  5107. func (this *EdbInfoController) EdbChartList() {
  5108. br := new(models.BaseResponse).Init()
  5109. defer func() {
  5110. if br.ErrMsg == "" {
  5111. br.IsSendEmail = false
  5112. }
  5113. this.Data["json"] = br
  5114. this.ServeJSON()
  5115. }()
  5116. sysUser := this.SysUser
  5117. if sysUser == nil {
  5118. br.Msg = "请登录"
  5119. br.ErrMsg = "请登录,SysUser Is Empty"
  5120. br.Ret = 408
  5121. return
  5122. }
  5123. // 分页
  5124. pageSize, _ := this.GetInt("PageSize")
  5125. currentIndex, _ := this.GetInt("CurrentIndex")
  5126. var total int
  5127. page := paging.GetPaging(currentIndex, pageSize, total)
  5128. var startSize int
  5129. if pageSize <= 0 {
  5130. pageSize = utils.PageSize20
  5131. }
  5132. if currentIndex <= 0 {
  5133. currentIndex = 1
  5134. }
  5135. startSize = paging.StartIndex(currentIndex, pageSize)
  5136. // 基础指标
  5137. var condition string
  5138. var pars []interface{}
  5139. condition += ` AND edb_info_type = ? `
  5140. pars = append(pars, 0)
  5141. // 分类筛选
  5142. classifyId, _ := this.GetInt("ClassifyId")
  5143. if classifyId > 0 {
  5144. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  5145. if e != nil && !utils.IsErrNoRow(e) {
  5146. br.Msg = "获取失败"
  5147. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  5148. return
  5149. }
  5150. var classifyIds []int
  5151. for _, v := range childClassify {
  5152. classifyIds = append(classifyIds, v.ClassifyId)
  5153. }
  5154. condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  5155. pars = append(pars, classifyIds)
  5156. }
  5157. // 创建人
  5158. adminId, _ := this.GetInt("AdminId")
  5159. if adminId > 0 {
  5160. condition += ` AND sys_user_id = ? `
  5161. pars = append(pars, adminId)
  5162. }
  5163. // 只看我的
  5164. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  5165. if isOnlyMe {
  5166. condition += ` AND sys_user_id = ? `
  5167. pars = append(pars, sysUser.AdminId)
  5168. }
  5169. // 获取当前账号的不可见指标
  5170. obj := data_manage.EdbInfoNoPermissionAdmin{}
  5171. confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
  5172. if e != nil {
  5173. br.Msg = "获取失败"
  5174. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
  5175. return
  5176. }
  5177. noPermissionEdbInfoIdList := make([]int, 0)
  5178. for _, v := range confList {
  5179. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  5180. }
  5181. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  5182. if noPermissionEdbInfoIdNum > 0 {
  5183. condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  5184. pars = append(pars, noPermissionEdbInfoIdList)
  5185. }
  5186. // 获取指标信息
  5187. dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  5188. if e != nil {
  5189. br.Msg = "获取失败"
  5190. br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
  5191. return
  5192. }
  5193. if len(list) == 0 {
  5194. list = make([]*data_manage.EdbInfoList, 0)
  5195. } else {
  5196. classifyIdList := make([]int, 0)
  5197. for _, v := range list {
  5198. classifyIdList = append(classifyIdList, v.ClassifyId)
  5199. }
  5200. // 指标权限
  5201. {
  5202. // 当前的分类
  5203. classifyMap := make(map[int]*data_manage.EdbClassify)
  5204. classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
  5205. if err != nil {
  5206. if err != nil {
  5207. br.Msg = "获取失败"
  5208. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  5209. return
  5210. }
  5211. }
  5212. for _, v := range classifyList {
  5213. classifyMap[v.ClassifyId] = v
  5214. }
  5215. // 获取所有有权限的指标和分类
  5216. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  5217. if err != nil {
  5218. br.Msg = "获取失败"
  5219. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  5220. return
  5221. }
  5222. issSupplierStopIndexCodeMap := make(map[string]bool)
  5223. {
  5224. tmpEdbCodeList := make([]string, 0)
  5225. for _, v := range list {
  5226. if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  5227. tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode)
  5228. }
  5229. }
  5230. if len(tmpEdbCodeList) > 0 {
  5231. notIsSupplierStopIndexList, e := data_manage.GetNotIsSupplierStopIndexByCodeList(tmpEdbCodeList, 1)
  5232. if e != nil {
  5233. br.Msg = "获取失败"
  5234. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  5235. return
  5236. }
  5237. // 已被供应商暂停的指标编码
  5238. for _, v := range notIsSupplierStopIndexList {
  5239. issSupplierStopIndexCodeMap[v.IndexCode] = true
  5240. }
  5241. }
  5242. }
  5243. for _, v := range list {
  5244. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  5245. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  5246. v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType, v.HaveOperaAuth)
  5247. }
  5248. // 供应商停用
  5249. if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  5250. if _, ok := issSupplierStopIndexCodeMap[v.EdbCode]; ok {
  5251. v.IsSupplierStop = 1
  5252. }
  5253. }
  5254. var relation *data_manage.BaseRelationEdbInfo
  5255. relation, err = data.GetEdbRelationListById(v.EdbInfoId, v.Source)
  5256. if err != nil {
  5257. br.Msg = "获取失败"
  5258. br.ErrMsg = "获取数据引用信息失败,Err:" + e.Error()
  5259. return
  5260. }
  5261. if relation.RelationNum > 0 {
  5262. v.IsRelation = true
  5263. }
  5264. }
  5265. }
  5266. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  5267. }
  5268. resp := response.EdbInfoChartListResp{
  5269. Paging: page,
  5270. List: list,
  5271. }
  5272. br.Ret = 200
  5273. br.Success = true
  5274. br.Msg = "获取成功"
  5275. br.Data = resp
  5276. }
  5277. // Modify
  5278. // @Title 修改指标信息接口
  5279. // @Description 编辑指标接口
  5280. // @Success 200 string "操作成功"
  5281. // @router /edb_info/modify [post]
  5282. func (this *EdbInfoController) Modify() {
  5283. br := new(models.BaseResponse).Init()
  5284. defer func() {
  5285. if br.ErrMsg == "" {
  5286. br.IsSendEmail = false
  5287. }
  5288. this.Data["json"] = br
  5289. this.ServeJSON()
  5290. }()
  5291. sysUser := this.SysUser
  5292. if sysUser == nil {
  5293. br.Msg = "请登录"
  5294. br.ErrMsg = "请登录,SysUser Is Empty"
  5295. br.Ret = 408
  5296. return
  5297. }
  5298. var req request.ModifyEdbInfoReq
  5299. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5300. if err != nil {
  5301. br.Msg = "参数解析异常!"
  5302. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5303. return
  5304. }
  5305. edbInfoId := req.EdbInfoId
  5306. if edbInfoId <= 0 {
  5307. br.Msg = "请选择指标"
  5308. br.IsSendEmail = false
  5309. return
  5310. }
  5311. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5312. if e != nil {
  5313. br.Msg = "操作失败"
  5314. br.ErrMsg = "获取指标信息失败, Err:" + err.Error()
  5315. return
  5316. }
  5317. var haveOperaAuth bool
  5318. // 权限校验
  5319. {
  5320. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId)
  5321. if err != nil {
  5322. br.Msg = err.Error()
  5323. br.ErrMsg = "校验指标权限失败,err:" + err.Error()
  5324. return
  5325. }
  5326. }
  5327. // 编辑权限校验
  5328. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  5329. if !button.OpButton {
  5330. br.Msg = "无权限操作"
  5331. return
  5332. }
  5333. edbInfo.MaxValue = req.MaxValue
  5334. edbInfo.MinValue = req.MinValue
  5335. edbInfo.ManualSave = 1
  5336. edbInfo.ModifyTime = time.Now()
  5337. err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"})
  5338. if err != nil {
  5339. br.Msg = "获取失败"
  5340. br.ErrMsg = "获取失败,Err:" + err.Error()
  5341. return
  5342. }
  5343. //修改es
  5344. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  5345. br.Ret = 200
  5346. br.Success = true
  5347. br.Msg = "修改成功"
  5348. br.IsAddLog = true
  5349. }
  5350. // ChartImageSet
  5351. // @Title 设置指标的图表图片
  5352. // @Description 设置指标的图表图片接口
  5353. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  5354. // @Success Ret=200 保存成功
  5355. // @router /edb_info/image/set [post]
  5356. func (this *EdbInfoController) ChartImageSet() {
  5357. br := new(models.BaseResponse).Init()
  5358. defer func() {
  5359. if br.ErrMsg == "" {
  5360. br.IsSendEmail = false
  5361. }
  5362. this.Data["json"] = br
  5363. this.ServeJSON()
  5364. }()
  5365. sysUser := this.SysUser
  5366. if sysUser == nil {
  5367. br.Msg = "请登录"
  5368. br.ErrMsg = "请登录,SysUser Is Empty"
  5369. br.Ret = 408
  5370. return
  5371. }
  5372. var req data_manage.SetEdbInfoImageReq
  5373. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  5374. br.Msg = "参数解析异常!"
  5375. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  5376. return
  5377. }
  5378. if req.EdbInfoId <= 0 || req.ImageUrl == "" {
  5379. br.Ret = 200
  5380. br.Success = true
  5381. br.Msg = "保存成功"
  5382. return
  5383. }
  5384. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  5385. if e != nil {
  5386. if utils.IsErrNoRow(e) {
  5387. br.Msg = "找不到该指标"
  5388. return
  5389. }
  5390. br.Msg = "保存失败"
  5391. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  5392. return
  5393. }
  5394. edbInfo.ChartImage = req.ImageUrl
  5395. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  5396. br.Msg = "保存失败"
  5397. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  5398. return
  5399. }
  5400. // 修改es数据
  5401. go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  5402. br.Ret = 200
  5403. br.Success = true
  5404. br.Msg = "保存成功"
  5405. }
  5406. // EdbInfoExistCheck
  5407. // @Title 新增指标-检验指标是否存在接口
  5408. // @Description 新增指标-检验指标是否存在接口
  5409. // @Param Source query int true "来源:1:同花顺,2:wind"
  5410. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5411. // @Param EdbCode query string false "指标编码/指标代码"
  5412. // @Param StockCode query string false "证券代码"
  5413. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5414. // @router /edb_info/exist/check [get]
  5415. func (this *EdbInfoController) EdbInfoExistCheck() {
  5416. br := new(models.BaseResponse).Init()
  5417. defer func() {
  5418. this.Data["json"] = br
  5419. this.ServeJSON()
  5420. }()
  5421. source, _ := this.GetInt("Source")
  5422. edbCode := this.GetString("EdbCode")
  5423. edbCode = strings.Trim(edbCode, "\t")
  5424. edbCode = strings.Trim(edbCode, " ")
  5425. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5426. subSource, _ := this.GetInt("SubSource")
  5427. stockCode := this.GetString("StockCode")
  5428. if source <= 0 {
  5429. br.Msg = "无效的数据来源"
  5430. return
  5431. }
  5432. if edbCode == "" {
  5433. br.Msg = "请输入指标ID"
  5434. return
  5435. }
  5436. if source != utils.DATA_SOURCE_WIND && source != utils.DATA_SOURCE_THS {
  5437. br.Msg = "无效的数据来源"
  5438. return
  5439. }
  5440. if subSource != utils.DATA_SUB_SOURCE_DATE {
  5441. br.Msg = "无效的数据库来源"
  5442. return
  5443. }
  5444. var indexCodeArr []string
  5445. edbCodeArr := strings.Split(edbCode, ",")
  5446. stockCodeArr := strings.Split(stockCode, ",")
  5447. var prefix string
  5448. if source == utils.DATA_SOURCE_WIND {
  5449. prefix = utils.WindDbWsd
  5450. } else if source == utils.DATA_SOURCE_THS {
  5451. prefix = utils.ThsDs
  5452. } else {
  5453. br.Msg = "来源错误"
  5454. br.ErrMsg = "来源错误"
  5455. return
  5456. }
  5457. for _, sv := range stockCodeArr {
  5458. for _, ev := range edbCodeArr {
  5459. indexCode := prefix + sv + ev
  5460. indexCodeArr = append(indexCodeArr, indexCode)
  5461. }
  5462. }
  5463. indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr)
  5464. if err != nil && !utils.IsErrNoRow(err) {
  5465. br.Msg = "校验指标是否存在失败"
  5466. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5467. return
  5468. }
  5469. var existStockCodeArr []string
  5470. var existEdbCodeArr []string
  5471. var existClassifyId []int
  5472. var existIndexId []int
  5473. for _, indexItem := range indexList {
  5474. for _, sv := range stockCodeArr {
  5475. for _, ev := range edbCodeArr {
  5476. if strings.Contains(indexItem.EdbCode, sv) {
  5477. existStockCodeArr = append(existStockCodeArr, sv)
  5478. }
  5479. if strings.Contains(indexItem.EdbCode, ev) {
  5480. existEdbCodeArr = append(existEdbCodeArr, ev)
  5481. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5482. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5483. }
  5484. }
  5485. }
  5486. }
  5487. resp := new(data_manage.EdbInfoExistCheckResp)
  5488. if len(indexList) > 0 {
  5489. resp.IndexExist = true
  5490. }
  5491. resp.ExistEdbCodeArr = existEdbCodeArr
  5492. resp.ExistStockCodeArr = existStockCodeArr
  5493. resp.ExistClassifyId = existClassifyId
  5494. resp.ExistIndexId = existIndexId
  5495. resp.ExistEdbInfo = indexList
  5496. br.Ret = 200
  5497. br.Success = true
  5498. br.Msg = "获取成功"
  5499. br.Data = resp
  5500. }
  5501. // EdbInfoAdd
  5502. // @Title 指标批量保存接口
  5503. // @Description 指标批量保存接口
  5504. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  5505. // @Success Ret=200 保存成功
  5506. // @router /edb_info/batch/add [post]
  5507. func (this *EdbInfoController) EdbInfoBatchAdd() {
  5508. br := new(models.BaseResponse).Init()
  5509. defer func() {
  5510. this.Data["json"] = br
  5511. this.ServeJSON()
  5512. }()
  5513. sysUser := this.SysUser
  5514. if sysUser == nil {
  5515. br.Msg = "请登录"
  5516. br.ErrMsg = "请登录,SysUser Is Empty"
  5517. br.Ret = 408
  5518. return
  5519. }
  5520. deleteCache := true
  5521. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  5522. defer func() {
  5523. if deleteCache {
  5524. utils.Rc.Delete(cacheKey)
  5525. }
  5526. }()
  5527. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  5528. deleteCache = false
  5529. br.Msg = "系统处理中,请稍后重试!"
  5530. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  5531. return
  5532. }
  5533. var req data_manage.BatchAddEdbInfoReq
  5534. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5535. if err != nil {
  5536. br.Msg = "参数解析异常!"
  5537. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5538. return
  5539. }
  5540. resp := new(data_manage.AddEdbInfoResp)
  5541. var edbNames string
  5542. for _, v := range req.BatchList {
  5543. edbNames += "'" + v.EdbName + "',"
  5544. }
  5545. edbNames = strings.Trim(edbNames, ",")
  5546. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  5547. if err != nil {
  5548. br.Msg = "查询指标名称重复错误!"
  5549. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  5550. return
  5551. }
  5552. if len(infoList) > 0 {
  5553. for _, v := range infoList {
  5554. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  5555. }
  5556. br.Data = resp
  5557. br.Msg = "指标名称重复!"
  5558. br.ErrMsg = "指标名称重复"
  5559. return
  5560. }
  5561. for k, v := range req.BatchList {
  5562. v.EdbName = strings.Trim(v.EdbName, " ")
  5563. v.EdbCode = strings.Trim(v.EdbCode, " ")
  5564. v.StockCode = strings.Trim(v.StockCode, " ")
  5565. if v.Source <= 0 {
  5566. br.Msg = "无效的数据来源"
  5567. return
  5568. }
  5569. if v.EdbCode == "" {
  5570. br.Msg = "指标ID不能为空"
  5571. return
  5572. }
  5573. if v.StockCode == "" {
  5574. br.Msg = "证券代码不能为空"
  5575. return
  5576. }
  5577. if v.EdbName == "" {
  5578. br.Msg = "指标名称不能为空"
  5579. return
  5580. }
  5581. if v.Frequency == "" {
  5582. br.Msg = "频率不能为空"
  5583. return
  5584. }
  5585. if v.ClassifyId <= 0 {
  5586. br.Msg = "请选择分类"
  5587. return
  5588. }
  5589. terminalCode, serverUrl, _, e := data.GetEdbTerminalCodeBySource(v.Source, v.EdbCode, v.StockCode)
  5590. if e != nil {
  5591. br.Msg = "获取可以使用的终端地址失败"
  5592. br.ErrMsg = "获取可以使用的终端地址失败,Err:" + e.Error()
  5593. return
  5594. }
  5595. edbInfoItem := new(data_manage.EdbInfo)
  5596. edbInfoItem.Source = v.Source
  5597. switch v.Source {
  5598. case utils.DATA_SOURCE_WIND:
  5599. edbInfoItem.SourceName = "wind"
  5600. edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode
  5601. case utils.DATA_SOURCE_THS:
  5602. edbInfoItem.SourceName = "ths"
  5603. edbInfoItem.EdbCode = utils.ThsDs + v.StockCode + v.EdbCode
  5604. }
  5605. edbInfoItem.SubSource = utils.DATA_SUB_SOURCE_DATE
  5606. edbInfoItem.SubSourceName = "日期序列"
  5607. edbInfoItem.EdbName = v.EdbName
  5608. edbInfoItem.EdbNameSource = v.EdbName
  5609. edbInfoItem.EdbNameEn = v.EdbName
  5610. edbInfoItem.Frequency = v.Frequency
  5611. edbInfoItem.Unit = v.Unit
  5612. edbInfoItem.UnitEn = v.Unit
  5613. edbInfoItem.ClassifyId = v.ClassifyId
  5614. edbInfoItem.SysUserId = sysUser.AdminId
  5615. edbInfoItem.SysUserRealName = sysUser.RealName
  5616. edbInfoItem.IndicatorCode = v.EdbCode
  5617. edbInfoItem.StockCode = v.StockCode
  5618. edbInfoItem.TerminalCode = terminalCode
  5619. edbInfoItem.ServerUrl = serverUrl
  5620. var extra data_manage.EdbInfoExtra
  5621. if v.ApiExtraPars != "" {
  5622. extra.ApiExtraPars = v.ApiExtraPars
  5623. b, e := json.Marshal(extra)
  5624. if e != nil {
  5625. br.Msg = "保存失败"
  5626. br.ErrMsg = fmt.Sprintf("额外参数JSON格式化失败, %v", e)
  5627. return
  5628. }
  5629. edbInfoItem.Extra = string(b)
  5630. }
  5631. // 指标入库
  5632. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  5633. if err != nil {
  5634. br.Msg = "保存失败"
  5635. if errMsg != `` {
  5636. br.Msg = errMsg
  5637. }
  5638. br.ErrMsg = err.Error()
  5639. br.IsSendEmail = isSendEmail
  5640. return
  5641. }
  5642. //新增操作日志
  5643. {
  5644. edbLog := new(data_manage.EdbInfoLog)
  5645. edbLog.EdbInfoId = edbInfo.EdbInfoId
  5646. edbLog.SourceName = edbInfo.SourceName
  5647. edbLog.Source = edbInfo.Source
  5648. edbLog.EdbCode = edbInfo.EdbCode
  5649. edbLog.EdbName = edbInfo.EdbName
  5650. edbLog.ClassifyId = edbInfo.ClassifyId
  5651. edbLog.SysUserId = sysUser.AdminId
  5652. edbLog.SysUserRealName = sysUser.RealName
  5653. edbLog.CreateTime = time.Now()
  5654. edbLog.Content = string(this.Ctx.Input.RequestBody)
  5655. edbLog.Status = "新增指标"
  5656. edbLog.Method = this.Ctx.Input.URI()
  5657. go data_manage.AddEdbInfoLog(edbLog)
  5658. }
  5659. if k <= 0 {
  5660. resp.EdbInfoId = edbInfo.EdbInfoId
  5661. resp.UniqueCode = edbInfo.UniqueCode
  5662. }
  5663. }
  5664. // 试用平台更新用户累计新增指标数
  5665. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  5666. if e != nil {
  5667. br.Msg = "操作失败"
  5668. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  5669. return
  5670. }
  5671. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  5672. go func() {
  5673. var r etaTrialService.EtaTrialUserReq
  5674. r.Mobile = adminItem.Mobile
  5675. _, _ = etaTrialService.UpdateUserIndexNum(r)
  5676. }()
  5677. }
  5678. br.Ret = 200
  5679. br.Success = true
  5680. br.Msg = "保存成功"
  5681. br.Data = resp
  5682. br.IsAddLog = true
  5683. }
  5684. // SmmExistCheck
  5685. // @Title 新增指标-检验指标是否存在接口-smm
  5686. // @Description 新增指标-检验指标是否存在接口-smm
  5687. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5688. // @Param EdbCode query string false "指标编码/指标代码"
  5689. // @Param StockCode query string false "证券代码"
  5690. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  5691. // @router /edb_info/smm/exist/check [post]
  5692. func (this *EdbInfoController) SmmExistCheck() {
  5693. br := new(models.BaseResponse).Init()
  5694. defer func() {
  5695. this.Data["json"] = br
  5696. this.ServeJSON()
  5697. }()
  5698. var req data_manage.SmmIndexExistCheckReq
  5699. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5700. if err != nil {
  5701. br.Msg = "参数解析异常!"
  5702. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5703. return
  5704. }
  5705. types := req.Types
  5706. frequency := req.Frequency
  5707. dataState := req.DataState
  5708. selectAll := req.SelectAll
  5709. keyword := req.Keyword
  5710. edbCode := req.EdbCode
  5711. edbCode = strings.Trim(edbCode, "\t")
  5712. edbCode = strings.Trim(edbCode, " ")
  5713. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5714. var edbCodeArr []string
  5715. var codeArr []string
  5716. if selectAll {
  5717. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5718. var condition string
  5719. var pars []interface{}
  5720. if len(types) > 0 {
  5721. condition += " AND ( "
  5722. for _, v := range types {
  5723. typeArr := strings.Split(v, ",")
  5724. for i, v := range typeArr {
  5725. if i == 0 {
  5726. condition += " ( "
  5727. }
  5728. typeStr := "type_"
  5729. typeStr += fmt.Sprintf("%d", i+1)
  5730. condition += typeStr + " =? "
  5731. pars = append(pars, v)
  5732. if i == len(typeArr)-1 {
  5733. condition += " ) "
  5734. } else {
  5735. condition += " AND "
  5736. }
  5737. }
  5738. condition += " OR "
  5739. }
  5740. condition = strings.Trim(condition, "OR ")
  5741. condition += " ) "
  5742. }
  5743. if frequency != "" {
  5744. frequencyArr := strings.Split(frequency, ",")
  5745. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5746. pars = append(pars, frequencyArr)
  5747. }
  5748. if dataState != "" {
  5749. stateArr := strings.Split(dataState, ",")
  5750. if strings.Contains(dataState, "normal") {
  5751. stateArr = append(stateArr, "")
  5752. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5753. pars = append(pars, stateArr)
  5754. } else {
  5755. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5756. pars = append(pars, stateArr)
  5757. }
  5758. }
  5759. if keyword != "" {
  5760. keyWordArr := strings.Split(keyword, " ")
  5761. if len(keyWordArr) > 0 {
  5762. condition += " AND ( "
  5763. for _, v := range keyWordArr {
  5764. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5765. }
  5766. condition = strings.TrimRight(condition, "OR")
  5767. condition += " ) "
  5768. }
  5769. }
  5770. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5771. if err != nil {
  5772. br.Msg = "获取指标列表失败"
  5773. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5774. return
  5775. }
  5776. for _, v := range indexList {
  5777. codeArr = append(codeArr, v.IndexCode)
  5778. }
  5779. noUseCodeArr := strings.Split(edbCode, ",")
  5780. for _, code := range codeArr {
  5781. // 检查code是否在noUseCodeArr数组中
  5782. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5783. // 如果不在,将其添加到结果数组中
  5784. edbCodeArr = append(edbCodeArr, code)
  5785. }
  5786. }
  5787. } else {
  5788. //未勾选全选EdbCode就是需要的code
  5789. edbCodeArr = strings.Split(edbCode, ",")
  5790. }
  5791. if len(edbCodeArr) > 30 {
  5792. br.Msg = "最多只能选择30个指标"
  5793. return
  5794. }
  5795. if len(edbCodeArr) <= 0 {
  5796. br.Msg = "无符合指标或指标代码错误"
  5797. return
  5798. }
  5799. indexList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_YS, edbCodeArr)
  5800. if err != nil && !utils.IsErrNoRow(err) {
  5801. br.Msg = "校验指标是否存在失败"
  5802. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  5803. return
  5804. }
  5805. var existEdbCodeArr []string
  5806. var existClassifyId []int
  5807. var existIndexId []int
  5808. for _, indexItem := range indexList {
  5809. for _, ev := range edbCodeArr {
  5810. if strings.Contains(indexItem.EdbCode, ev) {
  5811. existEdbCodeArr = append(existEdbCodeArr, ev)
  5812. existClassifyId = append(existClassifyId, indexItem.ClassifyId)
  5813. existIndexId = append(existIndexId, indexItem.EdbInfoId)
  5814. }
  5815. }
  5816. }
  5817. resp := new(data_manage.EdbInfoSmmExistCheckResp)
  5818. if len(indexList) > 0 {
  5819. resp.IndexExist = true
  5820. }
  5821. if len(existEdbCodeArr) == len(edbCodeArr) {
  5822. resp.ExistAll = true
  5823. }
  5824. resp.ExistEdbCodeArr = existEdbCodeArr
  5825. resp.ExistClassifyId = existClassifyId
  5826. resp.ExistIndexId = existIndexId
  5827. resp.ExistEdbInfo = indexList
  5828. br.Ret = 200
  5829. br.Success = true
  5830. br.Msg = "获取成功"
  5831. br.Data = resp
  5832. }
  5833. // EdbInfoSearch
  5834. // @Title 新增指标-查询指标信息接口-smm
  5835. // @Description 新增指标-查询指标信息接口-smm
  5836. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  5837. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  5838. // @Param EdbCode query string false "指标编码/指标代码"
  5839. // @Param StockCode query string false "证券代码"
  5840. // @Success 200 {object} data_manage.EdbInfoSearchResp
  5841. // @router /edb_info/smm/search [post]
  5842. func (this *EdbInfoController) EdbInfoSmmSearch() {
  5843. br := new(models.BaseResponse).Init()
  5844. defer func() {
  5845. this.Data["json"] = br
  5846. this.ServeJSON()
  5847. }()
  5848. var req data_manage.SmmIndexExistCheckReq
  5849. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5850. if err != nil {
  5851. br.Msg = "参数解析异常!"
  5852. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5853. return
  5854. }
  5855. types := req.Types
  5856. frequency := req.Frequency
  5857. dataState := req.DataState
  5858. selectAll := req.SelectAll
  5859. keyword := req.Keyword
  5860. edbCode := req.EdbCode
  5861. edbCode = strings.Trim(edbCode, "\t")
  5862. edbCode = strings.Trim(edbCode, " ")
  5863. edbCode = strings.Replace(edbCode, "\t", "", -1)
  5864. var edbCodeArr []string
  5865. var codeArr []string
  5866. if selectAll {
  5867. // 如果勾了列表全选,那么EdbCode传的就是排除的code
  5868. var condition string
  5869. var pars []interface{}
  5870. if len(types) > 0 {
  5871. condition += " AND ( "
  5872. for _, v := range types {
  5873. typeArr := strings.Split(v, ",")
  5874. for i, v := range typeArr {
  5875. if i == 0 {
  5876. condition += " ( "
  5877. }
  5878. typeStr := "type_"
  5879. typeStr += fmt.Sprintf("%d", i+1)
  5880. condition += typeStr + " =? "
  5881. pars = append(pars, v)
  5882. if i == len(typeArr)-1 {
  5883. condition += " ) "
  5884. } else {
  5885. condition += " AND "
  5886. }
  5887. }
  5888. condition += " OR "
  5889. }
  5890. condition = strings.Trim(condition, "OR ")
  5891. condition += " ) "
  5892. }
  5893. if frequency != "" {
  5894. frequencyArr := strings.Split(frequency, ",")
  5895. condition += ` AND frequency IN (` + utils.GetOrmInReplace(len(frequencyArr)) + `) `
  5896. pars = append(pars, frequencyArr)
  5897. }
  5898. if dataState != "" {
  5899. stateArr := strings.Split(dataState, ",")
  5900. if strings.Contains(dataState, "normal") {
  5901. stateArr = append(stateArr, "")
  5902. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5903. pars = append(pars, stateArr)
  5904. } else {
  5905. condition += ` AND data_state IN (` + utils.GetOrmInReplace(len(stateArr)) + `) `
  5906. pars = append(pars, stateArr)
  5907. }
  5908. }
  5909. if keyword != "" {
  5910. keyWordArr := strings.Split(keyword, " ")
  5911. if len(keyWordArr) > 0 {
  5912. condition += " AND ( "
  5913. for _, v := range keyWordArr {
  5914. condition += ` CONCAT(index_name,index_code) LIKE '%` + v + `%' OR`
  5915. }
  5916. condition = strings.TrimRight(condition, "OR")
  5917. condition += " ) "
  5918. }
  5919. }
  5920. indexList, err := data_manage.GetSmmIndexDataListNoPage(condition, pars)
  5921. if err != nil {
  5922. br.Msg = "获取指标列表失败"
  5923. br.ErrMsg = "获取指标列表失败,Err:" + err.Error()
  5924. return
  5925. }
  5926. for _, v := range indexList {
  5927. codeArr = append(codeArr, v.IndexCode)
  5928. }
  5929. noUseCodeArr := strings.Split(edbCode, ",")
  5930. for _, code := range codeArr {
  5931. // 检查code是否在noUseCodeArr数组中
  5932. if !utils.ArrContainsStr(noUseCodeArr, code) {
  5933. // 如果不在,将其添加到结果数组中
  5934. edbCodeArr = append(edbCodeArr, code)
  5935. }
  5936. }
  5937. } else {
  5938. //未勾选全选EdbCode就是需要的code
  5939. edbCodeArr = strings.Split(edbCode, ",")
  5940. }
  5941. if len(edbCodeArr) > 30 {
  5942. br.Msg = "最多只能选择30个指标"
  5943. return
  5944. }
  5945. if len(edbCodeArr) <= 0 {
  5946. br.Msg = "无符合指标或指标代码错误"
  5947. return
  5948. }
  5949. edbCodeStr := ""
  5950. for i, _ := range edbCodeArr {
  5951. edbCodeStr += "'" + edbCodeArr[i] + "'" + ","
  5952. }
  5953. edbCodeStr = strings.Trim(edbCodeStr, ",")
  5954. smmInfoList, err := data_manage.GetBaseFromSmmIndexByIndexCodes(edbCodeStr)
  5955. if err != nil && !utils.IsErrNoRow(err) {
  5956. br.Msg = "获取失败"
  5957. br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
  5958. return
  5959. }
  5960. smmInfoMap := make(map[string]*data_manage.BaseFromSmmIndex)
  5961. for _, v := range smmInfoList {
  5962. smmInfoMap[v.IndexCode] = v
  5963. }
  5964. searchItemList := make([]*data_manage.EdbInfoSearch, 0)
  5965. resp := new(data_manage.EdbInfoSearchResp)
  5966. needAddCodeArr := make([]string, 0)
  5967. noNeedAddCodeMap := make(map[string]string, 0)
  5968. for _, edbCode := range edbCodeArr {
  5969. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  5970. if err != nil && !utils.IsErrNoRow(err) {
  5971. br.Msg = "获取失败"
  5972. br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
  5973. return
  5974. }
  5975. fmt.Println("dataItems:", len(dataItems))
  5976. if len(dataItems) > 0 {
  5977. searchItem := new(data_manage.EdbInfoSearch)
  5978. searchItem.EdbCode = edbCode
  5979. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  5980. if err != nil {
  5981. br.Msg = "获取失败"
  5982. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  5983. return
  5984. }
  5985. searchItem.DataList = dataItems
  5986. searchItem.StartDate = minDate
  5987. searchItem.EndDate = maxDate
  5988. searchItem.Frequency = smmInfoMap[edbCode].Frequency
  5989. searchItem.Unit = smmInfoMap[edbCode].Unit
  5990. searchItem.EdbName = smmInfoMap[edbCode].IndexName
  5991. searchItem.EdbCode = smmInfoMap[edbCode].IndexCode
  5992. searchItemList = append(searchItemList, searchItem)
  5993. noNeedAddCodeMap[edbCode] = edbCode
  5994. } else {
  5995. // 把需要新加的code添加到needAddCodeArr数组中,一起批量请求
  5996. needAddCodeArr = append(needAddCodeArr, edbCode)
  5997. }
  5998. }
  5999. if len(needAddCodeArr) > 0 {
  6000. edbCode = strings.Join(needAddCodeArr, ",")
  6001. respItem, err := data.AddEdbData(utils.DATA_SOURCE_YS, edbCode, "")
  6002. if err != nil {
  6003. br.Msg = "获取失败"
  6004. br.ErrMsg = "获取失败,Err:" + err.Error()
  6005. return
  6006. }
  6007. if respItem.Ret != 200 {
  6008. if respItem.Ret == 421 {
  6009. br.Msg = "该渠道已超过添加上限"
  6010. } else if respItem.Ret == 4052 {
  6011. br.Msg = "该指标已下架"
  6012. } else {
  6013. br.Msg = "未搜索到该指标"
  6014. }
  6015. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  6016. return
  6017. }
  6018. }
  6019. for _, smmInfo := range smmInfoList {
  6020. if smmInfo != nil {
  6021. if _, ok := noNeedAddCodeMap[smmInfo.IndexCode]; !ok {
  6022. searchItem := new(data_manage.EdbInfoSearch)
  6023. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(smmInfo.IndexCode)
  6024. if err != nil {
  6025. br.Msg = "获取失败"
  6026. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  6027. return
  6028. }
  6029. searchItem.StartDate = minDate
  6030. searchItem.EndDate = maxDate
  6031. searchItem.Frequency = smmInfo.Frequency
  6032. searchItem.Unit = smmInfo.Unit
  6033. searchItem.EdbName = smmInfo.IndexName
  6034. searchItem.EdbCode = smmInfo.IndexCode
  6035. dataList, err := data_manage.GetEdbDataAllByEdbCode(smmInfo.IndexCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
  6036. if err != nil && !utils.IsErrNoRow(err) {
  6037. br.Msg = "获取失败"
  6038. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  6039. return
  6040. }
  6041. searchItem.DataList = dataList
  6042. searchItemList = append(searchItemList, searchItem)
  6043. }
  6044. }
  6045. }
  6046. resp.Status = 2
  6047. resp.StockSearchList = searchItemList
  6048. br.Ret = 200
  6049. br.Success = true
  6050. br.Msg = "获取成功"
  6051. br.Data = resp
  6052. }
  6053. // SmmEdbInfoBatchAdd
  6054. // @Title 指标批量保存接口-smm
  6055. // @Description 指标批量保存接口-smm
  6056. // @Param request body data_manage.BatchAddEdbInfoReq true "type json string"
  6057. // @Success Ret=200 保存成功
  6058. // @router /edb_info/smm/batch/add [post]
  6059. func (this *EdbInfoController) SmmEdbInfoBatchAdd() {
  6060. br := new(models.BaseResponse).Init()
  6061. defer func() {
  6062. this.Data["json"] = br
  6063. this.ServeJSON()
  6064. }()
  6065. sysUser := this.SysUser
  6066. if sysUser == nil {
  6067. br.Msg = "请登录"
  6068. br.ErrMsg = "请登录,SysUser Is Empty"
  6069. br.Ret = 408
  6070. return
  6071. }
  6072. deleteCache := true
  6073. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId)
  6074. defer func() {
  6075. if deleteCache {
  6076. utils.Rc.Delete(cacheKey)
  6077. }
  6078. }()
  6079. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  6080. deleteCache = false
  6081. br.Msg = "系统处理中,请稍后重试!"
  6082. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  6083. return
  6084. }
  6085. var req data_manage.BatchAddEdbInfoReq
  6086. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  6087. if err != nil {
  6088. br.Msg = "参数解析异常!"
  6089. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  6090. return
  6091. }
  6092. resp := new(data_manage.AddEdbInfoResp)
  6093. var edbNames string
  6094. for _, v := range req.BatchList {
  6095. edbNames += "'" + v.EdbName + "',"
  6096. }
  6097. edbNames = strings.Trim(edbNames, ",")
  6098. infoList, err := data_manage.GetEdbInfoByNames(edbNames)
  6099. if err != nil {
  6100. br.Msg = "查询指标名称重复错误!"
  6101. br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error()
  6102. return
  6103. }
  6104. if len(infoList) > 0 {
  6105. for _, v := range infoList {
  6106. resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName)
  6107. }
  6108. br.Data = resp
  6109. br.Msg = "指标名称重复!"
  6110. br.ErrMsg = "指标名称重复"
  6111. return
  6112. }
  6113. for k, v := range req.BatchList {
  6114. v.EdbName = strings.Trim(v.EdbName, " ")
  6115. v.EdbCode = strings.Trim(v.EdbCode, " ")
  6116. if v.Source <= 0 {
  6117. br.Msg = "无效的数据来源"
  6118. return
  6119. }
  6120. if v.EdbCode == "" {
  6121. br.Msg = "指标ID不能为空"
  6122. return
  6123. }
  6124. if v.EdbName == "" {
  6125. br.Msg = "指标名称不能为空"
  6126. return
  6127. }
  6128. if v.Frequency == "" {
  6129. br.Msg = "频率不能为空"
  6130. return
  6131. }
  6132. if v.ClassifyId <= 0 {
  6133. br.Msg = "请选择分类"
  6134. return
  6135. }
  6136. edbInfoItem := new(data_manage.EdbInfo)
  6137. edbInfoItem.Source = v.Source
  6138. edbInfoItem.SourceName = "SMM"
  6139. edbInfoItem.EdbCode = v.EdbCode
  6140. edbInfoItem.SubSource = 0
  6141. edbInfoItem.SubSourceName = ""
  6142. edbInfoItem.EdbName = v.EdbName
  6143. edbInfoItem.EdbNameSource = v.EdbName
  6144. edbInfoItem.EdbNameEn = v.EdbName
  6145. edbInfoItem.Frequency = v.Frequency
  6146. edbInfoItem.Unit = v.Unit
  6147. edbInfoItem.UnitEn = v.Unit
  6148. edbInfoItem.ClassifyId = v.ClassifyId
  6149. edbInfoItem.SysUserId = sysUser.AdminId
  6150. edbInfoItem.SysUserRealName = sysUser.RealName
  6151. edbInfoItem.IndicatorCode = ""
  6152. edbInfoItem.StockCode = ""
  6153. // 指标入库
  6154. edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem)
  6155. if err != nil {
  6156. br.Msg = "保存失败"
  6157. if errMsg != `` {
  6158. br.Msg = errMsg
  6159. }
  6160. br.ErrMsg = err.Error()
  6161. br.IsSendEmail = isSendEmail
  6162. return
  6163. }
  6164. //新增操作日志
  6165. {
  6166. edbLog := new(data_manage.EdbInfoLog)
  6167. edbLog.EdbInfoId = edbInfo.EdbInfoId
  6168. edbLog.SourceName = edbInfo.SourceName
  6169. edbLog.Source = edbInfo.Source
  6170. edbLog.EdbCode = edbInfo.EdbCode
  6171. edbLog.EdbName = edbInfo.EdbName
  6172. edbLog.ClassifyId = edbInfo.ClassifyId
  6173. edbLog.SysUserId = sysUser.AdminId
  6174. edbLog.SysUserRealName = sysUser.RealName
  6175. edbLog.CreateTime = time.Now()
  6176. edbLog.Content = string(this.Ctx.Input.RequestBody)
  6177. edbLog.Status = "新增指标"
  6178. edbLog.Method = this.Ctx.Input.URI()
  6179. go data_manage.AddEdbInfoLog(edbLog)
  6180. }
  6181. if k <= 0 {
  6182. resp.EdbInfoId = edbInfo.EdbInfoId
  6183. resp.UniqueCode = edbInfo.UniqueCode
  6184. }
  6185. }
  6186. br.Ret = 200
  6187. br.Success = true
  6188. br.Msg = "保存成功"
  6189. br.Data = resp
  6190. br.IsAddLog = true
  6191. }
  6192. // ChartImageSetBySvg
  6193. // @Title 设置指标的图表图片
  6194. // @Description 设置指标的图表图片接口
  6195. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  6196. // @Success Ret=200 保存成功
  6197. // @router /edb_info/image/set_by_svg [post]
  6198. func (this *EdbInfoController) ChartImageSetBySvg() {
  6199. br := new(models.BaseResponse).Init()
  6200. defer func() {
  6201. if br.ErrMsg == "" {
  6202. br.IsSendEmail = false
  6203. }
  6204. this.Data["json"] = br
  6205. this.ServeJSON()
  6206. }()
  6207. sysUser := this.SysUser
  6208. if sysUser == nil {
  6209. br.Msg = "请登录"
  6210. br.ErrMsg = "请登录,SysUser Is Empty"
  6211. br.Ret = 408
  6212. return
  6213. }
  6214. imgData := this.GetString("Img")
  6215. if imgData == "" {
  6216. br.Msg = "图片参数错误"
  6217. br.ErrMsg = "图片参数错误,Img Is Empty"
  6218. return
  6219. }
  6220. edbInfoId, _ := this.GetInt("EdbInfoId", 0)
  6221. if edbInfoId <= 0 {
  6222. br.Msg = "指标参数错误"
  6223. br.ErrMsg = "指标参数错误,EdbInfoId Is Empty"
  6224. return
  6225. }
  6226. // 通过svg图片生成图片资源地址
  6227. resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData)
  6228. if err != nil {
  6229. br.Msg = errMsg
  6230. br.ErrMsg = err.Error()
  6231. return
  6232. }
  6233. if edbInfoId <= 0 || resourceUrl == "" {
  6234. br.Ret = 200
  6235. br.Success = true
  6236. br.Msg = "保存成功"
  6237. return
  6238. }
  6239. edbInfo, e := data_manage.GetEdbInfoById(edbInfoId)
  6240. if e != nil {
  6241. if utils.IsErrNoRow(e) {
  6242. br.Msg = "找不到该指标"
  6243. return
  6244. }
  6245. br.Msg = "保存失败"
  6246. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  6247. return
  6248. }
  6249. edbInfo.ChartImage = resourceUrl
  6250. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  6251. br.Msg = "保存失败"
  6252. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  6253. return
  6254. }
  6255. // 修改es数据
  6256. go data.AddOrEditEdbInfoToEs(edbInfoId)
  6257. br.Ret = 200
  6258. br.Success = true
  6259. br.Msg = "保存成功"
  6260. }
  6261. // ModifyChartList
  6262. // @Title 批量修改图表
  6263. // @Description 批量修改图表
  6264. // @Param SysUserIds query string true "根据创建人查询"
  6265. // @Param ChartClassifyIds query string true "图片分类id"
  6266. // @Success 200 {object} models.ChartClassifyListResp
  6267. // @router /modify/edbList [post]
  6268. func (this *EdbInfoController) ModifyEdbList() {
  6269. br := new(models.BaseResponse).Init()
  6270. defer func() {
  6271. this.Data["json"] = br
  6272. this.ServeJSON()
  6273. }()
  6274. sysUser := this.SysUser
  6275. if sysUser == nil {
  6276. br.Msg = "请登录"
  6277. br.ErrMsg = "请登录,SysUser Is Empty"
  6278. br.Ret = 408
  6279. return
  6280. }
  6281. var req request.ModifyEdbListReq
  6282. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  6283. if err != nil {
  6284. br.Msg = "参数解析异常!"
  6285. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  6286. return
  6287. }
  6288. classifyIds := strings.Split(req.EdbClassifyIds, ",")
  6289. if !req.SelectAll && req.EdbInfoIds == "" {
  6290. br.Msg = "请选择图表"
  6291. return
  6292. }
  6293. if req.ClassifyId < 0 {
  6294. br.Msg = "请选择新分类"
  6295. return
  6296. }
  6297. var condition string
  6298. var pars []interface{}
  6299. edbInfoIds := make([]int, 0)
  6300. if req.SelectAll {
  6301. // 已授权分类id
  6302. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  6303. if err != nil {
  6304. br.Msg = "获取失败"
  6305. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  6306. return
  6307. }
  6308. classifyIdsArr := make([]int, 0)
  6309. for _, v := range classifyIds {
  6310. if v != `` {
  6311. id, _ := strconv.Atoi(v)
  6312. classifyIdsArr = append(classifyIdsArr, id)
  6313. }
  6314. }
  6315. if len(permissionClassifyIdList) > 0 {
  6316. classifyIdsArr = utils.IntersectInt(permissionClassifyIdList, classifyIdsArr)
  6317. }
  6318. condition += " AND edb_info_type = 0 "
  6319. if len(classifyIdsArr) > 0 {
  6320. if !req.SubClassify {
  6321. condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(classifyIdsArr)) + ") "
  6322. pars = append(pars, classifyIdsArr)
  6323. } else {
  6324. classifyAll, err := data_manage.GetNormalEdbClassifyAll()
  6325. if err != nil && !utils.IsErrNoRow(err) {
  6326. br.Msg = "获取失败"
  6327. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6328. return
  6329. }
  6330. finalClassifyIds := make([]int, 0)
  6331. parents := data.GetEdbClassifyChildrenRecursiveByParentIds(classifyAll, classifyIds)
  6332. sort.Slice(parents, func(i, j int) bool {
  6333. return parents[i].Level < parents[i].Level
  6334. })
  6335. for _, v := range parents {
  6336. finalClassifyIds = append(finalClassifyIds, v.ClassifyId)
  6337. }
  6338. condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(finalClassifyIds)) + ") "
  6339. pars = append(pars, finalClassifyIds)
  6340. }
  6341. }
  6342. if req.KeyWord != "" {
  6343. condition += ` AND edb_name LIKE '%` + req.KeyWord + `%' `
  6344. }
  6345. if req.Sources != "" {
  6346. condition += " AND source IN(" + utils.GetOrmInReplace(len(strings.Split(req.Sources, ","))) + ") "
  6347. pars = append(pars, strings.Split(req.Sources, ","))
  6348. }
  6349. if req.SysUserIds != "" {
  6350. adminIds := strings.Split(req.SysUserIds, ",")
  6351. if len(adminIds) == 0 {
  6352. br.Msg = "请选择正确的创建人"
  6353. return
  6354. }
  6355. adminIdsSlice := make([]int, 0)
  6356. for _, adminId := range adminIds {
  6357. adminIdInt, e := strconv.Atoi(adminId)
  6358. if e != nil {
  6359. br.Msg = "请选择正确的创建人"
  6360. return
  6361. }
  6362. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  6363. }
  6364. condition += " AND sys_user_id in (" + utils.GetOrmInReplace(len(adminIds)) + ") "
  6365. pars = append(pars, adminIdsSlice)
  6366. }
  6367. // 获取当前账号的不可见指标
  6368. obj := data_manage.EdbInfoNoPermissionAdmin{}
  6369. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  6370. if err != nil && !utils.IsErrNoRow(err) {
  6371. br.Msg = "获取失败"
  6372. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  6373. return
  6374. }
  6375. noPermissionEdbInfoIds := make([]int, 0)
  6376. for _, v := range confList {
  6377. noPermissionEdbInfoIds = append(noPermissionEdbInfoIds, v.EdbInfoId)
  6378. }
  6379. if len(noPermissionEdbInfoIds) > 0 {
  6380. condition += " AND edb_info_id NOT IN(" + utils.GetOrmInReplace(len(noPermissionEdbInfoIds)) + ") "
  6381. pars = append(pars, noPermissionEdbInfoIds)
  6382. }
  6383. count, err := data_manage.GetEdbInfoByConditionCount(condition, pars)
  6384. if err != nil && !utils.IsErrNoRow(err) {
  6385. br.Msg = "获取失败"
  6386. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6387. return
  6388. }
  6389. if count > 100 {
  6390. br.Msg = "最多选择100个"
  6391. return
  6392. }
  6393. list, err := data_manage.GetEdbInfoListByCondition(condition, pars, 0, 0, "")
  6394. if err != nil && !utils.IsErrNoRow(err) {
  6395. br.Msg = "获取失败"
  6396. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6397. return
  6398. }
  6399. for _, v := range list {
  6400. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  6401. }
  6402. } else {
  6403. edbIds := strings.Split(req.EdbInfoIds, ",")
  6404. if len(edbIds) == 0 {
  6405. br.Msg = "请选择图表"
  6406. return
  6407. }
  6408. for _, id := range edbIds {
  6409. tmp, e := strconv.Atoi(id)
  6410. if e != nil {
  6411. br.Msg = "请选择正确的分类"
  6412. return
  6413. }
  6414. edbInfoIds = append(edbInfoIds, tmp)
  6415. }
  6416. if len(edbInfoIds) > 100 {
  6417. br.Msg = "最多只能选择100个图表"
  6418. return
  6419. }
  6420. }
  6421. err = data_manage.UpdateEdbClassifyIdByChartInfoId(edbInfoIds, req.ClassifyId)
  6422. if err != nil {
  6423. br.Msg = "更新失败"
  6424. br.ErrMsg = "更新图表分类失败,Err:" + err.Error()
  6425. return
  6426. }
  6427. br.Ret = 200
  6428. br.Success = true
  6429. br.Msg = "操作成功"
  6430. }