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

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

S
songzhibin97 已提交
13
type DictionaryApi struct{}
14

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

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

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

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

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