Skip to content

Commit

Permalink
feat: Add employee support to bind existing users (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh425 authored Jun 13, 2024
1 parent 6fd656e commit 78056ff
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class AddStaffDto

public GenderTypes Gender { get; set; } = GenderTypes.Male;

public Guid UserId { get; set; }

public AddStaffDto()
{
JobNumber = "";
Expand All @@ -53,7 +55,7 @@ public AddStaffDto()
Avatar = "";
}

public AddStaffDto(string jobNumber, StaffTypes staffType, bool enabled, Guid departmentId, string? position, List<Guid> teams, string? name, string displayName, string avatar, string? idCard, string? companyName, string phoneNumber, string? landline, string? email, AddressValueDto address, string? password, GenderTypes gender)
public AddStaffDto(string jobNumber, StaffTypes staffType, bool enabled, Guid departmentId, string? position, List<Guid> teams, string? name, string displayName, string avatar, string? idCard, string? companyName, string phoneNumber, string? landline, string? email, AddressValueDto address, string? password, GenderTypes gender, Guid userId = default)
{
JobNumber = jobNumber;
StaffType = staffType;
Expand All @@ -72,5 +74,6 @@ public AddStaffDto(string jobNumber, StaffTypes staffType, bool enabled, Guid de
Address = address;
Password = password;
Gender = gender;
UserId = userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"UserEmailNotExist": "User email {0} does not exist",
"UserIdCardExist": "User idCard {0} already exists",
"UserAccountExist": "User account {0} already exists",
"UserStaffExist": "User bound to staff",
"UserAccountPhoneNumberExist": "An account exists with the same phone number {0}",
"AdministratorDeleteError": "administrator cannot delete",
"CurrentUserDeleteError": "The current user cannot delete itself",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"UserEmailNotExist": "Электронная почта пользователя {0} не существует",
"UserIdCardExist": "Удостоверение личности пользователя {0} уже существует",
"UserAccountExist": "Аккаунт пользователя {0} уже существует",
"UserStaffExist": "Пользователи привязывают сотрудников",
"AdministratorDeleteError": "Удаление супер-администратора невозможно",
"CurrentUserDeleteError": "Текущий пользователь не может удалить себя",
"LoginFreeze": "Вы ввели неправильный пароль 5 раз подряд, вход заблокирован. Попробуйте снова через 30 минут",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"UserEmailNotExist": "用户邮箱{0}不存在",
"UserIdCardExist": "用户身份证{0}已存在",
"UserAccountExist": "用户账号{0}已存在",
"UserStaffExist": "用户已绑定员工",
"AdministratorDeleteError": "超级管理员无法删除",
"CurrentUserDeleteError": "当前用户不能删除自己",
"LoginFreeze": "您连续输错密码5次,登录已冻结,请三十分钟后再次尝试",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ public class StaffDomainService : DomainService
{
readonly UserDomainService _userDomainService;
readonly IStaffRepository _staffRepository;
readonly IUserRepository _userRepository;

public StaffDomainService(UserDomainService userDomainService, IStaffRepository staffRepository)
public StaffDomainService(UserDomainService userDomainService, IStaffRepository staffRepository, IUserRepository userRepository)
{
_userDomainService = userDomainService;
_staffRepository = staffRepository;
_userRepository = userRepository;
}

public async Task<Staff> RemoveAsync(Guid Id)
Expand Down Expand Up @@ -43,8 +45,28 @@ await GetPositonId(staffDto.Position),
staffDto.Address
);
staff.SetDepartmentStaff(staffDto.DepartmentId);
await _userDomainService.AddAsync(new User(staffDto.Name, staffDto.DisplayName, staffDto.Avatar, staffDto.Account,

if (staffDto.UserId != default)
{
var user = await _userRepository.FindAsync(x => x.Id == staffDto.UserId);
if (user == null)
{
throw new UserFriendlyException(errorCode: UserFriendlyExceptionCodes.USER_NOT_FOUND);
}
if (user.Staff != null)
{
throw new UserFriendlyException(errorCode: UserFriendlyExceptionCodes.USER_STAFF_EXIST);
}

user.Bind(staff);
await _userRepository.UpdateAsync(user);
}
else
{
await _userDomainService.AddAsync(new User(staffDto.Name, staffDto.DisplayName, staffDto.Avatar, staffDto.Account,
staffDto.Password, staffDto.CompanyName, staffDto.Email, staffDto.PhoneNumber, staff));
}

return staff;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static class UserFriendlyExceptionCodes
public const string USER_ID_CARD_EXIST = "UserIdCardExist";
public const string USER_ACCOUNT_EXIST = "UserAccountExist";
public const string USER_ACCOUNT_PHONE_NUMBER_EXIST = "UserAccountPhoneNumberExist";
public const string USER_STAFF_EXIST = "UserStaffExist";
public const string THIRD_PARTY_IDP_NOT_EXIST = "ThirdPartyIdpNotExist";
public const string ADMINISTRATOR_DELETE_ERROR = "AdministratorDeleteError";
public const string CURRENT_USER_DELETE_ERROR = "CurrentUserDeleteError";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,51 @@
<MStepperContent Step="1">
<AutoHeight AutoClass="d-flex">
<AutoHeightContent>
<div class="ma-auto text-center">
<ButtonGroup @bind-Value="Staff.Gender" StyleType=StyleTypes.Toggle TValue="GenderTypes" />
<br />
<div class="mt-12">
<DefaultChangeImage @bind-Value="Staff.Avatar" Gender="Staff.Gender" WhenFileChangeUpload />
@if (!_isBindUser.HasValue)
{
<div class="d-flex justify-center align-center full-width full-height" style="gap:100px">
<div>
<MHover Context="hoverContext">
<MCard @attributes="hoverContext.Attrs" Height="480" Width="480" Class="@($"{_cardCss} {(hoverContext.Hover ? "primary" : "fill-background")}")" OnClick="()=>_isBindUser=true">
<SIcon Size="hoverContext.Hover?54:36" Color="@(hoverContext.Hover?"fill":"emphasis2")">
mdi-account-check
</SIcon>
<div class="h6 @(hoverContext.Hover?"pt-10 fill--text":"pt-12 regular--text")">
@T("BindUser")
</div>
</MCard>
</MHover>
</div>
<div>
<MHover Context="hoverContext">
<MCard @attributes="hoverContext.Attrs" Height="480" Width="480" Class="@($"{_cardCss} {(hoverContext.Hover ? "primary" : "fill-background")}")" OnClick="()=>_isBindUser=false">
<SIcon Size="hoverContext.Hover?54:36" Color="@(hoverContext.Hover?"fill":"emphasis2")">
mdi-account-plus-outline
</SIcon>
<div class="h6 @(hoverContext.Hover?"pt-10 fill--text":"pt-12 regular--text")">
@T("AddUser")
</div>
</MCard>
</MHover>
</div>
</div>
</div>
}
else if (_isBindUser == false)
{
<div class="ma-auto text-center">
<ButtonGroup @bind-Value="Staff.Gender" StyleType=StyleTypes.Toggle TValue="GenderTypes" />
<br />
<div class="mt-12">
<DefaultChangeImage @bind-Value="Staff.Avatar" Gender="Staff.Gender" WhenFileChangeUpload />
</div>
</div>
}
else
{
<div class="ma-auto text-center">
<SUserAutoComplete Small @bind-Value="Staff.UserId" OnSelectedItemUpdate="SelectUser" />
</div>
}
</AutoHeightContent>
<FooterContent>
<div class="d-flex">
Expand Down Expand Up @@ -79,7 +117,7 @@
</MRow>
<MRow Class="mt-4">
<MCol>
<STextField @bind-Value="@Staff.Password" Required DebounceInterval=500 Label="@T("Password")" Action="SetDefaultPwdAction"/>
<STextField @bind-Value="@Staff.Password" Required DebounceInterval=500 Label="@T("Password")" Action="SetDefaultPwdAction" />
</MCol>
</MRow>
</AutoHeightContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public partial class AddStaffDialog

private MForm _mForm = default!;

private bool? _isBindUser;

private string _cardCss = "d-flex flex-column justify-center align-center ma-auto";

protected override void OnInitialized()
{
PageName = "StaffBlock";
Expand Down Expand Up @@ -58,6 +62,8 @@ private async Task UpdateVisible(bool visible)
{
Visible = visible;
}

_isBindUser = null;
}

public async Task AddStaffAsync(FormContext context)
Expand Down Expand Up @@ -91,5 +97,15 @@ private void SetDefaultPwdAction(DefaultTextfieldAction action)
action.Content = T("Set it to the default password");
action.OnClick = async (_) => await SetDefaultPassword(_mForm.EditContext!);
}

private void SelectUser(UserSelectModel user)
{
Staff.Name = user.Name;
Staff.DisplayName = user.DisplayName;
Staff.Avatar = user.Avatar;
Staff.Account = user.Account;
Staff.Email = user.Email;
Staff.PhoneNumber = user.PhoneNumber ?? string.Empty;
}
}

4 changes: 3 additions & 1 deletion src/Web/Masa.Auth.Web.Admin.Rcl/wwwroot/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@
"StaffBlock": {
"JobNumber": "Job number",
"StaffType": "Staff type",
"StaffSyncTemplate": "Staff sync template"
"StaffSyncTemplate": "Staff sync template",
"AddUser": "Add user",
"BindUser": "Bind user"
},
"RoleBlock": {
"RoleOwner": "Role owner"
Expand Down
2 changes: 2 additions & 0 deletions src/Web/Masa.Auth.Web.Admin.Rcl/wwwroot/i18n/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@
"Male/Female": "Мужчина/Женщина",
"Delete Staff": "Удалить сотрудника",
"Freeze": "Заморозить",
"AddUser": "Новые пользователи",
"BindUser": "Связанные пользователи",
"InternalStaff/ExternalStaff": "Внутренний/Внешний сотрудник",
"Default to internal staff": "По умолчанию внутренний сотрудник",
"Failed to query staffList data:": "Не удалось запросить данные списка сотрудников:",
Expand Down
2 changes: 2 additions & 0 deletions src/Web/Masa.Auth.Web.Admin.Rcl/wwwroot/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@
"Male/Female": "男/女",
"Delete Staff": "删除员工",
"Freeze": "冻结",
"AddUser": "新建用户",
"BindUser": "绑定用户",
"InternalStaff/ExternalStaff": "内部员工/外部员工",
"Default to internal staff": "默认为内部员工",
"Failed to query staffList data:": "获取员工列表数据失败:",
Expand Down

0 comments on commit 78056ff

Please sign in to comment.