edb_info.go 140 KB

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