edb_classify.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/services/data"
  9. "eta/eta_api/services/data/data_manage_permission"
  10. "eta/eta_api/utils"
  11. "sort"
  12. )
  13. // EdbClassifyController 数据管理-分类模块
  14. type EdbClassifyController struct {
  15. controllers.BaseAuthController
  16. }
  17. // ListV2
  18. // @Title 分类列表
  19. // @Description 分类列表接口
  20. // @Success 200 {object} data_manage.EdbClassifyListResp
  21. // @router /classify/list [get]
  22. func (this *EdbClassifyController) ListV2() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  29. if err != nil && err.Error() != utils.ErrNoRow() {
  30. br.Msg = "获取失败"
  31. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  32. return
  33. }
  34. classifyAll, err := data_manage.GetEdbClassifyAll()
  35. if err != nil && err.Error() != utils.ErrNoRow() {
  36. br.Msg = "获取失败"
  37. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  38. return
  39. }
  40. // 分类map
  41. classifyMap := make(map[int]*data_manage.EdbClassifyItems)
  42. for _, v := range classifyAll {
  43. classifyMap[v.ClassifyId] = v
  44. }
  45. // 已授权分类id
  46. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  47. if err != nil {
  48. br.Msg = "获取失败"
  49. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  50. return
  51. }
  52. // 获取当前账号的不可见指标
  53. obj := data_manage.EdbInfoNoPermissionAdmin{}
  54. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  55. if err != nil && err.Error() != utils.ErrNoRow() {
  56. br.Msg = "获取失败"
  57. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  58. return
  59. }
  60. noPermissionEdbInfoIdMap := make(map[int]bool)
  61. for _, v := range confList {
  62. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  63. }
  64. allEdbInfo, err := data_manage.GetEdbInfoAll(utils.EDB_INFO_TYPE)
  65. if err != nil && err.Error() != utils.ErrNoRow() {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  68. return
  69. }
  70. edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  71. if len(allEdbInfo) > 0 {
  72. // 获取所有有权限的指标和分类
  73. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  74. if err != nil {
  75. br.Msg = "获取失败"
  76. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  77. return
  78. }
  79. for _, v := range allEdbInfo {
  80. // 如果指标不可见,那么就不返回该指标
  81. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  82. continue
  83. }
  84. // 数据权限
  85. if classifyInfo, ok := classifyMap[v.ClassifyId]; ok {
  86. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  87. }
  88. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  89. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  90. v.Button = button
  91. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  92. }
  93. }
  94. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  95. for _, v := range classifyAll {
  96. // 数据权限
  97. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  98. // 按钮权限
  99. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  100. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  101. v.Button = button
  102. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  103. if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  104. v.Children = existItems
  105. } else {
  106. items := make([]*data_manage.EdbClassifyItems, 0)
  107. v.Children = items
  108. }
  109. }
  110. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  111. for _, v := range rootList {
  112. // 数据权限
  113. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  114. // 按钮权限
  115. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  116. v.Button = button
  117. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  118. v.Children = existItems
  119. } else {
  120. items := make([]*data_manage.EdbClassifyItems, 0)
  121. v.Children = items
  122. }
  123. nodeAll = append(nodeAll, v)
  124. }
  125. resp := new(data_manage.EdbClassifyListResp)
  126. resp.AllNodes = nodeAll
  127. resp.CanOpClassify = true
  128. br.Ret = 200
  129. br.Success = true
  130. br.Msg = "获取成功"
  131. br.Data = resp
  132. }
  133. // @Title 获取所有分类接口-不包含指标
  134. // @Description 获取所有分类接口-不包含指标
  135. // @Success 200 {object} data_manage.EdbClassifyListResp
  136. // @router /classify/items [get]
  137. func (this *EdbClassifyController) Items() {
  138. br := new(models.BaseResponse).Init()
  139. defer func() {
  140. this.Data["json"] = br
  141. this.ServeJSON()
  142. }()
  143. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  144. if err != nil {
  145. br.Msg = "获取失败"
  146. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  147. return
  148. }
  149. classifyAll, err := data_manage.GetEdbClassifyAll()
  150. if err != nil {
  151. br.Msg = "获取失败"
  152. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  153. return
  154. }
  155. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  156. for k := range rootList {
  157. rootNode := rootList[k]
  158. data.EdbClassifyItemsMakeTree(classifyAll, rootNode)
  159. nodeAll = append(nodeAll, rootNode)
  160. }
  161. resp := new(data_manage.EdbClassifyListResp)
  162. resp.AllNodes = nodeAll
  163. br.Ret = 200
  164. br.Success = true
  165. br.Msg = "获取成功"
  166. br.Data = resp
  167. }
  168. // @Title 新增分类
  169. // @Description 新增分类接口
  170. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  171. // @Success 200 Ret=200 保存成功
  172. // @router /classify/add [post]
  173. func (this *EdbClassifyController) AddEdbClassify() {
  174. br := new(models.BaseResponse).Init()
  175. defer func() {
  176. this.Data["json"] = br
  177. this.ServeJSON()
  178. }()
  179. var req data_manage.AddEdbClassifyReq
  180. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  181. if err != nil {
  182. br.Msg = "参数解析异常!"
  183. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  184. return
  185. }
  186. if req.ClassifyName == "" {
  187. br.Msg = "请输入分类名称"
  188. br.IsSendEmail = false
  189. return
  190. }
  191. if req.ParentId < 0 {
  192. br.Msg = "参数错误"
  193. br.IsSendEmail = false
  194. return
  195. }
  196. //添加指标
  197. _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, 0, this.SysUser.AdminId, this.SysUser.AdminName, this.Lang)
  198. if errMsg != `` {
  199. br.Msg = errMsg
  200. br.ErrMsg = errMsg
  201. if err != nil {
  202. br.ErrMsg = errMsg + ";Err:" + err.Error()
  203. } else {
  204. br.IsSendEmail = false
  205. }
  206. return
  207. }
  208. //count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, req.ParentId)
  209. //if err != nil {
  210. // br.Msg = "判断名称是否已存在失败"
  211. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  212. // return
  213. //}
  214. //if count > 0 {
  215. // br.Msg = "分类名称已存在,请重新输入"
  216. // br.IsSendEmail = false
  217. // return
  218. //}
  219. ////获取该层级下最大的排序数
  220. //maxSort, err := data_manage.GetEdbClassifyMaxSort(req.ParentId, req.ClassifyType)
  221. //
  222. //classify := new(data_manage.EdbClassify)
  223. //classify.ClassifyType = req.ClassifyType
  224. //classify.ParentId = req.ParentId
  225. //classify.ClassifyName = req.ClassifyName
  226. //classify.HasData = 0
  227. //classify.CreateTime = time.Now()
  228. //classify.ModifyTime = time.Now()
  229. //classify.SysUserId = this.SysUser.AdminId
  230. //classify.SysUserRealName = this.SysUser.RealName
  231. //classify.Level = req.Level + 1
  232. //timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  233. //classify.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  234. //classify.Sort = maxSort
  235. //
  236. //_, err = data_manage.AddEdbClassify(classify)
  237. //if err != nil {
  238. // br.Msg = "保存分类失败"
  239. // br.ErrMsg = "保存分类失败,Err:" + err.Error()
  240. // return
  241. //}
  242. br.Ret = 200
  243. br.Msg = "保存成功"
  244. br.Success = true
  245. br.IsAddLog = true
  246. }
  247. // @Title 修改分类
  248. // @Description 修改分类接口
  249. // @Param request body data_manage.EditEdbClassifyReq true "type json string"
  250. // @Success 200 Ret=200 修改成功
  251. // @router /classify/edit [post]
  252. func (this *EdbClassifyController) EditEdbClassify() {
  253. br := new(models.BaseResponse).Init()
  254. defer func() {
  255. this.Data["json"] = br
  256. this.ServeJSON()
  257. }()
  258. var req data_manage.EditEdbClassifyReq
  259. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  260. if err != nil {
  261. br.Msg = "参数解析异常!"
  262. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  263. return
  264. }
  265. if req.ClassifyName == "" {
  266. br.Msg = "请输入分类名称"
  267. br.IsSendEmail = false
  268. return
  269. }
  270. if req.ClassifyId < 0 {
  271. br.Msg = "参数错误"
  272. br.IsSendEmail = false
  273. return
  274. }
  275. err, errMsg := data.EditEdbClassify(req.ClassifyId, req.ClassifyName, this.Lang, this.SysUser)
  276. if errMsg != `` {
  277. br.Msg = errMsg
  278. br.ErrMsg = errMsg
  279. if err != nil {
  280. br.ErrMsg = errMsg + ";Err:" + err.Error()
  281. } else {
  282. br.IsSendEmail = false
  283. }
  284. return
  285. }
  286. //item, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  287. //if err != nil {
  288. // br.Msg = "保存失败"
  289. // br.Msg = "获取分类信息失败,Err:" + err.Error()
  290. // return
  291. //}
  292. //
  293. //if item.ClassifyName != req.ClassifyName {
  294. // count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, item.ParentId)
  295. // if err != nil {
  296. // br.Msg = "判断名称是否已存在失败"
  297. // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
  298. // return
  299. // }
  300. // if count > 0 {
  301. // br.Msg = "分类名称已存在,请重新输入"
  302. // br.IsSendEmail = false
  303. // return
  304. // }
  305. //
  306. // err = data_manage.EditEdbClassify(req.ClassifyId, req.ClassifyName)
  307. // if err != nil {
  308. // br.Msg = "保存失败"
  309. // br.ErrMsg = "保存失败,Err:" + err.Error()
  310. // return
  311. // }
  312. //}
  313. br.Ret = 200
  314. br.Msg = "保存成功"
  315. br.Success = true
  316. br.IsAddLog = true
  317. }
  318. // @Title 删除检测接口
  319. // @Description 删除检测接口
  320. // @Param request body data_manage.ClassifyDeleteCheckReq true "type json string"
  321. // @Success 200 Ret=200 检测成功
  322. // @router /classify/delete/check [post]
  323. func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
  324. br := new(models.BaseResponse).Init()
  325. defer func() {
  326. this.Data["json"] = br
  327. this.ServeJSON()
  328. }()
  329. var req data_manage.ClassifyDeleteCheckReq
  330. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  331. if err != nil {
  332. br.Msg = "参数解析异常!"
  333. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  334. return
  335. }
  336. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  337. br.Msg = "参数错误"
  338. br.IsSendEmail = false
  339. return
  340. }
  341. deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
  342. if errMsg != `` {
  343. br.Msg = errMsg
  344. br.ErrMsg = errMsg
  345. if err != nil {
  346. br.ErrMsg = err.Error()
  347. } else {
  348. br.IsSendEmail = false
  349. }
  350. return
  351. }
  352. if this.Lang == "en" {
  353. if utils.ViperConfig.InConfig(tipsMsg) {
  354. tipsMsg = utils.ViperConfig.GetString(tipsMsg)
  355. }
  356. }
  357. //var deleteStatus int
  358. //var tipsMsg string
  359. ////删除分类
  360. //if req.ClassifyId > 0 && req.EdbInfoId == 0 {
  361. // //判断分类下,是否含有指标
  362. // count, err := data_manage.GetEdbInfoCountByClassifyId(req.ClassifyId)
  363. // if err != nil {
  364. // br.Msg = "删除失败"
  365. // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  366. // return
  367. // }
  368. //
  369. // if count > 0 {
  370. // deleteStatus = 1
  371. // tipsMsg = "若目录关联指标不可删除"
  372. // }
  373. //}
  374. //
  375. //if deleteStatus != 1 && req.EdbInfoId == 0 {
  376. // classifyCount, err := data_manage.GetClassifyCountByClassifyId(req.ClassifyId)
  377. // if err != nil && err.Error() != utils.ErrNoRow() {
  378. // br.Msg = "删除失败"
  379. // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
  380. // return
  381. // }
  382. // if classifyCount > 0 {
  383. // deleteStatus = 2
  384. // tipsMsg = "确认删除当前目录及包含的子目录吗"
  385. // }
  386. //}
  387. //
  388. ////删除指标
  389. //if req.EdbInfoId > 0 {
  390. // //判断指标是否用于作图,如果用于作图,则不可删除
  391. // chartCount, err := data_manage.GetChartEdbMappingCount(req.EdbInfoId)
  392. // if err != nil && err.Error() != utils.ErrNoRow() {
  393. // br.Msg = "删除失败"
  394. // br.ErrMsg = "判断指标是否被用于作图失败,Err:" + err.Error()
  395. // return
  396. // }
  397. // if chartCount > 0 {
  398. // deleteStatus = 3
  399. // tipsMsg = "当前指标已用作画图,不可删除"
  400. // }
  401. // //判断指标是否用于计算
  402. // {
  403. // calculateCount, err := data_manage.GetEdbInfoCalculateMappingCount(req.EdbInfoId)
  404. // if err != nil && err.Error() != utils.ErrNoRow() {
  405. // br.Msg = "删除失败"
  406. // br.ErrMsg = "判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + err.Error()
  407. // return
  408. // }
  409. // if calculateCount > 0 {
  410. // deleteStatus = 4
  411. // tipsMsg = "当前指标已用作,指标运算,不可删除"
  412. // }
  413. // }
  414. //}
  415. resp := new(data_manage.ClassifyDeleteCheckResp)
  416. resp.DeleteStatus = deleteStatus
  417. resp.TipsMsg = tipsMsg
  418. resp.TableList = tableList
  419. br.Ret = 200
  420. br.Msg = "检测成功"
  421. br.Success = true
  422. br.Data = resp
  423. }
  424. // @Title 删除分类/指标
  425. // @Description 删除分类/指标接口
  426. // @Param request body data_manage.DeleteEdbClassifyReq true "type json string"
  427. // @Success 200 Ret=200 新增成功
  428. // @router /classify/delete [post]
  429. func (this *EdbClassifyController) DeleteEdbClassify() {
  430. br := new(models.BaseResponse).Init()
  431. defer func() {
  432. this.Data["json"] = br
  433. this.ServeJSON()
  434. }()
  435. sysUser := this.SysUser
  436. if sysUser == nil {
  437. br.Msg = "请登录"
  438. br.ErrMsg = "请登录,SysUser Is Empty"
  439. br.Ret = 408
  440. return
  441. }
  442. var req data_manage.DeleteEdbClassifyReq
  443. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  444. if err != nil {
  445. br.Msg = "参数解析异常!"
  446. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  447. return
  448. }
  449. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  450. br.Msg = "参数错误"
  451. br.IsSendEmail = false
  452. return
  453. }
  454. nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  455. if errMsg != `` {
  456. br.Msg = errMsg
  457. br.ErrMsg = errMsg
  458. if err != nil {
  459. br.ErrMsg = err.Error()
  460. } else {
  461. br.IsSendEmail = false
  462. }
  463. return
  464. }
  465. resp := data_manage.AddEdbInfoResp{}
  466. if nextItem != nil {
  467. resp = data_manage.AddEdbInfoResp{
  468. EdbInfoId: nextItem.EdbInfoId,
  469. UniqueCode: nextItem.UniqueCode,
  470. }
  471. }
  472. br.Ret = 200
  473. br.Msg = "删除成功"
  474. br.Success = true
  475. br.IsAddLog = true
  476. br.Data = resp
  477. }
  478. // EdbClassifyMove
  479. // @Title 分类移动接口
  480. // @Description 分类移动接口
  481. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  482. // @router /edb_classify/move [post]
  483. func (this *EdbClassifyController) EdbClassifyMove() {
  484. br := new(models.BaseResponse).Init()
  485. defer func() {
  486. this.Data["json"] = br
  487. this.ServeJSON()
  488. }()
  489. sysUser := this.SysUser
  490. if sysUser == nil {
  491. br.Msg = "请登录"
  492. br.ErrMsg = "请登录,SysUser Is Empty"
  493. br.Ret = 408
  494. return
  495. }
  496. var req data_manage.MoveEdbClassifyReq
  497. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  498. if err != nil {
  499. br.Msg = "参数解析异常!"
  500. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  501. return
  502. }
  503. if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
  504. br.Msg = "参数错误"
  505. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  506. return
  507. }
  508. err, errMsg := data.MoveEdbClassify(req, sysUser, 0)
  509. if errMsg != `` {
  510. br.Msg = errMsg
  511. br.ErrMsg = errMsg
  512. if err != nil {
  513. br.ErrMsg = err.Error()
  514. } else {
  515. br.IsSendEmail = false
  516. }
  517. return
  518. }
  519. ////判断分类是否存在
  520. //edbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  521. //if err != nil {
  522. // br.Msg = "移动失败"
  523. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  524. // return
  525. //}
  526. //updateCol := make([]string, 0)
  527. //
  528. ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  529. //if edbClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  530. // parentEdbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ParentClassifyId)
  531. // if err != nil {
  532. // br.Msg = "移动失败"
  533. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  534. // return
  535. // }
  536. // edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  537. // edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  538. // edbClassifyInfo.ModifyTime = time.Now()
  539. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  540. //}
  541. //
  542. ////如果有传入 上一个兄弟节点分类id
  543. //if req.PrevClassifyId > 0 {
  544. // prevClassify, err := data_manage.GetEdbClassifyById(req.PrevClassifyId)
  545. // if err != nil {
  546. // br.Msg = "移动失败"
  547. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  548. // return
  549. // }
  550. //
  551. // //如果是移动在两个兄弟节点之间
  552. // if req.NextClassifyId > 0 {
  553. // //下一个兄弟节点
  554. // nextClassify, err := data_manage.GetEdbClassifyById(req.NextClassifyId)
  555. // if err != nil {
  556. // br.Msg = "移动失败"
  557. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  558. // return
  559. // }
  560. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  561. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort {
  562. // //变更兄弟节点的排序
  563. // updateSortStr := `sort + 2`
  564. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
  565. // } else {
  566. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  567. // if nextClassify.Sort-prevClassify.Sort == 1 {
  568. // //变更兄弟节点的排序
  569. // updateSortStr := `sort + 1`
  570. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  571. // }
  572. // }
  573. // }
  574. //
  575. // edbClassifyInfo.Sort = prevClassify.Sort + 1
  576. // edbClassifyInfo.ModifyTime = time.Now()
  577. // updateCol = append(updateCol, "Sort", "ModifyTime")
  578. //} else {
  579. // firstClassify, err := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId)
  580. // if err != nil && err.Error() != utils.ErrNoRow() {
  581. // br.Msg = "移动失败"
  582. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  583. // return
  584. // }
  585. //
  586. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  587. // if firstClassify != nil && firstClassify.Sort == 0 {
  588. // updateSortStr := ` sort + 1 `
  589. // _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr)
  590. // }
  591. //
  592. // edbClassifyInfo.Sort = 0 //那就是排在第一位
  593. // edbClassifyInfo.ModifyTime = time.Now()
  594. // updateCol = append(updateCol, "Sort", "ModifyTime")
  595. //}
  596. //
  597. ////更新
  598. //if len(updateCol) > 0 {
  599. // err = edbClassifyInfo.Update(updateCol)
  600. // if err != nil {
  601. // br.Msg = "移动失败"
  602. // br.ErrMsg = "修改失败,Err:" + err.Error()
  603. // return
  604. // }
  605. //}
  606. br.Ret = 200
  607. br.Success = true
  608. br.Msg = "移动成功"
  609. }
  610. // ItemsV2
  611. // @Title 分类列表
  612. // @Description 分类列表接口
  613. // @Success 200 {object} data_manage.EdbClassifyListResp
  614. // @router /classify/items/v2 [get]
  615. func (this *EdbClassifyController) ItemsV2() {
  616. br := new(models.BaseResponse).Init()
  617. defer func() {
  618. this.Data["json"] = br
  619. this.ServeJSON()
  620. }()
  621. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  622. if err != nil && err.Error() != utils.ErrNoRow() {
  623. br.Msg = "获取失败"
  624. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  625. return
  626. }
  627. classifyAll, err := data_manage.GetEdbClassifyAll()
  628. if err != nil && err.Error() != utils.ErrNoRow() {
  629. br.Msg = "获取失败"
  630. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  631. return
  632. }
  633. // 已授权分类id
  634. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  635. if err != nil {
  636. br.Msg = "获取失败"
  637. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  638. return
  639. }
  640. //allEdbInfo, err := data_manage.GetEdbInfoAll(0)
  641. //if err != nil && err.Error() != utils.ErrNoRow() {
  642. // br.Msg = "获取失败"
  643. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  644. // return
  645. //}
  646. //edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  647. //for _, v := range allEdbInfo {
  648. // button := data.GetEdbOpButton(this.SysUser, v.SysUserId)
  649. // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  650. // v.Button = button
  651. // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  652. //}
  653. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  654. for _, v := range classifyAll {
  655. // 数据权限
  656. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  657. // 按钮权限
  658. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  659. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  660. v.Button = button
  661. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  662. //if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  663. // v.Children = existItems
  664. //} else {
  665. // items := make([]*data_manage.EdbClassifyItems, 0)
  666. // v.Children = items
  667. //}
  668. }
  669. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  670. for _, v := range rootList {
  671. // 数据权限
  672. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  673. // 按钮权限
  674. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  675. v.Button = button
  676. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  677. v.Children = existItems
  678. } else {
  679. items := make([]*data_manage.EdbClassifyItems, 0)
  680. v.Children = items
  681. }
  682. nodeAll = append(nodeAll, v)
  683. }
  684. language := `CN`
  685. // 指标显示的语言
  686. {
  687. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  688. if configDetail != nil {
  689. language = configDetail.ConfigValue
  690. } else {
  691. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  692. if configDetail != nil {
  693. language = configDetail.ConfigValue
  694. }
  695. }
  696. }
  697. // 是否允许添加一级分类
  698. canOpClassify := true
  699. //button := data.GetEdbClassifyOpButton(this.SysUser, 0)
  700. //if !button.AddButton {
  701. // canOpClassify = false
  702. //}
  703. resp := data_manage.EdbClassifyListResp{
  704. AllNodes: nodeAll,
  705. CanOpClassify: canOpClassify,
  706. Language: language,
  707. }
  708. br.Ret = 200
  709. br.Success = true
  710. br.Msg = "获取成功"
  711. br.Data = resp
  712. }
  713. // @Title 获取分类下指标接口
  714. // @Description 获取分类下指标接口
  715. // @Param ClassifyId query int true "分类id"
  716. // @Success 200 {object} data_manage.EdbClassifyListResp
  717. // @router /classify/edb_info/list [get]
  718. func (this *EdbClassifyController) ClassifyEdbInfoList() {
  719. br := new(models.BaseResponse).Init()
  720. defer func() {
  721. this.Data["json"] = br
  722. this.ServeJSON()
  723. }()
  724. classifyId, _ := this.GetInt("ClassifyId")
  725. if classifyId <= 0 {
  726. br.Msg = "参数错误,请刷新页面"
  727. return
  728. }
  729. classifyInfo, err := data_manage.GetEdbClassifyById(classifyId)
  730. if err != nil {
  731. br.Msg = "获取失败"
  732. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  733. return
  734. }
  735. // 获取当前账号的不可见指标
  736. obj := data_manage.EdbInfoNoPermissionAdmin{}
  737. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  738. if err != nil && err.Error() != utils.ErrNoRow() {
  739. br.Msg = "获取失败"
  740. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  741. return
  742. }
  743. noPermissionEdbInfoIdMap := make(map[int]bool)
  744. for _, v := range confList {
  745. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  746. }
  747. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(classifyId, 0, 0)
  748. if err != nil && err.Error() != utils.ErrNoRow() {
  749. br.Msg = "获取失败"
  750. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  751. return
  752. }
  753. list := make([]*data_manage.EdbClassifyItems, 0)
  754. if len(allEdbInfo) > 0 {
  755. // 获取所有有权限的指标和分类
  756. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  757. if err != nil {
  758. br.Msg = "获取失败"
  759. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  760. return
  761. }
  762. for _, v := range allEdbInfo {
  763. // 如果指标不可见,那么就不返回该指标
  764. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  765. continue
  766. }
  767. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  768. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  769. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  770. v.Button = button
  771. list = append(list, v)
  772. }
  773. }
  774. resp := new(data_manage.ClassifyEdbInfoListResp)
  775. resp.EdbInfoList = list
  776. br.Ret = 200
  777. br.Success = true
  778. br.Msg = "获取成功"
  779. br.Data = resp
  780. }
  781. // ItemsV3
  782. // @Title 分类列表
  783. // @Description 分类列表接口
  784. // @Success 200 {object} data_manage.EdbClassifyListResp
  785. // @router /classify/items/v3 [get]
  786. func (this *EdbClassifyController) ItemsV3() {
  787. br := new(models.BaseResponse).Init()
  788. defer func() {
  789. this.Data["json"] = br
  790. this.ServeJSON()
  791. }()
  792. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  793. if err != nil && err.Error() != utils.ErrNoRow() {
  794. br.Msg = "获取失败"
  795. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  796. return
  797. }
  798. rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(0)
  799. if err != nil && err.Error() != utils.ErrNoRow() {
  800. br.Msg = "获取失败"
  801. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  802. return
  803. }
  804. classifyAll, err := data_manage.GetEdbClassifyAllV2(0)
  805. if err != nil && err.Error() != utils.ErrNoRow() {
  806. br.Msg = "获取失败"
  807. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  808. return
  809. }
  810. // 已授权分类id
  811. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  812. if err != nil {
  813. br.Msg = "获取失败"
  814. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  815. return
  816. }
  817. rootTwoMap := make(map[int][]*data_manage.EdbClassifyItems)
  818. for _, v := range rootTwoList {
  819. // 数据权限
  820. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  821. // 按钮权限
  822. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  823. v.Button = button
  824. rootTwoMap[v.ParentId] = append(rootTwoMap[v.ParentId], v)
  825. }
  826. rootTwoChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  827. for _, v := range classifyAll {
  828. // 数据权限
  829. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  830. // 按钮权限
  831. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  832. v.Button = button
  833. if v.Level == 3 {
  834. rootTwoChildMap[v.ParentId] = append(rootTwoChildMap[v.ParentId], v)
  835. }
  836. }
  837. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  838. for _, v := range rootList {
  839. // 数据权限
  840. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  841. // 按钮权限
  842. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  843. v.Button = button
  844. if existItems, ok := rootTwoMap[v.ClassifyId]; ok {
  845. v.Children = existItems
  846. for _, item := range existItems {
  847. // 数据权限
  848. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  849. // 按钮权限
  850. button := data.GetEdbClassifyOpButton(this.SysUser, item.SysUserId, v.HaveOperaAuth)
  851. item.Button = button
  852. if existItems, ok := rootTwoChildMap[item.ClassifyId]; ok {
  853. for _, existItem := range existItems {
  854. // 数据权限
  855. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  856. // 按钮权限
  857. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  858. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  859. existItem.Button = button
  860. }
  861. item.Children = existItems
  862. } else {
  863. items := make([]*data_manage.EdbClassifyItems, 0)
  864. item.Children = items
  865. }
  866. }
  867. } else {
  868. items := make([]*data_manage.EdbClassifyItems, 0)
  869. v.Children = items
  870. }
  871. nodeAll = append(nodeAll, v)
  872. }
  873. language := `CN`
  874. // 指标显示的语言
  875. {
  876. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  877. if configDetail != nil {
  878. language = configDetail.ConfigValue
  879. } else {
  880. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  881. if configDetail != nil {
  882. language = configDetail.ConfigValue
  883. }
  884. }
  885. }
  886. // 是否允许添加一级分类
  887. canOpClassify := true
  888. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  889. if !button.AddButton {
  890. canOpClassify = false
  891. }
  892. resp := new(data_manage.EdbClassifyListResp)
  893. resp.AllNodes = nodeAll
  894. resp.Language = language
  895. resp.CanOpClassify = canOpClassify
  896. br.Ret = 200
  897. br.Success = true
  898. br.Msg = "获取成功"
  899. br.Data = resp
  900. }
  901. // SimpleList
  902. // @Title 单层分类列表
  903. // @Description 单层分类列表
  904. // @Success 200 {object} data_manage.EdbClassifyListResp
  905. // @router /classify/simple [get]
  906. func (this *EdbClassifyController) SimpleList() {
  907. br := new(models.BaseResponse).Init()
  908. defer func() {
  909. this.Data["json"] = br
  910. this.ServeJSON()
  911. }()
  912. // 默认查一级分类和一级分类下的指标信息,
  913. // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
  914. // 增加标识判断是文件夹还是指标列表
  915. parentId, _ := this.GetInt("ParentId")
  916. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  917. // 如果选择了只看我的,那么只查询归属于我的账号
  918. sysUserId := 0
  919. if isOnlyMe {
  920. sysUserId = this.SysUser.AdminId
  921. }
  922. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 0)
  923. if err != nil && err.Error() != utils.ErrNoRow() {
  924. br.Msg = "获取失败"
  925. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  926. return
  927. }
  928. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  929. var sortList data_manage.EdbClassifyItemList
  930. if parentId > 0 {
  931. // 查询挂在当前分类上的指标列表
  932. // 获取当前账号的不可见指标
  933. obj := data_manage.EdbInfoNoPermissionAdmin{}
  934. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  935. if err != nil && err.Error() != utils.ErrNoRow() {
  936. br.Msg = "获取失败"
  937. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  938. return
  939. }
  940. noPermissionEdbInfoIdMap := make(map[int]bool)
  941. for _, v := range confList {
  942. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  943. }
  944. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, 0, sysUserId)
  945. if err != nil {
  946. br.Msg = "获取指标数据失败"
  947. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  948. return
  949. }
  950. if len(allEdbInfo) > 0 {
  951. // 查询当前分类信息
  952. currClassify, err := data_manage.GetEdbClassifyById(parentId)
  953. if err != nil {
  954. br.Msg = "获取失败"
  955. br.ErrMsg = "获取当前分类信息失败,Err:" + err.Error()
  956. return
  957. }
  958. // 获取所有有权限的指标和分类
  959. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  960. if err != nil {
  961. br.Msg = "获取失败"
  962. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  963. return
  964. }
  965. for _, v := range allEdbInfo {
  966. // 如果指标不可见,那么就不返回该指标
  967. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  968. continue
  969. }
  970. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  971. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  972. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  973. v.Button = button
  974. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  975. v.ParentId = parentId
  976. nodeAll = append(nodeAll, v)
  977. }
  978. }
  979. }
  980. if len(rootList) > 0 {
  981. // 已授权分类id
  982. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  983. if err != nil {
  984. br.Msg = "获取失败"
  985. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  986. return
  987. }
  988. for _, v := range rootList {
  989. // 数据权限
  990. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  991. // 按钮权限
  992. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  993. v.Button = button
  994. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  995. nodeAll = append(nodeAll, v)
  996. }
  997. }
  998. if len(nodeAll) > 0 {
  999. //根据sort值排序
  1000. sortList = nodeAll
  1001. sort.Sort(sortList)
  1002. }
  1003. language := `CN`
  1004. // 指标显示的语言
  1005. {
  1006. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1007. if configDetail != nil {
  1008. language = configDetail.ConfigValue
  1009. } else {
  1010. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1011. if configDetail != nil {
  1012. language = configDetail.ConfigValue
  1013. }
  1014. }
  1015. }
  1016. // 是否允许添加一级分类
  1017. canOpClassify := true
  1018. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  1019. if !button.AddButton {
  1020. canOpClassify = false
  1021. }
  1022. resp := new(data_manage.EdbClassifyListResp)
  1023. resp.AllNodes = sortList
  1024. resp.Language = language
  1025. resp.CanOpClassify = canOpClassify
  1026. br.Ret = 200
  1027. br.Success = true
  1028. br.Msg = "获取成功"
  1029. br.Data = resp
  1030. }
  1031. // ClassifyTree
  1032. // @Title 多层分类列表树
  1033. // @Description 多层分类列表树
  1034. // @Success 200 {object} data_manage.EdbClassifyListResp
  1035. // @router /classify/tree [get]
  1036. func (this *EdbClassifyController) ClassifyTree() {
  1037. br := new(models.BaseResponse).Init()
  1038. defer func() {
  1039. this.Data["json"] = br
  1040. this.ServeJSON()
  1041. }()
  1042. allList, err := data_manage.GetNormalEdbClassifyAll()
  1043. if err != nil && err.Error() != utils.ErrNoRow() {
  1044. br.Msg = "获取失败"
  1045. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1046. return
  1047. }
  1048. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  1049. var sortList data_manage.EdbClassifyItemList
  1050. if len(allList) > 0 {
  1051. // 已授权分类id
  1052. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  1053. if err != nil {
  1054. br.Msg = "获取失败"
  1055. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1056. return
  1057. }
  1058. for k, v := range allList {
  1059. // 数据权限
  1060. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  1061. // 按钮权限
  1062. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  1063. allList[k].Button = button
  1064. }
  1065. nodeAll = data.GetClassifyTreeRecursive(allList, 0)
  1066. //根据sort值排序
  1067. sortList = nodeAll
  1068. sort.Sort(sortList)
  1069. }
  1070. language := `CN`
  1071. // 指标显示的语言
  1072. {
  1073. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1074. if configDetail != nil {
  1075. language = configDetail.ConfigValue
  1076. } else {
  1077. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1078. if configDetail != nil {
  1079. language = configDetail.ConfigValue
  1080. }
  1081. }
  1082. }
  1083. // 是否允许添加一级分类
  1084. canOpClassify := true
  1085. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  1086. if !button.AddButton {
  1087. canOpClassify = false
  1088. }
  1089. resp := new(data_manage.EdbClassifyListResp)
  1090. resp.AllNodes = sortList
  1091. resp.Language = language
  1092. resp.CanOpClassify = canOpClassify
  1093. br.Ret = 200
  1094. br.Success = true
  1095. br.Msg = "获取成功"
  1096. br.Data = resp
  1097. }
  1098. // EdbClassifyMoveV2
  1099. // @Title 分类移动接口v2
  1100. // @Description 分类移动接口v2
  1101. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  1102. // @router /edb_classify/move/v2 [post]
  1103. //func (this *EdbClassifyController) EdbClassifyMoveV2() {
  1104. // br := new(models.BaseResponse).Init()
  1105. // defer func() {
  1106. // this.Data["json"] = br
  1107. // this.ServeJSON()
  1108. // }()
  1109. //
  1110. // sysUser := this.SysUser
  1111. // if sysUser == nil {
  1112. // br.Msg = "请登录"
  1113. // br.ErrMsg = "请登录,SysUser Is Empty"
  1114. // br.Ret = 408
  1115. // return
  1116. // }
  1117. //
  1118. // var req data_manage.MoveEdbClassifyReq
  1119. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1120. // if err != nil {
  1121. // br.Msg = "参数解析异常!"
  1122. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1123. // return
  1124. // }
  1125. //
  1126. // if req.ClassifyId <= 0 {
  1127. // br.Msg = "参数错误"
  1128. // br.ErrMsg = "分类id小于等于0"
  1129. // return
  1130. // }
  1131. //
  1132. // err, errMsg := data.MoveEdbClassify(req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId)
  1133. // if errMsg != `` {
  1134. // br.Msg = errMsg
  1135. // br.ErrMsg = errMsg
  1136. // if err != nil {
  1137. // br.ErrMsg = err.Error()
  1138. // } else {
  1139. // br.IsSendEmail = false
  1140. // }
  1141. // return
  1142. // }
  1143. //
  1144. // br.Ret = 200
  1145. // br.Success = true
  1146. // br.Msg = "移动成功"
  1147. //}