chart_classify.go 26 KB

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