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.
48 lines
1.4 KiB
48 lines
1.4 KiB
package manage
|
|
|
|
import (
|
|
"recook/internal/v2/lib/db"
|
|
)
|
|
|
|
type RecookManageRoleCategoryModel struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id;primary_key" json:"id"`
|
|
RoleId uint `json:"roleId"`
|
|
CategoryId uint `json:"categoryId"`
|
|
}
|
|
|
|
// TableName sets the insert table name for this struct type
|
|
func (r *RecookManageRoleCategoryModel) TableName() string {
|
|
return "recook_manage_role_category"
|
|
}
|
|
|
|
// @Style 添加
|
|
func (r *RecookManageRoleCategoryModel) Create(data *RecookManageRoleCategoryModel) {
|
|
r.GetDb().Create(data)
|
|
}
|
|
|
|
// @Style 批量添加
|
|
func (r *RecookManageRoleCategoryModel) CreateAll(datas *[]RecookManageRoleCategoryModel) error {
|
|
valueStr := ""
|
|
values := []interface{}{}
|
|
for _, item := range *datas {
|
|
valueStr += ",(?,?)"
|
|
values = append(values, item.CategoryId, item.RoleId)
|
|
}
|
|
if len(values) > 0 {
|
|
return r.GetDb().Exec("insert into recook_manage_role_category(category_id, role_id) values "+valueStr[1:], values...).Error
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// @Style 删除
|
|
func (r *RecookManageRoleCategoryModel) DeleteByRoleId(roleId uint) error {
|
|
return r.GetDb().Delete(&RecookManageRoleCategoryModel{}, "role_id = ?", roleId).Error
|
|
}
|
|
|
|
// @Style 删除
|
|
func (r *RecookManageRoleCategoryModel) FindByRoleId(roleId uint) (result []RecookManageRoleCategoryModel) {
|
|
r.GetDb().Model(&RecookManageRoleCategoryModel{}).Find(&result, "role_id = ?", roleId)
|
|
return
|
|
}
|