chart_classify.go 26 KB

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