predict_edb_classify.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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/utils"
  10. "sort"
  11. )
  12. // PredictEdbClassifyController 数据管理-预测指标分类模块
  13. type PredictEdbClassifyController struct {
  14. controllers.BaseAuthController
  15. }
  16. // List
  17. // @Title 预测指标分类列表
  18. // @Description 预测指标分类列表接口
  19. // @Param IsOnlyMe query bool false "是否只看我的"
  20. // @Success 200 {object} data_manage.EdbClassifyListResp
  21. // @router /predict_classify/list [get]
  22. func (this *PredictEdbClassifyController) List() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  29. rootList, err := data_manage.GetEdbClassifyByParentId(0, 1)
  30. if err != nil && err.Error() != utils.ErrNoRow() {
  31. br.Msg = "获取失败"
  32. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  33. return
  34. }
  35. // 获取当前账号的不可见指标
  36. obj := data_manage.EdbInfoNoPermissionAdmin{}
  37. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  38. if err != nil && err.Error() != utils.ErrNoRow() {
  39. br.Msg = "获取失败"
  40. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  41. return
  42. }
  43. noPermissionEdbInfoIdMap := make(map[int]bool)
  44. for _, v := range confList {
  45. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  46. }
  47. allEdbInfo, err := data_manage.GetPredictEdbInfoAll(1)
  48. if err != nil && err.Error() != utils.ErrNoRow() {
  49. br.Msg = "获取失败"
  50. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  51. return
  52. }
  53. edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  54. for _, v := range allEdbInfo {
  55. // 如果指标不可见,那么就不返回该指标
  56. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  57. continue
  58. }
  59. button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId)
  60. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  61. button.OpButton = false
  62. button.DeleteButton = false
  63. v.Button = button
  64. if isOnlyMe {
  65. if v.SysUserId == this.SysUser.AdminId {
  66. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  67. }
  68. } else {
  69. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  70. }
  71. }
  72. rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  73. for _, v := range rootList {
  74. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  75. v.Button = button
  76. rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
  77. if existItems, ok := edbInfoMap[v.ClassifyId]; ok {
  78. v.Children = existItems
  79. } else {
  80. items := make([]*data_manage.EdbClassifyItems, 0)
  81. v.Children = items
  82. }
  83. }
  84. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  85. for _, v := range rootList {
  86. nodeAll = append(nodeAll, v)
  87. }
  88. // 是否允许添加分类
  89. canOpClassify := true
  90. // 如果不是 超管 或者 ficc管理员 或者 ficc研究员,那么就没有权限
  91. //if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RESEARCHR, utils.ROLE_TYPE_CODE_FICC_RESEARCHR}, this.SysUser.RoleTypeCode) {
  92. // canOpClassify = false
  93. //}
  94. language := `CN`
  95. // 指标显示的语言
  96. {
  97. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
  98. if configDetail != nil {
  99. language = configDetail.ConfigValue
  100. } else {
  101. configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
  102. if configDetail != nil {
  103. language = configDetail.ConfigValue
  104. }
  105. }
  106. }
  107. resp := data_manage.EdbClassifyListResp{
  108. AllNodes: nodeAll,
  109. CanOpClassify: canOpClassify,
  110. Language: language,
  111. }
  112. br.Ret = 200
  113. br.Success = true
  114. br.Msg = "获取成功"
  115. br.Data = resp
  116. }
  117. // Items
  118. // @Title 获取所有预测指标分类接口-不包含指标
  119. // @Description 获取所有预测指标分类接口-不包含指标
  120. // @Success 200 {object} data_manage.EdbClassifyListResp
  121. // @router /predict_classify/items [get]
  122. func (this *PredictEdbClassifyController) Items() {
  123. br := new(models.BaseResponse).Init()
  124. defer func() {
  125. this.Data["json"] = br
  126. this.ServeJSON()
  127. }()
  128. rootList, err := data_manage.GetEdbClassifyByParentId(0, 1)
  129. if err != nil {
  130. br.Msg = "获取失败"
  131. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  132. return
  133. }
  134. resp := new(data_manage.EdbClassifyListResp)
  135. resp.AllNodes = rootList
  136. br.Ret = 200
  137. br.Success = true
  138. br.Msg = "获取成功"
  139. br.Data = resp
  140. }
  141. // Add
  142. // @Title 新增预测指标分类
  143. // @Description 新增预测指标分类接口
  144. // @Param request body data_manage.AddEdbClassifyReq true "type json string"
  145. // @Success 200 Ret=200 保存成功
  146. // @router /predict_classify/add [post]
  147. func (this *PredictEdbClassifyController) Add() {
  148. br := new(models.BaseResponse).Init()
  149. defer func() {
  150. this.Data["json"] = br
  151. this.ServeJSON()
  152. }()
  153. var req data_manage.AddEdbClassifyReq
  154. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  155. if err != nil {
  156. br.Msg = "参数解析异常!"
  157. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  158. return
  159. }
  160. if req.ClassifyName == "" {
  161. br.Msg = "请输入分类名称"
  162. br.IsSendEmail = false
  163. return
  164. }
  165. if req.ParentId < 0 {
  166. br.Msg = "参数错误"
  167. br.IsSendEmail = false
  168. return
  169. }
  170. button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0)
  171. if !button.AddButton {
  172. br.Msg = "不允许添加分类"
  173. br.IsSendEmail = false
  174. return
  175. }
  176. // 添加指标分类
  177. _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, 1, this.SysUser.AdminId, this.SysUser.AdminName)
  178. if errMsg != `` {
  179. br.Msg = errMsg
  180. br.ErrMsg = errMsg
  181. if err != nil {
  182. br.ErrMsg = errMsg + ";Err:" + err.Error()
  183. } else {
  184. br.IsSendEmail = false
  185. }
  186. return
  187. }
  188. br.Ret = 200
  189. br.Msg = "保存成功"
  190. br.Success = true
  191. br.IsAddLog = true
  192. }
  193. // Edit
  194. // @Title 修改预测指标分类
  195. // @Description 修改预测指标分类接口
  196. // @Param request body data_manage.EditEdbClassifyReq true "type json string"
  197. // @Success 200 Ret=200 修改成功
  198. // @router /predict_classify/edit [post]
  199. func (this *PredictEdbClassifyController) Edit() {
  200. br := new(models.BaseResponse).Init()
  201. defer func() {
  202. this.Data["json"] = br
  203. this.ServeJSON()
  204. }()
  205. var req data_manage.EditEdbClassifyReq
  206. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  207. if err != nil {
  208. br.Msg = "参数解析异常!"
  209. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  210. return
  211. }
  212. if req.ClassifyName == "" {
  213. br.Msg = "请输入分类名称"
  214. br.IsSendEmail = false
  215. return
  216. }
  217. if req.ClassifyId < 0 {
  218. br.Msg = "参数错误"
  219. br.IsSendEmail = false
  220. return
  221. }
  222. err, errMsg := data.EditEdbClassify(req.ClassifyId, req.ClassifyName, this.SysUser)
  223. if errMsg != `` {
  224. br.Msg = errMsg
  225. br.ErrMsg = errMsg
  226. if err != nil {
  227. br.ErrMsg = errMsg + ";Err:" + err.Error()
  228. } else {
  229. br.IsSendEmail = false
  230. }
  231. return
  232. }
  233. br.Ret = 200
  234. br.Msg = "保存成功"
  235. br.Success = true
  236. br.IsAddLog = true
  237. }
  238. // DeleteCheck
  239. // @Title 删除检测接口
  240. // @Description 删除检测接口
  241. // @Param request body data_manage.ClassifyDeleteCheckReq true "type json string"
  242. // @Success 200 Ret=200 检测成功
  243. // @router /predict_classify/delete/check [post]
  244. func (this *PredictEdbClassifyController) DeleteCheck() {
  245. br := new(models.BaseResponse).Init()
  246. defer func() {
  247. this.Data["json"] = br
  248. this.ServeJSON()
  249. }()
  250. var req data_manage.ClassifyDeleteCheckReq
  251. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  252. if err != nil {
  253. br.Msg = "参数解析异常!"
  254. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  255. return
  256. }
  257. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  258. br.Msg = "参数错误"
  259. br.IsSendEmail = false
  260. return
  261. }
  262. deleteStatus, tipsMsg, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
  263. if errMsg != `` {
  264. br.Msg = errMsg
  265. br.ErrMsg = errMsg
  266. if err != nil {
  267. br.ErrMsg = err.Error()
  268. } else {
  269. br.IsSendEmail = false
  270. }
  271. return
  272. }
  273. resp := new(data_manage.ClassifyDeleteCheckResp)
  274. resp.DeleteStatus = deleteStatus
  275. resp.TipsMsg = tipsMsg
  276. br.Ret = 200
  277. br.Msg = "检测成功"
  278. br.Success = true
  279. br.Data = resp
  280. }
  281. // Delete
  282. // @Title 删除分类/指标
  283. // @Description 删除分类/指标接口
  284. // @Param request body data_manage.DeleteEdbClassifyReq true "type json string"
  285. // @Success 200 Ret=200 新增成功
  286. // @router /predict_classify/delete [post]
  287. func (this *PredictEdbClassifyController) Delete() {
  288. br := new(models.BaseResponse).Init()
  289. defer func() {
  290. this.Data["json"] = br
  291. this.ServeJSON()
  292. }()
  293. sysUser := this.SysUser
  294. if sysUser == nil {
  295. br.Msg = "请登录"
  296. br.ErrMsg = "请登录,SysUser Is Empty"
  297. br.Ret = 408
  298. return
  299. }
  300. var req data_manage.DeleteEdbClassifyReq
  301. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  302. if err != nil {
  303. br.Msg = "参数解析异常!"
  304. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  305. return
  306. }
  307. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  308. br.Msg = "参数错误"
  309. br.IsSendEmail = false
  310. return
  311. }
  312. nextItem, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  313. if errMsg != `` {
  314. br.Msg = errMsg
  315. br.ErrMsg = errMsg
  316. if err != nil {
  317. br.ErrMsg = err.Error()
  318. } else {
  319. br.IsSendEmail = false
  320. }
  321. return
  322. }
  323. resp := data_manage.AddEdbInfoResp{}
  324. if nextItem != nil {
  325. resp = data_manage.AddEdbInfoResp{
  326. EdbInfoId: nextItem.EdbInfoId,
  327. UniqueCode: nextItem.UniqueCode,
  328. ClassifyId: nextItem.ClassifyId,
  329. }
  330. }
  331. br.Ret = 200
  332. br.Msg = "删除成功"
  333. br.Success = true
  334. br.IsAddLog = true
  335. br.Data = resp
  336. }
  337. // Move
  338. // EdbClassifyMove
  339. // @Title 分类移动接口
  340. // @Description 分类移动接口
  341. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  342. // @router /predict_classify/move [post]
  343. func (this *PredictEdbClassifyController) Move() {
  344. br := new(models.BaseResponse).Init()
  345. defer func() {
  346. this.Data["json"] = br
  347. this.ServeJSON()
  348. }()
  349. sysUser := this.SysUser
  350. if sysUser == nil {
  351. br.Msg = "请登录"
  352. br.ErrMsg = "请登录,SysUser Is Empty"
  353. br.Ret = 408
  354. return
  355. }
  356. var req data_manage.MoveEdbClassifyReq
  357. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  358. if err != nil {
  359. br.Msg = "参数解析异常!"
  360. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  361. return
  362. }
  363. if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
  364. br.Msg = "参数错误"
  365. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  366. return
  367. }
  368. err, errMsg := data.MoveEdbClassify(req, sysUser, 1)
  369. if errMsg != `` {
  370. br.Msg = errMsg
  371. br.ErrMsg = errMsg
  372. if err != nil {
  373. br.ErrMsg = err.Error()
  374. } else {
  375. br.IsSendEmail = false
  376. }
  377. return
  378. }
  379. ////判断分类是否存在
  380. //edbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  381. //if err != nil {
  382. // br.Msg = "移动失败"
  383. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  384. // return
  385. //}
  386. //updateCol := make([]string, 0)
  387. //
  388. ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  389. //if edbClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  390. // parentEdbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ParentClassifyId)
  391. // if err != nil {
  392. // br.Msg = "移动失败"
  393. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  394. // return
  395. // }
  396. // edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  397. // edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  398. // edbClassifyInfo.ModifyTime = time.Now()
  399. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  400. //}
  401. //
  402. ////如果有传入 上一个兄弟节点分类id
  403. //if req.PrevClassifyId > 0 {
  404. // prevClassify, err := data_manage.GetEdbClassifyById(req.PrevClassifyId)
  405. // if err != nil {
  406. // br.Msg = "移动失败"
  407. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  408. // return
  409. // }
  410. //
  411. // //如果是移动在两个兄弟节点之间
  412. // if req.NextClassifyId > 0 {
  413. // //下一个兄弟节点
  414. // nextClassify, err := data_manage.GetEdbClassifyById(req.NextClassifyId)
  415. // if err != nil {
  416. // br.Msg = "移动失败"
  417. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  418. // return
  419. // }
  420. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  421. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort {
  422. // //变更兄弟节点的排序
  423. // updateSortStr := `sort + 2`
  424. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
  425. // } else {
  426. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  427. // if nextClassify.Sort-prevClassify.Sort == 1 {
  428. // //变更兄弟节点的排序
  429. // updateSortStr := `sort + 1`
  430. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  431. // }
  432. // }
  433. // }
  434. //
  435. // edbClassifyInfo.Sort = prevClassify.Sort + 1
  436. // edbClassifyInfo.ModifyTime = time.Now()
  437. // updateCol = append(updateCol, "Sort", "ModifyTime")
  438. //} else {
  439. // firstClassify, err := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId)
  440. // if err != nil && err.Error() != utils.ErrNoRow() {
  441. // br.Msg = "移动失败"
  442. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  443. // return
  444. // }
  445. //
  446. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  447. // if firstClassify != nil && firstClassify.Sort == 0 {
  448. // updateSortStr := ` sort + 1 `
  449. // _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr)
  450. // }
  451. //
  452. // edbClassifyInfo.Sort = 0 //那就是排在第一位
  453. // edbClassifyInfo.ModifyTime = time.Now()
  454. // updateCol = append(updateCol, "Sort", "ModifyTime")
  455. //}
  456. //
  457. ////更新
  458. //if len(updateCol) > 0 {
  459. // err = edbClassifyInfo.Update(updateCol)
  460. // if err != nil {
  461. // br.Msg = "移动失败"
  462. // br.ErrMsg = "修改失败,Err:" + err.Error()
  463. // return
  464. // }
  465. //}
  466. br.Ret = 200
  467. br.Success = true
  468. br.Msg = "移动成功"
  469. }
  470. // ListV2
  471. // @Title 预测指标分类列表
  472. // @Description 预测指标分类列表接口
  473. // @Param IsOnlyMe query bool false "是否只看我的"
  474. // @Success 200 {object} data_manage.EdbClassifyListResp
  475. // @router /predict_classify/list/v2 [get]
  476. func (this *PredictEdbClassifyController) ListV2() {
  477. br := new(models.BaseResponse).Init()
  478. defer func() {
  479. this.Data["json"] = br
  480. this.ServeJSON()
  481. }()
  482. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  483. rootList, err := data_manage.GetEdbClassifyByParentId(0, 1)
  484. if err != nil && err.Error() != utils.ErrNoRow() {
  485. br.Msg = "获取失败"
  486. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  487. return
  488. }
  489. // 获取当前账号的不可见指标
  490. obj := data_manage.EdbInfoNoPermissionAdmin{}
  491. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  492. if err != nil && err.Error() != utils.ErrNoRow() {
  493. br.Msg = "获取失败"
  494. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  495. return
  496. }
  497. noPermissionEdbInfoIdMap := make(map[int]bool)
  498. for _, v := range confList {
  499. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  500. }
  501. allEdbInfo, err := data_manage.GetPredictEdbInfoAll(1)
  502. if err != nil && err.Error() != utils.ErrNoRow() {
  503. br.Msg = "获取失败"
  504. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  505. return
  506. }
  507. edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  508. for _, v := range allEdbInfo {
  509. // 如果指标不可见,那么就不返回该指标
  510. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  511. continue
  512. }
  513. button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId)
  514. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  515. button.OpButton = false
  516. button.DeleteButton = false
  517. v.Button = button
  518. if isOnlyMe {
  519. if v.SysUserId == this.SysUser.AdminId {
  520. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  521. }
  522. } else {
  523. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  524. }
  525. }
  526. rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(1)
  527. if err != nil && err.Error() != utils.ErrNoRow() {
  528. br.Msg = "获取失败"
  529. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  530. return
  531. }
  532. classifyAll, err := data_manage.GetEdbClassifyAllV2(1)
  533. if err != nil && err.Error() != utils.ErrNoRow() {
  534. br.Msg = "获取失败"
  535. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  536. return
  537. }
  538. rootTwoMap := make(map[int][]*data_manage.EdbClassifyItems)
  539. for _, v := range rootTwoList {
  540. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  541. v.Button = button
  542. rootTwoMap[v.ParentId] = append(rootTwoMap[v.ParentId], v)
  543. }
  544. rootTwoChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  545. for _, v := range classifyAll {
  546. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  547. v.Button = button
  548. if v.Level == 3 {
  549. rootTwoChildMap[v.ParentId] = append(rootTwoChildMap[v.ParentId], v)
  550. }
  551. }
  552. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  553. for _, v := range rootList {
  554. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  555. v.Button = button
  556. if existItems, ok := rootTwoMap[v.ClassifyId]; ok {
  557. v.Children = existItems
  558. for _, item := range existItems {
  559. item.Button = button
  560. if existItems, ok := rootTwoChildMap[item.ClassifyId]; ok {
  561. item.Children = existItems
  562. for _, existItem := range existItems {
  563. if _, ok := noPermissionEdbInfoIdMap[existItem.EdbInfoId]; ok {
  564. continue
  565. }
  566. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  567. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  568. existItem.Button = button
  569. if isOnlyMe {
  570. if existItem.SysUserId == this.SysUser.AdminId {
  571. edbInfoMap[existItem.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  572. }
  573. } else {
  574. edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  575. }
  576. }
  577. } else {
  578. items := make([]*data_manage.EdbClassifyItems, 0)
  579. item.Children = items
  580. }
  581. }
  582. } else {
  583. items := make([]*data_manage.EdbClassifyItems, 0)
  584. v.Children = items
  585. }
  586. nodeAll = append(nodeAll, v)
  587. }
  588. // 是否允许添加一级分类
  589. canOpClassify := true
  590. button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0)
  591. if !button.AddButton {
  592. canOpClassify = false
  593. }
  594. language := `CN`
  595. // 指标显示的语言
  596. {
  597. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
  598. if configDetail != nil {
  599. language = configDetail.ConfigValue
  600. } else {
  601. configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
  602. if configDetail != nil {
  603. language = configDetail.ConfigValue
  604. }
  605. }
  606. }
  607. resp := data_manage.EdbClassifyListResp{
  608. AllNodes: nodeAll,
  609. CanOpClassify: canOpClassify,
  610. Language: language,
  611. }
  612. br.Ret = 200
  613. br.Success = true
  614. br.Msg = "获取成功"
  615. br.Data = resp
  616. }
  617. // SimpleList
  618. // @Title 单层分类列表
  619. // @Description 单层分类列表
  620. // @Success 200 {object} data_manage.EdbClassifyListResp
  621. // @router /predict_classify/simple [get]
  622. func (this *PredictEdbClassifyController) SimpleList() {
  623. br := new(models.BaseResponse).Init()
  624. defer func() {
  625. this.Data["json"] = br
  626. this.ServeJSON()
  627. }()
  628. // 默认查一级分类和一级分类下的指标信息,
  629. // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
  630. // 增加标识判断是文件夹还是指标列表
  631. parentId, _ := this.GetInt("ParentId")
  632. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  633. // 如果选择了只看我的,那么只查询归属于我的账号
  634. sysUserId := 0
  635. if isOnlyMe {
  636. sysUserId = this.SysUser.AdminId
  637. }
  638. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 1)
  639. if err != nil && err.Error() != utils.ErrNoRow() {
  640. br.Msg = "获取失败"
  641. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  642. return
  643. }
  644. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  645. var sortList data_manage.EdbClassifyItemList
  646. if parentId > 0 {
  647. // 查询挂在当前分类上的指标列表
  648. // 获取当前账号的不可见指标
  649. obj := data_manage.EdbInfoNoPermissionAdmin{}
  650. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  651. if err != nil && err.Error() != utils.ErrNoRow() {
  652. br.Msg = "获取失败"
  653. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  654. return
  655. }
  656. noPermissionEdbInfoIdMap := make(map[int]bool)
  657. for _, v := range confList {
  658. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  659. }
  660. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, 1, sysUserId)
  661. if err != nil {
  662. br.Msg = "获取指标数据失败"
  663. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  664. return
  665. }
  666. for _, v := range allEdbInfo {
  667. // 如果指标不可见,那么就不返回该指标
  668. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  669. continue
  670. }
  671. button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId)
  672. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  673. button.OpButton = false
  674. button.DeleteButton = false
  675. v.Button = button
  676. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  677. v.ParentId = parentId
  678. nodeAll = append(nodeAll, v)
  679. }
  680. }
  681. if len(rootList) > 0 {
  682. for _, v := range rootList {
  683. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  684. v.Button = button
  685. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  686. nodeAll = append(nodeAll, v)
  687. }
  688. }
  689. if len(nodeAll) > 0 {
  690. //根据sort值排序
  691. sortList = nodeAll
  692. sort.Sort(sortList)
  693. }
  694. // 是否允许添加一级分类
  695. canOpClassify := true
  696. button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0)
  697. if !button.AddButton {
  698. canOpClassify = false
  699. }
  700. language := `CN`
  701. // 指标显示的语言
  702. {
  703. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
  704. if configDetail != nil {
  705. language = configDetail.ConfigValue
  706. } else {
  707. configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
  708. if configDetail != nil {
  709. language = configDetail.ConfigValue
  710. }
  711. }
  712. }
  713. resp := new(data_manage.EdbClassifyListResp)
  714. resp.AllNodes = sortList
  715. resp.Language = language
  716. resp.CanOpClassify = canOpClassify
  717. br.Ret = 200
  718. br.Success = true
  719. br.Msg = "获取成功"
  720. br.Data = resp
  721. }
  722. // ClassifyTree
  723. // @Title 多层分类列表树
  724. // @Description 多层分类列表树
  725. // @Success 200 {object} data_manage.EdbClassifyListResp
  726. // @router /predict_classify/tree [get]
  727. func (this *PredictEdbClassifyController) ClassifyTree() {
  728. br := new(models.BaseResponse).Init()
  729. defer func() {
  730. this.Data["json"] = br
  731. this.ServeJSON()
  732. }()
  733. allList, err := data_manage.GetPredictEdbClassifyAll()
  734. if err != nil && err.Error() != utils.ErrNoRow() {
  735. br.Msg = "获取失败"
  736. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  737. return
  738. }
  739. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  740. var sortList data_manage.EdbClassifyItemList
  741. if len(allList) > 0 {
  742. for k, v := range allList {
  743. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  744. allList[k].Button = button
  745. }
  746. nodeAll = data.GetClassifyTreeRecursive(allList, 0)
  747. //根据sort值排序
  748. sortList = nodeAll
  749. sort.Sort(sortList)
  750. }
  751. // 是否允许添加一级分类
  752. canOpClassify := true
  753. button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0)
  754. if !button.AddButton {
  755. canOpClassify = false
  756. }
  757. language := `CN`
  758. // 指标显示的语言
  759. {
  760. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
  761. if configDetail != nil {
  762. language = configDetail.ConfigValue
  763. } else {
  764. configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
  765. if configDetail != nil {
  766. language = configDetail.ConfigValue
  767. }
  768. }
  769. }
  770. resp := new(data_manage.EdbClassifyListResp)
  771. resp.AllNodes = sortList
  772. resp.Language = language
  773. resp.CanOpClassify = canOpClassify
  774. br.Ret = 200
  775. br.Success = true
  776. br.Msg = "获取成功"
  777. br.Data = resp
  778. }