edb_classify.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/controllers"
  5. "eta/eta_mobile/models"
  6. "eta/eta_mobile/models/data_manage"
  7. "eta/eta_mobile/models/system"
  8. "eta/eta_mobile/services/data"
  9. "eta/eta_mobile/services/data/data_manage_permission"
  10. "eta/eta_mobile/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, 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. //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 && err.Error() != utils.ErrNoRow() {
  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 && err.Error() != utils.ErrNoRow() {
  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 && err.Error() != utils.ErrNoRow() {
  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. br.Ret = 200
  414. br.Msg = "检测成功"
  415. br.Success = true
  416. br.Data = resp
  417. }
  418. // @Title 删除分类/指标
  419. // @Description 删除分类/指标接口
  420. // @Param request body data_manage.DeleteEdbClassifyReq true "type json string"
  421. // @Success 200 Ret=200 新增成功
  422. // @router /classify/delete [post]
  423. func (this *EdbClassifyController) DeleteEdbClassify() {
  424. br := new(models.BaseResponse).Init()
  425. defer func() {
  426. this.Data["json"] = br
  427. this.ServeJSON()
  428. }()
  429. sysUser := this.SysUser
  430. if sysUser == nil {
  431. br.Msg = "请登录"
  432. br.ErrMsg = "请登录,SysUser Is Empty"
  433. br.Ret = 408
  434. return
  435. }
  436. var req data_manage.DeleteEdbClassifyReq
  437. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  438. if err != nil {
  439. br.Msg = "参数解析异常!"
  440. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  441. return
  442. }
  443. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  444. br.Msg = "参数错误"
  445. br.IsSendEmail = false
  446. return
  447. }
  448. nextItem, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  449. if errMsg != `` {
  450. br.Msg = errMsg
  451. br.ErrMsg = errMsg
  452. if err != nil {
  453. br.ErrMsg = err.Error()
  454. } else {
  455. br.IsSendEmail = false
  456. }
  457. return
  458. }
  459. resp := data_manage.AddEdbInfoResp{}
  460. if nextItem != nil {
  461. resp = data_manage.AddEdbInfoResp{
  462. EdbInfoId: nextItem.EdbInfoId,
  463. UniqueCode: nextItem.UniqueCode,
  464. }
  465. }
  466. br.Ret = 200
  467. br.Msg = "删除成功"
  468. br.Success = true
  469. br.IsAddLog = true
  470. br.Data = resp
  471. }
  472. // EdbClassifyMove
  473. // @Title 分类移动接口
  474. // @Description 分类移动接口
  475. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  476. // @router /edb_classify/move [post]
  477. func (this *EdbClassifyController) EdbClassifyMove() {
  478. br := new(models.BaseResponse).Init()
  479. defer func() {
  480. this.Data["json"] = br
  481. this.ServeJSON()
  482. }()
  483. sysUser := this.SysUser
  484. if sysUser == nil {
  485. br.Msg = "请登录"
  486. br.ErrMsg = "请登录,SysUser Is Empty"
  487. br.Ret = 408
  488. return
  489. }
  490. var req data_manage.MoveEdbClassifyReq
  491. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  492. if err != nil {
  493. br.Msg = "参数解析异常!"
  494. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  495. return
  496. }
  497. if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
  498. br.Msg = "参数错误"
  499. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  500. return
  501. }
  502. err, errMsg := data.MoveEdbClassify(req, sysUser, 0)
  503. if errMsg != `` {
  504. br.Msg = errMsg
  505. br.ErrMsg = errMsg
  506. if err != nil {
  507. br.ErrMsg = err.Error()
  508. } else {
  509. br.IsSendEmail = false
  510. }
  511. return
  512. }
  513. ////判断分类是否存在
  514. //edbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  515. //if err != nil {
  516. // br.Msg = "移动失败"
  517. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  518. // return
  519. //}
  520. //updateCol := make([]string, 0)
  521. //
  522. ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  523. //if edbClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  524. // parentEdbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ParentClassifyId)
  525. // if err != nil {
  526. // br.Msg = "移动失败"
  527. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  528. // return
  529. // }
  530. // edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  531. // edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  532. // edbClassifyInfo.ModifyTime = time.Now()
  533. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  534. //}
  535. //
  536. ////如果有传入 上一个兄弟节点分类id
  537. //if req.PrevClassifyId > 0 {
  538. // prevClassify, err := data_manage.GetEdbClassifyById(req.PrevClassifyId)
  539. // if err != nil {
  540. // br.Msg = "移动失败"
  541. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  542. // return
  543. // }
  544. //
  545. // //如果是移动在两个兄弟节点之间
  546. // if req.NextClassifyId > 0 {
  547. // //下一个兄弟节点
  548. // nextClassify, err := data_manage.GetEdbClassifyById(req.NextClassifyId)
  549. // if err != nil {
  550. // br.Msg = "移动失败"
  551. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  552. // return
  553. // }
  554. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  555. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort {
  556. // //变更兄弟节点的排序
  557. // updateSortStr := `sort + 2`
  558. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
  559. // } else {
  560. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  561. // if nextClassify.Sort-prevClassify.Sort == 1 {
  562. // //变更兄弟节点的排序
  563. // updateSortStr := `sort + 1`
  564. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  565. // }
  566. // }
  567. // }
  568. //
  569. // edbClassifyInfo.Sort = prevClassify.Sort + 1
  570. // edbClassifyInfo.ModifyTime = time.Now()
  571. // updateCol = append(updateCol, "Sort", "ModifyTime")
  572. //} else {
  573. // firstClassify, err := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId)
  574. // if err != nil && err.Error() != utils.ErrNoRow() {
  575. // br.Msg = "移动失败"
  576. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  577. // return
  578. // }
  579. //
  580. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  581. // if firstClassify != nil && firstClassify.Sort == 0 {
  582. // updateSortStr := ` sort + 1 `
  583. // _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr)
  584. // }
  585. //
  586. // edbClassifyInfo.Sort = 0 //那就是排在第一位
  587. // edbClassifyInfo.ModifyTime = time.Now()
  588. // updateCol = append(updateCol, "Sort", "ModifyTime")
  589. //}
  590. //
  591. ////更新
  592. //if len(updateCol) > 0 {
  593. // err = edbClassifyInfo.Update(updateCol)
  594. // if err != nil {
  595. // br.Msg = "移动失败"
  596. // br.ErrMsg = "修改失败,Err:" + err.Error()
  597. // return
  598. // }
  599. //}
  600. br.Ret = 200
  601. br.Success = true
  602. br.Msg = "移动成功"
  603. }
  604. // ItemsV2
  605. // @Title 分类列表
  606. // @Description 分类列表接口
  607. // @Success 200 {object} data_manage.EdbClassifyListResp
  608. // @router /classify/items/v2 [get]
  609. func (this *EdbClassifyController) ItemsV2() {
  610. br := new(models.BaseResponse).Init()
  611. defer func() {
  612. this.Data["json"] = br
  613. this.ServeJSON()
  614. }()
  615. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  616. if err != nil && err.Error() != utils.ErrNoRow() {
  617. br.Msg = "获取失败"
  618. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  619. return
  620. }
  621. classifyAll, err := data_manage.GetEdbClassifyAll()
  622. if err != nil && err.Error() != utils.ErrNoRow() {
  623. br.Msg = "获取失败"
  624. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  625. return
  626. }
  627. // 已授权分类id
  628. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  629. if err != nil {
  630. br.Msg = "获取失败"
  631. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  632. return
  633. }
  634. //allEdbInfo, err := data_manage.GetEdbInfoAll(0)
  635. //if err != nil && err.Error() != utils.ErrNoRow() {
  636. // br.Msg = "获取失败"
  637. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  638. // return
  639. //}
  640. //edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  641. //for _, v := range allEdbInfo {
  642. // button := data.GetEdbOpButton(this.SysUser, v.SysUserId)
  643. // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  644. // v.Button = button
  645. // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  646. //}
  647. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  648. for _, v := range classifyAll {
  649. // 数据权限
  650. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  651. // 按钮权限
  652. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  653. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  654. v.Button = button
  655. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  656. //if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  657. // v.Children = existItems
  658. //} else {
  659. // items := make([]*data_manage.EdbClassifyItems, 0)
  660. // v.Children = items
  661. //}
  662. }
  663. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  664. for _, v := range rootList {
  665. // 数据权限
  666. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  667. // 按钮权限
  668. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  669. v.Button = button
  670. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  671. v.Children = existItems
  672. } else {
  673. items := make([]*data_manage.EdbClassifyItems, 0)
  674. v.Children = items
  675. }
  676. nodeAll = append(nodeAll, v)
  677. }
  678. language := `CN`
  679. // 指标显示的语言
  680. {
  681. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  682. if configDetail != nil {
  683. language = configDetail.ConfigValue
  684. } else {
  685. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  686. if configDetail != nil {
  687. language = configDetail.ConfigValue
  688. }
  689. }
  690. }
  691. // 是否允许添加一级分类
  692. canOpClassify := true
  693. //button := data.GetEdbClassifyOpButton(this.SysUser, 0)
  694. //if !button.AddButton {
  695. // canOpClassify = false
  696. //}
  697. resp := data_manage.EdbClassifyListResp{
  698. AllNodes: nodeAll,
  699. CanOpClassify: canOpClassify,
  700. Language: language,
  701. }
  702. br.Ret = 200
  703. br.Success = true
  704. br.Msg = "获取成功"
  705. br.Data = resp
  706. }
  707. // @Title 获取分类下指标接口
  708. // @Description 获取分类下指标接口
  709. // @Param ClassifyId query int true "分类id"
  710. // @Success 200 {object} data_manage.EdbClassifyListResp
  711. // @router /classify/edb_info/list [get]
  712. func (this *EdbClassifyController) ClassifyEdbInfoList() {
  713. br := new(models.BaseResponse).Init()
  714. defer func() {
  715. this.Data["json"] = br
  716. this.ServeJSON()
  717. }()
  718. classifyId, _ := this.GetInt("ClassifyId")
  719. if classifyId <= 0 {
  720. br.Msg = "参数错误,请刷新页面"
  721. return
  722. }
  723. classifyInfo, err := data_manage.GetEdbClassifyById(classifyId)
  724. if err != nil {
  725. br.Msg = "获取失败"
  726. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  727. return
  728. }
  729. // 获取当前账号的不可见指标
  730. obj := data_manage.EdbInfoNoPermissionAdmin{}
  731. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  732. if err != nil && err.Error() != utils.ErrNoRow() {
  733. br.Msg = "获取失败"
  734. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  735. return
  736. }
  737. noPermissionEdbInfoIdMap := make(map[int]bool)
  738. for _, v := range confList {
  739. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  740. }
  741. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(classifyId, 0, 0)
  742. if err != nil && err.Error() != utils.ErrNoRow() {
  743. br.Msg = "获取失败"
  744. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  745. return
  746. }
  747. list := make([]*data_manage.EdbClassifyItems, 0)
  748. if len(allEdbInfo) > 0 {
  749. // 获取所有有权限的指标和分类
  750. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  751. if err != nil {
  752. br.Msg = "获取失败"
  753. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  754. return
  755. }
  756. for _, v := range allEdbInfo {
  757. // 如果指标不可见,那么就不返回该指标
  758. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  759. continue
  760. }
  761. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  762. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  763. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  764. v.Button = button
  765. list = append(list, v)
  766. }
  767. }
  768. resp := new(data_manage.ClassifyEdbInfoListResp)
  769. resp.EdbInfoList = list
  770. br.Ret = 200
  771. br.Success = true
  772. br.Msg = "获取成功"
  773. br.Data = resp
  774. }
  775. // ItemsV3
  776. // @Title 分类列表
  777. // @Description 分类列表接口
  778. // @Success 200 {object} data_manage.EdbClassifyListResp
  779. // @router /classify/items/v3 [get]
  780. func (this *EdbClassifyController) ItemsV3() {
  781. br := new(models.BaseResponse).Init()
  782. defer func() {
  783. this.Data["json"] = br
  784. this.ServeJSON()
  785. }()
  786. rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
  787. if err != nil && err.Error() != utils.ErrNoRow() {
  788. br.Msg = "获取失败"
  789. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  790. return
  791. }
  792. rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(0)
  793. if err != nil && err.Error() != utils.ErrNoRow() {
  794. br.Msg = "获取失败"
  795. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  796. return
  797. }
  798. classifyAll, err := data_manage.GetEdbClassifyAllV2(0)
  799. if err != nil && err.Error() != utils.ErrNoRow() {
  800. br.Msg = "获取失败"
  801. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  802. return
  803. }
  804. // 已授权分类id
  805. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  806. if err != nil {
  807. br.Msg = "获取失败"
  808. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  809. return
  810. }
  811. rootTwoMap := make(map[int][]*data_manage.EdbClassifyItems)
  812. for _, v := range rootTwoList {
  813. // 数据权限
  814. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  815. // 按钮权限
  816. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  817. v.Button = button
  818. rootTwoMap[v.ParentId] = append(rootTwoMap[v.ParentId], v)
  819. }
  820. rootTwoChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  821. for _, v := range classifyAll {
  822. // 数据权限
  823. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  824. // 按钮权限
  825. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  826. v.Button = button
  827. if v.Level == 3 {
  828. rootTwoChildMap[v.ParentId] = append(rootTwoChildMap[v.ParentId], v)
  829. }
  830. }
  831. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  832. for _, v := range rootList {
  833. // 数据权限
  834. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  835. // 按钮权限
  836. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  837. v.Button = button
  838. if existItems, ok := rootTwoMap[v.ClassifyId]; ok {
  839. v.Children = existItems
  840. for _, item := range existItems {
  841. // 数据权限
  842. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  843. // 按钮权限
  844. button := data.GetEdbClassifyOpButton(this.SysUser, item.SysUserId, v.HaveOperaAuth)
  845. item.Button = button
  846. if existItems, ok := rootTwoChildMap[item.ClassifyId]; ok {
  847. for _, existItem := range existItems {
  848. // 数据权限
  849. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  850. // 按钮权限
  851. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  852. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  853. existItem.Button = button
  854. }
  855. item.Children = existItems
  856. } else {
  857. items := make([]*data_manage.EdbClassifyItems, 0)
  858. item.Children = items
  859. }
  860. }
  861. } else {
  862. items := make([]*data_manage.EdbClassifyItems, 0)
  863. v.Children = items
  864. }
  865. nodeAll = append(nodeAll, v)
  866. }
  867. language := `CN`
  868. // 指标显示的语言
  869. {
  870. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  871. if configDetail != nil {
  872. language = configDetail.ConfigValue
  873. } else {
  874. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  875. if configDetail != nil {
  876. language = configDetail.ConfigValue
  877. }
  878. }
  879. }
  880. // 是否允许添加一级分类
  881. canOpClassify := true
  882. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  883. if !button.AddButton {
  884. canOpClassify = false
  885. }
  886. resp := new(data_manage.EdbClassifyListResp)
  887. resp.AllNodes = nodeAll
  888. resp.Language = language
  889. resp.CanOpClassify = canOpClassify
  890. br.Ret = 200
  891. br.Success = true
  892. br.Msg = "获取成功"
  893. br.Data = resp
  894. }
  895. // SimpleList
  896. // @Title 单层分类列表
  897. // @Description 单层分类列表
  898. // @Success 200 {object} data_manage.EdbClassifyListResp
  899. // @router /classify/simple [get]
  900. func (this *EdbClassifyController) SimpleList() {
  901. br := new(models.BaseResponse).Init()
  902. defer func() {
  903. this.Data["json"] = br
  904. this.ServeJSON()
  905. }()
  906. // 默认查一级分类和一级分类下的指标信息,
  907. // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
  908. // 增加标识判断是文件夹还是指标列表
  909. parentId, _ := this.GetInt("ParentId")
  910. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  911. // 如果选择了只看我的,那么只查询归属于我的账号
  912. sysUserId := 0
  913. if isOnlyMe {
  914. sysUserId = this.SysUser.AdminId
  915. }
  916. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 0)
  917. if err != nil && err.Error() != utils.ErrNoRow() {
  918. br.Msg = "获取失败"
  919. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  920. return
  921. }
  922. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  923. var sortList data_manage.EdbClassifyItemList
  924. if parentId > 0 {
  925. // 查询挂在当前分类上的指标列表
  926. // 获取当前账号的不可见指标
  927. obj := data_manage.EdbInfoNoPermissionAdmin{}
  928. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  929. if err != nil && err.Error() != utils.ErrNoRow() {
  930. br.Msg = "获取失败"
  931. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  932. return
  933. }
  934. noPermissionEdbInfoIdMap := make(map[int]bool)
  935. for _, v := range confList {
  936. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  937. }
  938. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, 0, sysUserId)
  939. if err != nil {
  940. br.Msg = "获取指标数据失败"
  941. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  942. return
  943. }
  944. if len(allEdbInfo) > 0 {
  945. // 查询当前分类信息
  946. currClassify, err := data_manage.GetEdbClassifyById(parentId)
  947. if err != nil {
  948. br.Msg = "获取失败"
  949. br.ErrMsg = "获取当前分类信息失败,Err:" + err.Error()
  950. return
  951. }
  952. // 获取所有有权限的指标和分类
  953. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  954. if err != nil {
  955. br.Msg = "获取失败"
  956. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  957. return
  958. }
  959. for _, v := range allEdbInfo {
  960. // 如果指标不可见,那么就不返回该指标
  961. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  962. continue
  963. }
  964. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  965. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  966. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  967. v.Button = button
  968. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  969. v.ParentId = parentId
  970. nodeAll = append(nodeAll, v)
  971. }
  972. }
  973. }
  974. if len(rootList) > 0 {
  975. // 已授权分类id
  976. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  977. if err != nil {
  978. br.Msg = "获取失败"
  979. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  980. return
  981. }
  982. for _, v := range rootList {
  983. // 数据权限
  984. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  985. // 按钮权限
  986. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  987. v.Button = button
  988. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  989. nodeAll = append(nodeAll, v)
  990. }
  991. }
  992. if len(nodeAll) > 0 {
  993. //根据sort值排序
  994. sortList = nodeAll
  995. sort.Sort(sortList)
  996. }
  997. language := `CN`
  998. // 指标显示的语言
  999. {
  1000. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1001. if configDetail != nil {
  1002. language = configDetail.ConfigValue
  1003. } else {
  1004. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1005. if configDetail != nil {
  1006. language = configDetail.ConfigValue
  1007. }
  1008. }
  1009. }
  1010. // 是否允许添加一级分类
  1011. canOpClassify := true
  1012. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  1013. if !button.AddButton {
  1014. canOpClassify = false
  1015. }
  1016. resp := new(data_manage.EdbClassifyListResp)
  1017. resp.AllNodes = sortList
  1018. resp.Language = language
  1019. resp.CanOpClassify = canOpClassify
  1020. br.Ret = 200
  1021. br.Success = true
  1022. br.Msg = "获取成功"
  1023. br.Data = resp
  1024. }
  1025. // ClassifyTree
  1026. // @Title 多层分类列表树
  1027. // @Description 多层分类列表树
  1028. // @Success 200 {object} data_manage.EdbClassifyListResp
  1029. // @router /classify/tree [get]
  1030. func (this *EdbClassifyController) ClassifyTree() {
  1031. br := new(models.BaseResponse).Init()
  1032. defer func() {
  1033. this.Data["json"] = br
  1034. this.ServeJSON()
  1035. }()
  1036. allList, err := data_manage.GetNormalEdbClassifyAll()
  1037. if err != nil && err.Error() != utils.ErrNoRow() {
  1038. br.Msg = "获取失败"
  1039. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1040. return
  1041. }
  1042. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  1043. var sortList data_manage.EdbClassifyItemList
  1044. if len(allList) > 0 {
  1045. // 已授权分类id
  1046. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  1047. if err != nil {
  1048. br.Msg = "获取失败"
  1049. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1050. return
  1051. }
  1052. for k, v := range allList {
  1053. // 数据权限
  1054. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  1055. // 按钮权限
  1056. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  1057. allList[k].Button = button
  1058. }
  1059. nodeAll = data.GetClassifyTreeRecursive(allList, 0)
  1060. //根据sort值排序
  1061. sortList = nodeAll
  1062. sort.Sort(sortList)
  1063. }
  1064. language := `CN`
  1065. // 指标显示的语言
  1066. {
  1067. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1068. if configDetail != nil {
  1069. language = configDetail.ConfigValue
  1070. } else {
  1071. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1072. if configDetail != nil {
  1073. language = configDetail.ConfigValue
  1074. }
  1075. }
  1076. }
  1077. // 是否允许添加一级分类
  1078. canOpClassify := true
  1079. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  1080. if !button.AddButton {
  1081. canOpClassify = false
  1082. }
  1083. resp := new(data_manage.EdbClassifyListResp)
  1084. resp.AllNodes = sortList
  1085. resp.Language = language
  1086. resp.CanOpClassify = canOpClassify
  1087. br.Ret = 200
  1088. br.Success = true
  1089. br.Msg = "获取成功"
  1090. br.Data = resp
  1091. }
  1092. // EdbClassifyMoveV2
  1093. // @Title 分类移动接口v2
  1094. // @Description 分类移动接口v2
  1095. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  1096. // @router /edb_classify/move/v2 [post]
  1097. //func (this *EdbClassifyController) EdbClassifyMoveV2() {
  1098. // br := new(models.BaseResponse).Init()
  1099. // defer func() {
  1100. // this.Data["json"] = br
  1101. // this.ServeJSON()
  1102. // }()
  1103. //
  1104. // sysUser := this.SysUser
  1105. // if sysUser == nil {
  1106. // br.Msg = "请登录"
  1107. // br.ErrMsg = "请登录,SysUser Is Empty"
  1108. // br.Ret = 408
  1109. // return
  1110. // }
  1111. //
  1112. // var req data_manage.MoveEdbClassifyReq
  1113. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1114. // if err != nil {
  1115. // br.Msg = "参数解析异常!"
  1116. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1117. // return
  1118. // }
  1119. //
  1120. // if req.ClassifyId <= 0 {
  1121. // br.Msg = "参数错误"
  1122. // br.ErrMsg = "分类id小于等于0"
  1123. // return
  1124. // }
  1125. //
  1126. // err, errMsg := data.MoveEdbClassify(req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId)
  1127. // if errMsg != `` {
  1128. // br.Msg = errMsg
  1129. // br.ErrMsg = errMsg
  1130. // if err != nil {
  1131. // br.ErrMsg = err.Error()
  1132. // } else {
  1133. // br.IsSendEmail = false
  1134. // }
  1135. // return
  1136. // }
  1137. //
  1138. // br.Ret = 200
  1139. // br.Success = true
  1140. // br.Msg = "移动成功"
  1141. //}