sys_dictionary.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. func (s *DictionaryApi) FindSysDictionaryName(c *gin.Context) {
  86. var dictionary system.SysDictionary
  87. _ = c.ShouldBindQuery(&dictionary)
  88. if err, sysDictionary := dictionaryService.GetSysDictionaryDetail(dictionary.Name); err != nil {
  89. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  90. response.FailWithMessage("查询失败", c)
  91. } else {
  92. response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
  93. }
  94. }
  95. // @Tags SysDictionary
  96. // @Summary 分页获取SysDictionary列表
  97. // @Security ApiKeyAuth
  98. // @accept application/json
  99. // @Produce application/json
  100. // @Param data query request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
  101. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  102. // @Router /sysDictionary/getSysDictionaryList [get]
  103. func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
  104. var pageInfo request.SysDictionarySearch
  105. _ = c.ShouldBindQuery(&pageInfo)
  106. if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
  107. response.FailWithMessage(err.Error(), c)
  108. return
  109. }
  110. if err, list, total := dictionaryService.GetSysDictionaryInfoList(pageInfo); err != nil {
  111. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  112. response.FailWithMessage("获取失败", c)
  113. } else {
  114. response.OkWithDetailed(response.PageResult{
  115. List: list,
  116. Total: total,
  117. Page: pageInfo.Page,
  118. PageSize: pageInfo.PageSize,
  119. }, "获取成功", c)
  120. }
  121. }