Files
easygoadmin/app/controller/dict_data.go
yaoyilin dbd3c3c247 feat: 封装为包
封装为包
2022-10-31 23:55:00 +08:00

135 lines
2.5 KiB
Go

/**
* 字典数据-控制器
* @author
* @since 2021/11/13
* @File : dict_data
*/
package controller
import (
"github.com/gin-gonic/gin"
"gitlab.52pay.top/go/easygoadmin/app/dto"
"gitlab.52pay.top/go/easygoadmin/app/service"
"gitlab.52pay.top/go/easygoadmin/utils"
"gitlab.52pay.top/go/easygoadmin/utils/common"
"net/http"
)
var DictData = new(dictDataCtl)
type dictDataCtl struct{}
func (c *dictDataCtl) List(ctx *gin.Context) {
// 参数
var req *dto.DictDataPageReq
if err := ctx.ShouldBind(&req); err != nil {
ctx.JSON(http.StatusOK, common.JsonResult{
Code: -1,
Msg: err.Error(),
})
return
}
// 调用查询分页方法
list, count, err := service.DictData.GetList(req)
if err != nil {
ctx.JSON(http.StatusOK, common.JsonResult{
Code: -1,
Msg: err.Error(),
})
return
}
// 返回结果
ctx.JSON(http.StatusOK, common.JsonResult{
Code: 0,
Msg: "查询成功",
Data: list,
Count: count,
})
}
func (c *dictDataCtl) Add(ctx *gin.Context) {
// 参数
var req *dto.DictDataAddReq
if err := ctx.ShouldBind(&req); err != nil {
ctx.JSON(http.StatusOK, common.JsonResult{
Code: -1,
Msg: err.Error(),
})
return
}
// 调用添加方法
rows, err := service.DictData.Add(req, utils.Uid(ctx))
if err != nil || rows == 0 {
ctx.JSON(http.StatusOK, common.JsonResult{
Code: -1,
Msg: err.Error(),
})
return
}
// 返回结果
ctx.JSON(http.StatusOK, common.JsonResult{
Code: 0,
Msg: "添加成功",
})
}
func (c *dictDataCtl) Update(ctx *gin.Context) {
// 参数
var req *dto.DictDataUpdateReq
if err := ctx.ShouldBind(&req); err != nil {
ctx.JSON(http.StatusOK, common.JsonResult{
Code: -1,
Msg: err.Error(),
})
return
}
// 调用更新方法
rows, err := service.DictData.Update(req, utils.Uid(ctx))
if err != nil || rows == 0 {
ctx.JSON(http.StatusOK, common.JsonResult{
Code: -1,
Msg: err.Error(),
})
return
}
// 返回结果
ctx.JSON(http.StatusOK, common.JsonResult{
Code: 0,
Msg: "更新成功",
})
}
func (c *dictDataCtl) Delete(ctx *gin.Context) {
// 记录ID
ids := ctx.Param("ids")
if ids == "" {
ctx.JSON(http.StatusOK, common.JsonResult{
Code: -1,
Msg: "记录ID不能为空",
})
return
}
// 调用删除方法
rows, err := service.DictData.Delete(ids)
if err != nil || rows == 0 {
ctx.JSON(http.StatusOK, common.JsonResult{
Code: -1,
Msg: err.Error(),
})
return
}
// 返回结果
ctx.JSON(http.StatusOK, common.JsonResult{
Code: 0,
Msg: "删除成功",
})
}