sys_role.go 20 KB

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