chart_classify.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. package range_analysis
  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/system"
  8. "eta/eta_mobile/services/data"
  9. "eta/eta_mobile/services/data/data_manage_permission"
  10. "eta/eta_mobile/utils"
  11. "fmt"
  12. "sort"
  13. "time"
  14. )
  15. // RangeChartClassifyController 区间分析图表
  16. type RangeChartClassifyController struct {
  17. controllers.BaseAuthController
  18. }
  19. // ChartClassifyList
  20. // @Title 区间分析图表分类列表
  21. // @Description 区间分析图表分类列表接口
  22. // @Param IsShowMe query bool false "是否只看我的,true、false"
  23. // @Param ParentId query bool false "父级ID"
  24. // @Param Source query int false "图表类型,3:相关性,4:滚动相关性"
  25. // @Success 200 {object} data_manage.ChartClassifyListResp
  26. // @router /chart_classify/list [get]
  27. func (this *RangeChartClassifyController) ChartClassifyList() {
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. if br.ErrMsg == "" {
  31. br.IsSendEmail = false
  32. }
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. resp := new(data_manage.ChartClassifyListResp)
  37. // 获取当前账号的不可见指标
  38. //noPermissionChartIdMap := make(map[int]bool)
  39. //{
  40. // obj := data_manage.EdbInfoNoPermissionAdmin{}
  41. // confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  42. // if err != nil && err.Error() != utils.ErrNoRow() {
  43. // br.Msg = "获取失败"
  44. // br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  45. // return
  46. // }
  47. // for _, v := range confList {
  48. // noPermissionChartIdMap[v.ChartInfoId] = true
  49. // }
  50. //}
  51. isShowMe, _ := this.GetBool("IsShowMe")
  52. parentId, _ := this.GetInt("ParentId")
  53. source, _ := this.GetInt("Source", utils.CHART_SOURCE_RANGE_ANALYSIS)
  54. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  55. // 查询分类节点
  56. rootList, err := data_manage.GetChartClassifyByParentId(parentId, utils.CHART_SOURCE_RANGE_ANALYSIS)
  57. if err != nil && err.Error() != utils.ErrNoRow() {
  58. br.Msg = "获取失败"
  59. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  60. return
  61. }
  62. if len(rootList) > 0 {
  63. permissionClassifyIdList, e := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, 0)
  64. if e != nil {
  65. br.Msg = "获取失败"
  66. br.ErrMsg = "获取已授权分类id数据失败,Err:" + e.Error()
  67. return
  68. }
  69. for _, v := range rootList {
  70. // 操作按钮权限
  71. v.HaveOperaAuth = data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ChartClassifyId, permissionClassifyIdList)
  72. button := data.GetChartClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  73. v.Button = button
  74. v.ParentId = parentId
  75. v.Children = make([]*data_manage.ChartClassifyItems, 0)
  76. nodeAll = append(nodeAll, v)
  77. }
  78. }
  79. // 查询图表节点, ParentId=0时说明仅查询一级目录节点
  80. if parentId > 0 {
  81. // 查询当前分类信息
  82. currClassify, e := data_manage.GetChartClassifyById(parentId)
  83. if e != nil {
  84. br.Msg = "获取失败"
  85. br.ErrMsg = "获取当前分类信息失败,Err:" + e.Error()
  86. return
  87. }
  88. // 获取所有有权限的指标和分类
  89. permissionEdbIdList, permissionClassifyIdList, e := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  90. if e != nil {
  91. br.Msg = "获取失败"
  92. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + e.Error()
  93. return
  94. }
  95. var adminId int
  96. if isShowMe {
  97. adminId = this.SysUser.AdminId
  98. }
  99. charts, e := data_manage.GetChartInfoBySourceAndParentId(source, parentId, adminId)
  100. if e != nil {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = fmt.Sprintf("获取图表信息失败, Err: %v", e)
  103. return
  104. }
  105. for _, v := range charts {
  106. // 操作按钮权限
  107. v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionEdbIdList, permissionClassifyIdList)
  108. button := data.GetChartOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  109. button.AddButton = false //不管有没有权限,图表都是没有添加按钮的
  110. v.Button = button
  111. v.ParentId = parentId
  112. v.Children = make([]*data_manage.ChartClassifyItems, 0)
  113. nodeAll = append(nodeAll, v)
  114. }
  115. }
  116. // 整体排序
  117. if len(nodeAll) > 0 {
  118. sort.Slice(nodeAll, func(i, j int) bool {
  119. return nodeAll[i].Sort < nodeAll[j].Sort
  120. })
  121. }
  122. resp.AllNodes = nodeAll
  123. br.Ret = 200
  124. br.Success = true
  125. br.Msg = "获取成功"
  126. br.Data = resp
  127. }
  128. // getChartClassifyListForMe 获取我创建的图表
  129. func getChartClassifyListForMe(adminInfo system.Admin, resp *data_manage.ChartClassifyListResp) (errMsg string, err error) {
  130. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_RANGE_ANALYSIS)
  131. if err != nil && err.Error() != utils.ErrNoRow() {
  132. errMsg = "获取失败"
  133. return
  134. }
  135. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_RANGE_ANALYSIS)
  136. if err != nil && err.Error() != utils.ErrNoRow() {
  137. errMsg = "获取失败"
  138. return
  139. }
  140. allChartInfo, err := data_manage.GetChartInfoByAdminId([]int{utils.CHART_SOURCE_RANGE_ANALYSIS, utils.CHART_SOURCE_RANGE_ANALYSIS}, adminInfo.AdminId)
  141. if err != nil && err.Error() != utils.ErrNoRow() {
  142. errMsg = "获取失败"
  143. return
  144. }
  145. chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
  146. for _, v := range allChartInfo {
  147. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  148. }
  149. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  150. for _, v := range classifyAll {
  151. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  152. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  153. v.Children = existItems
  154. } else {
  155. items := make([]*data_manage.ChartClassifyItems, 0)
  156. v.Children = items
  157. }
  158. }
  159. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  160. for _, v := range rootList {
  161. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  162. v.Children = existItems
  163. } else {
  164. items := make([]*data_manage.ChartClassifyItems, 0)
  165. v.Children = items
  166. }
  167. nodeAll = append(nodeAll, v)
  168. }
  169. resp.AllNodes = nodeAll
  170. return
  171. }
  172. // ChartClassifyItems
  173. // @Title 获取所有区间分析图表分类接口-不包含图表
  174. // @Description 获取所有区间分析图表分类接口-不包含图表
  175. // @Success 200 {object} data_manage.ChartClassifyListResp
  176. // @router /chart_classify/items [get]
  177. func (this *RangeChartClassifyController) ChartClassifyItems() {
  178. br := new(models.BaseResponse).Init()
  179. defer func() {
  180. this.Data["json"] = br
  181. this.ServeJSON()
  182. }()
  183. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_RANGE_ANALYSIS)
  184. if err != nil {
  185. br.Msg = "获取失败"
  186. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  187. return
  188. }
  189. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  190. for k := range rootList {
  191. rootNode := rootList[k]
  192. nodeAll = append(nodeAll, rootNode)
  193. }
  194. resp := new(data_manage.ChartClassifyListResp)
  195. resp.AllNodes = nodeAll
  196. br.Ret = 200
  197. br.Success = true
  198. br.Msg = "获取成功"
  199. br.Data = resp
  200. }
  201. // AddChartClassify
  202. // @Title 新增区间分析图表分类
  203. // @Description 新增区间分析图表分类接口
  204. // @Param request body data_manage.AddChartClassifyReq true "type json string"
  205. // @Success 200 Ret=200 保存成功
  206. // @router /chart_classify/add [post]
  207. func (this *RangeChartClassifyController) AddChartClassify() {
  208. br := new(models.BaseResponse).Init()
  209. defer func() {
  210. this.Data["json"] = br
  211. this.ServeJSON()
  212. }()
  213. var req data_manage.AddChartClassifyReq
  214. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  215. if err != nil {
  216. br.Msg = "参数解析异常!"
  217. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  218. return
  219. }
  220. if req.ChartClassifyName == "" {
  221. br.Msg = "请输入分类名称"
  222. br.IsSendEmail = false
  223. return
  224. }
  225. if req.ParentId < 0 {
  226. br.Msg = "参数错误"
  227. br.IsSendEmail = false
  228. return
  229. }
  230. // 新增图表分类
  231. _, err, errMsg, isSendEmail := data.AddChartClassify(req.ChartClassifyName, req.ParentId, req.Level, utils.CHART_SOURCE_RANGE_ANALYSIS, this.Lang, this.SysUser)
  232. if err != nil {
  233. br.Msg = errMsg
  234. br.ErrMsg = "添加分类失败,Err:" + err.Error()
  235. br.IsSendEmail = isSendEmail
  236. return
  237. }
  238. br.Ret = 200
  239. br.Msg = "添加成功"
  240. br.Success = true
  241. }
  242. // EditChartClassify
  243. // @Title 修改区间分析图表分类
  244. // @Description 修改区间分析图表分类接口
  245. // @Param request body data_manage.EditChartClassifyReq true "type json string"
  246. // @Success 200 Ret=200 修改成功
  247. // @router /chart_classify/edit [post]
  248. func (this *RangeChartClassifyController) EditChartClassify() {
  249. br := new(models.BaseResponse).Init()
  250. defer func() {
  251. this.Data["json"] = br
  252. this.ServeJSON()
  253. }()
  254. var req data_manage.EditChartClassifyReq
  255. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  256. if err != nil {
  257. br.Msg = "参数解析异常!"
  258. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  259. return
  260. }
  261. if req.ChartClassifyName == "" {
  262. br.Msg = "请输入分类名称"
  263. br.IsSendEmail = false
  264. return
  265. }
  266. if req.ChartClassifyId <= 0 {
  267. br.Msg = "参数错误"
  268. br.IsSendEmail = false
  269. return
  270. }
  271. // 编辑图表分类
  272. _, err, errMsg, isSendEmail := data.EditChartClassify(req.ChartClassifyId, utils.CHART_SOURCE_RANGE_ANALYSIS, req.ChartClassifyName, this.Lang, this.SysUser)
  273. if err != nil {
  274. br.Msg = errMsg
  275. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  276. br.IsSendEmail = isSendEmail
  277. return
  278. }
  279. br.Ret = 200
  280. br.Msg = "修改成功"
  281. br.Success = true
  282. br.IsAddLog = true
  283. }
  284. // DeleteChartClassifyCheck
  285. // @Title 删除图表检测接口
  286. // @Description 删除图表检测接口
  287. // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
  288. // @Success 200 Ret=200 检测成功
  289. // @router /chart_classify/delete/check [post]
  290. func (this *RangeChartClassifyController) DeleteChartClassifyCheck() {
  291. br := new(models.BaseResponse).Init()
  292. defer func() {
  293. this.Data["json"] = br
  294. this.ServeJSON()
  295. }()
  296. var req data_manage.ChartClassifyDeleteCheckReq
  297. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  298. if err != nil {
  299. br.Msg = "参数解析异常!"
  300. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  301. return
  302. }
  303. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  304. br.Msg = "参数错误"
  305. br.IsSendEmail = false
  306. return
  307. }
  308. var deleteStatus int
  309. var tipsMsg string
  310. //删除分类
  311. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  312. //判断区间分析图表分类下,是否含有图表
  313. count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  314. if err != nil {
  315. br.Msg = "删除失败"
  316. br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  317. return
  318. }
  319. if count > 0 {
  320. deleteStatus = 1
  321. tipsMsg = "该分类下关联图表不可删除"
  322. }
  323. }
  324. if deleteStatus != 1 && req.ChartInfoId == 0 {
  325. classifyCount, err := data_manage.GetChartClassifyCountByClassifyId(req.ChartClassifyId)
  326. if err != nil && err.Error() != utils.ErrNoRow() {
  327. br.Msg = "删除失败"
  328. br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
  329. return
  330. }
  331. if classifyCount > 0 {
  332. deleteStatus = 2
  333. tipsMsg = "确认删除当前目录及包含的子目录吗"
  334. }
  335. }
  336. if deleteStatus == 0 {
  337. tipsMsg = "可删除,进行删除操作"
  338. }
  339. resp := new(data_manage.ChartClassifyDeleteCheckResp)
  340. resp.DeleteStatus = deleteStatus
  341. resp.TipsMsg = tipsMsg
  342. br.Ret = 200
  343. br.Msg = "检测成功"
  344. br.Success = true
  345. br.Data = resp
  346. }
  347. // DeleteChartClassify
  348. // @Title 删除区间分析图表分类/图表
  349. // @Description 删除区间分析图表分类/图表接口
  350. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  351. // @Success 200 Ret=200 删除成功
  352. // @router /chart_classify/delete [post]
  353. func (this *RangeChartClassifyController) DeleteChartClassify() {
  354. br := new(models.BaseResponse).Init()
  355. defer func() {
  356. this.Data["json"] = br
  357. this.ServeJSON()
  358. }()
  359. sysUser := this.SysUser
  360. if sysUser == nil {
  361. br.Msg = "请登录"
  362. br.ErrMsg = "请登录,SysUser Is Empty"
  363. br.Ret = 408
  364. return
  365. }
  366. var req data_manage.DeleteChartClassifyReq
  367. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  368. if err != nil {
  369. br.Msg = "参数解析异常!"
  370. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  371. return
  372. }
  373. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  374. br.Msg = "参数错误"
  375. br.IsSendEmail = false
  376. return
  377. }
  378. //删除分类
  379. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  380. //判断是否含有指标
  381. count, err := data_manage.GetChartInfoCountByClassifyId(req.ChartClassifyId)
  382. if err != nil && err.Error() != utils.ErrNoRow() {
  383. br.Msg = "删除失败"
  384. br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  385. return
  386. }
  387. if count > 0 {
  388. br.Msg = "该目录下存在关联指标,不可删除"
  389. br.IsSendEmail = false
  390. return
  391. }
  392. err = data_manage.DeleteChartClassify(req.ChartClassifyId)
  393. if err != nil {
  394. br.Msg = "删除失败"
  395. br.ErrMsg = "删除失败,Err:" + err.Error()
  396. return
  397. }
  398. }
  399. resp := new(data_manage.AddChartInfoResp)
  400. //删除图表
  401. if req.ChartInfoId > 0 {
  402. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  403. if err != nil {
  404. if err.Error() == utils.ErrNoRow() {
  405. br.Msg = "图表已删除,请刷新页面"
  406. br.ErrMsg = "指标不存在,Err:" + err.Error()
  407. return
  408. } else {
  409. br.Msg = "删除失败"
  410. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  411. return
  412. }
  413. }
  414. if chartInfo == nil {
  415. br.Msg = "图表已删除,请刷新页面"
  416. return
  417. }
  418. //图表操作权限
  419. ok := data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  420. if !ok {
  421. br.Msg = "没有该图表的操作权限"
  422. br.ErrMsg = "没有该图表的操作权限"
  423. return
  424. }
  425. // 获取引用该图表的MyCharts, 用于ES删除
  426. var myCond string
  427. var myPars []interface{}
  428. myCond += ` AND a.chart_info_id = ? `
  429. myPars = append(myPars, chartInfo.ChartInfoId)
  430. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  431. if e != nil {
  432. br.Msg = "删除失败"
  433. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  434. return
  435. }
  436. myIds := make([]int, 0)
  437. for _, m := range myCharts {
  438. myIds = append(myIds, m.MyChartId)
  439. }
  440. source := chartInfo.Source // 区间分析图表(滚动相关性)
  441. //删除图表及关联指标
  442. err = data_manage.DeleteChartInfoAndData(chartInfo.ChartInfoId)
  443. if err != nil {
  444. br.Msg = "删除失败"
  445. br.ErrMsg = "删除失败,Err:" + err.Error()
  446. return
  447. }
  448. // 删除图表系列
  449. chartSeriesOb := new(data_manage.FactorEdbSeriesChartMapping)
  450. seriesMappingItem, e := chartSeriesOb.GetItemByChartInfoId(chartInfo.ChartInfoId)
  451. if e != nil {
  452. if e.Error() == utils.ErrNoRow() {
  453. } else {
  454. br.Msg = "删除失败"
  455. br.ErrMsg = "获取图表关联失败, Err: " + e.Error()
  456. return
  457. }
  458. } else {
  459. factorSeriesOb := new(data_manage.FactorEdbSeries)
  460. e = factorSeriesOb.RemoveSeriesAndMappingByFactorEdbSeriesId(seriesMappingItem)
  461. if e != nil {
  462. br.Msg = "删除失败"
  463. br.ErrMsg = "获取图表关联失败, Err: " + e.Error()
  464. return
  465. }
  466. }
  467. //删除ES
  468. {
  469. go data.EsDeleteChartInfo(chartInfo.ChartInfoId)
  470. // 删除MY ETA 图表 es数据
  471. //go data.EsDeleteMyChartInfoByChartInfoId(chartInfo.ChartInfoId)
  472. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  473. }
  474. var condition string
  475. var pars []interface{}
  476. condition += " AND chart_classify_id=? AND source = ? "
  477. pars = append(pars, chartInfo.ChartClassifyId, source)
  478. condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
  479. pars = append(pars, req.ChartInfoId)
  480. nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  481. if err != nil && err.Error() != utils.ErrNoRow() {
  482. br.Msg = "删除失败"
  483. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  484. return
  485. }
  486. if nextItem != nil {
  487. resp.UniqueCode = nextItem.UniqueCode
  488. resp.ChartInfoId = nextItem.ChartInfoId
  489. } else {
  490. var condition string
  491. var pars []interface{}
  492. condition += " AND level=1 "
  493. //pars = append(pars, chartInfo.ChartClassifyId)
  494. condition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
  495. pars = append(pars, chartInfo.ChartClassifyId)
  496. classifyItem, err := data_manage.GetChartClassifyByCondition(condition, pars)
  497. if err != nil && err.Error() != utils.ErrNoRow() {
  498. br.Msg = "删除失败"
  499. br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
  500. return
  501. }
  502. if classifyItem != nil {
  503. nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
  504. if err != nil && err.Error() != utils.ErrNoRow() {
  505. br.Msg = "删除失败"
  506. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  507. return
  508. }
  509. if nextItem != nil {
  510. resp.UniqueCode = nextItem.UniqueCode
  511. resp.ChartInfoId = nextItem.ChartInfoId
  512. }
  513. }
  514. }
  515. //新增操作日志
  516. {
  517. chartLog := new(data_manage.ChartInfoLog)
  518. chartLog.ChartName = chartInfo.ChartName
  519. chartLog.ChartInfoId = req.ChartInfoId
  520. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  521. chartLog.SysUserId = sysUser.AdminId
  522. chartLog.SysUserRealName = sysUser.RealName
  523. chartLog.UniqueCode = chartInfo.UniqueCode
  524. chartLog.CreateTime = time.Now()
  525. chartLog.Content = string(this.Ctx.Input.RequestBody)
  526. chartLog.Status = "删除图表"
  527. chartLog.Method = this.Ctx.Input.URI()
  528. go data_manage.AddChartInfoLog(chartLog)
  529. }
  530. }
  531. br.Ret = 200
  532. br.Msg = "删除成功"
  533. br.Success = true
  534. br.Data = resp
  535. br.IsAddLog = true
  536. }
  537. // ClassifyTree
  538. // @Title 多层分类列表树
  539. // @Description 多层分类列表树
  540. // @Success 200 {object} data_manage.ChartClassifyListResp
  541. // @router /chart_classify/tree [get]
  542. func (this *RangeChartClassifyController) ClassifyTree() {
  543. br := new(models.BaseResponse).Init()
  544. defer func() {
  545. if br.ErrMsg == "" {
  546. br.IsSendEmail = false
  547. }
  548. this.Data["json"] = br
  549. this.ServeJSON()
  550. }()
  551. allList, err := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_RANGE_ANALYSIS)
  552. if err != nil {
  553. br.Msg = "获取失败"
  554. br.ErrMsg = "获取所有分类失败, Err:" + err.Error()
  555. return
  556. }
  557. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  558. if len(allList) > 0 {
  559. // 已授权分类id
  560. permissionClassifyIdList, e := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, 0)
  561. if e != nil {
  562. br.Msg = "获取失败"
  563. br.ErrMsg = "获取已授权分类id数据失败,Err:" + e.Error()
  564. return
  565. }
  566. for k, v := range allList {
  567. // 数据权限
  568. v.HaveOperaAuth = data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ChartClassifyId, permissionClassifyIdList)
  569. // 按钮权限
  570. button := data.GetChartClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  571. allList[k].Button = button
  572. }
  573. nodeAll = data.GetChartClassifyTreeRecursive(allList, 0)
  574. //根据sort值排序
  575. sort.Slice(nodeAll, func(i, j int) bool {
  576. return nodeAll[i].Sort < nodeAll[j].Sort
  577. })
  578. }
  579. language := `CN`
  580. // 显示的语言
  581. {
  582. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  583. if configDetail != nil {
  584. language = configDetail.ConfigValue
  585. } else {
  586. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  587. if configDetail != nil {
  588. language = configDetail.ConfigValue
  589. }
  590. }
  591. }
  592. // 是否允许添加一级分类
  593. canOpClassify := true
  594. button := data.GetChartClassifyOpButton(this.SysUser, 0, true)
  595. if !button.AddButton {
  596. canOpClassify = false
  597. }
  598. resp := new(data_manage.ChartClassifyListResp)
  599. resp.AllNodes = nodeAll
  600. resp.Language = language
  601. resp.CanOpClassify = canOpClassify
  602. br.Ret = 200
  603. br.Success = true
  604. br.Msg = "获取成功"
  605. br.Data = resp
  606. }