public_edb_classify.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/data_manage/request"
  8. "eta_gn/eta_api/models/system"
  9. "eta_gn/eta_api/services/data"
  10. "eta_gn/eta_api/services/data/data_manage_permission"
  11. "eta_gn/eta_api/utils"
  12. "fmt"
  13. "sort"
  14. )
  15. // EdbPublicClassifyController 数据管理-公共分类模块
  16. type EdbPublicClassifyController struct {
  17. controllers.BaseAuthController
  18. }
  19. // SimpleList
  20. // @Title 单层公共分类列表
  21. // @Description 单层公共分类列表
  22. // @Success 200 {object} data_manage.EdbClassifyListResp
  23. // @router /edb_public/classify/simple [get]
  24. func (c *EdbPublicClassifyController) SimpleList() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. c.Data["json"] = br
  28. c.ServeJSON()
  29. }()
  30. // 公共分类来源筛选
  31. // 目前只有数据加工会涉及到公共分类
  32. classifyType := utils.EdbClassifyTypeCalculate
  33. // 默认查一级公共分类和一级公共分类下的指标信息,
  34. // 如果是 子级公共分类,查询该子级公共分类的下一级公共分类和指标信息
  35. // 增加标识判断是文件夹还是指标列表
  36. parentId, _ := c.GetInt("ParentId")
  37. edbPublicClassifyObj := data_manage.EdbPublicClassify{}
  38. rootList, err := edbPublicClassifyObj.GetEdbClassifyItemsByParentId(parentId, int8(classifyType))
  39. if err != nil && !utils.IsErrNoRow(err) {
  40. br.Msg = "获取失败"
  41. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  42. return
  43. }
  44. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  45. var sortList data_manage.EdbClassifyItemList
  46. if parentId > 0 {
  47. // 指标类型(基础指标,预测指标)
  48. edbType := 0
  49. switch classifyType {
  50. case utils.EdbClassifyTypeBase:
  51. edbType = 1
  52. case utils.EdbClassifyTypeCalculate:
  53. edbType = 2
  54. }
  55. allEdbInfo, err := data_manage.GetEdbInfoByPublicClassifyId(parentId, 0, edbType)
  56. if err != nil {
  57. br.Msg = "获取指标数据失败"
  58. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  59. return
  60. }
  61. if len(allEdbInfo) > 0 {
  62. // 查询当前公共分类信息
  63. for _, v := range allEdbInfo {
  64. v.HaveOperaAuth = true
  65. button := data.GetEdbOpButton(c.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  66. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  67. v.Button = button
  68. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  69. v.ParentId = parentId
  70. nodeAll = append(nodeAll, v)
  71. }
  72. }
  73. }
  74. if len(rootList) > 0 {
  75. // 已授权公共分类id
  76. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(c.SysUser.AdminId, 0)
  77. if err != nil {
  78. br.Msg = "获取失败"
  79. br.ErrMsg = "获取已授权公共分类id数据失败,Err:" + err.Error()
  80. return
  81. }
  82. for _, v := range rootList {
  83. // 公共分类设定了权限且无权限, 那么忽略掉该节点
  84. if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) {
  85. continue
  86. }
  87. // 数据权限
  88. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  89. // 按钮权限
  90. button := data.GetEdbClassifyOpButton(c.SysUser, v.SysUserId, v.HaveOperaAuth)
  91. v.Button = button
  92. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  93. nodeAll = append(nodeAll, v)
  94. }
  95. }
  96. if len(nodeAll) > 0 {
  97. //根据sort值排序
  98. sortList = nodeAll
  99. sort.Sort(sortList)
  100. }
  101. language := `CN`
  102. // 指标显示的语言
  103. {
  104. configDetail, _ := system.GetConfigDetailByCode(c.SysUser.AdminId, system.EdbLanguageVar)
  105. if configDetail != nil {
  106. language = configDetail.ConfigValue
  107. } else {
  108. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  109. if configDetail != nil {
  110. language = configDetail.ConfigValue
  111. }
  112. }
  113. }
  114. // 是否允许添加一级公共分类
  115. canOpClassify := true
  116. button := data.GetEdbClassifyOpButton(c.SysUser, 0, true)
  117. if !button.AddButton {
  118. canOpClassify = false
  119. }
  120. resp := new(data_manage.EdbClassifyListResp)
  121. resp.AllNodes = sortList
  122. resp.Language = language
  123. resp.CanOpClassify = canOpClassify
  124. br.Ret = 200
  125. br.Success = true
  126. br.Msg = "获取成功"
  127. br.Data = resp
  128. }
  129. // ClassifyTree
  130. // @Title 多层公共分类列表树
  131. // @Description 多层公共分类列表树
  132. // @Success 200 {object} data_manage.EdbClassifyListResp
  133. // @router /edb_public/classify/tree [get]
  134. func (c *EdbPublicClassifyController) ClassifyTree() {
  135. br := new(models.BaseResponse).Init()
  136. defer func() {
  137. c.Data["json"] = br
  138. c.ServeJSON()
  139. }()
  140. // 公共分类来源筛选
  141. classifyType := utils.EdbClassifyTypeCalculate
  142. edbPublicClassifyObj := data_manage.EdbPublicClassify{}
  143. allList, err := edbPublicClassifyObj.GetAllEdbClassifyByType(int8(classifyType))
  144. if err != nil && !utils.IsErrNoRow(err) {
  145. br.Msg = "获取失败"
  146. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  147. return
  148. }
  149. var sortList data_manage.EdbClassifyItemList
  150. if len(allList) > 0 {
  151. for k, v := range allList {
  152. // 数据权限
  153. v.HaveOperaAuth = true
  154. // 按钮权限
  155. button := data.GetEdbClassifyOpButton(c.SysUser, v.SysUserId, v.HaveOperaAuth)
  156. allList[k].Button = button
  157. }
  158. allList = data.GetClassifyTreeRecursive(allList, 0)
  159. //根据sort值排序
  160. sortList = allList
  161. sort.Sort(sortList)
  162. }
  163. language := `CN`
  164. // 是否允许添加一级公共分类
  165. canOpClassify := true
  166. button := data.GetEdbClassifyOpButton(c.SysUser, 0, true)
  167. if !button.AddButton {
  168. canOpClassify = false
  169. }
  170. resp := new(data_manage.EdbClassifyListResp)
  171. resp.AllNodes = sortList
  172. resp.Language = language
  173. resp.CanOpClassify = canOpClassify
  174. br.Ret = 200
  175. br.Success = true
  176. br.Msg = "获取成功"
  177. br.Data = resp
  178. }
  179. // AddEdbClassify
  180. // @Title 新增公共分类
  181. // @Description 新增公共分类接口
  182. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  183. // @Success 200 Ret=200 保存成功
  184. // @router /edb_public/classify/add [post]
  185. func (c *EdbPublicClassifyController) AddClassify() {
  186. br := new(models.BaseResponse).Init()
  187. defer func() {
  188. c.Data["json"] = br
  189. c.ServeJSON()
  190. }()
  191. var req data_manage.AddEdbClassifyReq
  192. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  193. if err != nil {
  194. br.Msg = "参数解析异常!"
  195. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  196. return
  197. }
  198. if req.ClassifyName == "" {
  199. br.Msg = "请输入公共分类名称"
  200. br.IsSendEmail = false
  201. return
  202. }
  203. if req.ParentId < 0 {
  204. br.Msg = "参数错误"
  205. br.IsSendEmail = false
  206. return
  207. }
  208. // 公共分类来源筛选
  209. classifyType := utils.EdbClassifyTypeCalculate
  210. //添加指标
  211. _, err, errMsg := data.AddEdbPublicClassify(req.ClassifyName, req.ParentId, uint8(classifyType), c.SysUser.AdminId, c.SysUser.RealName)
  212. if errMsg != `` {
  213. br.Msg = errMsg
  214. br.ErrMsg = errMsg
  215. if err != nil {
  216. br.ErrMsg = errMsg + ";Err:" + err.Error()
  217. } else {
  218. br.IsSendEmail = false
  219. }
  220. return
  221. }
  222. //count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, req.ParentId)
  223. //if err != nil {
  224. // br.Msg = "判断名称是否已存在失败"
  225. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  226. // return
  227. //}
  228. //if count > 0 {
  229. // br.Msg = "公共分类名称已存在,请重新输入"
  230. // br.IsSendEmail = false
  231. // return
  232. //}
  233. ////获取该层级下最大的排序数
  234. //maxSort, err := data_manage.GetEdbClassifyMaxSort(req.ParentId, req.ClassifyType)
  235. //
  236. //classify := new(data_manage.EdbClassify)
  237. //classify.ClassifyType = req.ClassifyType
  238. //classify.ParentId = req.ParentId
  239. //classify.ClassifyName = req.ClassifyName
  240. //classify.HasData = 0
  241. //classify.CreateTime = time.Now()
  242. //classify.ModifyTime = time.Now()
  243. //classify.SysUserId = c.SysUser.AdminId
  244. //classify.SysUserRealName = c.SysUser.RealName
  245. //classify.Level = req.Level + 1
  246. //timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  247. //classify.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  248. //classify.Sort = maxSort
  249. //
  250. //_, err = data_manage.AddEdbClassify(classify)
  251. //if err != nil {
  252. // br.Msg = "保存公共分类失败"
  253. // br.ErrMsg = "保存公共分类失败,Err:" + err.Error()
  254. // return
  255. //}
  256. br.Ret = 200
  257. br.Msg = "新增成功"
  258. br.Success = true
  259. br.IsAddLog = true
  260. }
  261. // EditEdbClassify
  262. // @Title 修改公共分类
  263. // @Description 修改公共分类接口
  264. // @Param request body data_manage.EditEdbClassifyReq true "type json string"
  265. // @Success 200 Ret=200 修改成功
  266. // @router /edb_public/classify/edit [post]
  267. func (c *EdbPublicClassifyController) EditEdbClassify() {
  268. br := new(models.BaseResponse).Init()
  269. defer func() {
  270. c.Data["json"] = br
  271. c.ServeJSON()
  272. }()
  273. var req data_manage.EditEdbClassifyReq
  274. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  275. if err != nil {
  276. br.Msg = "参数解析异常!"
  277. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  278. return
  279. }
  280. if req.ClassifyName == "" {
  281. br.Msg = "请输入公共分类名称"
  282. br.IsSendEmail = false
  283. return
  284. }
  285. if req.ClassifyId < 0 {
  286. br.Msg = "参数错误"
  287. br.IsSendEmail = false
  288. return
  289. }
  290. err, errMsg := data.EditEdbPublicClassify(req.ClassifyId, req.ClassifyName, c.SysUser)
  291. if errMsg != `` {
  292. br.Msg = errMsg
  293. br.ErrMsg = errMsg
  294. if err != nil {
  295. br.ErrMsg = errMsg + ";Err:" + err.Error()
  296. } else {
  297. br.IsSendEmail = false
  298. }
  299. return
  300. }
  301. br.Ret = 200
  302. br.Msg = "修改成功"
  303. br.Success = true
  304. br.IsAddLog = true
  305. }
  306. // DeleteEdbClassifyCheck
  307. // @Title 删除检测接口
  308. // @Description 删除检测接口
  309. // @Param request body request.PublicClassifyDeleteCheckReq true "type json string"
  310. // @Success 200 Ret=200 检测成功
  311. // @router /edb_public/classify/delete/check [post]
  312. func (c *EdbPublicClassifyController) DeleteClassifyCheck() {
  313. br := new(models.BaseResponse).Init()
  314. defer func() {
  315. c.Data["json"] = br
  316. c.ServeJSON()
  317. }()
  318. var req request.PublicClassifyDeleteCheckReq
  319. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  320. if err != nil {
  321. br.Msg = "参数解析异常!"
  322. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  323. return
  324. }
  325. if req.ClassifyId <= 0 {
  326. br.Msg = "参数错误"
  327. br.IsSendEmail = false
  328. return
  329. }
  330. deleteStatus, tipsMsg, _, tableList, err, errMsg := data.DeleteEdbPublicClassifyCheck(req.ClassifyId, c.SysUser)
  331. if errMsg != `` {
  332. br.Msg = errMsg
  333. br.ErrMsg = errMsg
  334. if err != nil {
  335. br.ErrMsg = err.Error()
  336. } else {
  337. br.IsSendEmail = false
  338. }
  339. return
  340. }
  341. if c.Lang == "en" {
  342. if utils.ViperConfig.InConfig(tipsMsg) {
  343. tipsMsg = utils.ViperConfig.GetString(tipsMsg)
  344. }
  345. }
  346. //var deleteStatus int
  347. //var tipsMsg string
  348. ////删除公共分类
  349. //if req.ClassifyId > 0 && req.EdbInfoId == 0 {
  350. // //判断公共分类下,是否含有指标
  351. // count, err := data_manage.GetEdbInfoCountByClassifyId(req.ClassifyId)
  352. // if err != nil {
  353. // br.Msg = "删除失败"
  354. // br.ErrMsg = "公共分类下是否含有指标失败,Err:" + err.Error()
  355. // return
  356. // }
  357. //
  358. // if count > 0 {
  359. // deleteStatus = 1
  360. // tipsMsg = "若目录关联指标不可删除"
  361. // }
  362. //}
  363. //
  364. //if deleteStatus != 1 && req.EdbInfoId == 0 {
  365. // classifyCount, err := data_manage.GetClassifyCountByClassifyId(req.ClassifyId)
  366. // if err != nil && !utils.IsErrNoRow(err) {
  367. // br.Msg = "删除失败"
  368. // br.ErrMsg = "公共分类下是否含有指标失败,Err:" + err.Error()
  369. // return
  370. // }
  371. // if classifyCount > 0 {
  372. // deleteStatus = 2
  373. // tipsMsg = "确认删除当前目录及包含的子目录吗"
  374. // }
  375. //}
  376. //
  377. ////删除指标
  378. //if req.EdbInfoId > 0 {
  379. // //判断指标是否用于作图,如果用于作图,则不可删除
  380. // chartCount, err := data_manage.GetChartEdbMappingCount(req.EdbInfoId)
  381. // if err != nil && !utils.IsErrNoRow(err) {
  382. // br.Msg = "删除失败"
  383. // br.ErrMsg = "判断指标是否被用于作图失败,Err:" + err.Error()
  384. // return
  385. // }
  386. // if chartCount > 0 {
  387. // deleteStatus = 3
  388. // tipsMsg = "当前指标已用作画图,不可删除"
  389. // }
  390. // //判断指标是否用于计算
  391. // {
  392. // calculateCount, err := data_manage.GetEdbInfoCalculateMappingCount(req.EdbInfoId)
  393. // if err != nil && !utils.IsErrNoRow(err) {
  394. // br.Msg = "删除失败"
  395. // br.ErrMsg = "判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + err.Error()
  396. // return
  397. // }
  398. // if calculateCount > 0 {
  399. // deleteStatus = 4
  400. // tipsMsg = "当前指标已用作,指标运算,不可删除"
  401. // }
  402. // }
  403. //}
  404. resp := new(data_manage.ClassifyDeleteCheckResp)
  405. resp.DeleteStatus = deleteStatus
  406. resp.TipsMsg = tipsMsg
  407. resp.TableList = tableList
  408. br.Ret = 200
  409. br.Msg = "检测成功"
  410. br.Success = true
  411. br.Data = resp
  412. }
  413. // DeleteEdbClassify
  414. // @Title 删除公共分类/指标
  415. // @Description 删除公共分类/指标接口
  416. // @Param request body request.PublicClassifyDeleteCheckReq true "type json string"
  417. // @Success 200 Ret=200 删除成功
  418. // @router /edb_public/classify/delete [post]
  419. func (c *EdbPublicClassifyController) DeleteClassify() {
  420. br := new(models.BaseResponse).Init()
  421. defer func() {
  422. c.Data["json"] = br
  423. c.ServeJSON()
  424. }()
  425. sysUser := c.SysUser
  426. if sysUser == nil {
  427. br.Msg = "请登录"
  428. br.ErrMsg = "请登录,SysUser Is Empty"
  429. br.Ret = 408
  430. return
  431. }
  432. var req request.PublicClassifyDeleteCheckReq
  433. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  434. if err != nil {
  435. br.Msg = "参数解析异常!"
  436. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  437. return
  438. }
  439. if req.ClassifyId <= 0 {
  440. br.Msg = "参数错误"
  441. br.IsSendEmail = false
  442. return
  443. }
  444. nextItem, _, err, errMsg := data.DeleteEdbPublicClassify(req.ClassifyId, sysUser, string(c.Ctx.Input.RequestBody), c.Ctx.Input.URI())
  445. if errMsg != `` {
  446. br.Msg = errMsg
  447. br.ErrMsg = errMsg
  448. if err != nil {
  449. br.ErrMsg = err.Error()
  450. } else {
  451. br.IsSendEmail = false
  452. }
  453. return
  454. }
  455. resp := data_manage.AddEdbInfoResp{}
  456. if nextItem != nil {
  457. resp = data_manage.AddEdbInfoResp{
  458. EdbInfoId: nextItem.EdbInfoId,
  459. UniqueCode: nextItem.UniqueCode,
  460. }
  461. }
  462. br.Ret = 200
  463. br.Msg = "删除成功"
  464. br.Success = true
  465. br.IsAddLog = true
  466. br.Data = resp
  467. }
  468. // ListV2
  469. // @Title 公共分类列表
  470. // @Description 公共分类列表接口
  471. // @Success 200 {object} data_manage.EdbClassifyListResp
  472. // @router /edb_public/classify/list [get]
  473. func (c *EdbPublicClassifyController) ListV2() {
  474. br := new(models.BaseResponse).Init()
  475. defer func() {
  476. c.Data["json"] = br
  477. c.ServeJSON()
  478. }()
  479. // 公共分类来源筛选
  480. classifyType, _ := c.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  481. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  482. br.Msg = "参数有误"
  483. br.ErrMsg = fmt.Sprintf("指标公共分类类型有误, ClassifyType: %d", classifyType)
  484. return
  485. }
  486. edbType := utils.EdbTypeBase
  487. if classifyType == utils.EdbClassifyTypeCalculate {
  488. edbType = utils.EdbTypeCalculate
  489. }
  490. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType), c.SysUser.AdminId)
  491. if err != nil && !utils.IsErrNoRow(err) {
  492. br.Msg = "获取失败"
  493. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  494. return
  495. }
  496. //classifyAll, err := data_manage.GetEdbClassifyAll()
  497. classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType, c.SysUser.AdminId)
  498. if err != nil && !utils.IsErrNoRow(err) {
  499. br.Msg = "获取失败"
  500. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  501. return
  502. }
  503. // 公共分类map
  504. classifyMap := make(map[int]*data_manage.EdbClassifyItems)
  505. for _, v := range classifyAll {
  506. classifyMap[v.ClassifyId] = v
  507. }
  508. // 已授权公共分类id
  509. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(c.SysUser.AdminId, 0)
  510. if err != nil {
  511. br.Msg = "获取失败"
  512. br.ErrMsg = "获取已授权公共分类id数据失败,Err:" + err.Error()
  513. return
  514. }
  515. // 获取当前账号的不可见指标
  516. obj := data_manage.EdbInfoNoPermissionAdmin{}
  517. confList, err := obj.GetAllListByAdminId(c.SysUser.AdminId)
  518. if err != nil && !utils.IsErrNoRow(err) {
  519. br.Msg = "获取失败"
  520. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  521. return
  522. }
  523. noPermissionEdbInfoIdMap := make(map[int]bool)
  524. for _, v := range confList {
  525. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  526. }
  527. //allEdbInfo, err := data_manage.GetEdbInfoAll(utils.EDB_INFO_TYPE)
  528. allEdbInfo, err := data_manage.GetEdbInfoByTypes(utils.EDB_INFO_TYPE, edbType)
  529. if err != nil && !utils.IsErrNoRow(err) {
  530. br.Msg = "获取失败"
  531. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  532. return
  533. }
  534. edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  535. if len(allEdbInfo) > 0 {
  536. // 获取所有有权限的指标和公共分类
  537. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(c.SysUser.AdminId, 0, 0)
  538. if err != nil {
  539. br.Msg = "获取失败"
  540. br.ErrMsg = "获取所有有权限的指标和公共分类失败,Err:" + err.Error()
  541. return
  542. }
  543. for _, v := range allEdbInfo {
  544. // 如果指标不可见,那么就不返回该指标
  545. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  546. continue
  547. }
  548. // 数据权限
  549. if classifyInfo, ok := classifyMap[v.ClassifyId]; ok {
  550. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  551. }
  552. button := data.GetEdbOpButton(c.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  553. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  554. v.Button = button
  555. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  556. }
  557. }
  558. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  559. for _, v := range classifyAll {
  560. // 数据权限
  561. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  562. // 按钮权限
  563. button := data.GetEdbClassifyOpButton(c.SysUser, v.SysUserId, v.HaveOperaAuth)
  564. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  565. v.Button = button
  566. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  567. if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  568. v.Children = existItems
  569. } else {
  570. items := make([]*data_manage.EdbClassifyItems, 0)
  571. v.Children = items
  572. }
  573. }
  574. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  575. for _, v := range rootList {
  576. // 数据权限
  577. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  578. // 按钮权限
  579. button := data.GetEdbClassifyOpButton(c.SysUser, v.SysUserId, v.HaveOperaAuth)
  580. v.Button = button
  581. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  582. v.Children = existItems
  583. } else {
  584. items := make([]*data_manage.EdbClassifyItems, 0)
  585. v.Children = items
  586. }
  587. nodeAll = append(nodeAll, v)
  588. }
  589. resp := new(data_manage.EdbClassifyListResp)
  590. resp.AllNodes = nodeAll
  591. resp.CanOpClassify = true
  592. br.Ret = 200
  593. br.Success = true
  594. br.Msg = "获取成功"
  595. br.Data = resp
  596. }
  597. // EdbClassifyMove
  598. // @Title 分类移动接口
  599. // @Description 分类移动接口
  600. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  601. // @router /edb_public/edb_classify/move [post]
  602. func (c *EdbPublicClassifyController) EdbClassifyMove() {
  603. br := new(models.BaseResponse).Init()
  604. defer func() {
  605. c.Data["json"] = br
  606. c.ServeJSON()
  607. }()
  608. sysUser := c.SysUser
  609. if sysUser == nil {
  610. br.Msg = "请登录"
  611. br.ErrMsg = "请登录,SysUser Is Empty"
  612. br.Ret = 408
  613. return
  614. }
  615. var req data_manage.MoveEdbClassifyReq
  616. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  617. if err != nil {
  618. br.Msg = "参数解析异常!"
  619. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  620. return
  621. }
  622. if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
  623. br.Msg = "参数错误"
  624. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  625. return
  626. }
  627. // 分类来源筛选
  628. classifyType := req.ClassifyType // 默认指标库的
  629. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  630. br.Msg = "参数有误"
  631. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  632. return
  633. }
  634. err, errMsg := data.MoveEdbPublicClassify(req, sysUser, uint8(classifyType))
  635. if errMsg != `` {
  636. br.Msg = errMsg
  637. br.ErrMsg = errMsg
  638. if err != nil {
  639. br.ErrMsg = err.Error()
  640. } else {
  641. br.IsSendEmail = false
  642. }
  643. return
  644. }
  645. ////判断分类是否存在
  646. //edbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  647. //if err != nil {
  648. // br.Msg = "移动失败"
  649. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  650. // return
  651. //}
  652. //updateCol := make([]string, 0)
  653. //
  654. ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  655. //if edbClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  656. // parentEdbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ParentClassifyId)
  657. // if err != nil {
  658. // br.Msg = "移动失败"
  659. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  660. // return
  661. // }
  662. // edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  663. // edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  664. // edbClassifyInfo.ModifyTime = time.Now()
  665. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  666. //}
  667. //
  668. ////如果有传入 上一个兄弟节点分类id
  669. //if req.PrevClassifyId > 0 {
  670. // prevClassify, err := data_manage.GetEdbClassifyById(req.PrevClassifyId)
  671. // if err != nil {
  672. // br.Msg = "移动失败"
  673. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  674. // return
  675. // }
  676. //
  677. // //如果是移动在两个兄弟节点之间
  678. // if req.NextClassifyId > 0 {
  679. // //下一个兄弟节点
  680. // nextClassify, err := data_manage.GetEdbClassifyById(req.NextClassifyId)
  681. // if err != nil {
  682. // br.Msg = "移动失败"
  683. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  684. // return
  685. // }
  686. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  687. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort {
  688. // //变更兄弟节点的排序
  689. // updateSortStr := `sort + 2`
  690. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
  691. // } else {
  692. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  693. // if nextClassify.Sort-prevClassify.Sort == 1 {
  694. // //变更兄弟节点的排序
  695. // updateSortStr := `sort + 1`
  696. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  697. // }
  698. // }
  699. // }
  700. //
  701. // edbClassifyInfo.Sort = prevClassify.Sort + 1
  702. // edbClassifyInfo.ModifyTime = time.Now()
  703. // updateCol = append(updateCol, "Sort", "ModifyTime")
  704. //} else {
  705. // firstClassify, err := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId)
  706. // if err != nil && !utils.IsErrNoRow(err) {
  707. // br.Msg = "移动失败"
  708. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  709. // return
  710. // }
  711. //
  712. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  713. // if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
  714. // updateSortStr := ` sort + 1 `
  715. // _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr)
  716. // }
  717. //
  718. // edbClassifyInfo.Sort = 0 //那就是排在第一位
  719. // edbClassifyInfo.ModifyTime = time.Now()
  720. // updateCol = append(updateCol, "Sort", "ModifyTime")
  721. //}
  722. //
  723. ////更新
  724. //if len(updateCol) > 0 {
  725. // err = edbClassifyInfo.Update(updateCol)
  726. // if err != nil {
  727. // br.Msg = "移动失败"
  728. // br.ErrMsg = "修改失败,Err:" + err.Error()
  729. // return
  730. // }
  731. //}
  732. br.Ret = 200
  733. br.Success = true
  734. br.Msg = "移动成功"
  735. }