chart_info.go 131 KB

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