-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from HisKingdom/main
- Loading branch information
Showing
39 changed files
with
1,828 additions
and
21 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/NetCorePal.D3Shop.Admin.Shared/Dtos/Identity/CreateDepartmentUserInfoDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NetCorePal.D3Shop.Admin.Shared.Dtos.Identity | ||
{ | ||
|
||
/// <summary> | ||
/// 创建部门用户信息 | ||
/// </summary> | ||
/// <param name="UserId"></param> | ||
/// <param name="UserName"></param> | ||
public record CreateDepartmentUserInfoDto(AdminUserId UserId, string UserName); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/NetCorePal.D3Shop.Admin.Shared/Dtos/Identity/UpdateDepartmentUserInfoDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NetCorePal.D3Shop.Admin.Shared.Dtos.Identity | ||
{ | ||
|
||
/// <summary> | ||
/// 更新部门用户信息 | ||
/// </summary> | ||
/// <param name="UserId"></param> | ||
/// <param name="UserName"></param> | ||
public record UpdateDepartmentUserInfoDto(AdminUserId UserId, string UserName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/NetCorePal.D3Shop.Admin.Shared/Requests/CreateDepartmentRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using NetCorePal.D3Shop.Admin.Shared.Dtos.Identity; | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.DepartmentAggregate; | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace NetCorePal.D3Shop.Admin.Shared.Requests; | ||
|
||
public class CreateDepartmentRequest | ||
{ | ||
[Required] public string Name { get; set; } = string.Empty; | ||
public string Description { get; set; } = string.Empty; | ||
public DeptId ParentId { get; set; } = new DeptId(0); | ||
|
||
public IEnumerable<CreateDepartmentUserInfoDto> Users { get; set; } = []; | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
src/NetCorePal.D3Shop.Admin.Shared/Requests/DepartmentQueryRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using NetCorePal.Extensions.Dto; | ||
|
||
namespace NetCorePal.D3Shop.Admin.Shared.Requests; | ||
|
||
public class DepartmentQueryRequest : PageRequest | ||
{ | ||
public string? Name { get; set; } | ||
} |
12 changes: 12 additions & 0 deletions
12
src/NetCorePal.D3Shop.Admin.Shared/Requests/UpdateDepartmentInfoRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using NetCorePal.D3Shop.Admin.Shared.Dtos.Identity; | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace NetCorePal.D3Shop.Admin.Shared.Requests; | ||
|
||
public class UpdateDepartmentInfoRequest | ||
{ | ||
[Required] public string Name { get; set; } = string.Empty; | ||
public string Description { get; set; } = string.Empty; | ||
public IEnumerable<CreateDepartmentUserInfoDto> Users { get; set; } = []; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/NetCorePal.D3Shop.Admin.Shared/Responses/DepartmentResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.DepartmentAggregate; | ||
|
||
namespace NetCorePal.D3Shop.Admin.Shared.Responses; | ||
|
||
public class DepartmentResponse(DeptId id, string name, string description) | ||
{ | ||
public DeptId Id { get; } = id; | ||
public string Name { get; set; } = name; | ||
public string Description { get; set; } = description; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/AdminUserAggregate/UserDept.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.DepartmentAggregate; | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate | ||
{ | ||
public class UserDept | ||
{ | ||
protected UserDept() { } | ||
|
||
public AdminUserId AdminUserId { get; private set; } = default!; | ||
public DeptId DeptId { get; private set; } = default!; | ||
public string DeptName { get; private set; } = string.Empty; | ||
|
||
public UserDept(DeptId deptId, string deptName) | ||
{ | ||
DeptId = deptId; | ||
DeptName = deptName; | ||
} | ||
|
||
public void UpdateDeptInfo(string deptName) | ||
{ | ||
DeptName = deptName; | ||
} | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/DepartmentAggregate/Department.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; | ||
using NetCorePal.D3Shop.Domain.DomainEvents.Identity; | ||
using NetCorePal.Extensions.Domain; | ||
using NetCorePal.Extensions.Primitives; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NetCorePal.D3Shop.Domain.AggregatesModel.Identity.DepartmentAggregate | ||
{ | ||
public partial record DeptId : IInt64StronglyTypedId; | ||
|
||
/// <summary> | ||
/// 部门 | ||
/// </summary> | ||
public class Department : Entity<DeptId>, IAggregateRoot | ||
{ | ||
|
||
/// <summary> | ||
/// 部门名称 | ||
/// </summary> | ||
|
||
public string Name { get; private set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// 描述 | ||
/// </summary> | ||
public string Description { get; private set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// 父部门id | ||
/// </summary> | ||
|
||
public DeptId ParentId { get; private set; } = new DeptId(0); | ||
|
||
public DateTime CreatedAt { get; init; } | ||
|
||
public bool IsDeleted { get; private set; } | ||
public DateTime? DeletedAt { get; private set; } | ||
|
||
public virtual ICollection<DepartmentUser> Users { get; } = []; | ||
|
||
|
||
protected Department() | ||
{ | ||
|
||
} | ||
|
||
public Department(string name, string description, DeptId parentId, IEnumerable<DepartmentUser> deptUsers) | ||
{ | ||
Name = name; | ||
Description = description; | ||
ParentId = parentId; | ||
CreatedAt = DateTime.Now; | ||
foreach (var user in deptUsers) | ||
{ | ||
Users.Add(user); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 修改部门信息 | ||
/// </summary> | ||
/// <param name="name"></param> | ||
/// <param name="description"></param> | ||
/// <param name="deptUsers"></param> | ||
public void UpdateDepartInfo(string name, string description, IEnumerable<DepartmentUser> deptUsers) | ||
{ | ||
Name = name; | ||
Description = description; | ||
|
||
var currentUserMap = Users.ToDictionary(r => r.UserId); | ||
var targetUserMap = deptUsers.ToDictionary(r => r.UserId); | ||
|
||
var userIdsToRemove = currentUserMap.Keys.Except(targetUserMap.Keys); | ||
foreach (var userId in userIdsToRemove) | ||
{ | ||
Users.Remove(currentUserMap[userId]); | ||
} | ||
|
||
var userIdsToAdd = targetUserMap.Keys.Except(currentUserMap.Keys); | ||
foreach (var userId in userIdsToAdd) | ||
{ | ||
var targetUser = targetUserMap[userId]; | ||
Users.Add(targetUser); | ||
} | ||
|
||
AddDomainEvent(new DepartmentInfoChangedDomainEvent(this)); | ||
} | ||
|
||
|
||
public void UpdateDepartmentUserName(AdminUserId userId, string userName) | ||
{ | ||
var savedUser = Users.FirstOrDefault(r => r.UserId == userId); | ||
savedUser?.UpdateUserInfo(userName); | ||
} | ||
|
||
|
||
public void Delete() | ||
{ | ||
if (IsDeleted) throw new KnownException("部门已经被删除!"); | ||
IsDeleted = true; | ||
DeletedAt = DateTime.Now; | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/DepartmentAggregate/DepartmentUser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NetCorePal.D3Shop.Domain.AggregatesModel.Identity.DepartmentAggregate | ||
{ | ||
|
||
/// <summary> | ||
/// 部门用户 | ||
/// </summary> | ||
public class DepartmentUser | ||
{ | ||
protected DepartmentUser() | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// 部门id | ||
/// </summary> | ||
public DeptId DeptId { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// 用户名称 | ||
/// </summary> | ||
public string UserName { get; private set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// 部门id | ||
/// </summary> | ||
public AdminUserId UserId { get; set; } = default!; | ||
|
||
public DepartmentUser(string userName, AdminUserId userId) | ||
{ | ||
UserName = userName; | ||
UserId = userId; | ||
} | ||
|
||
public void UpdateUserInfo(string userName) | ||
{ | ||
UserName = userName; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/NetCorePal.D3Shop.Domain/DomainEvents/Identity/DepartmentInfoChangedDomainEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.DepartmentAggregate; | ||
using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; | ||
using NetCorePal.Extensions.Domain; | ||
|
||
namespace NetCorePal.D3Shop.Domain.DomainEvents.Identity; | ||
|
||
public record DepartmentInfoChangedDomainEvent(Department Department) : IDomainEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.