edb_info.go 130 KB

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