chart_info.go 121 KB

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