edb_classify.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  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. if isOnlyMe {
  1004. sortList, err = data.GetEdbClassifyByIsMe(sysUserId, parentId, 0, sortList)
  1005. if err != nil {
  1006. br.Msg = "获取失败"
  1007. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1008. return
  1009. }
  1010. }
  1011. language := `CN`
  1012. // 指标显示的语言
  1013. {
  1014. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1015. if configDetail != nil {
  1016. language = configDetail.ConfigValue
  1017. } else {
  1018. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1019. if configDetail != nil {
  1020. language = configDetail.ConfigValue
  1021. }
  1022. }
  1023. }
  1024. // 是否允许添加一级分类
  1025. canOpClassify := true
  1026. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  1027. if !button.AddButton {
  1028. canOpClassify = false
  1029. }
  1030. resp := new(data_manage.EdbClassifyListResp)
  1031. resp.AllNodes = sortList
  1032. resp.Language = language
  1033. resp.CanOpClassify = canOpClassify
  1034. br.Ret = 200
  1035. br.Success = true
  1036. br.Msg = "获取成功"
  1037. br.Data = resp
  1038. }
  1039. // ClassifyTree
  1040. // @Title 多层分类列表树
  1041. // @Description 多层分类列表树
  1042. // @Success 200 {object} data_manage.EdbClassifyListResp
  1043. // @router /classify/tree [get]
  1044. func (this *EdbClassifyController) ClassifyTree() {
  1045. br := new(models.BaseResponse).Init()
  1046. defer func() {
  1047. this.Data["json"] = br
  1048. this.ServeJSON()
  1049. }()
  1050. allList, err := data_manage.GetNormalEdbClassifyAll()
  1051. if err != nil && err.Error() != utils.ErrNoRow() {
  1052. br.Msg = "获取失败"
  1053. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1054. return
  1055. }
  1056. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  1057. var sortList data_manage.EdbClassifyItemList
  1058. if len(allList) > 0 {
  1059. // 已授权分类id
  1060. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  1061. if err != nil {
  1062. br.Msg = "获取失败"
  1063. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1064. return
  1065. }
  1066. for k, v := range allList {
  1067. // 数据权限
  1068. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  1069. // 按钮权限
  1070. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  1071. allList[k].Button = button
  1072. }
  1073. nodeAll = data.GetClassifyTreeRecursive(allList, 0)
  1074. //根据sort值排序
  1075. sortList = nodeAll
  1076. sort.Sort(sortList)
  1077. }
  1078. language := `CN`
  1079. // 指标显示的语言
  1080. {
  1081. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  1082. if configDetail != nil {
  1083. language = configDetail.ConfigValue
  1084. } else {
  1085. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  1086. if configDetail != nil {
  1087. language = configDetail.ConfigValue
  1088. }
  1089. }
  1090. }
  1091. // 是否允许添加一级分类
  1092. canOpClassify := true
  1093. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  1094. if !button.AddButton {
  1095. canOpClassify = false
  1096. }
  1097. resp := new(data_manage.EdbClassifyListResp)
  1098. resp.AllNodes = sortList
  1099. resp.Language = language
  1100. resp.CanOpClassify = canOpClassify
  1101. br.Ret = 200
  1102. br.Success = true
  1103. br.Msg = "获取成功"
  1104. br.Data = resp
  1105. }
  1106. // EdbClassifyMoveV2
  1107. // @Title 分类移动接口v2
  1108. // @Description 分类移动接口v2
  1109. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  1110. // @router /edb_classify/move/v2 [post]
  1111. //func (this *EdbClassifyController) EdbClassifyMoveV2() {
  1112. // br := new(models.BaseResponse).Init()
  1113. // defer func() {
  1114. // this.Data["json"] = br
  1115. // this.ServeJSON()
  1116. // }()
  1117. //
  1118. // sysUser := this.SysUser
  1119. // if sysUser == nil {
  1120. // br.Msg = "请登录"
  1121. // br.ErrMsg = "请登录,SysUser Is Empty"
  1122. // br.Ret = 408
  1123. // return
  1124. // }
  1125. //
  1126. // var req data_manage.MoveEdbClassifyReq
  1127. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1128. // if err != nil {
  1129. // br.Msg = "参数解析异常!"
  1130. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1131. // return
  1132. // }
  1133. //
  1134. // if req.ClassifyId <= 0 {
  1135. // br.Msg = "参数错误"
  1136. // br.ErrMsg = "分类id小于等于0"
  1137. // return
  1138. // }
  1139. //
  1140. // err, errMsg := data.MoveEdbClassify(req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId)
  1141. // if errMsg != `` {
  1142. // br.Msg = errMsg
  1143. // br.ErrMsg = errMsg
  1144. // if err != nil {
  1145. // br.ErrMsg = err.Error()
  1146. // } else {
  1147. // br.IsSendEmail = false
  1148. // }
  1149. // return
  1150. // }
  1151. //
  1152. // br.Ret = 200
  1153. // br.Success = true
  1154. // br.Msg = "移动成功"
  1155. //}