edb_classify.go 43 KB

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