edb_info.go 171 KB

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