广告平台(站长使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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