chart_info.go 132 KB

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