chart_classify.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/system"
  8. "eta_gn/eta_api/services/data"
  9. "eta_gn/eta_api/services/data/data_manage_permission"
  10. "eta_gn/eta_api/utils"
  11. "fmt"
  12. "time"
  13. )
  14. type ChartClassifyController struct {
  15. controllers.BaseAuthController
  16. }
  17. // @router /chart_classify/list [get]
  18. func (this *ChartClassifyController) ChartClassifyListV2() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. resp := new(data_manage.ChartClassifyListResp)
  25. noPermissionChartIdMap := make(map[int]bool)
  26. {
  27. obj := data_manage.EdbInfoNoPermissionAdmin{}
  28. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  29. if err != nil && !utils.IsErrNoRow(err) {
  30. br.Msg = "获取失败"
  31. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  32. return
  33. }
  34. for _, v := range confList {
  35. noPermissionChartIdMap[v.ChartInfoId] = true
  36. }
  37. }
  38. isShowMe, _ := this.GetBool("IsShowMe")
  39. if isShowMe {
  40. errMsg, err := getChartClassifyListForMe(*this.SysUser, resp)
  41. if err != nil {
  42. br.Msg = errMsg
  43. br.ErrMsg = err.Error()
  44. return
  45. }
  46. allNodes := data.HandleNoPermissionChart(resp.AllNodes, noPermissionChartIdMap, this.SysUser.AdminId)
  47. resp.AllNodes = allNodes
  48. br.Ret = 200
  49. br.Success = true
  50. br.Msg = "获取成功"
  51. br.Data = resp
  52. fmt.Println("source my classify")
  53. return
  54. }
  55. key := utils.CACHE_CHART_CLASSIFY
  56. if utils.Re == nil {
  57. if utils.Re == nil && utils.Rc.IsExist(key) {
  58. if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  59. err := json.Unmarshal(redisData, &resp)
  60. if err == nil && resp != nil {
  61. allNodes := data.HandleNoPermissionChart(resp.AllNodes, noPermissionChartIdMap, this.SysUser.AdminId)
  62. resp.AllNodes = allNodes
  63. br.Ret = 200
  64. br.Success = true
  65. br.Msg = "获取成功"
  66. br.Data = resp
  67. fmt.Println("source redis")
  68. return
  69. }
  70. }
  71. }
  72. }
  73. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  74. if err != nil && !utils.IsErrNoRow(err) {
  75. br.Msg = "获取失败"
  76. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  77. return
  78. }
  79. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  80. if err != nil && !utils.IsErrNoRow(err) {
  81. br.Msg = "获取失败"
  82. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  83. return
  84. }
  85. allChartInfo, err := data_manage.GetChartInfoAll([]int{utils.CHART_SOURCE_DEFAULT})
  86. if err != nil && !utils.IsErrNoRow(err) {
  87. br.Msg = "获取失败"
  88. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  89. return
  90. }
  91. chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
  92. for _, v := range allChartInfo {
  93. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  94. }
  95. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  96. for _, v := range classifyAll {
  97. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  98. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  99. v.Children = existItems
  100. } else {
  101. items := make([]*data_manage.ChartClassifyItems, 0)
  102. v.Children = items
  103. }
  104. }
  105. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  106. for _, v := range rootList {
  107. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  108. v.Children = existItems
  109. } else {
  110. items := make([]*data_manage.ChartClassifyItems, 0)
  111. v.Children = items
  112. }
  113. nodeAll = append(nodeAll, v)
  114. }
  115. resp.AllNodes = nodeAll
  116. if utils.Re == nil {
  117. redisData, _ := json.Marshal(resp)
  118. utils.Rc.Put(key, redisData, 2*time.Hour)
  119. }
  120. allNodes := data.HandleNoPermissionChart(resp.AllNodes, noPermissionChartIdMap, this.SysUser.AdminId)
  121. resp.AllNodes = allNodes
  122. br.Ret = 200
  123. br.Success = true
  124. br.Msg = "获取成功"
  125. br.Data = resp
  126. }
  127. func getChartClassifyListForMe(adminInfo system.Admin, resp *data_manage.ChartClassifyListResp) (errMsg string, err error) {
  128. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  129. if err != nil && !utils.IsErrNoRow(err) {
  130. errMsg = "获取失败"
  131. return
  132. }
  133. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  134. if err != nil && !utils.IsErrNoRow(err) {
  135. errMsg = "获取失败"
  136. return
  137. }
  138. allChartInfo, err := data_manage.GetChartInfoByAdminId([]int{utils.CHART_SOURCE_DEFAULT}, adminInfo.AdminId)
  139. if err != nil && !utils.IsErrNoRow(err) {
  140. errMsg = "获取失败"
  141. return
  142. }
  143. chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
  144. for _, v := range allChartInfo {
  145. chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
  146. }
  147. rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
  148. for _, v := range classifyAll {
  149. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  150. if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
  151. v.Children = existItems
  152. } else {
  153. items := make([]*data_manage.ChartClassifyItems, 0)
  154. v.Children = items
  155. }
  156. }
  157. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  158. for _, v := range rootList {
  159. if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
  160. v.Children = existItems
  161. } else {
  162. items := make([]*data_manage.ChartClassifyItems, 0)
  163. v.Children = items
  164. }
  165. nodeAll = append(nodeAll, v)
  166. }
  167. resp.AllNodes = nodeAll
  168. return
  169. }
  170. // @router /chart_classify/items [get]
  171. func (this *ChartClassifyController) ChartClassifyItems() {
  172. br := new(models.BaseResponse).Init()
  173. defer func() {
  174. this.Data["json"] = br
  175. this.ServeJSON()
  176. }()
  177. rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
  178. if err != nil {
  179. br.Msg = "获取失败"
  180. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  181. return
  182. }
  183. classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
  184. if err != nil {
  185. br.Msg = "获取失败"
  186. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  187. return
  188. }
  189. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, 0)
  190. if err != nil {
  191. br.Msg = "获取失败"
  192. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  193. return
  194. }
  195. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  196. for k := range rootList {
  197. rootNode := rootList[k]
  198. data.ChartClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode, permissionClassifyIdList)
  199. nodeAll = append(nodeAll, rootNode)
  200. }
  201. language := `CN`
  202. {
  203. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  204. if configDetail != nil {
  205. language = configDetail.ConfigValue
  206. } else {
  207. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  208. if configDetail != nil {
  209. language = configDetail.ConfigValue
  210. }
  211. }
  212. }
  213. canOpClassify := true
  214. resp := data_manage.ChartClassifyListResp{
  215. AllNodes: nodeAll,
  216. Language: language,
  217. CanOpClassify: canOpClassify,
  218. }
  219. br.Ret = 200
  220. br.Success = true
  221. br.Msg = "获取成功"
  222. br.Data = resp
  223. }
  224. // @router /chart_classify/add [post]
  225. func (this *ChartClassifyController) AddChartClassify() {
  226. br := new(models.BaseResponse).Init()
  227. defer func() {
  228. this.Data["json"] = br
  229. this.ServeJSON()
  230. }()
  231. var req data_manage.AddChartClassifyReq
  232. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  233. if err != nil {
  234. br.Msg = "参数解析异常!"
  235. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  236. return
  237. }
  238. if req.ChartClassifyName == "" {
  239. br.Msg = "请输入分类名称"
  240. br.IsSendEmail = false
  241. return
  242. }
  243. if req.ParentId < 0 {
  244. br.Msg = "参数错误"
  245. br.IsSendEmail = false
  246. return
  247. }
  248. _, err, errMsg, isSendEmail := data.AddChartClassify(req.ChartClassifyName, req.ParentId, req.Level, utils.CHART_SOURCE_DEFAULT, this.Lang, this.SysUser)
  249. if err != nil {
  250. br.Msg = errMsg
  251. br.ErrMsg = "添加分类失败,Err:" + err.Error()
  252. br.IsSendEmail = isSendEmail
  253. return
  254. }
  255. br.Ret = 200
  256. br.Msg = "保存成功"
  257. br.Success = true
  258. }
  259. // @router /chart_classify/edit [post]
  260. func (this *ChartClassifyController) EditChartClassify() {
  261. br := new(models.BaseResponse).Init()
  262. defer func() {
  263. this.Data["json"] = br
  264. this.ServeJSON()
  265. }()
  266. var req data_manage.EditChartClassifyReq
  267. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  268. if err != nil {
  269. br.Msg = "参数解析异常!"
  270. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  271. return
  272. }
  273. if req.ChartClassifyName == "" {
  274. br.Msg = "请输入分类名称"
  275. br.IsSendEmail = false
  276. return
  277. }
  278. if req.ChartClassifyId <= 0 {
  279. br.Msg = "参数错误"
  280. br.IsSendEmail = false
  281. return
  282. }
  283. _, err, errMsg, isSendEmail := data.EditChartClassify(req.ChartClassifyId, utils.CHART_SOURCE_DEFAULT, req.ChartClassifyName, this.Lang, this.SysUser)
  284. if err != nil {
  285. br.Msg = errMsg
  286. br.ErrMsg = "保存分类失败,Err:" + err.Error()
  287. br.IsSendEmail = isSendEmail
  288. return
  289. }
  290. br.Ret = 200
  291. br.Msg = "保存成功"
  292. br.Success = true
  293. br.IsAddLog = true
  294. }
  295. // @router /chart_classify/delete/check [post]
  296. func (this *ChartClassifyController) DeleteChartClassifyCheck() {
  297. br := new(models.BaseResponse).Init()
  298. defer func() {
  299. this.Data["json"] = br
  300. this.ServeJSON()
  301. }()
  302. var req data_manage.ChartClassifyDeleteCheckReq
  303. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  304. if err != nil {
  305. br.Msg = "参数解析异常!"
  306. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  307. return
  308. }
  309. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  310. br.Msg = "参数错误"
  311. br.IsSendEmail = false
  312. return
  313. }
  314. var deleteStatus int
  315. var tipsMsg string
  316. childIds := make([]int, 0)
  317. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  318. item, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  319. if err != nil {
  320. br.Msg = "保存失败"
  321. br.Msg = "获取分类信息失败,Err:" + err.Error()
  322. return
  323. }
  324. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, item.ChartClassifyId)
  325. if err != nil {
  326. br.Msg = "获取失败"
  327. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  328. return
  329. }
  330. {
  331. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
  332. button := data.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
  333. if !button.OpButton {
  334. br.Msg = "无操作权限"
  335. br.IsSendEmail = false
  336. return
  337. }
  338. }
  339. classifyAll, err := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
  340. if err != nil {
  341. br.Msg = "删除失败"
  342. br.ErrMsg = "获取分类数据失败,Err:" + err.Error()
  343. return
  344. }
  345. classifyAllMap := make(map[int]*data_manage.ChartClassifyItems)
  346. for _, v := range classifyAll {
  347. classifyAllMap[v.ChartClassifyId] = v
  348. }
  349. data.GetChartClassifyChildIds(req.ChartClassifyId, classifyAllMap, &childIds)
  350. condition := ``
  351. pars := make([]interface{}, 0)
  352. if len(childIds) > 0 {
  353. ids := utils.IntArr2joinString(childIds, ",")
  354. condition = ` AND chart_classify_id IN (` + ids + `) `
  355. } else {
  356. condition = ` AND chart_classify_id = ? `
  357. pars = append(pars, req.ChartClassifyId)
  358. }
  359. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  360. if err != nil {
  361. br.Msg = "判断图表名称是否存在失败"
  362. br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
  363. return
  364. }
  365. if count > 0 {
  366. deleteStatus = 1
  367. tipsMsg = "该分类下关联图表不可删除"
  368. }
  369. }
  370. if deleteStatus != 1 && req.ChartInfoId == 0 {
  371. if len(childIds) > 0 {
  372. deleteStatus = 2
  373. tipsMsg = "确认删除当前目录及包含的子目录吗"
  374. }
  375. }
  376. if deleteStatus == 0 {
  377. tipsMsg = "可删除,进行删除操作"
  378. }
  379. resp := new(data_manage.ChartClassifyDeleteCheckResp)
  380. resp.DeleteStatus = deleteStatus
  381. resp.TipsMsg = tipsMsg
  382. br.Ret = 200
  383. br.Msg = "检测成功"
  384. br.Success = true
  385. br.Data = resp
  386. }
  387. // @router /chart_classify/delete [post]
  388. func (this *ChartClassifyController) DeleteChartClassify() {
  389. br := new(models.BaseResponse).Init()
  390. defer func() {
  391. this.Data["json"] = br
  392. this.ServeJSON()
  393. }()
  394. sysUser := this.SysUser
  395. if sysUser == nil {
  396. br.Msg = "请登录"
  397. br.ErrMsg = "请登录,SysUser Is Empty"
  398. br.Ret = 408
  399. return
  400. }
  401. var req data_manage.DeleteChartClassifyReq
  402. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  403. if err != nil {
  404. br.Msg = "参数解析异常!"
  405. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  406. return
  407. }
  408. if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
  409. br.Msg = "参数错误"
  410. br.IsSendEmail = false
  411. return
  412. }
  413. if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
  414. item, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  415. if err != nil {
  416. br.Msg = "保存失败"
  417. br.Msg = "获取分类信息失败,Err:" + err.Error()
  418. return
  419. }
  420. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, item.ChartClassifyId)
  421. if err != nil {
  422. br.Msg = "获取失败"
  423. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  424. return
  425. }
  426. {
  427. haveOperaAuth := data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
  428. button := data.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
  429. if !button.OpButton {
  430. br.Msg = "无操作权限"
  431. br.IsSendEmail = false
  432. return
  433. }
  434. }
  435. childIds := make([]int, 0)
  436. classifyAll, err := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
  437. if err != nil {
  438. br.Msg = "删除失败"
  439. br.ErrMsg = "获取分类数据失败,Err:" + err.Error()
  440. return
  441. }
  442. classifyAllMap := make(map[int]*data_manage.ChartClassifyItems)
  443. for _, v := range classifyAll {
  444. classifyAllMap[v.ChartClassifyId] = v
  445. }
  446. data.GetChartClassifyChildIds(req.ChartClassifyId, classifyAllMap, &childIds)
  447. condition := ``
  448. pars := make([]interface{}, 0)
  449. if len(childIds) > 0 {
  450. ids := utils.IntArr2joinString(childIds, ",")
  451. condition = ` AND chart_classify_id IN (` + ids + `) `
  452. } else {
  453. condition = ` AND chart_classify_id = ? `
  454. pars = append(pars, req.ChartClassifyId)
  455. }
  456. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  457. if err != nil {
  458. br.Msg = "判断图表名称是否存在失败"
  459. br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
  460. return
  461. }
  462. if count > 0 {
  463. br.Msg = "该目录下存在关联指标,不可删除"
  464. br.IsSendEmail = false
  465. return
  466. }
  467. delIds := append(childIds, req.ChartClassifyId)
  468. err = data_manage.DeleteChartClassifyByIds(delIds)
  469. if err != nil {
  470. br.Msg = "删除失败"
  471. br.ErrMsg = "删除失败,Err:" + err.Error()
  472. return
  473. }
  474. }
  475. resp := new(data_manage.AddChartInfoResp)
  476. if req.ChartInfoId > 0 {
  477. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  478. if err != nil {
  479. if utils.IsErrNoRow(err) {
  480. br.Msg = "图表已删除,请刷新页面"
  481. br.ErrMsg = "指标不存在,Err:" + err.Error()
  482. return
  483. } else {
  484. br.Msg = "删除失败"
  485. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  486. return
  487. }
  488. }
  489. if chartInfo == nil {
  490. br.Msg = "图表已删除,请刷新页面"
  491. return
  492. }
  493. chartClassifyItem, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  494. if err != nil {
  495. br.Msg = "获取失败"
  496. br.ErrMsg = "获取图表分类详情数据失败,Err:" + err.Error()
  497. return
  498. }
  499. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  500. if err != nil {
  501. br.Msg = "获取失败"
  502. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  503. return
  504. }
  505. {
  506. haveOperaAuth := data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassifyItem.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  507. ok := data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, haveOperaAuth)
  508. if !ok {
  509. br.Msg = "没有该图表的操作权限"
  510. br.ErrMsg = "没有该图表的操作权限"
  511. return
  512. }
  513. }
  514. var myCond string
  515. var myPars []interface{}
  516. myCond += ` AND a.chart_info_id = ? `
  517. myPars = append(myPars, req.ChartInfoId)
  518. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  519. if e != nil {
  520. br.Msg = "删除失败"
  521. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  522. return
  523. }
  524. myIds := make([]int, 0)
  525. for _, m := range myCharts {
  526. myIds = append(myIds, m.MyChartId)
  527. }
  528. err = data_manage.DeleteChartInfoAndData(req.ChartInfoId)
  529. if err != nil {
  530. br.Msg = "删除失败"
  531. br.ErrMsg = "删除失败,Err:" + err.Error()
  532. return
  533. }
  534. if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  535. err = data_manage.DeleteChartSeriesAndEdbMapping(req.ChartInfoId)
  536. if err != nil {
  537. br.Msg = "删除失败"
  538. br.ErrMsg = "删除失败,Err:" + err.Error()
  539. return
  540. }
  541. }
  542. {
  543. go data.EsDeleteChartInfo(req.ChartInfoId)
  544. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  545. }
  546. var condition string
  547. var pars []interface{}
  548. condition += " AND chart_classify_id=? AND source = ? "
  549. pars = append(pars, chartInfo.ChartClassifyId, utils.CHART_SOURCE_DEFAULT)
  550. condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
  551. pars = append(pars, req.ChartInfoId)
  552. nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  553. if err != nil && !utils.IsErrNoRow(err) {
  554. br.Msg = "删除失败"
  555. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  556. return
  557. }
  558. if nextItem != nil {
  559. resp.UniqueCode = nextItem.UniqueCode
  560. resp.ChartInfoId = nextItem.ChartInfoId
  561. } else {
  562. var condition string
  563. var pars []interface{}
  564. condition += " AND level=3 "
  565. condition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
  566. pars = append(pars, chartInfo.ChartClassifyId)
  567. classifyItem, err := data_manage.GetChartClassifyByCondition(condition, pars)
  568. if err != nil && !utils.IsErrNoRow(err) {
  569. br.Msg = "删除失败"
  570. br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
  571. return
  572. }
  573. if classifyItem != nil {
  574. nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
  575. if err != nil && !utils.IsErrNoRow(err) {
  576. br.Msg = "删除失败"
  577. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  578. return
  579. }
  580. if nextItem != nil {
  581. resp.UniqueCode = nextItem.UniqueCode
  582. resp.ChartInfoId = nextItem.ChartInfoId
  583. }
  584. }
  585. }
  586. _ = data_manage.DeleteEdbRelationByObjectId(req.ChartInfoId, utils.EDB_RELATION_CHART)
  587. {
  588. chartLog := new(data_manage.ChartInfoLog)
  589. chartLog.ChartName = chartInfo.ChartName
  590. chartLog.ChartInfoId = req.ChartInfoId
  591. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  592. chartLog.SysUserId = sysUser.AdminId
  593. chartLog.SysUserRealName = sysUser.RealName
  594. chartLog.UniqueCode = chartInfo.UniqueCode
  595. chartLog.CreateTime = time.Now()
  596. chartLog.Content = string(this.Ctx.Input.RequestBody)
  597. chartLog.Status = "删除图表"
  598. chartLog.Method = this.Ctx.Input.URI()
  599. go data_manage.AddChartInfoLog(chartLog)
  600. }
  601. }
  602. br.Ret = 200
  603. br.Msg = "删除成功"
  604. br.Success = true
  605. br.Data = resp
  606. br.IsAddLog = true
  607. }
  608. // @router /chart_classify/move [post]
  609. func (this *ChartClassifyController) ChartClassifyMove() {
  610. br := new(models.BaseResponse).Init()
  611. defer func() {
  612. if br.ErrMsg == "" {
  613. br.IsSendEmail = false
  614. }
  615. this.Data["json"] = br
  616. this.ServeJSON()
  617. }()
  618. sysUser := this.SysUser
  619. if sysUser == nil {
  620. br.Msg = "请登录"
  621. br.ErrMsg = "请登录,SysUser Is Empty"
  622. br.Ret = 408
  623. return
  624. }
  625. var req data_manage.MoveChartClassifyReq
  626. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  627. if err != nil {
  628. br.Msg = "参数解析异常!"
  629. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  630. return
  631. }
  632. if req.ClassifyId <= 0 {
  633. br.Msg = "参数错误"
  634. br.ErrMsg = "分类id小于等于0"
  635. return
  636. }
  637. chartClassifyInfo, err := data_manage.GetChartClassifyById(req.ClassifyId)
  638. if err != nil {
  639. if utils.IsErrNoRow(err) {
  640. br.Msg = "分类不存在,请刷新页面"
  641. return
  642. }
  643. br.Msg = "移动失败"
  644. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  645. return
  646. }
  647. exists, e := data_manage.GetChartClassifyByParentIdAndName(utils.CHART_SOURCE_DEFAULT, req.ParentClassifyId, chartClassifyInfo.ChartClassifyName, req.ClassifyId)
  648. if e != nil && !utils.IsErrNoRow(e) {
  649. br.Msg = "移动失败"
  650. br.ErrMsg = "获取父级目录下的同名分类失败, Err: " + e.Error()
  651. return
  652. }
  653. if e == nil && exists.ChartClassifyId > 0 {
  654. br.Msg = "移动失败,分类名称已存在"
  655. return
  656. }
  657. permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, chartClassifyInfo.ChartClassifyId)
  658. if err != nil {
  659. br.Msg = "获取失败"
  660. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  661. return
  662. }
  663. {
  664. haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(chartClassifyInfo.IsJoinPermission, chartClassifyInfo.ChartClassifyId, permissionClassifyIdList)
  665. button := data.GetChartClassifyOpButton(this.SysUser, chartClassifyInfo.SysUserId, haveOperaAuth)
  666. if !button.OpButton {
  667. br.Msg = "无操作权限"
  668. br.IsSendEmail = false
  669. return
  670. }
  671. }
  672. if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
  673. br.Msg = "分类异常"
  674. br.ErrMsg = "分类异常,不是ETA图库的分类"
  675. return
  676. }
  677. updateCol := make([]string, 0)
  678. if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  679. parentChartClassifyInfo, err := data_manage.GetChartClassifyById(req.ParentClassifyId)
  680. if err != nil {
  681. br.Msg = "移动失败"
  682. br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  683. return
  684. }
  685. chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  686. chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  687. chartClassifyInfo.ModifyTime = time.Now()
  688. updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  689. }
  690. if req.PrevClassifyId > 0 {
  691. prevClassify, err := data_manage.GetChartClassifyById(req.PrevClassifyId)
  692. if err != nil {
  693. br.Msg = "移动失败"
  694. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  695. return
  696. }
  697. if req.NextClassifyId > 0 {
  698. nextClassify, err := data_manage.GetChartClassifyById(req.NextClassifyId)
  699. if err != nil {
  700. br.Msg = "移动失败"
  701. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  702. return
  703. }
  704. if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
  705. updateSortStr := `sort + 2`
  706. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
  707. } else {
  708. if nextClassify.Sort-prevClassify.Sort == 1 {
  709. updateSortStr := `sort + 1`
  710. _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  711. }
  712. }
  713. }
  714. chartClassifyInfo.Sort = prevClassify.Sort + 1
  715. chartClassifyInfo.ModifyTime = time.Now()
  716. updateCol = append(updateCol, "Sort", "ModifyTime")
  717. } else {
  718. firstClassify, err := data_manage.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
  719. if err != nil && !utils.IsErrNoRow(err) {
  720. br.Msg = "移动失败"
  721. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  722. return
  723. }
  724. if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
  725. updateSortStr := ` sort + 1 `
  726. _ = data_manage.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
  727. }
  728. chartClassifyInfo.Sort = 0 //那就是排在第一位
  729. chartClassifyInfo.ModifyTime = time.Now()
  730. updateCol = append(updateCol, "Sort", "ModifyTime")
  731. }
  732. if len(updateCol) > 0 {
  733. err = chartClassifyInfo.Update(updateCol)
  734. if err != nil {
  735. br.Msg = "移动失败"
  736. br.ErrMsg = "修改失败,Err:" + err.Error()
  737. return
  738. }
  739. }
  740. br.Ret = 200
  741. br.Success = true
  742. br.Msg = "移动成功"
  743. }
  744. // @router /chart_classify/chart/list [get]
  745. func (this *ChartClassifyController) ChartClassifyChartListV2() {
  746. br := new(models.BaseResponse).Init()
  747. defer func() {
  748. this.Data["json"] = br
  749. this.ServeJSON()
  750. }()
  751. sysUser := this.SysUser
  752. if sysUser == nil {
  753. br.Msg = "请登录"
  754. br.ErrMsg = "请登录,SysUser Is Empty"
  755. br.Ret = 408
  756. return
  757. }
  758. resp := new(data_manage.ChartClassifyListResp)
  759. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  760. if chartClassifyId <= 0 {
  761. br.Msg = "参数错误"
  762. return
  763. }
  764. noPermissionChartIdMap := make(map[int]bool)
  765. {
  766. obj := data_manage.EdbInfoNoPermissionAdmin{}
  767. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  768. if err != nil && !utils.IsErrNoRow(err) {
  769. br.Msg = "获取失败"
  770. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  771. return
  772. }
  773. for _, v := range confList {
  774. noPermissionChartIdMap[v.ChartInfoId] = true
  775. }
  776. }
  777. isShowMe, _ := this.GetBool("IsShowMe")
  778. if isShowMe {
  779. allChartInfo, err := data_manage.GetChartInfoByAdminIdAndClassify([]int{utils.CHART_SOURCE_DEFAULT}, sysUser.AdminId, chartClassifyId)
  780. if err != nil && !utils.IsErrNoRow(err) {
  781. br.Msg = "获取失败"
  782. br.ErrMsg = "获取全部数据失败,Err:" + err.Error()
  783. return
  784. }
  785. allNodes := data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  786. resp.AllNodes = allNodes
  787. br.Ret = 200
  788. br.Success = true
  789. br.Msg = "获取成功"
  790. br.Data = resp
  791. fmt.Println("source my classify")
  792. return
  793. }
  794. allChartInfo, err := data_manage.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId)
  795. if err != nil && !utils.IsErrNoRow(err) {
  796. br.Msg = "获取失败"
  797. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  798. return
  799. }
  800. allNodes := data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
  801. for k, item := range allNodes {
  802. item.Button = data.GetChartOpButton(this.SysUser, item.SysUserId, item.HaveOperaAuth)
  803. item.Button.AddButton = false
  804. item.Button.OpButton = false
  805. item.Button.DeleteButton = false
  806. allNodes[k] = item
  807. }
  808. resp.AllNodes = allNodes
  809. br.Ret = 200
  810. br.Success = true
  811. br.Msg = "获取成功"
  812. br.Data = resp
  813. }