chart_classify.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. package range_analysis
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/services/data"
  9. "eta/eta_api/services/data/data_manage_permission"
  10. "eta/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 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. // 删除配置关联指标数据
  475. multiConfig, e := data_manage.GetMultipleGraphConfigChartMappingByChartId(chartInfo.ChartInfoId)
  476. if e != nil && e.Error() != utils.ErrNoRow() {
  477. br.Msg = "删除失败"
  478. br.ErrMsg = "获取图表关联配置失败, Err: " + e.Error()
  479. return
  480. }
  481. if multiConfig != nil { // 删除配置关联指标数据
  482. e = data_manage.DeleteMultipleGraphConfigByChartInfoId(chartInfo.ChartInfoId, multiConfig.MultipleGraphConfigId, utils.CHART_SOURCE_RANGE_ANALYSIS)
  483. if e != nil {
  484. br.Msg = "删除失败"
  485. br.ErrMsg = "删除图表关联配置失败, Err: " + e.Error()
  486. return
  487. }
  488. }
  489. var condition string
  490. var pars []interface{}
  491. condition += " AND chart_classify_id=? AND source = ? "
  492. pars = append(pars, chartInfo.ChartClassifyId, source)
  493. condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
  494. pars = append(pars, req.ChartInfoId)
  495. nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  496. if err != nil && err.Error() != utils.ErrNoRow() {
  497. br.Msg = "删除失败"
  498. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  499. return
  500. }
  501. if nextItem != nil {
  502. resp.UniqueCode = nextItem.UniqueCode
  503. resp.ChartInfoId = nextItem.ChartInfoId
  504. } else {
  505. var condition string
  506. var pars []interface{}
  507. condition += " AND level=1 "
  508. //pars = append(pars, chartInfo.ChartClassifyId)
  509. condition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
  510. pars = append(pars, chartInfo.ChartClassifyId)
  511. classifyItem, err := data_manage.GetChartClassifyByCondition(condition, pars)
  512. if err != nil && err.Error() != utils.ErrNoRow() {
  513. br.Msg = "删除失败"
  514. br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
  515. return
  516. }
  517. if classifyItem != nil {
  518. nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
  519. if err != nil && err.Error() != utils.ErrNoRow() {
  520. br.Msg = "删除失败"
  521. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  522. return
  523. }
  524. if nextItem != nil {
  525. resp.UniqueCode = nextItem.UniqueCode
  526. resp.ChartInfoId = nextItem.ChartInfoId
  527. }
  528. }
  529. }
  530. //新增操作日志
  531. {
  532. chartLog := new(data_manage.ChartInfoLog)
  533. chartLog.ChartName = chartInfo.ChartName
  534. chartLog.ChartInfoId = req.ChartInfoId
  535. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  536. chartLog.SysUserId = sysUser.AdminId
  537. chartLog.SysUserRealName = sysUser.RealName
  538. chartLog.UniqueCode = chartInfo.UniqueCode
  539. chartLog.CreateTime = time.Now()
  540. chartLog.Content = string(this.Ctx.Input.RequestBody)
  541. chartLog.Status = "删除图表"
  542. chartLog.Method = this.Ctx.Input.URI()
  543. go data_manage.AddChartInfoLog(chartLog)
  544. }
  545. }
  546. br.Ret = 200
  547. br.Msg = "删除成功"
  548. br.Success = true
  549. br.Data = resp
  550. br.IsAddLog = true
  551. }
  552. // ChartClassifyMove
  553. // @Title 区间分析图表分类移动接口
  554. // @Description 区间分析图表分类移动接口
  555. // @Success 200 {object} data_manage.MoveChartClassifyReq
  556. // @router /chart_classify/move [post]
  557. func (this *RangeChartClassifyController) ChartClassifyMove() {
  558. br := new(models.BaseResponse).Init()
  559. defer func() {
  560. if br.ErrMsg == "" {
  561. br.IsSendEmail = false
  562. }
  563. this.Data["json"] = br
  564. this.ServeJSON()
  565. }()
  566. sysUser := this.SysUser
  567. if sysUser == nil {
  568. br.Msg = "请登录"
  569. br.ErrMsg = "请登录,SysUser Is Empty"
  570. br.Ret = 408
  571. return
  572. }
  573. var req data_manage.MoveChartClassifyReq
  574. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  575. if err != nil {
  576. br.Msg = "参数解析异常!"
  577. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  578. return
  579. }
  580. if req.ClassifyId <= 0 && req.ChartInfoId <= 0 {
  581. br.Msg = "参数错误"
  582. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  583. return
  584. }
  585. err, errMsg := data.MoveChartClassify(req, sysUser, utils.CHART_SOURCE_RANGE_ANALYSIS)
  586. if errMsg != `` {
  587. br.Msg = errMsg
  588. br.ErrMsg = errMsg
  589. if err != nil {
  590. br.ErrMsg = err.Error()
  591. } else {
  592. br.IsSendEmail = false
  593. }
  594. return
  595. }
  596. //if req.ClassifyId <= 0 {
  597. // br.Msg = "参数错误"
  598. // br.ErrMsg = "分类id小于等于0"
  599. // return
  600. //}
  601. //
  602. ////判断分类是否存在
  603. //chartClassifyInfo, err := data_manage.GetChartClassifyById(req.ClassifyId)
  604. //if err != nil {
  605. // br.Msg = "移动失败"
  606. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  607. // return
  608. //}
  609. //if chartClassifyInfo.Source != utils.CHART_SOURCE_RANGE_ANALYSIS {
  610. // br.Msg = "分类异常"
  611. // br.ErrMsg = "分类异常,不是区间分析图表的分类"
  612. // return
  613. //}
  614. //updateCol := make([]string, 0)
  615. //
  616. ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  617. //if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  618. // parentChartClassifyInfo, err := data_manage.GetChartClassifyById(req.ParentClassifyId)
  619. // if err != nil {
  620. // br.Msg = "移动失败"
  621. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  622. // return
  623. // }
  624. // chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
  625. // chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
  626. // chartClassifyInfo.ModifyTime = time.Now()
  627. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  628. //}
  629. //
  630. ////如果有传入 上一个兄弟节点分类id
  631. //if req.PrevClassifyId > 0 {
  632. // //上一个兄弟节点
  633. // prevClassify, err := data_manage.GetChartClassifyById(req.PrevClassifyId)
  634. // if err != nil {
  635. // br.Msg = "移动失败"
  636. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  637. // return
  638. // }
  639. //
  640. // //如果是移动在两个兄弟节点之间
  641. // if req.NextClassifyId > 0 {
  642. // //下一个兄弟节点
  643. // nextClassify, err := data_manage.GetChartClassifyById(req.NextClassifyId)
  644. // if err != nil {
  645. // br.Msg = "移动失败"
  646. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  647. // return
  648. // }
  649. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  650. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
  651. // //变更兄弟节点的排序
  652. // updateSortStr := `sort + 2`
  653. // _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
  654. // } else {
  655. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  656. // if nextClassify.Sort-prevClassify.Sort == 1 {
  657. // //变更兄弟节点的排序
  658. // updateSortStr := `sort + 1`
  659. // _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  660. // }
  661. // }
  662. // }
  663. //
  664. // chartClassifyInfo.Sort = prevClassify.Sort + 1
  665. // chartClassifyInfo.ModifyTime = time.Now()
  666. // updateCol = append(updateCol, "Sort", "ModifyTime")
  667. //
  668. //} else {
  669. // firstClassify, err := data_manage.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
  670. // if err != nil && err.Error() != utils.ErrNoRow() {
  671. // br.Msg = "移动失败"
  672. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  673. // return
  674. // }
  675. //
  676. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  677. // if firstClassify != nil && firstClassify.Sort == 0 {
  678. // updateSortStr := ` sort + 1 `
  679. // _ = data_manage.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
  680. // }
  681. //
  682. // chartClassifyInfo.Sort = 0 //那就是排在第一位
  683. // chartClassifyInfo.ModifyTime = time.Now()
  684. // updateCol = append(updateCol, "Sort", "ModifyTime")
  685. //}
  686. //
  687. ////更新
  688. //if len(updateCol) > 0 {
  689. // err = chartClassifyInfo.Update(updateCol)
  690. // if err != nil {
  691. // br.Msg = "移动失败"
  692. // br.ErrMsg = "修改失败,Err:" + err.Error()
  693. // return
  694. // }
  695. //}
  696. br.Ret = 200
  697. br.Success = true
  698. br.Msg = "移动成功"
  699. }
  700. // ClassifyTree
  701. // @Title 多层分类列表树
  702. // @Description 多层分类列表树
  703. // @Success 200 {object} data_manage.ChartClassifyListResp
  704. // @router /chart_classify/tree [get]
  705. func (this *RangeChartClassifyController) ClassifyTree() {
  706. br := new(models.BaseResponse).Init()
  707. defer func() {
  708. if br.ErrMsg == "" {
  709. br.IsSendEmail = false
  710. }
  711. this.Data["json"] = br
  712. this.ServeJSON()
  713. }()
  714. allList, err := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_RANGE_ANALYSIS)
  715. if err != nil {
  716. br.Msg = "获取失败"
  717. br.ErrMsg = "获取所有分类失败, Err:" + err.Error()
  718. return
  719. }
  720. nodeAll := make([]*data_manage.ChartClassifyItems, 0)
  721. if len(allList) > 0 {
  722. // 已授权分类id
  723. permissionClassifyIdList, e := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, 0)
  724. if e != nil {
  725. br.Msg = "获取失败"
  726. br.ErrMsg = "获取已授权分类id数据失败,Err:" + e.Error()
  727. return
  728. }
  729. for k, v := range allList {
  730. // 数据权限
  731. v.HaveOperaAuth = data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ChartClassifyId, permissionClassifyIdList)
  732. // 按钮权限
  733. button := data.GetChartClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  734. allList[k].Button = button
  735. }
  736. nodeAll = data.GetChartClassifyTreeRecursive(allList, 0)
  737. //根据sort值排序
  738. sort.Slice(nodeAll, func(i, j int) bool {
  739. return nodeAll[i].Sort < nodeAll[j].Sort
  740. })
  741. }
  742. language := `CN`
  743. // 显示的语言
  744. {
  745. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
  746. if configDetail != nil {
  747. language = configDetail.ConfigValue
  748. } else {
  749. configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
  750. if configDetail != nil {
  751. language = configDetail.ConfigValue
  752. }
  753. }
  754. }
  755. // 是否允许添加一级分类
  756. canOpClassify := true
  757. button := data.GetChartClassifyOpButton(this.SysUser, 0, true)
  758. if !button.AddButton {
  759. canOpClassify = false
  760. }
  761. resp := new(data_manage.ChartClassifyListResp)
  762. resp.AllNodes = nodeAll
  763. resp.Language = language
  764. resp.CanOpClassify = canOpClassify
  765. br.Ret = 200
  766. br.Success = true
  767. br.Msg = "获取成功"
  768. br.Data = resp
  769. }