edb_info.go 195 KB

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