busniess-user-center/internal/repo/menu.go

91 lines
3.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Code generated by sql2gorm. DO NOT EDIT.
package repo
import (
"context"
"time"
"github.com/samber/do"
"gorm.io/gorm"
appModel "busniess-user-center/internal/models/application"
)
func init(){
do.Provide[MenuRepo](nil, NewMenuRepo)
}
// 菜单
type Menu struct {
ID uint `gorm:"column:id;primary_key;AUTO_INCREMENT"` // id
AppCode string `gorm:"column:app_code;NOT NULL"` // 应用code
Code string `gorm:"column:code;NOT NULL"` // 编码
Name string `gorm:"column:name;NOT NULL"` // 名称
ParentCode string `gorm:"column:parent_code;NOT NULL"` // 父级菜单编码
Order int `gorm:"column:order;default:0;NOT NULL"` // 排序
Icon string `gorm:"column:icon;NOT NULL"` // 图标
Path string `gorm:"column:path;NOT NULL"` // 访问路径
ChildPath string `gorm:"column:child_path;NOT NULL"` // 子级路径(前端用)
GoFirstChild int `gorm:"column:go_first_child;default:0;NOT NULL"` // 前端用
IsShow int `gorm:"column:is_show;default:0;NOT NULL"` // 是否显示01
CreatedBy string `gorm:"column:created_by"` // 创建人
CreatedOn time.Time `gorm:"column:created_on;default:CURRENT_TIMESTAMP;NOT NULL"` // 记录创建时间
ModifiedBy string `gorm:"column:modified_by"` // 修改人
ModifiedOn time.Time `gorm:"column:modified_on;default:CURRENT_TIMESTAMP"` // 记录修改时间
}
func (m *Menu) TableName() string {
return "menu"
}
type MenuRepo interface{
GetAppMenus(ctx context.Context,appCode string)([]appModel.Menu,error)
Create(ctx context.Context,menu *Menu)(id uint,err error)
DelMenuById(ctx context.Context,id uint)error
SaveMenu(ctx context.Context,menu *Menu)error
GetMenuById(ctx context.Context,id uint)(menu Menu,err error)
}
type menuRepo struct{
db *gorm.DB
}
func NewMenuRepo(i *do.Injector)(MenuRepo,error){
return &menuRepo{
db: do.MustInvoke[*gorm.DB](i),
}, nil
}
func (m *menuRepo)GetAppMenus(ctx context.Context,appCode string)(menus []appModel.Menu,err error){
dbMenus,err := m.getAppMenu(appCode)
if err != nil{
return
}
menus = makeTreeStructure(dbMenus)
return
}
func (m *menuRepo)getAppMenu(appCode string)(menus []Menu,err error){
err = m.db.Where("app_code = ?",appCode).Find(&menus).Error
return
}
func (m *menuRepo)Create(ctx context.Context,menu *Menu)(id uint,err error){
menu.ID = 0
err = m.db.Create(menu).Error
id = menu.ID
return
}
func (m *menuRepo)DelMenuById(ctx context.Context,id uint)error{
return m.db.Where("id = ?",id).Delete(&Menu{}).Error
}
func (m *menuRepo)SaveMenu(ctx context.Context,menu *Menu)error{
return m.db.Save(&menu).Error
}
func (m *menuRepo)GetMenuById(ctx context.Context,id uint)(menu Menu,err error){
err = m.db.Where("id = ?",id).Take(&menu).Error
return
}