edb_info.go 151 KB

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