广告平台(站长使用)
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

hdl_role.go 19 KiB

3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
1ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
1ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. package hdl
  2. import (
  3. "applet/app/e"
  4. "applet/app/enum"
  5. "applet/app/lib/validate"
  6. "applet/app/md"
  7. "applet/app/svc"
  8. "applet/app/utils"
  9. db "code.fnuoos.com/zhimeng/model.git/src"
  10. "code.fnuoos.com/zhimeng/model.git/src/implement"
  11. "code.fnuoos.com/zhimeng/model.git/src/model"
  12. "github.com/gin-gonic/gin"
  13. "time"
  14. )
  15. // PermissionGroupList
  16. // @Summary 权限组列表
  17. // @Tags 权限管理
  18. // @Description 权限管理-权限组列表
  19. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  20. // @Accept json
  21. // @Produce json
  22. // @param adm_id query string true "管理员id"
  23. // @Success 200 {string} "具体看返回内容"
  24. // @Failure 400 {object} md.Response "具体错误"
  25. // @Router /role/permissionGroupList [GET]
  26. func PermissionGroupList(c *gin.Context) {
  27. roleId := c.DefaultQuery("role_id", "")
  28. engine := db.DBs[svc.GetMasterId(c)]
  29. qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine)
  30. groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroup()
  31. if err != nil {
  32. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  33. return
  34. }
  35. roleDb := implement.NewRoleDb(engine, utils.StrToInt(roleId))
  36. list, _, err := roleDb.FindPermissionGroupByRole(utils.StrToInt(roleId))
  37. if err != nil {
  38. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  39. return
  40. }
  41. var isHasPermissionGroupId []string
  42. for _, v := range list {
  43. isHasPermissionGroupId = append(isHasPermissionGroupId, utils.IntToStr(v.PermissionGroup.Id))
  44. }
  45. var tempRespMap = map[string]*md.PermissionGroupListResp{}
  46. var tempRespMapKeys []string
  47. for _, v := range *groupList {
  48. isCheck := false
  49. if utils.InArr(utils.IntToStr(v.Id), isHasPermissionGroupId) {
  50. isCheck = true
  51. }
  52. tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
  53. Id: v.Id,
  54. Name: v.Name,
  55. Key: v.Key,
  56. State: v.State,
  57. ParentId: v.ParentId,
  58. CreateAt: v.CreateAt,
  59. UpdateAt: v.UpdateAt,
  60. IsCheck: isCheck,
  61. }
  62. tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
  63. }
  64. for _, v := range tempRespMap {
  65. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
  66. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  67. }
  68. }
  69. for _, v := range tempRespMap {
  70. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
  71. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  72. }
  73. }
  74. var resp []*md.PermissionGroupListResp
  75. for _, v := range tempRespMapKeys {
  76. if tempRespMap[v].ParentId == 0 {
  77. resp = append(resp, tempRespMap[v])
  78. }
  79. }
  80. e.OutSuc(c, map[string]interface{}{
  81. "list": resp,
  82. "state": []map[string]interface{}{
  83. {
  84. "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
  85. "value": enum.PermissionGroupStateForNormal,
  86. },
  87. {
  88. "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
  89. "value": enum.PermissionGroupStateForDiscard,
  90. },
  91. },
  92. }, nil)
  93. return
  94. }
  95. // RoleList
  96. // @Summary 角色列表
  97. // @Tags 权限管理
  98. // @Description 权限管理-角色列表
  99. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  100. // @Accept json
  101. // @Produce json
  102. // @Success 200 {string} "具体看返回内容"
  103. // @Failure 400 {object} md.Response "具体错误"
  104. // @Router /api/role/roleList [GET]
  105. func RoleList(c *gin.Context) {
  106. engine := db.DBs[svc.GetMasterId(c)]
  107. roleDb := implement.NewRoleDb(engine, 0)
  108. roleList, err := roleDb.FindRole()
  109. if err != nil {
  110. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  111. return
  112. }
  113. adminRoleDb := implement.NewAdminRoleDb(engine)
  114. adminDb := implement.NewAdminDb(engine)
  115. var result []*md.RoleListResp
  116. for _, v := range *roleList {
  117. var temp md.RoleListResp
  118. temp.Data = v
  119. adminRoles, err1 := adminRoleDb.FindAdminRoleByRoleId(v.Id)
  120. if err1 != nil {
  121. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  122. return
  123. }
  124. for _, adminRole := range *adminRoles {
  125. admin, err2 := adminDb.GetAdmin(adminRole.AdmId)
  126. if err2 != nil {
  127. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  128. return
  129. }
  130. temp.AdminList = append(temp.AdminList, struct {
  131. Name string `json:"name"`
  132. }{
  133. Name: admin.Username,
  134. })
  135. }
  136. result = append(result, &temp)
  137. }
  138. e.OutSuc(c, map[string]interface{}{
  139. "list": result,
  140. "state": []map[string]interface{}{
  141. {
  142. "name": enum.RoleState(enum.RoleStateForNormal).String(),
  143. "value": enum.RoleStateForNormal,
  144. },
  145. {
  146. "name": enum.RoleState(enum.RoleStateForFreeze).String(),
  147. "value": enum.RoleStateForFreeze,
  148. },
  149. },
  150. }, nil)
  151. return
  152. }
  153. // AddRole
  154. // @Summary 添加角色
  155. // @Tags 权限管理
  156. // @Description 权限管理-添加角色
  157. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  158. // @Accept json
  159. // @Produce json
  160. // @Param args body md.AddRoleReq true "请求参数"
  161. // @Success 200 {string} "success"
  162. // @Failure 400 {object} md.Response "具体错误"
  163. // @Router /api/role/addRole [POST]
  164. func AddRole(c *gin.Context) {
  165. var req md.AddRoleReq
  166. err := c.ShouldBindJSON(&req)
  167. if err != nil {
  168. err = validate.HandleValidateErr(err)
  169. err1 := err.(e.E)
  170. e.OutErr(c, err1.Code, err1.Error())
  171. return
  172. }
  173. engine := db.DBs[svc.GetMasterId(c)]
  174. roleDb := implement.NewRoleDb(engine, 0)
  175. now := time.Now()
  176. _, err = roleDb.RoleInsert(&model.Role{
  177. Name: req.Name,
  178. State: enum.RoleStateForNormal,
  179. Memo: req.Memo,
  180. Logo: req.Logo,
  181. Label: req.Label,
  182. CreateAt: now.Format("2006-01-02 15:04:05"),
  183. UpdateAt: now.Format("2006-01-02 15:04:05"),
  184. })
  185. if err != nil {
  186. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  187. return
  188. }
  189. e.OutSuc(c, "success", nil)
  190. return
  191. }
  192. // UpdateRole
  193. // @Summary 修改角色
  194. // @Tags 权限管理
  195. // @Description 权限管理-修改角色
  196. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  197. // @Accept json
  198. // @Produce json
  199. // @Param args body md.UpdateRoleReq true "请求参数"
  200. // @Success 200 {string} "success"
  201. // @Failure 400 {object} md.Response "具体错误"
  202. // @Router /api/role/updateRole [POST]
  203. func UpdateRole(c *gin.Context) {
  204. var req md.UpdateRoleReq
  205. err := c.ShouldBindJSON(&req)
  206. if err != nil {
  207. err = validate.HandleValidateErr(err)
  208. err1 := err.(e.E)
  209. e.OutErr(c, err1.Code, err1.Error())
  210. return
  211. }
  212. engine := db.DBs[svc.GetMasterId(c)]
  213. roleDb := implement.NewRoleDb(engine, req.RoleId)
  214. role, err := roleDb.GetRole()
  215. if err != nil {
  216. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  217. return
  218. }
  219. if role == nil {
  220. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  221. return
  222. }
  223. role.Name = req.Name
  224. role.Memo = req.Memo
  225. role.Logo = req.Logo
  226. role.Label = req.Label
  227. _, err = roleDb.UpdateRole(role, "name", "memo")
  228. if err != nil {
  229. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  230. return
  231. }
  232. e.OutSuc(c, "success", nil)
  233. return
  234. }
  235. // RoleBindPermissionGroup
  236. // @Summary 角色绑定权限组
  237. // @Tags 权限管理
  238. // @Description 权限管理-角色绑定权限组
  239. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  240. // @Accept json
  241. // @Produce json
  242. // @Param args body md.RoleBindPermissionGroupReq true "请求参数"
  243. // @Success 200 {string} "success"
  244. // @Failure 400 {object} md.Response "具体错误"
  245. // @Router /api/role/roleBindPermissionGroup [POST]
  246. func RoleBindPermissionGroup(c *gin.Context) {
  247. var req md.RoleBindPermissionGroupReq
  248. err := c.ShouldBindJSON(&req)
  249. if err != nil {
  250. err = validate.HandleValidateErr(err)
  251. err1 := err.(e.E)
  252. e.OutErr(c, err1.Code, err1.Error())
  253. return
  254. }
  255. err = svc.RoleBindPermissionGroup(c, req)
  256. if err != nil {
  257. e.OutErr(c, e.ERR, err.Error())
  258. return
  259. }
  260. e.OutSuc(c, "success", nil)
  261. return
  262. }
  263. // UpdateRoleState
  264. // @Summary 修改角色状态
  265. // @Tags 权限管理
  266. // @Description 权限管理-修改角色状态
  267. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  268. // @Accept json
  269. // @Produce json
  270. // @Param args body md.UpdateRoleStateReq true "请求参数"
  271. // @Success 200 {string} "success"
  272. // @Failure 400 {object} md.Response "具体错误"
  273. // @Router /api/role/updateRoleState [POST]
  274. func UpdateRoleState(c *gin.Context) {
  275. var req md.UpdateRoleStateReq
  276. err := c.ShouldBindJSON(&req)
  277. if err != nil {
  278. err = validate.HandleValidateErr(err)
  279. err1 := err.(e.E)
  280. e.OutErr(c, err1.Code, err1.Error())
  281. return
  282. }
  283. engine := db.DBs[svc.GetMasterId(c)]
  284. roleDb := implement.NewRoleDb(engine, req.RoleId)
  285. role, err := roleDb.GetRole()
  286. if err != nil {
  287. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  288. return
  289. }
  290. if role == nil {
  291. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  292. return
  293. }
  294. role.State = req.State
  295. _, err = roleDb.UpdateRole(role, "state")
  296. if err != nil {
  297. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  298. return
  299. }
  300. e.OutSuc(c, "success", nil)
  301. return
  302. }
  303. // DeleteRole
  304. // @Summary 删除角色
  305. // @Tags 权限管理
  306. // @Description 权限管理-删除角色
  307. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  308. // @Accept json
  309. // @Produce json
  310. // @Param args body md.UpdateRoleStateReq true "请求参数"
  311. // @Success 200 {string} "success"
  312. // @Failure 400 {object} md.Response "具体错误"
  313. // @Router /api/role/deleteRole/{$id} [DELETE]
  314. func DeleteRole(c *gin.Context) {
  315. id := c.Param("id")
  316. engine := db.DBs[svc.GetMasterId(c)]
  317. roleDb := implement.NewRoleDb(engine, utils.StrToInt(id))
  318. role, err := roleDb.GetRole()
  319. if err != nil {
  320. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  321. return
  322. }
  323. if role == nil {
  324. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  325. return
  326. }
  327. err = svc.DeleteRole(c, utils.StrToInt(id))
  328. if err != nil {
  329. e.OutErr(c, e.ERR, err.Error())
  330. return
  331. }
  332. e.OutSuc(c, "success", nil)
  333. return
  334. }
  335. // AdminList
  336. // @Summary 管理员列表
  337. // @Tags 权限管理
  338. // @Description 权限管理-管理员列表
  339. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  340. // @Accept json
  341. // @Produce json
  342. // @Param args body md.AdminListReq true "请求参数"
  343. // @Success 200 {string} "具体看返回内容"
  344. // @Failure 400 {object} md.Response "具体错误"
  345. // @Router /api/role/adminList [POST]
  346. func AdminList(c *gin.Context) {
  347. var req md.AdminListReq
  348. err := c.ShouldBindJSON(&req)
  349. if err != nil {
  350. err = validate.HandleValidateErr(err)
  351. err1 := err.(e.E)
  352. e.OutErr(c, err1.Code, err1.Error())
  353. return
  354. }
  355. if req.Limit == 0 {
  356. req.Limit = 10
  357. }
  358. if req.Page == 0 {
  359. req.Page = 10
  360. }
  361. engine := db.DBs[svc.GetMasterId(c)]
  362. adminDb := implement.NewAdminDb(engine)
  363. adminList, total, err := adminDb.FindAdmin(req.UserName, req.State, req.Page, req.Limit)
  364. if err != nil {
  365. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  366. return
  367. }
  368. var result []md.AdminListResp
  369. for _, v := range adminList {
  370. permissionGroupList, _, err1 := adminDb.FindAdminRolePermissionGroup(v.AdmId)
  371. if err1 != nil {
  372. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  373. return
  374. }
  375. var roleList []string
  376. for _, v1 := range permissionGroupList {
  377. roleList = append(roleList, v1.Role.Name)
  378. }
  379. result = append(result, md.AdminListResp{
  380. AdmId: v.AdmId,
  381. Username: v.Username,
  382. State: v.State,
  383. IsSuperAdministrator: v.IsSuperAdministrator,
  384. Memo: v.Memo,
  385. CreateAt: v.CreateAt,
  386. UpdateAt: v.UpdateAt,
  387. RoleList: roleList,
  388. })
  389. }
  390. e.OutSuc(c, map[string]interface{}{
  391. "list": result,
  392. "total": total,
  393. "state": []map[string]interface{}{
  394. {
  395. "name": enum.RoleState(enum.RoleStateForNormal).String(),
  396. "value": enum.RoleStateForNormal,
  397. },
  398. {
  399. "name": enum.RoleState(enum.RoleStateForFreeze).String(),
  400. "value": enum.RoleStateForFreeze,
  401. },
  402. },
  403. }, nil)
  404. return
  405. }
  406. // UpdateAdminState
  407. // @Summary 修改管理员状态
  408. // @Tags 权限管理
  409. // @Description 权限管理-修改管理员状态
  410. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  411. // @Accept json
  412. // @Produce json
  413. // @Param args body md.UpdateAdminStateReq true "请求参数"
  414. // @Success 200 {string} "success"
  415. // @Failure 400 {object} md.Response "具体错误"
  416. // @Router /api/role/updateAdminState [POST]
  417. func UpdateAdminState(c *gin.Context) {
  418. var req md.UpdateAdminStateReq
  419. err := c.ShouldBindJSON(&req)
  420. if err != nil {
  421. err = validate.HandleValidateErr(err)
  422. err1 := err.(e.E)
  423. e.OutErr(c, err1.Code, err1.Error())
  424. return
  425. }
  426. engine := db.DBs[svc.GetMasterId(c)]
  427. admDb := implement.NewAdminDb(engine)
  428. admin, err := admDb.GetAdmin(req.AdmId)
  429. if err != nil {
  430. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  431. return
  432. }
  433. if admin == nil {
  434. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  435. return
  436. }
  437. admin.State = req.State
  438. _, err = admDb.UpdateAdmin(admin, "state")
  439. if err != nil {
  440. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  441. return
  442. }
  443. e.OutSuc(c, "success", nil)
  444. return
  445. }
  446. // UpdateAdmin
  447. // @Summary 修改管理员信息
  448. // @Tags 权限管理
  449. // @Description 权限管理-修改管理员信息
  450. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  451. // @Accept json
  452. // @Produce json
  453. // @Param args body md.UpdateAdminReq true "请求参数"
  454. // @Success 200 {string} "success"
  455. // @Failure 400 {object} md.Response "具体错误"
  456. // @Router /api/role/updateAdmin [POST]
  457. func UpdateAdmin(c *gin.Context) {
  458. var req md.UpdateAdminReq
  459. err := c.ShouldBindJSON(&req)
  460. if err != nil {
  461. err = validate.HandleValidateErr(err)
  462. err1 := err.(e.E)
  463. e.OutErr(c, err1.Code, err1.Error())
  464. return
  465. }
  466. engine := db.DBs[svc.GetMasterId(c)]
  467. admDb := implement.NewAdminDb(engine)
  468. admin, err := admDb.GetAdmin(req.AdmId)
  469. if err != nil {
  470. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  471. return
  472. }
  473. if admin == nil {
  474. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  475. return
  476. }
  477. admin.Username = req.Username
  478. admin.Memo = req.Memo
  479. admin.Password = utils.Md5(req.Password)
  480. _, err = admDb.UpdateAdmin(admin, "username", "memo", "password")
  481. if err != nil {
  482. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  483. return
  484. }
  485. e.OutSuc(c, "success", nil)
  486. return
  487. }
  488. // AddAdmin
  489. // @Summary 新增管理员
  490. // @Tags 权限管理
  491. // @Description 权限管理-新增管理员
  492. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  493. // @Accept json
  494. // @Produce json
  495. // @Param args body md.AddAdminReq true "请求参数"
  496. // @Success 200 {string} "success"
  497. // @Failure 400 {object} md.Response "具体错误"
  498. // @Router /api/role/addAdmin [POST]
  499. func AddAdmin(c *gin.Context) {
  500. var req md.AddAdminReq
  501. err := c.ShouldBindJSON(&req)
  502. if err != nil {
  503. err = validate.HandleValidateErr(err)
  504. err1 := err.(e.E)
  505. e.OutErr(c, err1.Code, err1.Error())
  506. return
  507. }
  508. engine := db.DBs[svc.GetMasterId(c)]
  509. admDb := implement.NewAdminDb(engine)
  510. isHasAdmin, err := admDb.GetAdminByUserName(req.Username)
  511. if err != nil {
  512. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  513. return
  514. }
  515. if isHasAdmin != nil {
  516. e.OutErr(c, e.ERR, "当前用户名已存在,请勿重复添加")
  517. return
  518. }
  519. admId, err := admDb.CreateAdminId()
  520. if err != nil {
  521. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  522. return
  523. }
  524. admin := model.Admin{
  525. AdmId: admId,
  526. Username: req.Username,
  527. Password: utils.Md5(req.Password),
  528. State: enum.AdminStateForNormal,
  529. IsSuperAdministrator: 0,
  530. Memo: req.Memo,
  531. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  532. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  533. }
  534. _, err = admDb.AdminInsert(&admin)
  535. if err != nil {
  536. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  537. return
  538. }
  539. e.OutSuc(c, "success", nil)
  540. return
  541. }
  542. // DeleteAdmin
  543. // @Summary 删除管理员
  544. // @Tags 权限管理
  545. // @Description 权限管理-删除管理员
  546. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  547. // @Accept json
  548. // @Produce json
  549. // @Success 200 {string} "success"
  550. // @Failure 400 {object} md.Response "具体错误"
  551. // @Router /api/role/deleteAdmin/{$adm_id} [DELETE]
  552. func DeleteAdmin(c *gin.Context) {
  553. admId := c.Param("adm_id")
  554. err := svc.AdminDelete(c, []int{utils.StrToInt(admId)})
  555. if err != nil {
  556. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  557. return
  558. }
  559. e.OutSuc(c, "success", nil)
  560. return
  561. }
  562. // BindAdminRole
  563. // @Summary 管理员绑定角色
  564. // @Tags 权限管理
  565. // @Description 权限管理-管理员绑定角色
  566. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  567. // @Accept json
  568. // @Produce json
  569. // @Param args body md.BindAdminRoleReq true "请求参数"
  570. // @Success 200 {string} "success"
  571. // @Failure 400 {object} md.Response "具体错误"
  572. // @Router /api/role/bindAdminRole/ [POST]
  573. func BindAdminRole(c *gin.Context) {
  574. var req md.BindAdminRoleReq
  575. err := c.ShouldBindJSON(&req)
  576. if err != nil {
  577. err = validate.HandleValidateErr(err)
  578. err1 := err.(e.E)
  579. e.OutErr(c, err1.Code, err1.Error())
  580. return
  581. }
  582. err = svc.BindAdminRole(c, req)
  583. if err != nil {
  584. e.OutErr(c, e.ERR, err.Error())
  585. return
  586. }
  587. e.OutSuc(c, "success", nil)
  588. return
  589. }
  590. // AdminInfo
  591. // @Summary 管理员信息
  592. // @Tags 权限管理
  593. // @Description 权限管理-管理员信息
  594. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  595. // @Accept json
  596. // @Produce json
  597. // @param adm_id query string true "管理员id"
  598. // @Success 200 {string} "具体看返回内容"
  599. // @Failure 400 {object} md.Response "具体错误"
  600. // @Router /api/role/adminInfo [GET]
  601. func AdminInfo(c *gin.Context) {
  602. admId := c.DefaultQuery("adm_id", "")
  603. engine := db.DBs[svc.GetMasterId(c)]
  604. admDb := implement.NewAdminDb(engine)
  605. admin, err := admDb.GetAdmin(utils.StrToInt(admId))
  606. if err != nil {
  607. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  608. return
  609. }
  610. admin.Password = ""
  611. e.OutSuc(c, map[string]interface{}{
  612. "info": admin,
  613. "state": []map[string]interface{}{
  614. {
  615. "name": enum.RoleState(enum.RoleStateForNormal).String(),
  616. "value": enum.RoleStateForNormal,
  617. },
  618. {
  619. "name": enum.RoleState(enum.RoleStateForFreeze).String(),
  620. "value": enum.RoleStateForFreeze,
  621. },
  622. },
  623. }, nil)
  624. return
  625. }