sys_role_menu.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package system
  2. import (
  3. "context"
  4. "hongze/fms_api/global"
  5. "time"
  6. )
  7. // 角色和菜单关联表
  8. type SysRoleMenu struct {
  9. RoleMenuId int64 `gorm:"primaryKey;column:role_menu_id" json:"_"` //序号
  10. RoleId int64 `gorm:"column:role_id" json:"role_id"` //角色ID
  11. MenuId int64 `gorm:"column:menu_id" json:"menu_id"` //菜单ID
  12. CreateTime time.Time `gorm:"autoCreateTime;column:create_time" json:"create_time"` //创建时间
  13. ModifyTime time.Time `gorm:"autoUpdateTime:milli;column:modify_time" json:"modify_time"` //最后更新时间
  14. }
  15. // TableName get sql table name.获取数据库表名
  16. func (rm *SysRoleMenu) TableName() string {
  17. return "sys_role_menu"
  18. }
  19. // 批量新增
  20. func (rm *SysRoleMenu) AddMulti(list []*SysRoleMenu) (err error) {
  21. err = global.DEFAULT_MYSQL.CreateInBatches(list, len(list)).Error
  22. return
  23. }
  24. // 删除
  25. func (rm *SysRoleMenu) DeleteByCondition(condition string, pars []interface{}) (err error) {
  26. err = global.DEFAULT_MYSQL.Where(condition, pars...).Delete(rm).Error
  27. return
  28. }
  29. func (rm *SysRoleMenu) GetMenuListByCondition(condition string, pars []interface{}) (results []*SysRoleMenu, err error) {
  30. err = global.DEFAULT_MYSQL.WithContext(context.TODO()).Model(rm).
  31. Table("sys_role_menu as rm ").
  32. Select("rm.*").
  33. Joins("Inner JOIN sys_menu r ON rm.menu_id = r.menu_id").
  34. Where(condition, pars...).Find(&results).Error
  35. return
  36. }