mirror of
https://gitlab.52pay.top/go/easygoadmin.git
synced 2025-09-26 22:47:58 +08:00
205 lines
4.0 KiB
Go
205 lines
4.0 KiB
Go
/**
|
|
* 岗位管理-控制器
|
|
* @author
|
|
* @since 2021/9/10
|
|
* @File : position
|
|
*/
|
|
package controller
|
|
|
|
import (
|
|
"easygoadmin/app/dto"
|
|
"easygoadmin/app/model"
|
|
"easygoadmin/app/service"
|
|
"easygoadmin/utils"
|
|
"easygoadmin/utils/common"
|
|
"easygoadmin/utils/gconv"
|
|
"easygoadmin/utils/response"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
var Position = new(positionCtl)
|
|
|
|
type positionCtl struct{}
|
|
|
|
func (c *positionCtl) Index(ctx *gin.Context) {
|
|
// 渲染模板
|
|
response.BuildTpl(ctx, "position_index.html").WriteTpl()
|
|
}
|
|
|
|
func (c *positionCtl) List(ctx *gin.Context) {
|
|
// 参数绑定
|
|
var req *dto.PositionPageReq
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
ctx.JSON(http.StatusOK, common.JsonResult{
|
|
Code: -1,
|
|
Msg: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
// 调用查询列表方法
|
|
list, count, err := service.Position.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 *positionCtl) Edit(ctx *gin.Context) {
|
|
// 查询记录
|
|
id := gconv.Int(ctx.Query("id"))
|
|
if id > 0 {
|
|
info := &model.Position{Id: id}
|
|
isOk, err := info.Get()
|
|
if !isOk || err != nil {
|
|
ctx.JSON(http.StatusOK, common.JsonResult{
|
|
Code: -1,
|
|
Msg: err.Error(),
|
|
})
|
|
}
|
|
// 渲染模板
|
|
response.BuildTpl(ctx, "position_edit.html").WriteTpl(gin.H{
|
|
"info": info,
|
|
})
|
|
} else {
|
|
// 渲染模板
|
|
response.BuildTpl(ctx, "position_edit.html").WriteTpl()
|
|
}
|
|
|
|
}
|
|
|
|
func (c *positionCtl) Add(ctx *gin.Context) {
|
|
// 参数绑定
|
|
var req *dto.PositionAddReq
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
ctx.JSON(http.StatusOK, common.JsonResult{
|
|
Code: -1,
|
|
Msg: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
// 调用添加方法
|
|
rows, err := service.Position.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 *positionCtl) Update(ctx *gin.Context) {
|
|
// 参数绑定
|
|
var req *dto.PositionUpdateReq
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
ctx.JSON(http.StatusOK, common.JsonResult{
|
|
Code: -1,
|
|
Msg: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
// 调用更新方法
|
|
rows, err := service.Position.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 *positionCtl) 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.Position.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: "删除成功",
|
|
})
|
|
}
|
|
|
|
func (c *positionCtl) Status(ctx *gin.Context) {
|
|
// 参数绑定
|
|
var req *dto.PositionStatusReq
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
ctx.JSON(http.StatusOK, common.JsonResult{
|
|
Code: -1,
|
|
Msg: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
// 调用设置状态方法
|
|
rows, err := service.Position.Status(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 *positionCtl) GetPositionList(ctx *gin.Context) {
|
|
// 查询岗位列表
|
|
list := make([]model.Position, 0)
|
|
utils.XormDb.Where("status=1 and mark=1").Asc("sort").Find(&list)
|
|
// 返回结果
|
|
ctx.JSON(http.StatusOK, common.JsonResult{
|
|
Code: 0,
|
|
Msg: "查询成功",
|
|
Data: list,
|
|
})
|
|
}
|