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.

116 lines
3.9 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, sysDictionary := service.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil {
  78. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  79. response.FailWithMessage("查询失败", c)
  80. } else {
  81. response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
  82. }
  83. }
  84. // @Tags SysDictionary
  85. // @Summary 分页获取SysDictionary列表
  86. // @Security ApiKeyAuth
  87. // @accept application/json
  88. // @Produce application/json
  89. // @Param data body request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
  90. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  91. // @Router /sysDictionary/getSysDictionaryList [get]
  92. func GetSysDictionaryList(c *gin.Context) {
  93. var pageInfo request.SysDictionarySearch
  94. _ = c.ShouldBindQuery(&pageInfo)
  95. if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
  96. response.FailWithMessage(err.Error(), c)
  97. return
  98. }
  99. if err, list, total := service.GetSysDictionaryInfoList(pageInfo); err != nil {
  100. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  101. response.FailWithMessage("获取失败", c)
  102. } else {
  103. response.OkWithDetailed(response.PageResult{
  104. List: list,
  105. Total: total,
  106. Page: pageInfo.Page,
  107. PageSize: pageInfo.PageSize,
  108. }, "获取成功", c)
  109. }
  110. }