chart_info.go 128 KB

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