蛋蛋星球 后台端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 3 nedēļām
pirms 2 nedēļām
pirms 3 nedēļām
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/enum"
  6. "applet/app/lib/validate"
  7. "applet/app/md"
  8. "applet/app/svc"
  9. "applet/app/utils"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  11. "code.fnuoos.com/EggPlanet/egg_models.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 /api/role/permissionGroupList [GET]
  26. func PermissionGroupList(c *gin.Context) {
  27. roleId := c.DefaultQuery("role_id", "")
  28. engine := db.Db
  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.Db
  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.Db
  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. CreateAt: now.Format("2006-01-02 15:04:05"),
  181. UpdateAt: now.Format("2006-01-02 15:04:05"),
  182. })
  183. if err != nil {
  184. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  185. return
  186. }
  187. e.OutSuc(c, "success", nil)
  188. return
  189. }
  190. // UpdateRole
  191. // @Summary 修改角色
  192. // @Tags 权限管理
  193. // @Description 权限管理-修改角色
  194. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  195. // @Accept json
  196. // @Produce json
  197. // @Param args body md.UpdateRoleReq true "请求参数"
  198. // @Success 200 {string} "success"
  199. // @Failure 400 {object} md.Response "具体错误"
  200. // @Router /api/role/updateRole [POST]
  201. func UpdateRole(c *gin.Context) {
  202. var req md.UpdateRoleReq
  203. err := c.ShouldBindJSON(&req)
  204. if err != nil {
  205. err = validate.HandleValidateErr(err)
  206. err1 := err.(e.E)
  207. e.OutErr(c, err1.Code, err1.Error())
  208. return
  209. }
  210. engine := db.Db
  211. roleDb := implement.NewRoleDb(engine, req.RoleId)
  212. role, err := roleDb.GetRole()
  213. if err != nil {
  214. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  215. return
  216. }
  217. if role == nil {
  218. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  219. return
  220. }
  221. role.Name = req.Name
  222. role.Memo = req.Memo
  223. _, err = roleDb.UpdateRole(role, "name", "memo")
  224. if err != nil {
  225. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  226. return
  227. }
  228. e.OutSuc(c, "success", nil)
  229. return
  230. }
  231. // RoleBindPermissionGroup
  232. // @Summary 角色绑定权限组
  233. // @Tags 权限管理
  234. // @Description 权限管理-角色绑定权限组
  235. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  236. // @Accept json
  237. // @Produce json
  238. // @Param args body md.RoleBindPermissionGroupReq true "请求参数"
  239. // @Success 200 {string} "success"
  240. // @Failure 400 {object} md.Response "具体错误"
  241. // @Router /api/role/roleBindPermissionGroup [POST]
  242. func RoleBindPermissionGroup(c *gin.Context) {
  243. var req md.RoleBindPermissionGroupReq
  244. err := c.ShouldBindJSON(&req)
  245. if err != nil {
  246. err = validate.HandleValidateErr(err)
  247. err1 := err.(e.E)
  248. e.OutErr(c, err1.Code, err1.Error())
  249. return
  250. }
  251. err = svc.RoleBindPermissionGroup(req)
  252. if err != nil {
  253. e.OutErr(c, e.ERR, err.Error())
  254. return
  255. }
  256. e.OutSuc(c, "success", nil)
  257. return
  258. }
  259. // UpdateRoleState
  260. // @Summary 修改角色状态
  261. // @Tags 权限管理
  262. // @Description 权限管理-修改角色状态
  263. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  264. // @Accept json
  265. // @Produce json
  266. // @Param args body md.UpdateRoleStateReq true "请求参数"
  267. // @Success 200 {string} "success"
  268. // @Failure 400 {object} md.Response "具体错误"
  269. // @Router /api/role/updateRoleState [POST]
  270. func UpdateRoleState(c *gin.Context) {
  271. var req md.UpdateRoleStateReq
  272. err := c.ShouldBindJSON(&req)
  273. if err != nil {
  274. err = validate.HandleValidateErr(err)
  275. err1 := err.(e.E)
  276. e.OutErr(c, err1.Code, err1.Error())
  277. return
  278. }
  279. engine := db.Db
  280. roleDb := implement.NewRoleDb(engine, req.RoleId)
  281. role, err := roleDb.GetRole()
  282. if err != nil {
  283. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  284. return
  285. }
  286. if role == nil {
  287. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  288. return
  289. }
  290. role.State = req.State
  291. _, err = roleDb.UpdateRole(role, "state")
  292. if err != nil {
  293. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  294. return
  295. }
  296. e.OutSuc(c, "success", nil)
  297. return
  298. }
  299. // DeleteRole
  300. // @Summary 删除角色
  301. // @Tags 权限管理
  302. // @Description 权限管理-删除角色
  303. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  304. // @Accept json
  305. // @Produce json
  306. // @Param args body md.UpdateRoleStateReq true "请求参数"
  307. // @Success 200 {string} "success"
  308. // @Failure 400 {object} md.Response "具体错误"
  309. // @Router /api/role/deleteRole/{$id} [DELETE]
  310. func DeleteRole(c *gin.Context) {
  311. id := c.Param("id")
  312. engine := db.Db
  313. roleDb := implement.NewRoleDb(engine, utils.StrToInt(id))
  314. role, err := roleDb.GetRole()
  315. if err != nil {
  316. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  317. return
  318. }
  319. if role == nil {
  320. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  321. return
  322. }
  323. err = svc.DeleteRole(c, utils.StrToInt(id))
  324. if err != nil {
  325. e.OutErr(c, e.ERR, err.Error())
  326. return
  327. }
  328. e.OutSuc(c, "success", nil)
  329. return
  330. }
  331. // AdminList
  332. // @Summary 管理员列表
  333. // @Tags 权限管理
  334. // @Description 权限管理-管理员列表
  335. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  336. // @Accept json
  337. // @Produce json
  338. // @Param args body md.AdminListReq true "请求参数"
  339. // @Success 200 {string} "具体看返回内容"
  340. // @Failure 400 {object} md.Response "具体错误"
  341. // @Router /api/role/adminList [POST]
  342. func AdminList(c *gin.Context) {
  343. var req md.AdminListReq
  344. err := c.ShouldBindJSON(&req)
  345. if err != nil {
  346. err = validate.HandleValidateErr(err)
  347. err1 := err.(e.E)
  348. e.OutErr(c, err1.Code, err1.Error())
  349. return
  350. }
  351. if req.Limit == 0 {
  352. req.Limit = 10
  353. }
  354. if req.Page == 0 {
  355. req.Page = 10
  356. }
  357. engine := db.Db
  358. adminDb := implement.NewAdminDb(engine)
  359. adminList, total, err := adminDb.FindAdmin(req.UserName, req.State, req.Page, req.Limit)
  360. if err != nil {
  361. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  362. return
  363. }
  364. var result []md.AdminListResp
  365. for _, v := range adminList {
  366. permissionGroupList, _, err1 := adminDb.FindAdminRolePermissionGroup(v.AdmId)
  367. if err1 != nil {
  368. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  369. return
  370. }
  371. var roleList []string
  372. for _, v1 := range permissionGroupList {
  373. roleList = append(roleList, v1.Role.Name)
  374. }
  375. result = append(result, md.AdminListResp{
  376. AdmId: v.AdmId,
  377. Username: v.Username,
  378. State: v.State,
  379. IsSuperAdministrator: v.IsSuperAdministrator,
  380. Memo: v.Memo,
  381. CreateAt: v.CreateAt,
  382. UpdateAt: v.UpdateAt,
  383. RoleList: roleList,
  384. })
  385. }
  386. e.OutSuc(c, map[string]interface{}{
  387. "list": result,
  388. "total": total,
  389. "state": []map[string]interface{}{
  390. {
  391. "name": enum.RoleState(enum.RoleStateForNormal).String(),
  392. "value": enum.RoleStateForNormal,
  393. },
  394. {
  395. "name": enum.RoleState(enum.RoleStateForFreeze).String(),
  396. "value": enum.RoleStateForFreeze,
  397. },
  398. },
  399. }, nil)
  400. return
  401. }
  402. // UpdateAdminState
  403. // @Summary 修改管理员状态
  404. // @Tags 权限管理
  405. // @Description 权限管理-修改管理员状态
  406. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  407. // @Accept json
  408. // @Produce json
  409. // @Param args body md.UpdateAdminStateReq true "请求参数"
  410. // @Success 200 {string} "success"
  411. // @Failure 400 {object} md.Response "具体错误"
  412. // @Router /api/role/updateAdminState [POST]
  413. func UpdateAdminState(c *gin.Context) {
  414. var req md.UpdateAdminStateReq
  415. err := c.ShouldBindJSON(&req)
  416. if err != nil {
  417. err = validate.HandleValidateErr(err)
  418. err1 := err.(e.E)
  419. e.OutErr(c, err1.Code, err1.Error())
  420. return
  421. }
  422. engine := db.Db
  423. admDb := implement.NewAdminDb(engine)
  424. admin, err := admDb.GetAdmin(req.AdmId)
  425. if err != nil {
  426. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  427. return
  428. }
  429. if admin == nil {
  430. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  431. return
  432. }
  433. admin.State = req.State
  434. _, err = admDb.UpdateAdmin(admin, "state")
  435. if err != nil {
  436. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  437. return
  438. }
  439. e.OutSuc(c, "success", nil)
  440. return
  441. }
  442. // UpdateAdmin
  443. // @Summary 修改管理员信息
  444. // @Tags 权限管理
  445. // @Description 权限管理-修改管理员信息
  446. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  447. // @Accept json
  448. // @Produce json
  449. // @Param args body md.UpdateAdminReq true "请求参数"
  450. // @Success 200 {string} "success"
  451. // @Failure 400 {object} md.Response "具体错误"
  452. // @Router /api/role/updateAdmin [POST]
  453. func UpdateAdmin(c *gin.Context) {
  454. var req md.UpdateAdminReq
  455. err := c.ShouldBindJSON(&req)
  456. if err != nil {
  457. err = validate.HandleValidateErr(err)
  458. err1 := err.(e.E)
  459. e.OutErr(c, err1.Code, err1.Error())
  460. return
  461. }
  462. engine := db.Db
  463. admDb := implement.NewAdminDb(engine)
  464. admin, err := admDb.GetAdmin(req.AdmId)
  465. if err != nil {
  466. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  467. return
  468. }
  469. if admin == nil {
  470. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  471. return
  472. }
  473. admin.Username = req.Username
  474. admin.Memo = req.Memo
  475. if req.Password != "" {
  476. admin.Password = utils.Md5(req.Password)
  477. }
  478. _, err = admDb.UpdateAdmin(admin, "username", "memo", "password", "show_time")
  479. if err != nil {
  480. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  481. return
  482. }
  483. e.OutSuc(c, "success", nil)
  484. return
  485. }
  486. // AddAdmin
  487. // @Summary 新增管理员
  488. // @Tags 权限管理
  489. // @Description 权限管理-新增管理员
  490. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  491. // @Accept json
  492. // @Produce json
  493. // @Param args body md.AddAdminReq true "请求参数"
  494. // @Success 200 {string} "success"
  495. // @Failure 400 {object} md.Response "具体错误"
  496. // @Router /api/role/addAdmin [POST]
  497. func AddAdmin(c *gin.Context) {
  498. var req md.AddAdminReq
  499. err := c.ShouldBindJSON(&req)
  500. if err != nil {
  501. err = validate.HandleValidateErr(err)
  502. err1 := err.(e.E)
  503. e.OutErr(c, err1.Code, err1.Error())
  504. return
  505. }
  506. engine := db.Db
  507. admDb := implement.NewAdminDb(engine)
  508. isHasAdmin, err := admDb.GetAdminByUserName(req.Username)
  509. if err != nil {
  510. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  511. return
  512. }
  513. if isHasAdmin != nil {
  514. e.OutErr(c, e.ERR, "当前用户名已存在,请勿重复添加")
  515. return
  516. }
  517. admId, err := admDb.CreateAdminId()
  518. if err != nil {
  519. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  520. return
  521. }
  522. admin := model.Admin{
  523. AdmId: admId,
  524. Username: req.Username,
  525. Password: utils.Md5(req.Password),
  526. State: enum.AdminStateForNormal,
  527. IsSuperAdministrator: 0,
  528. Memo: req.Memo,
  529. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  530. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  531. }
  532. _, err = admDb.AdminInsert(&admin)
  533. if err != nil {
  534. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  535. return
  536. }
  537. e.OutSuc(c, "success", nil)
  538. return
  539. }
  540. // DeleteAdmin
  541. // @Summary 删除管理员
  542. // @Tags 权限管理
  543. // @Description 权限管理-删除管理员
  544. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  545. // @Accept json
  546. // @Produce json
  547. // @Success 200 {string} "success"
  548. // @Failure 400 {object} md.Response "具体错误"
  549. // @Router /api/role/deleteAdmin/{$adm_id} [DELETE]
  550. func DeleteAdmin(c *gin.Context) {
  551. admId := c.Param("adm_id")
  552. err := svc.AdminDelete([]int{utils.StrToInt(admId)})
  553. if err != nil {
  554. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  555. return
  556. }
  557. e.OutSuc(c, "success", nil)
  558. return
  559. }
  560. // BindAdminRole
  561. // @Summary 管理员绑定角色
  562. // @Tags 权限管理
  563. // @Description 权限管理-管理员绑定角色
  564. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  565. // @Accept json
  566. // @Produce json
  567. // @Param args body md.BindAdminRoleReq true "请求参数"
  568. // @Success 200 {string} "success"
  569. // @Failure 400 {object} md.Response "具体错误"
  570. // @Router /api/role/bindAdminRole [POST]
  571. func BindAdminRole(c *gin.Context) {
  572. var req md.BindAdminRoleReq
  573. err := c.ShouldBindJSON(&req)
  574. if err != nil {
  575. err = validate.HandleValidateErr(err)
  576. err1 := err.(e.E)
  577. e.OutErr(c, err1.Code, err1.Error())
  578. return
  579. }
  580. err = svc.BindAdminRole(c, req)
  581. if err != nil {
  582. e.OutErr(c, e.ERR, err.Error())
  583. return
  584. }
  585. e.OutSuc(c, "success", nil)
  586. return
  587. }
  588. // AdminInfo
  589. // @Summary 管理员信息
  590. // @Tags 权限管理
  591. // @Description 权限管理-管理员信息
  592. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  593. // @Accept json
  594. // @Produce json
  595. // @param adm_id query string true "管理员id"
  596. // @Success 200 {string} "具体看返回内容"
  597. // @Failure 400 {object} md.Response "具体错误"
  598. // @Router /api/role/adminInfo [GET]
  599. func AdminInfo(c *gin.Context) {
  600. admId := c.DefaultQuery("adm_id", "")
  601. engine := db.Db
  602. admDb := implement.NewAdminDb(engine)
  603. admin, err := admDb.GetAdmin(utils.StrToInt(admId))
  604. if err != nil {
  605. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  606. return
  607. }
  608. admin.Password = ""
  609. e.OutSuc(c, map[string]interface{}{
  610. "info": admin,
  611. "state": []map[string]interface{}{
  612. {
  613. "name": enum.RoleState(enum.RoleStateForNormal).String(),
  614. "value": enum.RoleStateForNormal,
  615. },
  616. {
  617. "name": enum.RoleState(enum.RoleStateForFreeze).String(),
  618. "value": enum.RoleStateForFreeze,
  619. },
  620. },
  621. }, nil)
  622. return
  623. }