english_auth.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. package english_report
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/company"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/models/system/request"
  9. "eta/eta_api/models/system/response"
  10. "eta/eta_api/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // EnglishAuthController 英文销售权限
  18. type EnglishAuthController struct {
  19. controllers.BaseAuthController
  20. }
  21. // List
  22. // @Title 权限列表
  23. // @Description 权限列表
  24. // @Success 200 {object} response.RoleAdminItemResp
  25. // @router /auth/list [get]
  26. func (this *EnglishAuthController) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. if br.ErrMsg == "" {
  30. br.IsSendEmail = false
  31. }
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. sysUser := this.SysUser
  36. if sysUser == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,SysUser is Empty"
  39. br.Ret = 408
  40. return
  41. }
  42. pageSize, _ := this.GetInt("PageSize")
  43. currentIndex, _ := this.GetInt("CurrentIndex")
  44. var startSize int
  45. if pageSize <= 0 {
  46. pageSize = utils.PageSize20
  47. }
  48. if currentIndex <= 0 {
  49. currentIndex = 1
  50. }
  51. startSize = paging.StartIndex(currentIndex, pageSize)
  52. // 获取英文角色配置
  53. confRoles := make([]company.ConfEnAuthRole, 0)
  54. authKey := company.ConfEnAuthRoleKey
  55. confAuth, e := company.GetConfigDetailByCode(authKey)
  56. if e != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取英文权限角色配置失败, Err: " + e.Error()
  59. return
  60. }
  61. if confAuth.ConfigValue == "" {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "英文权限角色配置为空"
  64. return
  65. }
  66. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &confRoles); e != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "英文权限角色配置有误"
  69. return
  70. }
  71. roleCodes := make([]string, 0)
  72. for _, v := range confRoles {
  73. roleCodes = append(roleCodes, v.RoleCode)
  74. }
  75. // 获取权限列表
  76. var cond string
  77. var pars []interface{}
  78. cond += ` AND r.role_type_code IN (` + utils.GetOrmInReplace(len(roleCodes)) + `)`
  79. pars = append(pars, roleCodes)
  80. total, adminList, err := system.GetEnglishAuthRoleAdminList(cond, pars, startSize, pageSize)
  81. if err != nil {
  82. br.Msg = "获取管理账号列表失败!"
  83. br.ErrMsg = "获取管理账号列表失败,Err:" + err.Error()
  84. return
  85. }
  86. // 查询分组信息
  87. departmentGroupNameMap := make(map[int]string)
  88. departmentNameMap := make(map[int]string)
  89. groupList, err := system.GetFullGroup()
  90. if err != nil {
  91. br.Msg = "查询分组信息失败!"
  92. br.ErrMsg = "查询分组信息失败,Err:" + err.Error()
  93. return
  94. }
  95. departmentList, err := system.GetDepartmentList()
  96. if err != nil {
  97. br.Msg = "查询部门信息失败!"
  98. br.ErrMsg = "查询部门信息失败,Err:" + err.Error()
  99. return
  100. }
  101. for _, d := range departmentList {
  102. departmentNameMap[d.DepartmentId] = d.DepartmentName
  103. }
  104. for _, g := range groupList {
  105. if g.ParentGroupName != "" {
  106. departmentGroupNameMap[g.GroupId] = g.DepartmentName + "/" + g.ParentGroupName + "/" + g.GroupName
  107. } else {
  108. departmentGroupNameMap[g.GroupId] = g.DepartmentName + "/" + g.GroupName
  109. }
  110. }
  111. // 查询角色信息
  112. roles, err := system.GetSysRoleAll(false)
  113. if err != nil {
  114. br.Msg = "查询角色信息失败!"
  115. br.ErrMsg = "查询角色信息失败,Err:" + err.Error()
  116. return
  117. }
  118. rolesNameMap := make(map[int]string)
  119. for _, v := range roles {
  120. rolesNameMap[v.RoleId] = v.RoleName
  121. }
  122. var list []*response.RoleAdminItemResp
  123. for _, v := range adminList {
  124. item := new(response.RoleAdminItemResp)
  125. item.SysRoleAdminId = v.SysRoleAdminId
  126. item.AdminId = v.AdminId
  127. item.Mobile = v.Mobile
  128. item.RealName = v.RealName
  129. item.Enabled = v.Enabled
  130. if v.GroupId > 0 {
  131. if departmentGroup, ok := departmentGroupNameMap[v.GroupId]; ok {
  132. item.DepartmentGroup = departmentGroup
  133. }
  134. } else {
  135. if departmentName, ok := departmentNameMap[v.DepartmentId]; ok {
  136. item.DepartmentGroup = departmentName
  137. }
  138. }
  139. // 整理角色名称
  140. item.RoleId = v.RoleId
  141. if rolesName, ok := rolesNameMap[v.RoleId]; ok {
  142. item.RoleName = rolesName
  143. }
  144. // 整理标签
  145. if v.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  146. item.LabelVal = 1
  147. } else if v.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  148. v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  149. item.LabelVal = 2
  150. } else {
  151. if v.Authority == 1 {
  152. item.LabelVal = 3
  153. } else if v.Authority == 2 && v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  154. item.LabelVal = 4
  155. } else if v.Authority == 2 && v.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  156. item.LabelVal = 5
  157. } else if v.Authority == 4 {
  158. item.LabelVal = 4
  159. }
  160. }
  161. list = append(list, item)
  162. }
  163. page := paging.GetPaging(currentIndex, pageSize, total)
  164. resp := response.RoleAdminListResp{
  165. List: list,
  166. Paging: page,
  167. }
  168. br.Ret = 200
  169. br.Success = true
  170. br.Msg = "获取成功"
  171. br.Data = resp
  172. }
  173. // BatchAdd
  174. // @Title 批量新增权限
  175. // @Description 批量新增权限
  176. // @Param request body request.AddEnglishAuthRoleAdminReq true "type json string"
  177. // @Success Ret=200 操作成功
  178. // @router /auth/batch_add [post]
  179. func (this *EnglishAuthController) BatchAdd() {
  180. br := new(models.BaseResponse).Init()
  181. defer func() {
  182. if br.ErrMsg == "" {
  183. br.IsSendEmail = false
  184. }
  185. this.Data["json"] = br
  186. this.ServeJSON()
  187. }()
  188. sysUser := this.SysUser
  189. if sysUser == nil {
  190. br.Msg = "请登录"
  191. br.ErrMsg = "请登录,SysUser Is Empty"
  192. br.Ret = 408
  193. return
  194. }
  195. if utils.BusinessCode != utils.BusinessCodeRelease {
  196. br.Ret = 200
  197. br.Success = true
  198. br.Msg = "操作成功"
  199. return
  200. }
  201. var req request.AddEnglishAuthRoleAdminReq
  202. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  203. if err != nil {
  204. br.Msg = "参数解析异常!"
  205. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  206. return
  207. }
  208. if req.AdminIds == "" {
  209. br.Msg = "请选择用户"
  210. return
  211. }
  212. // 校验参数
  213. adminIdArr := strings.Split(req.AdminIds, ",")
  214. if len(adminIdArr) == 0 {
  215. br.Msg = "请选择用户"
  216. return
  217. }
  218. adminIds := make([]int, 0)
  219. for i := range adminIdArr {
  220. v, e := strconv.Atoi(adminIdArr[i])
  221. if e != nil {
  222. br.Msg = "请选择用户"
  223. br.ErrMsg = "参数解析异常, Err:" + e.Error()
  224. return
  225. }
  226. adminIds = append(adminIds, v)
  227. }
  228. if len(adminIds) == 0 {
  229. br.Msg = "请选择有效用户"
  230. return
  231. }
  232. // 获取英文角色配置
  233. confRoles := make([]company.ConfEnAuthRole, 0)
  234. authKey := company.ConfEnAuthRoleKey
  235. confAuth, e := company.GetConfigDetailByCode(authKey)
  236. if e != nil {
  237. br.Msg = "获取失败"
  238. br.ErrMsg = "获取英文权限角色配置失败, Err: " + e.Error()
  239. return
  240. }
  241. if confAuth.ConfigValue == "" {
  242. br.Msg = "获取失败"
  243. br.ErrMsg = "英文权限角色配置为空"
  244. return
  245. }
  246. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &confRoles); e != nil {
  247. br.Msg = "获取失败"
  248. br.ErrMsg = "英文权限角色配置有误"
  249. return
  250. }
  251. roleCodes := make([]string, 0)
  252. for _, v := range confRoles {
  253. roleCodes = append(roleCodes, v.RoleCode)
  254. }
  255. // 获取英文权限角色
  256. roleItems, e := system.GetEnglishAuthRoleItems(roleCodes)
  257. if e != nil {
  258. br.Msg = "新增失败"
  259. br.ErrMsg = "获取英文权限角色IDs失败, Err: " + e.Error()
  260. return
  261. }
  262. if len(roleItems) == 0 || len(roleItems) != len(roleCodes) {
  263. br.Msg = "英文权限角色信息有误"
  264. return
  265. }
  266. // 查询已绑定的管理员账号
  267. var noBindIds []int
  268. bindMap := make(map[int]bool)
  269. hasBindList, e := system.CheckEnglishAuthRoleAdminByAdminIds(adminIds, roleCodes)
  270. if e != nil {
  271. br.Msg = "新增失败"
  272. br.ErrMsg = "查询已绑定英文权限的账号失败, Err:" + e.Error()
  273. return
  274. }
  275. for i := range hasBindList {
  276. bindMap[hasBindList[i].AdminId] = true
  277. }
  278. for i := range adminIds {
  279. if !bindMap[adminIds[i]] {
  280. noBindIds = append(noBindIds, adminIds[i])
  281. }
  282. }
  283. if len(noBindIds) == 0 {
  284. br.Msg = "账号已绑定,无需重复绑定"
  285. br.ErrMsg = "账号已绑定,无需重复绑定"
  286. return
  287. }
  288. // 获取未绑定的用户列表
  289. unboundAdmins := make([]*system.Admin, 0)
  290. {
  291. cond := fmt.Sprintf(` AND admin_id IN (%s)`, utils.GetOrmInReplace(len(noBindIds)))
  292. pars := make([]interface{}, 0)
  293. pars = append(pars, noBindIds)
  294. admins, e := system.GetSysAdminList(cond, pars, []string{}, "")
  295. if e != nil {
  296. br.Msg = "操作失败"
  297. br.ErrMsg = "获取未绑定的用户列表失败, Err: " + e.Error()
  298. return
  299. }
  300. unboundAdmins = admins
  301. }
  302. // 新增绑定关系
  303. var syncRoles []system.SyncAdminEnRole
  304. nowTime := time.Now().Local()
  305. newBounds := make([]*system.SysRoleAdmin, 0)
  306. for _, a := range unboundAdmins {
  307. var d system.SyncAdminEnRole
  308. d.AdminName = a.AdminName
  309. for r := range roleItems {
  310. v := &system.SysRoleAdmin{
  311. AdminId: a.AdminId,
  312. RoleId: roleItems[r].RoleId,
  313. CreateTime: nowTime,
  314. }
  315. newBounds = append(newBounds, v)
  316. d.RoleCodes = append(d.RoleCodes, roleItems[r].RoleTypeCode)
  317. }
  318. syncRoles = append(syncRoles, d)
  319. }
  320. if e = system.AddRoleAdminBatch(newBounds); e != nil {
  321. br.Msg = "新增失败"
  322. br.ErrMsg = "新增英文权限绑定关系失败, Err:" + e.Error()
  323. return
  324. }
  325. // 写入同步缓存
  326. for _, v := range syncRoles {
  327. _ = utils.Rc.LPush(utils.CACHE_SYNC_USER_EN_ROLE, v)
  328. }
  329. br.Ret = 200
  330. br.Success = true
  331. br.Msg = "操作成功"
  332. }
  333. // Detail
  334. // @Title 权限详情
  335. // @Description 权限详情
  336. // @Param AdminId query string int "管理员ID"
  337. // @Success 200 {object} response.EnglishAuthRoleDetailResp
  338. // @router /auth/detail [get]
  339. func (this *EnglishAuthController) Detail() {
  340. br := new(models.BaseResponse).Init()
  341. defer func() {
  342. if br.ErrMsg == "" {
  343. br.IsSendEmail = false
  344. }
  345. this.Data["json"] = br
  346. this.ServeJSON()
  347. }()
  348. sysUser := this.SysUser
  349. if sysUser == nil {
  350. br.Msg = "请登录"
  351. br.ErrMsg = "请登录,SysUser is Empty"
  352. br.Ret = 408
  353. return
  354. }
  355. adminId, _ := this.GetInt("AdminId", 0)
  356. if adminId <= 0 {
  357. br.Msg = "参数有误"
  358. return
  359. }
  360. // 获取英文角色配置
  361. confRoles := make([]company.ConfEnAuthRole, 0)
  362. authKey := company.ConfEnAuthRoleKey
  363. confAuth, e := company.GetConfigDetailByCode(authKey)
  364. if e != nil {
  365. br.Msg = "获取失败"
  366. br.ErrMsg = "获取英文权限角色配置失败, Err: " + e.Error()
  367. return
  368. }
  369. if confAuth.ConfigValue == "" {
  370. br.Msg = "获取失败"
  371. br.ErrMsg = "英文权限角色配置为空"
  372. return
  373. }
  374. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &confRoles); e != nil {
  375. br.Msg = "获取失败"
  376. br.ErrMsg = "英文权限角色配置有误"
  377. return
  378. }
  379. roleCodes := make([]string, 0)
  380. for _, v := range confRoles {
  381. roleCodes = append(roleCodes, v.RoleCode)
  382. }
  383. resp := make([]*response.EnglishAuthRoleDetailResp, 0)
  384. authList, e := system.GetAdminEnglishAuthRoleDetail(adminId, roleCodes)
  385. if e != nil {
  386. br.Msg = "获取失败"
  387. br.ErrMsg = "获取管理员英文权限详情失败, Err:" + e.Error()
  388. return
  389. }
  390. authMap := make(map[string]bool, 0)
  391. for i := range authList {
  392. authMap[authList[i].RoleTypeCode] = true
  393. }
  394. for _, v := range confRoles {
  395. resp = append(resp, &response.EnglishAuthRoleDetailResp{
  396. AdminId: adminId,
  397. AuthName: v.RoleName,
  398. RoleTypeCode: v.RoleCode,
  399. AuthOk: authMap[v.RoleCode],
  400. })
  401. }
  402. br.Ret = 200
  403. br.Success = true
  404. br.Msg = "获取成功"
  405. br.Data = resp
  406. }
  407. // Edit
  408. // @Title 编辑权限
  409. // @Description 编辑权限
  410. // @Param request body request.EditEnglishAuthRoleAdminReq true "type json string"
  411. // @Success Ret=200 操作成功
  412. // @router /auth/edit [post]
  413. func (this *EnglishAuthController) Edit() {
  414. br := new(models.BaseResponse).Init()
  415. defer func() {
  416. if br.ErrMsg == "" {
  417. br.IsSendEmail = false
  418. }
  419. this.Data["json"] = br
  420. this.ServeJSON()
  421. }()
  422. sysUser := this.SysUser
  423. if sysUser == nil {
  424. br.Msg = "请登录"
  425. br.ErrMsg = "请登录,SysUser Is Empty"
  426. br.Ret = 408
  427. return
  428. }
  429. if utils.BusinessCode != utils.BusinessCodeRelease {
  430. br.Ret = 200
  431. br.Success = true
  432. br.Msg = "操作成功"
  433. return
  434. }
  435. var req request.EditEnglishAuthRoleAdminReq
  436. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  437. if err != nil {
  438. br.Msg = "参数解析异常!"
  439. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  440. return
  441. }
  442. if req.AdminId <= 0 {
  443. br.Msg = "管理员ID有误"
  444. return
  445. }
  446. if req.RoleTypeCodes == "" {
  447. br.Msg = "请选择权限"
  448. return
  449. }
  450. roleArr := strings.Split(req.RoleTypeCodes, ",")
  451. if len(roleArr) == 0 {
  452. br.Msg = "请选择权限"
  453. return
  454. }
  455. // 若用户不存在, 则忽略
  456. admin, e := system.GetSysAdminById(req.AdminId)
  457. if e != nil {
  458. br.Ret = 200
  459. br.Success = true
  460. br.Msg = "操作成功"
  461. return
  462. }
  463. // 获取英文角色配置
  464. confRoles := make([]company.ConfEnAuthRole, 0)
  465. authKey := company.ConfEnAuthRoleKey
  466. confAuth, e := company.GetConfigDetailByCode(authKey)
  467. if e != nil {
  468. br.Msg = "获取失败"
  469. br.ErrMsg = "获取英文权限角色配置失败, Err: " + e.Error()
  470. return
  471. }
  472. if confAuth.ConfigValue == "" {
  473. br.Msg = "获取失败"
  474. br.ErrMsg = "英文权限角色配置为空"
  475. return
  476. }
  477. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &confRoles); e != nil {
  478. br.Msg = "获取失败"
  479. br.ErrMsg = "英文权限角色配置有误"
  480. return
  481. }
  482. roleCodes := make([]string, 0)
  483. for _, v := range confRoles {
  484. roleCodes = append(roleCodes, v.RoleCode)
  485. }
  486. for i := range roleArr {
  487. if !utils.InArrayByStr(roleCodes, roleArr[i]) {
  488. br.Msg = "权限信息有误"
  489. return
  490. }
  491. }
  492. // 获取英文权限角色IDs
  493. roleIds, e := system.GetEnglishAuthRoleIds(roleCodes)
  494. if e != nil {
  495. br.Msg = "新增失败"
  496. br.ErrMsg = "获取英文权限角色IDs失败, Err: " + e.Error()
  497. return
  498. }
  499. if len(roleIds) == 0 {
  500. br.Msg = "英文权限角色信息有误"
  501. return
  502. }
  503. // 获取编辑的权限角色IDs
  504. editRoles, e := system.GetEnglishAuthRoleItems(roleArr)
  505. if e != nil {
  506. br.Msg = "新增失败"
  507. br.ErrMsg = "获取编辑英文权限角色IDs失败, Err: " + e.Error()
  508. return
  509. }
  510. if len(editRoles) != len(roleArr) {
  511. br.Msg = "权限角色信息有误"
  512. return
  513. }
  514. // 同步缓存
  515. var syncData system.SyncAdminEnRole
  516. syncData.AdminName = admin.AdminName
  517. // 编辑权限
  518. nowTime := time.Now().Local()
  519. newBinds := make([]*system.SysRoleAdmin, 0)
  520. for _, r := range editRoles {
  521. v := &system.SysRoleAdmin{
  522. AdminId: req.AdminId,
  523. RoleId: r.RoleId,
  524. CreateTime: nowTime,
  525. }
  526. newBinds = append(newBinds, v)
  527. syncData.RoleCodes = append(syncData.RoleCodes, r.RoleTypeCode)
  528. }
  529. if e = system.EditEnglishAuthRoleAdmin(req.AdminId, roleIds, newBinds); e != nil {
  530. br.Msg = "编辑失败"
  531. br.ErrMsg = "编辑管理员英文权限绑定关系失败, Err:" + e.Error()
  532. return
  533. }
  534. // 写入同步缓存
  535. _ = utils.Rc.LPush(utils.CACHE_SYNC_USER_EN_ROLE, syncData)
  536. br.Ret = 200
  537. br.Success = true
  538. br.Msg = "操作成功"
  539. }
  540. // Del
  541. // @Title 删除权限
  542. // @Description 删除权限
  543. // @Param request body request.DelEnglishAuthRoleAdminReq true "type json string"
  544. // @Success Ret=200 操作成功
  545. // @router /auth/del [post]
  546. func (this *EnglishAuthController) Del() {
  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. if utils.BusinessCode != utils.BusinessCodeRelease {
  563. br.Ret = 200
  564. br.Success = true
  565. br.Msg = "操作成功"
  566. return
  567. }
  568. var req request.DelEnglishAuthRoleAdminReq
  569. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  570. if err != nil {
  571. br.Msg = "参数解析异常!"
  572. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  573. return
  574. }
  575. if req.AdminId <= 0 {
  576. br.Msg = "参数有误"
  577. return
  578. }
  579. // 若用户不存在, 则忽略
  580. admin, e := system.GetSysAdminById(req.AdminId)
  581. if e != nil {
  582. br.Ret = 200
  583. br.Success = true
  584. br.Msg = "操作成功"
  585. return
  586. }
  587. // 获取英文角色配置
  588. confRoles := make([]company.ConfEnAuthRole, 0)
  589. authKey := company.ConfEnAuthRoleKey
  590. confAuth, e := company.GetConfigDetailByCode(authKey)
  591. if e != nil {
  592. br.Msg = "获取失败"
  593. br.ErrMsg = "获取英文权限角色配置失败, Err: " + e.Error()
  594. return
  595. }
  596. if confAuth.ConfigValue == "" {
  597. br.Msg = "获取失败"
  598. br.ErrMsg = "英文权限角色配置为空"
  599. return
  600. }
  601. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &confRoles); e != nil {
  602. br.Msg = "获取失败"
  603. br.ErrMsg = "英文权限角色配置有误"
  604. return
  605. }
  606. roleCodes := make([]string, 0)
  607. for _, v := range confRoles {
  608. roleCodes = append(roleCodes, v.RoleCode)
  609. }
  610. // 获取英文权限角色IDs
  611. roleIds, e := system.GetEnglishAuthRoleIds(roleCodes)
  612. if e != nil {
  613. br.Msg = "删除失败"
  614. br.ErrMsg = "获取英文权限角色IDs失败, Err: " + e.Error()
  615. return
  616. }
  617. if len(roleIds) == 0 {
  618. br.Msg = "删除失败"
  619. br.ErrMsg = "解除英文权限角色绑定关系失败, 角色信息有误"
  620. return
  621. }
  622. // 解除绑定关系
  623. if e = system.DeleteRoleAdminByAdminIdAndRoleIds(req.AdminId, roleIds); e != nil {
  624. br.Msg = "删除失败"
  625. br.ErrMsg = "解除英文权限角色绑定关系失败, Err:" + e.Error()
  626. return
  627. }
  628. // 写入同步缓存
  629. var syncData system.SyncAdminEnRole
  630. syncData.AdminName = admin.AdminName
  631. _ = utils.Rc.LPush(utils.CACHE_SYNC_USER_EN_ROLE, syncData)
  632. br.Ret = 200
  633. br.Success = true
  634. br.Msg = "操作成功"
  635. }