sqlx
This commit is contained in:
@@ -29,5 +29,15 @@ func (b *auditLogService) BatchCreate(ctx context.Context, objs []*system.AuditL
|
||||
}
|
||||
|
||||
func (b *auditLogService) List(ctx context.Context, q dto.SearchDto) ([]*system.AuditLog, int64, error) {
|
||||
return b.repo.List(ctx, q)
|
||||
count, err := b.repo.Count(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, err := b.repo.List(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return res, count, nil
|
||||
}
|
||||
|
||||
@@ -41,7 +41,17 @@ func (s *configService) Get(ctx context.Context, id int32) (*system.Config, erro
|
||||
}
|
||||
|
||||
func (s *configService) List(ctx context.Context, q dto.SearchDto) ([]*system.Config, int64, error) {
|
||||
return s.repo.List(ctx, q)
|
||||
count, err := s.repo.Count(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, err := s.repo.List(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return res, count, nil
|
||||
}
|
||||
|
||||
func (s *configService) Pear(ctx context.Context) (*dto.PearConfig, error) {
|
||||
|
||||
@@ -115,7 +115,17 @@ func (s *departmentService) All(ctx context.Context) ([]*system.Department, erro
|
||||
}
|
||||
|
||||
func (s *departmentService) List(ctx context.Context, q dto.SearchDto) ([]*system.Department, int64, error) {
|
||||
return s.repo.List(ctx, q)
|
||||
count, err := s.repo.Count(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, err := s.repo.List(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return res, count, nil
|
||||
}
|
||||
|
||||
func (s *departmentService) RefreshCache(ctx context.Context) error {
|
||||
|
||||
@@ -25,7 +25,17 @@ func (s *loginLogService) Create(ctx context.Context, req *system.LoginLog) erro
|
||||
}
|
||||
|
||||
func (s *loginLogService) List(ctx context.Context, q dto.SearchDto) ([]*system.LoginLog, int64, error) {
|
||||
return s.repo.List(ctx, q)
|
||||
count, err := s.repo.Count(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, err := s.repo.List(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return res, count, nil
|
||||
}
|
||||
|
||||
func (s *loginLogService) LoginTime(ctx context.Context, email string) (dto.LoginTimeDto, error) {
|
||||
@@ -45,7 +55,9 @@ func (s *loginLogService) LoginTime(ctx context.Context, email string) (dto.Logi
|
||||
}
|
||||
|
||||
func (s *loginLogService) LoginCount(ctx context.Context, email string) int64 {
|
||||
count, err := s.repo.Count(ctx, email)
|
||||
count, err := s.repo.Count(ctx, dto.SearchDto{
|
||||
SearchEmail: email,
|
||||
})
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"management/internal/erpserver/model/dto"
|
||||
"management/internal/erpserver/model/system"
|
||||
"management/internal/erpserver/model/view"
|
||||
"management/internal/erpserver/repository"
|
||||
"management/internal/erpserver/service/util"
|
||||
"management/internal/erpserver/service/v1"
|
||||
"management/internal/pkg/know"
|
||||
@@ -178,15 +179,15 @@ func (s *menuService) MenuViewData(ctx context.Context, roleID int32) ([]*dto.Se
|
||||
|
||||
func (s *menuService) SetRoleMenu(ctx context.Context, roleID int32, rms []*system.RoleMenu) error {
|
||||
// 开启事务
|
||||
return s.Tx.Transaction(ctx, func(ctx context.Context) error {
|
||||
return repository.Transaction(ctx, s.Log, func(c context.Context) error {
|
||||
// 先删除该角色的所有权限
|
||||
err := s.roleMenuService.DeleteByRoleID(ctx, roleID)
|
||||
err := s.roleMenuService.DeleteByRoleID(c, roleID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 再添加该角色的所有权限
|
||||
return s.roleMenuService.Create(ctx, rms)
|
||||
return s.roleMenuService.Create(c, rms)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,17 @@ func (s *roleService) All(ctx context.Context) ([]*system.Role, error) {
|
||||
}
|
||||
|
||||
func (s *roleService) List(ctx context.Context, q dto.SearchDto) ([]*system.Role, int64, error) {
|
||||
return s.repo.List(ctx, q)
|
||||
count, err := s.repo.Count(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, err := s.repo.List(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return res, count, nil
|
||||
}
|
||||
|
||||
func (s *roleService) RefreshCache(ctx context.Context) error {
|
||||
|
||||
@@ -22,22 +22,25 @@ import (
|
||||
|
||||
type userService struct {
|
||||
*v1.Service
|
||||
repo system.UserRepository
|
||||
roleService v1.RoleService
|
||||
loginLogService v1.LoginLogService
|
||||
repo system.UserRepository
|
||||
roleService v1.RoleService
|
||||
departmentService v1.DepartmentService
|
||||
loginLogService v1.LoginLogService
|
||||
}
|
||||
|
||||
func NewUserService(
|
||||
service *v1.Service,
|
||||
repo system.UserRepository,
|
||||
roleService v1.RoleService,
|
||||
departmentService v1.DepartmentService,
|
||||
loginLogService v1.LoginLogService,
|
||||
) v1.UserService {
|
||||
return &userService{
|
||||
Service: service,
|
||||
repo: repo,
|
||||
roleService: roleService,
|
||||
loginLogService: loginLogService,
|
||||
Service: service,
|
||||
repo: repo,
|
||||
roleService: roleService,
|
||||
departmentService: departmentService,
|
||||
loginLogService: loginLogService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +114,22 @@ func (s *userService) All(ctx context.Context) ([]*system.User, error) {
|
||||
}
|
||||
|
||||
func (s *userService) List(ctx context.Context, q dto.SearchDto) ([]*system.User, int64, error) {
|
||||
return s.repo.List(ctx, q)
|
||||
count, err := s.repo.Count(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, err := s.repo.List(ctx, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
for _, user := range res {
|
||||
user.Role, _ = s.roleService.Get(ctx, user.RoleID)
|
||||
user.Department, _ = s.departmentService.Get(ctx, user.DepartmentID)
|
||||
}
|
||||
|
||||
return res, count, nil
|
||||
}
|
||||
|
||||
func (s *userService) Get(ctx context.Context, id int32) (*system.User, error) {
|
||||
|
||||
Reference in New Issue
Block a user