chart_info.go 129 KB

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