You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
3.4 KiB
136 lines
3.4 KiB
2 years ago
|
package vivib
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"github.com/beego/beego/v2/core/logs"
|
||
|
"github.com/beego/beego/v2/core/validation"
|
||
|
"strconv"
|
||
|
"viviman.top/controllers"
|
||
|
"viviman.top/dto"
|
||
|
"viviman.top/models"
|
||
|
"viviman.top/vo"
|
||
|
)
|
||
|
|
||
|
// LiCaiController 财务记录 API
|
||
|
type LiCaiController struct {
|
||
|
controllers.BaseController
|
||
|
}
|
||
|
|
||
|
func (c *LiCaiController) URLMapping() {
|
||
|
c.Mapping("Post", c.Post)
|
||
|
c.Mapping("CpPost", c.CpPost)
|
||
|
c.Mapping("GetAll", c.GetAll)
|
||
|
c.Mapping("Put", c.Put)
|
||
|
c.Mapping("Delete", c.Delete)
|
||
|
}
|
||
|
|
||
|
// GetOne @Title获取单个财务记录
|
||
|
// @Description 获取单个财务记录
|
||
|
// @Param id path int true "角色ID"
|
||
|
// @Success 200 {object} models.Role
|
||
|
// @router /:id [get]
|
||
|
func (c *LiCaiController) GetOne() {
|
||
|
id := c.Ctx.Input.Param(":id")
|
||
|
id64, _ := strconv.ParseInt(id, 10, 64)
|
||
|
role := models.GetOneRole(id64)
|
||
|
c.Data["json"] = controllers.SuccessData(role)
|
||
|
_ = c.ServeJSON()
|
||
|
}
|
||
|
|
||
|
// GetAll @Title角色列表
|
||
|
// @Description 角色列表
|
||
|
// @Success 200 {object} controllers.Result
|
||
|
// @router / [get]
|
||
|
func (c *LiCaiController) GetAll() {
|
||
|
total, list := models.GetAllRole(c.GetParams())
|
||
|
c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total})
|
||
|
_ = c.ServeJSON()
|
||
|
}
|
||
|
|
||
|
// CpPost @Title财务记录复制
|
||
|
// @Description 角色添加
|
||
|
// @Success 200 {object} controllers.Result
|
||
|
// @router / [post]
|
||
|
func (c *LiCaiController) CpPost() {
|
||
|
|
||
|
}
|
||
|
|
||
|
// Post @Title角色添加
|
||
|
// @Description 角色添加
|
||
|
// @Success 200 {object} controllers.Result
|
||
|
// @router / [post]
|
||
|
func (c *LiCaiController) Post() {
|
||
|
var model models.SysRole
|
||
|
valid := validation.Validation{}
|
||
|
json.Unmarshal(c.Ctx.Input.RequestBody, &model)
|
||
|
b, _ := valid.Valid(&model)
|
||
|
if !b {
|
||
|
for _, err := range valid.Errors {
|
||
|
c.Data["json"] = controllers.ErrMsg(err.Message)
|
||
|
}
|
||
|
}
|
||
|
_, e := models.AddRole(&model)
|
||
|
if e != nil {
|
||
|
c.Data["json"] = controllers.ErrMsg(e.Error())
|
||
|
}
|
||
|
c.Data["json"] = controllers.SuccessData("操作成功")
|
||
|
_ = c.ServeJSON()
|
||
|
}
|
||
|
|
||
|
// Put
|
||
|
// @router / [put]
|
||
|
func (c *LiCaiController) Put() {
|
||
|
var model models.SysRole
|
||
|
valid := validation.Validation{}
|
||
|
json.Unmarshal(c.Ctx.Input.RequestBody, &model)
|
||
|
b, _ := valid.Valid(&model)
|
||
|
if !b {
|
||
|
for _, err := range valid.Errors {
|
||
|
c.Data["json"] = controllers.ErrMsg(err.Message)
|
||
|
}
|
||
|
}
|
||
|
e := models.UpdateByRole(&model)
|
||
|
if e != nil {
|
||
|
c.Data["json"] = controllers.ErrMsg(e.Error())
|
||
|
}
|
||
|
c.Data["json"] = controllers.SuccessData("操作成功")
|
||
|
_ = c.ServeJSON()
|
||
|
}
|
||
|
|
||
|
// Delete @Title角色删除
|
||
|
// @Description 角色删除
|
||
|
// @Success 200 {object} controllers.Result
|
||
|
// @router / [delete]
|
||
|
func (c *LiCaiController) Delete() {
|
||
|
var ids []int64
|
||
|
json.Unmarshal(c.Ctx.Input.RequestBody, &ids)
|
||
|
logs.Info(ids)
|
||
|
e := models.DelByRole(ids)
|
||
|
if e != nil {
|
||
|
c.Data["json"] = controllers.ErrMsg(e.Error())
|
||
|
}
|
||
|
c.Data["json"] = controllers.SuccessData("操作成功")
|
||
|
_ = c.ServeJSON()
|
||
|
}
|
||
|
|
||
|
// Menu @Title角色菜单更新
|
||
|
// @Description 角色菜单更新
|
||
|
// @Success 200 {object} controllers.Result
|
||
|
// @router /menu [put]
|
||
|
func (c *LiCaiController) Menu() {
|
||
|
var model dto.RoleMenu
|
||
|
valid := validation.Validation{}
|
||
|
json.Unmarshal(c.Ctx.Input.RequestBody, &model)
|
||
|
logs.Info("=======menu======")
|
||
|
logs.Info(model)
|
||
|
b, _ := valid.Valid(&model)
|
||
|
if !b {
|
||
|
for _, err := range valid.Errors {
|
||
|
c.Data["json"] = controllers.ErrMsg(err.Message)
|
||
|
}
|
||
|
}
|
||
|
models.BatchRoleMenuAdd(model)
|
||
|
c.Data["json"] = controllers.SuccessData("操作成功")
|
||
|
_ = c.ServeJSON()
|
||
|
}
|