predict_edb_classify.go 27 KB

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