sys_role.go 18 KB

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