...
|
...
|
@@ -27,12 +27,6 @@ func (adminUserSrv AdminUserService) GetAdminUser(getAdminUserQuery *query.GetAd |
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
// return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// transactionContext.RollbackTransaction()
|
|
|
// }()
|
|
|
var (
|
|
|
adminuserRepository domain.AdminUserRepository
|
|
|
adminuser *domain.AdminUser
|
...
|
...
|
@@ -104,7 +98,7 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi |
|
|
}
|
|
|
permissionBases = append(permissionBases, p)
|
|
|
}
|
|
|
|
|
|
var accountChance bool
|
|
|
if saveUserCmd.Id > 0 {
|
|
|
adminuser, err = adminuserRepository.FindOne(domain.AdminUserFindOneQuery{
|
|
|
AdminUserId: saveUserCmd.Id,
|
...
|
...
|
@@ -112,12 +106,16 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi |
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if adminuser.Account != saveUserCmd.Account {
|
|
|
accountChance = true
|
|
|
}
|
|
|
adminuser.Account = saveUserCmd.Account
|
|
|
adminuser.AdminName = saveUserCmd.Name
|
|
|
adminuser.IsUsable = saveUserCmd.IsUsable
|
|
|
adminuser.Permission = permissionBases
|
|
|
|
|
|
} else {
|
|
|
accountChance = true
|
|
|
defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456")))
|
|
|
adminuser = &domain.AdminUser{
|
|
|
Id: saveUserCmd.Id,
|
...
|
...
|
@@ -128,6 +126,27 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi |
|
|
Permission: permissionBases,
|
|
|
}
|
|
|
}
|
|
|
if accountChance {
|
|
|
//检查账号是否已存在
|
|
|
var (
|
|
|
adminuserDao *dao.AdminUserDao
|
|
|
)
|
|
|
if v, err := factory.CreateAdminUserkDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
adminuserDao = v
|
|
|
}
|
|
|
ok, err := adminuserDao.AdminUserAccountExist(saveUserCmd.Account)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if ok {
|
|
|
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
adminuser, err = adminuserRepository.Save(adminuser)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -141,12 +160,6 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query |
|
|
if err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
// if err := transactionContext.StartTransaction(); err != nil {
|
|
|
// return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// transactionContext.RollbackTransaction()
|
|
|
// }()
|
|
|
var (
|
|
|
adminuserRepository domain.AdminUserRepository
|
|
|
adminusers []domain.AdminUser
|
...
|
...
|
@@ -173,7 +186,6 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query |
|
|
if err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext.CommitTransaction()
|
|
|
return adminusers, cnt, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -228,6 +240,11 @@ func (adminUserSrv AdminUserService) UpdateAdminIsUsable(uid int64, isUsable boo |
|
|
} else {
|
|
|
adminuserDao = v
|
|
|
}
|
|
|
if ok, err := adminuserDao.AdminUserIsDefault(uid); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else if ok {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "请勿禁用超级管理员")
|
|
|
}
|
|
|
err = adminuserDao.UpdateIsUsable(uid, isUsable)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
|