sys_role.go 18 KB

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