sys_dictionary.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package system
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "lc-fangdaosha/model/common/response"
  6. "lc-fangdaosha/model/system"
  7. "lc-fangdaosha/model/system/request"
  8. "lc-fangdaosha/utils"
  9. )
  10. type DictionaryApi struct{}
  11. // CreateSysDictionary
  12. // @Tags SysDictionary
  13. // @Summary 创建SysDictionary
  14. // @Security ApiKeyAuth
  15. // @accept application/json
  16. // @Produce application/json
  17. // @Param data body system.SysDictionary true "SysDictionary模型"
  18. // @Success 200 {object} response.Response{msg=string} "创建SysDictionary"
  19. // @Router /sysDictionary/createSysDictionary [post]
  20. func (s *DictionaryApi) CreateSysDictionary(c *gin.Context) {
  21. var dictionary system.SysDictionary
  22. err := c.ShouldBindJSON(&dictionary)
  23. if err != nil {
  24. response.FailWithMessage(err.Error(), c)
  25. return
  26. }
  27. err = dictionaryService.CreateSysDictionary(dictionary)
  28. if err != nil {
  29. logrus.Error("创建失败!", err)
  30. response.FailWithMessage("创建失败", c)
  31. return
  32. }
  33. response.OkWithMessage("创建成功", c)
  34. }
  35. // DeleteSysDictionary
  36. // @Tags SysDictionary
  37. // @Summary 删除SysDictionary
  38. // @Security ApiKeyAuth
  39. // @accept application/json
  40. // @Produce application/json
  41. // @Param data body system.SysDictionary true "SysDictionary模型"
  42. // @Success 200 {object} response.Response{msg=string} "删除SysDictionary"
  43. // @Router /sysDictionary/deleteSysDictionary [delete]
  44. func (s *DictionaryApi) DeleteSysDictionary(c *gin.Context) {
  45. var dictionary system.SysDictionary
  46. err := c.ShouldBindJSON(&dictionary)
  47. if err != nil {
  48. response.FailWithMessage(err.Error(), c)
  49. return
  50. }
  51. err = dictionaryService.DeleteSysDictionary(dictionary)
  52. if err != nil {
  53. logrus.Error("删除失败!", err)
  54. response.FailWithMessage("删除失败", c)
  55. return
  56. }
  57. response.OkWithMessage("删除成功", c)
  58. }
  59. // UpdateSysDictionary
  60. // @Tags SysDictionary
  61. // @Summary 更新SysDictionary
  62. // @Security ApiKeyAuth
  63. // @accept application/json
  64. // @Produce application/json
  65. // @Param data body system.SysDictionary true "SysDictionary模型"
  66. // @Success 200 {object} response.Response{msg=string} "更新SysDictionary"
  67. // @Router /sysDictionary/updateSysDictionary [put]
  68. func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
  69. var dictionary system.SysDictionary
  70. err := c.ShouldBindJSON(&dictionary)
  71. if err != nil {
  72. response.FailWithMessage(err.Error(), c)
  73. return
  74. }
  75. err = dictionaryService.UpdateSysDictionary(&dictionary)
  76. if err != nil {
  77. logrus.Error("更新失败!", err)
  78. response.FailWithMessage("更新失败", c)
  79. return
  80. }
  81. response.OkWithMessage("更新成功", c)
  82. }
  83. // FindSysDictionary
  84. // @Tags SysDictionary
  85. // @Summary 用id查询SysDictionary
  86. // @Security ApiKeyAuth
  87. // @accept application/json
  88. // @Produce application/json
  89. // @Param data query system.SysDictionary true "ID或字典英名"
  90. // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysDictionary"
  91. // @Router /sysDictionary/findSysDictionary [get]
  92. func (s *DictionaryApi) FindSysDictionary(c *gin.Context) {
  93. var dictionary system.SysDictionary
  94. err := c.ShouldBindQuery(&dictionary)
  95. if err != nil {
  96. response.FailWithMessage(err.Error(), c)
  97. return
  98. }
  99. sysDictionary, err := dictionaryService.GetSysDictionary(dictionary.Type, dictionary.ID, dictionary.Status)
  100. if err != nil {
  101. logrus.Error("字典未创建或未开启!", err)
  102. response.FailWithMessage("字典未创建或未开启", c)
  103. return
  104. }
  105. response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
  106. }
  107. // GetSysDictionaryList
  108. // @Tags SysDictionary
  109. // @Summary 分页获取SysDictionary列表
  110. // @Security ApiKeyAuth
  111. // @accept application/json
  112. // @Produce application/json
  113. // @Param data query request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
  114. // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysDictionary列表,返回包括列表,总数,页码,每页数量"
  115. // @Router /sysDictionary/getSysDictionaryList [get]
  116. func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
  117. var pageInfo request.SysDictionarySearch
  118. err := c.ShouldBindQuery(&pageInfo)
  119. if err != nil {
  120. response.FailWithMessage(err.Error(), c)
  121. return
  122. }
  123. err = utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify)
  124. if err != nil {
  125. response.FailWithMessage(err.Error(), c)
  126. return
  127. }
  128. list, total, err := dictionaryService.GetSysDictionaryInfoList(pageInfo)
  129. if err != nil {
  130. logrus.Error("获取失败!", err)
  131. response.FailWithMessage("获取失败", c)
  132. return
  133. }
  134. response.OkWithDetailed(response.PageResult{
  135. List: list,
  136. Total: total,
  137. Page: pageInfo.Page,
  138. PageSize: pageInfo.PageSize,
  139. }, "获取成功", c)
  140. }