sys_dictionary.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package system
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
  7. "github.com/flipped-aurora/gin-vue-admin/server/utils"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. )
  11. type DictionaryApi struct {
  12. }
  13. // @Tags SysDictionary
  14. // @Summary 创建SysDictionary
  15. // @Security ApiKeyAuth
  16. // @accept application/json
  17. // @Produce application/json
  18. // @Param data body system.SysDictionary true "SysDictionary模型"
  19. // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
  20. // @Router /sysDictionary/createSysDictionary [post]
  21. func (s *DictionaryApi) CreateSysDictionary(c *gin.Context) {
  22. var dictionary system.SysDictionary
  23. _ = c.ShouldBindJSON(&dictionary)
  24. if err := dictionaryService.CreateSysDictionary(dictionary); err != nil {
  25. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  26. response.FailWithMessage("创建失败", c)
  27. } else {
  28. response.OkWithMessage("创建成功", c)
  29. }
  30. }
  31. // @Tags SysDictionary
  32. // @Summary 删除SysDictionary
  33. // @Security ApiKeyAuth
  34. // @accept application/json
  35. // @Produce application/json
  36. // @Param data body system.SysDictionary true "SysDictionary模型"
  37. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  38. // @Router /sysDictionary/deleteSysDictionary [delete]
  39. func (s *DictionaryApi) DeleteSysDictionary(c *gin.Context) {
  40. var dictionary system.SysDictionary
  41. _ = c.ShouldBindJSON(&dictionary)
  42. if err := dictionaryService.DeleteSysDictionary(dictionary); err != nil {
  43. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  44. response.FailWithMessage("删除失败", c)
  45. } else {
  46. response.OkWithMessage("删除成功", c)
  47. }
  48. }
  49. // @Tags SysDictionary
  50. // @Summary 更新SysDictionary
  51. // @Security ApiKeyAuth
  52. // @accept application/json
  53. // @Produce application/json
  54. // @Param data body system.SysDictionary true "SysDictionary模型"
  55. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  56. // @Router /sysDictionary/updateSysDictionary [put]
  57. func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
  58. var dictionary system.SysDictionary
  59. _ = c.ShouldBindJSON(&dictionary)
  60. if err := dictionaryService.UpdateSysDictionary(&dictionary); err != nil {
  61. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  62. response.FailWithMessage("更新失败", c)
  63. } else {
  64. response.OkWithMessage("更新成功", c)
  65. }
  66. }
  67. // @Tags SysDictionary
  68. // @Summary 用id查询SysDictionary
  69. // @Security ApiKeyAuth
  70. // @accept application/json
  71. // @Produce application/json
  72. // @Param data query system.SysDictionary true "ID或字典英名"
  73. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  74. // @Router /sysDictionary/findSysDictionary [get]
  75. func (s *DictionaryApi) FindSysDictionary(c *gin.Context) {
  76. var dictionary system.SysDictionary
  77. _ = c.ShouldBindQuery(&dictionary)
  78. if err, sysDictionary := dictionaryService.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil {
  79. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  80. response.FailWithMessage("查询失败", c)
  81. } else {
  82. response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
  83. }
  84. }
  85. // @Tags SysDictionary
  86. // @Summary 分页获取SysDictionary列表
  87. // @Security ApiKeyAuth
  88. // @accept application/json
  89. // @Produce application/json
  90. // @Param data query request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
  91. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  92. // @Router /sysDictionary/getSysDictionaryList [get]
  93. func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
  94. var pageInfo request.SysDictionarySearch
  95. _ = c.ShouldBindQuery(&pageInfo)
  96. if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
  97. response.FailWithMessage(err.Error(), c)
  98. return
  99. }
  100. if err, list, total := dictionaryService.GetSysDictionaryInfoList(pageInfo); err != nil {
  101. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  102. response.FailWithMessage("获取失败", c)
  103. } else {
  104. response.OkWithDetailed(response.PageResult{
  105. List: list,
  106. Total: total,
  107. Page: pageInfo.Page,
  108. PageSize: pageInfo.PageSize,
  109. }, "获取成功", c)
  110. }
  111. }