chart_classify.go 26 KB

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