feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -1,18 +1,71 @@
|
||||
package repository
|
||||
|
||||
import "be.ems/src/modules/system/model"
|
||||
import (
|
||||
"be.ems/src/framework/database/db"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/modules/system/model"
|
||||
)
|
||||
|
||||
// ISysUserRole 用户与角色关联表 数据层接口
|
||||
type ISysUserRole interface {
|
||||
// CountUserRoleByRoleId 通过角色ID查询角色使用数量
|
||||
CountUserRoleByRoleId(roleId string) int64
|
||||
// NewSysUserRole 实例化数据层
|
||||
var NewSysUserRole = &SysUserRole{}
|
||||
|
||||
// BatchUserRole 批量新增用户角色信息
|
||||
BatchUserRole(sysUserRoles []model.SysUserRole) int64
|
||||
// SysUserRole 用户与角色关联表 数据层处理
|
||||
type SysUserRole struct{}
|
||||
|
||||
// DeleteUserRole 批量删除用户和角色关联
|
||||
DeleteUserRole(userIds []string) int64
|
||||
|
||||
// DeleteUserRoleByRoleId 批量取消授权用户角色
|
||||
DeleteUserRoleByRoleId(roleId string, userIds []string) int64
|
||||
// ExistUserByRoleId 存在用户使用数量
|
||||
func (r SysUserRole) ExistUserByRoleId(roleId int64) int64 {
|
||||
if roleId <= 0 {
|
||||
return 0
|
||||
}
|
||||
tx := db.DB("").Model(&model.SysUserRole{})
|
||||
tx = tx.Where("role_id = ?", roleId)
|
||||
// 查询数据
|
||||
var count int64 = 0
|
||||
if err := tx.Count(&count).Error; err != nil {
|
||||
logger.Errorf("query find err => %v", err.Error())
|
||||
return count
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// DeleteByUserIds 批量删除关联By用户
|
||||
func (r SysUserRole) DeleteByUserIds(userIds []int64) int64 {
|
||||
if len(userIds) <= 0 {
|
||||
return 0
|
||||
}
|
||||
tx := db.DB("").Where("user_id in ?", userIds)
|
||||
// 执行删除
|
||||
if err := tx.Delete(&model.SysUserRole{}).Error; err != nil {
|
||||
logger.Errorf("delete err => %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// DeleteByRoleId 批量删除关联By角色
|
||||
func (r SysUserRole) DeleteByRoleId(roleId int64, userIds []int64) int64 {
|
||||
if roleId <= 0 || len(userIds) <= 0 {
|
||||
return 0
|
||||
}
|
||||
tx := db.DB("").Where("role_id = ?", roleId).Where("user_id in ?", userIds)
|
||||
// 执行删除
|
||||
if err := tx.Delete(&model.SysUserRole{}).Error; err != nil {
|
||||
logger.Errorf("delete err => %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
// BatchInsert 批量新增信息
|
||||
func (r SysUserRole) BatchInsert(sysUserRoles []model.SysUserRole) int64 {
|
||||
if len(sysUserRoles) <= 0 {
|
||||
return 0
|
||||
}
|
||||
// 执行批量删除
|
||||
tx := db.DB("").CreateInBatches(sysUserRoles, 500)
|
||||
if err := tx.Error; err != nil {
|
||||
logger.Errorf("delete batch err => %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
return tx.RowsAffected
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user