chart_info.go 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912
  1. package range_analysis
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/data_manage/chart_theme"
  8. "eta_gn/eta_api/models/system"
  9. "eta_gn/eta_api/services/data"
  10. "eta_gn/eta_api/services/data/data_manage_permission"
  11. rangeServ "eta_gn/eta_api/services/data/range_analysis"
  12. "eta_gn/eta_api/utils"
  13. "fmt"
  14. "github.com/rdlucklib/rdluck_tools/paging"
  15. "sort"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. type RangeChartChartInfoController struct {
  21. controllers.BaseAuthController
  22. }
  23. // @router /chart_info/preview [post]
  24. func (this *RangeChartChartInfoController) Preview() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. sysUser := this.SysUser
  31. if sysUser == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,SysUser Is Empty"
  34. br.Ret = 408
  35. return
  36. }
  37. var req data_manage.ChartRangeAnalysisPreviewReq
  38. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  39. br.Msg = "参数解析异常!"
  40. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  41. return
  42. }
  43. if len(req.ChartEdbInfoList) == 0 {
  44. br.Msg = "请选择指标"
  45. return
  46. }
  47. err, msg, isSendEmail := rangeServ.CheckChartRangeExtraConfig(req.ExtraConfig)
  48. if err != nil {
  49. br.Msg = msg
  50. br.ErrMsg = err.Error()
  51. br.IsSendEmail = isSendEmail
  52. return
  53. }
  54. edbInfoMappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  55. for _, v := range req.ChartEdbInfoList {
  56. edbInfoMapping, e := data_manage.GetChartEdbMappingByEdbInfoId(v.EdbInfoId)
  57. if e != nil {
  58. if utils.IsErrNoRow(e) {
  59. br.Msg = v.EdbAliasName + "指标不存在"
  60. br.ErrMsg = v.EdbAliasName + "指标不存在"
  61. return
  62. }
  63. br.Msg = "获取失败"
  64. br.ErrMsg = "获取区间计算图表, A指标mapping信息失败, Err:" + e.Error()
  65. return
  66. }
  67. if v.EdbAliasName != "" {
  68. edbInfoMapping.EdbAliasName = v.EdbAliasName
  69. }
  70. edbInfoMapping.IsAxis = v.IsAxis
  71. edbInfoMappingList = append(edbInfoMappingList, edbInfoMapping)
  72. }
  73. chartInfo := new(data_manage.ChartInfoView)
  74. chartInfo.ChartType = 1
  75. chartInfo.Source = utils.CHART_SOURCE_RANGE_ANALYSIS
  76. chartThemeType, err := chart_theme.GetChartThemeTypeByChartTypeAndSource(chartInfo.ChartType, 1)
  77. if err != nil {
  78. return
  79. }
  80. chartTheme, err := data.GetChartThemeConfig(chartThemeType.DefaultChartThemeId, utils.CHART_SOURCE_DEFAULT, chartInfo.ChartType)
  81. if err != nil {
  82. br.Msg = "获取失败"
  83. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  84. return
  85. }
  86. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  87. chartInfo.ChartThemeStyle = chartTheme.Config
  88. edbList, xEdbIdValue, dataResp, e := rangeServ.GetChartDataByEdbInfoList(0, req.DateType, req.StartYear, req.StartDate, req.EndDate, edbInfoMappingList, &req.ExtraConfig)
  89. if e != nil {
  90. br.Msg = "获取失败"
  91. br.ErrMsg = "获取区间计算图表, 图表计算值失败, Err:" + e.Error()
  92. return
  93. }
  94. if req.ExtraConfig.MultipleGraphConfigId == 0 {
  95. multipleGraphConfig := &data_manage.MultipleGraphConfig{
  96. SysUserId: sysUser.AdminId,
  97. SysUserRealName: sysUser.RealName,
  98. ModifyTime: time.Now(),
  99. CreateTime: time.Now(),
  100. }
  101. err = data_manage.AddMultipleGraphConfig(multipleGraphConfig)
  102. if err != nil {
  103. br.Msg = "获取失败"
  104. br.ErrMsg = "新增区间计算图表配置失败, Err: " + err.Error()
  105. return
  106. }
  107. dataResp.MultipleGraphConfigId = multipleGraphConfig.MultipleGraphConfigId
  108. }
  109. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  110. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  111. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  112. resp := new(data_manage.ChartInfoDetailResp)
  113. resp.ChartInfo = chartInfo
  114. resp.EdbInfoList = edbList
  115. resp.XEdbIdValue = xEdbIdValue
  116. resp.DataResp = dataResp
  117. br.Data = resp
  118. br.Ret = 200
  119. br.Success = true
  120. br.Msg = "获取成功"
  121. }
  122. // @router /chart_info/add [post]
  123. func (this *RangeChartChartInfoController) Add() {
  124. br := new(models.BaseResponse).Init()
  125. defer func() {
  126. this.Data["json"] = br
  127. this.ServeJSON()
  128. }()
  129. sysUser := this.SysUser
  130. if sysUser == nil {
  131. br.Msg = "请登录"
  132. br.ErrMsg = "请登录,SysUser Is Empty"
  133. br.Ret = 408
  134. return
  135. }
  136. deleteCache := true
  137. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  138. defer func() {
  139. if deleteCache {
  140. _ = utils.Rc.Delete(cacheKey)
  141. }
  142. }()
  143. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  144. deleteCache = false
  145. br.Msg = "系统处理中,请稍后重试!"
  146. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  147. return
  148. }
  149. var req data_manage.AddChartInfoReq
  150. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  151. if err != nil {
  152. br.Msg = "参数解析异常!"
  153. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  154. return
  155. }
  156. if req.DateType == 0 {
  157. req.DateType = 3
  158. }
  159. chartInfo, err, errMsg, isSendEmail := rangeServ.AddChartInfo(req, utils.CHART_SOURCE_RANGE_ANALYSIS, sysUser, this.Lang)
  160. if err != nil {
  161. br.Msg = "保存失败"
  162. if errMsg != `` {
  163. br.Msg = errMsg
  164. }
  165. br.ErrMsg = err.Error()
  166. br.IsSendEmail = isSendEmail
  167. return
  168. }
  169. {
  170. chartLog := new(data_manage.ChartInfoLog)
  171. chartLog.ChartInfoId = chartInfo.ChartInfoId
  172. chartLog.ChartName = req.ChartName
  173. chartLog.ChartClassifyId = req.ChartClassifyId
  174. chartLog.SysUserId = sysUser.AdminId
  175. chartLog.SysUserRealName = sysUser.RealName
  176. chartLog.UniqueCode = chartInfo.UniqueCode
  177. chartLog.CreateTime = time.Now()
  178. chartLog.Content = string(this.Ctx.Input.RequestBody)
  179. chartLog.Status = "新增区间计算图表"
  180. chartLog.Method = this.Ctx.Input.URI()
  181. go data_manage.AddChartInfoLog(chartLog)
  182. }
  183. resp := new(data_manage.AddChartInfoResp)
  184. resp.ChartInfoId = chartInfo.ChartInfoId
  185. resp.UniqueCode = chartInfo.UniqueCode
  186. resp.ChartType = chartInfo.ChartType
  187. br.Ret = 200
  188. br.Success = true
  189. br.Msg = "保存成功"
  190. br.Data = resp
  191. br.IsAddLog = true
  192. }
  193. // @router /chart_info/edit [post]
  194. func (this *RangeChartChartInfoController) Edit() {
  195. br := new(models.BaseResponse).Init()
  196. defer func() {
  197. this.Data["json"] = br
  198. this.ServeJSON()
  199. }()
  200. sysUser := this.SysUser
  201. if sysUser == nil {
  202. br.Msg = "请登录"
  203. br.ErrMsg = "请登录,SysUser Is Empty"
  204. br.Ret = 408
  205. return
  206. }
  207. var req data_manage.EditChartInfoReq
  208. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  209. if err != nil {
  210. br.Msg = "参数解析异常!"
  211. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  212. return
  213. }
  214. chartItem, err, errMsg, isSendEmail := rangeServ.EditChartInfo(req, sysUser, this.Lang)
  215. if err != nil {
  216. br.Msg = "保存失败"
  217. if errMsg != `` {
  218. br.Msg = errMsg
  219. }
  220. br.ErrMsg = err.Error()
  221. br.IsSendEmail = isSendEmail
  222. return
  223. }
  224. resp := new(data_manage.AddChartInfoResp)
  225. resp.ChartInfoId = chartItem.ChartInfoId
  226. resp.UniqueCode = chartItem.UniqueCode
  227. resp.ChartType = req.ChartType
  228. {
  229. chartLog := new(data_manage.ChartInfoLog)
  230. chartLog.ChartName = chartItem.ChartName
  231. chartLog.ChartInfoId = req.ChartInfoId
  232. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  233. chartLog.SysUserId = sysUser.AdminId
  234. chartLog.SysUserRealName = sysUser.RealName
  235. chartLog.UniqueCode = chartItem.UniqueCode
  236. chartLog.CreateTime = time.Now()
  237. chartLog.Content = string(this.Ctx.Input.RequestBody)
  238. chartLog.Status = "编辑区间计算图表"
  239. chartLog.Method = this.Ctx.Input.URL()
  240. go data_manage.AddChartInfoLog(chartLog)
  241. }
  242. br.Ret = 200
  243. br.Success = true
  244. br.Msg = "保存成功"
  245. br.Data = resp
  246. br.IsAddLog = true
  247. }
  248. // @router /chart_info/detail [get]
  249. func (this *RangeChartChartInfoController) Detail() {
  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. chartInfoId, _ := this.GetInt("ChartInfoId")
  263. if chartInfoId <= 0 {
  264. br.Msg = "参数有误"
  265. return
  266. }
  267. dateType, _ := this.GetInt("DateType")
  268. fmt.Println("dateType:", dateType)
  269. startDate := this.GetString("StartDate")
  270. endDate := this.GetString("EndDate")
  271. startYear, _ := this.GetInt("StartYear")
  272. var err error
  273. chartInfo := new(data_manage.ChartInfoView)
  274. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  275. if err != nil {
  276. if utils.IsErrNoRow(err) {
  277. br.Msg = "图被删除,请刷新页面"
  278. br.ErrMsg = "图被删除,请刷新页面,Err:" + err.Error()
  279. return
  280. }
  281. br.Msg = "获取失败"
  282. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  283. return
  284. }
  285. if dateType <= 0 {
  286. dateType = chartInfo.DateType
  287. }
  288. if startDate == "" {
  289. startDate = chartInfo.StartDate
  290. }
  291. if endDate == "" {
  292. endDate = chartInfo.EndDate
  293. }
  294. if startYear <= 0 {
  295. startYear = chartInfo.StartYear
  296. }
  297. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, chartInfo.ChartType)
  298. if err != nil {
  299. br.Msg = "获取失败"
  300. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  301. return
  302. }
  303. chartInfo.ChartThemeStyle = chartTheme.Config
  304. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  305. edbInfoMappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  306. if err != nil {
  307. br.Msg = "获取失败"
  308. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  309. return
  310. }
  311. if len(edbInfoMappingList) == 0 {
  312. br.Msg = "获取失败"
  313. br.ErrMsg = "图表没有指标,无法计算"
  314. return
  315. }
  316. var extraConfig data_manage.ChartRangeAnalysisExtraConf
  317. if chartInfo.ExtraConfig == `` {
  318. br.Msg = "配置信息错误"
  319. return
  320. }
  321. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &extraConfig)
  322. if err != nil {
  323. br.Msg = "配置信息错误"
  324. br.ErrMsg = "图表配置信息错误,Err:" + err.Error()
  325. return
  326. }
  327. edbList, xEdbIdValue, dataResp, e := rangeServ.GetChartDataByEdbInfoList(chartInfoId, dateType, startYear, startDate, endDate, edbInfoMappingList, &extraConfig)
  328. if e != nil {
  329. br.Msg = "获取失败"
  330. br.ErrMsg = "获取区间计算图表, 图表计算值失败, Err:" + e.Error()
  331. return
  332. }
  333. if chartInfoId > 0 && chartInfo != nil {
  334. {
  335. var myChartCondition string
  336. var myChartPars []interface{}
  337. myChartCondition += ` AND a.admin_id=? `
  338. myChartPars = append(myChartPars, sysUser.AdminId)
  339. myChartCondition += ` AND a.chart_info_id=? `
  340. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  341. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  342. if err != nil && !utils.IsErrNoRow(err) {
  343. br.Msg = "获取失败"
  344. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  345. return
  346. }
  347. if myChartList != nil && len(myChartList) > 0 {
  348. chartInfo.IsAdd = true
  349. chartInfo.MyChartId = myChartList[0].MyChartId
  350. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  351. }
  352. }
  353. }
  354. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  355. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList[0:1], chartInfo.Source, chartInfo.ChartType)
  356. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  357. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  358. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  359. chartInfo.Button = data_manage.ChartViewButton{
  360. IsEdit: chartInfo.IsEdit,
  361. IsEnChart: chartInfo.IsEnChart,
  362. IsAdd: chartInfo.IsAdd,
  363. IsCopy: chartInfo.IsEdit,
  364. IsSetName: chartInfo.IsSetName,
  365. }
  366. {
  367. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  368. classifyMap := make(map[int]*data_manage.EdbClassify)
  369. {
  370. classifyIdList := make([]int, 0)
  371. for _, v := range edbList {
  372. classifyIdList = append(classifyIdList, v.ClassifyId)
  373. }
  374. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  375. if tmpErr != nil {
  376. br.Msg = "获取失败"
  377. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  378. return
  379. }
  380. for _, v := range classifyList {
  381. classifyMap[v.ClassifyId] = v
  382. }
  383. }
  384. for _, v := range edbList {
  385. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  386. ClassifyId: v.ClassifyId,
  387. IsJoinPermission: v.IsJoinPermission,
  388. EdbInfoId: v.EdbInfoId,
  389. }
  390. }
  391. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  392. if err != nil {
  393. br.Msg = "获取失败"
  394. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  395. return
  396. }
  397. for _, v := range edbList {
  398. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  399. if !ok {
  400. continue
  401. }
  402. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  403. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  404. }
  405. }
  406. }
  407. classifyLevels := make([]string, 0)
  408. {
  409. list, e := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_RANGE_ANALYSIS)
  410. if e != nil {
  411. br.Msg = "获取失败"
  412. br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", e)
  413. return
  414. }
  415. parents := data.GetChartClassifyParentRecursive(list, chartInfo.ChartClassifyId)
  416. sort.Slice(parents, func(i, j int) bool {
  417. return parents[i].Level < parents[i].Level
  418. })
  419. for _, v := range parents {
  420. classifyLevels = append(classifyLevels, v.UniqueCode)
  421. }
  422. }
  423. resp := new(data_manage.ChartInfoDetailResp)
  424. resp.ChartInfo = chartInfo
  425. resp.EdbInfoList = edbList
  426. resp.XEdbIdValue = xEdbIdValue
  427. resp.DataResp = dataResp
  428. resp.ClassifyLevels = classifyLevels
  429. br.Ret = 200
  430. br.Success = true
  431. br.Msg = "获取成功"
  432. br.Data = resp
  433. }
  434. // @router /chart_info/detail/from_unique_code [get]
  435. func (this *RangeChartChartInfoController) DetailFromUniqueCode() {
  436. br := new(models.BaseResponse).Init()
  437. defer func() {
  438. this.Data["json"] = br
  439. this.ServeJSON()
  440. }()
  441. sysUser := this.SysUser
  442. if sysUser == nil {
  443. br.Msg = "请登录"
  444. br.ErrMsg = "请登录,SysUser Is Empty"
  445. br.Ret = 408
  446. return
  447. }
  448. adminId := sysUser.AdminId
  449. uniqueCode := this.GetString("UniqueCode")
  450. if uniqueCode == "" {
  451. br.Msg = "参数错误"
  452. br.ErrMsg = "参数错误,uniqueCode is empty"
  453. return
  454. }
  455. isCache, _ := this.GetBool("IsCache")
  456. resp := new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  457. status := true
  458. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  459. if err != nil {
  460. if utils.IsErrNoRow(err) {
  461. status = false
  462. } else {
  463. br.Msg = "获取失败"
  464. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  465. return
  466. }
  467. }
  468. if chartInfo == nil {
  469. status = false
  470. }
  471. if !status {
  472. endInfoList := make([]*data_manage.ChartEdbInfoMapping, 0)
  473. resp.EdbInfoList = endInfoList
  474. resp.ChartInfo = chartInfo
  475. resp.Status = false
  476. br.Ret = 200
  477. br.Success = true
  478. br.Msg = "获取成功"
  479. br.Data = resp
  480. return
  481. }
  482. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  483. if utils.Re == nil && isCache {
  484. if utils.Re == nil && utils.Rc.IsExist(key) {
  485. if d, e := utils.Rc.RedisBytes(key); e == nil {
  486. err := json.Unmarshal(d, &resp)
  487. if err == nil && resp != nil {
  488. var myCond string
  489. var myPars []interface{}
  490. myCond += ` AND a.admin_id=? `
  491. myPars = append(myPars, adminId)
  492. myCond += ` AND a.chart_info_id=? `
  493. myPars = append(myPars, chartInfo.ChartInfoId)
  494. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  495. if err != nil && !utils.IsErrNoRow(err) {
  496. br.Msg = "获取失败"
  497. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  498. return
  499. }
  500. resp.ChartInfo.IsAdd = false
  501. resp.ChartInfo.MyChartId = 0
  502. resp.ChartInfo.MyChartClassifyId = ""
  503. if myList != nil && len(myList) > 0 {
  504. resp.ChartInfo.IsAdd = true
  505. resp.ChartInfo.MyChartId = myList[0].MyChartId
  506. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  507. }
  508. br.Ret = 200
  509. br.Success = true
  510. br.Msg = "获取成功"
  511. br.Data = resp
  512. return
  513. }
  514. }
  515. }
  516. }
  517. resp, isOk, msg, errMsg := GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  518. if !isOk {
  519. br.Msg = msg
  520. br.ErrMsg = errMsg
  521. return
  522. }
  523. br.Ret = 200
  524. br.Success = true
  525. br.Msg = "获取成功"
  526. br.Data = resp
  527. }
  528. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  529. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  530. adminId := sysUser.AdminId
  531. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  532. defer func() {
  533. if isOk {
  534. {
  535. var myChartCondition string
  536. var myChartPars []interface{}
  537. myChartCondition += ` AND a.admin_id=? `
  538. myChartPars = append(myChartPars, adminId)
  539. myChartCondition += ` AND a.chart_info_id=? `
  540. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  541. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  542. if err != nil && !utils.IsErrNoRow(err) {
  543. msg = "获取失败"
  544. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  545. return
  546. }
  547. if myChartList != nil && len(myChartList) > 0 {
  548. chartInfo.IsAdd = true
  549. chartInfo.MyChartId = myChartList[0].MyChartId
  550. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  551. }
  552. }
  553. resp.ChartInfo.HaveOperaAuth = true
  554. {
  555. classifyMap := make(map[int]*data_manage.EdbClassify)
  556. {
  557. classifyIdList := make([]int, 0)
  558. for _, v := range resp.EdbInfoList {
  559. classifyIdList = append(classifyIdList, v.ClassifyId)
  560. }
  561. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  562. if tmpErr != nil {
  563. errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  564. return
  565. }
  566. for _, v := range classifyList {
  567. classifyMap[v.ClassifyId] = v
  568. }
  569. }
  570. if len(edbClassifyPermissionMap) < 0 {
  571. edbInfoIdList := make([]int, 0)
  572. for _, v := range resp.EdbInfoList {
  573. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  574. }
  575. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  576. if tmpErr != nil {
  577. errMsg = "获取指标列表失败,Err:" + tmpErr.Error()
  578. return
  579. }
  580. for _, v := range edbInfoList {
  581. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  582. ClassifyId: v.ClassifyId,
  583. IsJoinPermission: v.IsJoinPermission,
  584. EdbInfoId: v.EdbInfoId,
  585. }
  586. }
  587. }
  588. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  589. if err != nil {
  590. errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  591. return
  592. }
  593. for _, v := range resp.EdbInfoList {
  594. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  595. if !ok {
  596. continue
  597. }
  598. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  599. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  600. }
  601. }
  602. }
  603. }
  604. }()
  605. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  606. if utils.Re == nil && isCache {
  607. if utils.Re == nil && utils.Rc.IsExist(key) {
  608. if chartData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  609. err := json.Unmarshal(chartData, &resp)
  610. if err != nil || resp == nil {
  611. return
  612. }
  613. isOk = true
  614. fmt.Println("source redis")
  615. return
  616. }
  617. }
  618. }
  619. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  620. if err != nil {
  621. msg = "获取失败"
  622. errMsg = "获取主题信息失败,Err:" + err.Error()
  623. return
  624. }
  625. chartInfo.ChartThemeStyle = chartTheme.Config
  626. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  627. chartInfoId := chartInfo.ChartInfoId
  628. edbInfoMappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  629. if err != nil {
  630. msg = "获取失败"
  631. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  632. return
  633. }
  634. dateType := chartInfo.DateType
  635. startYear := chartInfo.StartYear
  636. startDate := chartInfo.StartDate
  637. endDate := chartInfo.EndDate
  638. var extraConfig data_manage.ChartRangeAnalysisExtraConf
  639. if chartInfo.ExtraConfig == `` {
  640. msg = "配置信息错误"
  641. return
  642. }
  643. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &extraConfig)
  644. if err != nil {
  645. msg = "配置信息错误"
  646. errMsg = "图表配置信息错误,Err:" + err.Error()
  647. return
  648. }
  649. if len(edbInfoMappingList) == 0 {
  650. msg = "获取失败"
  651. errMsg = "图表没有指标,无法计算"
  652. return
  653. }
  654. edbList, xEdbIdValue, dataResp, e := rangeServ.GetChartDataByEdbInfoList(chartInfoId, dateType, startYear, startDate, endDate, edbInfoMappingList, &extraConfig)
  655. if e != nil {
  656. msg = "获取失败"
  657. errMsg = "获取区间计算图表, 图表计算值失败, Err:" + e.Error()
  658. return
  659. }
  660. if chartInfoId > 0 && chartInfo != nil {
  661. {
  662. var myChartCondition string
  663. var myChartPars []interface{}
  664. myChartCondition += ` AND a.admin_id=? `
  665. myChartPars = append(myChartPars, sysUser.AdminId)
  666. myChartCondition += ` AND a.chart_info_id=? `
  667. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  668. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  669. if err != nil && !utils.IsErrNoRow(err) {
  670. msg = "获取失败"
  671. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  672. return
  673. }
  674. if myChartList != nil && len(myChartList) > 0 {
  675. chartInfo.IsAdd = true
  676. chartInfo.MyChartId = myChartList[0].MyChartId
  677. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  678. }
  679. }
  680. }
  681. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  682. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList[0:1], chartInfo.Source, chartInfo.ChartType)
  683. chartInfo.UnitEn = ""
  684. chartInfo.Button = data_manage.ChartViewButton{
  685. IsEdit: chartInfo.IsEdit,
  686. IsEnChart: chartInfo.IsEnChart,
  687. IsAdd: chartInfo.IsAdd,
  688. IsCopy: chartInfo.IsEdit,
  689. IsSetName: chartInfo.IsSetName,
  690. }
  691. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  692. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  693. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  694. resp.ChartInfo = chartInfo
  695. resp.EdbInfoList = edbList
  696. resp.XEdbIdValue = xEdbIdValue
  697. resp.DataResp = dataResp
  698. resp.Status = true
  699. for _, v := range edbList {
  700. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  701. ClassifyId: v.ClassifyId,
  702. IsJoinPermission: v.IsJoinPermission,
  703. EdbInfoId: v.EdbInfoId,
  704. }
  705. }
  706. if utils.Re == nil {
  707. d, _ := json.Marshal(resp)
  708. _ = utils.Rc.Put(key, d, 2*time.Hour)
  709. }
  710. isOk = true
  711. return
  712. }
  713. // @router /chart_info/list [get]
  714. func (this *RangeChartChartInfoController) List() {
  715. br := new(models.BaseResponse).Init()
  716. defer func() {
  717. this.Data["json"] = br
  718. this.ServeJSON()
  719. }()
  720. sysUser := this.SysUser
  721. if sysUser == nil {
  722. br.Msg = "请登录"
  723. br.ErrMsg = "请登录,SysUser Is Empty"
  724. br.Ret = 408
  725. return
  726. }
  727. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  728. pageSize, _ := this.GetInt("PageSize")
  729. currentIndex, _ := this.GetInt("CurrentIndex")
  730. keyword := this.GetString("KeyWord")
  731. var total int
  732. page := paging.GetPaging(currentIndex, pageSize, total)
  733. var startSize int
  734. if pageSize <= 0 {
  735. pageSize = utils.PageSize20
  736. }
  737. if currentIndex <= 0 {
  738. currentIndex = 1
  739. }
  740. startSize = paging.StartIndex(currentIndex, pageSize)
  741. source := utils.CHART_SOURCE_RANGE_ANALYSIS
  742. var condition string
  743. var pars []interface{}
  744. condition += ` AND source = ? `
  745. pars = append(pars, source)
  746. if chartClassifyId > 0 {
  747. chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
  748. if err != nil && !utils.IsErrNoRow(err) {
  749. br.Msg = "获取图表信息失败"
  750. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  751. return
  752. }
  753. condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  754. }
  755. if keyword != "" {
  756. keywords := strings.Split(keyword, " ")
  757. condition += ` AND ( chart_name LIKE '%` + keywords[0] + `%' `
  758. for k, key := range keywords {
  759. if k == 0 {
  760. continue
  761. }
  762. condition += ` OR chart_name LIKE '%` + key + `%' `
  763. }
  764. condition += ` )`
  765. }
  766. isShowMe, _ := this.GetBool("IsShowMe")
  767. if isShowMe {
  768. condition += ` AND sys_user_id = ? `
  769. pars = append(pars, sysUser.AdminId)
  770. }
  771. noPermissionChartIdList := make([]int, 0)
  772. {
  773. obj := data_manage.EdbInfoNoPermissionAdmin{}
  774. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  775. if err != nil && !utils.IsErrNoRow(err) {
  776. br.Msg = "获取失败"
  777. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  778. return
  779. }
  780. for _, v := range confList {
  781. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  782. }
  783. }
  784. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  785. if lenNoPermissionChartIdList > 0 {
  786. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  787. pars = append(pars, noPermissionChartIdList)
  788. }
  789. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  790. if err != nil && !utils.IsErrNoRow(err) {
  791. br.Success = true
  792. br.Msg = "获取图表信息失败"
  793. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  794. return
  795. }
  796. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  797. if err != nil && !utils.IsErrNoRow(err) {
  798. br.Msg = "获取图表信息失败"
  799. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  800. return
  801. }
  802. myChartMap := make(map[int]*data_manage.MyChartView)
  803. for _, v := range myChartList {
  804. myChartMap[v.ChartInfoId] = v
  805. }
  806. listLen := len(list)
  807. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  808. if listLen > 0 {
  809. chartInfoIds := ""
  810. for _, v := range list {
  811. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  812. }
  813. if chartInfoIds != "" {
  814. chartInfoIds = strings.Trim(chartInfoIds, ",")
  815. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  816. if e != nil {
  817. br.Msg = "获取失败"
  818. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  819. return
  820. }
  821. for _, v := range edbList {
  822. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  823. }
  824. }
  825. }
  826. for i := 0; i < listLen; i++ {
  827. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  828. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  829. }
  830. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  831. list[i].IsAdd = true
  832. list[i].MyChartId = existItem.MyChartId
  833. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  834. }
  835. }
  836. resp := new(data_manage.ChartListResp)
  837. if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) {
  838. items := make([]*data_manage.ChartInfoView, 0)
  839. resp.Paging = page
  840. resp.List = items
  841. br.Ret = 200
  842. br.Success = true
  843. br.Msg = "获取成功"
  844. return
  845. }
  846. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  847. if err != nil && !utils.IsErrNoRow(err) {
  848. br.Msg = "获取指标信息失败"
  849. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  850. return
  851. }
  852. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  853. resp.Paging = page
  854. resp.List = list
  855. br.Ret = 200
  856. br.Success = true
  857. br.Msg = "获取成功"
  858. br.Data = resp
  859. }
  860. // @router /chart_info/copy [post]
  861. func (this *RangeChartChartInfoController) Copy() {
  862. br := new(models.BaseResponse).Init()
  863. defer func() {
  864. if br.ErrMsg == "" {
  865. br.IsSendEmail = false
  866. }
  867. this.Data["json"] = br
  868. this.ServeJSON()
  869. }()
  870. sysUser := this.SysUser
  871. if sysUser == nil {
  872. br.Msg = "请登录"
  873. br.ErrMsg = "请登录,SysUser Is Empty"
  874. br.Ret = 408
  875. return
  876. }
  877. var req data_manage.CopyAddChartInfoReq
  878. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  879. if err != nil {
  880. br.Msg = "参数解析异常!"
  881. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  882. return
  883. }
  884. if req.ChartInfoId <= 0 {
  885. br.Msg = "参数有误"
  886. br.ErrMsg = fmt.Sprintf("参数有误, ChartInfoId: %d", req.ChartInfoId)
  887. return
  888. }
  889. req.ChartName = strings.TrimSpace(req.ChartName)
  890. if req.ChartName == "" {
  891. br.Msg = "请输入图表名称"
  892. return
  893. }
  894. if req.ChartClassifyId <= 0 {
  895. br.Msg = "请选择图表分类"
  896. return
  897. }
  898. deleteCache := true
  899. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  900. defer func() {
  901. if deleteCache {
  902. utils.Rc.Delete(cacheKey)
  903. }
  904. }()
  905. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  906. deleteCache = false
  907. br.Msg = "系统处理中,请稍后重试!"
  908. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  909. return
  910. }
  911. chartSource := utils.CHART_SOURCE_RANGE_ANALYSIS
  912. {
  913. var cond string
  914. var pars []interface{}
  915. switch this.Lang {
  916. case utils.EnLangVersion:
  917. cond += " AND chart_name_en = ? AND source = ? "
  918. default:
  919. cond += " AND chart_name = ? AND source = ? "
  920. }
  921. pars = append(pars, req.ChartName, chartSource)
  922. count, e := data_manage.GetChartInfoCountByCondition(cond, pars)
  923. if e != nil {
  924. br.Msg = "保存失败"
  925. br.ErrMsg = fmt.Sprintf("获取同名图表失败, Err: %v", e)
  926. return
  927. }
  928. if count > 0 {
  929. br.Msg = "图表名称已存在, 请重新填写"
  930. return
  931. }
  932. _, e = data_manage.GetChartClassifyById(req.ChartClassifyId)
  933. if e != nil {
  934. if utils.IsErrNoRow(e) {
  935. br.Msg = "分类不存在"
  936. return
  937. }
  938. br.Msg = "保存失败"
  939. br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", e)
  940. return
  941. }
  942. }
  943. originChart, e := data_manage.GetChartInfoById(req.ChartInfoId)
  944. if e != nil {
  945. if utils.IsErrNoRow(e) {
  946. br.Msg = "原图表不存在"
  947. return
  948. }
  949. br.Msg = "保存失败"
  950. br.ErrMsg = fmt.Sprintf("获取原图表信息失败, Err: %v", e)
  951. return
  952. }
  953. if originChart.Source == utils.CHART_SOURCE_ROLLING_CORRELATION {
  954. br.Msg = `滚动区间计算图不支持另存为`
  955. br.IsSendEmail = false
  956. return
  957. }
  958. chartInfo := new(data_manage.ChartInfo)
  959. newChart, err, errMsg, isSendEmail := rangeServ.CopyChartInfo(req.ChartClassifyId, req.ChartName, originChart, sysUser, this.Lang)
  960. chartInfo = newChart
  961. if err != nil {
  962. br.Msg = "保存失败"
  963. if errMsg != `` {
  964. br.Msg = errMsg
  965. }
  966. br.ErrMsg = err.Error()
  967. br.IsSendEmail = isSendEmail
  968. return
  969. }
  970. {
  971. chartLog := new(data_manage.ChartInfoLog)
  972. chartLog.ChartInfoId = chartInfo.ChartInfoId
  973. chartLog.ChartName = req.ChartName
  974. chartLog.ChartClassifyId = req.ChartClassifyId
  975. chartLog.SysUserId = sysUser.AdminId
  976. chartLog.SysUserRealName = sysUser.RealName
  977. chartLog.UniqueCode = chartInfo.UniqueCode
  978. chartLog.CreateTime = time.Now()
  979. chartLog.Content = string(this.Ctx.Input.RequestBody)
  980. chartLog.Status = "复制区间计算图表"
  981. chartLog.Method = this.Ctx.Input.URI()
  982. go data_manage.AddChartInfoLog(chartLog)
  983. }
  984. br.Ret = 200
  985. br.Success = true
  986. br.Msg = "保存成功"
  987. br.Data = data_manage.AddChartInfoResp{
  988. ChartInfoId: chartInfo.ChartInfoId,
  989. UniqueCode: chartInfo.UniqueCode,
  990. ChartType: chartInfo.ChartType,
  991. }
  992. br.IsAddLog = true
  993. }
  994. // @router /chart_info/refresh [get]
  995. func (this *RangeChartChartInfoController) Refresh() {
  996. br := new(models.BaseResponse).Init()
  997. defer func() {
  998. this.Data["json"] = br
  999. this.ServeJSON()
  1000. }()
  1001. sysUser := this.SysUser
  1002. if sysUser == nil {
  1003. br.Msg = "请登录"
  1004. br.ErrMsg = "请登录,SysUser Is Empty"
  1005. br.Ret = 408
  1006. return
  1007. }
  1008. chartInfoId, _ := this.GetInt("ChartInfoId")
  1009. uniqueCode := this.GetString("UniqueCode")
  1010. if chartInfoId <= 0 && uniqueCode == `` {
  1011. br.Msg = "参数错误"
  1012. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  1013. return
  1014. }
  1015. var chartInfo *data_manage.ChartInfo
  1016. var err error
  1017. if chartInfoId > 0 {
  1018. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  1019. } else {
  1020. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  1021. }
  1022. if err != nil {
  1023. if utils.IsErrNoRow(err) {
  1024. br.Msg = "图表已被删除,无需刷新"
  1025. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  1026. return
  1027. }
  1028. br.Msg = "刷新失败"
  1029. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1030. return
  1031. }
  1032. isAsync, e := rangeServ.ChartInfoRefresh(chartInfo.ChartInfoId, chartInfo.UniqueCode)
  1033. if e != nil {
  1034. br.Msg = "刷新失败"
  1035. br.ErrMsg = "刷新区间计算图表失败, Err:" + err.Error()
  1036. return
  1037. }
  1038. if isAsync {
  1039. br.Ret = 200
  1040. br.Success = true
  1041. br.Msg = "刷新时间较长, 请10分钟后查看"
  1042. return
  1043. }
  1044. {
  1045. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  1046. _ = utils.Rc.Delete(key)
  1047. }
  1048. br.Ret = 200
  1049. br.Success = true
  1050. br.Msg = "刷新成功"
  1051. }
  1052. // @router /edb/save [post]
  1053. func (this *RangeChartChartInfoController) MultipleGraphConfigSaveEdb() {
  1054. br := new(models.BaseResponse).Init()
  1055. defer func() {
  1056. this.Data["json"] = br
  1057. this.ServeJSON()
  1058. }()
  1059. sysUser := this.SysUser
  1060. if sysUser == nil {
  1061. br.Msg = "请登录"
  1062. br.ErrMsg = "请登录,SysUser Is Empty"
  1063. br.Ret = 408
  1064. return
  1065. }
  1066. var req data_manage.SaveChartRangeAnalysisEdbReq
  1067. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1068. if err != nil {
  1069. br.Msg = "参数解析异常!"
  1070. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1071. return
  1072. }
  1073. cacheKey := "CACHE_CHART_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  1074. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1075. br.Msg = "系统处理中,请稍后重试!"
  1076. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1077. return
  1078. }
  1079. defer func() {
  1080. _ = utils.Rc.Delete(cacheKey)
  1081. }()
  1082. edbInfoIds := make([]int, 0)
  1083. for _, v := range req.EdbInfoList {
  1084. if v.EdbInfoId > 0 {
  1085. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  1086. }
  1087. edbInfoIds = append(edbInfoIds, v.FromEdbInfoId)
  1088. }
  1089. edbInfoMappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIds)
  1090. if err != nil {
  1091. br.Msg = "获取失败"
  1092. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1093. return
  1094. }
  1095. edbInfoMap := make(map[int]*data_manage.ChartEdbInfoMapping, 0)
  1096. for _, v := range edbInfoMappingList {
  1097. edbInfoMap[v.EdbInfoId] = v
  1098. }
  1099. for _, v := range req.EdbInfoList {
  1100. if _, ok := edbInfoMap[v.FromEdbInfoId]; !ok {
  1101. br.Msg = "指标信息不存在"
  1102. br.ErrMsg = "指标信息不存在,EdbInfoId:" + strconv.Itoa(v.FromEdbInfoId)
  1103. br.IsSendEmail = false
  1104. return
  1105. }
  1106. if v.EdbInfoId > 0 {
  1107. if _, ok := edbInfoMap[v.EdbInfoId]; !ok {
  1108. v.EdbInfoId = 0
  1109. }
  1110. }
  1111. }
  1112. extraConfig := req.ExtraConfig
  1113. var config data_manage.ChartRangeAnalysisExtraConf
  1114. if req.ExtraConfig == `` {
  1115. br.Msg = "请输入配置信息"
  1116. return
  1117. }
  1118. err = json.Unmarshal([]byte(req.ExtraConfig), &config)
  1119. if err != nil {
  1120. br.Msg = "配置信息格式错误"
  1121. br.ErrMsg = "配置信息格式错误,Err:" + err.Error()
  1122. return
  1123. }
  1124. err, errMsg, isSendEmail := rangeServ.CheckChartRangeExtraConfig(config)
  1125. if err != nil {
  1126. br.Msg = "配置信息校验失败"
  1127. br.ErrMsg = errMsg
  1128. br.IsSendEmail = isSendEmail
  1129. return
  1130. }
  1131. multipleGraphConfigEdbMappingList, err := data_manage.GetMultipleGraphConfigEdbMappingListByIdAndSource(req.MultipleGraphConfigId, utils.CHART_SOURCE_RANGE_ANALYSIS)
  1132. if err != nil {
  1133. br.Msg = `保存失败`
  1134. br.ErrMsg = "查询配置与图表的关联关系失败,ERR:" + err.Error()
  1135. return
  1136. }
  1137. deleteEdbInfoIds := make([]int, 0) // 需要解除绑定的指标ID
  1138. deleteEdbInfoIdMap := make(map[int]int, 0)
  1139. configMapping := make(map[int]*data_manage.MultipleGraphConfigEdbMapping, 0)
  1140. if len(multipleGraphConfigEdbMappingList) == 0 || req.IsSaveAs {
  1141. } else {
  1142. for _, v := range multipleGraphConfigEdbMappingList {
  1143. deleteEdbInfoIdMap[v.EdbInfoId] = v.EdbInfoId
  1144. configMapping[v.EdbInfoId] = v
  1145. }
  1146. }
  1147. resp := data_manage.BatchEdbInfoCalculateBatchSaveResp{
  1148. Fail: make([]data_manage.BatchEdbInfoCalculateBatchSaveFailResp, 0),
  1149. Success: make([]data_manage.BatchEdbInfoCalculateBatchSaveSuccessResp, 0),
  1150. }
  1151. calculateEdbList := make([]data_manage.BatchEdbInfoCalculateBatchSaveSuccessResp, 0)
  1152. addReqEdbList := make([]*data_manage.CalculateEdbInfoItem, 0)
  1153. editReqEdbList := make([]*data_manage.CalculateEdbInfoItem, 0)
  1154. for _, v := range req.EdbInfoList {
  1155. v.CalculateId = strconv.Itoa(v.FromEdbInfoId)
  1156. v.EdbName = strings.Trim(v.EdbName, " ")
  1157. if v.EdbName == "" {
  1158. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1159. CalculateId: v.CalculateId,
  1160. Msg: "指标名称不能为空",
  1161. })
  1162. continue
  1163. }
  1164. if v.Frequency == "" {
  1165. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1166. CalculateId: v.CalculateId,
  1167. Msg: "频率不能为空",
  1168. })
  1169. continue
  1170. }
  1171. if v.Unit == "" {
  1172. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1173. CalculateId: v.CalculateId,
  1174. Msg: "单位不能为空",
  1175. })
  1176. continue
  1177. }
  1178. if v.ClassifyId <= 0 {
  1179. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1180. CalculateId: v.CalculateId,
  1181. Msg: "请选择分类",
  1182. })
  1183. continue
  1184. }
  1185. redisKey := fmt.Sprint("edb_info:calculate:batch:save:", utils.DATA_SOURCE_CALCULATE_RANGEANLYSIS, ":", v.EdbName)
  1186. if req.EdbInfoType == 1 {
  1187. redisKey = fmt.Sprint("predict_edb_info:calculate:batch:save:", sysUser.AdminId, ":", utils.DATA_SOURCE_CALCULATE_RANGEANLYSIS, ":", v.CalculateId)
  1188. }
  1189. isExist := utils.Rc.IsExist(redisKey)
  1190. if isExist {
  1191. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1192. CalculateId: strconv.Itoa(v.FromEdbInfoId),
  1193. Msg: "指标正在处理,请勿重复提交",
  1194. })
  1195. continue
  1196. } else {
  1197. }
  1198. if v.EdbInfoId > 0 {
  1199. editReqEdbList = append(editReqEdbList, v)
  1200. delete(deleteEdbInfoIdMap, v.EdbInfoId)
  1201. } else {
  1202. addReqEdbList = append(addReqEdbList, v)
  1203. }
  1204. }
  1205. if len(editReqEdbList) <= 0 && len(addReqEdbList) <= 0 {
  1206. br.Msg = "新增失败!"
  1207. if len(resp.Fail) > 0 {
  1208. br.ErrMsg = resp.Fail[0].Msg
  1209. } else {
  1210. br.Msg = "请选择指标"
  1211. }
  1212. return
  1213. }
  1214. if req.EdbInfoType == 0 { //普通指标
  1215. for _, v := range addReqEdbList {
  1216. req2 := &data_manage.EdbInfoCalculateBatchSaveReqByEdbLib{
  1217. AdminId: sysUser.AdminId,
  1218. AdminName: sysUser.RealName,
  1219. EdbInfoId: v.EdbInfoId,
  1220. EdbName: v.EdbName,
  1221. Frequency: v.Frequency,
  1222. Unit: v.Unit,
  1223. ClassifyId: v.ClassifyId,
  1224. FromEdbInfoId: v.FromEdbInfoId,
  1225. CalculateFormula: extraConfig,
  1226. Source: utils.DATA_SOURCE_CALCULATE_RANGEANLYSIS,
  1227. }
  1228. reqJson, err := json.Marshal(req2)
  1229. if err != nil {
  1230. br.Msg = "参数解析异常!"
  1231. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1232. return
  1233. }
  1234. respItem, e := data.BatchSaveEdbCalculateData(string(reqJson), this.Lang)
  1235. if e != nil {
  1236. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1237. CalculateId: v.CalculateId,
  1238. Msg: "新增失败!",
  1239. ErrMsg: "新增失败,Err:" + e.Error(),
  1240. })
  1241. continue
  1242. }
  1243. if respItem.Ret != 200 {
  1244. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1245. CalculateId: v.CalculateId,
  1246. Msg: respItem.Msg,
  1247. ErrMsg: respItem.ErrMsg,
  1248. })
  1249. continue
  1250. }
  1251. calculateEdbList = append(calculateEdbList, data_manage.BatchEdbInfoCalculateBatchSaveSuccessResp{
  1252. CalculateId: v.CalculateId,
  1253. EdbInfoId: respItem.Data.EdbInfoId,
  1254. UniqueCode: respItem.Data.UniqueCode,
  1255. ClassifyId: v.ClassifyId,
  1256. })
  1257. }
  1258. if len(editReqEdbList) > 0 {
  1259. for _, v := range editReqEdbList {
  1260. req2 := &data_manage.EdbInfoCalculateBatchEditReqByEdbLib{
  1261. AdminId: sysUser.AdminId,
  1262. AdminName: sysUser.RealName,
  1263. EdbInfoId: v.EdbInfoId,
  1264. EdbName: v.EdbName,
  1265. Frequency: v.Frequency,
  1266. Unit: v.Unit,
  1267. ClassifyId: v.ClassifyId,
  1268. FromEdbInfoId: v.FromEdbInfoId,
  1269. CalculateFormula: extraConfig,
  1270. Source: utils.DATA_SOURCE_CALCULATE_RANGEANLYSIS,
  1271. }
  1272. reqJson, err := json.Marshal(req2)
  1273. if err != nil {
  1274. br.Msg = "参数解析异常!"
  1275. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1276. return
  1277. }
  1278. respItem, e := data.BatchEditEdbCalculateData(string(reqJson), this.Lang)
  1279. if e != nil {
  1280. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1281. CalculateId: v.CalculateId,
  1282. Msg: "新增失败!",
  1283. ErrMsg: "新增失败,Err:" + e.Error(),
  1284. })
  1285. continue
  1286. }
  1287. if respItem.Ret != 200 {
  1288. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1289. CalculateId: v.CalculateId,
  1290. Msg: respItem.Msg,
  1291. ErrMsg: respItem.ErrMsg,
  1292. })
  1293. continue
  1294. }
  1295. calculateEdbList = append(calculateEdbList, data_manage.BatchEdbInfoCalculateBatchSaveSuccessResp{
  1296. CalculateId: v.CalculateId,
  1297. EdbInfoId: respItem.Data.EdbInfoId,
  1298. UniqueCode: respItem.Data.UniqueCode,
  1299. ClassifyId: v.ClassifyId,
  1300. })
  1301. }
  1302. }
  1303. } else if req.EdbInfoType == 1 {
  1304. for _, v := range req.EdbInfoList {
  1305. predictReq := new(data_manage.PredictEdbInfoCalculateBatchSaveReq)
  1306. predictReq.EdbInfoId = v.EdbInfoId
  1307. predictReq.CalculateFormula = extraConfig
  1308. predictReq.EdbName = v.EdbName
  1309. predictReq.Frequency = v.Frequency
  1310. predictReq.Unit = v.Unit
  1311. predictReq.ClassifyId = v.ClassifyId
  1312. predictReq.FromEdbInfoId = v.FromEdbInfoId
  1313. predictReq.AdminId = sysUser.AdminId
  1314. predictReq.AdminName = sysUser.RealName
  1315. predictReq.Source = utils.DATA_SOURCE_PREDICT_CALCULATE_RANGEANLYSIS
  1316. reqJson, e := json.Marshal(predictReq)
  1317. if e != nil {
  1318. br.Msg = "参数解析异常!"
  1319. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  1320. return
  1321. }
  1322. respItem, e := data.BatchSavePredictEdbData(string(reqJson), this.Lang)
  1323. if e != nil {
  1324. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1325. CalculateId: v.CalculateId,
  1326. Msg: "新增失败!",
  1327. ErrMsg: "新增失败,Err:" + e.Error(),
  1328. })
  1329. continue
  1330. }
  1331. if respItem.Ret != 200 {
  1332. resp.Fail = append(resp.Fail, data_manage.BatchEdbInfoCalculateBatchSaveFailResp{
  1333. CalculateId: v.CalculateId,
  1334. Msg: respItem.Msg,
  1335. ErrMsg: respItem.ErrMsg,
  1336. })
  1337. continue
  1338. }
  1339. calculateEdbList = append(calculateEdbList, data_manage.BatchEdbInfoCalculateBatchSaveSuccessResp{
  1340. CalculateId: v.CalculateId,
  1341. EdbInfoId: respItem.Data.EdbInfoId,
  1342. UniqueCode: respItem.Data.UniqueCode,
  1343. ClassifyId: predictReq.ClassifyId,
  1344. })
  1345. }
  1346. }
  1347. for k, _ := range deleteEdbInfoIdMap {
  1348. deleteEdbInfoIds = append(deleteEdbInfoIds, k)
  1349. }
  1350. if len(deleteEdbInfoIds) > 0 {
  1351. err = data_manage.DeleteMultipleGraphConfigEdbMappingByEdbIds(req.MultipleGraphConfigId, utils.CHART_SOURCE_RANGE_ANALYSIS, deleteEdbInfoIds)
  1352. if err != nil {
  1353. br.Msg = "更新失败!"
  1354. br.ErrMsg = "删除失败,Err:" + err.Error()
  1355. return
  1356. }
  1357. }
  1358. if !req.IsSaveAs {
  1359. configEdbMappingList := make([]*data_manage.MultipleGraphConfigEdbMapping, 0)
  1360. for _, v := range calculateEdbList {
  1361. item, ok := configMapping[v.EdbInfoId]
  1362. if !ok {
  1363. multipleGraphConfigEdbMapping := &data_manage.MultipleGraphConfigEdbMapping{
  1364. MultipleGraphConfigId: req.MultipleGraphConfigId,
  1365. EdbInfoId: v.EdbInfoId,
  1366. Source: utils.CHART_SOURCE_RANGE_ANALYSIS,
  1367. ModifyTime: time.Now(),
  1368. CreateTime: time.Now(),
  1369. }
  1370. configEdbMappingList = append(configEdbMappingList, multipleGraphConfigEdbMapping)
  1371. } else {
  1372. item.ModifyTime = time.Now()
  1373. err = item.Update([]string{"ModifyTime"})
  1374. if err != nil {
  1375. br.Msg = "保存失败"
  1376. br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
  1377. return
  1378. }
  1379. }
  1380. }
  1381. if len(configEdbMappingList) > 0 {
  1382. err = data_manage.AddMultipleGraphConfigEdbMappingList(configEdbMappingList)
  1383. if err != nil {
  1384. br.Msg = "保存失败"
  1385. br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
  1386. return
  1387. }
  1388. }
  1389. }
  1390. resp.Success = calculateEdbList
  1391. br.Ret = 200
  1392. br.Success = true
  1393. br.Msg = "保存成功"
  1394. br.Data = resp
  1395. br.IsAddLog = true
  1396. }
  1397. // @router /edb/list [get]
  1398. func (this *RangeChartChartInfoController) MultipleGraphConfigEdbList() {
  1399. br := new(models.BaseResponse).Init()
  1400. defer func() {
  1401. this.Data["json"] = br
  1402. this.ServeJSON()
  1403. }()
  1404. sysUser := this.SysUser
  1405. if sysUser == nil {
  1406. br.Msg = "请登录"
  1407. br.ErrMsg = "请登录,SysUser Is Empty"
  1408. br.Ret = 408
  1409. return
  1410. }
  1411. multipleGraphConfigId, _ := this.GetInt("MultipleGraphConfigId")
  1412. if multipleGraphConfigId <= 0 {
  1413. br.Msg = "参数错误"
  1414. br.ErrMsg = "参数错误,MultipleGraphConfigId Is Empty"
  1415. return
  1416. }
  1417. list := make([]*data_manage.ChartRangeAnalysisConfigEdbItem, 0)
  1418. resp := data_manage.ChartRangeAnalysisConfigEdbResp{EdbInfoList: list}
  1419. multipleGraphConfigEdbMappingList, err := data_manage.GetMultipleGraphConfigEdbMappingListByIdAndSource(multipleGraphConfigId, utils.CHART_SOURCE_RANGE_ANALYSIS)
  1420. if err != nil {
  1421. br.Msg = `保存失败`
  1422. br.ErrMsg = "查询配置与图表的关联关系失败,ERR:" + err.Error()
  1423. return
  1424. }
  1425. if len(multipleGraphConfigEdbMappingList) == 0 {
  1426. br.Ret = 200
  1427. br.Success = true
  1428. br.Msg = "操作成功"
  1429. br.Data = resp
  1430. br.IsAddLog = true
  1431. return
  1432. }
  1433. edbInfoIds := make([]int, 0)
  1434. for _, v := range multipleGraphConfigEdbMappingList {
  1435. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  1436. }
  1437. edbList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIds)
  1438. if err != nil {
  1439. br.Msg = "获取失败"
  1440. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1441. return
  1442. }
  1443. edbInfoMap := make(map[int]*data_manage.ChartEdbInfoMapping, 0)
  1444. for _, v := range edbList {
  1445. edbInfoMap[v.EdbInfoId] = v
  1446. }
  1447. edbCalculateMappingList, e := data_manage.GetEdbInfoCalculateMappingListByEdbInfoIds(edbInfoIds)
  1448. if e != nil {
  1449. br.Msg = `保存失败`
  1450. br.ErrMsg = "获取计算指标信息失败,ERR:" + e.Error()
  1451. return
  1452. }
  1453. for _, v := range edbCalculateMappingList {
  1454. tmp := new(data_manage.ChartRangeAnalysisConfigEdbItem)
  1455. info, ok := edbInfoMap[v.EdbInfoId]
  1456. if ok {
  1457. tmp.EdbInfoId = v.EdbInfoId
  1458. tmp.Unit = info.Unit
  1459. tmp.UnitEn = info.UnitEn
  1460. tmp.Frequency = info.Frequency
  1461. tmp.EdbNameEn = info.EdbNameEn
  1462. tmp.EdbName = info.EdbName
  1463. tmp.ClassifyId = info.ClassifyId
  1464. tmp.FromEdbInfoId = v.FromEdbInfoId
  1465. tmp.EdbTypeInfo = info.EdbInfoCategoryType
  1466. list = append(list, tmp)
  1467. }
  1468. }
  1469. resp.EdbInfoList = list
  1470. br.Ret = 200
  1471. br.Success = true
  1472. br.Msg = "保存成功"
  1473. br.Data = resp
  1474. br.IsAddLog = true
  1475. }
  1476. // @router /chart_info/search_by_es [get]
  1477. func (this *RangeChartChartInfoController) SearchByEs() {
  1478. br := new(models.BaseResponse).Init()
  1479. defer func() {
  1480. this.Data["json"] = br
  1481. this.ServeJSON()
  1482. }()
  1483. sysUser := this.SysUser
  1484. if sysUser == nil {
  1485. br.Msg = "请登录"
  1486. br.ErrMsg = "请登录,SysUser Is Empty"
  1487. br.Ret = 408
  1488. return
  1489. }
  1490. pageSize, _ := this.GetInt("PageSize")
  1491. currentIndex, _ := this.GetInt("CurrentIndex")
  1492. var startSize int
  1493. if pageSize <= 0 {
  1494. pageSize = utils.PageSize20
  1495. }
  1496. if currentIndex <= 0 {
  1497. currentIndex = 1
  1498. }
  1499. startSize = paging.StartIndex(currentIndex, pageSize)
  1500. keyword := this.GetString("Keyword")
  1501. isShowMe, _ := this.GetBool("IsShowMe")
  1502. showSysId := 0
  1503. if isShowMe {
  1504. showSysId = sysUser.AdminId
  1505. }
  1506. sourceList := make([]int, 0)
  1507. sourceList = append(sourceList, utils.CHART_SOURCE_RANGE_ANALYSIS)
  1508. var searchList []*data_manage.ChartInfo
  1509. var total int64
  1510. var err error
  1511. noPermissionChartIdList := make([]int, 0)
  1512. {
  1513. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1514. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1515. if err != nil && !utils.IsErrNoRow(err) {
  1516. br.Msg = "获取失败"
  1517. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1518. return
  1519. }
  1520. for _, v := range confList {
  1521. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1522. }
  1523. }
  1524. if keyword != "" {
  1525. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1526. } else {
  1527. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1528. if err != nil && !utils.IsErrNoRow(err) {
  1529. br.Msg = "获取失败"
  1530. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1531. return
  1532. }
  1533. }
  1534. finalList := make([]*data_manage.ChartInfoMore, 0)
  1535. if len(searchList) > 0 {
  1536. chartInfoIds := ""
  1537. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1538. for _, v := range searchList {
  1539. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1540. }
  1541. if chartInfoIds != "" {
  1542. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1543. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1544. if e != nil {
  1545. br.Msg = "获取失败"
  1546. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1547. return
  1548. }
  1549. for _, v := range edbList {
  1550. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1551. }
  1552. }
  1553. for _, v := range searchList {
  1554. tmp := new(data_manage.ChartInfoMore)
  1555. tmp.ChartInfo = *v
  1556. tmp.HaveOperaAuth = true
  1557. if edbTmpList, ok := chartEdbMap[v.ChartInfoId]; ok {
  1558. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, edbTmpList, v.Source, v.ChartType)
  1559. }
  1560. finalList = append(finalList, tmp)
  1561. }
  1562. }
  1563. {
  1564. searchKeyword := new(data_manage.SearchKeyword)
  1565. searchKeyword.KeyWord = keyword
  1566. searchKeyword.CreateTime = time.Now()
  1567. go data_manage.AddSearchKeyword(searchKeyword)
  1568. }
  1569. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1570. resp := data_manage.ChartInfoListByEsResp{
  1571. Paging: page,
  1572. List: finalList,
  1573. }
  1574. br.Ret = 200
  1575. br.Success = true
  1576. br.Msg = "获取成功"
  1577. br.Data = resp
  1578. }
  1579. // @router /chart_info/base/edit [post]
  1580. func (this *RangeChartChartInfoController) BaseInfoEdit() {
  1581. br := new(models.BaseResponse).Init()
  1582. defer func() {
  1583. this.Data["json"] = br
  1584. this.ServeJSON()
  1585. }()
  1586. sysUser := this.SysUser
  1587. if sysUser == nil {
  1588. br.Msg = "请登录"
  1589. br.ErrMsg = "请登录,SysUser Is Empty"
  1590. br.Ret = 408
  1591. return
  1592. }
  1593. var req data_manage.EditChartRangeBaseReq
  1594. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1595. if err != nil {
  1596. br.Msg = "参数解析异常!"
  1597. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1598. return
  1599. }
  1600. req.ChartName = strings.Trim(req.ChartName, " ")
  1601. if req.ChartInfoId <= 0 {
  1602. br.Msg = "请选择图表"
  1603. return
  1604. }
  1605. if req.ChartName == "" {
  1606. br.Msg = "请输入图表名称"
  1607. return
  1608. }
  1609. chartItem, e := data_manage.GetChartInfoById(req.ChartInfoId)
  1610. if e != nil {
  1611. if utils.IsErrNoRow(e) {
  1612. br.Msg = "图表已被删除, 请刷新页面"
  1613. return
  1614. }
  1615. br.Msg = "获取图表信息失败"
  1616. br.ErrMsg = "获取图表信息失败, Err: " + e.Error()
  1617. return
  1618. }
  1619. if chartItem.Source != utils.CHART_SOURCE_RANGE_ANALYSIS {
  1620. br.Msg = "该图不是区间计算图表"
  1621. return
  1622. }
  1623. var condition string
  1624. var pars []interface{}
  1625. condition += " AND chart_info_id <> ? AND source = ? "
  1626. pars = append(pars, req.ChartInfoId, utils.CHART_SOURCE_RANGE_ANALYSIS)
  1627. switch this.Lang {
  1628. case utils.EnLangVersion:
  1629. condition += " AND chart_name_en = ? "
  1630. default:
  1631. condition += " AND chart_name = ? "
  1632. }
  1633. pars = append(pars, req.ChartName)
  1634. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  1635. if err != nil {
  1636. if !utils.IsErrNoRow(err) {
  1637. br.Msg = "判断英文图表名称是否存在失败"
  1638. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  1639. return
  1640. }
  1641. }
  1642. if err == nil && existItem.ChartInfoId > 0 {
  1643. br.Msg = existItem.ChartName + ":" + req.ChartName + "图表名称已存在"
  1644. return
  1645. }
  1646. switch this.Lang {
  1647. case utils.EnLangVersion:
  1648. chartItem.ChartNameEn = req.ChartName
  1649. default:
  1650. chartItem.ChartName = req.ChartName
  1651. }
  1652. chartItem.ModifyTime = time.Now().Local()
  1653. if e := chartItem.Update([]string{"ChartName", "ChartNameEn", "ModifyTime"}); e != nil {
  1654. br.Msg = "操作失败"
  1655. br.ErrMsg = "更新图表信息失败, Err: " + e.Error()
  1656. return
  1657. }
  1658. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  1659. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  1660. {
  1661. chartLog := new(data_manage.ChartInfoLog)
  1662. chartLog.ChartName = chartItem.ChartName
  1663. chartLog.ChartInfoId = req.ChartInfoId
  1664. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1665. chartLog.SysUserId = sysUser.AdminId
  1666. chartLog.SysUserRealName = sysUser.RealName
  1667. chartLog.UniqueCode = chartItem.UniqueCode
  1668. chartLog.CreateTime = time.Now()
  1669. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1670. chartLog.Status = "编辑区间计算图表基础信息"
  1671. chartLog.Method = this.Ctx.Input.URL()
  1672. go data_manage.AddChartInfoLog(chartLog)
  1673. }
  1674. if utils.Re == nil && utils.Rc != nil {
  1675. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  1676. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  1677. }
  1678. br.Ret = 200
  1679. br.Success = true
  1680. br.Msg = "编辑成功"
  1681. br.IsAddLog = true
  1682. }
  1683. // @router /chart_info/save [post]
  1684. func (this *RangeChartChartInfoController) ChartInfoSave() {
  1685. br := new(models.BaseResponse).Init()
  1686. defer func() {
  1687. this.Data["json"] = br
  1688. this.ServeJSON()
  1689. }()
  1690. sysUser := this.SysUser
  1691. if sysUser == nil {
  1692. br.Msg = "请登录"
  1693. br.ErrMsg = "请登录,SysUser Is Empty"
  1694. br.Ret = 408
  1695. return
  1696. }
  1697. var req data_manage.SaveChartRangeReq
  1698. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1699. if err != nil {
  1700. br.Msg = "参数解析异常!"
  1701. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1702. return
  1703. }
  1704. if req.ChartInfoId <= 0 {
  1705. br.Msg = "参数错误!"
  1706. return
  1707. }
  1708. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1709. if err != nil {
  1710. if utils.IsErrNoRow(err) {
  1711. br.Msg = "图表已被删除,请刷新页面!"
  1712. br.ErrMsg = "图表已被删除,请刷新页面,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  1713. return
  1714. }
  1715. br.Msg = "获取图表信息失败!"
  1716. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1717. return
  1718. }
  1719. err = data_manage.EditRangeChartInfo(&req)
  1720. if err != nil {
  1721. br.Msg = "保存失败"
  1722. br.ErrMsg = "保存失败,Err:" + err.Error()
  1723. return
  1724. }
  1725. key := utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode
  1726. if utils.Re == nil && utils.Rc != nil {
  1727. utils.Rc.Delete(key)
  1728. }
  1729. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  1730. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  1731. {
  1732. chartLog := new(data_manage.ChartInfoLog)
  1733. chartLog.ChartName = chartItem.ChartName
  1734. chartLog.ChartInfoId = req.ChartInfoId
  1735. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1736. chartLog.SysUserId = sysUser.AdminId
  1737. chartLog.SysUserRealName = sysUser.RealName
  1738. chartLog.UniqueCode = chartItem.UniqueCode
  1739. chartLog.CreateTime = time.Now()
  1740. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1741. chartLog.Status = "修改配置项"
  1742. chartLog.Method = this.Ctx.Input.URI()
  1743. go data_manage.AddChartInfoLog(chartLog)
  1744. }
  1745. br.Ret = 200
  1746. br.Success = true
  1747. br.Msg = "保存成功"
  1748. br.IsAddLog = true
  1749. }