fix
This commit is contained in:
@@ -1,2 +1,23 @@
|
||||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
import "context"
|
||||
|
||||
func (gm *LdapGroupMenusModel) FindOne(ctx context.Context, menuId, groupId int64) (resp *LdapGroupMenus, err error) {
|
||||
err = gm.db.WithContext(ctx).Model(&LdapGroupMenus{}).Where("menu_id = ? and group_id = ?", menuId, groupId).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (gm *LdapGroupMenusModel) Create(ctx context.Context, data *LdapGroupMenus) error {
|
||||
return gm.db.WithContext(ctx).Model(&LdapGroupMenus{}).Create(&data).Error
|
||||
}
|
||||
|
||||
func (gm *LdapGroupMenusModel) Delete(ctx context.Context, menuId, groupId int64) error {
|
||||
return gm.db.WithContext(ctx).Model(&LdapGroupMenus{}).Where("menu_id = ? and group_id", menuId, groupId).Delete(&LdapGroupMenus{}).Error
|
||||
}
|
||||
|
||||
func (gm *LdapGroupMenusModel) DeleteByMenuId(ctx context.Context, menuId int64) error {
|
||||
return gm.db.WithContext(ctx).Model(&LdapGroupMenus{}).Where("menu_id = ?", menuId).Delete(&LdapGroupMenus{}).Error
|
||||
}
|
||||
func (gm *LdapGroupMenusModel) DeleteByGroupId(ctx context.Context, groupId int64) error {
|
||||
return gm.db.WithContext(ctx).Model(&LdapGroupMenus{}).Where("group_id = ?", groupId).Delete(&LdapGroupMenus{}).Error
|
||||
}
|
||||
|
||||
@@ -18,3 +18,46 @@ func (m *LdapMenusModel) FindByPath(ctx context.Context, path string) (resp *Lda
|
||||
func (m *LdapMenusModel) Update(ctx context.Context, id int64, data *LdapMenus) error {
|
||||
return m.db.WithContext(ctx).Model(&LdapMenus{}).Where("id = ?", id).Updates(&data).Error
|
||||
}
|
||||
|
||||
type GetMenuListByParamReq struct {
|
||||
Ids []int64
|
||||
Name string
|
||||
Title string
|
||||
Path string
|
||||
Status *int64
|
||||
ParentId *int64
|
||||
Sort string
|
||||
Page int
|
||||
Limit int
|
||||
}
|
||||
|
||||
func (m *LdapMenusModel) GetMenuListByParam(ctx context.Context, req GetMenuListByParamReq) (resp []LdapMenus, total int64, err error) {
|
||||
db := m.db.WithContext(ctx).Model(&LdapMenus{})
|
||||
if len(req.Ids) > 0 {
|
||||
db = db.Where("id in(?)", req.Ids)
|
||||
}
|
||||
if req.Name != "" {
|
||||
db = db.Where("name like ?", "%"+req.Name+"%")
|
||||
}
|
||||
if req.Title != "" {
|
||||
db = db.Where("title like ?", "%"+req.Title+"%")
|
||||
}
|
||||
if req.Name != "" {
|
||||
db = db.Where("path like ?", "%"+req.Path+"%")
|
||||
}
|
||||
if req.Status != nil {
|
||||
db = db.Where("status = ?", req.Status)
|
||||
}
|
||||
if req.ParentId != nil {
|
||||
db = db.Where("parent_id = ?", req.ParentId)
|
||||
}
|
||||
if req.Sort != "" {
|
||||
db = db.Order(req.Sort)
|
||||
}
|
||||
if err = db.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
offset := (req.Page - 1) * req.Limit
|
||||
err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error
|
||||
return resp, total, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user