Files
jiacrontab/jiacrontab_admin/group.go
jiazhizhong 1279635d7f fix
2022-03-10 17:09:03 +08:00

67 lines
1.3 KiB
Go

package admin
import (
"jiacrontab/models"
"jiacrontab/pkg/proto"
)
// GetGroupList 获得所有的分组列表
func GetGroupList(ctx *myctx) {
var (
err error
groupList []models.Group
count int64
model = models.DB().Model(&models.Group{})
reqBody GetGroupListReqParams
)
if err = ctx.Valid(&reqBody); err != nil {
ctx.respParamError(err)
return
}
if !ctx.isSuper() {
ctx.respNotAllowed()
return
}
model.Where("name like ?", "%"+reqBody.SearchTxt+"%").Count(&count)
err = model.Where("name like ?", "%"+reqBody.SearchTxt+"%").Offset((reqBody.Page - 1) * reqBody.Pagesize).Order("updated_at desc").Limit(reqBody.Pagesize).Find(&groupList).Error
if err != nil {
ctx.respError(proto.Code_Error, err.Error(), nil)
return
}
ctx.respSucc("", map[string]interface{}{
"list": groupList,
"total": count,
"page": reqBody.Page,
"pagesize": reqBody.Pagesize,
})
}
// EditGroup 编辑分组
func EditGroup(ctx *myctx) {
var (
reqBody EditGroupReqParams
err error
group models.Group
)
if err = ctx.Valid(&reqBody); err != nil {
ctx.respParamError(err)
return
}
group.ID = reqBody.GroupID
group.Name = reqBody.GroupName
if err = group.Save(); err != nil {
ctx.respBasicError(err)
return
}
ctx.pubEvent(group.Name, event_EditGroup, "", reqBody)
ctx.respSucc("", nil)
}