广告平台(站长下代理使用)
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 месеца
преди 2 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 3 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
преди 2 месеца
преди 3 месеца
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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 ADMIN-权限管理
  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.DBs[svc.GetMasterId(c)]
  29. qrcodeWithBatchRecordsDb := implement.NewAgentPermissionGroupDb(engine)
  30. groupList, err := qrcodeWithBatchRecordsDb.FindAgentPermissionGroup()
  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 ADMIN-权限管理
  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.NewAgentRoleDb(engine)
  108. roleList, err := roleDb.FindAgentRole()
  109. if err != nil {
  110. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  111. return
  112. }
  113. adminRoleDb := implement.NewAgentWithRoleDb(engine)
  114. adminDb := implement.NewAgentDb(engine)
  115. var result []*md.RoleListResp
  116. for _, v := range *roleList {
  117. var temp md.RoleListResp
  118. temp.Data = v
  119. adminRoles, err1 := adminRoleDb.FindAgentWithRoleByRoleId(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.GetAgent(adminRole.Id)
  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 ADMIN-权限管理
  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.NewAgentRoleDb(engine)
  175. now := time.Now()
  176. _, err = roleDb.AgentRoleInsert(&model.AgentRole{
  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 ADMIN-权限管理
  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.DBs[svc.GetMasterId(c)]
  211. roleDb := implement.NewAgentRoleDb(engine)
  212. role, err := roleDb.GetAgentRole(req.RoleId)
  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.UpdateAgentRole(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 ADMIN-权限管理
  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(c, 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 ADMIN-权限管理
  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.DBs[svc.GetMasterId(c)]
  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 ADMIN-权限管理
  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.DBs[svc.GetMasterId(c)]
  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 ADMIN-权限管理
  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.DBs[svc.GetMasterId(c)]
  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. Id: 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 ADMIN-权限管理
  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.DBs[svc.GetMasterId(c)]
  423. admDb := implement.NewAdminDb(engine)
  424. admin, err := admDb.GetAdmin(req.Id)
  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 ADMIN-权限管理
  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.DBs[svc.GetMasterId(c)]
  463. admDb := implement.NewAdminDb(engine)
  464. admin, err := admDb.GetAdmin(req.Id)
  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. admin.Password = utils.Md5(req.Password)
  476. _, err = admDb.UpdateAdmin(admin, "username", "memo", "password")
  477. if err != nil {
  478. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  479. return
  480. }
  481. e.OutSuc(c, "success", nil)
  482. return
  483. }
  484. // AddAdmin
  485. // @Summary 新增管理员
  486. // @Tags ADMIN-权限管理
  487. // @Description 新增管理员
  488. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  489. // @Accept json
  490. // @Produce json
  491. // @Param args body md.AddAdminReq true "请求参数"
  492. // @Success 200 {string} "success"
  493. // @Failure 400 {object} md.Response "具体错误"
  494. // @Router /api/role/addAdmin [POST]
  495. func AddAdmin(c *gin.Context) {
  496. var req md.AddAdminReq
  497. err := c.ShouldBindJSON(&req)
  498. if err != nil {
  499. err = validate.HandleValidateErr(err)
  500. err1 := err.(e.E)
  501. e.OutErr(c, err1.Code, err1.Error())
  502. return
  503. }
  504. engine := db.DBs[svc.GetMasterId(c)]
  505. admDb := implement.NewAdminDb(engine)
  506. isHasAdmin, err := admDb.GetAdminByUserName(req.Username)
  507. if err != nil {
  508. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  509. return
  510. }
  511. if isHasAdmin != nil {
  512. e.OutErr(c, e.ERR, "当前用户名已存在,请勿重复添加")
  513. return
  514. }
  515. admId, err := admDb.CreateAdminId()
  516. if err != nil {
  517. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  518. return
  519. }
  520. admin := model.Admin{
  521. AdmId: admId,
  522. Username: req.Username,
  523. Password: utils.Md5(req.Password),
  524. State: enum.AdminStateForNormal,
  525. IsSuperAdministrator: 0,
  526. Memo: req.Memo,
  527. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  528. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  529. }
  530. _, err = admDb.AdminInsert(&admin)
  531. if err != nil {
  532. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  533. return
  534. }
  535. e.OutSuc(c, "success", nil)
  536. return
  537. }
  538. // DeleteAdmin
  539. // @Summary 删除管理员
  540. // @Tags ADMIN-权限管理
  541. // @Description 删除管理员
  542. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  543. // @Accept json
  544. // @Produce json
  545. // @Success 200 {string} "success"
  546. // @Failure 400 {object} md.Response "具体错误"
  547. // @Router /api/role/deleteAdmin/{$adm_id} [DELETE]
  548. func DeleteAdmin(c *gin.Context) {
  549. admId := c.Param("adm_id")
  550. err := svc.AdminDelete(c, []int{utils.StrToInt(admId)})
  551. if err != nil {
  552. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  553. return
  554. }
  555. e.OutSuc(c, "success", nil)
  556. return
  557. }
  558. // BindAdminRole
  559. // @Summary 管理员绑定角色
  560. // @Tags ADMIN-权限管理
  561. // @Description 管理员绑定角色
  562. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  563. // @Accept json
  564. // @Produce json
  565. // @Param args body md.BindAdminRoleReq true "请求参数"
  566. // @Success 200 {string} "success"
  567. // @Failure 400 {object} md.Response "具体错误"
  568. // @Router /api/role/bindAdminRole/ [POST]
  569. func BindAdminRole(c *gin.Context) {
  570. var req md.BindAdminRoleReq
  571. err := c.ShouldBindJSON(&req)
  572. if err != nil {
  573. err = validate.HandleValidateErr(err)
  574. err1 := err.(e.E)
  575. e.OutErr(c, err1.Code, err1.Error())
  576. return
  577. }
  578. err = svc.BindAdminRole(c, req)
  579. if err != nil {
  580. e.OutErr(c, e.ERR, err.Error())
  581. return
  582. }
  583. e.OutSuc(c, "success", nil)
  584. return
  585. }
  586. // AdminInfo
  587. // @Summary 管理员信息
  588. // @Tags ADMIN-权限管理
  589. // @Description 管理员信息
  590. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  591. // @Accept json
  592. // @Produce json
  593. // @param adm_id query string true "管理员id"
  594. // @Success 200 {string} "具体看返回内容"
  595. // @Failure 400 {object} md.Response "具体错误"
  596. // @Router /api/role/adminInfo [GET]
  597. func AdminInfo(c *gin.Context) {
  598. admId := c.DefaultQuery("adm_id", "")
  599. engine := db.DBs[svc.GetMasterId(c)]
  600. admDb := implement.NewAdminDb(engine)
  601. admin, err := admDb.GetAdmin(utils.StrToInt(admId))
  602. if err != nil {
  603. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  604. return
  605. }
  606. admin.Password = ""
  607. e.OutSuc(c, map[string]interface{}{
  608. "info": admin,
  609. "state": []map[string]interface{}{
  610. {
  611. "name": enum.RoleState(enum.RoleStateForNormal).String(),
  612. "value": enum.RoleStateForNormal,
  613. },
  614. {
  615. "name": enum.RoleState(enum.RoleStateForFreeze).String(),
  616. "value": enum.RoleStateForFreeze,
  617. },
  618. },
  619. }, nil)
  620. return
  621. }