chart_info.go 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/data_manage/response"
  8. "eta/eta_api/models/system"
  9. "eta/eta_api/services"
  10. "eta/eta_api/services/alarm_msg"
  11. "eta/eta_api/services/data"
  12. "eta/eta_api/services/data/data_manage_permission"
  13. "eta/eta_api/services/data/excel"
  14. "eta/eta_api/services/eta_forum"
  15. etaTrialService "eta/eta_api/services/eta_trial"
  16. "eta/eta_api/utils"
  17. "fmt"
  18. "os"
  19. "os/exec"
  20. "sort"
  21. "strconv"
  22. "strings"
  23. "time"
  24. "github.com/rdlucklib/rdluck_tools/paging"
  25. )
  26. // 图表管理
  27. type ChartInfoController struct {
  28. controllers.BaseAuthController
  29. }
  30. // @Title 保存图表接口
  31. // @Description 保存图表接口
  32. // @Param request body data_manage.SaveChartInfoReq true "type json string"
  33. // @Success Ret=200 返回图表id
  34. // @router /chart_info/save [post]
  35. func (this *ChartInfoController) ChartInfoSave() {
  36. br := new(models.BaseResponse).Init()
  37. defer func() {
  38. this.Data["json"] = br
  39. this.ServeJSON()
  40. }()
  41. sysUser := this.SysUser
  42. if sysUser == nil {
  43. br.Msg = "请登录"
  44. br.ErrMsg = "请登录,SysUser Is Empty"
  45. br.Ret = 408
  46. return
  47. }
  48. var req data_manage.SaveChartInfoReq
  49. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  50. if err != nil {
  51. br.Msg = "参数解析异常!"
  52. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  53. return
  54. }
  55. if req.ChartInfoId > 0 && len(req.ChartEdbInfoList) <= 0 {
  56. br.Msg = "参数错误!"
  57. return
  58. }
  59. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  60. if err != nil {
  61. if err.Error() == utils.ErrNoRow() {
  62. br.Msg = "图表已被删除,请刷新页面!"
  63. br.ErrMsg = "图表已被删除,请刷新页面,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  64. return
  65. }
  66. br.Msg = "获取图表信息失败!"
  67. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  68. return
  69. }
  70. //图表操作权限
  71. //ok := data.CheckOpChartPermission(sysUser, chartItem.SysUserId)
  72. //if !ok {
  73. // br.Msg = "没有该图表的操作权限"
  74. // br.ErrMsg = "没有该图表的操作权限"
  75. // return
  76. //}
  77. if req.Calendar == "" {
  78. req.Calendar = "公历"
  79. }
  80. err = data_manage.ModifyChartInfoAndMapping(chartItem.EdbInfoIds, &req, chartItem.ChartType)
  81. if err != nil {
  82. br.Msg = "保存失败"
  83. br.ErrMsg = "保存失败,Err:" + err.Error()
  84. return
  85. }
  86. key := utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode
  87. if utils.Re == nil && utils.Rc != nil {
  88. utils.Rc.Delete(key)
  89. }
  90. //修改es数据
  91. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  92. //修改my eta es数据
  93. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  94. //新增操作日志
  95. {
  96. chartLog := new(data_manage.ChartInfoLog)
  97. chartLog.ChartName = chartItem.ChartName
  98. chartLog.ChartInfoId = req.ChartInfoId
  99. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  100. chartLog.SysUserId = sysUser.AdminId
  101. chartLog.SysUserRealName = sysUser.RealName
  102. chartLog.UniqueCode = chartItem.UniqueCode
  103. chartLog.CreateTime = time.Now()
  104. chartLog.Content = string(this.Ctx.Input.RequestBody)
  105. chartLog.Status = "修改配置项"
  106. chartLog.Method = this.Ctx.Input.URI()
  107. go data_manage.AddChartInfoLog(chartLog)
  108. }
  109. br.Ret = 200
  110. br.Success = true
  111. br.Msg = "保存成功"
  112. br.IsAddLog = true
  113. }
  114. // ChartInfoAdd
  115. // @Title 新增图表接口
  116. // @Description 新增图表接口
  117. // @Param request body data_manage.AddChartInfoReq true "type json string"
  118. // @Success 200 {object} data_manage.AddChartInfoResp
  119. // @router /chart_info/add [post]
  120. func (this *ChartInfoController) ChartInfoAdd() {
  121. br := new(models.BaseResponse).Init()
  122. defer func() {
  123. this.Data["json"] = br
  124. this.ServeJSON()
  125. }()
  126. sysUser := this.SysUser
  127. if sysUser == nil {
  128. br.Msg = "请登录"
  129. br.ErrMsg = "请登录,SysUser Is Empty"
  130. br.Ret = 408
  131. return
  132. }
  133. deleteCache := true
  134. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  135. defer func() {
  136. if deleteCache {
  137. utils.Rc.Delete(cacheKey)
  138. }
  139. }()
  140. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  141. deleteCache = false
  142. br.Msg = "系统处理中,请稍后重试!"
  143. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  144. return
  145. }
  146. var req data_manage.AddChartInfoReq
  147. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  148. if err != nil {
  149. br.Msg = "参数解析异常!"
  150. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  151. return
  152. }
  153. req.ChartName = strings.Trim(req.ChartName, " ")
  154. if req.ChartName == "" {
  155. br.Msg = "请填写图表名称!"
  156. return
  157. }
  158. if req.ChartClassifyId <= 0 {
  159. br.Msg = "分类参数错误!"
  160. return
  161. }
  162. chartInfo, err, errMsg, isSendEmail := data.AddChartInfo(req, sysUser.AdminId, sysUser.RealName, this.Lang)
  163. if err != nil {
  164. br.Msg = "保存失败"
  165. if errMsg != `` {
  166. br.Msg = errMsg
  167. }
  168. br.ErrMsg = err.Error()
  169. br.IsSendEmail = isSendEmail
  170. return
  171. }
  172. resp := new(data_manage.AddChartInfoResp)
  173. resp.ChartInfoId = chartInfo.ChartInfoId
  174. resp.UniqueCode = chartInfo.UniqueCode
  175. resp.ChartType = req.ChartType
  176. //新增操作日志
  177. {
  178. chartLog := new(data_manage.ChartInfoLog)
  179. chartLog.ChartInfoId = chartInfo.ChartInfoId
  180. chartLog.ChartName = req.ChartName
  181. chartLog.ChartClassifyId = req.ChartClassifyId
  182. chartLog.SysUserId = sysUser.AdminId
  183. chartLog.SysUserRealName = sysUser.RealName
  184. chartLog.UniqueCode = chartInfo.UniqueCode
  185. chartLog.CreateTime = time.Now()
  186. chartLog.Content = string(this.Ctx.Input.RequestBody)
  187. chartLog.Status = "新增图表"
  188. chartLog.Method = this.Ctx.Input.URI()
  189. go data_manage.AddChartInfoLog(chartLog)
  190. }
  191. // 试用平台更新用户累计新增图表数
  192. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  193. if e != nil {
  194. br.Msg = "操作失败"
  195. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  196. return
  197. }
  198. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  199. go func() {
  200. var r etaTrialService.EtaTrialUserReq
  201. r.Mobile = adminItem.Mobile
  202. _, _ = etaTrialService.UpdateUserChartNum(r)
  203. }()
  204. }
  205. br.Ret = 200
  206. br.Success = true
  207. br.Msg = "保存成功"
  208. br.Data = resp
  209. br.IsAddLog = true
  210. }
  211. // @Title 编辑图表接口
  212. // @Description 编辑图表接口
  213. // @Param request body data_manage.EditChartInfoReq true "type json string"
  214. // @Success Ret=200 保存成功
  215. // @router /chart_info/edit [post]
  216. func (this *ChartInfoController) ChartInfoEdit() {
  217. br := new(models.BaseResponse).Init()
  218. defer func() {
  219. this.Data["json"] = br
  220. this.ServeJSON()
  221. }()
  222. sysUser := this.SysUser
  223. if sysUser == nil {
  224. br.Msg = "请登录"
  225. br.ErrMsg = "请登录,SysUser Is Empty"
  226. br.Ret = 408
  227. return
  228. }
  229. var req data_manage.EditChartInfoReq
  230. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  231. if err != nil {
  232. br.Msg = "参数解析异常!"
  233. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  234. return
  235. }
  236. chartItem, err, errMsg, isSendEmail := data.EditChartInfo(req, sysUser, this.Lang)
  237. if err != nil {
  238. br.Msg = "保存失败"
  239. if errMsg != `` {
  240. br.Msg = errMsg
  241. }
  242. br.ErrMsg = err.Error()
  243. br.IsSendEmail = isSendEmail
  244. return
  245. }
  246. resp := new(data_manage.AddChartInfoResp)
  247. resp.ChartInfoId = chartItem.ChartInfoId
  248. resp.UniqueCode = chartItem.UniqueCode
  249. resp.ChartType = req.ChartType
  250. //新增操作日志
  251. {
  252. chartLog := new(data_manage.ChartInfoLog)
  253. chartLog.ChartName = chartItem.ChartName
  254. chartLog.ChartInfoId = req.ChartInfoId
  255. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  256. chartLog.SysUserId = sysUser.AdminId
  257. chartLog.SysUserRealName = sysUser.RealName
  258. chartLog.UniqueCode = chartItem.UniqueCode
  259. chartLog.CreateTime = time.Now()
  260. chartLog.Content = string(this.Ctx.Input.RequestBody)
  261. chartLog.Status = "编辑图表"
  262. chartLog.Method = this.Ctx.Input.URL()
  263. go data_manage.AddChartInfoLog(chartLog)
  264. }
  265. br.Ret = 200
  266. br.Success = true
  267. br.Msg = "保存成功"
  268. br.Data = resp
  269. br.IsAddLog = true
  270. }
  271. // ChartEnInfoEdit
  272. // @Title 编辑图表英文信息接口
  273. // @Description 编辑图表英文信息接口
  274. // @Param request body data_manage.EditChartEnInfoReq true "type json string"
  275. // @Success Ret=200 编辑成功
  276. // @router /chart_info/en/edit [post]
  277. func (this *ChartInfoController) ChartEnInfoEdit() {
  278. br := new(models.BaseResponse).Init()
  279. defer func() {
  280. this.Data["json"] = br
  281. this.ServeJSON()
  282. }()
  283. sysUser := this.SysUser
  284. if sysUser == nil {
  285. br.Msg = "请登录"
  286. br.ErrMsg = "请登录,SysUser Is Empty"
  287. br.Ret = 408
  288. return
  289. }
  290. var req data_manage.EditChartEnInfoReq
  291. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  292. if err != nil {
  293. br.Msg = "参数解析异常!"
  294. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  295. return
  296. }
  297. req.ChartNameEn = strings.Trim(req.ChartNameEn, " ")
  298. if req.ChartInfoId <= 0 {
  299. br.Msg = "请选择图表"
  300. return
  301. }
  302. //判断指标名称是否存在
  303. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  304. if err != nil {
  305. if err.Error() == utils.ErrNoRow() {
  306. br.Msg = "图表已被删除,请刷新页面"
  307. br.ErrMsg = "图表已被删除,请刷新页面"
  308. return
  309. }
  310. br.Msg = "获取图表信息失败"
  311. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  312. return
  313. }
  314. // 判断是否有传入对应的指标配置
  315. noEdbInfoType := []int{10}
  316. if len(req.ChartEdbInfoList) <= 0 && !utils.InArrayByInt(noEdbInfoType, chartItem.ChartType) {
  317. br.Msg = "请选择指标!"
  318. return
  319. }
  320. var edbCondition string
  321. var edbPars []interface{}
  322. for _, v := range req.ChartEdbInfoList {
  323. edbInfoId := v.EdbInfoId
  324. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  325. if err != nil {
  326. if err.Error() == utils.ErrNoRow() {
  327. br.Msg = "图表不存在!"
  328. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  329. return
  330. } else {
  331. br.Msg = "获取图表信息失败!"
  332. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  333. return
  334. }
  335. }
  336. if edbInfo == nil {
  337. br.Msg = "指标不存在!"
  338. br.ErrMsg = "指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  339. return
  340. }
  341. //判断指标名称是否重复
  342. if v.EdbNameEn != "" {
  343. edbCondition = ""
  344. edbPars = make([]interface{}, 0)
  345. edbCondition += " AND edb_info_id<>? "
  346. edbPars = append(edbPars, edbInfo.EdbInfoId)
  347. /*edbCondition += " AND source=? "
  348. edbPars = append(edbPars, edbInfo.Source)*/
  349. edbCondition += " AND edb_name_en=? "
  350. edbPars = append(edbPars, v.EdbNameEn)
  351. edbExist, err := data_manage.GetEdbInfoByCondition(edbCondition, edbPars)
  352. if err != nil {
  353. if err.Error() != utils.ErrNoRow() {
  354. br.Msg = "判断英文指标名称是否存在失败"
  355. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  356. return
  357. }
  358. }
  359. if err == nil && edbExist.EdbInfoId > 0 {
  360. br.Msg = edbExist.EdbName + ":" + v.EdbNameEn + "指标名称已存在"
  361. br.ErrMsg = "英文指标名称已存在,请重新填写"
  362. br.IsSendEmail = false
  363. return
  364. }
  365. }
  366. }
  367. if req.ChartNameEn != "" || req.ExtraConfig != `` {
  368. var condition string
  369. var pars []interface{}
  370. condition += " AND chart_info_id<>? "
  371. pars = append(pars, req.ChartInfoId)
  372. /*condition += " AND chart_classify_id=? "
  373. pars = append(pars, chartItem.ChartClassifyId)*/
  374. condition += " AND chart_name_en=? "
  375. pars = append(pars, req.ChartNameEn)
  376. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  377. if err != nil {
  378. if err.Error() != utils.ErrNoRow() {
  379. br.Msg = "判断英文图表名称是否存在失败"
  380. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  381. return
  382. }
  383. }
  384. if err == nil && existItem.ChartInfoId > 0 {
  385. br.Msg = existItem.ChartName + ":" + req.ChartNameEn + "图表名称已存在"
  386. return
  387. }
  388. }
  389. err = data_manage.EditChartEnInfoAndEdbEnInfo(&req)
  390. if err != nil {
  391. br.Msg = "保存失败"
  392. br.ErrMsg = "保存失败,Err:" + err.Error()
  393. return
  394. }
  395. //添加es数据
  396. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  397. //修改my eta es数据
  398. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  399. //edbinfo 修改es信息
  400. for _, v := range req.ChartEdbInfoList {
  401. edbInfoId := v.EdbInfoId
  402. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  403. if err != nil {
  404. if err.Error() == utils.ErrNoRow() {
  405. br.Msg = "图表不存在!"
  406. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  407. return
  408. } else {
  409. br.Msg = "获取图表信息失败!"
  410. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  411. return
  412. }
  413. }
  414. if edbInfo != nil {
  415. go data.AddOrEditEdbInfoToEs(edbInfoId)
  416. }
  417. }
  418. //新增操作日志
  419. {
  420. chartLog := new(data_manage.ChartInfoLog)
  421. chartLog.ChartName = chartItem.ChartName
  422. chartLog.ChartInfoId = req.ChartInfoId
  423. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  424. chartLog.SysUserId = sysUser.AdminId
  425. chartLog.SysUserRealName = sysUser.RealName
  426. chartLog.UniqueCode = chartItem.UniqueCode
  427. chartLog.CreateTime = time.Now()
  428. chartLog.Content = string(this.Ctx.Input.RequestBody)
  429. chartLog.Status = "编辑图表英文信息"
  430. chartLog.Method = this.Ctx.Input.URL()
  431. go data_manage.AddChartInfoLog(chartLog)
  432. }
  433. //清除缓存
  434. if utils.Re == nil && utils.Rc != nil {
  435. utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  436. utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  437. }
  438. br.Ret = 200
  439. br.Success = true
  440. br.Msg = "编辑成功"
  441. br.IsAddLog = true
  442. }
  443. // ChartInfoBaseEdit
  444. // @Title 编辑图表基础信息接口
  445. // @Description 编辑图表基础信息接口
  446. // @Param request body data_manage.EditChartEnInfoBaseReq true "type json string"
  447. // @Success Ret=200 编辑成功
  448. // @router /chart_info/base/edit [post]
  449. func (this *ChartInfoController) ChartInfoBaseEdit() {
  450. br := new(models.BaseResponse).Init()
  451. defer func() {
  452. this.Data["json"] = br
  453. this.ServeJSON()
  454. }()
  455. sysUser := this.SysUser
  456. if sysUser == nil {
  457. br.Msg = "请登录"
  458. br.ErrMsg = "请登录,SysUser Is Empty"
  459. br.Ret = 408
  460. return
  461. }
  462. var req data_manage.EditChartInfoBaseReq
  463. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  464. if err != nil {
  465. br.Msg = "参数解析异常!"
  466. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  467. return
  468. }
  469. req.ChartName = strings.Trim(req.ChartName, " ")
  470. if req.ChartInfoId <= 0 {
  471. br.Msg = "请选择图表"
  472. return
  473. }
  474. //判断指标名称是否存在
  475. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  476. if err != nil {
  477. if err.Error() == utils.ErrNoRow() {
  478. br.Msg = "图表已被删除,请刷新页面"
  479. br.ErrMsg = "图表已被删除,请刷新页面"
  480. return
  481. }
  482. br.Msg = "获取图表信息失败"
  483. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  484. return
  485. }
  486. // 判断是否有传入对应的指标配置
  487. noEdbInfoType := []int{10}
  488. if len(req.ChartEdbInfoList) <= 0 && !utils.InArrayByInt(noEdbInfoType, chartItem.ChartType) {
  489. br.Msg = "请选择指标!"
  490. return
  491. }
  492. var edbCondition string
  493. var edbPars []interface{}
  494. for _, v := range req.ChartEdbInfoList {
  495. edbInfoId := v.EdbInfoId
  496. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  497. if err != nil {
  498. if err.Error() == utils.ErrNoRow() {
  499. br.Msg = "图表不存在!"
  500. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  501. return
  502. } else {
  503. br.Msg = "获取图表信息失败!"
  504. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  505. return
  506. }
  507. }
  508. if edbInfo == nil {
  509. br.Msg = "指标不存在!"
  510. br.ErrMsg = "指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  511. return
  512. }
  513. //判断指标名称是否重复
  514. if v.EdbName != "" {
  515. edbCondition = ""
  516. edbPars = make([]interface{}, 0)
  517. edbCondition += " AND edb_info_id<>? "
  518. edbPars = append(edbPars, edbInfo.EdbInfoId)
  519. switch this.Lang {
  520. case utils.EnLangVersion:
  521. edbCondition += " AND edb_name_en =? "
  522. default:
  523. edbCondition += " AND edb_name =? "
  524. }
  525. edbPars = append(edbPars, v.EdbName)
  526. edbExist, err := data_manage.GetEdbInfoByCondition(edbCondition, edbPars)
  527. if err != nil {
  528. if err.Error() != utils.ErrNoRow() {
  529. br.Msg = "判断英文指标名称是否存在失败"
  530. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  531. return
  532. }
  533. }
  534. if err == nil && edbExist.EdbInfoId > 0 {
  535. br.Msg = edbExist.EdbName + ":" + v.EdbName + "指标名称已存在"
  536. br.ErrMsg = "指标名称已存在,请重新填写"
  537. br.IsSendEmail = false
  538. return
  539. }
  540. }
  541. }
  542. if req.ChartName != "" || req.ExtraConfig != `` {
  543. var condition string
  544. var pars []interface{}
  545. condition += " AND chart_info_id<>? "
  546. pars = append(pars, req.ChartInfoId)
  547. switch this.Lang {
  548. case utils.EnLangVersion:
  549. condition += " AND chart_name_en = ? "
  550. default:
  551. condition += " AND chart_name = ? "
  552. }
  553. pars = append(pars, req.ChartName)
  554. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  555. if err != nil {
  556. if err.Error() != utils.ErrNoRow() {
  557. br.Msg = "判断英文图表名称是否存在失败"
  558. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  559. return
  560. }
  561. }
  562. if err == nil && existItem.ChartInfoId > 0 {
  563. br.Msg = existItem.ChartName + ":" + req.ChartName + "图表名称已存在"
  564. return
  565. }
  566. }
  567. err = data_manage.EditChartBaseInfoAndEdbEnInfo(&req, chartItem, this.Lang)
  568. if err != nil {
  569. br.Msg = "保存失败"
  570. br.ErrMsg = "保存失败,Err:" + err.Error()
  571. return
  572. }
  573. //添加es数据
  574. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  575. //修改my eta es数据
  576. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  577. //edbinfo 修改es信息
  578. for _, v := range req.ChartEdbInfoList {
  579. edbInfoId := v.EdbInfoId
  580. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  581. if err != nil {
  582. if err.Error() == utils.ErrNoRow() {
  583. br.Msg = "图表不存在!"
  584. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  585. return
  586. } else {
  587. br.Msg = "获取图表信息失败!"
  588. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  589. return
  590. }
  591. }
  592. if edbInfo != nil {
  593. go data.AddOrEditEdbInfoToEs(edbInfoId)
  594. }
  595. }
  596. //新增操作日志
  597. {
  598. chartLog := new(data_manage.ChartInfoLog)
  599. chartLog.ChartName = chartItem.ChartName
  600. chartLog.ChartInfoId = req.ChartInfoId
  601. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  602. chartLog.SysUserId = sysUser.AdminId
  603. chartLog.SysUserRealName = sysUser.RealName
  604. chartLog.UniqueCode = chartItem.UniqueCode
  605. chartLog.CreateTime = time.Now()
  606. chartLog.Content = string(this.Ctx.Input.RequestBody)
  607. chartLog.Status = "编辑图表英文信息"
  608. chartLog.Method = this.Ctx.Input.URL()
  609. go data_manage.AddChartInfoLog(chartLog)
  610. }
  611. //清除缓存
  612. if utils.Re == nil && utils.Rc != nil {
  613. utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  614. utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  615. }
  616. br.Ret = 200
  617. br.Success = true
  618. br.Msg = "编辑成功"
  619. br.IsAddLog = true
  620. }
  621. // @Title 获取最新图表接口
  622. // @Description 获取最新图表接口
  623. // @Success 200 {object} data_manage.ChartInfoList
  624. // @router /chart_info/newest [get]
  625. func (this *ChartInfoController) ChartInfoNewest() {
  626. br := new(models.BaseResponse).Init()
  627. defer func() {
  628. this.Data["json"] = br
  629. this.ServeJSON()
  630. }()
  631. item, err := data_manage.GetChartInfoByNewest(1)
  632. if err != nil && err.Error() != utils.ErrNoRow() {
  633. br.Msg = "获取最新图表失败"
  634. br.ErrMsg = "获取最新图表失败,Err:" + err.Error()
  635. return
  636. }
  637. br.Ret = 200
  638. br.Success = true
  639. br.Msg = "获取成功"
  640. br.Data = item
  641. }
  642. // ChartInfoMove
  643. // @Title 移动图表接口
  644. // @Description 移动图表接口
  645. // @Success 200 {object} data_manage.MoveChartInfoReq
  646. // @router /chart_info/move [post]
  647. func (this *ChartInfoController) ChartInfoMove() {
  648. br := new(models.BaseResponse).Init()
  649. defer func() {
  650. this.Data["json"] = br
  651. this.ServeJSON()
  652. }()
  653. sysUser := this.SysUser
  654. if sysUser == nil {
  655. br.Msg = "请登录"
  656. br.ErrMsg = "请登录,SysUser Is Empty"
  657. br.Ret = 408
  658. return
  659. }
  660. var req data_manage.MoveChartInfoReq
  661. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  662. if err != nil {
  663. br.Msg = "参数解析异常!"
  664. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  665. return
  666. }
  667. if req.ChartInfoId <= 0 {
  668. br.Msg = "参数错误"
  669. br.ErrMsg = "图表id小于等于0"
  670. return
  671. }
  672. if req.ChartClassifyId <= 0 {
  673. br.Msg = "请选择分类"
  674. return
  675. }
  676. //判断分类是否存在
  677. count, _ := data_manage.GetChartClassifyCountById(req.ChartClassifyId)
  678. if count <= 0 {
  679. br.Msg = "分类已被删除,不可移动,请刷新页面"
  680. return
  681. }
  682. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  683. if err != nil {
  684. br.Msg = "移动失败"
  685. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  686. return
  687. }
  688. if chartInfo.Source != utils.CHART_SOURCE_DEFAULT {
  689. br.Msg = "图表异常"
  690. br.ErrMsg = "分类异常,不是ETA图库的图表"
  691. return
  692. }
  693. // 数据权限校验
  694. {
  695. haveOperaAuth, err := data_manage_permission.CheckChartPermissionByChartInfoId(chartInfo.ChartInfoId, chartInfo.ChartClassifyId, chartInfo.IsJoinPermission, sysUser.AdminId)
  696. if err != nil {
  697. br.Msg = "移动失败"
  698. br.ErrMsg = "获取图表权限失败,Err:" + err.Error()
  699. return
  700. }
  701. if !haveOperaAuth {
  702. br.Msg = "无操作权限"
  703. br.ErrMsg = "无操作权限"
  704. br.IsSendEmail = false
  705. return
  706. }
  707. }
  708. //如果改变了分类,那么移动该图表数据
  709. if chartInfo.ChartClassifyId != req.ChartClassifyId {
  710. //查询需要修改的分类下是否存在同一个图表名称
  711. tmpChartInfo, tmpErr := data_manage.GetChartInfoByClassifyIdAndName(req.ChartClassifyId, chartInfo.ChartName)
  712. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  713. br.Msg = "移动失败"
  714. br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  715. return
  716. }
  717. if tmpChartInfo != nil {
  718. br.Msg = "移动失败,同一个分类下图表名称不允许重复"
  719. br.ErrMsg = "移动失败,同一个分类下图表名称不允许重复"
  720. return
  721. }
  722. err = data_manage.MoveChartInfo(req.ChartInfoId, req.ChartClassifyId)
  723. if err != nil {
  724. br.Msg = "移动失败"
  725. br.ErrMsg = "移动失败,Err:" + err.Error()
  726. return
  727. }
  728. }
  729. //移动排序
  730. updateCol := make([]string, 0)
  731. //如果有传入 上一个兄弟节点分类id
  732. if req.PrevChartInfoId > 0 {
  733. prevChartInfo, err := data_manage.GetChartInfoById(req.PrevChartInfoId)
  734. if err != nil {
  735. br.Msg = "移动失败"
  736. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  737. return
  738. }
  739. //如果是移动在两个兄弟节点之间
  740. if req.NextChartInfoId > 0 {
  741. //下一个兄弟节点
  742. nextChartInfo, err := data_manage.GetChartInfoById(req.NextChartInfoId)
  743. if err != nil {
  744. br.Msg = "移动失败"
  745. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  746. return
  747. }
  748. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  749. if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == chartInfo.Sort {
  750. //变更兄弟节点的排序
  751. updateSortStr := `sort + 2`
  752. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{chartInfo.Source}, updateSortStr)
  753. } else {
  754. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  755. if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  756. //变更兄弟节点的排序
  757. updateSortStr := `sort + 1`
  758. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{chartInfo.Source}, updateSortStr)
  759. }
  760. }
  761. }
  762. chartInfo.Sort = prevChartInfo.Sort + 1
  763. chartInfo.ModifyTime = time.Now()
  764. updateCol = append(updateCol, "Sort", "ModifyTime")
  765. } else {
  766. firstClassify, err := data_manage.GetFirstChartInfoByClassifyId(req.ChartClassifyId)
  767. if err != nil && err.Error() != utils.ErrNoRow() {
  768. br.Msg = "移动失败"
  769. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  770. return
  771. }
  772. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  773. if firstClassify != nil && firstClassify.Sort == 0 {
  774. updateSortStr := ` sort + 1 `
  775. _ = data_manage.UpdateChartInfoSortByClassifyId(firstClassify.ChartClassifyId, 0, firstClassify.ChartInfoId-1, []int{chartInfo.Source}, updateSortStr)
  776. }
  777. chartInfo.Sort = 0 //那就是排在第一位
  778. chartInfo.ModifyTime = time.Now()
  779. updateCol = append(updateCol, "Sort", "ModifyTime")
  780. }
  781. //更新
  782. if len(updateCol) > 0 {
  783. err = chartInfo.Update(updateCol)
  784. if err != nil {
  785. br.Msg = "移动失败"
  786. br.ErrMsg = "修改失败,Err:" + err.Error()
  787. return
  788. }
  789. //添加es数据
  790. go data.EsAddOrEditChartInfo(chartInfo.ChartInfoId)
  791. }
  792. if err != nil {
  793. br.Msg = "移动失败"
  794. br.ErrMsg = "修改失败,Err:" + err.Error()
  795. return
  796. }
  797. //添加es数据
  798. go data.EsAddOrEditChartInfo(req.ChartInfoId)
  799. //修改my eta es数据
  800. go data.EsAddOrEditMyChartInfoByChartInfoId(req.ChartInfoId)
  801. //新增操作日志
  802. {
  803. chartLog := new(data_manage.ChartInfoLog)
  804. chartLog.ChartName = chartInfo.ChartName
  805. chartLog.ChartInfoId = req.ChartInfoId
  806. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  807. chartLog.SysUserId = sysUser.AdminId
  808. chartLog.SysUserRealName = sysUser.RealName
  809. chartLog.UniqueCode = chartInfo.UniqueCode
  810. chartLog.CreateTime = time.Now()
  811. chartLog.Content = string(this.Ctx.Input.RequestBody)
  812. chartLog.Status = "移动图表"
  813. chartLog.Method = this.Ctx.Input.URL()
  814. go data_manage.AddChartInfoLog(chartLog)
  815. }
  816. br.Ret = 200
  817. br.Success = true
  818. br.Msg = "移动成功"
  819. }
  820. // ChartInfoDetail
  821. // @Title 获取图表详情
  822. // @Description 获取图表详情接口
  823. // @Param ChartInfoId query int true "图表id"
  824. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"
  825. // @Param StartDate query string true "自定义开始日期"
  826. // @Param EndDate query string true "自定义结束日期"
  827. // @Param Calendar query string true "公历/农历"
  828. // @Param SeasonStartDate query string true "季节性图开始日期"
  829. // @Param SeasonEndDate query string true "季节性图结束日期"
  830. // @Param EdbInfoId query string true "指标ID,多个用英文逗号隔开"
  831. // @Param ChartType query int true "生成样式:1:曲线图,2:季节性图"
  832. // @Success 200 {object} data_manage.ChartInfoDetailResp
  833. // @router /chart_info/detail [get]
  834. func (this *ChartInfoController) ChartInfoDetail() {
  835. br := new(models.BaseResponse).Init()
  836. defer func() {
  837. this.Data["json"] = br
  838. this.ServeJSON()
  839. }()
  840. sysUser := this.SysUser
  841. if sysUser == nil {
  842. br.Msg = "请登录"
  843. br.ErrMsg = "请登录,SysUser Is Empty"
  844. br.Ret = 408
  845. return
  846. }
  847. chartInfoId, _ := this.GetInt("ChartInfoId")
  848. dateType, _ := this.GetInt("DateType")
  849. fmt.Println("dateType:", dateType)
  850. if dateType <= 0 {
  851. dateType = 3
  852. }
  853. startDate := this.GetString("StartDate")
  854. endDate := this.GetString("EndDate")
  855. startYear, _ := this.GetInt("StartYear")
  856. edbInfoId := this.GetString("EdbInfoId")
  857. chartType, _ := this.GetInt("ChartType")
  858. calendar := this.GetString("Calendar")
  859. if calendar == "" {
  860. calendar = "公历"
  861. }
  862. var err error
  863. chartInfo := new(data_manage.ChartInfoView)
  864. chartInfo.HaveOperaAuth = true
  865. if chartInfoId > 0 {
  866. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  867. if err != nil {
  868. if err.Error() == utils.ErrNoRow() {
  869. br.Msg = "该图表已删除,自动查看下一图表"
  870. br.ErrMsg = "该图表已删除,自动查看下一图表,Err:" + err.Error()
  871. br.Ret = 406
  872. return
  873. }
  874. br.Msg = "获取失败"
  875. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  876. return
  877. }
  878. chartType = chartInfo.ChartType
  879. // 获取主题样式
  880. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  881. if err != nil {
  882. br.Msg = "获取失败"
  883. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  884. return
  885. }
  886. chartInfo.ChartThemeStyle = chartTheme.Config
  887. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  888. // 图表数据权限
  889. {
  890. // 图表分类
  891. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  892. if err != nil {
  893. br.Msg = "获取失败"
  894. br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
  895. return
  896. }
  897. // 已授权分类id
  898. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  899. if err != nil {
  900. br.Msg = "获取失败"
  901. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  902. return
  903. }
  904. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  905. }
  906. }
  907. resp := new(data_manage.ChartInfoDetailResp)
  908. mappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  909. if chartInfoId > 0 {
  910. mappingList, err = data_manage.GetChartEdbMappingList(chartInfoId)
  911. if err != nil {
  912. br.Msg = "获取失败"
  913. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  914. return
  915. }
  916. } else {
  917. if edbInfoId != "" {
  918. mappingList, err = data_manage.GetChartEdbMappingListByEdbInfoId(edbInfoId)
  919. if err != nil {
  920. br.Msg = "获取失败"
  921. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  922. return
  923. }
  924. }
  925. }
  926. // 图表额外数据参数
  927. extraConfigStr := chartInfo.ExtraConfig
  928. // 柱方图的一些配置
  929. var barConfig data_manage.BarChartInfoReq
  930. if chartInfo != nil && chartInfo.ChartType == 7 {
  931. if chartInfo.BarConfig == `` {
  932. br.Msg = "柱方图未配置"
  933. br.ErrMsg = "柱方图未配置"
  934. return
  935. }
  936. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  937. if err != nil {
  938. br.Msg = "柱方图配置异常"
  939. br.ErrMsg = "柱方图配置异常"
  940. return
  941. }
  942. extraConfigStr = chartInfo.BarConfig
  943. }
  944. var dateMax time.Time
  945. if dateType == utils.DateTypeNYears {
  946. for _, v := range mappingList {
  947. if v.LatestDate != "" {
  948. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  949. if tErr != nil {
  950. br.Msg = "获取失败"
  951. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  952. return
  953. }
  954. if lastDateT.After(dateMax) {
  955. dateMax = lastDateT
  956. }
  957. }
  958. }
  959. }
  960. // 开始/结束日期
  961. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
  962. if chartInfo.HaveOperaAuth {
  963. // 获取图表中的指标数据
  964. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  965. if err != nil {
  966. br.Msg = "获取失败"
  967. if errMsg != `` {
  968. br.Msg = errMsg
  969. }
  970. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  971. return
  972. }
  973. // 指标权限
  974. {
  975. classifyMap := make(map[int]*data_manage.EdbClassify)
  976. // 分类
  977. {
  978. classifyIdList := make([]int, 0)
  979. for _, v := range edbList {
  980. classifyIdList = append(classifyIdList, v.ClassifyId)
  981. }
  982. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  983. if tmpErr != nil {
  984. br.Msg = "获取失败"
  985. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  986. return
  987. }
  988. for _, v := range classifyList {
  989. classifyMap[v.ClassifyId] = v
  990. }
  991. }
  992. // 获取所有有权限的指标和分类
  993. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  994. if err != nil {
  995. br.Msg = "获取失败"
  996. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  997. return
  998. }
  999. for _, item := range edbList {
  1000. // 数据权限
  1001. if currClassify, ok := classifyMap[item.ClassifyId]; ok {
  1002. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(item.IsJoinPermission, currClassify.IsJoinPermission, item.EdbInfoId, item.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1003. }
  1004. }
  1005. }
  1006. // 单位
  1007. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  1008. chartInfo.Unit = yDataList[0].Unit
  1009. chartInfo.UnitEn = yDataList[0].UnitEn
  1010. }
  1011. warnEdbList := make([]string, 0)
  1012. for _, v := range edbList {
  1013. if v.IsNullData {
  1014. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1015. }
  1016. }
  1017. if len(warnEdbList) > 0 {
  1018. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1019. }
  1020. if chartInfoId > 0 && chartInfo != nil {
  1021. //判断是否加入我的图库
  1022. {
  1023. var myChartCondition string
  1024. var myChartPars []interface{}
  1025. myChartCondition += ` AND a.admin_id=? `
  1026. myChartPars = append(myChartPars, sysUser.AdminId)
  1027. myChartCondition += ` AND a.chart_info_id=? `
  1028. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1029. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1030. if err != nil && err.Error() != utils.ErrNoRow() {
  1031. br.Msg = "获取失败"
  1032. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1033. return
  1034. }
  1035. if myChartList != nil && len(myChartList) > 0 {
  1036. chartInfo.IsAdd = true
  1037. chartInfo.MyChartId = myChartList[0].MyChartId
  1038. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1039. }
  1040. }
  1041. if chartInfo.ChartType == 2 {
  1042. if chartInfo.SeasonStartDate != "" {
  1043. chartInfo.StartDate = chartInfo.SeasonStartDate
  1044. chartInfo.EndDate = chartInfo.SeasonEndDate
  1045. if chartInfo.DateType == 3 {
  1046. chartInfo.DateType = 5
  1047. }
  1048. }
  1049. }
  1050. }
  1051. // 图表的指标来源
  1052. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1053. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1054. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1055. //判断是否需要展示英文标识
  1056. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  1057. resp.EdbInfoList = edbList
  1058. resp.XEdbIdValue = xEdbIdValue
  1059. resp.YDataList = yDataList
  1060. resp.DataResp = dataResp
  1061. }
  1062. //图表操作权限
  1063. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  1064. chartInfo.Button = data_manage.ChartViewButton{
  1065. IsEdit: chartInfo.IsEdit,
  1066. IsEnChart: chartInfo.IsEnChart,
  1067. IsAdd: chartInfo.IsAdd,
  1068. IsCopy: true,
  1069. IsSetName: chartInfo.IsSetName,
  1070. }
  1071. // 图表当前分类的分类树
  1072. classifyLevels := make([]string, 0)
  1073. {
  1074. list, e := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
  1075. if e != nil {
  1076. br.Msg = "获取失败"
  1077. br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", e)
  1078. return
  1079. }
  1080. parents := data.GetChartClassifyParentRecursive(list, chartInfo.ChartClassifyId)
  1081. sort.Slice(parents, func(i, j int) bool {
  1082. return parents[i].Level < parents[i].Level
  1083. })
  1084. for _, v := range parents {
  1085. classifyLevels = append(classifyLevels, v.UniqueCode)
  1086. }
  1087. }
  1088. resp.ClassifyLevels = classifyLevels
  1089. resp.ChartInfo = chartInfo
  1090. resp.BarChartInfo = barConfig
  1091. br.Ret = 200
  1092. br.Success = true
  1093. br.Msg = "获取成功"
  1094. br.Data = resp
  1095. }
  1096. // PreviewChartInfoDetail
  1097. // @Title 获取图表详情(预览)
  1098. // @Description 获取图表详情接口(预览)
  1099. // @Param request body data_manage.PreviewChartInfoReq true "type json string"
  1100. // @Success 200 {object} data_manage.ChartInfoDetailResp
  1101. // @router /chart_info/detail/preview [post]
  1102. func (this *ChartInfoController) PreviewChartInfoDetail() {
  1103. br := new(models.BaseResponse).Init()
  1104. defer func() {
  1105. this.Data["json"] = br
  1106. this.ServeJSON()
  1107. }()
  1108. sysUser := this.SysUser
  1109. if sysUser == nil {
  1110. br.Msg = "请登录"
  1111. br.ErrMsg = "请登录,SysUser Is Empty"
  1112. br.Ret = 408
  1113. return
  1114. }
  1115. var req data_manage.PreviewChartInfoReq
  1116. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1117. if err != nil {
  1118. br.Msg = "参数解析异常!"
  1119. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1120. return
  1121. }
  1122. if req.DateType <= 0 {
  1123. req.DateType = 3
  1124. }
  1125. // edbInfoId 指标id
  1126. if len(req.ChartEdbInfoList) <= 0 {
  1127. br.Msg = "请选择指标"
  1128. br.ErrMsg = "指标为空"
  1129. br.IsSendEmail = false
  1130. return
  1131. }
  1132. calendar := req.Calendar
  1133. if calendar == "" {
  1134. calendar = "公历"
  1135. }
  1136. chartInfo := new(data_manage.ChartInfoView)
  1137. chartInfo.ChartType = req.ChartType
  1138. edbInfoIdList := make([]int, 0)
  1139. edbInfoIdMapping := make(map[int]*data_manage.ChartSaveItem)
  1140. for _, v := range req.ChartEdbInfoList {
  1141. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  1142. edbInfoIdMapping[v.EdbInfoId] = v
  1143. }
  1144. // 区分是否是来自平衡表图表的数据
  1145. var chartInfoDataShow data.ChartInfoDataShow
  1146. if req.ChartSource == utils.CHART_SOURCE_BALANCE_EXCEL { //来自平衡表图表的数据
  1147. excelChartInfoDataShow := new(data.ExcelChartInfoDataShow)
  1148. // 相关联指标
  1149. mappingListTmp, dataListMap, err, errMsg := excel.GetBalanceExcelChartSingle(chartInfo.ChartInfoId, req.ChartEdbInfoList[0].EdbInfoId, "")
  1150. if err != nil {
  1151. br.Msg = errMsg
  1152. br.ErrMsg = err.Error()
  1153. return
  1154. }
  1155. excelChartInfoDataShow.DataListMap = dataListMap
  1156. excelChartInfoDataShow.MappingListTmp = mappingListTmp
  1157. chartInfoDataShow = excelChartInfoDataShow
  1158. } else {
  1159. chartInfoDataShow = &data.BaseChartInfoDataShow{}
  1160. }
  1161. mappingList, err := chartInfoDataShow.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdList)
  1162. if err != nil {
  1163. br.Msg = "获取失败"
  1164. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1165. return
  1166. }
  1167. var dateMax time.Time
  1168. for k, v := range mappingList {
  1169. if tmpV, ok := edbInfoIdMapping[v.EdbInfoId]; ok {
  1170. v.EdbInfoType = tmpV.EdbInfoType
  1171. v.MaxData = tmpV.MaxData
  1172. v.MinData = tmpV.MinData
  1173. v.IsOrder = tmpV.IsOrder
  1174. v.IsAxis = tmpV.IsAxis
  1175. v.EdbInfoType = tmpV.EdbInfoType
  1176. v.LeadValue = tmpV.LeadValue
  1177. v.LeadUnit = tmpV.LeadUnit
  1178. v.ChartStyle = tmpV.ChartStyle
  1179. v.ChartColor = tmpV.ChartColor
  1180. v.PredictChartColor = tmpV.PredictChartColor
  1181. v.ChartWidth = tmpV.ChartWidth
  1182. //v.Source = tmpV.Source
  1183. // 得到指标更新的最新的年份
  1184. if req.DateType == utils.DateTypeNYears && v.LatestDate != "" {
  1185. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  1186. if tErr != nil {
  1187. br.Msg = "获取失败"
  1188. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  1189. return
  1190. }
  1191. if lastDateT.After(dateMax) {
  1192. dateMax = lastDateT
  1193. }
  1194. }
  1195. }
  1196. if req.ChartEdbInfoList[k].IsConvert == 1 {
  1197. v.IsConvert = 1
  1198. v.ConvertType = req.ChartEdbInfoList[k].ConvertType
  1199. v.ConvertValue = req.ChartEdbInfoList[k].ConvertValue
  1200. v.ConvertUnit = req.ChartEdbInfoList[k].ConvertUnit
  1201. v.ConvertEnUnit = req.ChartEdbInfoList[k].ConvertEnUnit
  1202. }
  1203. mappingList[k] = v
  1204. }
  1205. // 开始/结束日期
  1206. startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, dateMax)
  1207. if startDate == "" {
  1208. br.Msg = "获取失败"
  1209. br.ErrMsg = "获取失败 时间格式错误"
  1210. return
  1211. }
  1212. var seasonExtraConfig string
  1213. if req.ChartType == 2 {
  1214. seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
  1215. if tErr != nil {
  1216. br.Msg = "季节性图表配置信息异常"
  1217. br.ErrMsg = "季节性图表配置信息异常,Err:" + tErr.Error()
  1218. return
  1219. }
  1220. seasonExtraConfig = string(seasonExtra)
  1221. }
  1222. // 图表额外数据参数
  1223. extraConfigStr := chartInfo.ExtraConfig
  1224. // 柱方图的一些配置
  1225. var barConfig data_manage.BarChartInfoReq
  1226. if chartInfo != nil && chartInfo.ChartType == 7 {
  1227. if chartInfo.BarConfig == `` {
  1228. br.Msg = "柱方图未配置"
  1229. br.ErrMsg = "柱方图未配置"
  1230. return
  1231. }
  1232. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  1233. if err != nil {
  1234. br.Msg = "柱方图配置异常"
  1235. br.ErrMsg = "柱方图配置异常"
  1236. return
  1237. }
  1238. extraConfigStr = chartInfo.BarConfig
  1239. } else if chartInfo != nil && chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  1240. extraConfigStr = req.ExtraConfig
  1241. }
  1242. // 获取图表中的指标数据
  1243. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbDataV2(0, req.ChartType, calendar, startDate, endDate, mappingList, extraConfigStr, seasonExtraConfig, chartInfoDataShow)
  1244. if err != nil {
  1245. br.Msg = "获取失败"
  1246. if errMsg != `` {
  1247. br.Msg = errMsg
  1248. }
  1249. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1250. return
  1251. }
  1252. // 单位
  1253. if req.ChartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  1254. chartInfo.Unit = yDataList[0].Unit
  1255. chartInfo.UnitEn = yDataList[0].UnitEn
  1256. }
  1257. warnEdbList := make([]string, 0)
  1258. for _, v := range edbList {
  1259. if v.IsNullData {
  1260. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1261. }
  1262. }
  1263. if len(warnEdbList) > 0 {
  1264. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1265. }
  1266. //图表操作权限
  1267. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  1268. //判断是否需要展示英文标识
  1269. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  1270. chartInfo.Button = data_manage.ChartViewButton{
  1271. IsEdit: chartInfo.IsEdit,
  1272. IsEnChart: chartInfo.IsEnChart,
  1273. IsAdd: chartInfo.IsAdd,
  1274. IsCopy: true,
  1275. IsSetName: chartInfo.IsSetName,
  1276. }
  1277. // 图表的指标来源
  1278. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1279. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1280. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1281. // 标识线计算
  1282. if req.MarkersLines != "" {
  1283. markerLines := make([]data_manage.MarkersLine, 0)
  1284. err = json.Unmarshal([]byte(req.MarkersLines), &markerLines)
  1285. if err != nil {
  1286. br.Msg = "标识线配置异常"
  1287. br.ErrMsg = "标识线配置异常" + err.Error()
  1288. return
  1289. }
  1290. for i := range markerLines {
  1291. if markerLines[i].EdbType == 0 && markerLines[i].TimeIntervalType == 0 && markerLines[i].Axis != 3 {
  1292. // 图上第一个指标且时间区间跟随图表
  1293. if markerLines[i].MarkLineType == 2 {
  1294. if edbList[0].IsAxis == 1 {
  1295. value, err := data.MarkerLineCalculate(markerLines[i], edbList[0].DataList, chartInfo)
  1296. if err != nil {
  1297. br.Msg = "标识线配置异常"
  1298. br.ErrMsg = "标识线配置异常" + err.Error()
  1299. return
  1300. }
  1301. markerLines[i].Value = value
  1302. } else {
  1303. // 其他的都走指标计算
  1304. edbInfo, err := data_manage.GetEdbInfoById(markerLines[i].EdbInfoId)
  1305. if err != nil {
  1306. br.Msg = "指标计算标识线获取指标信息异常"
  1307. br.ErrMsg = "指标计算标识线获取指标信息异常" + err.Error()
  1308. return
  1309. }
  1310. // 判断时间区间不为跟随图表的情况
  1311. if markerLines[i].TimeIntervalType != 0 {
  1312. startDate = markerLines[i].StartDate.Date
  1313. endDate = markerLines[i].EndDate.Date
  1314. }
  1315. dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, startDate, endDate)
  1316. if err != nil {
  1317. br.Msg = "指标计算标识线获取指标数据异常"
  1318. br.ErrMsg = "指标计算标识线获取指标数据异常" + err.Error()
  1319. return
  1320. }
  1321. value, err := data.MarkerLineCalculate(markerLines[i], dataList, chartInfo)
  1322. if err != nil {
  1323. br.Msg = "标识线配置异常"
  1324. br.ErrMsg = "标识线配置异常" + err.Error()
  1325. return
  1326. }
  1327. markerLines[i].Value = value
  1328. }
  1329. }
  1330. }
  1331. }
  1332. markerLineStr, err := json.Marshal(markerLines)
  1333. if err != nil {
  1334. br.Msg = "标识线配置异常"
  1335. br.ErrMsg = "标识线配置异常" + err.Error()
  1336. return
  1337. }
  1338. chartInfo.MarkersLines = string(markerLineStr)
  1339. }
  1340. resp := new(data_manage.ChartInfoDetailResp)
  1341. resp.ChartInfo = chartInfo
  1342. resp.EdbInfoList = edbList
  1343. resp.XEdbIdValue = xEdbIdValue
  1344. resp.YDataList = yDataList
  1345. resp.BarChartInfo = barConfig
  1346. resp.DataResp = dataResp
  1347. br.Ret = 200
  1348. br.Success = true
  1349. br.Msg = "获取成功"
  1350. br.Data = resp
  1351. }
  1352. // ChartInfoDetailV2
  1353. // @Title 获取图表详情
  1354. // @Description 获取图表详情接口
  1355. // @Param ChartInfoId query int true "图表id"
  1356. // @Success 200 {object} data_manage.ChartInfoDetailResp
  1357. // @router /chart_info/detail/v2 [get]
  1358. func (this *ChartInfoController) ChartInfoDetailV2() {
  1359. br := new(models.BaseResponse).Init()
  1360. defer func() {
  1361. this.Data["json"] = br
  1362. this.ServeJSON()
  1363. }()
  1364. sysUser := this.SysUser
  1365. if sysUser == nil {
  1366. br.Msg = "请登录"
  1367. br.ErrMsg = "请登录,SysUser Is Empty"
  1368. br.Ret = 408
  1369. return
  1370. }
  1371. chartInfoId, _ := this.GetInt("ChartInfoId")
  1372. //startDate = strconv.Itoa(time.Now().Year()) + "-01-01"
  1373. if chartInfoId <= 0 {
  1374. br.Msg = "请选择图表"
  1375. br.IsSendEmail = false
  1376. return
  1377. }
  1378. chartInfo, err := data_manage.GetChartInfoViewById(chartInfoId)
  1379. if err != nil {
  1380. if err.Error() == utils.ErrNoRow() {
  1381. br.Msg = "该图表已删除,自动查看下一图表"
  1382. br.ErrMsg = "该图表已删除,自动查看下一图表,Err:" + err.Error()
  1383. br.Ret = 406
  1384. return
  1385. }
  1386. br.Msg = "获取失败"
  1387. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1388. return
  1389. }
  1390. resp := new(data_manage.ChartInfoDetailResp)
  1391. // 图表数据权限
  1392. {
  1393. // 图表分类
  1394. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  1395. if err != nil {
  1396. br.Msg = "获取失败"
  1397. br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
  1398. return
  1399. }
  1400. // 已授权分类id
  1401. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  1402. if err != nil {
  1403. br.Msg = "获取失败"
  1404. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1405. return
  1406. }
  1407. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1408. }
  1409. // 获取主题样式
  1410. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  1411. if err != nil {
  1412. br.Msg = "获取失败"
  1413. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  1414. return
  1415. }
  1416. chartInfo.ChartThemeStyle = chartTheme.Config
  1417. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  1418. dateType := chartInfo.DateType
  1419. fmt.Println("dateType:", dateType)
  1420. chartType := chartInfo.ChartType
  1421. startDate := chartInfo.StartDate
  1422. endDate := chartInfo.EndDate
  1423. seasonStartDate := chartInfo.SeasonStartDate
  1424. seasonEndDate := chartInfo.SeasonEndDate
  1425. startYear := chartInfo.StartYear
  1426. calendar := chartInfo.Calendar
  1427. if calendar == "" {
  1428. calendar = "公历"
  1429. }
  1430. // 相关联指标
  1431. mappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  1432. if err != nil {
  1433. br.Msg = "获取失败"
  1434. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1435. return
  1436. }
  1437. if chartType == 2 {
  1438. startDate = seasonStartDate
  1439. endDate = seasonEndDate
  1440. if dateType <= 0 {
  1441. if startDate != "" {
  1442. dateType = 5
  1443. } else {
  1444. dateType = utils.DateTypeNYears
  1445. }
  1446. }
  1447. } else {
  1448. if dateType <= 0 {
  1449. dateType = 3
  1450. }
  1451. }
  1452. var dateMax time.Time
  1453. if dateType == utils.DateTypeNYears {
  1454. for _, v := range mappingList {
  1455. if v.LatestDate != "" {
  1456. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  1457. if tErr != nil {
  1458. br.Msg = "获取失败"
  1459. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  1460. return
  1461. }
  1462. if lastDateT.After(dateMax) {
  1463. dateMax = lastDateT
  1464. }
  1465. }
  1466. }
  1467. }
  1468. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
  1469. if chartInfo.ChartType == 2 {
  1470. chartInfo.StartDate = startDate
  1471. chartInfo.EndDate = endDate
  1472. }
  1473. // 图表额外数据参数
  1474. extraConfigStr := chartInfo.ExtraConfig
  1475. // 柱方图的一些配置
  1476. var barConfig data_manage.BarChartInfoReq
  1477. if chartInfo != nil && chartInfo.ChartType == 7 {
  1478. if chartInfo.BarConfig == `` {
  1479. br.Msg = "柱方图未配置"
  1480. br.ErrMsg = "柱方图未配置"
  1481. return
  1482. }
  1483. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  1484. if err != nil {
  1485. br.Msg = "柱方图配置异常"
  1486. br.ErrMsg = "柱方图配置异常"
  1487. return
  1488. }
  1489. extraConfigStr = chartInfo.BarConfig
  1490. }
  1491. if chartInfo.HaveOperaAuth {
  1492. // 获取图表中的指标数据
  1493. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  1494. if err != nil {
  1495. br.Msg = "获取失败"
  1496. if errMsg != `` {
  1497. br.Msg = errMsg
  1498. }
  1499. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1500. return
  1501. }
  1502. // 单位
  1503. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  1504. chartInfo.Unit = yDataList[0].Unit
  1505. chartInfo.UnitEn = yDataList[0].UnitEn
  1506. }
  1507. warnEdbList := make([]string, 0)
  1508. for _, v := range edbList {
  1509. if v.IsNullData {
  1510. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1511. }
  1512. }
  1513. if len(warnEdbList) > 0 {
  1514. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1515. }
  1516. if chartInfoId > 0 && chartInfo != nil {
  1517. //判断是否加入我的图库
  1518. {
  1519. var myChartCondition string
  1520. var myChartPars []interface{}
  1521. myChartCondition += ` AND a.admin_id=? `
  1522. myChartPars = append(myChartPars, sysUser.AdminId)
  1523. myChartCondition += ` AND a.chart_info_id=? `
  1524. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1525. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1526. if err != nil && err.Error() != utils.ErrNoRow() {
  1527. br.Msg = "获取失败"
  1528. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1529. return
  1530. }
  1531. if myChartList != nil && len(myChartList) > 0 {
  1532. chartInfo.IsAdd = true
  1533. chartInfo.MyChartId = myChartList[0].MyChartId
  1534. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1535. }
  1536. }
  1537. }
  1538. //判断是否需要展示英文标识
  1539. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  1540. // 图表的指标来源
  1541. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1542. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1543. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1544. // 指标权限
  1545. {
  1546. classifyMap := make(map[int]*data_manage.EdbClassify)
  1547. // 分类
  1548. {
  1549. classifyIdList := make([]int, 0)
  1550. for _, v := range edbList {
  1551. classifyIdList = append(classifyIdList, v.ClassifyId)
  1552. }
  1553. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  1554. if tmpErr != nil {
  1555. br.Msg = "获取失败"
  1556. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  1557. return
  1558. }
  1559. for _, v := range classifyList {
  1560. classifyMap[v.ClassifyId] = v
  1561. }
  1562. }
  1563. // 获取所有有权限的指标和分类
  1564. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1565. if err != nil {
  1566. br.Msg = "获取失败"
  1567. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  1568. return
  1569. }
  1570. for _, item := range edbList {
  1571. // 数据权限
  1572. if currClassify, ok := classifyMap[item.ClassifyId]; ok {
  1573. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(item.IsJoinPermission, currClassify.IsJoinPermission, item.EdbInfoId, item.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1574. }
  1575. }
  1576. }
  1577. resp.EdbInfoList = edbList
  1578. resp.XEdbIdValue = xEdbIdValue
  1579. resp.YDataList = yDataList
  1580. resp.DataResp = dataResp
  1581. } else {
  1582. resp.EdbInfoList = mappingList
  1583. }
  1584. // 图表当前分类的分类树
  1585. classifyLevels := make([]string, 0)
  1586. {
  1587. list, e := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
  1588. if e != nil {
  1589. br.Msg = "获取失败"
  1590. br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", e)
  1591. return
  1592. }
  1593. parents := data.GetChartClassifyParentRecursive(list, chartInfo.ChartClassifyId)
  1594. sort.Slice(parents, func(i, j int) bool {
  1595. return parents[i].Level < parents[i].Level
  1596. })
  1597. for _, v := range parents {
  1598. classifyLevels = append(classifyLevels, v.UniqueCode)
  1599. }
  1600. }
  1601. resp.ClassifyLevels = classifyLevels
  1602. //图表操作权限
  1603. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  1604. chartInfo.Button = data_manage.ChartViewButton{
  1605. IsEdit: chartInfo.IsEdit,
  1606. IsEnChart: chartInfo.IsEnChart,
  1607. IsAdd: chartInfo.IsAdd,
  1608. IsCopy: true,
  1609. IsSetName: chartInfo.IsSetName,
  1610. }
  1611. resp.ChartInfo = chartInfo
  1612. resp.BarChartInfo = barConfig
  1613. br.Ret = 200
  1614. br.Success = true
  1615. br.Msg = "获取成功"
  1616. br.Data = resp
  1617. }
  1618. // @Title 图表指标模糊搜索
  1619. // @Description 图表指标模糊搜索接口
  1620. // @Param KeyWord query string true "指标名称/ID"
  1621. // @Success 200 {object} data_manage.ChartEdbInfo
  1622. // @router /chart_info/edb_info/search [get]
  1623. func (this *ChartInfoController) ChartInfoEdbInfoSearch() {
  1624. br := new(models.BaseResponse).Init()
  1625. defer func() {
  1626. this.Data["json"] = br
  1627. this.ServeJSON()
  1628. }()
  1629. sysUser := this.SysUser
  1630. if sysUser == nil {
  1631. br.Msg = "请登录"
  1632. br.ErrMsg = "请登录,SysUser Is Empty"
  1633. br.Ret = 408
  1634. return
  1635. }
  1636. KeyWord := this.GetString("KeyWord")
  1637. //if KeyWord == "" {
  1638. // br.Msg = "请输入指标名称/指标ID"
  1639. // return
  1640. //}
  1641. var err error
  1642. searchList := make([]*data_manage.ChartEdbInfo, 0)
  1643. searchList, err = data_manage.EdbInfoSearchByKeyWord(KeyWord)
  1644. if err != nil {
  1645. br.Msg = "获取失败"
  1646. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1647. return
  1648. }
  1649. if searchList == nil {
  1650. searchList = make([]*data_manage.ChartEdbInfo, 0)
  1651. }
  1652. lenSearchList := len(searchList)
  1653. for i := 0; i < lenSearchList; i++ {
  1654. searchList[i].EdbNameAlias = searchList[i].EdbName
  1655. }
  1656. for i := 0; i < lenSearchList; i++ {
  1657. for j := 0; j < lenSearchList; j++ {
  1658. if (searchList[i].EdbNameAlias == searchList[j].EdbNameAlias) &&
  1659. (searchList[i].EdbInfoId != searchList[j].EdbInfoId) &&
  1660. !(strings.Contains(searchList[i].EdbName, searchList[i].SourceName)) {
  1661. searchList[i].EdbName = searchList[i].EdbName + "(" + searchList[i].SourceName + ")"
  1662. }
  1663. }
  1664. }
  1665. br.Ret = 200
  1666. br.Success = true
  1667. br.Msg = "获取成功"
  1668. br.Data = searchList
  1669. }
  1670. // @Title 图表-获取指标详情
  1671. // @Description 图表-获取指标详情接口
  1672. // @Param EdbInfoId query int true "指标ID"
  1673. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今"
  1674. // @Param StartDate query string true "自定义开始日期"
  1675. // @Param EndDate query string true "自定义结束日期"
  1676. // @Param EdbInfoType query int true "1:标准指标,0:领先指标,默认为标准指标"
  1677. // @Param LeadValue query int true "领先值"
  1678. // @Param LeadUnit query string true "领先单位:天,月,季,周"
  1679. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  1680. // @router /chart_info/edb_info/detail [get]
  1681. func (this *ChartInfoController) ChartInfoEdbInfoDetail() {
  1682. br := new(models.BaseResponse).Init()
  1683. defer func() {
  1684. this.Data["json"] = br
  1685. this.ServeJSON()
  1686. }()
  1687. sysUser := this.SysUser
  1688. if sysUser == nil {
  1689. br.Msg = "请登录"
  1690. br.ErrMsg = "请登录,SysUser Is Empty"
  1691. br.Ret = 408
  1692. return
  1693. }
  1694. edbInfoId, _ := this.GetInt("EdbInfoId")
  1695. if edbInfoId <= 0 {
  1696. br.Msg = "参数错误"
  1697. return
  1698. }
  1699. dateType, _ := this.GetInt("DateType")
  1700. if dateType <= 0 {
  1701. dateType = 3
  1702. }
  1703. edbInfoType, _ := this.GetInt("EdbInfoType")
  1704. if edbInfoType < 0 {
  1705. edbInfoType = 1
  1706. }
  1707. leadValue, _ := this.GetInt("LeadValue")
  1708. if leadValue < 0 {
  1709. leadValue = 0
  1710. }
  1711. leadUnit := this.GetString("LeadUnit")
  1712. startDate := this.GetString("StartDate")
  1713. endDate := this.GetString("EndDate")
  1714. startYear, _ := this.GetInt("StartYear")
  1715. isTimeBetween := false //是否是时间区间
  1716. if dateType == 5 {
  1717. isTimeBetween = true
  1718. }
  1719. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1720. if err != nil {
  1721. br.Msg = "获取失败"
  1722. br.Msg = "获取失败,Err:" + err.Error()
  1723. return
  1724. }
  1725. var maxDate time.Time
  1726. if edbInfo.LatestDate != "" {
  1727. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  1728. maxDate = latestDateT
  1729. }
  1730. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxDate)
  1731. if startDate == "" {
  1732. br.Msg = "参数错误"
  1733. br.Msg = "参数错误,无效的查询日期"
  1734. return
  1735. }
  1736. var startDateReal string
  1737. var diffSeconds int64
  1738. if leadValue > 0 && leadUnit != "" {
  1739. var startTimeRealTemp time.Time
  1740. startDateParse, err := time.Parse(utils.FormatDate, startDate)
  1741. if err != nil {
  1742. br.Msg = "获取数据失败"
  1743. br.ErrMsg = "获取数据失败,日期格式错误:startDate:" + startDate
  1744. return
  1745. }
  1746. switch leadUnit {
  1747. case "天":
  1748. startTimeRealTemp = startDateParse.AddDate(0, 0, -leadValue)
  1749. case "月":
  1750. startTimeRealTemp = startDateParse.AddDate(0, -leadValue, 0)
  1751. case "季":
  1752. startTimeRealTemp = startDateParse.AddDate(0, -3*leadValue, 0)
  1753. case "周":
  1754. startTimeRealTemp = startDateParse.AddDate(0, 0, -7*leadValue)
  1755. case "年":
  1756. startTimeRealTemp = startDateParse.AddDate(-leadValue, 0, 0)
  1757. }
  1758. if startTimeRealTemp.Before(startDateParse) {
  1759. startDateReal = startTimeRealTemp.Format(utils.FormatDate)
  1760. diffSeconds = (int64(startTimeRealTemp.UnixNano()) - int64(startDateParse.UnixNano())) / 1e6
  1761. } else {
  1762. startDateReal = startDate
  1763. diffSeconds = 0
  1764. }
  1765. } else {
  1766. startDateReal = startDate
  1767. }
  1768. var dataList []*data_manage.EdbDataList
  1769. var minData, maxData float64
  1770. switch edbInfo.EdbInfoType {
  1771. case 0: //普通源指标
  1772. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDateReal, endDate)
  1773. if err != nil {
  1774. br.Msg = "获取失败"
  1775. br.Msg = "获取失败,Err:" + err.Error()
  1776. return
  1777. }
  1778. //查询区间内最大最小值
  1779. minData, maxData, err = data_manage.GetEdbDataListMinAndMax(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDateReal, endDate)
  1780. if err != nil {
  1781. br.Msg = "获取失败"
  1782. br.Msg = "获取指标最新的最大最小值失败,Err:" + err.Error()
  1783. return
  1784. }
  1785. case 1: //预测指标
  1786. tmpDataList, sourceEdbInfoItem, _, err, _ := data.GetPredictDataListByPredictEdbInfo(edbInfo, startDateReal, endDate, isTimeBetween)
  1787. if err != nil {
  1788. br.Msg = "获取失败"
  1789. br.Msg = "获取失败,Err:" + err.Error()
  1790. return
  1791. }
  1792. dataList = tmpDataList
  1793. // 有预测数据,且为普通的预测指标
  1794. if len(dataList) > 0 && edbInfo.EdbInfoType == 0 {
  1795. //查询区间内最大最小值
  1796. minData, maxData, err = data_manage.GetEdbDataListMinAndMax(sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, sourceEdbInfoItem.EdbInfoId, startDateReal, endDate)
  1797. if err != nil {
  1798. br.Msg = "获取失败"
  1799. br.Msg = "获取指标最新的最大最小值失败,Err:" + err.Error()
  1800. return
  1801. }
  1802. tmpValue := dataList[len(dataList)-1]
  1803. // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
  1804. if edbInfo.MaxValue < tmpValue.Value {
  1805. maxData = tmpValue.Value
  1806. }
  1807. // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
  1808. if edbInfo.MinValue > tmpValue.Value {
  1809. minData = tmpValue.Value
  1810. }
  1811. }
  1812. }
  1813. moveLatestDate := edbInfo.LatestDate
  1814. if diffSeconds != 0 {
  1815. dataListLen := len(dataList)
  1816. for i := 0; i < dataListLen; i++ {
  1817. dataList[i].DataTimestamp = dataList[i].DataTimestamp - diffSeconds
  1818. }
  1819. day, err := utils.GetDaysBetween2Date(utils.FormatDate, startDate, startDateReal)
  1820. if err != nil {
  1821. br.Msg = "获取失败"
  1822. br.Msg = "获取领先滞后的的日期间隔失败,Err:" + err.Error()
  1823. return
  1824. }
  1825. moveLatestDateTime, err := time.ParseInLocation(utils.FormatDate, moveLatestDate, time.Local)
  1826. if err != nil {
  1827. br.Msg = "获取失败"
  1828. br.Msg = "指标日期转换失败,Err:" + err.Error()
  1829. return
  1830. }
  1831. moveLatestDate = moveLatestDateTime.AddDate(0, 0, day).Format(utils.FormatDate)
  1832. }
  1833. mapping := new(data_manage.ChartEdbInfoMapping)
  1834. mapping.EdbInfoId = edbInfo.EdbInfoId
  1835. mapping.EdbInfoCategoryType = edbInfo.EdbInfoType
  1836. mapping.SourceName = edbInfo.SourceName
  1837. mapping.Source = edbInfo.Source
  1838. mapping.EdbCode = edbInfo.EdbCode
  1839. mapping.EdbName = edbInfo.EdbName
  1840. mapping.EdbType = edbInfo.EdbType
  1841. mapping.Frequency = edbInfo.Frequency
  1842. mapping.Unit = edbInfo.Unit
  1843. mapping.StartDate = edbInfo.StartDate
  1844. mapping.EndDate = edbInfo.EndDate
  1845. mapping.ChartEdbMappingId = 0
  1846. mapping.ChartInfoId = 0
  1847. mapping.MaxData = maxData
  1848. mapping.MinData = minData
  1849. mapping.IsOrder = false
  1850. mapping.IsAxis = 1
  1851. mapping.EdbInfoType = 1
  1852. mapping.LeadValue = 0
  1853. mapping.LeadUnit = ""
  1854. mapping.LeadUnitEn = ""
  1855. mapping.ChartStyle = ""
  1856. mapping.ChartColor = ""
  1857. mapping.PredictChartColor = ""
  1858. mapping.ChartWidth = 0
  1859. mapping.LatestDate = edbInfo.LatestDate
  1860. mapping.MoveLatestDate = moveLatestDate
  1861. mapping.DataList = dataList
  1862. resp := new(data_manage.ChartEdbInfoDetailResp)
  1863. resp.EdbInfo = mapping
  1864. br.Ret = 200
  1865. br.Success = true
  1866. br.Msg = "获取成功"
  1867. br.Data = resp
  1868. }
  1869. // ChartInfoSearch
  1870. // @Title 图表模糊搜索
  1871. // @Description 图表模糊搜索接口
  1872. // @Param KeyWord query string true "图表名称"
  1873. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1874. // @Success 200 {object} data_manage.ChartInfo
  1875. // @router /chart_info/search [get]
  1876. func (this *ChartInfoController) ChartInfoSearch() {
  1877. br := new(models.BaseResponse).Init()
  1878. defer func() {
  1879. this.Data["json"] = br
  1880. this.ServeJSON()
  1881. }()
  1882. sysUser := this.SysUser
  1883. if sysUser == nil {
  1884. br.Msg = "请登录"
  1885. br.ErrMsg = "请登录,SysUser Is Empty"
  1886. br.Ret = 408
  1887. return
  1888. }
  1889. keyWord := this.GetString("KeyWord")
  1890. searchList := make([]data_manage.ChartInfoMore, 0)
  1891. //var err error
  1892. //if KeyWord == "" {
  1893. // searchList, err = data_manage.ChartInfoSearchByKeyWord(KeyWord)
  1894. // if err != nil && err.Error() != utils.ErrNoRow() {
  1895. // br.Msg = "获取失败"
  1896. // br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1897. // return
  1898. // }
  1899. //} else {
  1900. // searchList, err = data.EsSearchChartInfo(KeyWord)
  1901. // if err != nil && err.Error() != utils.ErrNoRow() {
  1902. // br.Msg = "获取失败"
  1903. // br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1904. // return
  1905. // }
  1906. //}
  1907. //只看我的
  1908. isShowMe, _ := this.GetBool("IsShowMe")
  1909. showSysId := 0
  1910. if isShowMe {
  1911. showSysId = sysUser.AdminId
  1912. }
  1913. var keyWordArr []string
  1914. keyWordArr = append(keyWordArr, keyWord)
  1915. if keyWord != "" {
  1916. newKeyWord := strings.Split(keyWord, " ")
  1917. keyWordArr = append(keyWordArr, newKeyWord...)
  1918. }
  1919. existMap := make(map[int]string)
  1920. for _, v := range keyWordArr {
  1921. v = strings.Replace(v, " ", "%", -1)
  1922. newSearchList, err := data_manage.ChartInfoSearchByKeyWord(v, showSysId)
  1923. if err != nil && err.Error() != utils.ErrNoRow() {
  1924. br.Msg = "获取失败"
  1925. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1926. return
  1927. }
  1928. for _, nv := range newSearchList {
  1929. if _, ok := existMap[nv.ChartInfoId]; !ok {
  1930. searchList = append(searchList, data_manage.ChartInfoMore{
  1931. ChartInfo: *nv,
  1932. })
  1933. }
  1934. existMap[nv.ChartInfoId] = nv.ChartName
  1935. }
  1936. }
  1937. if searchList == nil {
  1938. searchList = make([]data_manage.ChartInfoMore, 0)
  1939. }
  1940. // 数据权限
  1941. if len(searchList) > 0 {
  1942. // 涉及分类id
  1943. classifyIdList := make([]int, 0)
  1944. for _, v := range searchList {
  1945. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1946. }
  1947. // 图表分类
  1948. chartClassifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1949. if err != nil {
  1950. br.Msg = "获取失败"
  1951. br.ErrMsg = "获取图表分类失败,Err:" + err.Error()
  1952. return
  1953. }
  1954. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  1955. for _, v := range chartClassifyList {
  1956. chartClassifyMap[v.ChartClassifyId] = v
  1957. }
  1958. // 已授权图表和分类id
  1959. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1960. if err != nil {
  1961. br.Msg = "获取失败"
  1962. br.ErrMsg = "已授权图表和分类id失败,Err:" + err.Error()
  1963. return
  1964. }
  1965. // 权限判断
  1966. for k, v := range searchList {
  1967. if currClassify, ok := chartClassifyMap[v.ChartClassifyId]; ok {
  1968. searchList[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1969. }
  1970. }
  1971. }
  1972. //新增搜索词记录
  1973. {
  1974. searchKeyword := new(data_manage.SearchKeyword)
  1975. searchKeyword.KeyWord = keyWord
  1976. searchKeyword.CreateTime = time.Now()
  1977. go data_manage.AddSearchKeyword(searchKeyword)
  1978. }
  1979. br.Ret = 200
  1980. br.Success = true
  1981. br.Msg = "获取成功"
  1982. br.Data = searchList
  1983. }
  1984. // ChartInfoSearchByEs
  1985. // @Title 图表模糊搜索(从es获取)
  1986. // @Description 图表模糊搜索(从es获取)
  1987. // @Param Keyword query string true "图表名称"
  1988. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1989. // @Success 200 {object} data_manage.ChartInfo
  1990. // @router /chart_info/search_by_es [get]
  1991. func (this *ChartInfoController) ChartInfoSearchByEs() {
  1992. br := new(models.BaseResponse).Init()
  1993. defer func() {
  1994. this.Data["json"] = br
  1995. this.ServeJSON()
  1996. }()
  1997. sysUser := this.SysUser
  1998. if sysUser == nil {
  1999. br.Msg = "请登录"
  2000. br.ErrMsg = "请登录,SysUser Is Empty"
  2001. br.Ret = 408
  2002. return
  2003. }
  2004. pageSize, _ := this.GetInt("PageSize")
  2005. currentIndex, _ := this.GetInt("CurrentIndex")
  2006. var startSize int
  2007. if pageSize <= 0 {
  2008. pageSize = utils.PageSize20
  2009. }
  2010. if currentIndex <= 0 {
  2011. currentIndex = 1
  2012. }
  2013. startSize = paging.StartIndex(currentIndex, pageSize)
  2014. keyword := this.GetString("Keyword")
  2015. //只看我的
  2016. isShowMe, _ := this.GetBool("IsShowMe")
  2017. showSysId := 0
  2018. if isShowMe {
  2019. showSysId = sysUser.AdminId
  2020. }
  2021. var searchList []*data_manage.ChartInfo
  2022. var total int64
  2023. var err error
  2024. // 获取当前账号的不可见指标
  2025. noPermissionChartIdList := make([]int, 0)
  2026. {
  2027. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2028. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  2029. if err != nil && err.Error() != utils.ErrNoRow() {
  2030. br.Msg = "获取失败"
  2031. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  2032. return
  2033. }
  2034. for _, v := range confList {
  2035. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  2036. }
  2037. }
  2038. // 是否走ES
  2039. isEs := false
  2040. if keyword != "" {
  2041. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize)
  2042. isEs = true
  2043. } else {
  2044. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize)
  2045. if err != nil && err.Error() != utils.ErrNoRow() {
  2046. br.Msg = "获取失败"
  2047. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2048. return
  2049. }
  2050. }
  2051. finalList := make([]*data_manage.ChartInfoMore, 0)
  2052. if len(searchList) > 0 {
  2053. // 涉及分类id
  2054. classifyIdList := make([]int, 0)
  2055. // 图表id
  2056. chartInfoIdList := make([]int, 0)
  2057. chartInfoIds := ""
  2058. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  2059. for _, v := range searchList {
  2060. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  2061. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  2062. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  2063. }
  2064. if chartInfoIds != "" {
  2065. chartInfoIds = strings.Trim(chartInfoIds, ",")
  2066. //判断是否需要展示英文标识
  2067. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  2068. if e != nil {
  2069. br.Msg = "获取失败"
  2070. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  2071. return
  2072. }
  2073. for _, v := range edbList {
  2074. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  2075. }
  2076. }
  2077. // 当前列表中的分类map
  2078. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  2079. // 图表分类
  2080. {
  2081. chartClassifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  2082. if err != nil {
  2083. br.Msg = "获取失败"
  2084. br.ErrMsg = "获取图表分类失败,Err:" + err.Error()
  2085. return
  2086. }
  2087. for _, v := range chartClassifyList {
  2088. chartClassifyMap[v.ChartClassifyId] = v
  2089. }
  2090. }
  2091. // 图表
  2092. if isEs {
  2093. // 当前列表中的图表map
  2094. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  2095. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  2096. if err != nil {
  2097. br.Msg = "获取失败"
  2098. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  2099. return
  2100. }
  2101. for _, tmpChartInfo := range tmpChartList {
  2102. chartInfoMap[tmpChartInfo.ChartInfoId] = tmpChartInfo
  2103. }
  2104. for _, v := range searchList {
  2105. // 图表权限
  2106. chartViewInfo, ok := chartInfoMap[v.ChartInfoId]
  2107. if !ok {
  2108. continue
  2109. }
  2110. v.IsJoinPermission = chartViewInfo.IsJoinPermission
  2111. }
  2112. }
  2113. // 已授权图表和分类id
  2114. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  2115. if err != nil {
  2116. br.Msg = "获取失败"
  2117. br.ErrMsg = "已授权图表和分类id失败,Err:" + err.Error()
  2118. return
  2119. }
  2120. for _, v := range searchList {
  2121. tmp := new(data_manage.ChartInfoMore)
  2122. tmp.ChartInfo = *v
  2123. //判断是否需要展示英文标识
  2124. if edbTmpList, ok := chartEdbMap[v.ChartInfoId]; ok {
  2125. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, edbTmpList, v.Source, v.ChartType)
  2126. }
  2127. // 图表权限
  2128. if currClassify, ok := chartClassifyMap[v.ChartClassifyId]; ok {
  2129. tmp.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  2130. }
  2131. finalList = append(finalList, tmp)
  2132. }
  2133. }
  2134. //新增搜索词记录
  2135. {
  2136. searchKeyword := new(data_manage.SearchKeyword)
  2137. searchKeyword.KeyWord = keyword
  2138. searchKeyword.CreateTime = time.Now()
  2139. go data_manage.AddSearchKeyword(searchKeyword)
  2140. }
  2141. page := paging.GetPaging(currentIndex, pageSize, int(total))
  2142. resp := data_manage.ChartInfoListByEsResp{
  2143. Paging: page,
  2144. List: finalList,
  2145. }
  2146. br.Ret = 200
  2147. br.Success = true
  2148. br.Msg = "获取成功"
  2149. br.Data = resp
  2150. }
  2151. // @Title 图表刷新接口
  2152. // @Description 图表刷新接口
  2153. // @Param ChartInfoId query int true "图表id"
  2154. // @Param UniqueCode query string true "唯一code"
  2155. // @Success Ret=200 刷新成功
  2156. // @router /chart_info/refresh [get]
  2157. func (this *EdbInfoController) ChartInfoRefresh() {
  2158. br := new(models.BaseResponse).Init()
  2159. defer func() {
  2160. this.Data["json"] = br
  2161. this.ServeJSON()
  2162. }()
  2163. sysUser := this.SysUser
  2164. if sysUser == nil {
  2165. br.Msg = "请登录"
  2166. br.ErrMsg = "请登录,SysUser Is Empty"
  2167. br.Ret = 408
  2168. return
  2169. }
  2170. chartInfoId, _ := this.GetInt("ChartInfoId")
  2171. uniqueCode := this.GetString("UniqueCode")
  2172. if chartInfoId <= 0 && uniqueCode == `` {
  2173. br.Msg = "参数错误"
  2174. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  2175. return
  2176. }
  2177. var chartInfo *data_manage.ChartInfo
  2178. var err error
  2179. if chartInfoId > 0 {
  2180. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  2181. } else {
  2182. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  2183. }
  2184. if err != nil {
  2185. if err.Error() == utils.ErrNoRow() {
  2186. br.Msg = "图表已被删除,无需刷新"
  2187. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2188. return
  2189. }
  2190. br.Msg = "刷新失败"
  2191. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2192. return
  2193. }
  2194. err, isAsync := data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  2195. if err != nil {
  2196. br.Msg = "刷新失败"
  2197. br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  2198. return
  2199. }
  2200. /*
  2201. //err = data.ChartInfoRefresh(chartInfo.ChartInfoId)
  2202. //if err != nil {
  2203. // br.Msg = "刷新失败"
  2204. // br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  2205. // return
  2206. //}
  2207. */
  2208. //清除图表缓存
  2209. {
  2210. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  2211. _ = utils.Rc.Delete(key)
  2212. }
  2213. br.Ret = 200
  2214. br.Success = true
  2215. br.Msg = "刷新成功"
  2216. if isAsync {
  2217. br.Msg = "图表关联指标较多,请10分钟后刷新页面查看最新数据"
  2218. }
  2219. }
  2220. // @Title 设置图表图片
  2221. // @Description 设置图表图片接口
  2222. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  2223. // @Success Ret=200 保存成功
  2224. // @router /chart_info/image/set [post]
  2225. func (this *ChartInfoController) ChartInfoImageSet() {
  2226. br := new(models.BaseResponse).Init()
  2227. defer func() {
  2228. this.Data["json"] = br
  2229. this.ServeJSON()
  2230. }()
  2231. sysUser := this.SysUser
  2232. if sysUser == nil {
  2233. br.Msg = "请登录"
  2234. br.ErrMsg = "请登录,SysUser Is Empty"
  2235. br.Ret = 408
  2236. return
  2237. }
  2238. var req data_manage.SetChartInfoImageReq
  2239. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2240. if err != nil {
  2241. br.Msg = "参数解析异常!"
  2242. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2243. return
  2244. }
  2245. if req.ChartInfoId > 0 && req.ImageUrl != "" {
  2246. err = data_manage.EditChartInfoImage(&req)
  2247. if err != nil {
  2248. br.Msg = "保存失败"
  2249. br.ErrMsg = "保存失败,Err:" + err.Error()
  2250. return
  2251. }
  2252. //修改es数据
  2253. go data.EsAddOrEditChartInfo(req.ChartInfoId)
  2254. //修改my eta es数据
  2255. go data.EsAddOrEditMyChartInfoByChartInfoId(req.ChartInfoId)
  2256. }
  2257. br.Ret = 200
  2258. br.Success = true
  2259. br.Msg = "保存成功"
  2260. }
  2261. // ChartInfoDetailFromUniqueCode
  2262. // @Title 根据编码获取图表详情
  2263. // @Description 根据编码获取图表详情接口
  2264. // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  2265. // @Param IsCache query bool true "是否走缓存,默认false"
  2266. // @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
  2267. // @router /chart_info/detail/from_unique_code [get]
  2268. func (this *ChartInfoController) ChartInfoDetailFromUniqueCode() {
  2269. br := new(models.BaseResponse).Init()
  2270. defer func() {
  2271. this.Data["json"] = br
  2272. this.ServeJSON()
  2273. }()
  2274. sysUser := this.SysUser
  2275. if sysUser == nil {
  2276. br.Msg = "请登录"
  2277. br.ErrMsg = "请登录,SysUser Is Empty"
  2278. br.Ret = 408
  2279. return
  2280. }
  2281. uniqueCode := this.GetString("UniqueCode")
  2282. if uniqueCode == "" {
  2283. br.Msg = "参数错误"
  2284. br.ErrMsg = "参数错误,uniqueCode is empty"
  2285. return
  2286. }
  2287. //是否走缓存
  2288. isCache, _ := this.GetBool("IsCache")
  2289. status := true
  2290. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  2291. if err != nil {
  2292. if err.Error() == utils.ErrNoRow() {
  2293. status = false
  2294. } else {
  2295. br.Msg = "获取失败"
  2296. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2297. return
  2298. }
  2299. }
  2300. if chartInfo == nil {
  2301. status = false
  2302. }
  2303. if !status {
  2304. resp := new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  2305. endInfoList := make([]*data_manage.ChartEdbInfoMapping, 0)
  2306. resp.EdbInfoList = endInfoList
  2307. resp.ChartInfo = chartInfo
  2308. resp.Status = false
  2309. return
  2310. }
  2311. resp, isOk, msg, errMsg := GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  2312. if !isOk {
  2313. br.Msg = msg
  2314. br.ErrMsg = errMsg
  2315. return
  2316. }
  2317. br.Ret = 200
  2318. br.Success = true
  2319. msg = "获取成功"
  2320. br.Data = resp
  2321. }
  2322. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  2323. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  2324. msg = `获取失败`
  2325. adminId := sysUser.AdminId
  2326. // 图表数据权限
  2327. // 图表分类
  2328. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  2329. if err != nil {
  2330. errMsg = "获取图表分类信息失败,Err:" + err.Error()
  2331. return
  2332. }
  2333. // 已授权分类id
  2334. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(adminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  2335. if err != nil {
  2336. errMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  2337. return
  2338. }
  2339. // 指标数据map
  2340. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  2341. defer func() {
  2342. if isOk {
  2343. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  2344. {
  2345. //判断是否加入我的图库
  2346. var myChartCondition string
  2347. var myChartPars []interface{}
  2348. myChartCondition += ` AND a.admin_id=? `
  2349. myChartPars = append(myChartPars, adminId)
  2350. myChartCondition += ` AND a.chart_info_id=? `
  2351. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  2352. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  2353. if err != nil && err.Error() != utils.ErrNoRow() {
  2354. msg = "获取失败"
  2355. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  2356. return
  2357. }
  2358. if myChartList != nil && len(myChartList) > 0 {
  2359. chartInfo.IsAdd = true
  2360. chartInfo.MyChartId = myChartList[0].MyChartId
  2361. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  2362. }
  2363. }
  2364. // 图表权限校验
  2365. {
  2366. resp.ChartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  2367. //图表操作权限
  2368. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, resp.ChartInfo.HaveOperaAuth)
  2369. chartInfo.Button = data_manage.ChartViewButton{
  2370. IsEdit: chartInfo.IsEdit,
  2371. IsEnChart: chartInfo.IsEnChart,
  2372. IsAdd: chartInfo.IsAdd,
  2373. IsCopy: true,
  2374. IsSetName: chartInfo.IsSetName,
  2375. }
  2376. //if !resp.ChartInfo.HaveOperaAuth {
  2377. // for _, v := range resp.EdbInfoList {
  2378. // v.DataList = nil
  2379. // }
  2380. // resp.DataResp = nil
  2381. // resp.XEdbIdValue = []int{}
  2382. // resp.YDataList = []data_manage.YData{}
  2383. //}
  2384. }
  2385. // 指标权限
  2386. {
  2387. classifyMap := make(map[int]*data_manage.EdbClassify)
  2388. // 分类
  2389. {
  2390. classifyIdList := make([]int, 0)
  2391. for _, v := range resp.EdbInfoList {
  2392. classifyIdList = append(classifyIdList, v.ClassifyId)
  2393. }
  2394. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  2395. if tmpErr != nil {
  2396. errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  2397. return
  2398. }
  2399. for _, v := range classifyList {
  2400. classifyMap[v.ClassifyId] = v
  2401. }
  2402. }
  2403. // 指标
  2404. if len(edbClassifyPermissionMap) < 0 {
  2405. edbInfoIdList := make([]int, 0)
  2406. for _, v := range resp.EdbInfoList {
  2407. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  2408. }
  2409. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  2410. if tmpErr != nil {
  2411. errMsg = "获取指标列表失败,Err:" + tmpErr.Error()
  2412. return
  2413. }
  2414. for _, v := range edbInfoList {
  2415. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  2416. ClassifyId: v.ClassifyId,
  2417. IsJoinPermission: v.IsJoinPermission,
  2418. EdbInfoId: v.EdbInfoId,
  2419. }
  2420. }
  2421. }
  2422. // 获取所有有权限的指标和分类
  2423. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  2424. if err != nil {
  2425. errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  2426. return
  2427. }
  2428. for _, v := range resp.EdbInfoList {
  2429. // 数据权限
  2430. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  2431. if !ok {
  2432. continue
  2433. }
  2434. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  2435. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  2436. }
  2437. }
  2438. }
  2439. }
  2440. if !isOk {
  2441. if errMsg != "" {
  2442. utils.FileLog.Info("查询图表详情失败,GetChartInfoDetailFromUniqueCode err:" + errMsg)
  2443. go alarm_msg.SendAlarmMsg("查询图表详情失败,GetChartInfoDetailFromUniqueCode,errmsg:"+errMsg, 3)
  2444. }
  2445. }
  2446. }()
  2447. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  2448. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  2449. if utils.Re == nil && isCache {
  2450. if utils.Re == nil && utils.Rc.IsExist(key) {
  2451. if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  2452. err := json.Unmarshal(redisData, &resp)
  2453. if err != nil || resp == nil {
  2454. return
  2455. }
  2456. isOk = true
  2457. fmt.Println("source redis")
  2458. return
  2459. }
  2460. }
  2461. }
  2462. // 获取主题样式
  2463. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  2464. if err != nil {
  2465. msg = "获取失败"
  2466. errMsg = "获取主题信息失败,Err:" + err.Error()
  2467. return
  2468. }
  2469. chartInfo.ChartThemeStyle = chartTheme.Config
  2470. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  2471. chartInfoId := chartInfo.ChartInfoId
  2472. dateType := chartInfo.DateType
  2473. startDate := chartInfo.StartDate
  2474. endDate := chartInfo.EndDate
  2475. startYear := chartInfo.StartYear
  2476. calendar := chartInfo.Calendar
  2477. chartType := chartInfo.ChartType
  2478. if calendar == "" {
  2479. calendar = "公历"
  2480. }
  2481. fmt.Println("a dateType:", dateType)
  2482. mappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  2483. if err != nil {
  2484. msg = "获取失败"
  2485. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2486. return
  2487. }
  2488. var dateMax time.Time
  2489. if dateType == utils.DateTypeNYears {
  2490. for _, v := range mappingList {
  2491. if v.LatestDate != "" {
  2492. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  2493. if tErr != nil {
  2494. msg = "获取失败"
  2495. errMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  2496. return
  2497. }
  2498. if lastDateT.After(dateMax) {
  2499. dateMax = lastDateT
  2500. }
  2501. }
  2502. }
  2503. }
  2504. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
  2505. extraConfigStr := chartInfo.ExtraConfig //图表额外数据参数
  2506. var barConfig data_manage.BarChartInfoReq
  2507. // 柱方图的一些配置
  2508. if chartInfo != nil && chartInfo.ChartType == 7 {
  2509. if chartInfo.BarConfig == `` {
  2510. msg = "柱方图未配置"
  2511. errMsg = "柱方图未配置"
  2512. return
  2513. }
  2514. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  2515. if err != nil {
  2516. msg = "柱方图配置异常"
  2517. errMsg = "柱方图配置异常"
  2518. return
  2519. }
  2520. extraConfigStr = chartInfo.BarConfig
  2521. }
  2522. // 获取图表中的指标数据
  2523. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  2524. if err != nil {
  2525. msg = "获取失败"
  2526. if errMsg != `` {
  2527. msg = errMsg
  2528. }
  2529. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2530. return
  2531. }
  2532. // 单位
  2533. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  2534. chartInfo.Unit = yDataList[0].Unit
  2535. chartInfo.UnitEn = yDataList[0].UnitEn
  2536. }
  2537. warnEdbList := make([]string, 0)
  2538. for _, v := range edbList {
  2539. if v.IsNullData {
  2540. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  2541. }
  2542. }
  2543. if len(warnEdbList) > 0 {
  2544. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  2545. }
  2546. /*
  2547. ChartClassify []*ChartClassifyView
  2548. */
  2549. chartViewClassify, _ := data_manage.GetChartClassifyViewById(chartInfo.ChartClassifyId)
  2550. if chartViewClassify != nil {
  2551. chartClassifyParent, _ := data_manage.GetChartClassifyViewById(chartClassify.ParentId)
  2552. chartInfo.ChartClassify = append(chartInfo.ChartClassify, chartClassifyParent)
  2553. }
  2554. chartInfo.ChartClassify = append(chartInfo.ChartClassify, chartViewClassify)
  2555. resp.EdbInfoList = edbList
  2556. //判断是否需要展示英文标识
  2557. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  2558. // 图表的指标来源
  2559. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  2560. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  2561. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  2562. resp.ChartInfo = chartInfo
  2563. resp.XEdbIdValue = xEdbIdValue
  2564. resp.YDataList = yDataList
  2565. resp.Status = true
  2566. resp.BarChartInfo = barConfig
  2567. resp.DataResp = dataResp
  2568. // 将数据加入缓存
  2569. if utils.Re == nil {
  2570. data, _ := json.Marshal(resp)
  2571. utils.Rc.Put(key, data, 2*time.Hour)
  2572. }
  2573. isOk = true
  2574. // 遍历到校验map
  2575. for _, v := range edbList {
  2576. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  2577. ClassifyId: v.ClassifyId,
  2578. IsJoinPermission: v.IsJoinPermission,
  2579. EdbInfoId: v.EdbInfoId,
  2580. }
  2581. }
  2582. return
  2583. }
  2584. // @Param Img query string true "图片"
  2585. // @Success 200 {object} models.ResourceResp
  2586. // @router /chart_info/base64Upload [post]
  2587. func (this *ChartInfoController) ChartInfoBase64Upload() {
  2588. br := new(models.BaseResponse).Init()
  2589. defer func() {
  2590. this.Data["json"] = br
  2591. this.ServeJSON()
  2592. }()
  2593. imgData := this.GetString("Img")
  2594. if imgData == "" {
  2595. br.Msg = "图片参数错误"
  2596. br.ErrMsg = "图片参数错误,Img Is Empty"
  2597. return
  2598. }
  2599. resp := new(models.ResourceResp)
  2600. uploadDir := "static/images/"
  2601. if !utils.FileIsExist(uploadDir) {
  2602. err := os.MkdirAll(uploadDir, utils.DIR_MOD)
  2603. if err != nil {
  2604. br.Msg = "图表保存失败"
  2605. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  2606. return
  2607. }
  2608. }
  2609. //var saveToOssPath string
  2610. randStr := utils.GetRandStringNoSpecialChar(28)
  2611. var fileName, outFileName string
  2612. fileName = randStr + ".txt"
  2613. fileName = uploadDir + fileName
  2614. err := utils.SaveToFile(imgData, fileName)
  2615. if err != nil {
  2616. br.Msg = "图片保存失败"
  2617. br.ErrMsg = "图片保存失败,Err:" + err.Error()
  2618. return
  2619. }
  2620. outFileName = randStr + ".png"
  2621. doneChannel := make(chan bool, 1)
  2622. errorChannel := make(chan error, 1)
  2623. cmd := exec.Command("highcharts-export-server", "--infile", fileName, "--constr", "Chart", "--scale", "2", "--workers", "10", "--workLimit", "3", "--outfile", outFileName)
  2624. go func() {
  2625. output, err := cmd.CombinedOutput()
  2626. if err != nil {
  2627. utils.FileLog.Info("execute command failed, output: , error: \n" + string(output) + err.Error())
  2628. errorChannel <- err
  2629. return
  2630. }
  2631. doneChannel <- true
  2632. }()
  2633. select {
  2634. case <-time.After(30 * time.Second):
  2635. utils.FileLog.Info("执行超过30秒 杀死超时进程")
  2636. e := cmd.Process.Kill()
  2637. if e != nil {
  2638. fmt.Println("cmd kill err: ", e.Error())
  2639. utils.FileLog.Info(fmt.Sprintf("cmd kill err: %s", e.Error()))
  2640. br.Msg = "图片生成失败"
  2641. br.ErrMsg = "图片生成失败, 执行超时" + e.Error()
  2642. return
  2643. }
  2644. fmt.Println("timeout kill process")
  2645. case <-doneChannel:
  2646. fmt.Println("done")
  2647. case err := <-errorChannel:
  2648. br.Msg = "文件上传失败"
  2649. br.ErrMsg = fmt.Sprintf("execute command failure err: %s", err.Error())
  2650. fmt.Println("execute command failure err:" + err.Error())
  2651. return
  2652. }
  2653. defer func() {
  2654. os.Remove(fileName)
  2655. os.Remove(outFileName)
  2656. }()
  2657. //saveToOssPath = uploadDir + time.Now().Format("200601/20060102/")
  2658. //saveToOssPath += outFileName
  2659. //上传到阿里云 和 minio
  2660. resourceUrl := ``
  2661. //if utils.ObjectStorageClient == "minio" {
  2662. // err = services.UploadFileToMinIo("", outFileName, saveToOssPath)
  2663. // if err != nil {
  2664. // br.Msg = "文件上传失败"
  2665. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  2666. // return
  2667. // }
  2668. // resourceUrl = utils.MinIoImghost + saveToOssPath
  2669. //} else {
  2670. // err = services.UploadFileToAliyun("", outFileName, saveToOssPath)
  2671. // if err != nil {
  2672. // br.Msg = "文件上传失败"
  2673. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  2674. // return
  2675. // }
  2676. // resourceUrl = utils.Imghost + saveToOssPath
  2677. //}
  2678. ossClient := services.NewOssClient()
  2679. if ossClient == nil {
  2680. br.Msg = "上传失败"
  2681. br.ErrMsg = "初始化OSS服务失败"
  2682. return
  2683. }
  2684. resourceUrl, err = ossClient.UploadFile(outFileName, outFileName, "")
  2685. if err != nil {
  2686. br.Msg = "文件上传失败"
  2687. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  2688. return
  2689. }
  2690. resp.ResourceUrl = resourceUrl
  2691. resp.Source = "convert"
  2692. //resp.CacheKey = imgDataKey
  2693. br.Msg = "上传成功"
  2694. br.Ret = 200
  2695. br.Success = true
  2696. br.Data = resp
  2697. return
  2698. }
  2699. // BatchChartInfoRefresh
  2700. // @Title 批量刷新图表接口
  2701. // @Description 批量刷新图表接口
  2702. // @Param request body data_manage.BatchChartRefreshReq true "type json string"
  2703. // @Success Ret=200 刷新成功
  2704. // @router /chart_info/batch_refresh [post]
  2705. func (this *EdbInfoController) BatchChartInfoRefresh() {
  2706. br := new(models.BaseResponse).Init()
  2707. defer func() {
  2708. this.Data["json"] = br
  2709. this.ServeJSON()
  2710. }()
  2711. sysUser := this.SysUser
  2712. if sysUser == nil {
  2713. br.Msg = "请登录"
  2714. br.ErrMsg = "请登录,SysUser Is Empty"
  2715. br.Ret = 408
  2716. return
  2717. }
  2718. var req data_manage.BatchChartRefreshReq
  2719. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2720. if err != nil {
  2721. br.Msg = "参数解析异常!"
  2722. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2723. return
  2724. }
  2725. if req.Source == "" {
  2726. br.Msg = "刷新来源有误"
  2727. return
  2728. }
  2729. if req.PrimaryId <= 0 {
  2730. br.Msg = "刷新对象有误"
  2731. return
  2732. }
  2733. //获取所有的图表列表
  2734. _, chartInfoList, err := data_manage.GetChartInfoListByUniqueCodeSlice(req.ChartInfoCode)
  2735. if len(chartInfoList) <= 0 {
  2736. br.Ret = 200
  2737. br.Success = true
  2738. br.Msg = "刷新成功"
  2739. return
  2740. }
  2741. redisKey := data.GetBatchChartRefreshKey(req.Source, req.PrimaryId, req.SubId)
  2742. // 图表中的指标刷新
  2743. err, isAsync := data.BatchChartInfoRefreshV2(chartInfoList, redisKey)
  2744. if err != nil {
  2745. br.Msg = "刷新失败"
  2746. br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  2747. return
  2748. }
  2749. br.Msg = "刷新成功"
  2750. if isAsync {
  2751. br.Msg = "研报中图表关联指标较多,请10分钟后刷新页面查看最新数据"
  2752. }
  2753. br.Ret = 200
  2754. br.Success = true
  2755. }
  2756. // CopyChartInfo
  2757. // @Title 复制并新增图表接口
  2758. // @Description 新增图表接口
  2759. // @Param request body data_manage.CopyAddChartInfoReq true "type json string"
  2760. // @Success 200 {object} data_manage.AddChartInfoResp
  2761. // @router /chart_info/copy [post]
  2762. func (this *ChartInfoController) CopyChartInfo() {
  2763. br := new(models.BaseResponse).Init()
  2764. defer func() {
  2765. this.Data["json"] = br
  2766. this.ServeJSON()
  2767. }()
  2768. sysUser := this.SysUser
  2769. if sysUser == nil {
  2770. br.Msg = "请登录"
  2771. br.ErrMsg = "请登录,SysUser Is Empty"
  2772. br.Ret = 408
  2773. return
  2774. }
  2775. deleteCache := true
  2776. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  2777. defer func() {
  2778. if deleteCache {
  2779. utils.Rc.Delete(cacheKey)
  2780. }
  2781. }()
  2782. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  2783. deleteCache = false
  2784. br.Msg = "系统处理中,请稍后重试!"
  2785. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  2786. return
  2787. }
  2788. var req data_manage.CopyAddChartInfoReq
  2789. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2790. if err != nil {
  2791. br.Msg = "参数解析异常!"
  2792. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2793. return
  2794. }
  2795. // 获取原图表信息
  2796. oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  2797. if err != nil {
  2798. br.Msg = "获取原图表信息失败"
  2799. br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
  2800. return
  2801. }
  2802. //校验图表名称是否重复
  2803. req.ChartName = strings.Trim(req.ChartName, " ")
  2804. if req.ChartName == "" {
  2805. br.Msg = "请填写图表名称!"
  2806. return
  2807. }
  2808. if req.ChartClassifyId <= 0 {
  2809. br.Msg = "分类参数错误!"
  2810. return
  2811. }
  2812. chartClassify, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  2813. if err != nil {
  2814. if err.Error() == utils.ErrNoRow() {
  2815. br.Msg = "分类不存在"
  2816. br.ErrMsg = "分类不存在"
  2817. return
  2818. }
  2819. br.Msg = "获取分类信息失败"
  2820. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  2821. return
  2822. }
  2823. if chartClassify == nil {
  2824. br.Msg = "分类不存在"
  2825. br.ErrMsg = "分类不存在"
  2826. return
  2827. }
  2828. //count, err := data_manage.ChartInfoExist("", edbInfoIdStr)
  2829. //if err != nil && err.Error() != utils.ErrNoRow() {
  2830. // br.Msg = "保存失败"
  2831. // br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
  2832. // return
  2833. //}
  2834. //if count > 0 {
  2835. // br.Msg = "所选指标已存在相同指标"
  2836. // return
  2837. //}
  2838. //判断图表是否存在
  2839. var condition string
  2840. var pars []interface{}
  2841. condition += " AND chart_classify_id=? "
  2842. pars = append(pars, req.ChartClassifyId)
  2843. condition += " AND chart_name=? AND source = ? "
  2844. pars = append(pars, req.ChartName, utils.CHART_SOURCE_DEFAULT)
  2845. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  2846. if err != nil {
  2847. br.Msg = "判断图表名称是否存在失败"
  2848. br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
  2849. return
  2850. }
  2851. if count > 0 {
  2852. br.Msg = "图表已存在,请重新填写"
  2853. br.IsSendEmail = false
  2854. return
  2855. }
  2856. //获取原图表关联的指标信息列表
  2857. edbMappingList, err := data_manage.GetChartEdbMappingList(req.ChartInfoId)
  2858. if err != nil {
  2859. br.Msg = "获取图表关联的指标信息失败!"
  2860. return
  2861. }
  2862. //添加图表
  2863. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  2864. chartInfo := &data_manage.ChartInfo{
  2865. ChartInfoId: 0,
  2866. ChartName: req.ChartName,
  2867. ChartNameEn: req.ChartName,
  2868. ChartClassifyId: req.ChartClassifyId,
  2869. SysUserId: sysUser.AdminId,
  2870. SysUserRealName: sysUser.RealName,
  2871. UniqueCode: utils.MD5(utils.CHART_PREFIX + "_" + timestamp),
  2872. CreateTime: time.Now(),
  2873. ModifyTime: time.Now(),
  2874. DateType: oldChartInfo.DateType,
  2875. StartDate: oldChartInfo.StartDate,
  2876. EndDate: oldChartInfo.EndDate,
  2877. IsSetName: oldChartInfo.IsSetName,
  2878. EdbInfoIds: oldChartInfo.EdbInfoIds,
  2879. ChartType: oldChartInfo.ChartType,
  2880. Calendar: oldChartInfo.Calendar,
  2881. SeasonStartDate: oldChartInfo.SeasonStartDate,
  2882. SeasonEndDate: oldChartInfo.SeasonEndDate,
  2883. ChartImage: oldChartInfo.ChartImage,
  2884. BarConfig: oldChartInfo.BarConfig,
  2885. //Sort: sort,
  2886. LeftMin: oldChartInfo.LeftMin,
  2887. LeftMax: oldChartInfo.LeftMax,
  2888. RightMin: oldChartInfo.RightMin,
  2889. RightMax: oldChartInfo.RightMax,
  2890. Right2Min: oldChartInfo.Right2Min,
  2891. Right2Max: oldChartInfo.Right2Max,
  2892. Disabled: oldChartInfo.Disabled,
  2893. Source: oldChartInfo.Source,
  2894. ExtraConfig: oldChartInfo.ExtraConfig,
  2895. SeasonExtraConfig: oldChartInfo.SeasonExtraConfig,
  2896. StartYear: oldChartInfo.StartYear,
  2897. Unit: oldChartInfo.Unit,
  2898. UnitEn: oldChartInfo.UnitEn,
  2899. ChartThemeId: oldChartInfo.ChartThemeId,
  2900. SourcesFrom: oldChartInfo.SourcesFrom,
  2901. Instructions: oldChartInfo.Instructions,
  2902. MarkersLines: oldChartInfo.MarkersLines,
  2903. MarkersAreas: oldChartInfo.MarkersAreas,
  2904. }
  2905. newId, err := data_manage.AddChartInfo(chartInfo)
  2906. if err != nil {
  2907. br.Msg = "保存失败"
  2908. br.ErrMsg = "保存失败,Err:" + err.Error()
  2909. return
  2910. }
  2911. chartInfo.ChartInfoId = int(newId)
  2912. // 添加图表与指标的关联关系
  2913. {
  2914. mapList := make([]*data_manage.ChartEdbMapping, 0)
  2915. for _, v := range edbMappingList {
  2916. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  2917. mapItem := &data_manage.ChartEdbMapping{
  2918. //ChartEdbMappingId: 0,
  2919. ChartInfoId: chartInfo.ChartInfoId,
  2920. EdbInfoId: v.EdbInfoId,
  2921. CreateTime: time.Now(),
  2922. ModifyTime: time.Now(),
  2923. UniqueCode: utils.MD5(utils.CHART_PREFIX + "_" + timestamp),
  2924. MaxData: v.MaxData,
  2925. MinData: v.MinData,
  2926. IsOrder: v.IsOrder,
  2927. IsAxis: v.IsAxis,
  2928. EdbInfoType: v.EdbInfoType,
  2929. LeadValue: v.LeadValue,
  2930. LeadUnit: v.LeadUnit,
  2931. ChartStyle: v.ChartStyle,
  2932. ChartColor: v.ChartColor,
  2933. ChartWidth: v.ChartWidth,
  2934. Source: v.Source,
  2935. EdbAliasName: v.EdbAliasName,
  2936. IsConvert: v.IsConvert,
  2937. ConvertType: v.ConvertType,
  2938. ConvertValue: v.ConvertValue,
  2939. ConvertUnit: v.ConvertEnUnit,
  2940. ConvertEnUnit: v.ConvertEnUnit,
  2941. }
  2942. mapList = append(mapList, mapItem)
  2943. }
  2944. err = data_manage.AddChartEdbMapping(mapList)
  2945. if err != nil {
  2946. br.Msg = "保存失败"
  2947. br.ErrMsg = "保存失败,Err:" + err.Error()
  2948. return
  2949. }
  2950. }
  2951. if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  2952. // 查询系列信息并复制
  2953. chartSeriesList, e := data_manage.GetChartSeriesByChartInfoId(oldChartInfo.ChartInfoId)
  2954. if e != nil {
  2955. br.Msg = "获取图表关联的系列信息失败"
  2956. br.ErrMsg = "获取图表关联的系列信息失败,Err:" + e.Error()
  2957. return
  2958. }
  2959. chartSeriesEdbList, e := data_manage.GetChartSeriesEdbByChartInfoId(oldChartInfo.ChartInfoId)
  2960. if err != nil {
  2961. br.Msg = "获取图表关联的系列指标信息失败"
  2962. br.ErrMsg = "获取图表关联的系列指标信息失败,Err:" + err.Error()
  2963. return
  2964. }
  2965. err = data_manage.CopyChartSeriesAndEdbMapping(chartSeriesList, chartSeriesEdbList, chartInfo.ChartInfoId)
  2966. if err != nil {
  2967. br.Msg = "保存失败"
  2968. br.ErrMsg = "保存图表系列失败,Err:" + err.Error()
  2969. return
  2970. }
  2971. }
  2972. //添加es数据
  2973. go data.EsAddOrEditChartInfo(chartInfo.ChartInfoId)
  2974. //修改my eta es数据
  2975. go data.EsAddOrEditMyChartInfoByChartInfoId(chartInfo.ChartInfoId)
  2976. //新增操作日志
  2977. {
  2978. chartLog := new(data_manage.ChartInfoLog)
  2979. chartLog.ChartInfoId = chartInfo.ChartInfoId
  2980. chartLog.ChartName = req.ChartName
  2981. chartLog.ChartClassifyId = req.ChartClassifyId
  2982. chartLog.SysUserId = sysUser.AdminId
  2983. chartLog.SysUserRealName = sysUser.RealName
  2984. chartLog.UniqueCode = chartInfo.UniqueCode
  2985. chartLog.CreateTime = time.Now()
  2986. chartLog.Content = string(this.Ctx.Input.RequestBody)
  2987. chartLog.Status = "新增图表"
  2988. chartLog.Method = this.Ctx.Input.URI()
  2989. go data_manage.AddChartInfoLog(chartLog)
  2990. }
  2991. // 试用平台更新用户累计新增图表数
  2992. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  2993. if e != nil {
  2994. br.Msg = "操作失败"
  2995. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  2996. return
  2997. }
  2998. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  2999. go func() {
  3000. var r etaTrialService.EtaTrialUserReq
  3001. r.Mobile = adminItem.Mobile
  3002. _, _ = etaTrialService.UpdateUserChartNum(r)
  3003. }()
  3004. }
  3005. br.Ret = 200
  3006. br.Success = true
  3007. br.Msg = "保存成功"
  3008. br.Data = data_manage.AddChartInfoResp{
  3009. ChartInfoId: chartInfo.ChartInfoId,
  3010. UniqueCode: chartInfo.UniqueCode,
  3011. ChartType: chartInfo.ChartType,
  3012. }
  3013. br.IsAddLog = true
  3014. }
  3015. // PreviewBarChartInfo
  3016. // @Title 图表-获取预览的柱方图数据
  3017. // @Description 图表-获取指标详情接口
  3018. // @Param request body data_manage.BarChartInfoReq true "type json string"
  3019. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  3020. // @router /chart_info/preview_bar [post]
  3021. func (this *ChartInfoController) PreviewBarChartInfo() {
  3022. br := new(models.BaseResponse).Init()
  3023. defer func() {
  3024. this.Data["json"] = br
  3025. this.ServeJSON()
  3026. }()
  3027. var req data_manage.BarChartInfoReq
  3028. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3029. if err != nil {
  3030. br.Msg = "参数解析异常!"
  3031. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3032. return
  3033. }
  3034. sysUser := this.SysUser
  3035. if sysUser == nil {
  3036. br.Msg = "请登录"
  3037. br.ErrMsg = "请登录,SysUser Is Empty"
  3038. br.Ret = 408
  3039. return
  3040. }
  3041. if len(req.EdbInfoIdList) <= 0 {
  3042. br.Msg = "请选择指标"
  3043. return
  3044. }
  3045. if len(req.DateList) <= 0 {
  3046. br.Msg = "请选择日期"
  3047. return
  3048. }
  3049. chartInfo := new(data_manage.ChartInfoView)
  3050. chartType := utils.CHART_TYPE_BAR
  3051. //edbInfoIdList := make([]int, 0)
  3052. edbInfoIdsList := make([]string, 0)
  3053. convertMap := make(map[int]*data_manage.ChartEdbInfoMapping, 0)
  3054. for _, v := range req.EdbInfoIdList {
  3055. edbInfoIdsList = append(edbInfoIdsList, strconv.Itoa(v.EdbInfoId))
  3056. convertMap[v.EdbInfoId] = &data_manage.ChartEdbInfoMapping{
  3057. IsConvert: v.IsConvert,
  3058. ConvertType: v.ConvertType,
  3059. ConvertValue: v.ConvertValue,
  3060. ConvertUnit: v.ConvertUnit,
  3061. ConvertEnUnit: v.ConvertEnUnit,
  3062. }
  3063. }
  3064. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoId(strings.Join(edbInfoIdsList, ","))
  3065. if err != nil {
  3066. br.Msg = "获取失败"
  3067. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3068. return
  3069. }
  3070. for i, item := range mappingList {
  3071. if _, ok := convertMap[item.EdbInfoId]; ok {
  3072. mappingList[i].ConvertValue = convertMap[item.EdbInfoId].ConvertValue
  3073. mappingList[i].ConvertUnit = convertMap[item.EdbInfoId].ConvertUnit
  3074. mappingList[i].ConvertEnUnit = convertMap[item.EdbInfoId].ConvertEnUnit
  3075. mappingList[i].ConvertType = convertMap[item.EdbInfoId].ConvertType
  3076. mappingList[i].IsConvert = convertMap[item.EdbInfoId].IsConvert
  3077. }
  3078. }
  3079. // 获取图表中的指标数据
  3080. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, string(this.Ctx.Input.RequestBody), "")
  3081. if err != nil {
  3082. br.Msg = "获取失败"
  3083. if errMsg != `` {
  3084. br.Msg = errMsg
  3085. }
  3086. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3087. return
  3088. }
  3089. // 单位
  3090. if len(yDataList) > 0 {
  3091. chartInfo.Unit = yDataList[0].Unit
  3092. chartInfo.UnitEn = yDataList[0].UnitEn
  3093. }
  3094. warnEdbList := make([]string, 0)
  3095. for _, v := range edbList {
  3096. if v.IsNullData {
  3097. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3098. }
  3099. for _, reqEdb := range req.EdbInfoIdList {
  3100. if v.EdbInfoId == reqEdb.EdbInfoId {
  3101. v.EdbAliasName = reqEdb.Name
  3102. }
  3103. }
  3104. }
  3105. if len(warnEdbList) > 0 {
  3106. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3107. }
  3108. // 图表的指标来源
  3109. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3110. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3111. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3112. //图表操作权限
  3113. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  3114. //判断是否需要展示英文标识
  3115. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  3116. chartInfo.Button = data_manage.ChartViewButton{
  3117. IsEdit: chartInfo.IsEdit,
  3118. IsEnChart: chartInfo.IsEnChart,
  3119. IsAdd: chartInfo.IsAdd,
  3120. IsCopy: true,
  3121. IsSetName: chartInfo.IsSetName,
  3122. }
  3123. // 标识线计算
  3124. if req.MarkersLines != "" {
  3125. markerLines := make([]data_manage.MarkersLine, 0)
  3126. err = json.Unmarshal([]byte(req.MarkersLines), &markerLines)
  3127. if err != nil {
  3128. br.Msg = "标识线配置异常"
  3129. br.ErrMsg = "标识线配置异常" + err.Error()
  3130. return
  3131. }
  3132. for i := range markerLines {
  3133. if markerLines[i].EdbType == 0 && markerLines[i].TimeIntervalType == 0 && markerLines[i].Axis != 3 {
  3134. // 图上第一个指标且时间区间跟随图表
  3135. if markerLines[i].MarkLineType == 2 {
  3136. // 图上第一个指标且时间区间跟随图表
  3137. if edbList[0].IsAxis == 1 {
  3138. value, err := data.MarkerLineCalculate(markerLines[i], edbList[0].DataList, chartInfo)
  3139. if err != nil {
  3140. br.Msg = "标识线配置异常"
  3141. br.ErrMsg = "标识线配置异常" + err.Error()
  3142. return
  3143. }
  3144. markerLines[i].Value = value
  3145. } else {
  3146. // 其他的都走指标计算
  3147. edbInfo, err := data_manage.GetEdbInfoById(markerLines[i].EdbInfoId)
  3148. if err != nil {
  3149. br.Msg = "指标计算标识线获取指标信息异常"
  3150. br.ErrMsg = "指标计算标识线获取指标信息异常" + err.Error()
  3151. return
  3152. }
  3153. dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, "", "")
  3154. if err != nil {
  3155. br.Msg = "指标计算标识线获取指标数据异常"
  3156. br.ErrMsg = "指标计算标识线获取指标数据异常" + err.Error()
  3157. return
  3158. }
  3159. value, err := data.MarkerLineCalculate(markerLines[i], dataList, chartInfo)
  3160. if err != nil {
  3161. br.Msg = "标识线配置异常"
  3162. br.ErrMsg = "标识线配置异常" + err.Error()
  3163. return
  3164. }
  3165. markerLines[i].Value = value
  3166. }
  3167. }
  3168. }
  3169. }
  3170. markerLineStr, err := json.Marshal(markerLines)
  3171. if err != nil {
  3172. br.Msg = "标识线配置异常"
  3173. br.ErrMsg = "标识线配置异常" + err.Error()
  3174. return
  3175. }
  3176. chartInfo.MarkersLines = string(markerLineStr)
  3177. }
  3178. resp := new(data_manage.ChartInfoDetailResp)
  3179. resp.ChartInfo = chartInfo
  3180. resp.EdbInfoList = edbList
  3181. resp.XEdbIdValue = xEdbIdValue
  3182. resp.YDataList = yDataList
  3183. resp.DataResp = dataResp
  3184. br.Ret = 200
  3185. br.Success = true
  3186. br.Msg = "获取成功"
  3187. br.Data = resp
  3188. }
  3189. // PreviewSectionScatterChartInfo
  3190. // @Title 图表-获取预览的截面散点图数据
  3191. // @Description 图表-获取指标详情接口
  3192. // @Param request body data_manage.SectionScatter true "type json string"
  3193. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  3194. // @router /chart_info/preview/time_section [post]
  3195. func (this *ChartInfoController) PreviewSectionScatterChartInfo() {
  3196. br := new(models.BaseResponse).Init()
  3197. defer func() {
  3198. this.Data["json"] = br
  3199. this.ServeJSON()
  3200. }()
  3201. var req data_manage.PreviewSectionScatterChartReq
  3202. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3203. if err != nil {
  3204. br.Msg = "参数解析异常!"
  3205. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3206. return
  3207. }
  3208. chartInfo := new(data_manage.ChartInfoView)
  3209. sysUser := this.SysUser
  3210. if sysUser == nil {
  3211. br.Msg = "请登录"
  3212. br.ErrMsg = "请登录,SysUser Is Empty"
  3213. br.Ret = 408
  3214. return
  3215. }
  3216. chartType := utils.CHART_TYPE_SECTION_SCATTER
  3217. edbInfoIdArr, err, errMsg := data.CheckChartExtraConfig(chartType, req.ExtraConfig)
  3218. if err != nil {
  3219. br.Msg = errMsg
  3220. br.ErrMsg = "添加失败:" + err.Error()
  3221. return
  3222. }
  3223. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  3224. // 获取图表中的指标数据
  3225. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, req.ExtraConfig, "")
  3226. if err != nil {
  3227. br.Msg = "获取失败"
  3228. if errMsg != `` {
  3229. br.Msg = errMsg
  3230. }
  3231. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3232. return
  3233. }
  3234. warnEdbList := make([]string, 0)
  3235. for _, v := range edbList {
  3236. if v.IsNullData {
  3237. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3238. }
  3239. }
  3240. if len(warnEdbList) > 0 {
  3241. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3242. }
  3243. // 图表的指标来源
  3244. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3245. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3246. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3247. //图表操作权限
  3248. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  3249. //判断是否需要展示英文标识
  3250. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  3251. chartInfo.Button = data_manage.ChartViewButton{
  3252. IsEdit: chartInfo.IsEdit,
  3253. IsEnChart: chartInfo.IsEnChart,
  3254. IsAdd: chartInfo.IsAdd,
  3255. IsCopy: true,
  3256. IsSetName: chartInfo.IsSetName,
  3257. }
  3258. resp := new(data_manage.ChartInfoDetailResp)
  3259. resp.ChartInfo = chartInfo
  3260. resp.EdbInfoList = edbList
  3261. resp.XEdbIdValue = xEdbIdValue
  3262. resp.YDataList = yDataList
  3263. resp.DataResp = dataResp
  3264. br.Ret = 200
  3265. br.Success = true
  3266. br.Msg = "获取成功"
  3267. br.Data = resp
  3268. }
  3269. // GetBatchChartRefreshResult
  3270. // @Title 获取批量刷新图表结果的接口
  3271. // @Description 获取批量刷新图表结果的接口
  3272. // @Param request body data_manage.BatchChartRefreshReq true "type json string"
  3273. // @Success Ret=200 刷新成功
  3274. // @router /chart_info/batch_refresh/result [post]
  3275. func (this *EdbInfoController) GetBatchChartRefreshResult() {
  3276. br := new(models.BaseResponse).Init()
  3277. defer func() {
  3278. this.Data["json"] = br
  3279. this.ServeJSON()
  3280. }()
  3281. sysUser := this.SysUser
  3282. if sysUser == nil {
  3283. br.Msg = "请登录"
  3284. br.ErrMsg = "请登录,SysUser Is Empty"
  3285. br.Ret = 408
  3286. return
  3287. }
  3288. var req data_manage.BatchChartRefreshReq
  3289. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3290. if err != nil {
  3291. br.Msg = "参数解析异常!"
  3292. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3293. return
  3294. }
  3295. if req.Source == "" {
  3296. br.Msg = "刷新来源有误"
  3297. return
  3298. }
  3299. if req.PrimaryId <= 0 {
  3300. br.Msg = "刷新对象有误"
  3301. return
  3302. }
  3303. // 刷新结果,默认是刷新完成了
  3304. refreshResult := data.CheckBatchChartRefreshResult(req.Source, req.PrimaryId, req.SubId)
  3305. resp := response.ChartRefreshResp{
  3306. RefreshResult: refreshResult,
  3307. }
  3308. br.Data = resp
  3309. br.Ret = 200
  3310. br.Success = true
  3311. }
  3312. //
  3313. //修复数据时间戳
  3314. //func init() {
  3315. // fmt.Println("start")
  3316. // edbInfoList,err:=data_manage.GetEdbInfo()
  3317. // if err!=nil {
  3318. // fmt.Println("Err:",err.Error())
  3319. // return
  3320. // }
  3321. // startDate:=time.Now().AddDate(-40,0,0).Format(utils.FormatDate)
  3322. // endDate:=time.Now().Format(utils.FormatDate)
  3323. // for _,v:=range edbInfoList{
  3324. // dataList,err:=data_manage.GetEdbDataList(v.Source,v.EdbInfoId,startDate,endDate)
  3325. // if err!=nil {
  3326. // fmt.Println("GetEdbDataList Err:",err.Error())
  3327. // return
  3328. // }
  3329. // for _,dv:=range dataList{
  3330. // dataTime,err:=time.Parse(utils.FormatDate,dv.DataTime)
  3331. // if err!=nil {
  3332. // fmt.Println("time.Parse Err:"+err.Error())
  3333. // return
  3334. // }
  3335. // timestamp:=dataTime.UnixNano()/1e6
  3336. // err=data_manage.ModifyEdbDatadTimestamp(v.Source,dv.EdbDataId,timestamp)
  3337. // if err!=nil{
  3338. // fmt.Println("ModifyEdbDatadTimestamp Err:"+err.Error())
  3339. // return
  3340. // }
  3341. // fmt.Println(v.Source,dv.EdbDataId,timestamp)
  3342. // }
  3343. // }
  3344. // //time.Sleep(2*time.Minute)
  3345. //
  3346. // //startDate:=time.Now().AddDate(-30,0,0).Format(utils.FormatDate)
  3347. // //endDate:=time.Now().Format(utils.FormatDate)
  3348. // //dataList,err:=data_manage.GetEdbDataList(1,100099,startDate,endDate)
  3349. // //if err!=nil {
  3350. // // fmt.Println("GetEdbDataList Err:",err.Error())
  3351. // // return
  3352. // //}
  3353. // //for _,dv:=range dataList{
  3354. // // dataTime,err:=time.Parse(utils.FormatDate,dv.DataTime)
  3355. // // if err!=nil {
  3356. // // fmt.Println("time.Parse Err:"+err.Error())
  3357. // // return
  3358. // // }
  3359. // // timestamp:=dataTime.UnixNano()/1e6
  3360. // // err=data_manage.ModifyEdbDatadTimestamp(2,dv.EdbDataId,timestamp)
  3361. // // if err!=nil{
  3362. // // fmt.Println("ModifyEdbDatadTimestamp Err:"+err.Error())
  3363. // // return
  3364. // // }
  3365. // // fmt.Println(2,dv.EdbDataId,timestamp)
  3366. // //}
  3367. //
  3368. // fmt.Println("end")
  3369. //}
  3370. //修复指标配置数据
  3371. //func init() {
  3372. // fmt.Println("start")
  3373. // edbInfo, err := data_manage.GetEdbInfoAll()
  3374. // fmt.Println(err)
  3375. // for k, v := range edbInfoAll {
  3376. // fmt.Println(k, v.EdbInfoId)
  3377. // item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
  3378. // fmt.Println(item, err)
  3379. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
  3380. // if err != nil {
  3381. // fmt.Println("ModifyEdbInfoMaxAndMinInfo Err:" + err.Error())
  3382. // }
  3383. // }
  3384. // fmt.Println("end")
  3385. //}
  3386. //func init() {
  3387. // fmt.Println("start")
  3388. // var yearArr []int
  3389. // yearArr = append(yearArr, 2021)
  3390. // yearArr = append(yearArr, 2010)
  3391. // yearArr = append(yearArr, 2020)
  3392. // yearArr = append(yearArr, 2017)
  3393. // yearArr = append(yearArr, 2019)
  3394. // sort.Sort(sort.Reverse(sort.IntSlice(yearArr)))
  3395. // fmt.Println(yearArr)
  3396. // fmt.Println("end")
  3397. //}
  3398. //季度指标数据计算(公历转农历)
  3399. //func init() {
  3400. // fmt.Println("start AddCalculateQuarter")
  3401. // list:=make([]*data_manage.EdbDataList,0)
  3402. // data_manage.AddCalculateQuarterV4(list)
  3403. // fmt.Println("end AddCalculateQuarter")
  3404. // //return
  3405. //}
  3406. /*
  3407. {
  3408. "ChartClassifyId": 58,
  3409. "ChartName": "公历转农历6",
  3410. "ChartType": 2,
  3411. "ChartEdbInfoList": [
  3412. {
  3413. "ChartColor": "#00f",
  3414. "ChartStyle": "spline",
  3415. "ChartWidth": 3,
  3416. "EdbInfoId": 100466,
  3417. "EdbInfoType": 1,
  3418. "IsAxis": 1,
  3419. "IsOrder": false,
  3420. "LeadUnit": "",
  3421. "LeadValue": 0,
  3422. "MaxData": 0.2943,
  3423. "MinData": -0.2448
  3424. }
  3425. ]
  3426. }
  3427. */
  3428. //func init() {
  3429. // fmt.Println("start")
  3430. // data_manage.AddCalculateQuarter(100466,6,"C2108252836")
  3431. // fmt.Println("end")
  3432. //}
  3433. //func init() {
  3434. // data.AddAllChartInfo()
  3435. //}
  3436. // 截面散点示例数据
  3437. //func init() {
  3438. //
  3439. // seriesList := []data_manage.SectionScatterSeriesItemReq{
  3440. // {
  3441. // Name: "系列1名称",
  3442. // Color: "红红火火色",
  3443. // EdbList: []data_manage.SectionScatterEdbItemReq{
  3444. // {
  3445. // XEdbInfoId: 1,
  3446. // YEdbInfoId: 2,
  3447. // Name: "破铜",
  3448. // NameEn: "Po Tong",
  3449. // XDateType: 1,
  3450. // XDate: "",
  3451. // XDateValue: 0,
  3452. // YDateType: 2,
  3453. // YDate: "",
  3454. // YDateValue: 30,
  3455. // IsShow: false,
  3456. // },
  3457. // {
  3458. // XEdbInfoId: 3,
  3459. // YEdbInfoId: 4,
  3460. // Name: "烂铁",
  3461. // NameEn: "Lan Tie",
  3462. // XDateType: 2,
  3463. // XDate: "",
  3464. // XDateValue: 30,
  3465. // YDateType: 3,
  3466. // YDate: "2023-02-17",
  3467. // YDateValue: 0,
  3468. // IsShow: false,
  3469. // },
  3470. // },
  3471. // ShowLine: false,
  3472. // ShowEquation: false,
  3473. // ShowR: false,
  3474. // },
  3475. // {
  3476. // Name: "系列2名称",
  3477. // Color: "恍恍惚惚色",
  3478. // EdbList: []data_manage.SectionScatterEdbItemReq{
  3479. // {
  3480. // XEdbInfoId: 1,
  3481. // YEdbInfoId: 2,
  3482. // Name: "破铜",
  3483. // NameEn: "Po Tong",
  3484. // XDateType: 3,
  3485. // XDate: "2023-02-17",
  3486. // XDateValue: 0,
  3487. // YDateType: 2,
  3488. // YDate: "",
  3489. // YDateValue: 60,
  3490. // IsShow: true,
  3491. // },
  3492. // {
  3493. // XEdbInfoId: 3,
  3494. // YEdbInfoId: 4,
  3495. // Name: "烂铁",
  3496. // NameEn: "Lan Tie",
  3497. // XDateType: 3,
  3498. // XDate: "2023-02-17",
  3499. // XDateValue: 0,
  3500. // YDateType: 2,
  3501. // YDate: "",
  3502. // YDateValue: 60,
  3503. // IsShow: false,
  3504. // },
  3505. // },
  3506. // ShowLine: false,
  3507. // ShowEquation: false,
  3508. // ShowR: false,
  3509. // },
  3510. // }
  3511. // rel := data_manage.SectionScatter{
  3512. // XName: "X轴名称",
  3513. // XNameEn: "X english name",
  3514. // XUnitName: "X轴单位",
  3515. // XUnitNameEn: "X unit english name",
  3516. // YName: "Y轴名称",
  3517. // YNameEn: "Y english name",
  3518. // YUnitName: "Y轴单位",
  3519. // YUnitNameEn: "Y unit english name",
  3520. // SeriesList: seriesList,
  3521. // }
  3522. // jsonByte, _ := json.Marshal(rel)
  3523. // utils.FileLog.Info(string(jsonByte))
  3524. //}
  3525. // func init() {
  3526. // var a, b float64
  3527. //
  3528. // testX := []float64{1, 3, 8, 7, 9}
  3529. // testY := []float64{10, 12, 24, 21, 34}
  3530. // {
  3531. // coordinateData := make([]utils.Coordinate, 0)
  3532. // for k, x := range testX {
  3533. // tmpCoordinate1 := utils.Coordinate{
  3534. // X: x,
  3535. // Y: testY[k],
  3536. // }
  3537. // coordinateData = append(coordinateData, tmpCoordinate1)
  3538. // }
  3539. // a, b = utils.GetLinearResult(coordinateData)
  3540. // trendLine := fmt.Sprintf("y=%sx+%s", utils.SubFloatToString(a, 4), utils.SubFloatToString(b, 4))
  3541. //
  3542. // fmt.Println(trendLine)
  3543. // }
  3544. //
  3545. // {
  3546. // r2 := utils.CalculationDecisive(testX, testY)
  3547. // fmt.Println(r2)
  3548. // }
  3549. // }
  3550. // FixChart 修复季节性图的日期数据
  3551. //func FixChart() {
  3552. // var condition string
  3553. // var pars []interface{}
  3554. //
  3555. // // 普通图表
  3556. // condition += ` AND chart_type = ? AND season_start_date != "" `
  3557. // pars = append(pars, 2)
  3558. //
  3559. // //获取图表信息
  3560. // list, err := data_manage.GetChartInfoListByCondition(condition, pars, 0, 10000)
  3561. // if err != nil {
  3562. // fmt.Println("err:", err)
  3563. // return
  3564. // }
  3565. //
  3566. // for _, v := range list {
  3567. // fmt.Println(v)
  3568. // v.SeasonStartDate = v.SeasonStartDate + "-01"
  3569. // v.SeasonEndDate = v.SeasonEndDate + "-12"
  3570. // err = v.Update([]string{"SeasonStartDate", "SeasonEndDate"})
  3571. // if err != nil {
  3572. // fmt.Println(v.ChartInfoId, ";", v.ChartName, "修改失敗")
  3573. // }
  3574. // data.EsAddOrEditChartInfo(v.ChartInfoId)
  3575. // data.EsAddOrEditMyChartInfoByChartInfoId(v.ChartInfoId)
  3576. // }
  3577. //}
  3578. // PreviewRadarChartInfo
  3579. // @Title 图表-获取预览的雷达图
  3580. // @Description 图表-获取预览的雷达图
  3581. // @Param ExtraConfig body data_manage.PreviewRadarChartReq true "type json string"
  3582. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  3583. // @router /chart_info/preview/radar [post]
  3584. func (this *ChartInfoController) PreviewRadarChartInfo() {
  3585. br := new(models.BaseResponse).Init()
  3586. defer func() {
  3587. this.Data["json"] = br
  3588. this.ServeJSON()
  3589. }()
  3590. var req data_manage.PreviewRadarChartReq
  3591. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3592. if err != nil {
  3593. br.Msg = "参数解析异常!"
  3594. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3595. return
  3596. }
  3597. chartInfo := new(data_manage.ChartInfoView)
  3598. sysUser := this.SysUser
  3599. if sysUser == nil {
  3600. br.Msg = "请登录"
  3601. br.ErrMsg = "请登录,SysUser Is Empty"
  3602. br.Ret = 408
  3603. return
  3604. }
  3605. chartType := utils.CHART_TYPE_RADAR
  3606. if len(req.ChartEdbInfoList) <= 0 {
  3607. br.Msg = "请选择指标"
  3608. return
  3609. }
  3610. edbInfoIdArr := make([]int, 0)
  3611. edbInfoNameMap := make(map[int]string)
  3612. for _, v := range req.ChartEdbInfoList {
  3613. edbInfoIdArr = append(edbInfoIdArr, v.EdbInfoId)
  3614. edbInfoNameMap[v.EdbInfoId] = v.EdbAliasName
  3615. }
  3616. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  3617. for _, v := range mappingList {
  3618. if name, ok := edbInfoNameMap[v.EdbInfoId]; ok {
  3619. v.EdbAliasName = name
  3620. }
  3621. }
  3622. // 获取图表中的指标数据
  3623. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, req.ExtraConfig, "")
  3624. if err != nil {
  3625. br.Msg = "获取失败"
  3626. if errMsg != `` {
  3627. br.Msg = errMsg
  3628. }
  3629. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3630. return
  3631. }
  3632. warnEdbList := make([]string, 0)
  3633. for _, v := range edbList {
  3634. if v.IsNullData {
  3635. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3636. }
  3637. }
  3638. if len(warnEdbList) > 0 {
  3639. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3640. }
  3641. //图表操作权限
  3642. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  3643. //判断是否需要展示英文标识
  3644. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  3645. chartInfo.Button = data_manage.ChartViewButton{
  3646. IsEdit: chartInfo.IsEdit,
  3647. IsEnChart: chartInfo.IsEnChart,
  3648. IsAdd: chartInfo.IsAdd,
  3649. IsCopy: true,
  3650. IsSetName: chartInfo.IsSetName,
  3651. }
  3652. // 图表的指标来源
  3653. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3654. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3655. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3656. resp := new(data_manage.ChartInfoDetailResp)
  3657. resp.ChartInfo = chartInfo
  3658. resp.EdbInfoList = edbList
  3659. resp.XEdbIdValue = xEdbIdValue
  3660. resp.YDataList = yDataList
  3661. resp.DataResp = dataResp
  3662. br.Ret = 200
  3663. br.Success = true
  3664. br.Msg = "获取成功"
  3665. br.Data = resp
  3666. }
  3667. // ChartInfoDetail
  3668. // @Title 获取图表详情-数据转换
  3669. // @Description 获取图表详情接口-数据转换
  3670. // @Param ChartInfoId query int true "图表id"
  3671. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"
  3672. // @Param StartDate query string true "自定义开始日期"
  3673. // @Param EndDate query string true "自定义结束日期"
  3674. // @Param Calendar query string true "公历/农历"
  3675. // @Param SeasonStartDate query string true "季节性图开始日期"
  3676. // @Param SeasonEndDate query string true "季节性图结束日期"
  3677. // @Param EdbInfoId query string true "指标ID,多个用英文逗号隔开"
  3678. // @Param ChartType query int true "生成样式:1:曲线图,2:季节性图"
  3679. // @Success 200 {object} data_manage.ChartInfoDetailResp
  3680. // @router /chart_info/convert/detail [get]
  3681. func (this *ChartInfoController) ChartInfoConvertDetail() {
  3682. br := new(models.BaseResponse).Init()
  3683. defer func() {
  3684. this.Data["json"] = br
  3685. this.ServeJSON()
  3686. }()
  3687. sysUser := this.SysUser
  3688. if sysUser == nil {
  3689. br.Msg = "请登录"
  3690. br.ErrMsg = "请登录,SysUser Is Empty"
  3691. br.Ret = 408
  3692. return
  3693. }
  3694. chartInfoId, _ := this.GetInt("ChartInfoId")
  3695. dateType, _ := this.GetInt("DateType")
  3696. fmt.Println("dateType:", dateType)
  3697. if dateType <= 0 {
  3698. dateType = 3
  3699. }
  3700. startDate := this.GetString("StartDate")
  3701. endDate := this.GetString("EndDate")
  3702. startYear, _ := this.GetInt("StartYear")
  3703. edbInfoId := this.GetString("EdbInfoId")
  3704. chartType, _ := this.GetInt("ChartType")
  3705. isAxis, _ := this.GetInt("IsAxis")
  3706. calendar := this.GetString("Calendar")
  3707. if calendar == "" {
  3708. calendar = "公历"
  3709. }
  3710. isConvert, _ := this.GetInt("IsConvert")
  3711. convertType, _ := this.GetInt("ConvertType")
  3712. convertValue, _ := this.GetFloat("ConvertValue")
  3713. convertUnit := this.GetString("ConvertUnit")
  3714. convertEnUnit := this.GetString("ConvertEnUnit")
  3715. resp := new(data_manage.ChartInfoDetailResp)
  3716. var err error
  3717. chartInfo := new(data_manage.ChartInfoView)
  3718. chartInfo.HaveOperaAuth = true
  3719. // 通过id获取详情
  3720. if chartInfoId > 0 {
  3721. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  3722. if err != nil {
  3723. if err.Error() == utils.ErrNoRow() {
  3724. br.Msg = "该图表已删除,自动查看下一图表"
  3725. br.ErrMsg = "该图表已删除,自动查看下一图表,Err:" + err.Error()
  3726. br.Ret = 406
  3727. return
  3728. }
  3729. br.Msg = "获取失败"
  3730. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3731. return
  3732. }
  3733. chartType = chartInfo.ChartType
  3734. // 获取主题样式
  3735. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  3736. if err != nil {
  3737. br.Msg = "获取失败"
  3738. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  3739. return
  3740. }
  3741. chartInfo.ChartThemeStyle = chartTheme.Config
  3742. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  3743. // 图表数据权限
  3744. {
  3745. // 图表分类
  3746. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  3747. if err != nil {
  3748. br.Msg = "获取失败"
  3749. br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
  3750. return
  3751. }
  3752. // 已授权分类id
  3753. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  3754. if err != nil {
  3755. br.Msg = "获取失败"
  3756. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  3757. return
  3758. }
  3759. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  3760. }
  3761. //图表操作权限
  3762. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  3763. chartInfo.Button = data_manage.ChartViewButton{
  3764. IsEdit: chartInfo.IsEdit,
  3765. IsEnChart: chartInfo.IsEnChart,
  3766. IsAdd: chartInfo.IsAdd,
  3767. IsCopy: true,
  3768. IsSetName: chartInfo.IsSetName,
  3769. }
  3770. }
  3771. // 有数据权限的话,获取图表的数据
  3772. if chartInfo.HaveOperaAuth {
  3773. mappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  3774. if chartInfoId > 0 {
  3775. mappingList, err = data_manage.GetChartEdbMappingList(chartInfoId)
  3776. if err != nil {
  3777. br.Msg = "获取失败"
  3778. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3779. return
  3780. }
  3781. } else {
  3782. if edbInfoId != "" {
  3783. mappingList, err = data_manage.GetChartEdbMappingListByEdbInfoId(edbInfoId)
  3784. if err != nil {
  3785. br.Msg = "获取失败"
  3786. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3787. return
  3788. }
  3789. if isConvert == 1 && len(mappingList) > 0 {
  3790. for i, _ := range mappingList {
  3791. mappingList[i].IsConvert = 1
  3792. mappingList[i].ConvertType = convertType
  3793. mappingList[i].ConvertValue = convertValue
  3794. mappingList[i].ConvertUnit = convertUnit
  3795. mappingList[i].ConvertEnUnit = convertEnUnit
  3796. }
  3797. }
  3798. }
  3799. }
  3800. // 图表额外数据参数
  3801. extraConfigStr := chartInfo.ExtraConfig
  3802. // 柱方图的一些配置
  3803. var barConfig data_manage.BarChartInfoReq
  3804. if chartInfo != nil && chartInfo.ChartType == 7 {
  3805. if chartInfo.BarConfig == `` {
  3806. br.Msg = "柱方图未配置"
  3807. br.ErrMsg = "柱方图未配置"
  3808. return
  3809. }
  3810. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  3811. if err != nil {
  3812. br.Msg = "柱方图配置异常"
  3813. br.ErrMsg = "柱方图配置异常"
  3814. return
  3815. }
  3816. extraConfigStr = chartInfo.BarConfig
  3817. }
  3818. var dateMax time.Time
  3819. if dateType == utils.DateTypeNYears {
  3820. for _, v := range mappingList {
  3821. if v.LatestDate != "" {
  3822. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  3823. if tErr != nil {
  3824. br.Msg = "获取失败"
  3825. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  3826. return
  3827. }
  3828. if lastDateT.After(dateMax) {
  3829. dateMax = lastDateT
  3830. }
  3831. }
  3832. }
  3833. }
  3834. // 开始/结束日期
  3835. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
  3836. // 获取图表中的指标数据
  3837. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartConvertEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig, isAxis)
  3838. if err != nil {
  3839. br.Msg = "获取失败"
  3840. if errMsg != `` {
  3841. br.Msg = errMsg
  3842. }
  3843. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3844. return
  3845. }
  3846. // 单位
  3847. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  3848. chartInfo.Unit = yDataList[0].Unit
  3849. chartInfo.UnitEn = yDataList[0].UnitEn
  3850. }
  3851. warnEdbList := make([]string, 0)
  3852. for _, v := range edbList {
  3853. if v.IsNullData {
  3854. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3855. }
  3856. }
  3857. if len(warnEdbList) > 0 {
  3858. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3859. }
  3860. if chartInfoId > 0 && chartInfo != nil {
  3861. //判断是否加入我的图库
  3862. {
  3863. var myChartCondition string
  3864. var myChartPars []interface{}
  3865. myChartCondition += ` AND a.admin_id=? `
  3866. myChartPars = append(myChartPars, sysUser.AdminId)
  3867. myChartCondition += ` AND a.chart_info_id=? `
  3868. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  3869. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  3870. if err != nil && err.Error() != utils.ErrNoRow() {
  3871. br.Msg = "获取失败"
  3872. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  3873. return
  3874. }
  3875. if myChartList != nil && len(myChartList) > 0 {
  3876. chartInfo.IsAdd = true
  3877. chartInfo.MyChartId = myChartList[0].MyChartId
  3878. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  3879. }
  3880. }
  3881. if chartInfo.ChartType == 2 {
  3882. if chartInfo.SeasonStartDate != "" {
  3883. chartInfo.StartDate = chartInfo.SeasonStartDate
  3884. chartInfo.EndDate = chartInfo.SeasonEndDate
  3885. if chartInfo.DateType == 3 {
  3886. chartInfo.DateType = 5
  3887. }
  3888. }
  3889. }
  3890. }
  3891. // 图表的指标来源
  3892. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3893. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3894. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3895. //判断是否需要展示英文标识
  3896. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  3897. resp.EdbInfoList = edbList
  3898. resp.XEdbIdValue = xEdbIdValue
  3899. resp.YDataList = yDataList
  3900. resp.DataResp = dataResp
  3901. resp.BarChartInfo = barConfig
  3902. }
  3903. resp.ChartInfo = chartInfo
  3904. br.Ret = 200
  3905. br.Success = true
  3906. br.Msg = "获取成功"
  3907. br.Data = resp
  3908. }
  3909. // UploadToForum
  3910. // @Title 上传至社区
  3911. // @Description 上传至社区
  3912. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  3913. // @Success Ret=200 保存成功
  3914. // @router /chart_info/forum/upload [post]
  3915. func (this *ChartInfoController) UploadToForum() {
  3916. br := new(models.BaseResponse).Init()
  3917. defer func() {
  3918. this.Data["json"] = br
  3919. this.ServeJSON()
  3920. }()
  3921. sysUser := this.SysUser
  3922. if sysUser == nil {
  3923. br.Msg = "请登录"
  3924. br.ErrMsg = "请登录,SysUser Is Empty"
  3925. br.Ret = 408
  3926. return
  3927. }
  3928. var req eta_forum.UploadChartToForumReq
  3929. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3930. if err != nil {
  3931. br.Msg = "参数解析异常!"
  3932. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3933. return
  3934. }
  3935. if req.ChartInfoId <= 0 {
  3936. br.Msg = "请选择图表"
  3937. return
  3938. }
  3939. err, errMsg := eta_forum.UploadChart(req.ChartInfoId, req.Description, sysUser)
  3940. if err != nil {
  3941. br.Msg = errMsg
  3942. br.ErrMsg = err.Error()
  3943. return
  3944. }
  3945. br.Ret = 200
  3946. br.Success = true
  3947. br.Msg = "保存成功"
  3948. }
  3949. // UpdateToForum
  3950. // @Title 更新社区图表
  3951. // @Description 更新社区图表
  3952. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  3953. // @Success Ret=200 保存成功
  3954. // @router /chart_info/forum/update [post]
  3955. func (this *ChartInfoController) UpdateToForum() {
  3956. br := new(models.BaseResponse).Init()
  3957. defer func() {
  3958. this.Data["json"] = br
  3959. this.ServeJSON()
  3960. }()
  3961. sysUser := this.SysUser
  3962. if sysUser == nil {
  3963. br.Msg = "请登录"
  3964. br.ErrMsg = "请登录,SysUser Is Empty"
  3965. br.Ret = 408
  3966. return
  3967. }
  3968. var req eta_forum.UpdateChartToForumReq
  3969. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3970. if err != nil {
  3971. br.Msg = "参数解析异常!"
  3972. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3973. return
  3974. }
  3975. if req.ChartInfoId <= 0 {
  3976. br.Msg = "请选择图表"
  3977. return
  3978. }
  3979. err, errMsg := eta_forum.UpdateChart(req.ChartInfoId)
  3980. if err != nil {
  3981. br.Msg = errMsg
  3982. br.ErrMsg = err.Error()
  3983. return
  3984. }
  3985. br.Ret = 200
  3986. br.Success = true
  3987. br.Msg = "保存成功"
  3988. }
  3989. // ForumDelete
  3990. // @Title 从社区撤回
  3991. // @Description 从社区撤回
  3992. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  3993. // @Success Ret=200 保存成功
  3994. // @router /chart_info/forum/delete [post]
  3995. func (this *ChartInfoController) ForumDelete() {
  3996. br := new(models.BaseResponse).Init()
  3997. defer func() {
  3998. this.Data["json"] = br
  3999. this.ServeJSON()
  4000. }()
  4001. sysUser := this.SysUser
  4002. if sysUser == nil {
  4003. br.Msg = "请登录"
  4004. br.ErrMsg = "请登录,SysUser Is Empty"
  4005. br.Ret = 408
  4006. return
  4007. }
  4008. var req eta_forum.DeleteChartReq
  4009. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4010. if err != nil {
  4011. br.Msg = "参数解析异常!"
  4012. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4013. return
  4014. }
  4015. if req.ChartInfoId <= 0 {
  4016. br.Msg = "请选择图表"
  4017. return
  4018. }
  4019. err, errMsg := eta_forum.DeleteChart(req.ChartInfoId)
  4020. if err != nil {
  4021. br.Msg = errMsg
  4022. br.ErrMsg = err.Error()
  4023. return
  4024. }
  4025. br.Ret = 200
  4026. br.Success = true
  4027. br.Msg = "操作成功"
  4028. }
  4029. // PreviewSeasonChartInfo
  4030. // @Title 图表-获取预览的季节性图
  4031. // @Description 图表-获取预览的季节性图
  4032. // @Param ExtraConfig body data_manage.PreviewRadarChartReq true "type json string"
  4033. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  4034. // @router /chart_info/preview/season [post]
  4035. func (this *ChartInfoController) PreviewSeasonChartInfo() {
  4036. br := new(models.BaseResponse).Init()
  4037. defer func() {
  4038. this.Data["json"] = br
  4039. this.ServeJSON()
  4040. }()
  4041. var req data_manage.PreviewSeasonChartReq
  4042. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4043. if err != nil {
  4044. br.Msg = "参数解析异常!"
  4045. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4046. return
  4047. }
  4048. chartInfo := new(data_manage.ChartInfoView)
  4049. sysUser := this.SysUser
  4050. if sysUser == nil {
  4051. br.Msg = "请登录"
  4052. br.ErrMsg = "请登录,SysUser Is Empty"
  4053. br.Ret = 408
  4054. return
  4055. }
  4056. chartType := utils.CHART_TYPE_SEASON
  4057. if len(req.ChartEdbInfoList) <= 0 {
  4058. br.Msg = "请选择指标"
  4059. return
  4060. }
  4061. edbInfoIdArr := make([]int, 0)
  4062. edbInfoNameMap := make(map[int]string)
  4063. for _, v := range req.ChartEdbInfoList {
  4064. edbInfoIdArr = append(edbInfoIdArr, v.EdbInfoId)
  4065. edbInfoNameMap[v.EdbInfoId] = v.EdbAliasName
  4066. }
  4067. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  4068. for _, v := range mappingList {
  4069. if name, ok := edbInfoNameMap[v.EdbInfoId]; ok {
  4070. v.EdbAliasName = name
  4071. }
  4072. }
  4073. var seasonExtraConfig string
  4074. seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
  4075. if tErr != nil {
  4076. br.Msg = "季节性图表配置信息异常"
  4077. br.ErrMsg = "季节性图表配置信息异常,Err:" + tErr.Error()
  4078. return
  4079. }
  4080. seasonExtraConfig = string(seasonExtra)
  4081. // 获取图表中的指标数据
  4082. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, "", seasonExtraConfig)
  4083. if err != nil {
  4084. br.Msg = "获取失败"
  4085. if errMsg != `` {
  4086. br.Msg = errMsg
  4087. }
  4088. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  4089. return
  4090. }
  4091. warnEdbList := make([]string, 0)
  4092. for _, v := range edbList {
  4093. if v.IsNullData {
  4094. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  4095. }
  4096. }
  4097. if len(warnEdbList) > 0 {
  4098. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  4099. }
  4100. //图表操作权限
  4101. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  4102. //判断是否需要展示英文标识
  4103. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  4104. chartInfo.Button = data_manage.ChartViewButton{
  4105. IsEdit: chartInfo.IsEdit,
  4106. IsEnChart: chartInfo.IsEnChart,
  4107. IsAdd: chartInfo.IsAdd,
  4108. IsCopy: true,
  4109. IsSetName: chartInfo.IsSetName,
  4110. }
  4111. // 图表的指标来源
  4112. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  4113. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  4114. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  4115. resp := new(data_manage.ChartInfoDetailResp)
  4116. resp.ChartInfo = chartInfo
  4117. resp.EdbInfoList = edbList
  4118. resp.XEdbIdValue = xEdbIdValue
  4119. resp.YDataList = yDataList
  4120. resp.DataResp = dataResp
  4121. br.Ret = 200
  4122. br.Success = true
  4123. br.Msg = "获取成功"
  4124. br.Data = resp
  4125. }
  4126. // ChartInfoImgSetBySvg
  4127. // @Title 图表图片上传
  4128. // @Param Img query string true "图片"
  4129. // @Param ChartInfoId query int true "图表ID"
  4130. // @Success 200 {object} models.ResourceResp
  4131. // @router /chart_info/image/set_by_svg [post]
  4132. func (this *ChartInfoController) ChartInfoImgSetBySvg() {
  4133. br := new(models.BaseResponse).Init()
  4134. defer func() {
  4135. this.Data["json"] = br
  4136. this.ServeJSON()
  4137. }()
  4138. imgData := this.GetString("Img")
  4139. if imgData == "" {
  4140. br.Msg = "图片参数错误"
  4141. br.ErrMsg = "图片参数错误,Img Is Empty"
  4142. return
  4143. }
  4144. chartInfoId, _ := this.GetInt("ChartInfoId", 0)
  4145. if chartInfoId <= 0 {
  4146. br.Msg = "图片参数错误"
  4147. br.ErrMsg = "图片参数错误,ChartInfoId Is Empty"
  4148. return
  4149. }
  4150. resp := new(models.ResourceResp)
  4151. // 通过svg图片生成图片资源地址
  4152. resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData)
  4153. if err != nil {
  4154. br.Msg = errMsg
  4155. br.ErrMsg = err.Error()
  4156. return
  4157. }
  4158. // 修改图表的缩略图信息
  4159. if chartInfoId > 0 && resourceUrl != "" {
  4160. err = data_manage.EditChartInfoImageV2(chartInfoId, resourceUrl)
  4161. if err != nil {
  4162. br.Msg = "保存失败"
  4163. br.ErrMsg = "保存失败,Err:" + err.Error()
  4164. return
  4165. }
  4166. //修改es数据
  4167. go data.EsAddOrEditChartInfo(chartInfoId)
  4168. //修改my eta es数据
  4169. go data.EsAddOrEditMyChartInfoByChartInfoId(chartInfoId)
  4170. }
  4171. resp.ResourceUrl = resourceUrl
  4172. resp.Source = "convert"
  4173. //resp.CacheKey = imgDataKey
  4174. br.Msg = "上传成功"
  4175. br.Ret = 200
  4176. br.Success = true
  4177. br.Data = resp
  4178. return
  4179. }
  4180. // @Title ETA图表列表接口
  4181. // @Description ETA图表列表接口
  4182. // @Param PageSize query int true "每页数据条数"
  4183. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4184. // @Param ChartClassifyId query int true "分类id"
  4185. // @Param KeyWord query string true "搜索关键词"
  4186. // @Param IsShowMe query bool true "是否只看我的,true、false"
  4187. // @Success 200 {object} data_manage.ChartListResp
  4188. // @router /chart/list [get]
  4189. func (this *ChartInfoController) ChartList() {
  4190. br := new(models.BaseResponse).Init()
  4191. defer func() {
  4192. this.Data["json"] = br
  4193. this.ServeJSON()
  4194. }()
  4195. sysUser := this.SysUser
  4196. if sysUser == nil {
  4197. br.Msg = "请登录"
  4198. br.ErrMsg = "请登录,SysUser Is Empty"
  4199. br.Ret = 408
  4200. return
  4201. }
  4202. subClassify, _ := this.GetBool("SubClassify")
  4203. chartClassifyIdsStr := this.GetString("ChartClassifyIds")
  4204. chartClassifyIds := strings.Split(chartClassifyIdsStr, ",")
  4205. pageSize, _ := this.GetInt("PageSize")
  4206. currentIndex, _ := this.GetInt("CurrentIndex")
  4207. keyWord := this.GetString("KeyWord")
  4208. sysUserIds := this.GetString("SysUserIds")
  4209. chartTypeIds := this.GetString("ChartTypeIds")
  4210. var total int
  4211. page := paging.GetPaging(currentIndex, pageSize, total)
  4212. var startSize int
  4213. if pageSize <= 0 {
  4214. pageSize = utils.PageSize20
  4215. }
  4216. if currentIndex <= 0 {
  4217. currentIndex = 1
  4218. }
  4219. startSize = paging.StartIndex(currentIndex, pageSize)
  4220. var condition string
  4221. var pars []interface{}
  4222. // 普通图表
  4223. condition += ` AND source = ? `
  4224. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  4225. if len(chartClassifyIdsStr) > 0 {
  4226. if !subClassify {
  4227. chartClassifyId, err := data_manage.GetChartClassifyByIdsNoSubClassify(chartClassifyIds)
  4228. if err != nil && err.Error() != utils.ErrNoRow() {
  4229. br.Msg = "获取图表信息失败"
  4230. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  4231. return
  4232. }
  4233. condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  4234. //pars = append(pars, chartClassifyId)
  4235. } else {
  4236. //chartClassifyId, err := data_manage.GetChartClassifyByIds(chartClassifyIds)
  4237. //if err != nil && err.Error() != utils.ErrNoRow() {
  4238. // br.Msg = "获取图表信息失败"
  4239. // br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  4240. // return
  4241. //}
  4242. //condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  4243. //pars = append(pars, chartClassifyId)
  4244. list, e := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
  4245. if e != nil {
  4246. br.Msg = "获取失败"
  4247. br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", e)
  4248. return
  4249. }
  4250. finalClassifyIds := make([]int, 0)
  4251. parents := data.GetChartClassifyChildrenRecursiveByParentIds(list, chartClassifyIds)
  4252. sort.Slice(parents, func(i, j int) bool {
  4253. return parents[i].Level < parents[i].Level
  4254. })
  4255. for _, v := range parents {
  4256. finalClassifyIds = append(finalClassifyIds, v.ChartClassifyId)
  4257. }
  4258. condition += " AND chart_classify_id IN(" + utils.GetOrmInReplace(len(finalClassifyIds)) + ") "
  4259. pars = append(pars, finalClassifyIds)
  4260. }
  4261. }
  4262. if keyWord != "" {
  4263. condition += ` AND ( chart_name LIKE '%` + keyWord + `%' OR chart_name_en LIKE '%` + keyWord + `%' )`
  4264. }
  4265. if sysUserIds != "" {
  4266. adminIds := strings.Split(sysUserIds, ",")
  4267. if len(adminIds) == 0 {
  4268. br.Msg = "请选择正确的创建人"
  4269. return
  4270. }
  4271. adminIdsSlice := make([]int, 0)
  4272. for _, adminId := range adminIds {
  4273. adminIdInt, e := strconv.Atoi(adminId)
  4274. if e != nil {
  4275. br.Msg = "请选择正确的创建人"
  4276. return
  4277. }
  4278. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  4279. }
  4280. condition += " AND sys_user_id in (" + utils.GetOrmInReplace(len(adminIds)) + ") "
  4281. pars = append(pars, adminIdsSlice)
  4282. }
  4283. if chartTypeIds != "" {
  4284. chartTypeIdList := strings.Split(chartTypeIds, ",")
  4285. condition += " AND chart_type in (" + utils.GetOrmInReplace(len(chartTypeIdList)) + ") "
  4286. pars = append(pars, chartTypeIdList)
  4287. }
  4288. //只看我的
  4289. //isShowMe, _ := this.GetBool("IsShowMe")
  4290. //if isShowMe {
  4291. // condition += ` AND sys_user_id = ? `
  4292. // pars = append(pars, sysUser.AdminId)
  4293. //}
  4294. // 获取当前账号的不可见指标
  4295. noPermissionChartIdList := make([]int, 0)
  4296. {
  4297. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4298. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  4299. if err != nil && err.Error() != utils.ErrNoRow() {
  4300. br.Msg = "获取失败"
  4301. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  4302. return
  4303. }
  4304. for _, v := range confList {
  4305. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  4306. }
  4307. }
  4308. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  4309. if lenNoPermissionChartIdList > 0 {
  4310. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  4311. pars = append(pars, noPermissionChartIdList)
  4312. }
  4313. //获取图表信息
  4314. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  4315. if err != nil && err.Error() != utils.ErrNoRow() {
  4316. br.Success = true
  4317. br.Msg = "获取图表信息失败"
  4318. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  4319. return
  4320. }
  4321. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  4322. if err != nil && err.Error() != utils.ErrNoRow() {
  4323. br.Msg = "获取图表信息失败"
  4324. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  4325. return
  4326. }
  4327. myChartMap := make(map[int]*data_manage.MyChartView)
  4328. for _, v := range myChartList {
  4329. myChartMap[v.ChartInfoId] = v
  4330. }
  4331. listLen := len(list)
  4332. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  4333. if listLen > 0 {
  4334. // 分类id
  4335. classifyIdList := make([]int, 0)
  4336. // 当前列表中的分类map
  4337. classifyMap := make(map[int]*data_manage.ChartClassify)
  4338. for _, v := range list {
  4339. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  4340. }
  4341. classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  4342. if err != nil {
  4343. br.Msg = "获取失败"
  4344. br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
  4345. return
  4346. }
  4347. for _, v := range classifyList {
  4348. classifyMap[v.ChartClassifyId] = v
  4349. }
  4350. // 已授权分类id
  4351. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  4352. if err != nil {
  4353. br.Msg = "获取失败"
  4354. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  4355. return
  4356. }
  4357. // 权限
  4358. for k, chartViewInfo := range list {
  4359. if currClassify, ok := classifyMap[chartViewInfo.ChartClassifyId]; ok {
  4360. list[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartViewInfo.IsJoinPermission, currClassify.IsJoinPermission, chartViewInfo.ChartInfoId, chartViewInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  4361. }
  4362. }
  4363. chartInfoIds := ""
  4364. for _, v := range list {
  4365. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  4366. }
  4367. if chartInfoIds != "" {
  4368. chartInfoIds = strings.Trim(chartInfoIds, ",")
  4369. //判断是否需要展示英文标识
  4370. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  4371. if e != nil {
  4372. br.Msg = "获取失败"
  4373. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  4374. return
  4375. }
  4376. for _, v := range edbList {
  4377. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  4378. }
  4379. }
  4380. }
  4381. listTmp, err := data_manage.GetChartTypeList()
  4382. if err != nil {
  4383. br.Msg = "获取图表类型失败"
  4384. br.ErrMsg = "获取图表类型失败,Err:" + err.Error()
  4385. return
  4386. }
  4387. //遍历list,将id和name组成map
  4388. chartTypeMap := make(map[int]data_manage.ChartType)
  4389. for _, v := range listTmp {
  4390. chartTypeMap[v.ChartTypeId] = v
  4391. }
  4392. for i := 0; i < listLen; i++ {
  4393. //判断是否需要展示英文标识
  4394. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  4395. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  4396. }
  4397. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  4398. list[i].IsAdd = true
  4399. list[i].MyChartId = existItem.MyChartId
  4400. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  4401. }
  4402. list[i].ChartTypeName = chartTypeMap[list[i].ChartType].ChartTypeName
  4403. list[i].ChartTypeNameEn = chartTypeMap[list[i].ChartType].ChartTypeNameEn
  4404. }
  4405. resp := new(data_manage.ChartListResp)
  4406. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  4407. items := make([]*data_manage.ChartInfoView, 0)
  4408. resp.Paging = page
  4409. resp.List = items
  4410. br.Ret = 200
  4411. br.Success = true
  4412. br.Msg = "获取成功"
  4413. return
  4414. }
  4415. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  4416. if err != nil && err.Error() != utils.ErrNoRow() {
  4417. br.Msg = "获取指标信息失败"
  4418. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  4419. return
  4420. }
  4421. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  4422. resp.Paging = page
  4423. resp.List = list
  4424. br.Ret = 200
  4425. br.Success = true
  4426. br.Msg = "获取成功"
  4427. br.Data = resp
  4428. }
  4429. // ModifyChartList
  4430. // @Title 批量修改图表
  4431. // @Description 批量修改图表
  4432. // @Param SysUserIds query string true "根据创建人查询"
  4433. // @Param ChartClassifyIds query string true "图片分类id"
  4434. // @Success 200 {object} models.ChartClassifyListResp
  4435. // @router /modify/chartList [post]
  4436. func (this *ChartInfoController) ModifyChartList() {
  4437. br := new(models.BaseResponse).Init()
  4438. defer func() {
  4439. this.Data["json"] = br
  4440. this.ServeJSON()
  4441. }()
  4442. sysUser := this.SysUser
  4443. if sysUser == nil {
  4444. br.Msg = "请登录"
  4445. br.ErrMsg = "请登录,SysUser Is Empty"
  4446. br.Ret = 408
  4447. return
  4448. }
  4449. var req data_manage.ModifyChartListReq
  4450. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4451. if err != nil {
  4452. br.Msg = "参数解析异常!"
  4453. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4454. return
  4455. }
  4456. if !req.SelectAll && req.ChartInfoIds == "" {
  4457. br.Msg = "请选择图表"
  4458. return
  4459. }
  4460. if req.ChartClassifyId < 0 {
  4461. br.Msg = "请选择新分类"
  4462. return
  4463. }
  4464. var chartIds []int
  4465. if req.SelectAll {
  4466. //根据查询条件筛选
  4467. chartClassifyIds := strings.Split(req.ChartClassifyIds, ",")
  4468. sysUserIds := req.SysUserIds
  4469. keyword := req.KeyWord
  4470. chartTypeIdsStr := req.ChartTypeIds
  4471. condition := " AND source = ? "
  4472. pars := make([]interface{}, 0)
  4473. pars = append(pars, utils.CHART_SOURCE_DEFAULT)
  4474. if len(chartClassifyIds) > 0 {
  4475. if !req.SubClassify {
  4476. chartClassifyId, err := data_manage.GetChartClassifyByIdsNoSubClassify(chartClassifyIds)
  4477. if err != nil && err.Error() != utils.ErrNoRow() {
  4478. br.Msg = "获取图表信息失败"
  4479. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  4480. return
  4481. }
  4482. condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  4483. //pars = append(pars, chartClassifyId)
  4484. } else {
  4485. //chartClassifyId, err := data_manage.GetChartClassifyByIds(chartClassifyIds)
  4486. //if err != nil && err.Error() != utils.ErrNoRow() {
  4487. // br.Msg = "获取图表信息失败"
  4488. // br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  4489. // return
  4490. //}
  4491. //condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  4492. //pars = append(pars, chartClassifyId)
  4493. list, e := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
  4494. if e != nil {
  4495. br.Msg = "获取失败"
  4496. br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", e)
  4497. return
  4498. }
  4499. finalClassifyIds := make([]int, 0)
  4500. parents := data.GetChartClassifyChildrenRecursiveByParentIds(list, chartClassifyIds)
  4501. sort.Slice(parents, func(i, j int) bool {
  4502. return parents[i].Level < parents[i].Level
  4503. })
  4504. for _, v := range parents {
  4505. finalClassifyIds = append(finalClassifyIds, v.ChartClassifyId)
  4506. }
  4507. condition += " AND chart_classify_id IN(" + utils.GetOrmInReplace(len(finalClassifyIds)) + ") "
  4508. pars = append(pars, finalClassifyIds)
  4509. }
  4510. }
  4511. if sysUserIds != "" {
  4512. adminIds := strings.Split(sysUserIds, ",")
  4513. if len(adminIds) == 0 {
  4514. br.Msg = "请选择正确的创建人"
  4515. return
  4516. }
  4517. adminIdsSlice := make([]int, 0)
  4518. for _, adminId := range adminIds {
  4519. adminIdInt, e := strconv.Atoi(adminId)
  4520. if e != nil {
  4521. br.Msg = "请选择正确的创建人"
  4522. return
  4523. }
  4524. adminIdsSlice = append(adminIdsSlice, adminIdInt)
  4525. }
  4526. condition += " AND sys_user_id in (" + utils.GetOrmInReplace(len(adminIds)) + ") "
  4527. pars = append(pars, adminIdsSlice)
  4528. }
  4529. if keyword != "" {
  4530. condition = " AND chart_name LIKE ? "
  4531. pars = append(pars, utils.GetLikeKeyword(keyword))
  4532. }
  4533. if chartTypeIdsStr != "" {
  4534. chartTypeIds := strings.Split(chartTypeIdsStr, ",")
  4535. if len(chartTypeIds) == 0 {
  4536. br.Msg = "请选择正确的图表类型"
  4537. return
  4538. }
  4539. condition += " AND chart_type IN(" + utils.GetOrmInReplace(len(chartTypeIds)) + ") "
  4540. pars = append(pars, chartTypeIds)
  4541. }
  4542. allChartInfo, err := data_manage.GetChartInfoItemsByCondition(condition, pars)
  4543. if err != nil {
  4544. br.Msg = "获取失败"
  4545. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  4546. return
  4547. }
  4548. // 判断是否超过100 个
  4549. if len(allChartInfo) > 100 {
  4550. br.Msg = "最多只能选择100个图表"
  4551. return
  4552. }
  4553. for _, v := range allChartInfo {
  4554. chartIds = append(chartIds, v.ChartInfoId)
  4555. }
  4556. } else {
  4557. chartIdStr := strings.Split(req.ChartInfoIds, ",")
  4558. if len(chartIdStr) == 0 {
  4559. br.Msg = "请选择正确的图表"
  4560. return
  4561. }
  4562. for _, id := range chartIdStr {
  4563. tmp, e := strconv.Atoi(id)
  4564. if e != nil {
  4565. br.Msg = "请选择正确的分类"
  4566. return
  4567. }
  4568. chartIds = append(chartIds, tmp)
  4569. }
  4570. // 判断是否超过100 个
  4571. if len(chartIds) > 100 {
  4572. br.Msg = "最多只能选择100个图表"
  4573. return
  4574. }
  4575. }
  4576. if len(chartIds) == 0 {
  4577. br.Msg = "请选择正确的图表"
  4578. return
  4579. }
  4580. err = data_manage.UpdateChartClassifyIdByChartInfoId(chartIds, req.ChartClassifyId)
  4581. if err != nil {
  4582. br.Msg = "更新失败"
  4583. br.ErrMsg = "更新图表分类失败,Err:" + err.Error()
  4584. return
  4585. }
  4586. br.Ret = 200
  4587. br.Success = true
  4588. br.Msg = "操作成功"
  4589. }