predict_edb_classify.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/controllers"
  5. "eta/eta_mobile/models"
  6. "eta/eta_mobile/models/data_manage"
  7. "eta/eta_mobile/models/system"
  8. "eta/eta_mobile/services/data"
  9. "eta/eta_mobile/services/data/data_manage_permission"
  10. "eta/eta_mobile/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 && err.Error() != utils.ErrNoRow() {
  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 && err.Error() != utils.ErrNoRow() {
  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 && err.Error() != utils.ErrNoRow() {
  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, 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. br.Ret = 200
  304. br.Msg = "检测成功"
  305. br.Success = true
  306. br.Data = resp
  307. }
  308. // Delete
  309. // @Title 删除分类/指标
  310. // @Description 删除分类/指标接口
  311. // @Param request body data_manage.DeleteEdbClassifyReq true "type json string"
  312. // @Success 200 Ret=200 新增成功
  313. // @router /predict_classify/delete [post]
  314. func (this *PredictEdbClassifyController) Delete() {
  315. br := new(models.BaseResponse).Init()
  316. defer func() {
  317. this.Data["json"] = br
  318. this.ServeJSON()
  319. }()
  320. sysUser := this.SysUser
  321. if sysUser == nil {
  322. br.Msg = "请登录"
  323. br.ErrMsg = "请登录,SysUser Is Empty"
  324. br.Ret = 408
  325. return
  326. }
  327. var req data_manage.DeleteEdbClassifyReq
  328. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  329. if err != nil {
  330. br.Msg = "参数解析异常!"
  331. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  332. return
  333. }
  334. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  335. br.Msg = "参数错误"
  336. br.IsSendEmail = false
  337. return
  338. }
  339. nextItem, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  340. if errMsg != `` {
  341. br.Msg = errMsg
  342. br.ErrMsg = errMsg
  343. if err != nil {
  344. br.ErrMsg = err.Error()
  345. } else {
  346. br.IsSendEmail = false
  347. }
  348. return
  349. }
  350. resp := data_manage.AddEdbInfoResp{}
  351. if nextItem != nil {
  352. resp = data_manage.AddEdbInfoResp{
  353. EdbInfoId: nextItem.EdbInfoId,
  354. UniqueCode: nextItem.UniqueCode,
  355. ClassifyId: nextItem.ClassifyId,
  356. }
  357. }
  358. br.Ret = 200
  359. br.Msg = "删除成功"
  360. br.Success = true
  361. br.IsAddLog = true
  362. br.Data = resp
  363. }
  364. // Move
  365. // EdbClassifyMove
  366. // @Title 分类移动接口
  367. // @Description 分类移动接口
  368. // @Success 200 {object} data_manage.MoveEdbClassifyReq
  369. // @router /predict_classify/move [post]
  370. func (this *PredictEdbClassifyController) Move() {
  371. br := new(models.BaseResponse).Init()
  372. defer func() {
  373. this.Data["json"] = br
  374. this.ServeJSON()
  375. }()
  376. sysUser := this.SysUser
  377. if sysUser == nil {
  378. br.Msg = "请登录"
  379. br.ErrMsg = "请登录,SysUser Is Empty"
  380. br.Ret = 408
  381. return
  382. }
  383. var req data_manage.MoveEdbClassifyReq
  384. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  385. if err != nil {
  386. br.Msg = "参数解析异常!"
  387. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  388. return
  389. }
  390. if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
  391. br.Msg = "参数错误"
  392. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  393. return
  394. }
  395. err, errMsg := data.MoveEdbClassify(req, sysUser, 1)
  396. if errMsg != `` {
  397. br.Msg = errMsg
  398. br.ErrMsg = errMsg
  399. if err != nil {
  400. br.ErrMsg = err.Error()
  401. } else {
  402. br.IsSendEmail = false
  403. }
  404. return
  405. }
  406. ////判断分类是否存在
  407. //edbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ClassifyId)
  408. //if err != nil {
  409. // br.Msg = "移动失败"
  410. // br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  411. // return
  412. //}
  413. //updateCol := make([]string, 0)
  414. //
  415. ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
  416. //if edbClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
  417. // parentEdbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ParentClassifyId)
  418. // if err != nil {
  419. // br.Msg = "移动失败"
  420. // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
  421. // return
  422. // }
  423. // edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
  424. // edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
  425. // edbClassifyInfo.ModifyTime = time.Now()
  426. // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
  427. //}
  428. //
  429. ////如果有传入 上一个兄弟节点分类id
  430. //if req.PrevClassifyId > 0 {
  431. // prevClassify, err := data_manage.GetEdbClassifyById(req.PrevClassifyId)
  432. // if err != nil {
  433. // br.Msg = "移动失败"
  434. // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  435. // return
  436. // }
  437. //
  438. // //如果是移动在两个兄弟节点之间
  439. // if req.NextClassifyId > 0 {
  440. // //下一个兄弟节点
  441. // nextClassify, err := data_manage.GetEdbClassifyById(req.NextClassifyId)
  442. // if err != nil {
  443. // br.Msg = "移动失败"
  444. // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  445. // return
  446. // }
  447. // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  448. // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort {
  449. // //变更兄弟节点的排序
  450. // updateSortStr := `sort + 2`
  451. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
  452. // } else {
  453. // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  454. // if nextClassify.Sort-prevClassify.Sort == 1 {
  455. // //变更兄弟节点的排序
  456. // updateSortStr := `sort + 1`
  457. // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
  458. // }
  459. // }
  460. // }
  461. //
  462. // edbClassifyInfo.Sort = prevClassify.Sort + 1
  463. // edbClassifyInfo.ModifyTime = time.Now()
  464. // updateCol = append(updateCol, "Sort", "ModifyTime")
  465. //} else {
  466. // firstClassify, err := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId)
  467. // if err != nil && err.Error() != utils.ErrNoRow() {
  468. // br.Msg = "移动失败"
  469. // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  470. // return
  471. // }
  472. //
  473. // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  474. // if firstClassify != nil && firstClassify.Sort == 0 {
  475. // updateSortStr := ` sort + 1 `
  476. // _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr)
  477. // }
  478. //
  479. // edbClassifyInfo.Sort = 0 //那就是排在第一位
  480. // edbClassifyInfo.ModifyTime = time.Now()
  481. // updateCol = append(updateCol, "Sort", "ModifyTime")
  482. //}
  483. //
  484. ////更新
  485. //if len(updateCol) > 0 {
  486. // err = edbClassifyInfo.Update(updateCol)
  487. // if err != nil {
  488. // br.Msg = "移动失败"
  489. // br.ErrMsg = "修改失败,Err:" + err.Error()
  490. // return
  491. // }
  492. //}
  493. br.Ret = 200
  494. br.Success = true
  495. br.Msg = "移动成功"
  496. }
  497. // ListV2
  498. // @Title 预测指标分类列表
  499. // @Description 预测指标分类列表接口
  500. // @Param IsOnlyMe query bool false "是否只看我的"
  501. // @Success 200 {object} data_manage.EdbClassifyListResp
  502. // @router /predict_classify/list/v2 [get]
  503. //func (this *PredictEdbClassifyController) ListV2() {
  504. // br := new(models.BaseResponse).Init()
  505. // defer func() {
  506. // this.Data["json"] = br
  507. // this.ServeJSON()
  508. // }()
  509. //
  510. // isOnlyMe, _ := this.GetBool("IsOnlyMe")
  511. //
  512. // rootList, err := data_manage.GetEdbClassifyByParentId(0, 1)
  513. // if err != nil && err.Error() != utils.ErrNoRow() {
  514. // br.Msg = "获取失败"
  515. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  516. // return
  517. // }
  518. // // 获取当前账号的不可见指标
  519. // obj := data_manage.EdbInfoNoPermissionAdmin{}
  520. // confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  521. // if err != nil && err.Error() != utils.ErrNoRow() {
  522. // br.Msg = "获取失败"
  523. // br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  524. // return
  525. // }
  526. // noPermissionEdbInfoIdMap := make(map[int]bool)
  527. // for _, v := range confList {
  528. // noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  529. // }
  530. //
  531. // allEdbInfo, err := data_manage.GetPredictEdbInfoAll(1)
  532. // if err != nil && err.Error() != utils.ErrNoRow() {
  533. // br.Msg = "获取失败"
  534. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  535. // return
  536. // }
  537. // edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
  538. // for _, v := range allEdbInfo {
  539. // // 如果指标不可见,那么就不返回该指标
  540. // if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  541. // continue
  542. // }
  543. // button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId)
  544. // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  545. // button.OpButton = false
  546. // button.DeleteButton = false
  547. // v.Button = button
  548. // if isOnlyMe {
  549. // if v.SysUserId == this.SysUser.AdminId {
  550. // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  551. // }
  552. // } else {
  553. // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  554. // }
  555. // }
  556. // rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(1)
  557. // if err != nil && err.Error() != utils.ErrNoRow() {
  558. // br.Msg = "获取失败"
  559. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  560. // return
  561. // }
  562. // classifyAll, err := data_manage.GetEdbClassifyAllV2(1)
  563. // if err != nil && err.Error() != utils.ErrNoRow() {
  564. // br.Msg = "获取失败"
  565. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  566. // return
  567. // }
  568. // rootTwoMap := make(map[int][]*data_manage.EdbClassifyItems)
  569. // for _, v := range rootTwoList {
  570. // button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  571. // v.Button = button
  572. // rootTwoMap[v.ParentId] = append(rootTwoMap[v.ParentId], v)
  573. // }
  574. // rootTwoChildMap := make(map[int][]*data_manage.EdbClassifyItems)
  575. // for _, v := range classifyAll {
  576. // button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  577. // v.Button = button
  578. // if v.Level == 3 {
  579. // rootTwoChildMap[v.ParentId] = append(rootTwoChildMap[v.ParentId], v)
  580. // }
  581. // }
  582. //
  583. // nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  584. // for _, v := range rootList {
  585. // button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  586. // v.Button = button
  587. //
  588. // if existItems, ok := rootTwoMap[v.ClassifyId]; ok {
  589. // v.Children = existItems
  590. // for _, item := range existItems {
  591. // item.Button = button
  592. //
  593. // if existItems, ok := rootTwoChildMap[item.ClassifyId]; ok {
  594. // item.Children = existItems
  595. // for _, existItem := range existItems {
  596. // if _, ok := noPermissionEdbInfoIdMap[existItem.EdbInfoId]; ok {
  597. // continue
  598. // }
  599. // button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId)
  600. // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  601. // existItem.Button = button
  602. // if isOnlyMe {
  603. // if existItem.SysUserId == this.SysUser.AdminId {
  604. // edbInfoMap[existItem.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  605. // }
  606. // } else {
  607. // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v)
  608. // }
  609. // }
  610. // } else {
  611. // items := make([]*data_manage.EdbClassifyItems, 0)
  612. // item.Children = items
  613. // }
  614. // }
  615. // } else {
  616. // items := make([]*data_manage.EdbClassifyItems, 0)
  617. // v.Children = items
  618. // }
  619. // nodeAll = append(nodeAll, v)
  620. // }
  621. //
  622. // // 是否允许添加一级分类
  623. // canOpClassify := true
  624. // button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0)
  625. // if !button.AddButton {
  626. // canOpClassify = false
  627. // }
  628. //
  629. // language := `CN`
  630. // // 指标显示的语言
  631. // {
  632. // configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
  633. // if configDetail != nil {
  634. // language = configDetail.ConfigValue
  635. // } else {
  636. // configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
  637. // if configDetail != nil {
  638. // language = configDetail.ConfigValue
  639. // }
  640. // }
  641. // }
  642. //
  643. // resp := data_manage.EdbClassifyListResp{
  644. // AllNodes: nodeAll,
  645. // CanOpClassify: canOpClassify,
  646. // Language: language,
  647. // }
  648. // br.Ret = 200
  649. // br.Success = true
  650. // br.Msg = "获取成功"
  651. // br.Data = resp
  652. //}
  653. // SimpleList
  654. // @Title 单层分类列表
  655. // @Description 单层分类列表
  656. // @Success 200 {object} data_manage.EdbClassifyListResp
  657. // @router /predict_classify/simple [get]
  658. func (this *PredictEdbClassifyController) SimpleList() {
  659. br := new(models.BaseResponse).Init()
  660. defer func() {
  661. this.Data["json"] = br
  662. this.ServeJSON()
  663. }()
  664. // 默认查一级分类和一级分类下的指标信息,
  665. // 如果是 子级分类,查询该子级分类的下一级分类和指标信息
  666. // 增加标识判断是文件夹还是指标列表
  667. parentId, _ := this.GetInt("ParentId")
  668. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  669. // 如果选择了只看我的,那么只查询归属于我的账号
  670. sysUserId := 0
  671. if isOnlyMe {
  672. sysUserId = this.SysUser.AdminId
  673. }
  674. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 1)
  675. if err != nil && err.Error() != utils.ErrNoRow() {
  676. br.Msg = "获取失败"
  677. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  678. return
  679. }
  680. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  681. var sortList data_manage.EdbClassifyItemList
  682. if parentId > 0 {
  683. // 查询挂在当前分类上的指标列表
  684. // 获取当前账号的不可见指标
  685. obj := data_manage.EdbInfoNoPermissionAdmin{}
  686. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  687. if err != nil && err.Error() != utils.ErrNoRow() {
  688. br.Msg = "获取失败"
  689. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  690. return
  691. }
  692. noPermissionEdbInfoIdMap := make(map[int]bool)
  693. for _, v := range confList {
  694. noPermissionEdbInfoIdMap[v.EdbInfoId] = true
  695. }
  696. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, 1, sysUserId)
  697. if err != nil {
  698. br.Msg = "获取指标数据失败"
  699. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  700. return
  701. }
  702. if len(allEdbInfo) > 0 {
  703. // 查询当前分类信息
  704. currClassify, err := data_manage.GetEdbClassifyById(parentId)
  705. if err != nil {
  706. br.Msg = "获取失败"
  707. br.ErrMsg = "获取当前分类信息失败,Err:" + err.Error()
  708. return
  709. }
  710. // 获取所有有权限的指标和分类
  711. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  712. if err != nil {
  713. br.Msg = "获取失败"
  714. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  715. return
  716. }
  717. for _, v := range allEdbInfo {
  718. // 如果指标不可见,那么就不返回该指标
  719. if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
  720. continue
  721. }
  722. // 数据权限
  723. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  724. // 按钮权限
  725. button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  726. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  727. button.OpButton = false
  728. button.DeleteButton = false
  729. v.Button = button
  730. v.ParentId = parentId
  731. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  732. nodeAll = append(nodeAll, v)
  733. }
  734. }
  735. }
  736. if len(rootList) > 0 {
  737. // 已授权分类id
  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. // 数据权限
  746. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  747. // 按钮权限
  748. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  749. v.Button = button
  750. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  751. nodeAll = append(nodeAll, v)
  752. }
  753. }
  754. if len(nodeAll) > 0 {
  755. //根据sort值排序
  756. sortList = nodeAll
  757. sort.Sort(sortList)
  758. }
  759. // 是否允许添加一级分类
  760. canOpClassify := true
  761. button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, true)
  762. if !button.AddButton {
  763. canOpClassify = false
  764. }
  765. language := `CN`
  766. // 指标显示的语言
  767. {
  768. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
  769. if configDetail != nil {
  770. language = configDetail.ConfigValue
  771. } else {
  772. configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
  773. if configDetail != nil {
  774. language = configDetail.ConfigValue
  775. }
  776. }
  777. }
  778. resp := new(data_manage.EdbClassifyListResp)
  779. resp.AllNodes = sortList
  780. resp.Language = language
  781. resp.CanOpClassify = canOpClassify
  782. br.Ret = 200
  783. br.Success = true
  784. br.Msg = "获取成功"
  785. br.Data = resp
  786. }
  787. // ClassifyTree
  788. // @Title 多层分类列表树
  789. // @Description 多层分类列表树
  790. // @Success 200 {object} data_manage.EdbClassifyListResp
  791. // @router /predict_classify/tree [get]
  792. func (this *PredictEdbClassifyController) ClassifyTree() {
  793. br := new(models.BaseResponse).Init()
  794. defer func() {
  795. this.Data["json"] = br
  796. this.ServeJSON()
  797. }()
  798. allList, err := data_manage.GetPredictEdbClassifyAll()
  799. if err != nil && err.Error() != utils.ErrNoRow() {
  800. br.Msg = "获取失败"
  801. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  802. return
  803. }
  804. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  805. var sortList data_manage.EdbClassifyItemList
  806. if len(allList) > 0 {
  807. // 已授权分类id
  808. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  809. if err != nil {
  810. br.Msg = "获取失败"
  811. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  812. return
  813. }
  814. for k, v := range allList {
  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. }