sys_role.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/system"
  6. "eta/eta_api/services"
  7. "eta/eta_api/services/eta_forum"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "github.com/rdlucklib/rdluck_tools/paging"
  14. )
  15. type SysRoleController struct {
  16. BaseAuthController
  17. }
  18. // @Title 新增角色
  19. // @Description 新增角色接口
  20. // @Param request body system.SysRoleAddReq true "type json string"
  21. // @Success 200 新增成功
  22. // @router /role/add [post]
  23. func (this *SysRoleController) Add() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. var req system.SysRoleAddReq
  30. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  31. if err != nil {
  32. br.Msg = "参数解析异常!"
  33. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  34. return
  35. }
  36. if req.RoleName == "" {
  37. br.Msg = "角色名称不能为空"
  38. return
  39. }
  40. count, err := system.GetSysRoleCount(req.RoleName)
  41. if err != nil && err.Error() != utils.ErrNoRow() {
  42. br.Msg = "获取数据失败"
  43. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  44. return
  45. }
  46. if count > 0 {
  47. br.Msg = "角色已存在,请重新输入"
  48. return
  49. }
  50. item := new(system.SysRole)
  51. item.RoleName = req.RoleName
  52. item.RoleType = req.RoleType
  53. item.RoleTypeCode = services.GetRoleTypeCode(req.RoleType)
  54. item.CreateTime = time.Now()
  55. item.ModifyTime = time.Now()
  56. roleId, err := system.AddSysRole(item)
  57. if err != nil {
  58. br.Msg = "新增失败"
  59. br.ErrMsg = "新增失败,Err:" + err.Error()
  60. return
  61. }
  62. // 同步角色缓存
  63. if utils.BusinessCode == utils.BusinessCodeRelease {
  64. var syncData system.SyncRoleData
  65. syncData.Source = utils.SOURCE_ETA_FLAG
  66. syncData.RoleId = int(roleId)
  67. _ = utils.Rc.LPush(utils.CACHE_SYNC_ROLE, syncData)
  68. }
  69. go eta_forum.RoleSave(int(roleId))
  70. br.Ret = 200
  71. br.Success = true
  72. br.Msg = "新增成功"
  73. }
  74. // @Title 修改角色
  75. // @Description 修改角色接口
  76. // @Param request body system.SysRoleEditReq true "type json string"
  77. // @Success 200 修改成功
  78. // @router /role/edit [post]
  79. func (this *SysRoleController) Edit() {
  80. br := new(models.BaseResponse).Init()
  81. defer func() {
  82. this.Data["json"] = br
  83. this.ServeJSON()
  84. }()
  85. var req system.SysRoleEditReq
  86. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  87. if err != nil {
  88. br.Msg = "参数解析异常!"
  89. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  90. return
  91. }
  92. if req.RoleId <= 0 {
  93. br.Msg = "参数错误"
  94. br.ErrMsg = "参数错误,GroupId 小于等于0 "
  95. return
  96. }
  97. if req.RoleName == "" {
  98. br.Msg = "分组名称不能为空"
  99. return
  100. }
  101. item, e := system.GetSysRoleById(req.RoleId)
  102. if e != nil {
  103. if e.Error() != utils.ErrNoRow() {
  104. br.Msg = "操作失败"
  105. br.ErrMsg = "获取角色失败, Err: " + e.Error()
  106. return
  107. }
  108. br.Msg = "角色不存在, 请刷新页面"
  109. return
  110. }
  111. // 不允许编辑admin用户
  112. if item.RoleName == "admin" {
  113. br.Msg = "admin用户不可编辑"
  114. return
  115. }
  116. exists, e := system.GetSysRoleByName(req.RoleName)
  117. if e != nil && e.Error() != utils.ErrNoRow() {
  118. br.Msg = "操作失败"
  119. br.ErrMsg = "获取重名角色失败, Err: " + e.Error()
  120. return
  121. }
  122. if exists != nil && exists.RoleId != item.RoleId {
  123. br.Msg = "名称已存在,请重新输入"
  124. return
  125. }
  126. roleTypeCode := services.GetRoleTypeCode(req.RoleType)
  127. e = system.ModifySysRole(req.RoleName, req.RoleType, roleTypeCode, req.RoleId)
  128. if e != nil {
  129. br.Msg = "操作失败"
  130. br.ErrMsg = "更新角色信息失败, Err: " + e.Error()
  131. return
  132. }
  133. // 同步角色缓存
  134. if utils.BusinessCode == utils.BusinessCodeRelease {
  135. var syncData system.SyncRoleData
  136. syncData.Source = utils.SOURCE_ETA_FLAG
  137. syncData.RoleId = item.RoleId
  138. _ = utils.Rc.LPush(utils.CACHE_SYNC_ROLE, syncData)
  139. }
  140. go eta_forum.RoleSave(item.RoleId)
  141. br.Ret = 200
  142. br.Success = true
  143. br.IsAddLog = true
  144. br.Msg = "修改成功"
  145. }
  146. // @Title 删除角色
  147. // @Description 删除角色接口
  148. // @Param request body system.SysRoleDeleteReq true "type json string"
  149. // @Success 200 删除成功
  150. // @router /role/delete [post]
  151. func (this *SysRoleController) Delete() {
  152. br := new(models.BaseResponse).Init()
  153. defer func() {
  154. this.Data["json"] = br
  155. this.ServeJSON()
  156. }()
  157. var req system.SysRoleDeleteReq
  158. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  159. if err != nil {
  160. br.Msg = "参数解析异常!"
  161. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  162. return
  163. }
  164. if req.RoleId <= 0 {
  165. br.Msg = "参数错误"
  166. br.ErrMsg = "参数错误,GroupId 小于等于0 "
  167. return
  168. }
  169. role, e := system.GetSysRoleById(req.RoleId)
  170. if e != nil {
  171. if err.Error() == utils.ErrNoRow() {
  172. br.Msg = "角色不存在, 请刷新页面"
  173. return
  174. }
  175. br.Msg = "删除失败"
  176. br.ErrMsg = "获取角色信息失败, Err: " + e.Error()
  177. return
  178. }
  179. if role.RoleName == "admin" {
  180. br.Msg = "admin用户不可删除"
  181. return
  182. }
  183. err = system.DeleteSysRole(req.RoleId)
  184. if err != nil {
  185. br.Msg = "删除失败"
  186. br.ErrMsg = "删除失败,Err:" + err.Error()
  187. return
  188. }
  189. // 同步角色缓存
  190. if utils.BusinessCode == utils.BusinessCodeRelease {
  191. var syncData system.SyncRoleData
  192. syncData.Source = utils.SOURCE_ETA_FLAG
  193. syncData.RoleId = role.RoleId
  194. _ = utils.Rc.LPush(utils.CACHE_SYNC_ROLE, syncData)
  195. }
  196. go eta_forum.RoleDelete(role.RoleId)
  197. br.Ret = 200
  198. br.Success = true
  199. br.IsAddLog = true
  200. br.Msg = "删除成功"
  201. }
  202. // @Title 获取角色列表
  203. // @Description 获取角色列表接口
  204. // @Param PageSize query int true "每页数据条数"
  205. // @Param CurrentIndex query int true "当前页页码,从1开始"
  206. // @Param KeyWord query string true "搜索关键词"
  207. // @Success 200 {object} system.SysRoleListResp
  208. // @router /role/list [get]
  209. func (this *SysRoleController) ListSysRole() {
  210. br := new(models.BaseResponse).Init()
  211. defer func() {
  212. this.Data["json"] = br
  213. this.ServeJSON()
  214. }()
  215. sysUser := this.SysUser
  216. if sysUser == nil {
  217. br.Msg = "请登录"
  218. br.ErrMsg = "请登录,SysUser Is Empty"
  219. return
  220. }
  221. pageSize, _ := this.GetInt("PageSize")
  222. currentIndex, _ := this.GetInt("CurrentIndex")
  223. keyWord := this.GetString("KeyWord")
  224. var startSize int
  225. if pageSize <= 0 {
  226. pageSize = utils.PageSize20
  227. }
  228. if currentIndex <= 0 {
  229. currentIndex = 1
  230. }
  231. startSize = utils.StartIndex(currentIndex, pageSize)
  232. var condition string
  233. var pars []interface{}
  234. if keyWord != "" {
  235. condition += ` AND role_name LIKE '%` + keyWord + `%' `
  236. }
  237. total, err := system.GetSysRoleListCount(condition, pars)
  238. if err != nil {
  239. br.Msg = "获取失败"
  240. br.ErrMsg = "获取失败,Err:" + err.Error()
  241. return
  242. }
  243. list, err := system.GetSysRoleList(condition, pars, startSize, pageSize)
  244. if err != nil {
  245. br.Msg = "获取失败"
  246. br.ErrMsg = "获取失败,Err:" + err.Error()
  247. return
  248. }
  249. page := paging.GetPaging(currentIndex, pageSize, total)
  250. resp := new(system.SysRoleListResp)
  251. resp.List = list
  252. resp.Paging = page
  253. br.Ret = 200
  254. br.Success = true
  255. br.Msg = "获取成功"
  256. br.Data = resp
  257. }
  258. // SysRoleMenusList
  259. // @Title 角色设置权限-菜单列表-CRM14.1弃用
  260. // @Description 角色设置权限-菜单列表
  261. // @Param RoleId query int true "角色Id"
  262. // @Success 200 {object} system.SysRoleListResp
  263. // @router /role/menu/list [get]
  264. func (this *SysRoleController) SysRoleMenusList() {
  265. br := new(models.BaseResponse).Init()
  266. defer func() {
  267. this.Data["json"] = br
  268. this.ServeJSON()
  269. }()
  270. roleId, err := this.GetInt("RoleId")
  271. if err != nil {
  272. br.Msg = "获取角色失败"
  273. br.ErrMsg = "获取角色失败,Err:" + err.Error()
  274. return
  275. }
  276. fmt.Println("roleId", roleId)
  277. list := make([]*system.RoleMenuList, 0)
  278. sysUser := this.SysUser
  279. if sysUser == nil {
  280. br.Msg = "请登录"
  281. br.ErrMsg = "请登录,SysUser Is Empty"
  282. return
  283. }
  284. list, err = system.GetRoleMenuList()
  285. if err != nil {
  286. br.Msg = "获取失败"
  287. br.ErrMsg = "获取失败,Err:" + err.Error()
  288. return
  289. }
  290. lenList := len(list)
  291. for i := 0; i < lenList; i++ {
  292. item := list[i]
  293. child, err := system.GetRoleMenuByParentId(item.MenuId)
  294. if err != nil {
  295. br.Msg = "获取失败"
  296. br.ErrMsg = "获取子菜单数据失败,Err:" + err.Error()
  297. return
  298. }
  299. list[i].Child = child
  300. checkList := make([]int, 0)
  301. if roleId > 0 {
  302. checkItem, err := system.GetCheckListRoleMenu(roleId, item.MenuId)
  303. if err != nil {
  304. br.Msg = "获取失败"
  305. br.ErrMsg = "获取选择数据失败,Err:" + err.Error()
  306. return
  307. }
  308. for _, v := range checkItem {
  309. checkList = append(checkList, v.MenuId)
  310. }
  311. }
  312. list[i].CheckList = checkList
  313. }
  314. resp := new(system.RoleMenuListResp)
  315. resp.List = list
  316. br.Ret = 200
  317. br.Success = true
  318. br.Msg = "获取成功"
  319. br.Data = resp
  320. }
  321. // SysRoleMenusAdd
  322. // @Title 角色设置权限-CRM14.1弃用
  323. // @Description 角色设置权限
  324. // @Param request body system.RoleMenusAddReq true "type json string"
  325. // @Success 200 {object} system.SysRoleListResp
  326. // @router /role/menu/add [post]
  327. func (this *SysRoleController) SysRoleMenusAdd() {
  328. br := new(models.BaseResponse).Init()
  329. defer func() {
  330. this.Data["json"] = br
  331. this.ServeJSON()
  332. }()
  333. var req system.RoleMenusAddReq
  334. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  335. if err != nil {
  336. br.Msg = "参数解析异常!"
  337. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  338. return
  339. }
  340. roleId := req.RoleId
  341. if roleId <= 0 {
  342. br.Msg = "参数错误"
  343. br.ErrMsg = "参数错误,RoleId 小于等于0 "
  344. return
  345. }
  346. if req.MenuIdStr == "" {
  347. br.Msg = "请选择菜单"
  348. br.ErrMsg = "请选择菜单,MenuIdStr IS Empty "
  349. return
  350. }
  351. sysUser := this.SysUser
  352. if sysUser == nil {
  353. br.Msg = "请登录"
  354. br.ErrMsg = "请登录,SysUser Is Empty"
  355. return
  356. }
  357. err = system.DeleteRoleMenuByRoleId(roleId)
  358. if err != nil {
  359. br.Msg = "设置失败"
  360. br.ErrMsg = "清空原有设置失败,Err:" + err.Error()
  361. return
  362. }
  363. menuArr := strings.Split(req.MenuIdStr, ",")
  364. for _, v := range menuArr {
  365. menuId, err := strconv.Atoi(v)
  366. if err != nil {
  367. br.Msg = "设置失败"
  368. br.ErrMsg = "menuId 解析失败,Err:" + err.Error()
  369. return
  370. }
  371. item := new(system.SysRoleMenu)
  372. item.RoleId = roleId
  373. item.MenuId = menuId
  374. _, err = system.AddSysRoleMenu(item)
  375. if err != nil {
  376. br.Msg = "设置失败"
  377. br.ErrMsg = "新增设置失败,Err:" + err.Error()
  378. return
  379. }
  380. }
  381. if req.MenuButtonIdStr != "" {
  382. err = system.DeleteSysRoleButton(roleId)
  383. if err != nil {
  384. br.Msg = "设置失败"
  385. br.ErrMsg = "删除已设置数据失败,Err:" + err.Error()
  386. return
  387. }
  388. buttonMap := make(map[string]string)
  389. buttonArr := strings.Split(req.MenuButtonIdStr, ",")
  390. for _, v := range buttonArr {
  391. if _, ok := buttonMap[v]; !ok {
  392. buttonId, err := strconv.Atoi(v)
  393. count, err := system.GetSysRoleButtonCount(roleId, buttonId)
  394. if err != nil {
  395. br.Msg = "判断设置失败存在失败"
  396. br.ErrMsg = "判断设置失败存在失败,Err:" + err.Error()
  397. return
  398. }
  399. if count <= 0 {
  400. button := new(system.SysRoleButton)
  401. button.RoleId = roleId
  402. button.MenuButtonId = buttonId
  403. button.CreateTime = time.Now()
  404. _, err = system.AddSysRoleButton(button)
  405. if err != nil {
  406. br.Msg = "设置失败"
  407. br.ErrMsg = "按钮权限设置失败,Err:" + err.Error()
  408. return
  409. }
  410. }
  411. }
  412. buttonMap[v] = v
  413. }
  414. } else {
  415. err = system.DeleteSysRoleButton(roleId)
  416. if err != nil {
  417. br.Msg = "设置失败"
  418. br.ErrMsg = "删除已设置数据失败,Err:" + err.Error()
  419. return
  420. }
  421. }
  422. br.Ret = 200
  423. br.Success = true
  424. br.IsAddLog = true
  425. br.Msg = "设置成功"
  426. }
  427. // @Title 获取所有角色
  428. // @Description 获取所有角色
  429. // @Success 200 {object} system.SysRoleListResp
  430. // @router /role/all [get]
  431. func (this *SysRoleController) AllSysRole() {
  432. br := new(models.BaseResponse).Init()
  433. defer func() {
  434. this.Data["json"] = br
  435. this.ServeJSON()
  436. }()
  437. sysUser := this.SysUser
  438. if sysUser == nil {
  439. br.Msg = "请登录"
  440. br.ErrMsg = "请登录,SysUser Is Empty"
  441. return
  442. }
  443. levelFlag := false
  444. roleLevel := this.GetString("RoleLevel")
  445. if roleLevel != "" {
  446. levelFlag = true
  447. }
  448. list, err := system.GetSysRoleAll(levelFlag)
  449. if err != nil {
  450. br.Msg = "获取失败"
  451. br.ErrMsg = "获取失败,Err:" + err.Error()
  452. return
  453. }
  454. resp := new(system.SysRoleAllResp)
  455. resp.List = list
  456. br.Ret = 200
  457. br.Success = true
  458. br.Msg = "获取成功"
  459. br.Data = resp
  460. }
  461. // SysRoleMenuAuthList
  462. // @Title 角色设置权限-菜单列表
  463. // @Description 角色设置权限-菜单列表
  464. // @Param RoleId query int true "角色Id"
  465. // @Success 200 {object} system.SysRoleListResp
  466. // @router /role/menu/auth_list [get]
  467. func (this *SysRoleController) SysRoleMenuAuthList() {
  468. br := new(models.BaseResponse).Init()
  469. defer func() {
  470. if br.ErrMsg == "" {
  471. br.IsSendEmail = false
  472. }
  473. this.Data["json"] = br
  474. this.ServeJSON()
  475. }()
  476. sysUser := this.SysUser
  477. if sysUser == nil {
  478. br.Msg = "请登录"
  479. br.ErrMsg = "请登录,SysUser Is Empty"
  480. return
  481. }
  482. resp := new(system.SysMenuListResp)
  483. resp.ChoiceList = make([]int, 0)
  484. resp.HalfChoiceList = make([]int, 0)
  485. resp.List = make([]*system.SysMenuItem, 0)
  486. // 角色勾选的权限
  487. roleId, _ := this.GetInt("RoleId", 0)
  488. if roleId > 0 {
  489. relates, e := system.GetSysRoleMenuByRoleId(roleId)
  490. if e != nil {
  491. br.Msg = "获取失败"
  492. br.ErrMsg = "获取角色关联菜单失败, Err: " + e.Error()
  493. return
  494. }
  495. for _, r := range relates {
  496. if r.Type == 1 {
  497. resp.HalfChoiceList = append(resp.HalfChoiceList, r.MenuId)
  498. continue
  499. }
  500. resp.ChoiceList = append(resp.ChoiceList, r.MenuId)
  501. }
  502. }
  503. sysRole, err := system.GetSysRoleById(roleId)
  504. if err == nil {
  505. if sysRole.RoleName == "admin" {
  506. br.Ret = 200
  507. br.Success = true
  508. br.Msg = "获取成功"
  509. return
  510. }
  511. }
  512. order := `sort ASC, create_time DESC, menu_id DESC`
  513. list, e := system.GetSysMenuItemsByCondition(` AND hidden = 0`, make([]interface{}, 0), []string{}, order)
  514. if e != nil {
  515. br.Msg = "获取失败"
  516. br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
  517. return
  518. }
  519. items := make([]*system.SysMenuItem, 0)
  520. for _, v := range list {
  521. t := &system.SysMenuItem{
  522. MenuId: v.MenuId,
  523. ParentId: v.ParentId,
  524. Name: v.Name,
  525. Sort: v.Sort,
  526. Path: v.Path,
  527. IconPath: v.IconPath,
  528. Component: v.Component,
  529. Hidden: v.Hidden,
  530. MenuType: v.MenuType,
  531. ButtonCode: v.ButtonCode,
  532. Children: make([]*system.SysMenuItem, 0),
  533. }
  534. items = append(items, t)
  535. }
  536. // 递归返回树形结构
  537. items = services.GetMenuTreeRecursive(items, 0)
  538. resp.List = items
  539. br.Data = resp
  540. br.Ret = 200
  541. br.Success = true
  542. br.Msg = "获取成功"
  543. }
  544. // SysRoleMenuAuthSave
  545. // @Title 角色设置权限-保存
  546. // @Description 角色设置权限-保存
  547. // @Param request body RoleMenusSaveReq true "type json string"
  548. // @Success 200 {object} system.SysRoleListResp
  549. // @router /role/menu/auth_save [post]
  550. func (this *SysRoleController) SysRoleMenuAuthSave() {
  551. br := new(models.BaseResponse).Init()
  552. defer func() {
  553. if br.ErrMsg == "" {
  554. br.IsSendEmail = false
  555. }
  556. this.Data["json"] = br
  557. this.ServeJSON()
  558. }()
  559. sysUser := this.SysUser
  560. if sysUser == nil {
  561. br.Msg = "请登录"
  562. br.ErrMsg = "请登录,SysUser Is Empty"
  563. br.Ret = 408
  564. return
  565. }
  566. type RoleMenusSaveReq struct {
  567. RoleId int `description:"角色ID"`
  568. MenuIds []int `description:"菜单IDs"`
  569. HalfMenuIds []int `description:"半选菜单IDs-仅供前端回显用的"`
  570. }
  571. var req RoleMenusSaveReq
  572. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  573. if err != nil {
  574. br.Msg = "参数解析异常!"
  575. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  576. return
  577. }
  578. if req.RoleId <= 0 {
  579. br.Msg = "参数有误"
  580. return
  581. }
  582. if len(req.MenuIds) == 0 {
  583. br.Msg = "请选择菜单"
  584. return
  585. }
  586. items := make([]*system.SysRoleMenu, 0)
  587. for _, v := range req.MenuIds {
  588. t := new(system.SysRoleMenu)
  589. t.MenuId = v
  590. t.RoleId = req.RoleId
  591. items = append(items, t)
  592. }
  593. for _, v := range req.HalfMenuIds {
  594. t := new(system.SysRoleMenu)
  595. t.MenuId = v
  596. t.Type = 1
  597. t.RoleId = req.RoleId
  598. items = append(items, t)
  599. }
  600. if e := system.CreateMultiSysRoleMenu(req.RoleId, items); e != nil {
  601. br.Msg = "保存失败"
  602. br.ErrMsg = "保存角色菜单权限失败, Err: " + e.Error()
  603. return
  604. }
  605. br.Ret = 200
  606. br.Success = true
  607. br.Msg = "设置成功"
  608. }
  609. // ButtonList
  610. // @Title 角色-按钮权限列表
  611. // @Description 角色-按钮权限列表
  612. // @Param RoleId query int true "角色Id"
  613. // @Success 200 {object} system.SysRoleListResp
  614. // @router /role/menu/buttons [get]
  615. func (this *SysRoleController) ButtonList() {
  616. br := new(models.BaseResponse).Init()
  617. defer func() {
  618. if br.ErrMsg == "" {
  619. br.IsSendEmail = false
  620. }
  621. this.Data["json"] = br
  622. this.ServeJSON()
  623. }()
  624. sysUser := this.SysUser
  625. if sysUser == nil {
  626. br.Msg = "请登录"
  627. br.ErrMsg = "请登录,SysUser Is Empty"
  628. br.Ret = 408
  629. return
  630. }
  631. roleId := sysUser.RoleId
  632. list, e := system.GetMenuButtonsByRoleId(roleId)
  633. if e != nil {
  634. br.Msg = "获取失败"
  635. br.ErrMsg = "获取角色按钮权限失败, Err: " + e.Error()
  636. return
  637. }
  638. buttonList := make([]*system.SysMenuButtonResp, 0)
  639. for _, v := range list {
  640. tmp := new(system.SysMenuButtonResp)
  641. tmp.MenuId = v.MenuId
  642. tmp.ParentId = v.ParentId
  643. tmp.MenuType = v.MenuType
  644. tmp.Name = v.Name
  645. tmp.ButtonCode = v.ButtonCode
  646. buttonList = append(buttonList, tmp)
  647. }
  648. br.Data = buttonList
  649. br.Ret = 200
  650. br.Success = true
  651. br.Msg = "获取成功"
  652. }
  653. // SystemConfig
  654. // @Title 系统配置列表
  655. // @Description 系统配置列表
  656. // @Success 200 {object} []system.BusinessConf
  657. // @router /config [get]
  658. func (this *SysRoleController) SystemConfig() {
  659. br := new(models.BaseResponse).Init()
  660. defer func() {
  661. if br.ErrMsg == "" {
  662. br.IsSendEmail = false
  663. }
  664. this.Data["json"] = br
  665. this.ServeJSON()
  666. }()
  667. sysUser := this.SysUser
  668. if sysUser == nil {
  669. br.Msg = "请登录"
  670. br.ErrMsg = "请登录,SysUser Is Empty"
  671. br.Ret = 408
  672. return
  673. }
  674. list := make([]system.BusinessConf, 0)
  675. // 获取基础配置, 若未配置则直接返回
  676. conf, e := models.GetBusinessConf()
  677. if e != nil {
  678. br.Msg = "获取失败"
  679. br.ErrMsg = "获取基础配置失败, Err: " + e.Error()
  680. return
  681. }
  682. list = append(list, system.BusinessConf{
  683. ConfKey: "ReportViewUrl",
  684. ConfVal: conf["ReportViewUrl"],
  685. }, system.BusinessConf{
  686. ConfKey: "ChartViewUrl",
  687. ConfVal: conf["ChartViewUrl"],
  688. }, system.BusinessConf{
  689. ConfKey: "LoginUrl",
  690. ConfVal: conf["LoginUrl"],
  691. })
  692. osc := system.BusinessConf{
  693. ConfKey: "ObjectStorageClient",
  694. ConfVal: utils.ObjectStorageClient,
  695. }
  696. if osc.ConfVal == "" {
  697. osc.ConfVal = "oss"
  698. }
  699. // ppt上传走后端配置
  700. pptUpload := system.BusinessConf{
  701. ConfKey: "PptUpdateApi",
  702. ConfVal: utils.PptUpdateApi,
  703. }
  704. list = append(list, osc, pptUpload)
  705. // 获取审批流设置
  706. //confKey := "approval_flow"
  707. //confTmp, e := company.GetConfigDetailByCode(confKey)
  708. //if e != nil {
  709. // br.Msg = "获取审批流配置失败"
  710. // br.ErrMsg = "获取审批流配置失败, Err: " + e.Error()
  711. // return
  712. //}
  713. //list = append(list, system.BusinessConf{
  714. // ConfKey: "ApprovalFlow",
  715. // ConfVal: confTmp.ConfigValue,
  716. //})
  717. br.Data = list
  718. br.Ret = 200
  719. br.Success = true
  720. br.Msg = "获取成功"
  721. }