public_edb_classify.go 24 KB

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