edb_classify.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/system"
  8. "eta_gn/eta_api/services/data"
  9. "eta_gn/eta_api/services/data/data_manage_permission"
  10. "eta_gn/eta_api/utils"
  11. "fmt"
  12. "sort"
  13. )
  14. type EdbClassifyController struct {
  15. controllers.BaseAuthController
  16. }
  17. // @router /classify/list [get]
  18. func (this *EdbClassifyController) ListV2() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  25. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  26. br.Msg = "参数有误"
  27. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  28. return
  29. }
  30. edbType := utils.EdbTypeBase
  31. if classifyType == utils.EdbClassifyTypeCalculate {
  32. edbType = utils.EdbTypeCalculate
  33. }
  34. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType))
  35. if err != nil && !utils.IsErrNoRow(err) {
  36. br.Msg = "获取失败"
  37. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  38. return
  39. }
  40. classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType)
  41. if err != nil && !utils.IsErrNoRow(err) {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  44. return
  45. }
  46. classifyMap := make(map[int]*data_manage.EdbClassifyItems)
  47. for _, v := range classifyAll {
  48. classifyMap[v.ClassifyId] = v
  49. }
  50. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  51. if err != nil {
  52. br.Msg = "获取失败"
  53. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  54. return
  55. }
  56. obj := data_manage.EdbInfoNoPermissionAdmin{}
  57. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  58. if err != nil && !utils.IsErrNoRow(err) {
  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.GetEdbInfoByTypes(utils.EDB_INFO_TYPE, edbType)
  68. if err != nil && !utils.IsErrNoRow(err) {
  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. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  76. if err != nil {
  77. br.Msg = "获取失败"
  78. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  79. return
  80. }
  81. for _, v := range allEdbInfo {
  82. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  83. continue
  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. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  97. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  98. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  99. v.Button = button
  100. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  101. if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  102. v.Children = existItems
  103. } else {
  104. items := make([]*data_manage.EdbClassifyItems, 0)
  105. v.Children = items
  106. }
  107. }
  108. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  109. for _, v := range rootList {
  110. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  111. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  112. v.Button = button
  113. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  114. v.Children = existItems
  115. } else {
  116. items := make([]*data_manage.EdbClassifyItems, 0)
  117. v.Children = items
  118. }
  119. nodeAll = append(nodeAll, v)
  120. }
  121. resp := new(data_manage.EdbClassifyListResp)
  122. resp.AllNodes = nodeAll
  123. resp.CanOpClassify = true
  124. br.Ret = 200
  125. br.Success = true
  126. br.Msg = "获取成功"
  127. br.Data = resp
  128. }
  129. // @router /classify/items [get]
  130. func (this *EdbClassifyController) Items() {
  131. br := new(models.BaseResponse).Init()
  132. defer func() {
  133. this.Data["json"] = br
  134. this.ServeJSON()
  135. }()
  136. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  137. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  138. br.Msg = "参数有误"
  139. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  140. return
  141. }
  142. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType))
  143. if err != nil {
  144. br.Msg = "获取失败"
  145. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  146. return
  147. }
  148. classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType)
  149. if err != nil {
  150. br.Msg = "获取失败"
  151. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  152. return
  153. }
  154. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  155. for k := range rootList {
  156. rootNode := rootList[k]
  157. data.EdbClassifyItemsMakeTree(classifyAll, rootNode)
  158. nodeAll = append(nodeAll, rootNode)
  159. }
  160. resp := new(data_manage.EdbClassifyListResp)
  161. resp.AllNodes = nodeAll
  162. br.Ret = 200
  163. br.Success = true
  164. br.Msg = "获取成功"
  165. br.Data = resp
  166. }
  167. // @router /classify/add [post]
  168. func (this *EdbClassifyController) AddEdbClassify() {
  169. br := new(models.BaseResponse).Init()
  170. defer func() {
  171. this.Data["json"] = br
  172. this.ServeJSON()
  173. }()
  174. var req data_manage.AddEdbClassifyReq
  175. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  176. if err != nil {
  177. br.Msg = "参数解析异常!"
  178. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  179. return
  180. }
  181. if req.ClassifyName == "" {
  182. br.Msg = "请输入分类名称"
  183. br.IsSendEmail = false
  184. return
  185. }
  186. if req.ParentId < 0 {
  187. br.Msg = "参数错误"
  188. br.IsSendEmail = false
  189. return
  190. }
  191. classifyType := req.ClassifyType
  192. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  193. br.Msg = "参数有误"
  194. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  195. return
  196. }
  197. _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, classifyType, 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. br.Ret = 200
  209. br.Msg = "保存成功"
  210. br.Success = true
  211. br.IsAddLog = true
  212. }
  213. // @router /classify/edit [post]
  214. func (this *EdbClassifyController) EditEdbClassify() {
  215. br := new(models.BaseResponse).Init()
  216. defer func() {
  217. this.Data["json"] = br
  218. this.ServeJSON()
  219. }()
  220. var req data_manage.EditEdbClassifyReq
  221. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  222. if err != nil {
  223. br.Msg = "参数解析异常!"
  224. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  225. return
  226. }
  227. if req.ClassifyName == "" {
  228. br.Msg = "请输入分类名称"
  229. br.IsSendEmail = false
  230. return
  231. }
  232. if req.ClassifyId < 0 {
  233. br.Msg = "参数错误"
  234. br.IsSendEmail = false
  235. return
  236. }
  237. err, errMsg := data.EditEdbClassify(req.ClassifyId, req.ClassifyName, this.Lang, this.SysUser)
  238. if errMsg != `` {
  239. br.Msg = errMsg
  240. br.ErrMsg = errMsg
  241. if err != nil {
  242. br.ErrMsg = errMsg + ";Err:" + err.Error()
  243. } else {
  244. br.IsSendEmail = false
  245. }
  246. return
  247. }
  248. br.Ret = 200
  249. br.Msg = "保存成功"
  250. br.Success = true
  251. br.IsAddLog = true
  252. }
  253. // @router /classify/delete/check [post]
  254. func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
  255. br := new(models.BaseResponse).Init()
  256. defer func() {
  257. this.Data["json"] = br
  258. this.ServeJSON()
  259. }()
  260. var req data_manage.ClassifyDeleteCheckReq
  261. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  262. if err != nil {
  263. br.Msg = "参数解析异常!"
  264. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  265. return
  266. }
  267. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  268. br.Msg = "参数错误"
  269. br.IsSendEmail = false
  270. return
  271. }
  272. deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
  273. if errMsg != `` {
  274. br.Msg = errMsg
  275. br.ErrMsg = errMsg
  276. if err != nil {
  277. br.ErrMsg = err.Error()
  278. } else {
  279. br.IsSendEmail = false
  280. }
  281. return
  282. }
  283. if this.Lang == "en" {
  284. if utils.ViperConfig.InConfig(tipsMsg) {
  285. tipsMsg = utils.ViperConfig.GetString(tipsMsg)
  286. }
  287. }
  288. resp := new(data_manage.ClassifyDeleteCheckResp)
  289. resp.DeleteStatus = deleteStatus
  290. resp.TipsMsg = tipsMsg
  291. resp.TableList = tableList
  292. br.Ret = 200
  293. br.Msg = "检测成功"
  294. br.Success = true
  295. br.Data = resp
  296. }
  297. // @router /classify/delete [post]
  298. func (this *EdbClassifyController) DeleteEdbClassify() {
  299. br := new(models.BaseResponse).Init()
  300. defer func() {
  301. this.Data["json"] = br
  302. this.ServeJSON()
  303. }()
  304. sysUser := this.SysUser
  305. if sysUser == nil {
  306. br.Msg = "请登录"
  307. br.ErrMsg = "请登录,SysUser Is Empty"
  308. br.Ret = 408
  309. return
  310. }
  311. var req data_manage.DeleteEdbClassifyReq
  312. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  313. if err != nil {
  314. br.Msg = "参数解析异常!"
  315. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  316. return
  317. }
  318. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  319. br.Msg = "参数错误"
  320. br.IsSendEmail = false
  321. return
  322. }
  323. nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  324. if errMsg != `` {
  325. br.Msg = errMsg
  326. br.ErrMsg = errMsg
  327. if err != nil {
  328. br.ErrMsg = err.Error()
  329. } else {
  330. br.IsSendEmail = false
  331. }
  332. return
  333. }
  334. resp := data_manage.AddEdbInfoResp{}
  335. if nextItem != nil {
  336. resp = data_manage.AddEdbInfoResp{
  337. EdbInfoId: nextItem.EdbInfoId,
  338. UniqueCode: nextItem.UniqueCode,
  339. }
  340. }
  341. br.Ret = 200
  342. br.Msg = "删除成功"
  343. br.Success = true
  344. br.IsAddLog = true
  345. br.Data = resp
  346. }
  347. // @router /edb_classify/move [post]
  348. func (this *EdbClassifyController) EdbClassifyMove() {
  349. br := new(models.BaseResponse).Init()
  350. defer func() {
  351. this.Data["json"] = br
  352. this.ServeJSON()
  353. }()
  354. sysUser := this.SysUser
  355. if sysUser == nil {
  356. br.Msg = "请登录"
  357. br.ErrMsg = "请登录,SysUser Is Empty"
  358. br.Ret = 408
  359. return
  360. }
  361. var req data_manage.MoveEdbClassifyReq
  362. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  363. if err != nil {
  364. br.Msg = "参数解析异常!"
  365. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  366. return
  367. }
  368. if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
  369. br.Msg = "参数错误"
  370. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  371. return
  372. }
  373. classifyType := req.ClassifyType // 默认指标库的
  374. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  375. br.Msg = "参数有误"
  376. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  377. return
  378. }
  379. err, errMsg := data.MoveEdbClassify(req, sysUser, uint8(classifyType))
  380. if errMsg != `` {
  381. br.Msg = errMsg
  382. br.ErrMsg = errMsg
  383. if err != nil {
  384. br.ErrMsg = err.Error()
  385. } else {
  386. br.IsSendEmail = false
  387. }
  388. return
  389. }
  390. br.Ret = 200
  391. br.Success = true
  392. br.Msg = "移动成功"
  393. }
  394. // @router /classify/items/v2 [get]
  395. func (this *EdbClassifyController) ItemsV2() {
  396. br := new(models.BaseResponse).Init()
  397. defer func() {
  398. this.Data["json"] = br
  399. this.ServeJSON()
  400. }()
  401. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  402. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  403. br.Msg = "参数有误"
  404. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  405. return
  406. }
  407. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType))
  408. if err != nil && !utils.IsErrNoRow(err) {
  409. br.Msg = "获取失败"
  410. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  411. return
  412. }
  413. classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType)
  414. if err != nil && !utils.IsErrNoRow(err) {
  415. br.Msg = "获取失败"
  416. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  417. return
  418. }
  419. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  420. if err != nil {
  421. br.Msg = "获取失败"
  422. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  423. return
  424. }
  425. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  426. for _, v := range classifyAll {
  427. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  428. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  429. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  430. v.Button = button
  431. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  432. }
  433. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  434. for _, v := range rootList {
  435. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  436. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  437. v.Button = button
  438. if existItems, ok := rootChildMap[v.ClassifyId]; ok {
  439. v.Children = existItems
  440. } else {
  441. items := make([]*data_manage.EdbClassifyItems, 0)
  442. v.Children = items
  443. }
  444. nodeAll = append(nodeAll, v)
  445. }
  446. language := `CN`
  447. {
  448. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  449. if configDetail != nil {
  450. language = configDetail.ConfigValue
  451. } else {
  452. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  453. if configDetail != nil {
  454. language = configDetail.ConfigValue
  455. }
  456. }
  457. }
  458. canOpClassify := true
  459. resp := data_manage.EdbClassifyListResp{
  460. AllNodes: nodeAll,
  461. CanOpClassify: canOpClassify,
  462. Language: language,
  463. }
  464. br.Ret = 200
  465. br.Success = true
  466. br.Msg = "获取成功"
  467. br.Data = resp
  468. }
  469. // @router /classify/edb_info/list [get]
  470. func (this *EdbClassifyController) ClassifyEdbInfoList() {
  471. br := new(models.BaseResponse).Init()
  472. defer func() {
  473. this.Data["json"] = br
  474. this.ServeJSON()
  475. }()
  476. classifyId, _ := this.GetInt("ClassifyId")
  477. if classifyId <= 0 {
  478. br.Msg = "参数错误,请刷新页面"
  479. return
  480. }
  481. classifyInfo, err := data_manage.GetEdbClassifyById(classifyId)
  482. if err != nil {
  483. br.Msg = "获取失败"
  484. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  485. return
  486. }
  487. obj := data_manage.EdbInfoNoPermissionAdmin{}
  488. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  489. if err != nil && !utils.IsErrNoRow(err) {
  490. br.Msg = "获取失败"
  491. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  492. return
  493. }
  494. noPermissionEdbInfoIdMap := make(map[int]bool)
  495. for _, v := range confList {
  496. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  497. }
  498. edbType := 0
  499. switch classifyInfo.ClassifyType {
  500. case utils.EdbClassifyTypeBase:
  501. edbType = 1
  502. case utils.EdbClassifyTypeCalculate:
  503. edbType = 2
  504. }
  505. noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.EDB_INFO_TYPE, edbType)
  506. if err != nil {
  507. br.Msg = "获取失败"
  508. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  509. return
  510. }
  511. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(classifyId, utils.EDB_INFO_TYPE, edbType, 0, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList)
  512. if err != nil && !utils.IsErrNoRow(err) {
  513. br.Msg = "获取失败"
  514. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  515. return
  516. }
  517. list := make([]*data_manage.EdbClassifyItems, 0)
  518. if len(allEdbInfo) > 0 {
  519. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  520. if err != nil {
  521. br.Msg = "获取失败"
  522. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  523. return
  524. }
  525. for _, v := range allEdbInfo {
  526. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  527. continue
  528. }
  529. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  530. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  531. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  532. v.Button = button
  533. list = append(list, v)
  534. }
  535. }
  536. resp := new(data_manage.ClassifyEdbInfoListResp)
  537. resp.EdbInfoList = list
  538. br.Ret = 200
  539. br.Success = true
  540. br.Msg = "获取成功"
  541. br.Data = resp
  542. }
  543. // @router /classify/items/v3 [get]
  544. func (this *EdbClassifyController) ItemsV3() {
  545. br := new(models.BaseResponse).Init()
  546. defer func() {
  547. this.Data["json"] = br
  548. this.ServeJSON()
  549. }()
  550. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  551. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  552. br.Msg = "参数有误"
  553. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  554. return
  555. }
  556. rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType))
  557. if err != nil && !utils.IsErrNoRow(err) {
  558. br.Msg = "获取失败"
  559. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  560. return
  561. }
  562. rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(int8(classifyType))
  563. if err != nil && !utils.IsErrNoRow(err) {
  564. br.Msg = "获取失败"
  565. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  566. return
  567. }
  568. classifyAll, err := data_manage.GetEdbClassifyAllV2(int8(classifyType))
  569. if err != nil && !utils.IsErrNoRow(err) {
  570. br.Msg = "获取失败"
  571. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  572. return
  573. }
  574. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  575. if err != nil {
  576. br.Msg = "获取失败"
  577. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  578. return
  579. }
  580. rootTwoMap := make(map[int][]*data_manage.EdbClassifyItems)
  581. for _, v := range rootTwoList {
  582. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  583. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  584. v.Button = button
  585. rootTwoMap[v.ParentId] = append(rootTwoMap[v.ParentId], v)
  586. }
  587. rootTwoChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  588. for _, v := range classifyAll {
  589. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  590. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  591. v.Button = button
  592. if v.Level == 3 {
  593. rootTwoChildMap[v.ParentId] = append(rootTwoChildMap[v.ParentId], v)
  594. }
  595. }
  596. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  597. for _, v := range rootList {
  598. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  599. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  600. v.Button = button
  601. if existItems, ok := rootTwoMap[v.ClassifyId]; ok {
  602. v.Children = existItems
  603. for _, item := range existItems {
  604. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  605. button := data.GetEdbClassifyOpButton(this.SysUser, item.SysUserId, v.HaveOperaAuth)
  606. item.Button = button
  607. if existItems, ok := rootTwoChildMap[item.ClassifyId]; ok {
  608. for _, existItem := range existItems {
  609. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  610. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  611. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  612. existItem.Button = button
  613. }
  614. item.Children = existItems
  615. } else {
  616. items := make([]*data_manage.EdbClassifyItems, 0)
  617. item.Children = items
  618. }
  619. }
  620. } else {
  621. items := make([]*data_manage.EdbClassifyItems, 0)
  622. v.Children = items
  623. }
  624. nodeAll = append(nodeAll, v)
  625. }
  626. language := `CN`
  627. {
  628. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  629. if configDetail != nil {
  630. language = configDetail.ConfigValue
  631. } else {
  632. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  633. if configDetail != nil {
  634. language = configDetail.ConfigValue
  635. }
  636. }
  637. }
  638. canOpClassify := true
  639. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  640. if !button.AddButton {
  641. canOpClassify = false
  642. }
  643. resp := new(data_manage.EdbClassifyListResp)
  644. resp.AllNodes = nodeAll
  645. resp.Language = language
  646. resp.CanOpClassify = canOpClassify
  647. br.Ret = 200
  648. br.Success = true
  649. br.Msg = "获取成功"
  650. br.Data = resp
  651. }
  652. // @router /classify/simple [get]
  653. func (this *EdbClassifyController) SimpleList() {
  654. br := new(models.BaseResponse).Init()
  655. defer func() {
  656. this.Data["json"] = br
  657. this.ServeJSON()
  658. }()
  659. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  660. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
  661. br.Msg = "参数有误"
  662. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  663. return
  664. }
  665. parentId, _ := this.GetInt("ParentId")
  666. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  667. sysUserId := 0
  668. if isOnlyMe {
  669. sysUserId = this.SysUser.AdminId
  670. }
  671. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, int8(classifyType))
  672. if err != nil && !utils.IsErrNoRow(err) {
  673. br.Msg = "获取失败"
  674. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  675. return
  676. }
  677. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  678. var sortList data_manage.EdbClassifyItemList
  679. if parentId > 0 {
  680. obj := data_manage.EdbInfoNoPermissionAdmin{}
  681. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  682. if err != nil && !utils.IsErrNoRow(err) {
  683. br.Msg = "获取失败"
  684. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  685. return
  686. }
  687. noPermissionEdbInfoIdMap := make(map[int]bool)
  688. for _, v := range confList {
  689. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  690. }
  691. edbType := 0
  692. switch classifyType {
  693. case utils.EdbClassifyTypeBase:
  694. edbType = 1
  695. case utils.EdbClassifyTypeCalculate:
  696. edbType = 2
  697. }
  698. noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.EDB_INFO_TYPE, edbType)
  699. if err != nil {
  700. br.Msg = "获取失败"
  701. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  702. return
  703. }
  704. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, 0, edbType, sysUserId, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList)
  705. if err != nil {
  706. br.Msg = "获取指标数据失败"
  707. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  708. return
  709. }
  710. if len(allEdbInfo) > 0 {
  711. currClassify, err := data_manage.GetEdbClassifyById(parentId)
  712. if err != nil {
  713. br.Msg = "获取失败"
  714. br.ErrMsg = "获取当前分类信息失败,Err:" + err.Error()
  715. return
  716. }
  717. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  718. if err != nil {
  719. br.Msg = "获取失败"
  720. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  721. return
  722. }
  723. for _, v := range allEdbInfo {
  724. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  725. continue
  726. }
  727. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  728. button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth)
  729. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  730. v.Button = button
  731. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  732. v.ParentId = parentId
  733. nodeAll = append(nodeAll, v)
  734. }
  735. }
  736. }
  737. if len(rootList) > 0 {
  738. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  739. if err != nil {
  740. br.Msg = "获取失败"
  741. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  742. return
  743. }
  744. for _, v := range rootList {
  745. if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) {
  746. continue
  747. }
  748. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  749. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  750. v.Button = button
  751. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  752. nodeAll = append(nodeAll, v)
  753. }
  754. }
  755. if len(nodeAll) > 0 {
  756. sortList = nodeAll
  757. sort.Sort(sortList)
  758. }
  759. language := `CN`
  760. {
  761. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  762. if configDetail != nil {
  763. language = configDetail.ConfigValue
  764. } else {
  765. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  766. if configDetail != nil {
  767. language = configDetail.ConfigValue
  768. }
  769. }
  770. }
  771. canOpClassify := true
  772. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  773. if !button.AddButton {
  774. canOpClassify = false
  775. }
  776. resp := new(data_manage.EdbClassifyListResp)
  777. resp.AllNodes = sortList
  778. resp.Language = language
  779. resp.CanOpClassify = canOpClassify
  780. br.Ret = 200
  781. br.Success = true
  782. br.Msg = "获取成功"
  783. br.Data = resp
  784. }
  785. // @router /classify/tree [get]
  786. func (this *EdbClassifyController) ClassifyTree() {
  787. br := new(models.BaseResponse).Init()
  788. defer func() {
  789. this.Data["json"] = br
  790. this.ServeJSON()
  791. }()
  792. classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的
  793. if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate && classifyType != utils.EdbClassifyTypeOrigin {
  794. br.Msg = "参数有误"
  795. br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
  796. return
  797. }
  798. allList := make([]*data_manage.EdbClassifyItems, 0)
  799. if classifyType == utils.EdbClassifyTypeOrigin {
  800. list, e := data_manage.GetEdbClassifyByClassifyTypes([]int{utils.EdbClassifyTypeBase, utils.EdbClassifyTypeCalculate})
  801. if e != nil && !utils.IsErrNoRow(e) {
  802. br.Msg = "获取失败"
  803. br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e)
  804. return
  805. }
  806. allList = list
  807. } else {
  808. list, err := data_manage.GetAllEdbClassifyByType(classifyType)
  809. if err != nil && !utils.IsErrNoRow(err) {
  810. br.Msg = "获取失败"
  811. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  812. return
  813. }
  814. allList = list
  815. }
  816. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  817. var sortList data_manage.EdbClassifyItemList
  818. if len(allList) > 0 {
  819. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  820. if err != nil {
  821. br.Msg = "获取失败"
  822. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  823. return
  824. }
  825. newNodes := make([]*data_manage.EdbClassifyItems, 0)
  826. for _, v := range allList {
  827. if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) {
  828. continue
  829. }
  830. newNodes = append(newNodes, v)
  831. }
  832. for k, v := range newNodes {
  833. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  834. button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  835. newNodes[k].Button = button
  836. }
  837. nodeAll = data.GetClassifyTreeRecursive(newNodes, 0)
  838. sortList = nodeAll
  839. sort.Sort(sortList)
  840. }
  841. language := `CN`
  842. {
  843. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar)
  844. if configDetail != nil {
  845. language = configDetail.ConfigValue
  846. } else {
  847. configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar)
  848. if configDetail != nil {
  849. language = configDetail.ConfigValue
  850. }
  851. }
  852. }
  853. canOpClassify := true
  854. button := data.GetEdbClassifyOpButton(this.SysUser, 0, true)
  855. if !button.AddButton {
  856. canOpClassify = false
  857. }
  858. resp := new(data_manage.EdbClassifyListResp)
  859. resp.AllNodes = sortList
  860. resp.Language = language
  861. resp.CanOpClassify = canOpClassify
  862. br.Ret = 200
  863. br.Success = true
  864. br.Msg = "获取成功"
  865. br.Data = resp
  866. }
  867. // @router /edb_classify/move/v2 [post]