chart_info.go 150 KB

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