sys_role.go 18 KB

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