mirror of
https://gitlab.52pay.top/go/easygoadmin.git
synced 2025-09-27 10:24:14 +08:00
124 lines
2.4 KiB
Go
124 lines
2.4 KiB
Go
/**
|
|
* 配置管理-控制器
|
|
* @author
|
|
* @since 2021/11/13
|
|
* @File : config
|
|
*/
|
|
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"
|
|
"gitlab.52pay.top/go/easygoadmin/utils/response"
|
|
"net/http"
|
|
)
|
|
|
|
var Config = new(configCtl)
|
|
|
|
type configCtl struct{}
|
|
|
|
func (c *configCtl) Index(ctx *gin.Context) {
|
|
// 渲染模板
|
|
response.BuildTpl(ctx, "config_index.html").WriteTpl(gin.H{
|
|
"configTypeList": common.CONFIG_DATA_TYPE_LIST,
|
|
})
|
|
}
|
|
|
|
func (c *configCtl) List(ctx *gin.Context) {
|
|
// 调用查询列表方法
|
|
list := service.Config.GetList()
|
|
// 返回结果
|
|
ctx.JSON(http.StatusOK, common.JsonResult{
|
|
Code: 0,
|
|
Msg: "查询成功",
|
|
Data: list,
|
|
})
|
|
}
|
|
|
|
func (c *configCtl) Add(ctx *gin.Context) {
|
|
// 参数
|
|
var req *dto.ConfigAddReq
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
ctx.JSON(http.StatusOK, common.JsonResult{
|
|
Code: -1,
|
|
Msg: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
// 调用添加方法
|
|
rows, err := service.Config.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 *configCtl) Update(ctx *gin.Context) {
|
|
// 参数
|
|
var req *dto.ConfigUpdateReq
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
ctx.JSON(http.StatusOK, common.JsonResult{
|
|
Code: -1,
|
|
Msg: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
// 调用更新方法
|
|
rows, err := service.Config.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 *configCtl) 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.Config.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: "删除成功",
|
|
})
|
|
}
|