From 40539c831b22a68e1ad470f50b691f967c21730c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E5=BB=BA=E7=A5=A5?= <958464639@qq.com> Date: Sun, 7 Jul 2024 21:40:40 +0800 Subject: [PATCH] =?UTF-8?q?7.1-1.5=E7=AC=94=E8=AE=B0=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\274\217\345\255\246\344\271\240 copy.md" | 24 +++ ...55\347\232\204\345\256\236\344\275\223.md" | 148 ++++++++++++++++++ ...23\347\232\204\350\277\236\346\216\245.md" | 12 ++ ...43\345\217\212\345\256\236\347\216\260.md" | 33 ++++ ...72\347\232\204\347\273\247\346\211\277.md" | 6 + 5 files changed, 223 insertions(+) create mode 100644 "\345\215\242\345\273\272\347\245\245/20240701-\345\256\236\350\256\255\347\254\254\344\270\200\345\244\251_ddd\346\240\274\345\274\217\345\255\246\344\271\240 copy.md" create mode 100644 "\345\215\242\345\273\272\347\245\245/20240702-\345\256\232\344\271\211Domain\344\270\255\347\232\204\345\256\236\344\275\223.md" create mode 100644 "\345\215\242\345\273\272\347\245\245/20240703-\344\276\235\350\265\226\345\256\211\350\243\205\347\232\204\344\275\215\347\275\256\344\273\245\345\217\212 postgreSQL \346\225\260\346\215\256\345\272\223\347\232\204\350\277\236\346\216\245.md" create mode 100644 "\345\215\242\345\273\272\347\245\245/20240704-\346\216\245\345\217\243\345\217\212\345\256\236\347\216\260.md" create mode 100644 "\345\215\242\345\273\272\347\245\245/20240705-\350\241\214\344\270\272\347\232\204\347\273\247\346\211\277.md" diff --git "a/\345\215\242\345\273\272\347\245\245/20240701-\345\256\236\350\256\255\347\254\254\344\270\200\345\244\251_ddd\346\240\274\345\274\217\345\255\246\344\271\240 copy.md" "b/\345\215\242\345\273\272\347\245\245/20240701-\345\256\236\350\256\255\347\254\254\344\270\200\345\244\251_ddd\346\240\274\345\274\217\345\255\246\344\271\240 copy.md" new file mode 100644 index 0000000..30f1f30 --- /dev/null +++ "b/\345\215\242\345\273\272\347\245\245/20240701-\345\256\236\350\256\255\347\254\254\344\270\200\345\244\251_ddd\346\240\274\345\274\217\345\255\246\344\271\240 copy.md" @@ -0,0 +1,24 @@ +## ddd格式学习及创建 + +> 可以课外学习了解:abp vnext、orm 工具、领域驱动、ddd(领域驱动设计,架构设计方法论)、导航属性 +> 明天使用 flunt api 验证 + +- 创建一个项目(中大型项目分层级) + - (`Admin.Api`):`创建 WebApi` + - dotnet new webapi -n 命名.Api + - (`Admin.Api.Domain`):`创建一个领域层`(实体、值对象、领域服务、规约、仓储接口) + - dotnet new classlib -n 命名.Domain + - (`Admin.Api.Application`):`创建一个应用层/服务层` + - dotnet new classlib -n 命名.Application + - (`Admin.Api.Application.Contracts`):`创建一个应用接口和 Dto` + - dotnet new classlib -n 命名.Application.Contracts + - (`Admin.Api.Infrastructure`):`创建基础设施层` + - dotnet new classlib -n 命名.Infrastructure + - (`Admin.Api.Infrastructure.EntityFrameworkCore`):`orm 工具层` + - dotnet new classlib -n 命名.Infrastructure.EntityFrameworkCore + - (`Admin.sln`):`创建解决方案` + - dotnet new sln -n 命名 + - 添加项目到解决方案 + - dotnet sln 命名.sln `add` 命名.Api/ + - 项目之间的添加 + - dotnet `add` 要添加名 `reference` 被添加名 diff --git "a/\345\215\242\345\273\272\347\245\245/20240702-\345\256\232\344\271\211Domain\344\270\255\347\232\204\345\256\236\344\275\223.md" "b/\345\215\242\345\273\272\347\245\245/20240702-\345\256\232\344\271\211Domain\344\270\255\347\232\204\345\256\236\344\275\223.md" new file mode 100644 index 0000000..c493a94 --- /dev/null +++ "b/\345\215\242\345\273\272\347\245\245/20240702-\345\256\232\344\271\211Domain\344\270\255\347\232\204\345\256\236\344\275\223.md" @@ -0,0 +1,148 @@ +## 定义 Domai 中的实体 + +- Domain 层 + + 1. 创建继承类 BaseEntity + + ```csharp + //继承的对象 + public abstract class BaseEntity + { + public Guid Id { get; set; } + public DateTime CreationTime { get; set; }//创建时间 + public DateTime? LastModificationTime { get; set; }//最后更改时间 + public Guid? CreatorUserId { get; set; }//创建人 + public Guid? LastModifierUserId { get; set; } + public bool IsActive { get; set; }//是否启用 + public bool IsDeleted { get; set; }//是否删除 + } + ``` + + 2. 创建实体类 user + + ```csharp + public class AppUser : Entity + { + public string Name { get; set; }//名字 + public string Password { get; set; }//密码 + public string Email { get; set; }//邮箱 + public string Phone { get; set; }//电话 + public string Avatar { get; set; }//头像 + public string Address { get; set; }//地址 + public string Description { get; set; }//描述 + public string Role { get; set; }//角色 + public string Status { get; set; }//状态 + public string Salt { get; set; }//随机数 + //角色新增 + public void AddUser(AppRole appRole) + { + _appRoles.Add(appRole); + } + //角色删除(传角色对象删除) + public void RemoveUser(AppRole appRole) + { + _appRoles.Remove(appRole); + } + //角色删除(传角色名删除) + public void RemoveUser(string RoleName) + { + var appRole = _appRoles.FirstOrDefault(x => x.RoleName == RoleName); + if (appRole != null) + { + _appRoles.Remove(appRole); + } + } + //角色判断是否存在 + public bool HasPermission(AppRole appRole) + { + return true; + } + } + ``` + + 3. 创建权限表 permission + + ```csharp + public class AppPermission : Entity + { + public string Name { get; set; }//权限名称 + public string Description { get; set; }//权限描述 + public string Code { get; set; }//权限码 + public string Status { get; set; }//状态 + public string Role { get; set; }//角色 + public string Type { get; set; }//类型 + public string Category { get; set; }//分类 + public string Icon { get; set; }//图标 + public string Url { get; set; }//地址 + public string ParentId { get; set; }//父级id + public string ParentName { get; set; }//父级名称 + + public AppPermission(){} + public AppPermission(string permissionName,string permissionDescription) + { + PermissionName = permissionName; + PermissionDescription = permissionDescription; + } + } + ``` + + 4. 创建 Operation(操作) + + ```csharp + public class AppOperation : Entity + { + public string Name { get; set; }//操作名称 + public string Description { get; set; }//操作描述 + public string Code { get; set; }//操作码 + } + ``` + + 5. 创建 resource(资源) + + ```csharp + public class AppResource : Entity + { + public string Name { get; set; }//资源名称 + public string Description { get; set; }//资源描述 + public string Code { get; set; }//资源码 + } + ``` + + 6. 创建 role.cs + + ```csharp + public class AppRole : Entity + { + public string Name { get; set; }//角色名称 + public string Description { get; set; }//角色描述 + public string Code { get; set; }//角色码 + public string Status { get; set; }//状态 + public string Type { get; set; }//类型 + public string Category { get; set; }//分类 + //分配权限 + public void RoleAddPermission(AppPermission appPermission) + { + + } + //移除权限 + public void RoleRemovePermission(AppPermission appPermission) + { + + } + //判断是否有权限 + public bool HasPermission(AppOperation appOperation,AppResource appResource) + { + return true; + } + } + ``` + + 7. 创建 rolePermission + + ```csharp + public class RolePermission + { + public string RoleId { get; set; }//角色id + public string PermissionId { get; set; }//权限id + } + ``` diff --git "a/\345\215\242\345\273\272\347\245\245/20240703-\344\276\235\350\265\226\345\256\211\350\243\205\347\232\204\344\275\215\347\275\256\344\273\245\345\217\212 postgreSQL \346\225\260\346\215\256\345\272\223\347\232\204\350\277\236\346\216\245.md" "b/\345\215\242\345\273\272\347\245\245/20240703-\344\276\235\350\265\226\345\256\211\350\243\205\347\232\204\344\275\215\347\275\256\344\273\245\345\217\212 postgreSQL \346\225\260\346\215\256\345\272\223\347\232\204\350\277\236\346\216\245.md" new file mode 100644 index 0000000..567fc7e --- /dev/null +++ "b/\345\215\242\345\273\272\347\245\245/20240703-\344\276\235\350\265\226\345\256\211\350\243\205\347\232\204\344\275\215\347\275\256\344\273\245\345\217\212 postgreSQL \346\225\260\346\215\256\345\272\223\347\232\204\350\277\236\346\216\245.md" @@ -0,0 +1,12 @@ +## 依赖安装的位置以及 postgreSQL 数据库的连接 + +> flunt api + +1. EntityFrameworkCore + +- 安装依赖包 + - Admin.Api.EntityFrameworkCore + - Microsoft.EntityFrameworkCore + - Admin.Api + - Microsoft.EntityFrameworkCore.Design + - Npgsql.EntityFrameworkCore.PostgreSQL diff --git "a/\345\215\242\345\273\272\347\245\245/20240704-\346\216\245\345\217\243\345\217\212\345\256\236\347\216\260.md" "b/\345\215\242\345\273\272\347\245\245/20240704-\346\216\245\345\217\243\345\217\212\345\256\236\347\216\260.md" new file mode 100644 index 0000000..87ec2d6 --- /dev/null +++ "b/\345\215\242\345\273\272\347\245\245/20240704-\346\216\245\345\217\243\345\217\212\345\256\236\347\216\260.md" @@ -0,0 +1,33 @@ +## 接口及实现 + +> 任务:1、理解流程 2、继续去完善 + +- 数据库(Navicat Premium Lite) + +1. 设计控制器 + +- 如果实体有自己的行为,当自己无法单独满足时,则可以将行为放到领域服务层 + +2. Admin2024.Application.Contracts(契约,约束数据) + +- AppUser + - 命名规则(AppService 结尾) + - + +3. Admin2024.Application(服务,实现类) + +- AppUser + - 命名(AppService 结尾) + +4. Admin2024.EntityFrameworkCore + +- Repository + + ```csharp + + ``` + +1. Domain + +- 定义实例模型 +- 定义行为待继承的类(System 中都继承它) diff --git "a/\345\215\242\345\273\272\347\245\245/20240705-\350\241\214\344\270\272\347\232\204\347\273\247\346\211\277.md" "b/\345\215\242\345\273\272\347\245\245/20240705-\350\241\214\344\270\272\347\232\204\347\273\247\346\211\277.md" new file mode 100644 index 0000000..7b06f2e --- /dev/null +++ "b/\345\215\242\345\273\272\347\245\245/20240705-\350\241\214\344\270\272\347\232\204\347\273\247\346\211\277.md" @@ -0,0 +1,6 @@ +## 行为的继承 + +> JWT(正常生成 token sesion cookies(前端如何保存 Take 数据)) 后端拿到用户信息 种子数据(管理员)//雪花算法 + +- 公共基类 virtual +- 继承基类 override`base.OnActionExecuting(context); ` -- Gitee