sys_dictionary.go 4.1 KB
Newer Older
1
package system
Mr.奇淼('s avatar
Mr.奇淼( 已提交
2 3

import (
4
	"gin-vue-admin/global"
5
	"gin-vue-admin/model/common/response"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
6 7
	"gin-vue-admin/model/system"
	"gin-vue-admin/model/system/request"
8
	"gin-vue-admin/utils"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
9
	"github.com/gin-gonic/gin"
10
	"go.uber.org/zap"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
11 12
)

13 14 15
type DictionaryApi struct {
}

Mr.奇淼('s avatar
Mr.奇淼( 已提交
16 17 18 19 20
// @Tags SysDictionary
// @Summary 创建SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
21 22
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
23
// @Router /sysDictionary/createSysDictionary [post]
24
func (s *DictionaryApi) CreateSysDictionary(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
25
	var dictionary system.SysDictionary
26
	_ = c.ShouldBindJSON(&dictionary)
27
	if err := dictionaryService.CreateSysDictionary(dictionary); err != nil {
28 29
		global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
30 31 32 33 34 35 36 37 38 39
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// @Tags SysDictionary
// @Summary 删除SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
40
// @Param data body model.SysDictionary true "SysDictionary模型"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
41 42
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysDictionary/deleteSysDictionary [delete]
43
func (s *DictionaryApi) DeleteSysDictionary(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
44
	var dictionary system.SysDictionary
45
	_ = c.ShouldBindJSON(&dictionary)
46
	if err := dictionaryService.DeleteSysDictionary(dictionary); err != nil {
47 48
		global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
49 50 51 52 53 54 55 56 57 58
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags SysDictionary
// @Summary 更新SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
59
// @Param data body model.SysDictionary true "SysDictionary模型"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
60 61
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /sysDictionary/updateSysDictionary [put]
62
func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
63
	var dictionary system.SysDictionary
64
	_ = c.ShouldBindJSON(&dictionary)
65
	if err := dictionaryService.UpdateSysDictionary(&dictionary); err != nil {
66 67
		global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
68 69 70 71 72 73 74 75 76 77
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// @Tags SysDictionary
// @Summary 用id查询SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
78
// @Param data body model.SysDictionary true "ID或字典英名"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
79 80
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysDictionary/findSysDictionary [get]
81
func (s *DictionaryApi) FindSysDictionary(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
82
	var dictionary system.SysDictionary
83
	_ = c.ShouldBindQuery(&dictionary)
84
	if err, sysDictionary := dictionaryService.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil {
85 86
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
87
	} else {
88
		response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
89 90 91 92 93 94 95 96
	}
}

// @Tags SysDictionary
// @Summary 分页获取SysDictionary列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
97
// @Param data body request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
98 99
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysDictionary/getSysDictionaryList [get]
100
func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
101 102
	var pageInfo request.SysDictionarySearch
	_ = c.ShouldBindQuery(&pageInfo)
103 104 105 106
	if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
107
	if err, list, total := dictionaryService.GetSysDictionaryInfoList(pageInfo); err != nil {
108 109
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
110
	} else {
111
		response.OkWithDetailed(response.PageResult{
Mr.奇淼('s avatar
Mr.奇淼( 已提交
112 113 114 115
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
116
		}, "获取成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
117 118
	}
}