12345678910111213141516171819202122232425262728293031323334353637383940 |
- package crm
- import (
- "hongze/hz_crm_eta/global"
- "time"
- )
- // SysRoleAdmin 管理员和角色映射表
- type SysRoleAdmin struct {
- Id int `gorm:"primaryKey;column:id;type:int(11);not null" json:"id"`
- RoleId int `gorm:"column:role_id;type:int(11);not null" json:"role_id"` // 角色Id
- AdminId int `gorm:"column:admin_id;type:bigint(20);not null" json:"admin_id"` // 管理后台账号Id
- CreateTime time.Time `gorm:"column:create_time;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"create_time"` // 创建时间
- }
- func (m *SysRoleAdmin) TableName() string {
- return "sys_role_admin"
- }
- func (m *SysRoleAdmin) DeleteAndCreate(adminId int, roleIds []int, items []*SysRoleAdmin) (err error) {
- tx := global.MYSQL["hz_crm"].Begin()
- defer func() {
- if err != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- sql := `DELETE FROM sys_role_admin WHERE admin_id = ? AND role_id IN (?)`
- tx.Exec(sql, adminId, roleIds)
- if len(items) > 0 {
- err = tx.CreateInBatches(items, len(items)).Error
- if err != nil {
- return
- }
- }
- return
- }
|