predict_edb_classify.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. type PredictEdbClassifyController struct {
  14. controllers.BaseAuthController
  15. }
  16. // @router /predict_classify/list [get]
  17. // @router /predict_classify/items [get]
  18. func (this *PredictEdbClassifyController) Items() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. rootList, err := data_manage.GetEdbClassifyByParentId(0, 1)
  25. if err != nil {
  26. br.Msg = "获取失败"
  27. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  28. return
  29. }
  30. resp := new(data_manage.EdbClassifyListResp)
  31. resp.AllNodes = rootList
  32. br.Ret = 200
  33. br.Success = true
  34. br.Msg = "获取成功"
  35. br.Data = resp
  36. }
  37. // @router /predict_classify/add [post]
  38. func (this *PredictEdbClassifyController) Add() {
  39. br := new(models.BaseResponse).Init()
  40. defer func() {
  41. this.Data["json"] = br
  42. this.ServeJSON()
  43. }()
  44. var req data_manage.AddEdbClassifyReq
  45. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  46. if err != nil {
  47. br.Msg = "参数解析异常!"
  48. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  49. return
  50. }
  51. if req.ClassifyName == "" {
  52. br.Msg = "请输入分类名称"
  53. br.IsSendEmail = false
  54. return
  55. }
  56. if req.ParentId < 0 {
  57. br.Msg = "参数错误"
  58. br.IsSendEmail = false
  59. return
  60. }
  61. haveOperaAuth := true
  62. if req.ParentId > 0 {
  63. parentClassify, err := data_manage.GetEdbClassifyById(req.ParentId)
  64. if err != nil {
  65. br.Msg = "获取父级分类失败"
  66. br.ErrMsg = "获取父级分类失败,Err:" + err.Error()
  67. return
  68. }
  69. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, parentClassify.ClassifyId)
  70. if err != nil {
  71. br.Msg = "添加失败"
  72. br.ErrMsg = "获取父级分类失败,Err:" + err.Error()
  73. return
  74. }
  75. haveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(parentClassify.IsJoinPermission, parentClassify.ClassifyId, permissionClassifyIdList)
  76. }
  77. button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, haveOperaAuth)
  78. if !button.AddButton {
  79. br.Msg = "不允许添加分类"
  80. br.IsSendEmail = false
  81. return
  82. }
  83. _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, 1, this.SysUser.AdminId, this.SysUser.AdminName, this.Lang)
  84. if errMsg != `` {
  85. br.Msg = errMsg
  86. br.ErrMsg = errMsg
  87. if err != nil {
  88. br.ErrMsg = errMsg + ";Err:" + err.Error()
  89. } else {
  90. br.IsSendEmail = false
  91. }
  92. return
  93. }
  94. br.Ret = 200
  95. br.Msg = "保存成功"
  96. br.Success = true
  97. br.IsAddLog = true
  98. }
  99. // @router /predict_classify/edit [post]
  100. func (this *PredictEdbClassifyController) Edit() {
  101. br := new(models.BaseResponse).Init()
  102. defer func() {
  103. this.Data["json"] = br
  104. this.ServeJSON()
  105. }()
  106. var req data_manage.EditEdbClassifyReq
  107. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  108. if err != nil {
  109. br.Msg = "参数解析异常!"
  110. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  111. return
  112. }
  113. if req.ClassifyName == "" {
  114. br.Msg = "请输入分类名称"
  115. br.IsSendEmail = false
  116. return
  117. }
  118. if req.ClassifyId < 0 {
  119. br.Msg = "参数错误"
  120. br.IsSendEmail = false
  121. return
  122. }
  123. err, errMsg := data.EditEdbClassify(req.ClassifyId, req.ClassifyName, this.Lang, this.SysUser)
  124. if errMsg != `` {
  125. br.Msg = errMsg
  126. br.ErrMsg = errMsg
  127. if err != nil {
  128. br.ErrMsg = errMsg + ";Err:" + err.Error()
  129. } else {
  130. br.IsSendEmail = false
  131. }
  132. return
  133. }
  134. br.Ret = 200
  135. br.Msg = "保存成功"
  136. br.Success = true
  137. br.IsAddLog = true
  138. }
  139. // @router /predict_classify/delete/check [post]
  140. func (this *PredictEdbClassifyController) DeleteCheck() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. var req data_manage.ClassifyDeleteCheckReq
  147. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  148. if err != nil {
  149. br.Msg = "参数解析异常!"
  150. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  151. return
  152. }
  153. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  154. br.Msg = "参数错误"
  155. br.IsSendEmail = false
  156. return
  157. }
  158. deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
  159. if errMsg != `` {
  160. br.Msg = errMsg
  161. br.ErrMsg = errMsg
  162. if err != nil {
  163. br.ErrMsg = err.Error()
  164. } else {
  165. br.IsSendEmail = false
  166. }
  167. return
  168. }
  169. resp := new(data_manage.ClassifyDeleteCheckResp)
  170. resp.DeleteStatus = deleteStatus
  171. resp.TipsMsg = tipsMsg
  172. resp.TableList = tableList
  173. br.Ret = 200
  174. br.Msg = "检测成功"
  175. br.Success = true
  176. br.Data = resp
  177. }
  178. // @router /predict_classify/delete [post]
  179. func (this *PredictEdbClassifyController) Delete() {
  180. br := new(models.BaseResponse).Init()
  181. defer func() {
  182. this.Data["json"] = br
  183. this.ServeJSON()
  184. }()
  185. sysUser := this.SysUser
  186. if sysUser == nil {
  187. br.Msg = "请登录"
  188. br.ErrMsg = "请登录,SysUser Is Empty"
  189. br.Ret = 408
  190. return
  191. }
  192. var req data_manage.DeleteEdbClassifyReq
  193. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  194. if err != nil {
  195. br.Msg = "参数解析异常!"
  196. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  197. return
  198. }
  199. if req.ClassifyId < 0 && req.EdbInfoId <= 0 {
  200. br.Msg = "参数错误"
  201. br.IsSendEmail = false
  202. return
  203. }
  204. nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  205. if errMsg != `` {
  206. br.Msg = errMsg
  207. br.ErrMsg = errMsg
  208. if err != nil {
  209. br.ErrMsg = err.Error()
  210. } else {
  211. br.IsSendEmail = false
  212. }
  213. return
  214. }
  215. resp := data_manage.AddEdbInfoResp{}
  216. if nextItem != nil {
  217. resp = data_manage.AddEdbInfoResp{
  218. EdbInfoId: nextItem.EdbInfoId,
  219. UniqueCode: nextItem.UniqueCode,
  220. ClassifyId: nextItem.ClassifyId,
  221. }
  222. }
  223. br.Ret = 200
  224. br.Msg = "删除成功"
  225. br.Success = true
  226. br.IsAddLog = true
  227. br.Data = resp
  228. }
  229. // @router /predict_classify/move [post]
  230. func (this *PredictEdbClassifyController) Move() {
  231. br := new(models.BaseResponse).Init()
  232. defer func() {
  233. this.Data["json"] = br
  234. this.ServeJSON()
  235. }()
  236. sysUser := this.SysUser
  237. if sysUser == nil {
  238. br.Msg = "请登录"
  239. br.ErrMsg = "请登录,SysUser Is Empty"
  240. br.Ret = 408
  241. return
  242. }
  243. var req data_manage.MoveEdbClassifyReq
  244. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  245. if err != nil {
  246. br.Msg = "参数解析异常!"
  247. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  248. return
  249. }
  250. if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
  251. br.Msg = "参数错误"
  252. br.ErrMsg = "请选择拖动目标,分类目录或者指标"
  253. return
  254. }
  255. err, errMsg := data.MoveEdbClassify(req, sysUser, 1)
  256. if errMsg != `` {
  257. br.Msg = errMsg
  258. br.ErrMsg = errMsg
  259. if err != nil {
  260. br.ErrMsg = err.Error()
  261. } else {
  262. br.IsSendEmail = false
  263. }
  264. return
  265. }
  266. br.Ret = 200
  267. br.Success = true
  268. br.Msg = "移动成功"
  269. }
  270. // @router /predict_classify/list/v2 [get]
  271. // @router /predict_classify/simple [get]
  272. func (this *PredictEdbClassifyController) SimpleList() {
  273. br := new(models.BaseResponse).Init()
  274. defer func() {
  275. this.Data["json"] = br
  276. this.ServeJSON()
  277. }()
  278. parentId, _ := this.GetInt("ParentId")
  279. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  280. sysUserId := 0
  281. if isOnlyMe {
  282. sysUserId = this.SysUser.AdminId
  283. }
  284. rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 1)
  285. if err != nil && !utils.IsErrNoRow(err) {
  286. br.Msg = "获取失败"
  287. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  288. return
  289. }
  290. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  291. var sortList data_manage.EdbClassifyItemList
  292. if parentId > 0 {
  293. noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.PREDICT_EDB_INFO_TYPE, 0)
  294. if err != nil {
  295. br.Msg = "获取失败"
  296. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  297. return
  298. }
  299. allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, utils.PREDICT_EDB_INFO_TYPE, 0, sysUserId, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList)
  300. if err != nil {
  301. br.Msg = "获取指标数据失败"
  302. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  303. return
  304. }
  305. if len(allEdbInfo) > 0 {
  306. currClassify, err := data_manage.GetEdbClassifyById(parentId)
  307. if err != nil {
  308. br.Msg = "获取失败"
  309. br.ErrMsg = "获取当前分类信息失败,Err:" + err.Error()
  310. return
  311. }
  312. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
  313. if err != nil {
  314. br.Msg = "获取失败"
  315. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  316. return
  317. }
  318. for _, v := range allEdbInfo {
  319. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  320. button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  321. button.AddButton = false //不管有没有权限,指标都是没有添加按钮的
  322. button.OpButton = false
  323. button.DeleteButton = false
  324. v.Button = button
  325. v.ParentId = parentId
  326. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  327. nodeAll = append(nodeAll, v)
  328. }
  329. }
  330. }
  331. if len(rootList) > 0 {
  332. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  333. if err != nil {
  334. br.Msg = "获取失败"
  335. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  336. return
  337. }
  338. for _, v := range rootList {
  339. if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) {
  340. continue
  341. }
  342. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  343. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  344. v.Button = button
  345. v.Children = make([]*data_manage.EdbClassifyItems, 0)
  346. nodeAll = append(nodeAll, v)
  347. }
  348. }
  349. if len(nodeAll) > 0 {
  350. sortList = nodeAll
  351. sort.Sort(sortList)
  352. }
  353. canOpClassify := true
  354. button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, true)
  355. if !button.AddButton {
  356. canOpClassify = false
  357. }
  358. language := `CN`
  359. {
  360. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
  361. if configDetail != nil {
  362. language = configDetail.ConfigValue
  363. } else {
  364. configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
  365. if configDetail != nil {
  366. language = configDetail.ConfigValue
  367. }
  368. }
  369. }
  370. resp := new(data_manage.EdbClassifyListResp)
  371. resp.AllNodes = sortList
  372. resp.Language = language
  373. resp.CanOpClassify = canOpClassify
  374. br.Ret = 200
  375. br.Success = true
  376. br.Msg = "获取成功"
  377. br.Data = resp
  378. }
  379. // @router /predict_classify/tree [get]
  380. func (this *PredictEdbClassifyController) ClassifyTree() {
  381. br := new(models.BaseResponse).Init()
  382. defer func() {
  383. this.Data["json"] = br
  384. this.ServeJSON()
  385. }()
  386. allList, err := data_manage.GetPredictEdbClassifyAll()
  387. if err != nil && !utils.IsErrNoRow(err) {
  388. br.Msg = "获取失败"
  389. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  390. return
  391. }
  392. nodeAll := make([]*data_manage.EdbClassifyItems, 0)
  393. var sortList data_manage.EdbClassifyItemList
  394. if len(allList) > 0 {
  395. permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
  396. if err != nil {
  397. br.Msg = "获取失败"
  398. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  399. return
  400. }
  401. for k, v := range allList {
  402. if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) {
  403. continue
  404. }
  405. v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
  406. button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
  407. allList[k].Button = button
  408. }
  409. nodeAll = data.GetClassifyTreeRecursive(allList, 0)
  410. sortList = nodeAll
  411. sort.Sort(sortList)
  412. }
  413. canOpClassify := true
  414. button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, true)
  415. if !button.AddButton {
  416. canOpClassify = false
  417. }
  418. language := `CN`
  419. {
  420. configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar)
  421. if configDetail != nil {
  422. language = configDetail.ConfigValue
  423. } else {
  424. configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar)
  425. if configDetail != nil {
  426. language = configDetail.ConfigValue
  427. }
  428. }
  429. }
  430. resp := new(data_manage.EdbClassifyListResp)
  431. resp.AllNodes = sortList
  432. resp.Language = language
  433. resp.CanOpClassify = canOpClassify
  434. br.Ret = 200
  435. br.Success = true
  436. br.Msg = "获取成功"
  437. br.Data = resp
  438. }