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.

120 lines
4.1 KiB

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