edb_info.go 152 KB

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