sys_role.go 19 KB

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