Compare commits

..

483 Commits

Author SHA1 Message Date
chenchun
bb894e14a4 Merge remote-tracking branch 'origin/card-flip' into card-flip
# Conflicts:
#	Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs
2025-11-17 11:22:44 +08:00
chenchun
b492d82442 Merge branch 'abp' into card-flip
# Conflicts:
#	Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
#	Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs
#	Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain.Shared/Caches/FileCacheItem.cs
#	Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json
2025-11-17 11:21:14 +08:00
chenchun
5eaffe2ec2 feat: 新增更新并发乐观锁配置与支持
- 在 DbConnOptions 新增 EnabledConcurrencyException(bool,默认 false) 配置项。
- 在 SqlSugarRepository 引入 IAbpLazyServiceProvider,通过 IOptions<DbConnOptions> 延迟获取配置。
- UpdateAsync 改为仅当 EnabledConcurrencyException 为 true 且实体实现 IHasConcurrencyStamp 时,使用 ExecuteCommandWithOptLockAsync 并捕获 VersionExceptions 抛出 AbpDbConcurrencyException;否则回退到原有的 UpdateAsync 实现。
- 清理/调整部分 using 引用,新增 Microsoft.Extensions.Options 与 Volo.Abp.DependencyInjection 引用。

注意:默认值为 false,需在配置中显式开启 EnabledConcurrencyException 才会启用乐观并发校验,开启后会改变之前对带版本实体自动使用乐观锁的行为。
2025-11-17 11:19:15 +08:00
Gsh
d7bcad9da7 feat: 前端打包报错处理 2025-11-17 02:03:10 +08:00
Gsh
04e11d15e2 feat: 新手引导优化 2025-11-17 01:39:13 +08:00
Gsh
97e3dc5eed feat: 公告弹窗优化 2025-11-17 01:20:20 +08:00
Gsh
695bd56a27 feat: 增加新手引导 2025-11-17 01:05:57 +08:00
ccnetcore
7919383be3 feat: 完成v2.3.0发布 2025-11-17 00:43:41 +08:00
ccnetcore
d6cc3c5d96 Merge branch 'abp' into card-flip
# Conflicts:
#	Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs
#	Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain.Shared/Caches/FileCacheItem.cs
2025-11-17 00:43:27 +08:00
Gsh
19f0d05a69 fix: 尊享明细表格优化 2025-11-16 23:00:19 +08:00
Gsh
3c5e575e9b fix: 公告优化 2025-11-16 22:39:42 +08:00
Gsh
f875617de1 fix: 版本号2.3 2025-11-16 22:05:44 +08:00
Gsh
9976e8a6e2 fix: 翻牌机制优化 2025-11-16 22:05:01 +08:00
Gsh
38e8cbc5ca fix: 优化邀请 2025-11-16 21:50:54 +08:00
Gsh
d95c14c903 fix: 优化尊享包记录 2025-11-16 21:39:08 +08:00
ccnetcore
ffb2f2fb4c fix: 修复尊享包查询条件并新增时间范围筛选 2025-11-16 21:32:41 +08:00
ccnetcore
4bd2fc357d refactor: 邀请码逻辑调整,支持双方填写/使用邀请码统计,并移除已被邀请状态字段 2025-11-14 23:53:29 +08:00
chenchun
da23d17af8 feat: 为尊享包 Token 列表新增按是否免费过滤并添加请求 DTO
- 新增 PremiumTokenUsageGetListInput,包含 IsFree 过滤项并继承分页 DTO
- 修改 UsageStatisticsService.GetPremiumTokenUsageListAsync 签名为使用新的输入 DTO,并根据 IsFree 添加 WhereIF 过滤
- 微调 DTO 导入与格式化(PremiumTokenUsageGetListOutput)
2025-11-14 18:00:49 +08:00
chenchun
c1a6046107 feat: 完成公告、尊享记录功能 2025-11-14 17:54:40 +08:00
chenchun
2ec7b5f4fd fix: 修复软删除时空引用异常
在 SqlSugarRepository.cs 中对 ISoftDelete 分支增加 GetByIdAsync 返回 null 的判断,避免在实体为 null 时继续反射赋值导致 NullReferenceException。若实体不存在,直接返回 false。
2025-11-13 16:49:44 +08:00
Gsh
d21f61646a fix: 系统公告与尊享额度明细 2025-11-12 23:08:52 +08:00
chenchun
eecdf442fb feat: 新增公告跳转链接字段 Url
- 在 AnnouncementAggregateRoot、AnnouncementLogDto、AnnouncementCacheDto 中新增 string? Url 属性,用于存储公告的跳转链接。
- 如果需要持久化到数据库,请同步添加对应的迁移/映射配置。
2025-11-12 21:49:31 +08:00
chenchun
1b4c3cbb8d feat: 支持尊享包用量统计 2025-11-10 15:18:05 +08:00
chenchun
b7756e2112 feat: 新增功能
- 概要
  - 重构并扩展公告相关模型、DTO、服务,新增公告类型、图片与时间字段,调整缓存与查询处理。
  - 新增枚举 AnnouncementTypeEnum。

- 主要改动(简要)
  - Yi.Framework.AiHub.Application.Contracts/Dtos/Announcement/AnnouncementLogDto.cs
    - 新增 ImageUrl、StartTime、EndTime、Type 字段,移除 Date 字段,Title 不再默认空串。
  - Yi.Framework.AiHub.Domain/Entities
    - 重命名 AnnouncementLogAggregateRoot -> AnnouncementAggregateRoot
    - 表名由 Ai_AnnouncementLog 改为 Ai_Announcement(SugarTable 标注)
    - 新增 ImageUrl、StartTime、EndTime、Type、Remark 字段(Remark 已存在,保持)
  - Yi.Framework.AiHub.Domain.Shared/Enums/AnnouncementTypeEnum.cs
    - 新增枚举文件(Activity=1, System=2)
  - Yi.Framework.AiHub.Application.Contracts/IServices/IAnnouncementService.cs
    - GetAsync 返回类型由 AnnouncementOutput 改为 List<AnnouncementLogDto>
  - Yi.Framework.AiHub.Application/Services/AnnouncementService.cs
    - 使用 Mapster 进行 DTO 映射
    - 查询按 StartTime 降序,返回 List<AnnouncementLogDto>,缓存结构简化
  - Yi.Abp.Web/YiAbpWebModule.cs
    - 改为初始化 AnnouncementAggregateRoot 的表(Ai_Announcement)
  - Yi.Ai.Vue3/types/import_meta.d.ts
    - 移除 VITE_BUILD_COMPRESS 环境变量声明

- 重要注意/兼容性提示
  - 接口变更:IAnnouncementService.GetAsync 返回类型已改变,调用方需同步更新(之前返回 AnnouncementOutput 的代码需调整)。
  - 数据库表变更:表名从 Ai_AnnouncementLog -> Ai_Announcement,若需保留历史数据,请在部署前做好数据迁移(重命名表或迁移数据到新表结构),或使用 CodeFirst 初始化新表(当前代码在启动时会 InitTables<AnnouncementAggregateRoot>())。
  - 新增 Mapster 适配(确保项目有 Mapster 依赖)。
  - 前端类型声明移除环境变量后,前端构建/运行脚本若依赖 VITE_BUILD_COMPRESS 需同步调整。
  - 若有缓存结构(AnnouncementCacheDto)或序列化相关约定变更,确认兼容性。

- 建议操作
  - 更新所有使用 IAnnouncementService 的代码(API 层/前端适配返回结构)。
  - 在非生产环境先执行数据迁移验证(保留旧表数据或写迁移脚本)。
  - 确认 Mapster 包已安装并编译通过。
  - 前端项目检查并同步 import_meta.d.ts 变更。
2025-11-10 15:03:02 +08:00
chenchun
cb49059e84 feat: 翻牌与邀请码逻辑重构,新增中奖记录与前7次中奖概率
- CardFlipTaskAggregateRoot.cs
  - 用 WinRecords(Dictionary<int,long>) 替代原先第8/9/10次的各自字段,且以 JSON 存库(SugarColumn IsJson)。
  - 构造函数初始化 WinRecords。
  - 新增 SetWinReward(int flipCount, long amount) 统一记录中奖。

- CardFlipService.cs
  - 读取并展示 WinRecords,按翻牌顺序映射中奖信息(不再依赖单独的第8/9/10字段)。

- CardFlipManager.cs
  - 重构中奖逻辑:
    - 前7次翻牌改为 50% 概率可中奖,奖励范围 1w–3w(新增配置常量 FREE_*)。
    - 统一通过 SetWinReward 记录任意次的中奖金额。
    - GenerateRandomReward 根据最小值自动选单位(1w 或 100w)。
  - 邀请类型翻牌校验由“仅统计被填写次数”改为“统计本周作为邀请人或被邀请人的邀请记录数量”(双方都计入),并据此判断是否可解锁邀请翻牌次数。

- InviteCodeManager.cs
  - 使用邀请码时:
    - 验证规则调整:一个账号只能填写别人的邀请码一次(hasUsedOthersCode 检查)。
    - 邀请记录的语义变化:当使用邀请码时,邀请记录同时代表邀请人和被邀请人各增加一次翻牌机会。
    - 不再将邀请码标记为单次已用;改为增加 UsedCount(一个邀请码可以被多人使用)。
    - 优化日志与提示信息。

- InviteCodeAggregateRoot.cs
  - 移除 IsUsed、UsedTime、UsedByUserId、MarkAsUsed 等单次使用相关字段/方法。
  - 保留 IsUserInvited(被邀请后不能再作为被邀请者使用)和 UsedCount(统计多人使用次数)。

注意事项
- 这是数据结构与业务逻辑的变更,数据库表结构发生变化(新增 WinRecords JSON 字段,移除若干字段)。上线前请准备相应的迁移脚本或数据迁移方案,确保历史中奖数据平滑迁移到 WinRecords。
- 变更会影响相关单元/集成测试、前端展示字段,需同步更新对应测试与界面展示逻辑。
2025-11-07 21:31:18 +08:00
chenchun
690cabfd96 feat: 新增公告功能 2025-11-06 16:59:29 +08:00
chenchun
4521212a90 feat: 新增文件缓存功能
- 在 Yi.Framework.Rbac.Application.Services.FileService 中注入 IMemoryCache,用于缓存文件元数据,减少对仓储的重复读取。
  - 在 Get 方法中通过 key "File:{code}" 缓存 FileCacheItem,设置绝对过期时间为 1 天。
  - 缓存项使用 Mapster 适配为 FileCacheItem,再适配回 FileAggregateRoot(保留现有逻辑判断和路径获取)。
- 新增缓存模型 Yi.Framework.Rbac.Domain.Shared.Caches.FileCacheItem(包含 Id、FileSize、FileName、FilePath、创建/修改信息等)。
- 增加并调整相关 using 引用(Microsoft.Extensions.Caching.Memory、Volo.Abp.Caching、Domain.Shared.Caches)。
- 同时修复了保存多文件时的缩进/空格格式(不影响功能)。
2025-11-06 11:29:21 +08:00
chenchun
771ecd9d81 Merge branch 'abp' into ai-hub
# Conflicts:
#	Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/FileService.cs
2025-11-06 11:23:46 +08:00
chenchun
94834f45c3 perf: 使用 FileStreamResult 流式返回文件,避免一次性读取到内存
改为 FileStream 并返回 FileStreamResult,减小内存占用并支持大型文件;修正变量名拼写并添加 null-forgiving 标记。
2025-11-06 11:13:50 +08:00
chenchun
a9b2979a21 Merge branch 'abp' into ai-hub 2025-11-06 11:00:04 +08:00
chenchun
22ac150acd fix: 修正 FileAggregateRoot.FilePath 的赋值,保存目录路径而非包含文件名的完整路径 2025-11-06 10:58:33 +08:00
Gsh
17337b8d78 fix: 系统公告弹窗前端 2025-11-05 23:12:23 +08:00
chenchun
09fb43ee14 refactor: 修改 YiCrudAppService.DeleteAsync 的参数名 ids -> id
在 Yi.Abp.Net8/framework/Yi.Framework.Ddd.Application/YiCrudAppService.cs 中,将 DeleteAsync 方法的参数名由 ids 改为 id,更新了对应的 XML 注释与对 Repository.DeleteManyAsync 的调用参数。仅为参数重命名,无功能变更。
2025-11-05 16:28:52 +08:00
ccnetcore
477c0e3f2c Merge branch 'invitation' into ai-hub 2025-11-02 13:00:36 +08:00
Gsh
2e4f520dac fix: 更改版本号 2025-11-02 01:27:03 +08:00
ccnetcore
067b25b9af Merge remote-tracking branch 'origin/invitation' into invitation 2025-11-02 01:21:33 +08:00
ccnetcore
36370c215d fix: 修复周邀请次数统计时使用错误的用户ID字段 2025-11-02 01:21:28 +08:00
Gsh
e24731acfe fix: 分享词修改 2025-11-02 01:17:22 +08:00
Gsh
927e9df7de fix: 分享地址固定为海外地址 2025-11-02 00:55:47 +08:00
Gsh
114b41144e fix: 增加邀请链接逻辑 2025-11-02 00:51:14 +08:00
ccnetcore
5019a36138 fix: 优化邀请码不足提示文案 2025-11-02 00:32:04 +08:00
Gsh
e15eb6149b fix: 翻牌样式优化,动画效果完善 2025-11-01 18:48:17 +08:00
Gsh
9d401a9c93 fix: 翻牌样式优化,动画效果完善 2025-11-01 17:56:19 +08:00
Gsh
eacf86e118 fix: 翻牌样式优化,动画效果待完善 2025-10-31 00:41:21 +08:00
chenchun
c4b631c815 feat: 新增翻牌幸运值悬浮球及相关逻辑
- .claude/settings.local.json:新增 Read 权限路径(Read(//e/code/github/Yi/Yi.Ai.Vue3/**))
- Yi.Ai.Vue3/src/components/userPersonalCenter/components/CardFlipActivity.vue:
  - 新增 luckyValue 响应式状态与 updateLuckyValue() 方法,并在获取任务状态后更新幸运值
  - 新增悬浮球 UI(SVG 进度环、图标、百分比文本)及样式和动画
  - 调整了 v-loading 为 false,并注释了部分错误提示(可能为调试遗留)
- 说明:样式使用嵌套写法(scss/sass 风格),请确认构建流程支持;建议确认 v-loading 与错误提示变更是否为预期并视情况修正。
2025-10-30 21:16:19 +08:00
chenchun
fb25e75a3a feat: 完成邀请机制 2025-10-30 20:17:14 +08:00
chenchun
e9099bbe04 feat: 增加基于本周填写邀请码数量的邀请翻牌校验
- 注入 ISqlSugarRepository<InvitationRecordAggregateRoot> 到 CardFlipManager 并更新构造函数。
- 在邀请类型(FlipType.Invite)翻牌时,改为校验用户本周已填写的邀请码数量是否满足本次翻牌所需(根据 InviteFlipsUsed 计算所需数量),不足则抛出友好异常提示。
- 保持原有错误处理与日志逻辑不变。
2025-10-30 20:13:49 +08:00
chenchun
f02fb91175 feat: 增加邀请码每周使用上限并调整翻牌规则(扩展免费次数、移除赠送翻牌与翻倍提示) 2025-10-30 19:51:56 +08:00
chenchun
5beef22269 fix: 修复权限判断逻辑(应为 &&,避免始终抛出权限异常)
修正 AiAccountService.GetProfitStatisticsAsync 中的条件判断,原先使用 || 导致即使为 Guo 或 cc 仍被拒绝访问。
2025-10-30 14:48:53 +08:00
chenchun
933cbb91d8 feat: 新增尊享包利润统计接口及 ElCollapseTransition 类型声明
- 在 AiAccountService 中新增 GetProfitStatisticsAsync 接口(GET account/profit-statistics),注入 PremiumPackage 仓储并统计尊享包已消耗/剩余、总成本、总收益、利润率及按200售价的成本估算。接口受授权控制。
- 注入 ISqlSugarRepository<PremiumPackageAggregateRoot> 并在构造函数中赋值。
- 在 types/components.d.ts 中新增 ElCollapseTransition 类型声明,补充前端组件类型提示。
- 注意:接口中对用户权限的判断使用了 "CurrentUser.UserName != \"Guo\" || CurrentUser.UserName != \"cc\"",该逻辑可能有误(应为 &&),建议确认并修正权限校验。
2025-10-30 14:38:58 +08:00
chenchun
efd917d184 style: 全部样式更新2.0 2025-10-30 11:21:11 +08:00
chenchun
e906208f4a feat: 新增邀请翻牌验证及相关文案与界面调整
- CardFlipManager:注入 InviteCodeManager,新增对 Invite 类型翻牌的邀请校验(未使用邀请码则抛出异常),防止未被邀请的用户使用邀请类型翻牌。
- CardFlipService:调整提示文案,统一使用“本周”前缀,并在邀请解锁提示中强调必定中奖且每次中奖最大额度翻倍。
- 前端:
  - CardFlipActivity.vue:注释掉翻牌失败的全局提示,调整统计文案为“本周已翻/本周剩余/本周邀请”,并在邀请弹窗文案中说明必定中奖且奖励翻倍。
  - Avatar.vue:更新菜单项标签为“每日任务(限时)”和“每周邀请(限时)”。
2025-10-30 11:19:22 +08:00
chenchun
cf137f6307 fix: 兼容客户端空值,Contents 为空时返回 "_" 并修正 Content 判空逻辑
修复 AnthropicMessageInput 中对 Content/Contents 的判空处理:
- 当 Contents 为 null 或 Count==0 时返回 "_",以兼容客户端对空值的特殊处理。
- 修正对 Content 的判空逻辑,使用 !string.IsNullOrEmpty(...) 确保非空字符串优先返回,避免将空字符串当作有效内容。
2025-10-29 22:23:09 +08:00
chenchun
e6b991fe86 feat: 调整翻牌与邀请码逻辑,增加第8次奖励及前端骨架屏 2025-10-29 21:55:17 +08:00
chenchun
3e75792e43 fix: 修复bug - 在可用性检查中支持忽略剩余令牌校验,避免负数用量包被错误过滤
- 将 PremiumPackageAggregateRoot.IsAvailable 增加参数 isVerifyRemainingToken=true,保持默认行为不变,允许按需跳过对 RemainingTokens 的校验。
- 在 UsageStatisticsService 中计算可用包时改为使用 p.IsAvailable(false),仅过滤过期或禁用的包,但不再因 RemainingTokens 为负而将包排除,从而保证统计(如 TotalTokens/RemainingTokens 汇总)包含负数用量的包,修正统计错误。

修改文件:
- Yi.Framework.AiHub.Domain/Entities/PremiumPackageAggregateRoot.cs
- Yi.Framework.AiHub.Application/Services/UsageStatisticsService.cs
2025-10-29 16:34:53 +08:00
Gsh
dd3f6325bb fix: 个人中心优化 2025-10-29 00:17:36 +08:00
chenchun
108ba348f6 feat: 扣减尊享包用量并调整日常任务奖励
- 在 AiGateWayManager 中新增:当请求使用尊享包模型时,按实际使用的 totalTokens 调用 PremiumPackageManager.TryConsumeTokensAsync 扣减用户尊享包用量(仅在 totalTokens > 0 时)。
- 调整 DailyTaskService 中两项日常任务的奖励配置:1000w 消耗奖励由 200w -> 100w,3000w 消耗奖励由 400w -> 200w。
- 兼顾少量格式化优化(if 条件空格调整)。
2025-10-28 17:43:23 +08:00
chenchun
bcdcec40e0 Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-10-28 16:13:13 +08:00
chenchun
2ce8baea42 fix: 优化对话异常提示信息
将抛出异常的消息从 "OpenAI对话异常{StatusCode}" 修改为更详细的中文提示,包含 StatusCode 与 Response 内容,便于排查。未改变逻辑,仅调整异常文本。
2025-10-28 16:12:52 +08:00
chenchun
c6425ca206 fix: 优化对话异常提示信息
将抛出异常的消息从 "OpenAI对话异常{StatusCode}" 修改为更详细的中文提示,包含 StatusCode 与 Response 内容,便于排查。未改变逻辑,仅调整异常文本。
2025-10-28 16:02:01 +08:00
chenchun
acb359ec33 style: 删除多余的 SqlSugar InitTables 注释并调整注释格式
在 Yi.Abp.Web/YiAbpWebModule.cs 中移除两行多余的注释,调整剩余注释的空格格式,清理代码注释,不影响程序逻辑。
2025-10-27 22:01:57 +08:00
chenchun
a1395d9a33 feat: 新增翻牌顺序追踪并重构翻牌/邀请码逻辑到 Manager,更新前端
- 在 CardFlipStatusOutput 与前端 types 添加 FlipOrderIndex 字段以记录牌在翻牌顺序中的位置
- 在域实体 CardFlipTaskAggregateRoot 增加 FlippedOrder(Json 列)以保存用户实际翻牌顺序
- 将 CardFlipService 重构为调用 CardFlipManager 与 InviteCodeManager,移除大量内聚的业务实现与常量(职责下沉到 Manager)
- 调整翻牌、使用邀请码和查询相关流程为 Manager 驱动,更新返回结构与提示文本
- 更新前端 CardFlipActivity 组件与 types,允许任意未翻的卡片被点击并显示翻牌顺序位置
- 若干文案、格式与日志细节修正
2025-10-27 21:57:26 +08:00
ccnetcore
609de29e71 feat: AnthropicMessageContent 新增 Signature 字段 2025-10-26 14:51:48 +08:00
ccnetcore
2efed4f4a5 feat: AnthropicThinkingInput 新增 signature、thinking、data、text 字段 2025-10-26 10:38:01 +08:00
chenchun
aec90ec9d6 feat: 新增翻牌活动入口与全局组件声明
- 在 Header Avatar 菜单新增翻牌活动(cardFlip)入口,并添加对应插槽 <card-flip-activity/>
- 在 types/components.d.ts 中添加 CardFlipActivity 与 ElCollapseTransition 类型声明
- 在 .eslintrc-auto-import.json 中新增 ElMessage 与 ElMessageBox 自动导入
- 从 import_meta.d.ts 中移除 VITE_BUILD_COMPRESS 环境声明
- 在 YiAbpWebModule.cs 中添加相关 using 并保留数据库建表初始化的注释(CodeFirst.InitTables)
2025-10-23 21:58:47 +08:00
chenchun
1aaff2942d fix: 调整 Anthropic DTO 属性为可空类型以避免反序列化错误 2025-10-21 16:55:05 +08:00
chenchun
cdbfc5383d feat: 为充值记录新增订单类型字段并区分VIP与套餐逻辑 2025-10-20 10:18:24 +08:00
ccnetcore
f302555e0c feat: 完善描述 2025-10-18 17:40:46 +08:00
ccnetcore
86c5890476 feat: 用户中心新增每日任务组件并在头像菜单中集成 2025-10-18 17:34:46 +08:00
ccnetcore
a13ee395c7 feat: 支持 x-api-key 认证并扩展 Anthropic 响应字段,优化工具调用处理 2025-10-18 13:23:54 +08:00
Gsh
9abcd72aca fix: 增加教程导航 2025-10-16 22:50:10 +08:00
ccnetcore
4ddea6d468 Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-10-16 22:12:36 +08:00
ccnetcore
867a2dc861 fix: 修正Claude聊天响应的Token统计逻辑并优化AiGateWayManager使用条件,同时移除前端无用环境变量定义 2025-10-16 22:11:09 +08:00
chenchun
4a72e3fa0d Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-10-16 09:35:56 +08:00
chenchun
8b4371aabb feat: 尊享包购买流程新增充值记录保存功能 2025-10-16 09:35:25 +08:00
Gsh
799dd08ec0 feat: 模型提示词、剩余额度、对话状态优化 2025-10-16 01:20:11 +08:00
Gsh
c5c22224cf feat: 2.0发布 2025-10-15 23:44:18 +08:00
ccnetcore
2dae47e85c feat: 修复价格 2025-10-15 23:18:26 +08:00
ccnetcore
375dd4f797 fix: 修复支付3位数问题 2025-10-15 23:04:09 +08:00
ccnetcore
acb2db8397 fix: 商品类型返回值 2025-10-15 23:00:42 +08:00
ccnetcore
b7a3e76d0b Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-10-15 19:51:28 +08:00
ccnetcore
48150b712a refactor: 会话ID为空时不存储消息内容,并移除无用注释 2025-10-15 19:49:33 +08:00
chenchun
6db9dfc308 Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-10-15 11:54:06 +08:00
chenchun
2d6c1f3c46 fix: 验证交易状态仅在成功时执行充值逻辑 2025-10-15 11:53:54 +08:00
Gsh
161e10d2d1 feat: 产品样式调整 2025-10-15 00:16:57 +08:00
Gsh
a9a2a91183 feat: 产品样式调整 2025-10-15 00:05:10 +08:00
Gsh
1c9a6f108e feat: 产品样式调整 2025-10-15 00:05:10 +08:00
ccnetcore
d6adf9b736 feat: 增加 Claude 模型 Token 使用量倍数调整功能 2025-10-14 23:41:26 +08:00
ccnetcore
959eb3f782 fix: 优化服务号与支付逻辑,增加AccessToken为空校验及优惠描述完善 2025-10-14 23:02:44 +08:00
ccnetcore
7a53e0c90c refactor: 简化尊享包Token扣减逻辑,移除多包分配与校验流程 2025-10-14 22:34:05 +08:00
ccnetcore
533b87fc5b fix: 修复统计近7天token消耗时角色过滤条件错误 2025-10-14 22:22:35 +08:00
ccnetcore
15713cf7fe feat: 支持Claude模型API类型及尊享包校验与扣减逻辑 2025-10-14 22:17:21 +08:00
Gsh
31dc756868 feat: 尊享模型效果 2025-10-14 21:29:20 +08:00
ccnetcore
52f6b6130f feat: 为 HttpClient 添加默认 User-Agent 请求头 2025-10-13 23:08:15 +08:00
ccnetcore
16945b3d5b fix: 修复剩余令牌统计逻辑,增加过期时间判断 2025-10-13 22:09:47 +08:00
Gsh
bdc664fc44 feat: 增加尊享token包产品 2025-10-13 01:14:40 +08:00
Gsh
9555ef10e0 feat: 增加尊享token包产品 2025-10-13 01:03:41 +08:00
Gsh
49e6cb26fc feat: 增加尊享产品 2025-10-12 23:00:08 +08:00
ccnetcore
3ace29e692 fix: 修复无会话时仍存储消息内容的问题 2025-10-12 22:46:20 +08:00
ccnetcore
aa9dd0129b refactor: 将尊享包Token统计逻辑从AiAccountService迁移至UsageStatisticsService,并移除AiUserRoleMenuDto相关字段 2025-10-12 21:51:51 +08:00
ccnetcore
1464271fbd Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-10-12 21:12:37 +08:00
ccnetcore
754f145559 fix: 允许尊享包扣减到负数并优化Token统计逻辑 2025-10-12 21:12:21 +08:00
Gsh
6afd0cb955 feat: 个人中心优化 2025-10-12 21:08:23 +08:00
ccnetcore
d32906702a feat: 商品枚举与支付服务优化,支持中文名称、参考价格及类别筛选 2025-10-12 21:04:08 +08:00
ccnetcore
9bcdaf6bd8 fix: 更新尊享包折扣规则为每10元减2.5元,最多减50元,并同步修改提示文案 2025-10-12 20:14:07 +08:00
ccnetcore
db82a8cf08 Merge branch 'premium' into ai-hub 2025-10-12 20:10:23 +08:00
ccnetcore
a9e8b2b01f feat: 增加尊享包商品及折扣逻辑,完善VIP与尊享包相关接口和数据返回
- 新增尊享包商品类型,支持 5000W 和 10000W Tokens
- 增加尊享包折扣计算与折扣后价格获取方法
- PayService 新增获取商品列表接口,支持尊享包折扣展示
- PayManager 支持尊享包订单金额按折扣计算,并新增获取用户累计充值金额方法
- OpenApiService Anthropic接口增加VIP与尊享包用量校验
- AiGateWayManager 增加尊享包Token扣减逻辑
- AiAccountService 返回用户VIP状态、到期时间及尊享包Token统计信息
2025-10-12 20:07:58 +08:00
Gsh
85bd1ce8d6 feat: 个人中心新增尊享服务、模型列表区分 2025-10-12 18:30:34 +08:00
ccnetcore
4d09243efd feat: 完成尊享服务 2025-10-12 16:42:26 +08:00
ccnetcore
5934056fe6 fix: 修复Anthropic接口TokenUsage序列化及HttpClient创建方式问题 2025-10-12 14:38:26 +08:00
chenchun
2a81062fa3 perf: 优化 HttpClient 配置,增加 10 分钟超时设置 2025-10-12 00:02:34 +08:00
chenchun
fdc868323f fix: 修正 TokenUsage 计算逻辑,使用 CacheReadInputTokens 替代重复的 CacheCreationInputTokens 2025-10-11 23:36:26 +08:00
chenchun
593b3a4cdd fix: 修正消息与Anthropic返回的Token统计逻辑,避免零值覆盖并支持缓存Token计算 2025-10-11 23:27:46 +08:00
chenchun
2b12e18e6c fix: 为AnthropicHandles添加MaxTokens有效性校验 2025-10-11 20:32:41 +08:00
chenchun
345ed80ec8 feat: 新增claude接口转换支持 2025-10-11 15:25:43 +08:00
chenchun
29dc1ae250 fix: 限制 Azure OpenAI 请求最大 tokens 并优化响应处理空行格式 2025-10-10 15:16:16 +08:00
ccnetcore
9fdd41b134 fix: 更新会员套餐为8个月并调整价格信息 2025-10-08 21:24:29 +08:00
ccnetcore
31ee5e8ffb feat: 新增 YiXinVip 8 个月商品类型并移除 9 个月配置 2025-10-08 21:18:42 +08:00
ccnetcore
d7922bb71d fix: 修复 tokenUsage 为空时的空引用问题 2025-09-27 17:40:31 +08:00
ccnetcore
1cc5f2a14f refactor: 注释掉 Furion 统一结果 API 注册,保留 ABP 默认处理方式 2025-09-27 17:26:13 +08:00
橙子
d9997eeb28 !100 update Yi.Abp.Net8/framework/Yi.Framework.AspNetCore/UnifyResult/Fiters/FriendlyExceptionFilter.cs.
Merge pull request !100 from Gary/N/A
2025-09-22 07:14:02 +00:00
Gary
06e77aa8fd update Yi.Abp.Net8/framework/Yi.Framework.AspNetCore/UnifyResult/Fiters/FriendlyExceptionFilter.cs.
判断是否为模型验证错误,如果是,将errors传回,并打印日志

Signed-off-by: Gary <1511313969@qq.com>
2025-09-22 07:13:46 +00:00
橙子
e9e2228f6e !97 岗位状态修改
Merge pull request !97 from 嗳摸嫫/jun
2025-09-22 07:13:45 +00:00
橙子
d516a381d0 !98 update Yi.Abp.Net8/framework/Yi.Framework.Mapster/YiFrameworkMapsterModule.cs.
Merge pull request !98 from Gary/N/A
2025-09-22 07:13:26 +00:00
Gary
4e792ba976 update Yi.Abp.Net8/framework/Yi.Framework.Mapster/YiFrameworkMapsterModule.cs.
自动扫描所有继承IRegister 的Mapster 配置

Signed-off-by: Gary <1511313969@qq.com>
2025-09-22 02:58:59 +00:00
chenchun
fa3ac91ba4 fix: 修正文件整理大师Vip数量限制提示错误 2025-09-18 16:17:10 +08:00
chenchun
f90d3871fa feat: 启用 Furion 统一返回结果并优化过滤器配置
- 在 `YiAbpWebModule` 中启用 `AddFurionUnifyResultApi` 以支持 Furion 风格的统一 API 返回格式
- 调整 `UnifyResultExtensions`,移除 `AbpExceptionFilter` 和 `AbpNoContentActionFilter`,确保统一结果过滤器优先执行
2025-09-16 11:48:36 +08:00
ccnetcore
e7c152e955 fix: 修复文件整理大师文件数量限制及模型名称错误 2025-09-13 21:19:54 +08:00
ccnetcore
0223b5c104 fix: 更新客服联系方式和产品价格信息
- 统一修改客服支持提示信息为"备注ai获取专属客服支持"
- 更新会员套餐价格和描述信息
- 替换模型排行榜iframe为openrouter链接
- 调整内容截断长度从2000到10000字符
2025-09-07 18:49:58 +08:00
ccnetcore
9e41a7c446 fix: 调整YiXinVip商品价格及有效期配置 2025-09-07 18:29:41 +08:00
ccnetcore
2ba0ffc1b7 Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-09-07 17:16:13 +08:00
ccnetcore
7d038e1266 style: 优化样式1.3 2025-09-07 17:16:07 +08:00
Gsh
b98285f314 fix: 处理二维码接口过多调用问题 2025-09-07 13:30:03 +08:00
ccnetcore
73438da666 fix: 将 VerifyNext 接口由 GET 改为 POST 请求 2025-09-07 01:34:52 +08:00
ccnetcore
85f2e1b579 feat: 新增文件整理大师服务及校验与对话接口 2025-09-07 01:34:25 +08:00
ccnetcore
ece89ebad0 refactor: 移除自定义 HttpClientFactory,改用依赖注入的 IHttpClientFactory 2025-09-04 22:26:06 +08:00
Gsh
6e2dd39246 fix: 未登录支付按钮改登录 2025-09-03 11:43:40 +08:00
Gsh
a61286e534 fix: 非会员模型选择跳转修改 2025-09-03 10:56:44 +08:00
Gsh
4f944a5466 fix: 优化二维码加载错误显示 2025-08-31 23:56:42 +08:00
ccnetcore
d29aac088a feat: 全面优化ai-hub前端细节 2025-08-31 01:37:36 +08:00
Gsh
8abd122773 feat: 重新登录逻辑更改 2025-08-30 23:58:57 +08:00
Gsh
08084aa0bc feat: 默认展示二维码登录 2025-08-30 23:13:46 +08:00
Gsh
e69cd5a73c feat: 用户头像路径固定 2025-08-30 23:05:14 +08:00
Gsh
76aa3bdc64 feat: 用户头像路径固定 2025-08-30 22:39:27 +08:00
Gsh
93251104af Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-08-30 22:29:21 +08:00
Gsh
3cae477f3e feat: 增加扫码登录功能 2025-08-30 22:28:38 +08:00
ccnetcore
25c736dc0a fix: 修复扫码回调在非等待状态下仍被处理的问题 2025-08-30 22:07:09 +08:00
ccnetcore
96a09d8980 fix: 修复绑定用户时返回值未包含用户ID的问题 2025-08-30 21:58:43 +08:00
ccnetcore
72387235a0 refactor: 移除分布式锁获取时的超时参数 2025-08-30 21:17:25 +08:00
ccnetcore
1b00e505b7 fix: 修复绑定微信二维码生成时未登录用户的异常提示 2025-08-30 18:02:46 +08:00
ccnetcore
1c54e47b9e feat: 新增AI账户服务及扩展用户信息获取功能,支持通过userId查询用户信息 2025-08-30 17:55:13 +08:00
ccnetcore
ba07e2c905 feat: 新增服务号注册授权页面并优化注册提示信息 2025-08-30 00:02:27 +08:00
ccnetcore
bde4611a50 fix: 修复服务号注册缓存时间及锁定范围问题 2025-08-29 23:32:40 +08:00
ccnetcore
e7326fea7b Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-08-29 22:21:11 +08:00
ccnetcore
d13b23ad2e fix: 修复服务号扫码场景缓存未保存用户ID且场景结果错误的问题 2025-08-29 22:20:52 +08:00
Gsh
8b1830a711 Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-08-29 22:02:14 +08:00
Gsh
b70c530754 fix: 增加扫码 2025-08-29 22:01:44 +08:00
ccnetcore
d90e24f9ed fix: 修复服务号回调处理返回用户ID及缓存更新逻辑 2025-08-29 21:55:07 +08:00
chenchun
1fbd521d1a fix: 注册接口加分布式锁防止并发重复注册 2025-08-29 14:33:35 +08:00
chenchun
2ae6183e7f fix: 防止重复注册意社区账号 2025-08-29 14:31:04 +08:00
chenchun
7905911624 feat: 注册用户时支持传入头像参数 2025-08-29 14:11:50 +08:00
chenchun
c5b6b33d8e feat: 注册公众号用户时保存额外用户信息到数据库 2025-08-29 13:54:02 +08:00
chenchun
5d29fd6d3b feat: 为微信服务号用户信息响应模型添加JsonPropertyName映射并移除无用字段 2025-08-29 13:41:50 +08:00
chenchun
ad8f48f36b feat: 服务号用户信息获取增加日志记录 2025-08-29 11:53:36 +08:00
chenchun
f9843c13d4 fix: 修复场景缓存为空时的处理逻辑并调整注册成功缓存写入方式 2025-08-29 11:34:57 +08:00
chenchun
6bd561b094 feat: 新增微信公众号扫码注册功能及幂等处理
- 新增 `FuwuhaoConst` 常量类,统一缓存 Key 前缀管理
- `FuwuhaoOptions` 增加 FromUser、RedirectUri、PicUrl 配置项
- `FuwuhaoManager` 新增 `BuildRegisterMessage` 方法,构建注册引导图文消息
- `FuwuhaoService`
  - 增加 OpenId 与 Scene 绑定缓存,支持扫码注册有效期管理
  - 回调处理支持注册场景,返回图文消息引导用户注册
  - 新增注册接口 `RegisterByCodeAsync`,根据微信授权信息自动注册账号并更新场景状态
- `AccountManager` 注册方法增加分布式锁,防止重复注册,并校验用户名唯一性
2025-08-29 11:01:09 +08:00
chenchun
d2c6238df1 feat: 启用AI股票生成与新闻生成任务并切换至OpenAI接口配置 2025-08-28 15:40:59 +08:00
chenchun
1d108983e8 feat: 增加服务号回调签名校验及扫码回调幂等处理
- `FuwuhaoManager` 新增 `ValidateCallback` 方法,用于校验微信回调签名
- `FuwuhaoOptions` 增加 `CallbackToken` 配置项
- `QrCodeResponse` 属性添加 `JsonPropertyName` 标注,支持 JSON 序列化映射
- `FuwuhaoService` 在回调接口中增加签名校验,并通过分布式锁实现幂等处理
- 调整场景值解析逻辑,过滤非扫码/关注事件
- 优化缓存过期时间设置
2025-08-28 15:20:15 +08:00
ccnetcore
b768bca638 feat: 完成支持微信扫码功能 2025-08-27 23:42:46 +08:00
chenchun
28fcd6c9ce feat: 新增服务号回调处理服务及数据模型 2025-08-27 17:46:39 +08:00
HW-July
6005b9329d 岗位状态修改 2025-08-25 17:12:18 +08:00
ccnetcore
10559a925c style: 优化样式1.2 2025-08-25 00:39:16 +08:00
ccnetcore
942e218a9e feat: 新增 FileMaster 发送消息接口 2025-08-23 13:15:28 +08:00
ccnetcore
f6af9edc38 feat: 删除文件 2025-08-23 12:23:17 +08:00
ccnetcore
e0f6331ec3 feat:构建 2025-08-23 12:21:16 +08:00
ccnetcore
06f0c6caa7 style: 整体调整 2025-08-23 12:14:09 +08:00
ccnetcore
56ec260e3a perf: 优化已完成状态下的输出等待时间,加快响应速度 2025-08-21 21:50:06 +08:00
ccnetcore
176cf84369 fix: 修复 AiGateWayManager 中可能的空引用异常 2025-08-21 01:16:57 +08:00
Gsh
6de3b722ed fix: 新增文件助手目录 2025-08-18 23:07:34 +08:00
Gsh
2cf6326764 fix: 更新组件库 2025-08-18 21:02:55 +08:00
Gsh
ec27ee58b4 fix: 充值成功与记录页面增加联系客服,apikey教程更改 2025-08-17 22:08:03 +08:00
ccnetcore
4e42e2202e refactor: 移除代码补全兼容逻辑并优化 DTO 可空类型处理 2025-08-16 19:20:58 +08:00
ccnetcore
e60d8eceb7 feat: 新增 YiXinVip 商品价格配置及前端构建压缩环境变量定义 2025-08-16 00:08:03 +08:00
Gsh
08fb939b38 fix: 动态支付响应页面 2025-08-15 23:49:18 +08:00
ccnetcore
482dd73afd feat: 支持创建订单时自定义支付宝回调地址 2025-08-15 23:41:01 +08:00
Gsh
f09a9fee75 fix: 产品相关页面样式优化 2025-08-15 23:28:09 +08:00
chenchun
9a31d14b41 feat: 优化CORS配置支持通配符和代码格式化
- 支持CORS配置使用通配符"*"允许所有来源访问
- 优化CORS策略配置逻辑,区分通配符和具体域名处理
- 格式化代码,移除多余空行和统一代码风格
- 修复Hangfire配置中的变量赋值格式
- 更新默认CORS配置为通配符模式
2025-08-14 17:04:27 +08:00
chenchun
2fd7f88f04 feat: 新增海外站点流量限制和CORS配置优化
- 新增yxai.chat域名到CORS白名单
- 为海外站点yxai.chat添加大流量接口访问限制
- 修复Azure OpenAI图像生成服务默认尺寸设置
2025-08-14 15:14:30 +08:00
chenchun
9d4cc802e9 fix: 添加CodeGeeX跨域支持
在CORS配置中新增http://codegeex域名,支持CodeGeeX工具的跨域访问请求
2025-08-14 14:24:03 +08:00
Gsh
ee6b4827fa feat: 增加支付宝在线支付、套餐订购弹窗、会员权益、支持模型展示等 2025-08-14 00:26:39 +08:00
ccnetcore
48d8c528f6 fix: 调整YiXinVip各档价格为0.01方便测试 2025-08-13 22:21:03 +08:00
ccnetcore
40c0a5ac64 feat: 支付完成后自动为用户充值VIP并支持按商品类型计算有效期 2025-08-13 22:19:31 +08:00
chenchun
3a60bcc174 refactor: 优化交易状态枚举处理方式
- 为TradeStatusEnum枚举添加Description特性标注
- 重构GetTradeStatusDescription方法,使用反射获取Description特性值
- 简化ParseTradeStatus方法,使用Enum.TryParse替代switch表达式
- 提高代码可维护性,避免硬编码状态描述
2025-08-13 18:30:56 +08:00
chenchun
2b3fad16fd feat: 优化支付宝回调通知记录功能
- 新增SignStr字段记录支付宝回调的原始签名字符串
- 修改日志记录格式,使用键值对形式记录回调通知数据
- 更新PayManager.RecordPayNoticeAsync方法支持记录原始签名字符串
- 移除AlipayManager中冗余的注释说明
2025-08-13 18:21:05 +08:00
chenchun
f0cf6bf5c8 fix: 修复支付宝支付功能相关问题
- 修复支付接口参数顺序错误,调整商品名称和订单号参数位置
- 修复支付页面HTML返回格式,直接返回Body内容而非序列化字符串
- 添加支付相关接口的权限控制,支付回调接口允许匿名访问
- 优化支付宝回调验签逻辑,保持原始参数顺序避免验签失败
- 增加回调格式错误的异常处理
- 修复商品类型枚举显示名称为英文,新增测试商品类型
- 修正Token服务提示文案中的错别字
- 移除订单更新时不必要的时间字段设置
2025-08-13 17:42:13 +08:00
chenchun
0ba4e3240b feat: 完成支付宝接入 2025-08-13 12:07:35 +08:00
ccnetcore
9332b17fc1 feat: 集成支付宝支付SDK并添加当面付测试调用,更新CORS配置支持capacitor 2025-08-13 08:26:45 +08:00
ccnetcore
4ec4023f40 feat: 增加EmbeddingResponse的object字段并完善AiGateWayManager的Usage统计,更新CORS配置 2025-08-11 20:24:48 +08:00
chenchun
d9971541f2 feat: 支持字符串类型的embedding输入参数
在AiGateWayManager中新增对JsonElement字符串类型的处理,确保embedding请求能够正确处理单个字符串输入参数。
2025-08-11 18:10:11 +08:00
chenchun
7b0e4fcc73 fix: 修复Embedding输入处理逻辑和字段可空性
- 优化Embedding输入类型判断逻辑,支持string和JsonElement数组类型
- 将EncodingFormat字段设置为可空类型,提高兼容性
- 注释知识库场景下的消息统计功能,避免不必要的数据记录
2025-08-11 18:05:33 +08:00
chenchun
cfde73d13a fix: 修复输出为空问题 2025-08-11 16:53:33 +08:00
chenchun
c17c9000a8 refactor: 移除AiHub Domain层对Application.Contracts的循环依赖
移除Yi.Framework.AiHub.Domain项目中对Yi.Framework.AiHub.Application.Contracts的项目引用,解决领域层和应用层之间的循环依赖问题,符合DDD架构分层原则。
2025-08-11 15:51:59 +08:00
chenchun
42d537a68b style: 调整架构引用 2025-08-11 15:31:11 +08:00
chenchun
25eebec8f7 feat: 新增向量嵌入服务支持
新增SiliconFlow向量嵌入服务实现,支持文本向量化功能:
- 新增ITextEmbeddingService接口和SiliconFlowTextEmbeddingService实现
- 新增EmbeddingCreateRequest/Response等向量相关DTO
- 在AiGateWayManager中新增EmbeddingForStatisticsAsync方法
- 在OpenApiService中新增向量生成API接口
- 扩展ModelTypeEnum枚举支持Embedding类型
- 优化ThorChatMessage的Content属性处理逻辑
2025-08-11 15:29:24 +08:00
Gsh
bbe5b01872 fix: 优化token图表,增加全屏显示 2025-08-10 15:34:53 +08:00
ccnetcore
6b31536de5 fix: 修复用户过期判断逻辑,按日期比较避免当天误判 2025-08-10 12:07:09 +08:00
ccnetcore
2e5db5500f Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-08-10 11:53:52 +08:00
ccnetcore
7038d31c53 feat: 新增VIP充值接口并支持通过角色代码为用户分配角色 2025-08-10 11:53:28 +08:00
Gsh
3eb27c3d35 fix: 增加对话token显示,token消耗统计 2025-08-10 00:56:44 +08:00
ccnetcore
a9c3a1bcec fix: 修复统计中 Token 数量计算错误,将计数改为求和 2025-08-09 23:38:56 +08:00
ccnetcore
384926e73a feat: 新增用户数据导出功能 2025-08-09 22:55:26 +08:00
ccnetcore
4335c12659 chore: 注释掉生成新闻和股票价格的异步调用 2025-08-09 13:58:26 +08:00
ccnetcore
e6e4829164 feat: 新增VIP过期自动卸载功能
- 新增`AiRechargeManager`类,实现VIP过期用户的自动卸载逻辑。
- 新增`AiHubConst`常量类,统一管理角色名称。
- 在`IRoleService`中添加`RemoveUserRoleByRoleCodeAsync`方法,用于移除指定用户的角色。
- 在`RoleManager`中实现`RemoveUserRoleByRoleCodeAsync`方法。
- 优化`CurrentExtensions`中VIP角色判断逻辑,使用常量替代硬编码。
- 调整`YiAbpWebModule`中部分代码格式,提升可读性。
2025-08-09 13:14:15 +08:00
ccnetcore
f3c67cf598 fix: 修复统计数量偶发问题 2025-08-09 12:20:28 +08:00
ccnetcore
4681d468ce style: 优化验证码样式 2025-08-05 22:41:20 +08:00
chenchun
63e7d3d5f5 style: 更新主题2.2 2025-08-05 18:23:33 +08:00
chenchun
f47d8c8ce3 style: 优化2.1样式 2025-08-05 17:19:03 +08:00
chenchun
6f69f45ddc Merge branch 'bbs-sharpdance' into ai-hub 2025-08-05 14:11:16 +08:00
chenchun
e73678c788 style: 全部样式更新2.0 2025-08-05 14:09:39 +08:00
ccnetcore
09a2f91cbf style: 优化样式1.1 2025-08-04 23:55:48 +08:00
ccnetcore
29da7499a4 Merge branch 'bbs-sharpdance' into ai-hub 2025-08-04 23:37:11 +08:00
ccnetcore
5b024e9443 style: 重写ele 2025-08-04 23:34:13 +08:00
ccnetcore
225932eff1 style: 上线全局样式 2025-08-04 23:29:25 +08:00
Gsh
65d5f5ae86 fix: 加载优化、vip状态优化、apikey优化 2025-08-04 23:11:42 +08:00
ccnetcore
3e647ef14d style: 全局修改样式主题 2025-08-04 22:35:45 +08:00
chenchun
7cb3aea2e6 style: 调整样式 2025-08-04 18:27:18 +08:00
chenchun
7f4b8f1c8a feat: 添加暗色主题支持
- 在HTML根元素添加dark类名以启用暗色模式
- 引入Element Plus暗色主题CSS变量文件
- 格式化代码缩进和结构,提升代码可读性
2025-08-04 17:07:01 +08:00
ccnetcore
0a2710b865 feat: 支持图片生成 2025-08-04 01:03:47 +08:00
ccnetcore
2a301c4983 feat: 支持图片生成 2025-08-03 23:23:32 +08:00
Gsh
faa8131a1b fix: 未登录对话id逻辑玩优化 2025-08-03 21:56:51 +08:00
ccnetcore
71bd885bd0 fix: 支持router参数 2025-08-03 21:47:22 +08:00
ccnetcore
691a1e50f0 feat: 支持未登录用户统计 2025-08-03 21:32:54 +08:00
ccnetcore
ef6e9fd16d style: 优化提示词 2025-08-02 22:04:22 +08:00
chenchun
17f9ac6d54 style: 优化防抖样式 2025-08-01 17:58:07 +08:00
chenchun
3f8e6e48c0 Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-07-28 14:39:09 +08:00
chenchun
bda4fdf69d feat: 兼容代码补全功能 2025-07-28 14:39:02 +08:00
Gsh
5c85ed13fd fix: 加载进度优化与登录弹窗优化 2025-07-28 13:43:46 +08:00
chenchun
1986901031 Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-07-28 13:15:49 +08:00
chenchun
e1d3ec21e5 feat: 支持错误处理 2025-07-28 13:15:42 +08:00
Gsh
f45283dade Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-07-28 12:59:42 +08:00
Gsh
31c44d8df7 fix: 登录弹窗超时功能取消 2025-07-28 12:59:07 +08:00
chenchun
bf443963c8 fix: 修复ThorChatCompletionsRequest中Messages属性的可空类型问题 2025-07-28 12:50:48 +08:00
chenchun
a0eb234539 feat: 兼容了用量使用显示 2025-07-22 10:40:23 +08:00
ccnetcore
b6d670c240 perf: 兼容deepseek格式 2025-07-21 22:03:55 +08:00
ccnetcore
b5fb2c42c6 feat: 兼容deepseek协议 2025-07-21 21:57:14 +08:00
ccnetcore
d72cc529ba perf: 优化流式输出 2025-07-21 21:15:02 +08:00
Gsh
660bd00cae fix: apikey加载状态 2025-07-20 22:12:48 +08:00
Gsh
b5489711ec fix: 加载优化 2025-07-20 21:01:41 +08:00
Gsh
76717c4f8a Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-07-20 17:23:33 +08:00
ccnetcore
3d53d0bcd6 style: 完成进度条加载 2025-07-20 17:14:05 +08:00
ccnetcore
c7c9428b68 style: 完成进度条加载 2025-07-20 17:01:17 +08:00
ccnetcore
991a970d6a style: 完成进度条加载 2025-07-20 16:40:54 +08:00
ccnetcore
cbe93b9f7e style: 完成进度条加载 2025-07-20 15:15:05 +08:00
ccnetcore
5d7217b775 feat: 完成支持functioncall功能 2025-07-18 23:12:20 +08:00
ccnetcore
d6836b8bcf feat: 提交cicd产物 2025-07-18 21:08:51 +08:00
ccnetcore
c367651c78 chorm: 构建 2025-07-18 21:00:23 +08:00
ccnetcore
77123fd971 cicd: 提交流水线 2025-07-18 21:00:06 +08:00
ccnetcore
9d73a6837b Merge branch 'ai-hub' into ai-hub-dev 2025-07-18 20:46:36 +08:00
ccnetcore
651f0157dc feat: 完成兼容处理 2025-07-18 20:46:30 +08:00
Gsh
90e8dbe449 fix: 对话参数修改 2025-07-18 20:33:51 +08:00
ccnetcore
ccba2667bc Merge branch 'ai-hub' into ai-hub-dev 2025-07-18 19:51:15 +08:00
Gsh
3ce9fc9790 fix: 对话参数修改 2025-07-18 19:49:11 +08:00
ccnetcore
2f24dd77bf feat: 完成对接 2025-07-18 00:27:59 +08:00
ccnetcore
2bc07cb3df feat: 完成错误信息展示 2025-07-18 00:14:19 +08:00
ccnetcore
30678dbbb4 feat: 完成功能 2025-07-17 23:52:00 +08:00
ccnetcore
c5b0f69b51 feat: 重构完成 2025-07-17 23:16:16 +08:00
ccnetcore
e593f2cba4 feat: Thor搭建 2025-07-17 23:10:26 +08:00
ccnetcore
10f7499066 feat: 完成cicd搭建 2025-07-16 23:34:52 +08:00
Gsh
36b7e495f7 update: md渲染优化与依赖更新(0715 02:07) 2025-07-16 00:12:00 +08:00
Gsh
94b96e3c19 fix: 更新md 2025-07-15 16:42:47 +08:00
Gsh
0d1ee18da0 fix: 增加重新登录意社区 2025-07-15 00:54:34 +08:00
Gsh
cab0b61ee0 fix: 对话md渲染优化 2025-07-14 22:21:24 +08:00
Gsh
8e6611d76d Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-07-14 22:20:55 +08:00
Gsh
1ef82e5f93 fix: 对话md渲染优化 2025-07-14 22:20:32 +08:00
ccnetcore
43dc962606 feat: 支持邮箱注册功能 2025-07-13 21:26:46 +08:00
ccnetcore
020d674ca2 style: 调整header 2025-07-12 18:42:26 +08:00
ccnetcore
bb0e1081cc style: 调整header 2025-07-12 18:41:26 +08:00
Gsh
5162f9ce3b fix: 对话创建防抖 2025-07-12 00:36:11 +08:00
ccnetcore
57fae7fe4b fix: 知识库访问 2025-07-09 23:26:32 +08:00
ccnetcore
17412d7de7 feat: 新增支持Prompt 2025-07-09 23:11:57 +08:00
ccnetcore
d59f40dfba Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-07-09 22:44:36 +08:00
ccnetcore
5953be63cb feat: 兼容cline 2025-07-09 22:44:24 +08:00
Gsh
58a4311947 fix: 更新消息暂停 2025-07-09 22:31:52 +08:00
ccnetcore
c5a9b9a15f feat: 支持非流式传输 2025-07-09 21:52:00 +08:00
chenchun
716c344780 feat: 支持非流式传输功能 2025-07-09 19:12:53 +08:00
Gsh
9af8c4897b fix: 增加消息复制、消息时间 2025-07-09 00:08:30 +08:00
Gsh
ca72024a68 feat: 增加用户充值记录查询 2025-07-08 22:59:24 +08:00
chenchun
0d2bc585a9 feat: 提高模型输出速度 2025-07-08 18:24:21 +08:00
chenchun
4e3edefb35 feat: 整体调节 2025-07-08 15:47:51 +08:00
Gsh
9408242726 fix: 禁止移动端缩放、对话头像更改 2025-07-08 00:29:41 +08:00
Gsh
4710208e81 fix: 隐藏文件上传按钮,去除不必要的log打印 2025-07-07 23:29:39 +08:00
Gsh
4fc6a1e818 fix: 隐藏文件上传按钮,去除不必要的log打印 2025-07-07 23:27:55 +08:00
ccnetcore
c9b79a074b style: 增加markdown样式优化 2025-07-07 22:34:19 +08:00
Gsh
2e79eb346f fix: 添加微信群二维码 2025-07-07 21:47:21 +08:00
Gsh
3f88bd4158 fix:增加md样式重写文件 2025-07-07 21:21:55 +08:00
Gsh
f58e079741 fix:增加md样式文件 2025-07-07 21:12:35 +08:00
Gsh
6f1eb1f4b9 feat: 新增markdown渲染 2025-07-07 21:01:59 +08:00
ccnetcore
826d529997 fix: 修复接口名称 2025-07-05 17:47:44 +08:00
ccnetcore
43e60eab4a feat: 完成充值记录 2025-07-05 17:43:48 +08:00
Gsh
6c33024790 fix:百度seo添加与对话错误处理 2025-07-05 17:25:14 +08:00
Gsh
d27e625fde fix:前端模型主键换位modelId 2025-07-05 15:59:22 +08:00
橙子
9d4b3e7d0c update README.md.
Signed-off-by: 橙子 <454313500@qq.com>
2025-07-05 07:50:10 +00:00
Gsh
23cecb9360 fix:401、403错误提示,对话角色更改assistant,模型选择持久化 2025-07-05 15:49:29 +08:00
ccnetcore
7e4c835ced fix: 修复nugetapi 2025-07-05 15:31:18 +08:00
ccnetcore
aff460f555 feat: 升级yi.abp.tool 2025-07-05 15:23:08 +08:00
ccnetcore
52961b459e feat: 优化整体aihub架构 2025-07-05 15:11:56 +08:00
ccnetcore
0af2f867fc feat: 提交构建 2025-07-05 01:06:19 +08:00
chenchun
85e291e0b8 chorm: 修改构建域名 2025-07-04 19:17:45 +08:00
chenchun
6d8a859b20 feat: 关闭前端动画 2025-07-04 19:13:21 +08:00
ccnetcore
a70dfb0769 feat: 完成跨域处理 2025-07-04 00:16:58 +08:00
Gsh
c637d412e6 fix:增加用户中心,完成Apikey功能页,增加角色工具方法 2025-07-04 00:12:26 +08:00
ccnetcore
e996bc2d7f feat: 完成token模块 2025-07-03 22:44:52 +08:00
ccnetcore
15be047371 feat: 完成openapi改造 2025-07-03 22:31:39 +08:00
ccnetcore
0a0e0bca10 feat: 完成上下文功能 2025-07-03 21:28:40 +08:00
Gsh
9a8f3bd161 fix:增加seo优化 2025-07-03 17:13:21 +08:00
ccnetcore
7e2c035692 feat: 完成api接口搭建 2025-07-02 23:30:29 +08:00
chenchun
72795382a1 style: 调整样式 2025-07-02 15:03:16 +08:00
橙子
35cdff2afa update README.md.
Signed-off-by: 橙子 <454313500@qq.com>
2025-07-02 06:04:18 +00:00
橙子
dcf547f513 style: 新增赞助
Signed-off-by: 橙子 <454313500@qq.com>
2025-07-02 06:03:28 +00:00
橙子
8660d45f36 update README.md.
Signed-off-by: 橙子 <454313500@qq.com>
2025-07-02 06:01:51 +00:00
橙子
63dd55e7a4 !95 修正分页导致部门结构显示异常。取消后台分页功能,同菜单结构无需分页。
Merge pull request !95 from Po/N/A
2025-07-02 03:49:56 +00:00
Po
40cd89f90c 修正分页导致部门结构显示异常。取消后台分页功能,同菜单结构无需分页。
Signed-off-by: Po <448443959@qq.com>
2025-07-02 02:50:06 +00:00
ccnetcore
44b2ade9bc feat: 完成错误信息输出 2025-07-02 00:28:44 +08:00
Gsh
1200d02fbf fix:对话时只提供最近6条记录 2025-07-02 00:11:43 +08:00
chenchun
b020f48325 style: 调整配置jwt文件 2025-07-01 16:41:58 +08:00
chenchun
917857f1ff feat: 修改超时,改成10分钟 2025-07-01 16:11:41 +08:00
ccnetcore
69d8ff1034 fix: 修改deepseek校验 2025-06-30 22:23:37 +08:00
ccnetcore
9a334101ca fix: 修复ai模型问题 2025-06-30 21:58:34 +08:00
ccnetcore
ee53b3d9c4 feat: 完成细节调整 2025-06-30 21:08:32 +08:00
Gsh
01a5ad5302 fix:模型选择限制 2025-06-30 17:53:59 +08:00
Gsh
f12f0e1f84 fix:双token更新 2025-06-30 16:59:20 +08:00
Gsh
6aefcdbed8 fix:登录判断优化 2025-06-30 16:02:39 +08:00
ccnetcore
3d22a2ef65 feat: 完成支持鉴权刷新功能 2025-06-29 19:34:09 +08:00
Gsh
a33c6dbf1a fix: 增加用户角色标识与优化产品页 2025-06-29 17:47:07 +08:00
ccnetcore
2b7c779e14 style: 新增样式 2025-06-29 16:36:34 +08:00
ccnetcore
0e36f7c0b3 feat: 完成登录校验拦截 2025-06-29 15:41:49 +08:00
ccnetcore
228a309545 Revert "fix: 修复token样式"
This reverts commit b15ad8eb5e.
2025-06-29 15:22:57 +08:00
ccnetcore
b15ad8eb5e fix: 修复token样式 2025-06-29 15:22:04 +08:00
ccnetcore
a525735b0b Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-06-29 15:18:45 +08:00
ccnetcore
6a58af8dfb feat: 完成双token刷新 2025-06-29 15:18:30 +08:00
Gsh
0089e63832 feat: 产品订阅页面优化 2025-06-29 14:42:10 +08:00
ccnetcore
d4f00eb89f style: 修改Ai_Session表类型 2025-06-29 12:21:28 +08:00
Gsh
d15e6e395b fix: 修复拦截器报错 2025-06-29 12:09:34 +08:00
Gsh
39eb4bef07 fix: bbs与ai存储refreshToken 2025-06-29 00:57:57 +08:00
ccnetcore
03de576d8c fix: 修复值对象报错问题 2025-06-28 23:39:15 +08:00
ccnetcore
216b57a4c7 feat: 更新hook fetch 库 2025-06-28 23:07:32 +08:00
Gsh
5383d2d40e fix: 前端请求头增加浏览器指纹 2025-06-28 18:44:10 +08:00
Gsh
1d7a2013e3 fix: 单点登录优化与环境变量完善 2025-06-28 18:14:12 +08:00
Gsh
24d2908cca update: 修复样式规则报错 2025-06-28 14:33:13 +08:00
ccnetcore
330845a387 style: 调整下拉框样式 2025-06-27 22:50:51 +08:00
ccnetcore
bbedd01a72 fix: 兼容claude ai 2025-06-27 22:49:08 +08:00
ccnetcore
2b07061c18 feat: 完成个个模型ai统计 2025-06-27 22:21:44 +08:00
ccnetcore
01a3c81359 feat: 完成用量统计功能模块 2025-06-27 22:13:26 +08:00
Gsh
96e275efa6 fix: 单点登录优化 2025-06-27 14:23:06 +08:00
chenchun
12eb6c73c3 feat: 完成接入claude 2025-06-26 17:54:52 +08:00
ccnetcore
4166eddd28 Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-06-26 00:38:53 +08:00
ccnetcore
6ea1592c19 style: 调整标题样式 2025-06-26 00:38:36 +08:00
Gsh
f8799a073c Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-06-26 00:37:04 +08:00
Gsh
0eb83fc930 fix: 产品页面完善,增加空白布局与布局切换 2025-06-26 00:35:13 +08:00
ccnetcore
a5dd3946f8 fix: 修复模型接口错误 2025-06-25 23:15:31 +08:00
ccnetcore
2732df24af fix: 修复模型接口错误 2025-06-25 23:05:20 +08:00
ccnetcore
f0ae27a50b fix: 修复模型接口错误 2025-06-25 22:45:57 +08:00
ccnetcore
c5037ea397 feat: 完成ai网关改造 2025-06-25 22:41:32 +08:00
chenchun
695aaedfba feat: 完成ai-hub第一期功能 2025-06-25 17:12:09 +08:00
ccnetcore
4f71d874bd style: 调整速度 2025-06-25 00:35:25 +08:00
ccnetcore
c69729fadd feat: 提交队列 2025-06-25 00:30:01 +08:00
ccnetcore
64d04996af perf: 优化sse流式传输 2025-06-25 00:23:00 +08:00
ccnetcore
8eea510583 feat: ai完成接入deepseek 2025-06-25 00:05:00 +08:00
Gsh
04c2b246f6 fix: 放开产品页面 2025-06-23 23:36:59 +08:00
ccnetcore
a46eb176d7 feat: 还原 2025-06-23 23:04:22 +08:00
ccnetcore
2bea88f1a3 feat: 新增pro打包 2025-06-23 23:03:54 +08:00
ccnetcore
06617de984 feat: 完成对接接口 2025-06-22 19:09:13 +08:00
Gsh
6459d7c024 fix: ai-hub接口替换 2025-06-21 22:12:21 +08:00
Gsh
bd4af8039f fix: 用户信息接口替换 2025-06-21 21:57:07 +08:00
Gsh
8aaa22cea3 feat: ai-hub与bbs单点登录联通 2025-06-21 21:52:44 +08:00
ccnetcore
7d902682f8 feat: 完成账户信息转发 2025-06-21 21:40:51 +08:00
ccnetcore
a81be99100 style: 调整前端样式 2025-06-21 13:34:56 +08:00
ccnetcore
b6dfe93d2c Merge remote-tracking branch 'origin/ai-hub' into ai-hub 2025-06-21 13:30:21 +08:00
ccnetcore
35aa022984 fix: 优化用户更新,超管问题 2025-06-21 13:30:12 +08:00
ccnetcore
dfe2d4cc37 fix: 优化用户更新,超管问题 2025-06-21 13:29:41 +08:00
ccnetcore
1d16502d32 feat: 完成dto搭建 2025-06-21 13:20:13 +08:00
ccnetcore
25c88187a3 feat: 改造接口 2025-06-21 13:15:14 +08:00
ccnetcore
ac04e846fa feat: 完成ai message、session搭建 2025-06-21 13:02:38 +08:00
ccnetcore
29985e2118 feat: 完成ai网关搭建 2025-06-21 01:41:05 +08:00
ccnetcore
3b74dfd49a feat:完成ai网关搭建 2025-06-21 01:08:14 +08:00
cc
6abcc49ed4 feat: 提交 2025-06-20 18:06:33 +08:00
Gsh
f16e1cd7a6 fix: 关闭打包检查 2025-06-20 01:19:15 +08:00
ccnetcore
4341b8a24b style: 设置前端logo样式 2025-06-20 00:06:10 +08:00
Gsh
a89e11d132 feat: 前端接口代理 2025-06-19 23:45:22 +08:00
ccnetcore
bc91a8cff2 feat: 新增取消功能 2025-06-19 22:24:21 +08:00
ccnetcore
8040010b98 feat: 完成ai接口 2025-06-19 21:24:13 +08:00
ccnetcore
b39f15c798 feat: 新增文件夹 2025-06-19 19:13:43 +08:00
ccnetcore
c3cf49c63e feat: 完成节点改造 2025-06-19 14:17:24 +08:00
ccnetcore
899bd7e316 feat: 完成cicd流水线 2025-06-19 01:02:08 +08:00
Gsh
890727d495 feat: 产品页面搭建 2025-06-18 23:28:27 +08:00
ccnetcore
8a8e69596a feat: 完成ai改造 2025-06-17 23:38:20 +08:00
ccnetcore
58fcc92e4d feat: 完成AzureOpenAI改造 2025-06-17 23:25:55 +08:00
Gsh
0cd795f57a feat: 前端搭建 2025-06-17 22:37:37 +08:00
ccnetcore
4830be6388 feat: 搭建ai 2025-06-16 22:39:09 +08:00
ccnetcore
901ccc7314 feat: 处理短信升级问题 2025-06-02 02:40:22 +08:00
ccnetcore
629add1e8a feat: 支持用户限制 2025-06-02 02:12:38 +08:00
chenchun
8b92cd6bed perf: 支持ai转义 2025-05-01 15:58:43 +08:00
chenchun
e63fb71ef6 fix: 支持ai转义功能 2025-05-01 15:58:03 +08:00
chenchun
aa122d2d82 Merge remote-tracking branch 'origin/abp' into abp 2025-05-01 14:55:45 +08:00
chenchun
5d6bfe36d0 logs: 日志调整 2025-05-01 14:55:32 +08:00
橙子
26dadd7dae !92 优化动态下拉框宽度样式,和延迟获取数据
Merge pull request !92 from JiangCY/abp
2025-04-17 07:09:43 +00:00
橙子
520dca6953 !93 update Yi.RuoYi.Vue3/src/utils/index.js.
Merge pull request !93 from fenngmr/fix-utils-parseTime
2025-04-17 07:09:23 +00:00
fenngmr
699f7febe4 update Yi.RuoYi.Vue3/src/utils/index.js.
Signed-off-by: fenngmr <guo_fengxian@163.com>
2025-04-14 08:11:32 +00:00
橙子
87a14ebac1 feat: 社区新增有偿悬赏功能 2025-04-12 23:18:06 +08:00
JiangCYkk
29573342b5 优化动态下拉框宽度样式,和延迟获取数据 2025-04-08 17:27:26 +08:00
橙子
91b216c06e !91 1.处理删除菜单传参错误的问题;
Merge pull request !91 from JiangCY/abp
2025-03-30 03:29:35 +00:00
JiangCYkk
83a6ec1b98 1.处理删除菜单传参错误的问题;
2.处理字典数据新增修改窗口没有提交按钮的问题;
2025-03-28 16:46:05 +08:00
JiangCYkk
c5d636d697 添加动态数据下拉框,可以通过下拉框筛选获取后台数据;
未实现滚动分页;
2025-03-28 16:45:36 +08:00
JiangCYkk
3d704220f3 添加数据库上下文改为 services.Add() 方法,TryAdd() 让后面的 YiRbacDbContext 无法注入,导致数据权限过滤失效了 2025-03-28 16:45:26 +08:00
橙子
b830317608 Merge remote-tracking branch 'origin/abp' into abp 2025-03-23 17:16:37 +08:00
橙子
21ff599a4e fix: 修复更新事件 2025-03-23 17:15:17 +08:00
chenchun
224c2b96e4 feat: 新增模型 2025-03-21 18:25:22 +08:00
chenchun
cbb3510d94 feat: 重构聊天室语义内核 2025-03-21 18:24:59 +08:00
chenchun
0b111852ec fix: 修复点数问题 2025-03-21 15:51:44 +08:00
chenchun
ff8038a616 fix: 修复股市问题 2025-03-21 15:36:22 +08:00
橙子
710ad95eda feat: 支持默认启用redis 2025-03-18 23:13:16 +08:00
橙子
f7d9effa07 feat: 上线ai股市模块 2025-03-15 00:58:10 +08:00
橙子
cec28faaf7 perf: 优化提示词 2025-03-14 00:14:44 +08:00
橙子
bcdcca82eb fix: 修复排序问题 2025-03-14 00:10:31 +08:00
chenchun
4e0cc9a24a feat: 完善前端界面 2025-03-13 20:45:23 +08:00
chenchun
53a402a656 feat: 优化提示词 2025-03-13 15:30:24 +08:00
橙子
85ed4df1e4 fix: 修复记录时间 2025-03-11 22:00:11 +08:00
chenchun
8ef91ebd03 feat: 完成股票价格生成job 2025-03-11 13:43:26 +08:00
chenchun
ccaebb8ec2 feat: 完善提示词 2025-03-11 13:40:15 +08:00
橙子
4afc1cc492 feat: 新增job db选择 2025-03-10 22:27:54 +08:00
橙子
ddba0f9aa1 style: 修改默认redisdb 2025-03-10 22:08:38 +08:00
橙子
c782246a1d feat: 完成提示词工程 2025-03-09 23:51:30 +08:00
橙子
afa5fad8c6 Merge remote-tracking branch 'origin/stock' into stock 2025-03-09 16:21:52 +08:00
橙子
d605809932 feat: 完善对接接口 2025-03-09 16:21:47 +08:00
橙子
30250db0fb feat: 完善对接接口 2025-03-09 16:21:39 +08:00
橙子
b48f584db8 style: 修改定时任务种子数据 2025-03-08 23:36:03 +08:00
橙子
56d850d74b chorm: 构建 2025-03-08 23:22:01 +08:00
橙子
3ef1323f05 stly: 更换样式 2025-03-08 22:49:08 +08:00
橙子
d9ed547a20 stly: 更换样式 2025-03-08 22:47:30 +08:00
橙子
82865631fc feat: ai完成stock模块搭建 2025-03-08 22:14:26 +08:00
橙子
337088c908 feat: 补充部分功能 2025-03-07 00:35:32 +08:00
橙子
c092ee46e9 feat: 完成ai生成 2025-03-05 23:08:58 +08:00
橙子
287634cf99 feat: 新增ai-stock模块 2025-03-02 01:54:12 +08:00
橙子
c1535fd116 perf: 优化错误提示 2025-03-01 23:43:19 +08:00
橙子
d7d4fd8a48 perf: 优化排行榜页面 2025-03-01 14:58:21 +08:00
橙子
1552b00516 perf: 优化首页 2025-03-01 02:41:33 +08:00
橙子
a40d9b79b4 feat:新增stock页面 2025-03-01 01:53:55 +08:00
橙子
0bc5b1a940 feat:新增stock页面 2025-03-01 01:53:42 +08:00
橙子
4dce50438c feat: 完成 2025-03-01 00:12:56 +08:00
橙子
de7f9264fd Merge branch 'refs/heads/stock' into perf-ai 2025-03-01 00:08:32 +08:00
橙子
f00a90f1ef Merge branch 'refs/heads/abp' into perf-ai 2025-03-01 00:08:22 +08:00
橙子
2c578cc9e4 feat: 新增模块 2025-03-01 00:06:56 +08:00
橙子
a04974d905 feat: 新增stock模块 2025-02-28 23:50:35 +08:00
chenchun
23cedbec83 feat: 支持更多ai接入 2025-02-25 15:09:17 +08:00
橙子
3e07ca822a refactor: ai+人工重构优化 framework 2025-02-23 03:06:06 +08:00
橙子
f9341fd2ac feat: 完成单元测试搭建 2025-02-23 01:41:31 +08:00
橙子
f6b19ec2a5 feat: 完成job模块优化 2025-02-23 01:31:30 +08:00
橙子
f8a4c737ee update README.md.
Signed-off-by: 橙子 <454313500@qq.com>
2025-02-22 08:32:32 +00:00
橙子
c395900861 !89 docs: Improve module and dependency documentation clarity
Merge pull request !89 from bytebistro/abp
2025-02-22 07:59:31 +00:00
橙子
b2ad667894 style: 修改md 2025-02-22 15:56:54 +08:00
橙子
45736dfce9 feat: 完成多租户优化改造 2025-02-22 15:26:00 +08:00
chenchun
753b5b0a26 feat: 优化多租户配置 2025-02-21 18:00:06 +08:00
bytebistro
3aaed801f6 docs: Improve module and dependency documentation clarity 2025-02-14 14:37:45 +08:00
橙子
1fd4f2754a feat:优化文章性能 2025-02-12 22:25:27 +08:00
橙子
bedee3391e feat:聊天室支持公式,优化文章 2025-02-12 22:25:15 +08:00
橙子
176a672e86 update README-en.md.
Signed-off-by: 橙子 <454313500@qq.com>
2025-02-09 14:29:55 +00:00
橙子
9da6bcde41 update README.md.
Signed-off-by: 橙子 <454313500@qq.com>
2025-02-09 14:29:18 +00:00
橙子
3f8daa1d17 update README-Docker.md.
Signed-off-by: 橙子 <454313500@qq.com>
2025-02-09 14:25:52 +00:00
橙子
ed873da3b6 feat: 支持docker 2025-02-09 22:23:23 +08:00
橙子
c0dfa83828 doc: 完善docker文档 2025-02-09 01:49:07 +08:00
橙子
db08688968 Merge remote-tracking branch 'origin/abp' into abp 2025-02-09 01:28:22 +08:00
橙子
400a146a48 feat: 新增docker支持 2025-02-09 01:28:13 +08:00
chenchun
a645264da7 feat: 统一修改时区 2025-02-08 10:39:53 +08:00
chenchun
09d19d876f fix: 时区默认采用上海 2025-02-08 10:37:33 +08:00
橙子
373877cfcf feat: 支持hangfire内存模式 2025-02-07 17:52:38 +08:00
橙子
9e143c0a75 style: 修改job时间 2025-02-07 16:06:46 +08:00
橙子
37b16e8395 perf: 整体优化细节 2025-02-06 12:54:48 +08:00
橙子
9c94953e0e fix: 修复文件上传问题 2025-02-06 11:41:56 +08:00
橙子
2c48b8f881 feat:新增面试宝典 2025-02-05 11:58:50 +08:00
橙子
4c4b78dda7 perf: 优化包版本 2025-02-05 11:36:20 +08:00
橙子
4ba9a7917f feat:支持更新时间或者创建时间排序 2025-02-05 00:59:25 +08:00
橙子
5d286ebc9e feat: db操作支持不修改更新审计日志 2025-02-05 00:02:04 +08:00
橙子
e69bbb46b3 fix: 修复跳转刷新问题 2025-02-04 15:47:59 +08:00
1798 changed files with 65252 additions and 3280 deletions

2
.gitignore vendored
View File

@@ -263,7 +263,9 @@ src/Acme.BookStore.Blazor.Server.Tiered/Logs/*
# Use abp install-libs to restore.
**/wwwroot/libs/*
public
dist
dist - 副本
.vscode
/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Development.json
/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.Production.json

37
README-Docker.md Normal file
View File

@@ -0,0 +1,37 @@
# 🍉Docker 构建说明
## 🍊后端
执行目录Yi\Yi.Abp.Net8
#### 🍊启动
D:/code/csharp/source/Yi/Yi.Bbs.Vue3/yi-bbs.conf 为我的配置文件,内部带了默认的配置文件,根据自己配置进行更改
//不带配置文件
docker run -d --name yi.admin -p 19001:19001 jiftcc/yi.admin:1.0.0
//带配置文件
docker run -d --name yi.admin -p 19001:19001 -v D:/code/csharp/source/Yi/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json:/app/appsettings.json jiftcc/yi.admin:1.0.0
#### 🍊完整代码编译
docker build -t jiftcc/yi.admin:1.0.0 -f Dockerfile .
#### 🍊快速产物编译
docker build -t jiftcc/yi.admin:1.0.0 -f DockerfileFast .
****
## 🍇前端
执行目录Yi\Yi.Bbs.Vue3
#### 🍇启动
D:/code/csharp/source/Yi/Yi.Bbs.Vue3/yi-bbs.conf 为我的conf配置目录默认反向代理到ccnetcore.com根据自己后端地址进行修改配置
docker run -d --name yi.bbs -p 18001:18001 -v D:/code/csharp/source/Yi/Yi.Bbs.Vue3/yi-bbs.conf:/etc/nginx/conf.d/yi-bbs.conf jiftcc/yi.bbs:1.0.0
#### 🍇完整代码编译
docker build -t jiftcc/yi.bbs:1.0.0 -f Dockerfile .
#### 🍇快速产物编译
docker build -t jiftcc/yi.bbs:1.0.0 -f DockerfileFast .

View File

@@ -35,6 +35,18 @@ A Comprehensive Solution, Ultimately Just Another Wheel.
- Yi.RuoYi.Vue3RuoYi JS Backend Frontend
****
## 🍉 docker
Full contentREADME-Docker.md
backend`docker run -d --name yi.admin -p 19001:19001 jiftcc/yi.admin:last`
bbs frontend`docker run -d --name yi.bbs -p 18001:18001 -v /home/Yi/Yi.Bbs.Vue3/yi-bbs.conf:/etc/nginx/conf.d/yi-bbs.conf jiftcc/yi.bbs:last`
> In addition, we provide Docker build operation, and we hope that you can build your own image through this method
****
## 🍊 Official website and demo link

View File

@@ -7,6 +7,12 @@
[![fork](https://gitee.com/ccnetcore/yi/badge/fork.svg?theme=dark)](https://gitee.com/ccnetcore/Yi)
[![license](https://img.shields.io/badge/license-MIT-yellow)](https://gitee.com/ccnetcore/Yi)
本项目 CDN 加速及安全防护由 Tencent EdgeOne 赞助
[亚洲最佳CDN、边缘和安全解决方案 - Tencent EdgeOne](https://edgeone.ai/zh?from=github)
<img src="readme/edgeone.png"/>
[English](README-en.md) | 简体中文
****
## 🍍 简介:
@@ -22,7 +28,7 @@ YiFramework是一个基于.Net8+Abp.vNext+SqlSugar的DDD领域驱动设计后端
Yi框架-一套与SqlSugar一样爽的.Net8开源框架。
与Sqlsugar理念一致以用户体验出发。
适合.Net8学习、Sqlsugar学习 、项目二次开发。
全生态拥抱AI接入AI100%代码经过AI洗礼
集大成者,终究轮子
更新频繁可watching持续关注。
@@ -41,6 +47,17 @@ Yi框架-一套与SqlSugar一样爽的.Net8开源框架。
- Yi.Pure.Vue3Pure ts后台前端
- Yi.RuoYi.Vue3RuoYi js后台前端
****
## 🍉 docker 一键启动
完整内容在README-Docker.md
后端:`docker run -d --name yi.admin -p 19001:19001 jiftcc/yi.admin:last`
bbs前端`docker run -d --name yi.bbs -p 18001:18001 -v /home/Yi/Yi.Bbs.Vue3/yi-bbs.conf:/etc/nginx/conf.d/yi-bbs.conf jiftcc/yi.bbs:last`
> 另外我们提供docker的build操作我们更希望你能通过此种方式二开构建属于自己的镜像
****
## 🍊 官网及演示地址:
@@ -49,9 +66,9 @@ Yi框架-一套与SqlSugar一样爽的.Net8开源框架。
Yi社区官网网址Bbs社区正式[ccnetcore.com](https://ccnetcore.com) (已上线,欢迎加入)
Rbac后台演示地址https://ccnetcore.com:1000 用户cc、密码123456
Rbac后台演示地址https://data.ccnetcore.com:1000 用户cc、密码123456
Pure后台演示地址https://ccnetcore.com:1001 用户cc、密码123456
Pure后台演示地址https://data.ccnetcore.com:1001 用户cc、密码123456
## 🍏 支持:
@@ -60,8 +77,11 @@ Pure后台演示地址https://ccnetcore.com:1001 用户cc、密码123456
- [x] 完全支持微服务架构
****
## 🍇 详细到爆炸的Yi框架教程导航
0. [社区导航大全](https://ccnetcore.com/article/aaa00329-7f35-d3fe-d258-3a0f8380b742/fb8c871b-41fc-21bc-474f-3a154498f42b)
1. [框架快速开始教程](https://ccnetcore.com/article/aaa00329-7f35-d3fe-d258-3a0f8380b742)(已完成)
2. [框架功能模块教程](https://ccnetcore.com/article/8c464ab3-8ba5-2761-a4b0-3a0f83a9f312)(已完成)
3. [实战演练开发教程](https://ccnetcore.com/article/e89c9593-f337-ada7-d108-3a0f83ae48e6)(已完成)
@@ -247,9 +267,9 @@ js Vue3
作者QQ`454313500`2029年之前作者24小时在线时刻保持活跃更新。
QQ交流群官方一群已满、官方二群已满、官方三群`786308927`(已满)、官方四群:`498310311`基本已满)、官方五群:`981136525`(新群)
QQ交流群官方一群已满、官方二群已满、官方三群`786308927`(已满)、官方四群:`498310311`(已满)、官方五群:`981136525`
微信交流群:官方微信一群(已满)、官方微信二群
微信交流群:官方微信一群(已满)、官方微信二群(已满)、官方微信三群
微信交流群:加作者微信 chengzilaoge520 橙子老哥520备注拉群

View File

@@ -0,0 +1,10 @@
{
"permissions": {
"allow": [
"Bash(dotnet build \"E:\\code\\github\\Yi\\Yi.Abp.Net8\\module\\ai-hub\\Yi.Framework.AiHub.Application\\Yi.Framework.AiHub.Application.csproj\" --no-restore)",
"Read(//e/code/github/Yi/Yi.Ai.Vue3/**)"
],
"deny": [],
"ask": []
}
}

View File

@@ -27,4 +27,7 @@ README.md
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
!.git/refs/heads/**
appsettings.Development.json
appsettings.Production.json
appsettings.Staging.json

22
Yi.Abp.Net8/Dockerfile Normal file
View File

@@ -0,0 +1,22 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER root
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo "Asia/Shanghai" > /etc/timezone
WORKDIR /app
EXPOSE 19001
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /main
COPY . .
WORKDIR "/main/src/Yi.Abp.Web"
RUN dotnet restore "Yi.Abp.Web.csproj"
FROM build AS publish
WORKDIR "/main/src/Yi.Abp.Web"
RUN dotnet publish "Yi.Abp.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Yi.Abp.Web.dll"]

View File

@@ -0,0 +1,11 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER root
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo "Asia/Shanghai" > /etc/timezone
WORKDIR /app
EXPOSE 19001
FROM base AS final
WORKDIR /app
COPY ["./publish","."]
ENTRYPOINT ["dotnet", "Yi.Abp.Web.dll"]

View File

@@ -36,6 +36,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
version.props = version.props
publish.bat = publish.bat
publish_Demo.bat = publish_Demo.bat
Dockerfile = Dockerfile
DockerfileFast = DockerfileFast
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.SqlSugarCore.Abstractions", "framework\Yi.Framework.SqlSugarCore.Abstractions\Yi.Framework.SqlSugarCore.Abstractions.csproj", "{FD6D6860-3753-4747-8A26-977E4A3001F9}"
@@ -172,6 +174,30 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.WeChat.MiniPro
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.BackgroundWorkers.Hangfire", "framework\Yi.Framework.BackgroundWorkers.Hangfire\Yi.Framework.BackgroundWorkers.Hangfire.csproj", "{862CA181-BEE6-4870-82D2-B662E527ED8C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ai-stock", "ai-stock", "{DB46873F-981A-43D8-91B0-D464CCB65943}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Application", "module\ai-stock\Yi.Framework.Stock.Application\Yi.Framework.Stock.Application.csproj", "{B79CE23C-10F8-48A5-A039-5940A188CF5A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Application.Contracts", "module\ai-stock\Yi.Framework.Stock.Application.Contracts\Yi.Framework.Stock.Application.Contracts.csproj", "{846B781A-B77E-4F86-A31F-0B5B57AB0775}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Domain", "module\ai-stock\Yi.Framework.Stock.Domain\Yi.Framework.Stock.Domain.csproj", "{162821E4-8FE0-4A68-B3C0-49BD6596446F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.Domain.Shared", "module\ai-stock\Yi.Framework.Stock.Domain.Shared\Yi.Framework.Stock.Domain.Shared.csproj", "{10273544-715D-4BB3-893C-6F010D947BDD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Stock.SqlSugarCore", "module\ai-stock\Yi.Framework.Stock.SqlSugarCore\Yi.Framework.Stock.SqlSugarCore.csproj", "{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ai-hub", "ai-hub", "{7AD5DBAE-44F9-474B-8F7B-837EDE908934}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.Application", "module\ai-hub\Yi.Framework.AiHub.Application\Yi.Framework.AiHub.Application.csproj", "{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.Application.Contracts", "module\ai-hub\Yi.Framework.AiHub.Application.Contracts\Yi.Framework.AiHub.Application.Contracts.csproj", "{123D1C81-D667-4060-8E85-FFE7FB4584AD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.Domain", "module\ai-hub\Yi.Framework.AiHub.Domain\Yi.Framework.AiHub.Domain.csproj", "{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.Domain.Shared", "module\ai-hub\Yi.Framework.AiHub.Domain.Shared\Yi.Framework.AiHub.Domain.Shared.csproj", "{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AiHub.SqlSugarCore", "module\ai-hub\Yi.Framework.AiHub.SqlSugarCore\Yi.Framework.AiHub.SqlSugarCore.csproj", "{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -434,6 +460,46 @@ Global
{862CA181-BEE6-4870-82D2-B662E527ED8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{862CA181-BEE6-4870-82D2-B662E527ED8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{862CA181-BEE6-4870-82D2-B662E527ED8C}.Release|Any CPU.Build.0 = Release|Any CPU
{B79CE23C-10F8-48A5-A039-5940A188CF5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B79CE23C-10F8-48A5-A039-5940A188CF5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B79CE23C-10F8-48A5-A039-5940A188CF5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B79CE23C-10F8-48A5-A039-5940A188CF5A}.Release|Any CPU.Build.0 = Release|Any CPU
{846B781A-B77E-4F86-A31F-0B5B57AB0775}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{846B781A-B77E-4F86-A31F-0B5B57AB0775}.Debug|Any CPU.Build.0 = Debug|Any CPU
{846B781A-B77E-4F86-A31F-0B5B57AB0775}.Release|Any CPU.ActiveCfg = Release|Any CPU
{846B781A-B77E-4F86-A31F-0B5B57AB0775}.Release|Any CPU.Build.0 = Release|Any CPU
{162821E4-8FE0-4A68-B3C0-49BD6596446F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{162821E4-8FE0-4A68-B3C0-49BD6596446F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{162821E4-8FE0-4A68-B3C0-49BD6596446F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{162821E4-8FE0-4A68-B3C0-49BD6596446F}.Release|Any CPU.Build.0 = Release|Any CPU
{10273544-715D-4BB3-893C-6F010D947BDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10273544-715D-4BB3-893C-6F010D947BDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10273544-715D-4BB3-893C-6F010D947BDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10273544-715D-4BB3-893C-6F010D947BDD}.Release|Any CPU.Build.0 = Release|Any CPU
{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F49318F-E6C7-4194-BAE0-83D4FB8D1983}.Release|Any CPU.Build.0 = Release|Any CPU
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895}.Release|Any CPU.Build.0 = Release|Any CPU
{123D1C81-D667-4060-8E85-FFE7FB4584AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{123D1C81-D667-4060-8E85-FFE7FB4584AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{123D1C81-D667-4060-8E85-FFE7FB4584AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{123D1C81-D667-4060-8E85-FFE7FB4584AD}.Release|Any CPU.Build.0 = Release|Any CPU
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D}.Release|Any CPU.Build.0 = Release|Any CPU
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48}.Release|Any CPU.Build.0 = Release|Any CPU
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -511,6 +577,18 @@ Global
{4CE6E4AE-0BA4-4984-A4F1-A9A414B1BB8F} = {B8F76A6B-2EEB-4E64-9F26-D84584E16B9C}
{81CEA2ED-917B-41D8-BE0D-39A785B050C0} = {77B949E9-530E-45A5-9657-20F7D5C6875C}
{862CA181-BEE6-4870-82D2-B662E527ED8C} = {77B949E9-530E-45A5-9657-20F7D5C6875C}
{DB46873F-981A-43D8-91B0-D464CCB65943} = {2317227D-7796-4E7B-BEDB-7CD1CAE7B853}
{B79CE23C-10F8-48A5-A039-5940A188CF5A} = {DB46873F-981A-43D8-91B0-D464CCB65943}
{846B781A-B77E-4F86-A31F-0B5B57AB0775} = {DB46873F-981A-43D8-91B0-D464CCB65943}
{162821E4-8FE0-4A68-B3C0-49BD6596446F} = {DB46873F-981A-43D8-91B0-D464CCB65943}
{10273544-715D-4BB3-893C-6F010D947BDD} = {DB46873F-981A-43D8-91B0-D464CCB65943}
{5F49318F-E6C7-4194-BAE0-83D4FB8D1983} = {DB46873F-981A-43D8-91B0-D464CCB65943}
{7AD5DBAE-44F9-474B-8F7B-837EDE908934} = {2317227D-7796-4E7B-BEDB-7CD1CAE7B853}
{1AD10DD2-535E-4EAB-A8A4-EC3FCA206895} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
{123D1C81-D667-4060-8E85-FFE7FB4584AD} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
{8EB4C8BB-6B21-4811-9FAB-B98FA5CA754D} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
{5FC6CA90-D5B4-433E-9B2C-94330FFB4C48} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
{8698C812-4DDC-4E80-BCD6-24C5D56AEDB1} = {7AD5DBAE-44F9-474B-8F7B-837EDE908934}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {23D6FBC9-C970-4641-BC1E-2AEA59F51C18}

View File

@@ -0,0 +1,64 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using Yi.Framework.Core.Authentication;
namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Authentication;
/// <summary>
/// 可刷新的鉴权提供者
/// </summary>
public class RefreshAuthenticationHandlerProvider : IRefreshAuthenticationHandlerProvider
{
private Dictionary<string, IAuthenticationHandler> _handlerMap =
new Dictionary<string, IAuthenticationHandler>((IEqualityComparer<string>)StringComparer.Ordinal);
/// <summary>Constructor.</summary>
/// <param name="schemes">The <see cref="T:Microsoft.AspNetCore.Authentication.IAuthenticationHandlerProvider" />.</param>
public RefreshAuthenticationHandlerProvider(IAuthenticationSchemeProvider schemes)
{
this.Schemes = schemes;
}
/// <summary>
/// The <see cref="T:Microsoft.AspNetCore.Authentication.IAuthenticationHandlerProvider" />.
/// </summary>
public IAuthenticationSchemeProvider Schemes { get; }
/// <summary>Returns the handler instance that will be used.</summary>
/// <param name="context">The context.</param>
/// <param name="authenticationScheme">The name of the authentication scheme being handled.</param>
/// <returns>The handler instance.</returns>
public async Task<IAuthenticationHandler?> GetHandlerAsync(
HttpContext context,
string authenticationScheme)
{
IAuthenticationHandler handlerAsync;
if (this._handlerMap.TryGetValue(authenticationScheme, out handlerAsync))
return handlerAsync;
AuthenticationScheme schemeAsync = await this.Schemes.GetSchemeAsync(authenticationScheme);
if (schemeAsync == null)
return (IAuthenticationHandler)null;
if ((context.RequestServices.GetService(schemeAsync.HandlerType) ??
ActivatorUtilities.CreateInstance(context.RequestServices, schemeAsync.HandlerType)) is
IAuthenticationHandler handler)
{
handlerAsync = handler;
await handler.InitializeAsync(schemeAsync, context);
this._handlerMap[authenticationScheme] = handler;
}
return handlerAsync;
}
/// <summary>
/// 刷新鉴权
/// </summary>
public void RefreshAuthentication()
{
_handlerMap = new Dictionary<string, IAuthenticationHandler>((IEqualityComparer<string>)StringComparer.Ordinal);
}
}

View File

@@ -4,13 +4,23 @@ using Yi.Framework.AspNetCore.Microsoft.AspNetCore.Middlewares;
namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Builder
{
/// <summary>
/// 提供API信息处理的应用程序构建器扩展方法
/// </summary>
public static class ApiInfoBuilderExtensions
{
public static IApplicationBuilder UseYiApiHandlinge([NotNull] this IApplicationBuilder app)
/// <summary>
/// 使用Yi框架的API信息处理中间件
/// </summary>
/// <param name="builder">应用程序构建器实例</param>
/// <returns>配置后的应用程序构建器实例</returns>
/// <exception cref="ArgumentNullException">当builder参数为null时抛出</exception>
public static IApplicationBuilder UseApiInfoHandling([NotNull] this IApplicationBuilder builder)
{
app.UseMiddleware<ApiInfoMiddleware>();
return app;
// 添加API信息处理中间件到请求管道
builder.UseMiddleware<ApiInfoMiddleware>();
return builder;
}
}
}

View File

@@ -5,49 +5,101 @@ using Volo.Abp.AspNetCore.Mvc;
namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Builder
{
public static class SwaggerBuilderExtensons
/// <summary>
/// Swagger构建器扩展类
/// </summary>
public static class SwaggerBuilderExtensions
{
public static IApplicationBuilder UseYiSwagger(this IApplicationBuilder app, params SwaggerModel[] swaggerModels)
/// <summary>
/// 配置并使用Yi框架的Swagger中间件
/// </summary>
/// <param name="app">应用程序构建器</param>
/// <param name="swaggerConfigs">Swagger配置模型数组</param>
/// <returns>应用程序构建器</returns>
public static IApplicationBuilder UseYiSwagger(
this IApplicationBuilder app,
params SwaggerConfiguration[] swaggerConfigs)
{
var mvcOptions = app.ApplicationServices.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>().Value;
app.UseSwagger();
app.UseSwaggerUI(c =>
if (app == null)
{
foreach (var setting in mvcOptions.ConventionalControllers.ConventionalControllerSettings)
throw new ArgumentNullException(nameof(app));
}
var mvcOptions = app.ApplicationServices
.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>()
.Value;
// 启用Swagger中间件
app.UseSwagger();
// 配置SwaggerUI
app.UseSwaggerUI(options =>
{
// 添加约定控制器的Swagger终结点
var conventionalSettings = mvcOptions.ConventionalControllers.ConventionalControllerSettings;
foreach (var setting in conventionalSettings)
{
c.SwaggerEndpoint($"/swagger/{setting.RemoteServiceName}/swagger.json", setting.RemoteServiceName);
options.SwaggerEndpoint(
$"/swagger/{setting.RemoteServiceName}/swagger.json",
setting.RemoteServiceName);
}
if (mvcOptions.ConventionalControllers.ConventionalControllerSettings.Count==0&&swaggerModels.Length == 0)
// 如果没有配置任何终结点,使用默认配置
if (!conventionalSettings.Any() && (swaggerConfigs == null || !swaggerConfigs.Any()))
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework");
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework");
return;
}
else
// 添加自定义Swagger配置的终结点
if (swaggerConfigs != null)
{
foreach (var k in swaggerModels)
foreach (var config in swaggerConfigs)
{
c.SwaggerEndpoint(k.Url, k.Name);
options.SwaggerEndpoint(config.Url, config.Name);
}
}
});
return app;
}
}
public class SwaggerModel
/// <summary>
/// Swagger配置模型
/// </summary>
public class SwaggerConfiguration
{
public SwaggerModel(string name)
private const string DefaultSwaggerUrl = "/swagger/v1/swagger.json";
/// <summary>
/// Swagger JSON文档的URL
/// </summary>
public string Url { get; }
/// <summary>
/// Swagger文档的显示名称
/// </summary>
public string Name { get; }
/// <summary>
/// 使用默认URL创建Swagger配置
/// </summary>
/// <param name="name">文档显示名称</param>
public SwaggerConfiguration(string name)
: this(DefaultSwaggerUrl, name)
{
this.Name = name;
this.Url = "/swagger/v1/swagger.json";
}
public SwaggerModel(string url, string name)
/// <summary>
/// 创建自定义Swagger配置
/// </summary>
/// <param name="url">Swagger JSON文档URL</param>
/// <param name="name">文档显示名称</param>
public SwaggerConfiguration(string url, string name)
{
this.Url = url;
this.Name = name;
Url = url ?? throw new ArgumentNullException(nameof(url));
Name = name ?? throw new ArgumentNullException(nameof(name));
}
public string Url { get; set; }
public string Name { get; set; }
}
}

View File

@@ -1,39 +1,61 @@
using System.Diagnostics;
using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Json;
using Yi.Framework.Core.Extensions;
using static System.Net.WebRequestMethods;
namespace Yi.Framework.AspNetCore.Microsoft.AspNetCore.Middlewares
{
/// <summary>
/// API响应信息处理中间件
/// 主要用于处理特定文件类型的响应头信息
/// </summary>
[DebuggerStepThrough]
public class ApiInfoMiddleware : IMiddleware, ITransientDependency
{
/// <summary>
/// 处理HTTP请求的中间件方法
/// </summary>
/// <param name="context">HTTP上下文</param>
/// <param name="next">请求处理委托</param>
/// <returns>异步任务</returns>
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
context.Response.OnStarting([DebuggerStepThrough] () =>
// 在响应开始时处理文件下载相关的响应头
context.Response.OnStarting(() =>
{
if (context.Response.StatusCode == StatusCodes.Status200OK
&& context.Response.Headers["Content-Type"].ToString() == "application/vnd.ms-excel")
{
context.FileAttachmentHandle($"{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx");
}
if (context.Response.StatusCode == StatusCodes.Status200OK &&
context.Response.Headers["Content-Type"].ToString() == "application/x-zip-compressed")
{
context.FileAttachmentHandle($"{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.zip");
}
HandleFileDownloadResponse(context);
return Task.CompletedTask;
});
// 继续处理管道中的下一个中间件
await next(context);
}
/// <summary>
/// 处理文件下载响应的响应头信息
/// </summary>
/// <param name="context">HTTP上下文</param>
private static void HandleFileDownloadResponse(HttpContext context)
{
// 仅处理状态码为200的响应
if (context.Response.StatusCode != StatusCodes.Status200OK)
{
return;
}
var contentType = context.Response.Headers["Content-Type"].ToString();
var timestamp = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
// 处理Excel文件下载
if (contentType == "application/vnd.ms-excel")
{
context.FileAttachmentHandle($"{timestamp}.xlsx");
}
// 处理ZIP文件下载
else if (contentType == "application/x-zip-compressed")
{
context.FileAttachmentHandle($"{timestamp}.zip");
}
}
}
}

View File

@@ -1,137 +1,196 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Options;
using Volo.Abp.AspNetCore.Mvc.Conventions;
namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Swagger生成器扩展类
/// </summary>
public static class SwaggerAddExtensions
{
public static IServiceCollection AddYiSwaggerGen<Program>(this IServiceCollection services,
Action<SwaggerGenOptions>? action = null)
/// <summary>
/// 添加Yi框架的Swagger生成器服务
/// </summary>
/// <typeparam name="TProgram">程序入口类型</typeparam>
/// <param name="services">服务集合</param>
/// <param name="setupAction">自定义配置动作</param>
/// <returns>服务集合</returns>
public static IServiceCollection AddYiSwaggerGen<TProgram>(
this IServiceCollection services,
Action<SwaggerGenOptions>? setupAction = null)
{
// 获取MVC配置选项
var mvcOptions = services.GetPreConfigureActions<AbpAspNetCoreMvcOptions>().Configure();
var mvcSettings =
mvcOptions.ConventionalControllers.ConventionalControllerSettings.DistinctBy(x => x.RemoteServiceName);
// 获取并去重远程服务名称
var remoteServiceSettings = mvcOptions.ConventionalControllers
.ConventionalControllerSettings
.DistinctBy(x => x.RemoteServiceName);
services.AddAbpSwaggerGen(
options =>
{
if (action is not null)
{
action.Invoke(options);
}
// 应用外部配置
setupAction?.Invoke(options);
// 配置分组,还需要去重,支持重写,如果外部传入后,将以外部为准
foreach (var setting in mvcSettings.OrderBy(x => x.RemoteServiceName))
{
if (!options.SwaggerGeneratorOptions.SwaggerDocs.ContainsKey(setting.RemoteServiceName))
{
options.SwaggerDoc(setting.RemoteServiceName,
new OpenApiInfo { Title = setting.RemoteServiceName, Version = "v1" });
}
}
// 配置API文档分组
ConfigureApiGroups(options, remoteServiceSettings);
// 根据分组名称过滤 API 文档
options.DocInclusionPredicate((docName, apiDesc) =>
{
if (apiDesc.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
{
var settingOrNull = mvcSettings
.Where(x => x.Assembly == controllerActionDescriptor.ControllerTypeInfo.Assembly)
.FirstOrDefault();
if (settingOrNull is not null)
{
return docName == settingOrNull.RemoteServiceName;
}
}
return false;
});
// 配置API文档过滤器
ConfigureApiFilter(options, remoteServiceSettings);
// 配置Schema ID生成规则
options.CustomSchemaIds(type => type.FullName);
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
if (basePath is not null)
{
foreach (var item in Directory.GetFiles(basePath, "*.xml"))
{
options.IncludeXmlComments(item, true);
}
}
options.AddSecurityDefinition("JwtBearer", new OpenApiSecurityScheme()
{
Description = "直接输入Token即可",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
Scheme = "bearer"
});
var scheme = new OpenApiSecurityScheme()
{
Reference = new OpenApiReference() { Type = ReferenceType.SecurityScheme, Id = "JwtBearer" }
};
options.AddSecurityRequirement(new OpenApiSecurityRequirement()
{
[scheme] = new string[0]
});
// 包含XML注释文档
IncludeXmlComments<TProgram>(options);
options.OperationFilter<AddRequiredHeaderParameter>();
options.SchemaFilter<EnumSchemaFilter>();
// 配置JWT认证
ConfigureJwtAuthentication(options);
// 添加自定义过滤器
ConfigureCustomFilters(options);
}
);
return services;
}
/// <summary>
/// 配置API分组
/// </summary>
private static void ConfigureApiGroups(
SwaggerGenOptions options,
IEnumerable<ConventionalControllerSetting> settings)
{
foreach (var setting in settings.OrderBy(x => x.RemoteServiceName))
{
if (!options.SwaggerGeneratorOptions.SwaggerDocs.ContainsKey(setting.RemoteServiceName))
{
options.SwaggerDoc(setting.RemoteServiceName, new OpenApiInfo
{
Title = setting.RemoteServiceName,
Version = "v1"
});
}
}
}
/// <summary>
/// 配置API文档过滤器
/// </summary>
private static void ConfigureApiFilter(
SwaggerGenOptions options,
IEnumerable<ConventionalControllerSetting> settings)
{
options.DocInclusionPredicate((docName, apiDesc) =>
{
if (apiDesc.ActionDescriptor is ControllerActionDescriptor controllerDesc)
{
var matchedSetting = settings
.FirstOrDefault(x => x.Assembly == controllerDesc.ControllerTypeInfo.Assembly);
return matchedSetting?.RemoteServiceName == docName;
}
return false;
});
}
/// <summary>
/// 包含XML注释文档
/// </summary>
private static void IncludeXmlComments<TProgram>(SwaggerGenOptions options)
{
var basePath = Path.GetDirectoryName(typeof(TProgram).Assembly.Location);
if (basePath is not null)
{
foreach (var xmlFile in Directory.GetFiles(basePath, "*.xml"))
{
options.IncludeXmlComments(xmlFile, true);
}
}
}
/// <summary>
/// 配置JWT认证
/// </summary>
private static void ConfigureJwtAuthentication(SwaggerGenOptions options)
{
options.AddSecurityDefinition("JwtBearer", new OpenApiSecurityScheme
{
Description = "请在此输入JWT Token",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
Scheme = "bearer"
});
var scheme = new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "JwtBearer"
}
};
options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
[scheme] = Array.Empty<string>()
});
}
/// <summary>
/// 配置自定义过滤器
/// </summary>
private static void ConfigureCustomFilters(SwaggerGenOptions options)
{
options.OperationFilter<TenantHeaderOperationFilter>();
options.SchemaFilter<EnumSchemaFilter>();
}
}
/// <summary>
/// Swagger文档枚举字段显示枚举属性和枚举值,以及枚举描述
/// Swagger文档枚举字段显示过滤器
/// </summary>
public class EnumSchemaFilter : ISchemaFilter
{
/// <summary>
/// 实现接口
/// 应用枚举架构过滤器
/// </summary>
/// <param name="model"></param>
/// <param name="context"></param>
public void Apply(OpenApiSchema model, SchemaFilterContext context)
/// <param name="schema">OpenAPI架构</param>
/// <param name="context">架构过滤器上下文</param>
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
if (context.Type.IsEnum)
if (!context.Type.IsEnum) return;
schema.Enum.Clear();
schema.Type = "string";
schema.Format = null;
var enumDescriptions = new StringBuilder();
foreach (var enumName in Enum.GetNames(context.Type))
{
model.Enum.Clear();
model.Type = "string";
model.Format = null;
var enumValue = (Enum)Enum.Parse(context.Type, enumName);
var description = GetEnumDescription(enumValue);
var enumIntValue = Convert.ToInt64(enumValue);
StringBuilder stringBuilder = new StringBuilder();
Enum.GetNames(context.Type)
.ToList()
.ForEach(name =>
{
Enum e = (Enum)Enum.Parse(context.Type, name);
var descrptionOrNull = GetEnumDescription(e);
model.Enum.Add(new OpenApiString(name));
stringBuilder.Append(
$"【枚举:{name}{(descrptionOrNull is null ? string.Empty : $"({descrptionOrNull})")}={Convert.ToInt64(Enum.Parse(context.Type, name))}】<br />");
});
model.Description = stringBuilder.ToString();
schema.Enum.Add(new OpenApiString(enumName));
enumDescriptions.AppendLine(
$"【枚举:{enumName}{(description is null ? string.Empty : $"({description})")}={enumIntValue}】");
}
schema.Description = enumDescriptions.ToString();
}
/// <summary>
/// 获取枚举描述特性值
/// </summary>
private static string? GetEnumDescription(Enum value)
{
var fieldInfo = value.GetType().GetField(value.ToString());
@@ -140,22 +199,30 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
}
}
public class AddRequiredHeaderParameter : IOperationFilter
/// <summary>
/// 租户头部参数过滤器
/// </summary>
public class TenantHeaderOperationFilter : IOperationFilter
{
public static string HeaderKey { get; set; } = "__tenant";
/// <summary>
/// 租户标识键名
/// </summary>
private const string TenantHeaderKey = "__tenant";
/// <summary>
/// 应用租户头部参数过滤器
/// </summary>
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (operation.Parameters == null)
operation.Parameters = new List<OpenApiParameter>();
operation.Parameters ??= new List<OpenApiParameter>();
operation.Parameters.Add(new OpenApiParameter
{
Name = HeaderKey,
Name = TenantHeaderKey,
In = ParameterLocation.Header,
Required = false,
AllowEmptyValue = true,
Description = "租户id或者租户名称(可空为默认租户)"
Description = "租户ID或租户名称(留空表示默认租户)"
});
}
}

View File

@@ -9,65 +9,129 @@ using Volo.Abp.Reflection;
namespace Yi.Framework.AspNetCore.Mvc
{
/// <summary>
/// 自定义路由构建器用于生成API路由规则
/// </summary>
[Dependency(ServiceLifetime.Transient, ReplaceServices = true)]
[ExposeServices(typeof(IConventionalRouteBuilder))]
public class YiConventionalRouteBuilder : ConventionalRouteBuilder
{
public YiConventionalRouteBuilder(IOptions<AbpConventionalControllerOptions> options) : base(options)
/// <summary>
/// 构造函数
/// </summary>
/// <param name="options">ABP约定控制器配置选项</param>
public YiConventionalRouteBuilder(IOptions<AbpConventionalControllerOptions> options)
: base(options)
{
}
/// <summary>
/// 构建API路由
/// </summary>
/// <param name="rootPath">根路径</param>
/// <param name="controllerName">控制器名称</param>
/// <param name="action">Action模型</param>
/// <param name="httpMethod">HTTP方法</param>
/// <param name="configuration">控制器配置</param>
/// <returns>构建的路由URL</returns>
public override string Build(
string rootPath,
string controllerName,
ActionModel action,
string httpMethod,
[CanBeNull] ConventionalControllerSetting configuration)
string rootPath,
string controllerName,
ActionModel action,
string httpMethod,
[CanBeNull] ConventionalControllerSetting configuration)
{
// 获取API路由前缀
var apiRoutePrefix = GetApiRoutePrefix(action, configuration);
var controllerNameInUrl =
NormalizeUrlControllerName(rootPath, controllerName, action, httpMethod, configuration);
// 规范化控制器名称
var normalizedControllerName = NormalizeUrlControllerName(
rootPath,
controllerName,
action,
httpMethod,
configuration);
var url = $"{rootPath}/{NormalizeControllerNameCase(controllerNameInUrl, configuration)}";
// 构建基础URL
var url = $"{rootPath}/{NormalizeControllerNameCase(normalizedControllerName, configuration)}";
//Add {id} path if needed
var idParameterModel = action.Parameters.FirstOrDefault(p => p.ParameterName == "id");
if (idParameterModel != null)
{
if (TypeHelper.IsPrimitiveExtended(idParameterModel.ParameterType, includeEnums: true))
{
url += "/{id}";
}
else
{
var properties = idParameterModel
.ParameterType
.GetProperties(BindingFlags.Instance | BindingFlags.Public);
// 处理ID参数路由
url = BuildIdParameterRoute(url, action, configuration);
foreach (var property in properties)
{
url += "/{" + NormalizeIdPropertyNameCase(property, configuration) + "}";
}
}
}
//Add action name if needed
var actionNameInUrl = NormalizeUrlActionName(rootPath, controllerName, action, httpMethod, configuration);
if (!actionNameInUrl.IsNullOrEmpty())
{
url += $"/{NormalizeActionNameCase(actionNameInUrl, configuration)}";
//Add secondary Id
var secondaryIds = action.Parameters
.Where(p => p.ParameterName.EndsWith("Id", StringComparison.Ordinal)).ToList();
if (secondaryIds.Count == 1)
{
url += $"/{{{NormalizeSecondaryIdNameCase(secondaryIds[0], configuration)}}}";
}
}
// 处理Action名称路由
url = BuildActionNameRoute(url, rootPath, controllerName, action, httpMethod, configuration);
return url;
}
/// <summary>
/// 构建ID参数路由部分
/// </summary>
private string BuildIdParameterRoute(
string baseUrl,
ActionModel action,
ConventionalControllerSetting configuration)
{
var idParameter = action.Parameters.FirstOrDefault(p => p.ParameterName == "id");
if (idParameter == null)
{
return baseUrl;
}
// 处理原始类型ID
if (TypeHelper.IsPrimitiveExtended(idParameter.ParameterType, includeEnums: true))
{
return $"{baseUrl}/{{id}}";
}
// 处理复杂类型ID
var properties = idParameter.ParameterType
.GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (var property in properties)
{
baseUrl += $"/{{{NormalizeIdPropertyNameCase(property, configuration)}}}";
}
return baseUrl;
}
/// <summary>
/// 构建Action名称路由部分
/// </summary>
private string BuildActionNameRoute(
string baseUrl,
string rootPath,
string controllerName,
ActionModel action,
string httpMethod,
ConventionalControllerSetting configuration)
{
var actionNameInUrl = NormalizeUrlActionName(
rootPath,
controllerName,
action,
httpMethod,
configuration);
if (actionNameInUrl.IsNullOrEmpty())
{
return baseUrl;
}
baseUrl += $"/{NormalizeActionNameCase(actionNameInUrl, configuration)}";
// 处理次要ID参数
var secondaryIds = action.Parameters
.Where(p => p.ParameterName.EndsWith("Id", StringComparison.Ordinal))
.ToList();
if (secondaryIds.Count == 1)
{
baseUrl += $"/{{{NormalizeSecondaryIdNameCase(secondaryIds[0], configuration)}}}";
}
return baseUrl;
}
}
}

View File

@@ -13,24 +13,46 @@ using Volo.Abp.Reflection;
namespace Yi.Framework.AspNetCore.Mvc
{
/// <summary>
/// 自定义服务约定实现,用于处理API路由和HTTP方法约束
/// </summary>
[Dependency(ServiceLifetime.Transient, ReplaceServices = true)]
[ExposeServices(typeof(IAbpServiceConvention))]
public class YiServiceConvention : AbpServiceConvention
{
public YiServiceConvention(IOptions<AbpAspNetCoreMvcOptions> options, IConventionalRouteBuilder conventionalRouteBuilder) : base(options, conventionalRouteBuilder)
/// <summary>
/// 初始化服务约定的新实例
/// </summary>
/// <param name="options">ABP AspNetCore MVC 配置选项</param>
/// <param name="conventionalRouteBuilder">约定路由构建器</param>
public YiServiceConvention(
IOptions<AbpAspNetCoreMvcOptions> options,
IConventionalRouteBuilder conventionalRouteBuilder)
: base(options, conventionalRouteBuilder)
{
}
protected override void ConfigureSelector(string rootPath, string controllerName, ActionModel action, ConventionalControllerSetting? configuration)
/// <summary>
/// 配置选择器,处理路由和HTTP方法约束
/// </summary>
protected override void ConfigureSelector(
string rootPath,
string controllerName,
ActionModel action,
ConventionalControllerSetting? configuration)
{
// 移除空选择器
RemoveEmptySelectors(action.Selectors);
var remoteServiceAtt = ReflectionHelper.GetSingleAttributeOrDefault<RemoteServiceAttribute>(action.ActionMethod);
if (remoteServiceAtt != null && !remoteServiceAtt.IsEnabledFor(action.ActionMethod))
// 检查远程服务特性
var remoteServiceAttr = ReflectionHelper
.GetSingleAttributeOrDefault<RemoteServiceAttribute>(action.ActionMethod);
if (remoteServiceAttr != null && !remoteServiceAttr.IsEnabledFor(action.ActionMethod))
{
return;
}
// 根据选择器是否存在执行不同的配置
if (!action.Selectors.Any())
{
AddAbpServiceSelector(rootPath, controllerName, action, configuration);
@@ -41,56 +63,92 @@ namespace Yi.Framework.AspNetCore.Mvc
}
}
protected override void AddAbpServiceSelector(string rootPath, string controllerName, ActionModel action, ConventionalControllerSetting? configuration)
{
base.AddAbpServiceSelector(rootPath, controllerName, action, configuration);
}
protected override void NormalizeSelectorRoutes(string rootPath, string controllerName, ActionModel action, ConventionalControllerSetting? configuration)
/// <summary>
/// 规范化选择器路由
/// </summary>
protected override void NormalizeSelectorRoutes(
string rootPath,
string controllerName,
ActionModel action,
ConventionalControllerSetting? configuration)
{
foreach (var selector in action.Selectors)
{
var httpMethod = selector.ActionConstraints
.OfType<HttpMethodActionConstraint>()
.FirstOrDefault()?
.HttpMethods?
.FirstOrDefault();
if (httpMethod == null)
{
httpMethod = SelectHttpMethod(action, configuration);
}
if (selector.AttributeRouteModel == null)
{
selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(rootPath, controllerName, action, httpMethod, configuration);
}
else
{
var template = selector.AttributeRouteModel.Template;
if (!template.StartsWith("/"))
{
var route = $"{rootPath}/{template}";
selector.AttributeRouteModel.Template = route;
}
}
if (!selector.ActionConstraints.OfType<HttpMethodActionConstraint>().Any())
{
selector.ActionConstraints.Add(new HttpMethodActionConstraint(new[] { httpMethod }));
}
// 获取HTTP方法约束
var httpMethod = GetOrCreateHttpMethod(selector, action, configuration);
// 处理路由模板
ConfigureRouteTemplate(selector, rootPath, controllerName, action, httpMethod, configuration);
// 确保HTTP方法约束存在
EnsureHttpMethodConstraint(selector, httpMethod);
}
}
/// <summary>
/// 获取或创建HTTP方法
/// </summary>
private string GetOrCreateHttpMethod(
SelectorModel selector,
ActionModel action,
ConventionalControllerSetting? configuration)
{
return selector.ActionConstraints
.OfType<HttpMethodActionConstraint>()
.FirstOrDefault()?
.HttpMethods?
.FirstOrDefault()
?? SelectHttpMethod(action, configuration);
}
/// <summary>
/// 配置路由模板
/// </summary>
private void ConfigureRouteTemplate(
SelectorModel selector,
string rootPath,
string controllerName,
ActionModel action,
string httpMethod,
ConventionalControllerSetting? configuration)
{
if (selector.AttributeRouteModel == null)
{
selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(
rootPath,
controllerName,
action,
httpMethod,
configuration);
}
else
{
NormalizeAttributeRouteTemplate(selector, rootPath);
}
}
/// <summary>
/// 规范化特性路由模板
/// </summary>
private void NormalizeAttributeRouteTemplate(SelectorModel selector, string rootPath)
{
var template = selector.AttributeRouteModel.Template;
if (!template.StartsWith("/"))
{
selector.AttributeRouteModel.Template = $"{rootPath}/{template}";
}
}
/// <summary>
/// 确保HTTP方法约束存在
/// </summary>
private void EnsureHttpMethodConstraint(SelectorModel selector, string httpMethod)
{
if (!selector.ActionConstraints.OfType<HttpMethodActionConstraint>().Any())
{
selector.ActionConstraints.Add(
new HttpMethodActionConstraint(new[] { httpMethod }));
}
}
}
}

View File

@@ -5,32 +5,53 @@ using Volo.Abp.AspNetCore.WebClientInfo;
namespace Yi.Framework.AspNetCore;
/// <summary>
/// 真实IP地址提供程序,支持代理服务器场景
/// </summary>
public class RealIpHttpContextWebClientInfoProvider : HttpContextWebClientInfoProvider
{
public RealIpHttpContextWebClientInfoProvider(ILogger<HttpContextWebClientInfoProvider> logger,
IHttpContextAccessor httpContextAccessor) : base(logger, httpContextAccessor)
private const string XForwardedForHeader = "X-Forwarded-For";
/// <summary>
/// 初始化真实IP地址提供程序的新实例
/// </summary>
public RealIpHttpContextWebClientInfoProvider(
ILogger<HttpContextWebClientInfoProvider> logger,
IHttpContextAccessor httpContextAccessor)
: base(logger, httpContextAccessor)
{
}
/// <summary>
/// 获取客户端IP地址,优先从X-Forwarded-For头部获取
/// </summary>
/// <returns>客户端IP地址</returns>
protected override string? GetClientIpAddress()
{
try
{
var httpContext = HttpContextAccessor.HttpContext;
var headers = httpContext?.Request?.Headers;
if (headers != null && headers.ContainsKey("X-Forwarded-For"))
if (httpContext == null)
{
httpContext.Connection.RemoteIpAddress =
IPAddress.Parse(headers["X-Forwarded-For"].FirstOrDefault());
return null;
}
return httpContext?.Connection?.RemoteIpAddress?.ToString();
var headers = httpContext.Request?.Headers;
if (headers != null && headers.ContainsKey(XForwardedForHeader))
{
// 从X-Forwarded-For获取真实客户端IP
var forwardedIp = headers[XForwardedForHeader].FirstOrDefault();
if (!string.IsNullOrEmpty(forwardedIp))
{
httpContext.Connection.RemoteIpAddress = IPAddress.Parse(forwardedIp);
}
}
return httpContext.Connection?.RemoteIpAddress?.ToString();
}
catch (Exception ex)
{
Logger.LogException(ex, LogLevel.Warning);
Logger.LogWarning(ex, "获取客户端IP地址时发生异常");
return null;
}
}

View File

@@ -1,49 +1,55 @@
namespace Yi.Framework.AspNetCore
{
/// <summary>
/// 远程服务成功响应信息
/// </summary>
[Serializable]
public class RemoteServiceSuccessInfo
{
/// <summary>
/// Creates a new instance of <see cref="RemoteServiceSuccessInfo"/>.
/// 获取或设置响应代码
/// </summary>
public string? Code { get; private set; }
/// <summary>
/// 获取或设置响应消息
/// </summary>
public string? Message { get; private set; }
/// <summary>
/// 获取或设置详细信息
/// </summary>
public string? Details { get; private set; }
/// <summary>
/// 获取或设置响应数据
/// </summary>
public object? Data { get; private set; }
/// <summary>
/// 初始化远程服务成功响应信息的新实例
/// </summary>
public RemoteServiceSuccessInfo()
{
}
/// <summary>
/// Creates a new instance of <see cref="RemoteServiceSuccessInfo"/>.
/// 使用指定参数初始化远程服务成功响应信息的新实例
/// </summary>
/// <param name="code">Error code</param>
/// <param name="details">Error details</param>
/// <param name="message">Error message</param>
/// <param name="data">Error data</param>
public RemoteServiceSuccessInfo(string message, string? details = null, string? code = null, object? data = null)
/// <param name="message">响应消息</param>
/// <param name="details">详细信息</param>
/// <param name="code">响应代码</param>
/// <param name="data">响应数据</param>
public RemoteServiceSuccessInfo(
string message,
string? details = null,
string? code = null,
object? data = null)
{
Message = message;
Details = details;
Code = code;
Data = data;
}
/// <summary>
/// code.
/// </summary>
public string? Code { get; set; }
/// <summary>
/// message.
/// </summary>
public string? Message { get; set; }
/// <summary>
/// details.
/// </summary>
public string? Details { get; set; }
/// <summary>
/// data.
/// </summary>
public object? Data { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
// MIT 许可证
// MIT 许可证
//
// 版权 © 2020-present 百小僧, 百签科技(广东)有限公司 和所有贡献者
//
@@ -17,25 +17,25 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Validation;
using Yi.Framework.Core.Extensions;
namespace Yi.Framework.AspNetCore.UnifyResult.Fiters;
/// <summary>
/// 友好异常拦截器
/// 友好异常拦截器
/// </summary>
public sealed class FriendlyExceptionFilter : IAsyncExceptionFilter
{
/// <summary>
/// 异常拦截
/// 异常拦截
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public async Task OnExceptionAsync(ExceptionContext context)
{
// 排除 WebSocket 请求处理
if (context.HttpContext.IsWebSocketRequest()) return;
@@ -44,20 +44,23 @@ public sealed class FriendlyExceptionFilter : IAsyncExceptionFilter
// 解析异常信息
var exceptionMetadata = GetExceptionMetadata(context);
IUnifyResultProvider unifyResult = context.GetRequiredService<IUnifyResultProvider>();
var unifyResult = context.GetRequiredService<IUnifyResultProvider>();
// 执行规范化异常处理
context.Result = unifyResult.OnException(context, exceptionMetadata);
// 创建日志记录器
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<FriendlyExceptionFilter>>();
var errorMsg = "";
if (exceptionMetadata.Errors != null) errorMsg = "\n" + JsonConvert.SerializeObject(exceptionMetadata.Errors);
// 记录拦截日常
logger.LogError(context.Exception, context.Exception.Message);
logger.LogError(context.Exception, context.Exception.Message + errorMsg);
}
/// <summary>
/// 获取异常元数据
/// 获取异常元数据
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
@@ -74,22 +77,25 @@ public sealed class FriendlyExceptionFilter : IAsyncExceptionFilter
// 判断是否是 ExceptionContext 或者 ActionExecutedContext
var exception = context is ExceptionContext exContext
? exContext.Exception
: (
context is ActionExecutedContext edContext
? edContext.Exception
: default
);
: context is ActionExecutedContext edContext
? edContext.Exception
: default;
if (exception is AbpValidationException validationException)
{
errors = validationException.ValidationErrors;
isValidationException = true;
}
// 判断是否是友好异常
if (exception is UserFriendlyException friendlyException)
{
int statusCode2 = 500;
var statusCode2 = 500;
int.TryParse(friendlyException.Code, out statusCode2);
isFriendlyException = true;
errorCode = friendlyException.Code;
originErrorCode = friendlyException.Code;
statusCode = statusCode2==0?403:statusCode2;
isValidationException = false;
statusCode = statusCode2 == 0 ? 403 : statusCode2;
errors = friendlyException.Message;
data = friendlyException.Data;
}

View File

@@ -2,6 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.SwaggerGen;
using Volo.Abp.AspNetCore.Mvc.ExceptionHandling;
using Volo.Abp.AspNetCore.Mvc.Response;
using Yi.Framework.AspNetCore.UnifyResult.Fiters;
namespace Yi.Framework.AspNetCore.UnifyResult;
@@ -20,9 +21,10 @@ public static class UnifyResultExtensions
services.AddTransient<FriendlyExceptionFilter>();
services.AddMvc(options =>
{
options.Filters.RemoveAll(x => (x as ServiceFilterAttribute)?.ServiceType == typeof(AbpExceptionFilter));
options.Filters.RemoveAll(x => (x as ServiceFilterAttribute)?.ServiceType == typeof(AbpNoContentActionFilter));
options.Filters.AddService<SucceededUnifyResultFilter>(99);
options.Filters.AddService<FriendlyExceptionFilter>(100);
options.Filters.RemoveAll(x => (x as ServiceFilterAttribute)?.ServiceType == typeof(AbpExceptionFilter));
});
return services;
}

View File

@@ -1,33 +1,37 @@
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Linq;
using Swashbuckle.AspNetCore.SwaggerGen;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.WebClientInfo;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Modularity;
using Yi.Framework.AspNetCore.Mvc;
using Yi.Framework.AspNetCore.Microsoft.AspNetCore.Authentication;
using Yi.Framework.Core;
using Yi.Framework.Core.Authentication;
namespace Yi.Framework.AspNetCore
{
[DependsOn(typeof(YiFrameworkCoreModule)
)]
/// <summary>
/// Yi框架ASP.NET Core模块
/// </summary>
[DependsOn(typeof(YiFrameworkCoreModule))]
public class YiFrameworkAspNetCoreModule : AbpModule
{
/// <summary>
/// 配置服务后的处理
/// </summary>
public override void PostConfigureServices(ServiceConfigurationContext context)
{
var services = context.Services;
services.Replace(new ServiceDescriptor(typeof(IWebClientInfoProvider),
typeof(RealIpHttpContextWebClientInfoProvider), ServiceLifetime.Transient));
// 替换默认的WebClientInfoProvider为支持代理的实现
services.Replace(new ServiceDescriptor(
typeof(IWebClientInfoProvider),
typeof(RealIpHttpContextWebClientInfoProvider),
ServiceLifetime.Transient));
// 替换默认的AuthenticationHandlerProvider为支持刷新鉴权
services.Replace(new ServiceDescriptor(
typeof(IAuthenticationHandlerProvider),
typeof(RefreshAuthenticationHandlerProvider),
ServiceLifetime.Scoped));
}
}
}

View File

@@ -5,40 +5,72 @@ using Volo.Abp.Uow;
namespace Yi.Framework.BackgroundWorkers.Hangfire;
public class UnitOfWorkHangfireFilter : IServerFilter, ISingletonDependency
/// <summary>
/// Hangfire 工作单元过滤器
/// 用于管理后台任务的事务处理
/// </summary>
public sealed class UnitOfWorkHangfireFilter : IServerFilter, ISingletonDependency
{
private const string CurrentJobUow = "HangfireUnitOfWork";
private const string UnitOfWorkItemKey = "HangfireUnitOfWork";
private readonly IUnitOfWorkManager _unitOfWorkManager;
/// <summary>
/// 初始化工作单元过滤器
/// </summary>
/// <param name="unitOfWorkManager">工作单元管理器</param>
public UnitOfWorkHangfireFilter(IUnitOfWorkManager unitOfWorkManager)
{
_unitOfWorkManager = unitOfWorkManager;
}
/// <summary>
/// 任务执行前的处理
/// </summary>
/// <param name="context">执行上下文</param>
public void OnPerforming(PerformingContext context)
{
// 开启一个工作单元并存储到上下文中
var uow = _unitOfWorkManager.Begin();
context.Items.Add(CurrentJobUow, uow);
context.Items.Add(UnitOfWorkItemKey, uow);
}
/// <summary>
/// 任务执行后的处理
/// </summary>
/// <param name="context">执行上下文</param>
public void OnPerformed(PerformedContext context)
{
AsyncHelper.RunSync(()=>OnPerformedAsync(context));
AsyncHelper.RunSync(() => OnPerformedAsync(context));
}
/// <summary>
/// 任务执行后的异步处理
/// </summary>
/// <param name="context">执行上下文</param>
private async Task OnPerformedAsync(PerformedContext context)
{
if (context.Items.TryGetValue(CurrentJobUow, out var obj)
&& obj is IUnitOfWork uow)
if (!context.Items.TryGetValue(UnitOfWorkItemKey, out var obj) ||
obj is not IUnitOfWork uow)
{
return;
}
try
{
// 如果没有异常且工作单元未完成,则提交事务
if (context.Exception == null && !uow.IsCompleted)
{
await uow.CompleteAsync();
}
else
{
// 否则回滚事务
await uow.RollbackAsync();
}
}
finally
{
// 确保工作单元被释放
uow.Dispose();
}
}

View File

@@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Volo.Abp.BackgroundJobs.Hangfire" Version="$(AbpVersion)" />
<PackageReference Include="Volo.Abp.BackgroundWorkers.Hangfire" Version="$(AbpVersion)" />
</ItemGroup>

View File

@@ -1,34 +1,90 @@
using Hangfire;
using System.Linq.Expressions;
using Hangfire;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.BackgroundJobs.Hangfire;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.BackgroundWorkers.Hangfire;
using Volo.Abp.DynamicProxy;
namespace Yi.Framework.BackgroundWorkers.Hangfire;
[DependsOn(typeof(AbpBackgroundWorkersHangfireModule))]
public class YiFrameworkBackgroundWorkersHangfireModule : AbpModule
/// <summary>
/// Hangfire 后台任务模块
/// </summary>
[DependsOn(typeof(AbpBackgroundWorkersHangfireModule),
typeof(AbpBackgroundJobsHangfireModule))]
public sealed class YiFrameworkBackgroundWorkersHangfireModule : AbpModule
{
/// <summary>
/// 配置服务前的预处理
/// </summary>
/// <param name="context">服务配置上下文</param>
public override void PreConfigureServices(ServiceConfigurationContext context)
{
// 添加 Hangfire 后台任务约定注册器
context.Services.AddConventionalRegistrar(new YiHangfireConventionalRegistrar());
}
/// <summary>
/// 应用程序初始化
/// </summary>
/// <param name="context">应用程序初始化上下文</param>
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
//定时任务自动注入Abp默认只有在Quartz才实现
var backgroundWorkerManager = context.ServiceProvider.GetRequiredService<IBackgroundWorkerManager>();
var works = context.ServiceProvider.GetServices<IHangfireBackgroundWorker>();
foreach (var work in works)
if (!context.ServiceProvider.GetRequiredService<IOptions<AbpBackgroundWorkerOptions>>().Value.IsEnabled)
{
//如果为空默认使用服务器本地utc时间
work.TimeZone ??= TimeZoneInfo.Local;
await backgroundWorkerManager.AddAsync(work);
return;
}
// 获取后台任务管理器和所有 Hangfire 后台任务
var backgroundWorkerManager = context.ServiceProvider.GetRequiredService<IBackgroundWorkerManager>();
var workers = context.ServiceProvider.GetServices<IHangfireBackgroundWorker>();
// 获取配置
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
// 检查是否启用 Redis
var isRedisEnabled = configuration.GetValue<bool>("Redis:IsEnabled");
foreach (var worker in workers)
{
// 设置时区为本地时区(上海)
worker.TimeZone = TimeZoneInfo.Local;
if (isRedisEnabled)
{
// Redis 模式:使用 ABP 后台任务管理器
await backgroundWorkerManager.AddAsync(worker);
}
else
{
// 内存模式:直接使用 Hangfire
var unProxyWorker = ProxyHelper.UnProxy(worker);
// 添加或更新循环任务
RecurringJob.AddOrUpdate(
worker.RecurringJobId,
(Expression<Func<Task>>)(() =>
((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(default)),
worker.CronExpression,
new RecurringJobOptions
{
TimeZone = worker.TimeZone
});
}
}
}
/// <summary>
/// 应用程序初始化前的预处理
/// </summary>
/// <param name="context">应用程序初始化上下文</param>
public override void OnPreApplicationInitialization(ApplicationInitializationContext context)
{
// 添加工作单元过滤器
var services = context.ServiceProvider;
GlobalJobFilters.Filters.Add(services.GetRequiredService<UnitOfWorkHangfireFilter>());
}

View File

@@ -3,18 +3,32 @@ using Volo.Abp.DependencyInjection;
namespace Yi.Framework.BackgroundWorkers.Hangfire;
public class YiHangfireConventionalRegistrar : DefaultConventionalRegistrar
/// <summary>
/// Hangfire 后台任务约定注册器
/// </summary>
public sealed class YiHangfireConventionalRegistrar : DefaultConventionalRegistrar
{
/// <summary>
/// 检查类型是否禁用约定注册
/// </summary>
/// <param name="type">要检查的类型</param>
/// <returns>如果类型不是 IHangfireBackgroundWorker 或已被禁用则返回 true</returns>
protected override bool IsConventionalRegistrationDisabled(Type type)
{
return !typeof(IHangfireBackgroundWorker).IsAssignableFrom(type) || base.IsConventionalRegistrationDisabled(type);
return !typeof(IHangfireBackgroundWorker).IsAssignableFrom(type) ||
base.IsConventionalRegistrationDisabled(type);
}
/// <summary>
/// 获取要暴露的服务类型列表
/// </summary>
/// <param name="type">实现类型</param>
/// <returns>服务类型列表</returns>
protected override List<Type> GetExposedServiceTypes(Type type)
{
return new List<Type>()
{
typeof(IHangfireBackgroundWorker)
};
return new List<Type>
{
typeof(IHangfireBackgroundWorker)
};
}
}

View File

@@ -6,116 +6,141 @@ using Volo.Abp.Users;
namespace Yi.Framework.BackgroundWorkers.Hangfire;
public class YiTokenAuthorizationFilter : IDashboardAsyncAuthorizationFilter, ITransientDependency
/// <summary>
/// Hangfire 仪表盘的令牌认证过滤器
/// </summary>
public sealed class YiTokenAuthorizationFilter : IDashboardAsyncAuthorizationFilter, ITransientDependency
{
private const string Bearer = "Bearer: ";
private string RequireUser { get; set; } = "cc";
private TimeSpan ExpiresTime { get; set; } = TimeSpan.FromMinutes(10);
private IServiceProvider _serviceProvider;
private const string BearerPrefix = "Bearer ";
private const string TokenCookieKey = "Token";
private const string HtmlContentType = "text/html";
private readonly IServiceProvider _serviceProvider;
private string _requiredUsername = "cc";
private TimeSpan _tokenExpiration = TimeSpan.FromMinutes(10);
/// <summary>
/// 初始化令牌认证过滤器
/// </summary>
/// <param name="serviceProvider">服务提供者</param>
public YiTokenAuthorizationFilter(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public YiTokenAuthorizationFilter SetRequireUser(string userName)
/// <summary>
/// 设置需要的用户名
/// </summary>
/// <param name="username">允许访问的用户名</param>
/// <returns>当前实例,支持链式调用</returns>
public YiTokenAuthorizationFilter SetRequiredUsername(string username)
{
RequireUser = userName;
_requiredUsername = username ?? throw new ArgumentNullException(nameof(username));
return this;
}
public YiTokenAuthorizationFilter SetExpiresTime(TimeSpan expiresTime)
/// <summary>
/// 设置令牌过期时间
/// </summary>
/// <param name="expiration">过期时间间隔</param>
/// <returns>当前实例,支持链式调用</returns>
public YiTokenAuthorizationFilter SetTokenExpiration(TimeSpan expiration)
{
ExpiresTime = expiresTime;
_tokenExpiration = expiration;
return this;
}
/// <summary>
/// 授权验证
/// </summary>
/// <param name="context">仪表盘上下文</param>
/// <returns>是否通过授权</returns>
public bool Authorize(DashboardContext context)
{
var httpContext = context.GetHttpContext();
var _currentUser = _serviceProvider.GetRequiredService<ICurrentUser>();
//如果验证通过设置cookies
if (_currentUser.IsAuthenticated)
var currentUser = _serviceProvider.GetRequiredService<ICurrentUser>();
if (!currentUser.IsAuthenticated)
{
var cookieOptions = new CookieOptions
{
Expires = DateTimeOffset.Now + ExpiresTime, // 设置 cookie 过期时间,10分钟
};
var authorization = httpContext.Request.Headers["Authorization"].ToString();
if (!string.IsNullOrWhiteSpace(authorization))
{
var token = httpContext.Request.Headers["Authorization"].ToString().Substring(Bearer.Length - 1);
httpContext.Response.Cookies.Append("Token", token, cookieOptions);
}
if (_currentUser.UserName == RequireUser)
{
return true;
}
SetChallengeResponse(httpContext);
return false;
}
SetChallengeResponse(httpContext);
return false;
// 如果验证通过,设置 cookie
var authorization = httpContext.Request.Headers.Authorization.ToString();
if (!string.IsNullOrWhiteSpace(authorization) && authorization.StartsWith(BearerPrefix))
{
var token = authorization[BearerPrefix.Length..];
SetTokenCookie(httpContext, token);
}
return currentUser.UserName == _requiredUsername;
}
/// <summary>
/// 设置认证挑战响应
/// 当用户未认证时返回一个包含令牌输入表单的HTML页面
/// </summary>
/// <param name="httpContext">HTTP 上下文</param>
private void SetChallengeResponse(HttpContext httpContext)
{
httpContext.Response.StatusCode = 401;
httpContext.Response.ContentType = "text/html; charset=utf-8";
string html = """
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Token </title>
<script>
function sendToken() {
// 获取输入的 token
var token = document.getElementById("tokenInput").value;
token = token.replace('Bearer ','');
// 构建请求 URL
var url = "/hangfire";
// 发送 GET 请求
fetch(url,{
headers: {
'Content-Type': 'application/json', // 设置内容类型为 JSON
'Authorization': 'Bearer '+encodeURIComponent(token), // 设置授权头,例如使用 Bearer token
},
})
.then(response => {
if (response.ok) {
return response.text(); // 或使用 response.json() 如果返回的是 JSON
}
throw new Error('Network response was not ok.');
})
.then(data => {
// 处理成功返回的数据
document.open();
document.write(data);
document.close();
})
.catch(error => {
// 处理错误
console.error('There has been a problem with your fetch operation:', error);
alert("请求失败: " + error.message);
});
}
</script>
</head>
<body style="text-align: center;">
<h1>Yi-hangfire</h1>
<h1>Token</h1>
<textarea id="tokenInput" placeholder="请输入 token" style="width: 80%;height: 120px;margin: 0 10%;"></textarea>
<button onclick="sendToken()"></button>
</body>
</html>
""";
httpContext.Response.ContentType = HtmlContentType;
var html = @"
<html>
<head>
<title>Hangfire Dashboard Authorization</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
.container { max-width: 400px; margin: 0 auto; }
.form-group { margin-bottom: 15px; }
input[type='text'] { width: 100%; padding: 8px; }
button { background: #337ab7; color: white; border: none; padding: 10px 15px; cursor: pointer; }
button:hover { background: #286090; }
</style>
</head>
<body>
<div class='container'>
<h2>Authorization Required</h2>
<div class='form-group'>
<input type='text' id='token' placeholder='Enter your Bearer token...' />
</div>
<button onclick='authorize()'>Authorize</button>
</div>
<script>
function authorize() {
var token = document.getElementById('token').value;
if (token) {
document.cookie = 'Token=' + token + '; path=/';
window.location.reload();
}
}
</script>
</body>
</html>";
httpContext.Response.WriteAsync(html);
}
/// <summary>
/// 设置令牌 Cookie
/// </summary>
/// <param name="httpContext">HTTP 上下文</param>
/// <param name="token">令牌值</param>
private void SetTokenCookie(HttpContext httpContext, string token)
{
var cookieOptions = new CookieOptions
{
Expires = DateTimeOffset.Now.Add(_tokenExpiration),
HttpOnly = true,
Secure = httpContext.Request.IsHttps,
SameSite = SameSiteMode.Lax
};
httpContext.Response.Cookies.Append(TokenCookieKey, token, cookieOptions);
}
public Task<bool> AuthorizeAsync(DashboardContext context)
{
return Task.FromResult(Authorize(context));

View File

@@ -10,28 +10,43 @@ using Volo.Abp.MultiTenancy;
namespace Yi.Framework.Caching.FreeRedis
{
[Dependency(ReplaceServices =true)]
/// <summary>
/// 缓存键标准化处理器
/// 用于处理缓存键的格式化和多租户支持
/// </summary>
[Dependency(ReplaceServices = true)]
public class YiDistributedCacheKeyNormalizer : IDistributedCacheKeyNormalizer, ITransientDependency
{
protected ICurrentTenant CurrentTenant { get; }
protected AbpDistributedCacheOptions DistributedCacheOptions { get; }
private readonly ICurrentTenant _currentTenant;
private readonly AbpDistributedCacheOptions _distributedCacheOptions;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="currentTenant">当前租户服务</param>
/// <param name="distributedCacheOptions">分布式缓存配置选项</param>
public YiDistributedCacheKeyNormalizer(
ICurrentTenant currentTenant,
IOptions<AbpDistributedCacheOptions> distributedCacheOptions)
{
CurrentTenant = currentTenant;
DistributedCacheOptions = distributedCacheOptions.Value;
_currentTenant = currentTenant;
_distributedCacheOptions = distributedCacheOptions.Value;
}
/// <summary>
/// 标准化缓存键
/// </summary>
/// <param name="args">缓存键标准化参数</param>
/// <returns>标准化后的缓存键</returns>
public virtual string NormalizeKey(DistributedCacheKeyNormalizeArgs args)
{
var normalizedKey = $"{DistributedCacheOptions.KeyPrefix}{args.Key}";
// 添加全局缓存前缀
var normalizedKey = $"{_distributedCacheOptions.KeyPrefix}{args.Key}";
//if (!args.IgnoreMultiTenancy && CurrentTenant.Id.HasValue)
//todo 多租户支持已注释,如需启用取消注释即可
//if (!args.IgnoreMultiTenancy && _currentTenant.Id.HasValue)
//{
// normalizedKey = $"t:{CurrentTenant.Id.Value},{normalizedKey}";
// normalizedKey = $"t:{_currentTenant.Id.Value},{normalizedKey}";
//}
return normalizedKey;

View File

@@ -1,5 +1,6 @@
using FreeRedis;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Caching;
@@ -7,26 +8,57 @@ using Volo.Abp.Caching;
namespace Yi.Framework.Caching.FreeRedis
{
/// <summary>
/// 此模块得益于FreeRedis作者支持IDistributedCache使用湿滑
/// FreeRedis缓存模块
/// 提供基于FreeRedis的分布式缓存实现
/// </summary>
[DependsOn(typeof(AbpCachingModule))]
public class YiFrameworkCachingFreeRedisModule : AbpModule
{
private const string RedisEnabledKey = "Redis:IsEnabled";
private const string RedisConfigurationKey = "Redis:Configuration";
/// <summary>
/// 配置服务
/// </summary>
/// <param name="context">服务配置上下文</param>
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var redisEnabled = configuration["Redis:IsEnabled"];
if (redisEnabled.IsNullOrEmpty() || bool.Parse(redisEnabled))
// 检查Redis是否启用
if (!IsRedisEnabled(configuration))
{
var redisConfiguration = configuration["Redis:Configuration"];
RedisClient redisClient = new RedisClient(redisConfiguration);
context.Services.AddSingleton<IRedisClient>(redisClient);
context.Services.Replace(ServiceDescriptor.Singleton<IDistributedCache>(new
DistributedCache(redisClient)));
return;
}
// 注册Redis服务
RegisterRedisServices(context, configuration);
}
/// <summary>
/// 检查Redis是否启用
/// </summary>
/// <param name="configuration">配置</param>
/// <returns>是否启用Redis</returns>
private static bool IsRedisEnabled(IConfiguration configuration)
{
var redisEnabled = configuration[RedisEnabledKey];
return redisEnabled.IsNullOrEmpty() || bool.Parse(redisEnabled);
}
/// <summary>
/// 注册Redis相关服务
/// </summary>
/// <param name="context">服务配置上下文</param>
/// <param name="configuration">配置</param>
private static void RegisterRedisServices(ServiceConfigurationContext context, IConfiguration configuration)
{
var redisConfiguration = configuration[RedisConfigurationKey];
var redisClient = new RedisClient(redisConfiguration);
context.Services.AddSingleton<IRedisClient>(redisClient);
context.Services.Replace(ServiceDescriptor.Singleton<IDistributedCache>(
new DistributedCache(redisClient)));
}
}
}

View File

@@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace Yi.Framework.Core.Authentication;
public static class AuthenticationExtensions
{
public static void RefreshAuthentication(this HttpContext context)
{
var currentAuthenticationHandler =
context.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>();
if (currentAuthenticationHandler is IRefreshAuthenticationHandlerProvider refreshAuthenticationHandler)
{
refreshAuthenticationHandler.RefreshAuthentication();
}
}
}

View File

@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Authentication;
namespace Yi.Framework.Core.Authentication;
public interface IRefreshAuthenticationHandlerProvider: IAuthenticationHandlerProvider
{
/// <summary>
/// 刷新鉴权
/// </summary>
void RefreshAuthentication();
}

View File

@@ -6,8 +6,21 @@ using System.Threading.Tasks;
namespace Yi.Framework.Core.Data
{
/// <summary>
/// 排序接口
/// </summary>
/// <remarks>
/// 实现此接口的实体类将支持排序功能
/// 通常用于列表数据的展示顺序控制
/// </remarks>
public interface IOrderNum
{
/// <summary>
/// 排序号
/// </summary>
/// <remarks>
/// 数字越小越靠前,默认为0
/// </remarks>
int OrderNum { get; set; }
}
}

View File

@@ -6,8 +6,21 @@ using System.Threading.Tasks;
namespace Yi.Framework.Core.Data
{
/// <summary>
/// 状态接口
/// </summary>
/// <remarks>
/// 实现此接口的实体类将支持启用/禁用状态管理
/// 用于控制数据记录的可用状态
/// </remarks>
public interface IState
{
public bool State { get; set; }
/// <summary>
/// 状态标识
/// </summary>
/// <remarks>
/// true表示启用,false表示禁用
/// </remarks>
bool State { get; set; }
}
}

View File

@@ -7,14 +7,37 @@ using System.Threading.Tasks;
namespace Yi.Framework.Core.Enums
{
/// <summary>
/// 定义公共文件路径
/// 文件类型枚举
/// </summary>
/// <remarks>
/// 用于定义系统支持的文件类型分类
/// 主要用于文件上传和存储时的类型区分
/// </remarks>
public enum FileTypeEnum
{
file,
image,
thumbnail,
excel,
temp
/// <summary>
/// 普通文件
/// </summary>
file = 0,
/// <summary>
/// 图片文件
/// </summary>
image = 1,
/// <summary>
/// 缩略图文件
/// </summary>
thumbnail = 2,
/// <summary>
/// Excel文件
/// </summary>
excel = 3,
/// <summary>
/// 临时文件
/// </summary>
temp = 4
}
}

View File

@@ -6,9 +6,23 @@ using System.Threading.Tasks;
namespace Yi.Framework.Core.Enums
{
/// <summary>
/// 排序方向枚举
/// </summary>
/// <remarks>
/// 用于定义数据查询时的排序方向
/// 常用于列表数据排序
/// </remarks>
public enum OrderByEnum
{
Asc,
Desc
/// <summary>
/// 升序排列
/// </summary>
Asc = 0,
/// <summary>
/// 降序排列
/// </summary>
Desc = 1
}
}

View File

@@ -6,67 +6,91 @@ using System.Threading.Tasks;
namespace Yi.Framework.Core.Enums
{
/// <summary>
/// 查询操作符枚举
/// </summary>
/// <remarks>
/// 定义查询条件中支持的操作符类型
/// 用于构建动态查询条件
/// </remarks>
public enum QueryOperatorEnum
{
/// <summary>
///
/// 等
/// </summary>
Equal,
Equal = 0,
/// <summary>
/// 匹配
/// 模糊匹配
/// </summary>
Like,
Like = 1,
/// <summary>
/// 大于
/// </summary>
GreaterThan,
GreaterThan = 2,
/// <summary>
/// 大于或等于
/// </summary>
GreaterThanOrEqual,
GreaterThanOrEqual = 3,
/// <summary>
/// 小于
/// </summary>
LessThan,
LessThan = 4,
/// <summary>
/// 小于或等于
/// </summary>
LessThanOrEqual,
LessThanOrEqual = 5,
/// <summary>
/// 等于集合
/// 在指定集合
/// </summary>
In,
In = 6,
/// <summary>
/// 不等于集合
/// 不在指定集合
/// </summary>
NotIn,
NotIn = 7,
/// <summary>
/// 左匹配
/// 左侧模糊匹配
/// </summary>
LikeLeft,
LikeLeft = 8,
/// <summary>
/// 右匹配
/// 右侧模糊匹配
/// </summary>
LikeRight,
LikeRight = 9,
/// <summary>
/// 不
/// 不等
/// </summary>
NoEqual,
NoEqual = 10,
/// <summary>
/// 为或空
/// 为null或空
/// </summary>
IsNullOrEmpty,
IsNullOrEmpty = 11,
/// <summary>
/// 不为
/// 不为null
/// </summary>
IsNot,
IsNot = 12,
/// <summary>
/// 不匹配
/// </summary>
NoLike,
NoLike = 13,
/// <summary>
/// 时间段 值用 "|" 隔开
/// 日期范围
/// </summary>
DateRange
/// <remarks>
/// 使用"|"分隔起始和结束日期
/// </remarks>
DateRange = 14
}
}

View File

@@ -6,26 +6,33 @@ using System.Threading.Tasks;
namespace Yi.Framework.Core.Enums
{
/// <summary>
/// API返回状态码枚举
/// </summary>
/// <remarks>
/// 定义API接口统一的返回状态码
/// 遵循HTTP状态码规范
/// </remarks>
public enum ResultCodeEnum
{
/// <summary>
/// 操作成功
/// 操作成功
/// </summary>
Success = 200,
/// <summary>
/// 操作不成功
/// </summary>
NotSuccess = 500,
/// <summary>
/// 无权限
/// 未授权访问
/// </summary>
NoPermission = 401,
/// <summary>
/// 被拒绝
/// 访问被拒绝
/// </summary>
Denied = 403
Denied = 403,
/// <summary>
/// 操作失败
/// </summary>
NotSuccess = 500
}
}

View File

@@ -4,110 +4,131 @@ using Microsoft.AspNetCore.Http;
namespace Yi.Framework.Core.Extensions
{
/// <summary>
/// HttpContext扩展方法类
/// </summary>
public static class HttpContextExtensions
{
/// <summary>
/// 设置文件下载名称
/// 设置内联文件下载响应头
/// </summary>
/// <param name="httpContext"></param>
/// <param name="fileName"></param>
/// <param name="httpContext">HTTP上下文</param>
/// <param name="fileName">文件名</param>
public static void FileInlineHandle(this HttpContext httpContext, string fileName)
{
string encodeFilename = System.Web.HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("UTF-8"));
httpContext.Response.Headers.Add("Content-Disposition", "inline;filename=" + encodeFilename);
var encodeFilename = System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8);
httpContext.Response.Headers.Add("Content-Disposition", $"inline;filename={encodeFilename}");
}
/// <summary>
/// 设置文件附件名称
/// 设置附件下载响应头
/// </summary>
/// <param name="httpContext"></param>
/// <param name="fileName"></param>
/// <param name="httpContext">HTTP上下文</param>
/// <param name="fileName">文件名</param>
public static void FileAttachmentHandle(this HttpContext httpContext, string fileName)
{
string encodeFilename = System.Web.HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("UTF-8"));
httpContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + encodeFilename);
var encodeFilename = System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8);
httpContext.Response.Headers.Add("Content-Disposition", $"attachment;filename={encodeFilename}");
}
/// <summary>
/// 获取语言种类
/// 获取客户端首选语言
/// </summary>
/// <param name="httpContext"></param>
/// <returns></returns>
/// <param name="httpContext">HTTP上下文</param>
/// <returns>语言代码,默认返回zh-CN</returns>
public static string GetLanguage(this HttpContext httpContext)
{
string res = "zh-CN";
var str = httpContext.Request.Headers["Accept-Language"].FirstOrDefault();
if (str is not null)
{
res = str.Split(",")[0];
}
return res;
const string defaultLanguage = "zh-CN";
var acceptLanguage = httpContext.Request.Headers["Accept-Language"].FirstOrDefault();
return string.IsNullOrEmpty(acceptLanguage)
? defaultLanguage
: acceptLanguage.Split(',')[0];
}
/// <summary>
/// 判断是否为异步请求
/// 判断是否为Ajax请求
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <param name="request">HTTP请求</param>
/// <returns>是否为Ajax请求</returns>
public static bool IsAjaxRequest(this HttpRequest request)
{
string header = request.Headers["X-Requested-With"];
return "XMLHttpRequest".Equals(header);
const string ajaxHeader = "XMLHttpRequest";
return ajaxHeader.Equals(request.Headers["X-Requested-With"],
StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// 获取客户端IP
/// 获取客户端IP地址
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
/// <param name="context">HTTP上下文</param>
/// <returns>客户端IP地址</returns>
public static string GetClientIp(this HttpContext context)
{
if (context == null) return "";
var result = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
if (string.IsNullOrEmpty(result))
const string localhost = "127.0.0.1";
if (context == null) return string.Empty;
// 尝试获取X-Forwarded-For头
var ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
// 如果没有代理头,则获取远程IP
if (string.IsNullOrEmpty(ip))
{
result = context.Connection.RemoteIpAddress?.ToString();
ip = context.Connection.RemoteIpAddress?.ToString();
}
if (string.IsNullOrEmpty(result) || result.Contains("::1"))
result = "127.0.0.1";
result = result.Replace("::ffff:", "127.0.0.1");
//如果有端口号,删除端口号
result = Regex.Replace(result, @":\d{1,5}$", "");
//Ip规则校验
var regResult =
Regex.IsMatch(result, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$")
|| Regex.IsMatch(result, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?):\d{1,5}$");
// 处理特殊IP
if (string.IsNullOrEmpty(ip) || ip.Contains("::1"))
{
return localhost;
}
result = regResult ? result : "127.0.0.1";
return result;
// 清理IPv6格式
ip = ip.Replace("::ffff:", localhost);
// 移除端口号
ip = Regex.Replace(ip, @":\d{1,5}$", "");
// 验证IP格式
var isValidIp = Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$") ||
Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?):\d{1,5}$");
return isValidIp ? ip : localhost;
}
/// <summary>
/// 获取浏览器标识
/// 获取User-Agent信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
/// <param name="context">HTTP上下文</param>
/// <returns>User-Agent字符串</returns>
public static string GetUserAgent(this HttpContext context)
{
return context.Request.Headers["User-Agent"];
return context.Request.Headers["User-Agent"].ToString();
}
/// <summary>
/// 获取用户权限声明值
/// </summary>
/// <param name="context">HTTP上下文</param>
/// <param name="permissionsName">权限声明名称</param>
/// <returns>权限值数组</returns>
public static string[]? GetUserPermissions(this HttpContext context, string permissionsName)
{
return context.User.Claims.Where(x => x.Type == permissionsName).Select(x => x.Value).ToArray();
return context.User.Claims
.Where(x => x.Type == permissionsName)
.Select(x => x.Value)
.ToArray();
}
/// <summary>
/// 判断是否WebSocket 请求
/// 判断是否WebSocket请求
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
/// <param name="context">HTTP上下文</param>
/// <returns>是否为WebSocket请求</returns>
public static bool IsWebSocketRequest(this HttpContext context)
{
return context.WebSockets.IsWebSocketRequest || context.Request.Path == "/ws";
return context.WebSockets.IsWebSocketRequest ||
context.Request.Path == "/ws";
}
}
}

View File

@@ -3,25 +3,48 @@ using System.Text.Json.Serialization;
namespace Yi.Framework.Core.Json;
/// <summary>
/// DateTime JSON序列化转换器
/// </summary>
public class DatetimeJsonConverter : JsonConverter<DateTime>
{
private string _format;
public DatetimeJsonConverter(string format="yyyy-MM-dd HH:mm:ss")
private readonly string _dateFormat;
/// <summary>
/// 初始化DateTime转换器
/// </summary>
/// <param name="format">日期格式化字符串,默认为yyyy-MM-dd HH:mm:ss</param>
public DatetimeJsonConverter(string format = "yyyy-MM-dd HH:mm:ss")
{
_format = format;
_dateFormat = format;
}
/// <summary>
/// 从JSON读取DateTime值
/// </summary>
/// <param name="reader">JSON读取器</param>
/// <param name="typeToConvert">目标类型</param>
/// <param name="options">JSON序列化选项</param>
/// <returns>DateTime值</returns>
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if(reader.TokenType==JsonTokenType.String)
if (reader.TokenType == JsonTokenType.String)
{
if (DateTime.TryParse(reader.GetString(), out DateTime dateTime)) return dateTime;
return DateTime.TryParse(reader.GetString(), out DateTime dateTime)
? dateTime
: reader.GetDateTime();
}
return reader.GetDateTime();
}
/// <summary>
/// 将DateTime写入JSON
/// </summary>
/// <param name="writer">JSON写入器</param>
/// <param name="value">DateTime值</param>
/// <param name="options">JSON序列化选项</param>
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString(_format));
writer.WriteStringValue(value.ToString(_dateFormat));
}
}

View File

@@ -8,52 +8,81 @@ using Volo.Abp.Modularity;
namespace Yi.Framework.Core.Modularity;
[Dependency(ReplaceServices =true)]
/// <summary>
/// Yi框架模块管理器
/// </summary>
[Dependency(ReplaceServices = true)]
public class YiModuleManager : ModuleManager, IModuleManager, ISingletonDependency
{
private readonly IModuleContainer _moduleContainer;
private readonly IEnumerable<IModuleLifecycleContributor> _lifecycleContributors;
private readonly ILogger<YiModuleManager> _logger;
public YiModuleManager(IModuleContainer moduleContainer, ILogger<YiModuleManager> logger, IOptions<AbpModuleLifecycleOptions> options, IServiceProvider serviceProvider) : base(moduleContainer, logger, options, serviceProvider)
/// <summary>
/// 初始化模块管理器
/// </summary>
public YiModuleManager(
IModuleContainer moduleContainer,
ILogger<YiModuleManager> logger,
IOptions<AbpModuleLifecycleOptions> options,
IServiceProvider serviceProvider)
: base(moduleContainer, logger, options, serviceProvider)
{
_moduleContainer = moduleContainer;
_logger = logger;
_lifecycleContributors = options.Value.Contributors.Select(serviceProvider.GetRequiredService).Cast<IModuleLifecycleContributor>().ToArray();
_lifecycleContributors = options.Value.Contributors
.Select(serviceProvider.GetRequiredService)
.Cast<IModuleLifecycleContributor>()
.ToArray();
}
/// <summary>
/// 初始化所有模块
/// </summary>
/// <param name="context">应用程序初始化上下文</param>
public override async Task InitializeModulesAsync(ApplicationInitializationContext context)
{
_logger.LogDebug("==========模块Initialize初始化统计-跳过0ms模块==========");
var total = 0;
var watch =new Stopwatch();
long totalTime = 0;
var moduleCount = 0;
var stopwatch = new Stopwatch();
var totalTime = 0L;
foreach (var contributor in _lifecycleContributors)
{
foreach (var module in _moduleContainer.Modules)
{
try
{
watch.Restart();
stopwatch.Restart();
await contributor.InitializeAsync(context, module.Instance);
watch.Stop();
totalTime += watch.ElapsedMilliseconds;
total++;
if (watch.ElapsedMilliseconds > 1)
stopwatch.Stop();
totalTime += stopwatch.ElapsedMilliseconds;
moduleCount++;
// 仅记录耗时超过1ms的模块
if (stopwatch.ElapsedMilliseconds > 1)
{
_logger.LogDebug($"耗时-{watch.ElapsedMilliseconds}ms,已加载模块-{module.Assembly.GetName().Name}");
_logger.LogDebug(
"耗时-{Time}ms,已加载模块-{ModuleName}",
stopwatch.ElapsedMilliseconds,
module.Assembly.GetName().Name);
}
}
catch (Exception ex)
{
throw new AbpInitializationException($"An error occurred during the initialize {contributor.GetType().FullName} phase of the module {module.Type.AssemblyQualifiedName}: {ex.Message}. See the inner exception for details.", ex);
throw new AbpInitializationException(
$"模块 {module.Type.AssemblyQualifiedName} 在 {contributor.GetType().FullName} 阶段初始化失败: {ex.Message}",
ex);
}
}
}
_logger.LogInformation($"==========【{total}】个模块初始化执行完毕,总耗时【{totalTime}ms】==========");
_logger.LogInformation(
"==========【{Count}】个模块初始化执行完毕,总耗时【{Time}ms】==========",
moduleCount,
totalTime);
}
}

View File

@@ -0,0 +1,8 @@
namespace Yi.Framework.Core.Options;
public class SemanticKernelOptions
{
public List<string> ModelIds { get; set; }
public string Endpoint { get; set; }
public string ApiKey { get; set; }
}

View File

@@ -2,8 +2,28 @@
namespace Yi.Framework.Core
{
public class YiFrameworkCoreModule:AbpModule
/// <summary>
/// Yi框架核心模块
/// </summary>
/// <remarks>
/// 提供框架的基础功能和核心服务
/// </remarks>
public class YiFrameworkCoreModule : AbpModule
{
/// <summary>
/// 配置服务
/// </summary>
public override void ConfigureServices(ServiceConfigurationContext context)
{
base.ConfigureServices(context);
}
/// <summary>
/// 应用程序初始化
/// </summary>
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
base.OnApplicationInitialization(context);
}
}
}

View File

@@ -3,8 +3,17 @@ using Volo.Abp.Application.Services;
namespace Yi.Framework.Ddd.Application.Contracts
{
public interface IDeletesAppService<in TKey> : IDeleteAppService< TKey> , IApplicationService, IRemoteService
/// <summary>
/// 批量删除服务接口
/// </summary>
/// <typeparam name="TKey">主键类型</typeparam>
public interface IDeletesAppService<in TKey> : IDeleteAppService<TKey>, IApplicationService, IRemoteService
{
/// <summary>
/// 批量删除实体
/// </summary>
/// <param name="ids">要删除的实体ID集合</param>
/// <returns>删除操作的异步任务</returns>
Task DeleteAsync(IEnumerable<TKey> ids);
}
}

View File

@@ -2,9 +2,19 @@
namespace Yi.Framework.Ddd.Application.Contracts
{
/// <summary>
/// 带时间范围的分页查询请求接口
/// </summary>
public interface IPageTimeResultRequestDto : IPagedAndSortedResultRequest
{
/// <summary>
/// 查询开始时间
/// </summary>
DateTime? StartTime { get; set; }
/// <summary>
/// 查询结束时间
/// </summary>
DateTime? EndTime { get; set; }
}
}

View File

@@ -2,6 +2,9 @@
namespace Yi.Framework.Ddd.Application.Contracts
{
/// <summary>
/// 分页查询请求接口,包含时间范围和排序功能
/// </summary>
public interface IPagedAllResultRequestDto : IPageTimeResultRequestDto, IPagedAndSortedResultRequest
{
}

View File

@@ -7,24 +7,47 @@ using Volo.Abp.Application.Services;
namespace Yi.Framework.Ddd.Application.Contracts
{
/// <summary>
/// Yi框架CRUD服务基础接口
/// </summary>
/// <typeparam name="TEntityDto">实体DTO类型</typeparam>
/// <typeparam name="TKey">主键类型</typeparam>
public interface IYiCrudAppService<TEntityDto, in TKey> : ICrudAppService<TEntityDto, TKey>
{
}
/// <summary>
/// Yi框架CRUD服务接口带查询输入
/// </summary>
/// <typeparam name="TEntityDto">实体DTO类型</typeparam>
/// <typeparam name="TKey">主键类型</typeparam>
/// <typeparam name="TGetListInput">查询输入类型</typeparam>
public interface IYiCrudAppService<TEntityDto, in TKey, in TGetListInput> : ICrudAppService<TEntityDto, TKey, TGetListInput>
{
}
/// <summary>
/// Yi框架CRUD服务接口带查询输入和创建输入
/// </summary>
/// <typeparam name="TEntityDto">实体DTO类型</typeparam>
/// <typeparam name="TKey">主键类型</typeparam>
/// <typeparam name="TGetListInput">查询输入类型</typeparam>
/// <typeparam name="TCreateInput">创建输入类型</typeparam>
public interface IYiCrudAppService<TEntityDto, in TKey, in TGetListInput, in TCreateInput> : ICrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput>
{
}
/// <summary>
/// Yi框架CRUD服务接口带查询、创建和更新输入
/// </summary>
public interface IYiCrudAppService<TEntityDto, in TKey, in TGetListInput, in TCreateInput, in TUpdateInput> : ICrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
{
}
/// <summary>
/// Yi框架完整CRUD服务接口包含所有操作和批量删除功能
/// </summary>
public interface IYiCrudAppService<TGetOutputDto, TGetListOutputDto, in TKey, in TGetListInput, in TCreateInput, in TUpdateInput> : ICrudAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>, IDeletesAppService<TKey>
{
}
}

View File

@@ -2,48 +2,50 @@
namespace Yi.Framework.Ddd.Application.Contracts
{
/// <summary>
/// 分页查询请求DTO包含时间范围和自定义排序功能
/// </summary>
public class PagedAllResultRequestDto : PagedAndSortedResultRequestDto, IPagedAllResultRequestDto
{
/// <summary>
/// 查询开始时间条件
/// 查询开始时间
/// </summary>
public DateTime? StartTime { get; set; }
/// <summary>
/// 查询结束时间条件
/// 查询结束时间
/// </summary>
public DateTime? EndTime { get; set; }
/// <summary>
/// 排序列名,字段名对应前端
/// 排序列名
/// </summary>
public string? OrderByColumn { get; set; }
/// <summary>
/// 是否顺序,字段名对应前端
/// 排序方向ascending/descending
/// </summary>
public string? IsAsc { get; set; }
/// <summary>
/// 是否
/// 是否为升序排
/// </summary>
public bool CanAsc => IsAsc?.ToLower() == "ascending" ? true : false;
public bool IsAscending => string.Equals(IsAsc, "ascending", StringComparison.OrdinalIgnoreCase);
private string _sorting;
private string? _sorting;
//排序引用
public new string? Sorting
/// <summary>
/// 排序表达式
/// </summary>
public override string? Sorting
{
get
{
if (!OrderByColumn.IsNullOrWhiteSpace())
if (!string.IsNullOrWhiteSpace(OrderByColumn))
{
return $"{OrderByColumn} {(CanAsc ? "ASC" : "DESC")}";
}
else
{
return _sorting;
return $"{OrderByColumn} {(IsAscending ? "ASC" : "DESC")}";
}
return _sorting;
}
set => _sorting = value;
}

View File

@@ -3,6 +3,9 @@ using Volo.Abp.Modularity;
namespace Yi.Framework.Ddd.Application.Contracts
{
/// <summary>
/// Yi框架DDD应用层契约模块
/// </summary>
[DependsOn(typeof(AbpDddApplicationContractsModule))]
public class YiFrameworkDddApplicationContractsModule : AbpModule
{

View File

@@ -6,11 +6,19 @@ using Volo.Abp.MultiTenancy;
namespace Yi.Framework.Ddd.Application
{
public abstract class YiCacheCrudAppService<TEntity, TEntityDto, TKey> : YiCrudAppService<TEntity, TEntityDto, TKey, PagedAndSortedResultRequestDto>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
/// <summary>
/// 带缓存的CRUD应用服务基类
/// </summary>
/// <typeparam name="TEntity">实体类型</typeparam>
/// <typeparam name="TEntityDto">实体DTO类型</typeparam>
/// <typeparam name="TKey">主键类型</typeparam>
public abstract class YiCacheCrudAppService<TEntity, TEntityDto, TKey>
: YiCrudAppService<TEntity, TEntityDto, TKey, PagedAndSortedResultRequestDto>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
protected YiCacheCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
protected YiCacheCrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
}
@@ -47,73 +55,92 @@ namespace Yi.Framework.Ddd.Application
}
/// <summary>
/// 完整的带缓存CRUD应用服务实现
/// </summary>
public abstract class YiCacheCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
: YiCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>
where TGetOutputDto : IEntityDto<TKey>
where TGetListOutputDto : IEntityDto<TKey>
where TEntity : class, IEntity<TKey>
where TGetOutputDto : IEntityDto<TKey>
where TGetListOutputDto : IEntityDto<TKey>
{
protected IDistributedCache<TEntity> Cache => LazyServiceProvider.LazyGetRequiredService<IDistributedCache<TEntity>>();
/// <summary>
/// 分布式缓存访问器
/// </summary>
private IDistributedCache<TEntity> EntityCache =>
LazyServiceProvider.LazyGetRequiredService<IDistributedCache<TEntity>>();
protected string GetCacheKey(TKey id) => typeof(TEntity).Name + ":" + CurrentTenant.Id ?? Guid.Empty + ":" + id.ToString();
protected YiCacheCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
/// <summary>
/// 获取缓存键
/// </summary>
protected virtual string GenerateCacheKey(TKey id) =>
$"{typeof(TEntity).Name}:{CurrentTenant.Id ?? Guid.Empty}:{id}";
protected YiCacheCrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
public override async Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInput input)
/// <summary>
/// 更新实体并清除缓存
/// </summary>
public override async Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInput input)
{
var output = await base.UpdateAsync(id, input);
await Cache.RemoveAsync(GetCacheKey(id));
return output;
var result = await base.UpdateAsync(id, input);
await EntityCache.RemoveAsync(GenerateCacheKey(id));
return result;
}
public override async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
/// <summary>
/// 获取实体列表(需要继承实现具体的缓存策略)
/// </summary>
public override Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
{
//两种方式:
//1全表缓存使用缓存直接查询
//2非全部缓存查询到的数据直接添加到缓存
//判断是否该实体为全表缓存
throw new NotImplementedException();
//IDistributedCache 有局限性,条件查询无法进行缓存了
//if (true)
//{
// return await GetListByCacheAsync(input);
//}
//else
//{
// return await GetListByDbAsync(input);
//}
// 建议实现两种缓存策略:
// 1. 全表缓存: 适用于数据量小且变动不频繁的场景
// 2. 按需缓存: 仅缓存常用数据,适用于大数据量场景
throw new NotImplementedException("请实现具体的缓存查询策略");
}
protected virtual async Task<PagedResultDto<TGetListOutputDto>> GetListByDbAsync(TGetListInput input)
/// <summary>
/// 从数据库获取实体列表
/// </summary>
protected virtual Task<PagedResultDto<TGetListOutputDto>> GetListFromDatabaseAsync(
TGetListInput input)
{
//如果不是全表缓存,可以走这个啦
throw new NotImplementedException();
}
protected virtual async Task<PagedResultDto<TGetListOutputDto>> GetListByCacheAsync(TGetListInput input)
{
//如果是全表缓存,可以走这个啦
throw new NotImplementedException();
}
/// <summary>
/// 从缓存获取实体列表
/// </summary>
protected virtual Task<PagedResultDto<TGetListOutputDto>> GetListFromCacheAsync(
TGetListInput input)
{
throw new NotImplementedException();
}
/// <summary>
/// 获取单个实体(优先从缓存获取)
/// </summary>
protected override async Task<TEntity> GetEntityByIdAsync(TKey id)
{
var output = await Cache.GetOrAddAsync(GetCacheKey(id), async () => await base.GetEntityByIdAsync(id));
return output!;
return (await EntityCache.GetOrAddAsync(
GenerateCacheKey(id),
async () => await base.GetEntityByIdAsync(id)))!;
}
public override async Task DeleteAsync(IEnumerable<TKey> id)
/// <summary>
/// 批量删除实体并清除缓存
/// </summary>
public override async Task DeleteAsync(IEnumerable<TKey> ids)
{
await base.DeleteAsync(id);
foreach (var itemId in id)
{
await Cache.RemoveAsync(GetCacheKey(itemId));
}
await base.DeleteAsync(ids);
// 批量清除缓存
var tasks = ids.Select(id =>
EntityCache.RemoveAsync(GenerateCacheKey(id)));
await Task.WhenAll(tasks);
}
}
}

View File

@@ -8,126 +8,198 @@ using Volo.Abp.Domain.Repositories;
namespace Yi.Framework.Ddd.Application
{
public abstract class
YiCrudAppService<TEntity, TEntityDto, TKey> : YiCrudAppService<TEntity, TEntityDto, TKey,
PagedAndSortedResultRequestDto>
/// <summary>
/// CRUD应用服务基类 - 基础版本
/// </summary>
public abstract class YiCrudAppService<TEntity, TEntityDto, TKey>
: YiCrudAppService<TEntity, TEntityDto, TKey, PagedAndSortedResultRequestDto>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
protected YiCrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
}
/// <summary>
/// CRUD应用服务基类 - 支持自定义查询输入
/// </summary>
public abstract class YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput>
: YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TEntityDto>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
protected YiCrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
}
/// <summary>
/// CRUD应用服务基类 - 支持自定义创建输入
/// </summary>
public abstract class YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput>
: YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TCreateInput>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
protected YiCrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
}
/// <summary>
/// CRUD应用服务基类 - 支持自定义更新输入
/// </summary>
public abstract class YiCrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
: YiCrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
protected YiCrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
}
public abstract class YiCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput,
TUpdateInput>
/// <summary>
/// CRUD应用服务基类 - 完整实现
/// </summary>
public abstract class YiCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
: CrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>
where TGetOutputDto : IEntityDto<TKey>
where TGetListOutputDto : IEntityDto<TKey>
{
protected YiCrudAppService(IRepository<TEntity, TKey> repository) : base(repository)
/// <summary>
/// 临时文件存储路径
/// </summary>
private const string TempFilePath = "/wwwroot/temp";
protected YiCrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
/// <summary>
/// 更新实体
/// </summary>
/// <param name="id">实体ID</param>
/// <param name="input">更新输入</param>
/// <returns>更新后的实体DTO</returns>
public override async Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInput input)
{
// 检查更新权限
await CheckUpdatePolicyAsync();
// 获取并验证实体
var entity = await GetEntityByIdAsync(id);
await CheckUpdateInputDtoAsync(entity,input);
// 检查更新输入
await CheckUpdateInputDtoAsync(entity, input);
// 映射并更新实体
await MapToEntityAsync(input, entity);
await Repository.UpdateAsync(entity, autoSave: true);
return await MapToGetOutputDtoAsync(entity);
}
protected virtual Task CheckUpdateInputDtoAsync(TEntity entity,TUpdateInput input)
/// <summary>
/// 检查更新输入数据的有效性
/// </summary>
protected virtual Task CheckUpdateInputDtoAsync(TEntity entity, TUpdateInput input)
{
return Task.CompletedTask;
}
/// <summary>
/// 创建实体
/// </summary>
/// <param name="input">创建输入</param>
/// <returns>创建后的实体DTO</returns>
public override async Task<TGetOutputDto> CreateAsync(TCreateInput input)
{
// 检查创建权限
await CheckCreatePolicyAsync();
// 检查创建输入
await CheckCreateInputDtoAsync(input);
// 映射到实体
var entity = await MapToEntityAsync(input);
// 设置租户ID
TryToSetTenantId(entity);
// 插入实体
await Repository.InsertAsync(entity, autoSave: true);
return await MapToGetOutputDtoAsync(entity);
}
/// <summary>
/// 检查创建输入数据的有效性
/// </summary>
protected virtual Task CheckCreateInputDtoAsync(TCreateInput input)
{
return Task.CompletedTask;
}
/// <summary>
/// 多查
/// 获取实体列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <param name="input">查询输入</param>
/// <returns>分页结果</returns>
public override async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
{
List<TEntity>? entites = null;
//区分多查还是批量查
List<TEntity> entities;
// 根据输入类型决定查询方式
if (input is IPagedResultRequest pagedInput)
{
entites = await Repository.GetPagedListAsync(pagedInput.SkipCount, pagedInput.MaxResultCount,
string.Empty);
// 分页查询
entities = await Repository.GetPagedListAsync(
pagedInput.SkipCount,
pagedInput.MaxResultCount,
string.Empty
);
}
else
{
entites = await Repository.GetListAsync();
// 查询全部
entities = await Repository.GetListAsync();
}
var total = await Repository.GetCountAsync();
var output = await MapToGetListOutputDtosAsync(entites);
return new PagedResultDto<TGetListOutputDto>(total, output);
//throw new NotImplementedException($"【{typeof(TEntity)}】实体的CrudAppService查询为具体业务通用查询几乎无实际场景请重写实现");
// 获取总数并映射结果
var totalCount = await Repository.GetCountAsync();
var dtos = await MapToGetListOutputDtosAsync(entities);
return new PagedResultDto<TGetListOutputDto>(totalCount, dtos);
}
/// <summary>
/// 多删
/// 获取实体动态下拉框列表,子类重写该方法,通过 keywords 进行筛选
/// </summary>
/// <param name="id"></param>
/// <param name="keywords">查询关键字</param>
/// <returns></returns>
public virtual async Task<PagedResultDto<TGetListOutputDto>> GetSelectDataListAsync(string? keywords = null)
{
List<TEntity> entities = await Repository.GetListAsync();
// 获取总数并映射结果
var totalCount = entities.Count;
var dtos = await MapToGetListOutputDtosAsync(entities);
return new PagedResultDto<TGetListOutputDto>(totalCount, dtos);
}
/// <summary>
/// 批量删除实体
/// </summary>
/// <param name="id">实体ID集合</param>
[RemoteService(isEnabled: true)]
public virtual async Task DeleteAsync(IEnumerable<TKey> id)
{
@@ -135,56 +207,61 @@ namespace Yi.Framework.Ddd.Application
}
/// <summary>
/// 偷梁换柱
/// 单个删除实体(禁用远程访问)
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[RemoteService(isEnabled: false)]
public override Task DeleteAsync(TKey id)
{
return base.DeleteAsync(id);
}
/// <summary>
/// 导出excel
/// 导出Excel
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <param name="input">查询条件</param>
/// <returns>Excel文件</returns>
public virtual async Task<IActionResult> GetExportExcelAsync(TGetListInput input)
{
// 重置分页参数以获取全部数据
if (input is IPagedResultRequest paged)
{
paged.SkipCount = 0;
paged.MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount;
}
var output = await this.GetListAsync(input);
var dirPath = $"/wwwroot/temp";
// 获取数据
var output = await GetListAsync(input);
var fileName = $"{typeof(TEntity).Name}_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}_{Guid.NewGuid()}";
var filePath = $"{dirPath}/{fileName}.xlsx";
if (!Directory.Exists(dirPath))
// 确保临时目录存在
if (!Directory.Exists(TempFilePath))
{
Directory.CreateDirectory(dirPath);
Directory.CreateDirectory(TempFilePath);
}
MiniExcel.SaveAs(filePath, output.Items);
// 生成文件名和路径
var fileName = GenerateExcelFileName();
var filePath = Path.Combine(TempFilePath, fileName);
// 保存Excel文件
await MiniExcel.SaveAsAsync(filePath, output.Items);
return new PhysicalFileResult(filePath, "application/vnd.ms-excel");
}
/// <summary>
/// 导入excle
/// 生成Excel文件名
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public virtual async Task PostImportExcelAsync(List<TCreateInput> input)
private string GenerateExcelFileName()
{
var entities = input.Select(x => MapToEntity(x)).ToList();
//安全起见,该接口需要自己实现
throw new NotImplementedException();
//await Repository.DeleteManyAsync(entities.Select(x => x.Id));
//await Repository.InsertManyAsync(entities);
return $"{typeof(TEntity).Name}_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{Guid.NewGuid()}.xlsx";
}
/// <summary>
/// 导入Excel(需要实现类重写此方法)
/// </summary>
public virtual Task PostImportExcelAsync(List<TCreateInput> input)
{
throw new NotImplementedException("请在实现类中重写此方法以支持Excel导入");
}
}
}

View File

@@ -6,14 +6,34 @@ using Yi.Framework.Ddd.Application.Contracts;
namespace Yi.Framework.Ddd.Application
{
[DependsOn(typeof(AbpDddApplicationModule),
typeof(YiFrameworkDddApplicationContractsModule))]
/// <summary>
/// Yi框架DDD应用层模块
/// </summary>
[DependsOn(
typeof(AbpDddApplicationModule),
typeof(YiFrameworkDddApplicationContractsModule)
)]
public class YiFrameworkDddApplicationModule : AbpModule
{
/// <summary>
/// 应用程序初始化配置
/// </summary>
/// <param name="context">应用程序初始化上下文</param>
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
//分页限制
// 配置分页查询的默认值和最大值限制
ConfigureDefaultPagingSettings();
}
/// <summary>
/// 配置默认分页设置
/// </summary>
private void ConfigureDefaultPagingSettings()
{
// 设置默认每页显示记录数
LimitedResultRequestDto.DefaultMaxResultCount = 10;
// 设置最大允许的每页记录数
LimitedResultRequestDto.MaxMaxResultCount = 10000;
}
}

View File

@@ -8,17 +8,37 @@ using Volo.Abp.ObjectMapping;
namespace Yi.Framework.Mapster
{
/// <summary>
/// Mapster自动对象映射提供程序
/// 实现IAutoObjectMappingProvider接口提供对象间的自动映射功能
/// </summary>
public class MapsterAutoObjectMappingProvider : IAutoObjectMappingProvider
{
/// <summary>
/// 将源对象映射到目标类型
/// </summary>
/// <typeparam name="TSource">源类型</typeparam>
/// <typeparam name="TDestination">目标类型</typeparam>
/// <param name="source">源对象</param>
/// <returns>映射后的目标类型实例</returns>
public TDestination Map<TSource, TDestination>(object source)
{
var sss = typeof(TDestination).Name;
// 使用Mapster的Adapt方法进行对象映射
return source.Adapt<TDestination>();
}
/// <summary>
/// 将源对象映射到现有的目标对象
/// </summary>
/// <typeparam name="TSource">源类型</typeparam>
/// <typeparam name="TDestination">目标类型</typeparam>
/// <param name="source">源对象</param>
/// <param name="destination">目标对象</param>
/// <returns>映射后的目标对象</returns>
public TDestination Map<TSource, TDestination>(TSource source, TDestination destination)
{
return source.Adapt<TSource, TDestination>(destination);
// 使用Mapster的Adapt方法进行对象映射保留目标对象的实例
return source.Adapt(destination);
}
}
}

View File

@@ -7,18 +7,51 @@ using Volo.Abp.ObjectMapping;
namespace Yi.Framework.Mapster
{
/// <summary>
/// Mapster对象映射器
/// 实现IObjectMapper接口提供对象映射功能
/// </summary>
public class MapsterObjectMapper : IObjectMapper
{
public IAutoObjectMappingProvider AutoObjectMappingProvider => throw new NotImplementedException();
private readonly IAutoObjectMappingProvider _autoObjectMappingProvider;
public TDestination Map<TSource, TDestination>(TSource source)
/// <summary>
/// 构造函数
/// </summary>
/// <param name="autoObjectMappingProvider">自动对象映射提供程序</param>
public MapsterObjectMapper(IAutoObjectMappingProvider autoObjectMappingProvider)
{
throw new NotImplementedException();
_autoObjectMappingProvider = autoObjectMappingProvider;
}
/// <summary>
/// 获取自动对象映射提供程序
/// </summary>
public IAutoObjectMappingProvider AutoObjectMappingProvider => _autoObjectMappingProvider;
/// <summary>
/// 将源对象映射到目标类型
/// </summary>
/// <typeparam name="TSource">源类型</typeparam>
/// <typeparam name="TDestination">目标类型</typeparam>
/// <param name="source">源对象</param>
/// <returns>映射后的目标类型实例</returns>
public TDestination Map<TSource, TDestination>(TSource source)
{
return AutoObjectMappingProvider.Map<TSource, TDestination>(source);
}
/// <summary>
/// 将源对象映射到现有的目标对象
/// </summary>
/// <typeparam name="TSource">源类型</typeparam>
/// <typeparam name="TDestination">目标类型</typeparam>
/// <param name="source">源对象</param>
/// <param name="destination">目标对象</param>
/// <returns>映射后的目标对象</returns>
public TDestination Map<TSource, TDestination>(TSource source, TDestination destination)
{
throw new NotImplementedException();
return AutoObjectMappingProvider.Map(source, destination);
}
}
}

View File

@@ -1,21 +1,33 @@
using MapsterMapper;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Modularity;
using Volo.Abp.ObjectMapping;
using Yi.Framework.Core;
using Mapster;
namespace Yi.Framework.Mapster
{
[DependsOn(typeof(YiFrameworkCoreModule),
/// <summary>
/// Yi框架Mapster模块
/// 用于配置和注册Mapster相关服务
/// </summary>
[DependsOn(
typeof(YiFrameworkCoreModule),
typeof(AbpObjectMappingModule)
)]
)]
public class YiFrameworkMapsterModule : AbpModule
{
/// <summary>
/// 配置服务
/// </summary>
/// <param name="context">服务配置上下文</param>
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddTransient<IAutoObjectMappingProvider, MapsterAutoObjectMappingProvider>();
var services = context.Services;
// 扫描并注册所有映射配置
TypeAdapterConfig.GlobalSettings.Scan(AppDomain.CurrentDomain.GetAssemblies());
// 注册Mapster相关服务
services.AddTransient<IAutoObjectMappingProvider, MapsterAutoObjectMappingProvider>();
services.AddTransient<IObjectMapper, MapsterObjectMapper>();
}
}
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Core\Yi.Framework.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SemanticKernel" Version="1.57.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,15 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Yi.Framework.Core.Options;
namespace Yi.Framework.SemanticKernel;
public class YiFrameworkSemanticKernelModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var services = context.Services;
}
}

View File

@@ -3,10 +3,14 @@ using ArgumentException = System.ArgumentException;
namespace Yi.Framework.SqlSugarCore.Abstractions
{
/// <summary>
/// 数据库连接配置选项
/// </summary>
public class DbConnOptions
{
/// <summary>
/// 连接字符串(如果开启多租户,也就是默认库了),必填
/// 主数据库连接字符串
/// 如果开启多租户,此为默认租户数据库
/// </summary>
public string? Url { get; set; }
@@ -16,43 +20,48 @@ namespace Yi.Framework.SqlSugarCore.Abstractions
public DbType? DbType { get; set; }
/// <summary>
/// 开启种子数据
/// 是否启用种子数据初始化
/// </summary>
public bool EnabledDbSeed { get; set; } = false;
/// <summary>
/// 开启驼峰转下划线
/// 是否启用驼峰命名转下划线命名
/// </summary>
public bool EnableUnderLine { get; set; } = false;
/// <summary>
/// 开启codefirst
/// 是否启用Code First模式
/// </summary>
public bool EnabledCodeFirst { get; set; } = false;
/// <summary>
/// 开启sql日志
/// 是否启用SQL日志记录
/// </summary>
public bool EnabledSqlLog { get; set; } = true;
/// <summary>
/// 实体程序集
/// 实体类所在程序集名称列表
/// </summary>
public List<string>? EntityAssembly { get; set; }
/// <summary>
/// 开启读写分离
/// 是否启用读写分离
/// </summary>
public bool EnabledReadWrite { get; set; } = false;
/// <summary>
/// 读写分离
/// 只读数据库连接字符串列表
/// </summary>
public List<string>? ReadUrl { get; set; }
/// <summary>
/// 开启Saas多租户
/// 是否启用SaaS多租户
/// </summary>
public bool EnabledSaasMultiTenancy { get; set; } = false;
/// <summary>
/// 是否开启更新并发乐观锁
/// </summary>
public bool EnabledConcurrencyException { get;set; } = false;
}
}

View File

@@ -4,10 +4,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.SqlSugarCore.Abstractions
namespace Yi.Framework.SqlSugarCore.Abstractions;
/// <summary>
/// 默认租户表特性
/// 标记此特性的实体类将在默认租户数据库中创建表
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class DefaultTenantTableAttribute : Attribute
{
[AttributeUsage(AttributeTargets.Class)]
public class DefaultTenantTableAttribute : Attribute
{
}
}

View File

@@ -8,15 +8,18 @@ using Volo.Abp.DependencyInjection;
namespace Yi.Framework.SqlSugarCore.Abstractions
{
/// <summary>
/// SqlSugar数据库上下文接口
/// </summary>
public interface ISqlSugarDbContext
{
/// <summary>
/// SqlSugarDb
/// 获取SqlSugar客户端实例
/// </summary>
ISqlSugarClient SqlSugarClient { get; }
/// <summary>
/// 数据库备份
/// 执行数据库备份
/// </summary>
void BackupDataBase();
}

View File

@@ -3,19 +3,55 @@ using SqlSugar;
namespace Yi.Framework.SqlSugarCore.Abstractions;
/// <summary>
/// SqlSugar数据库上下文依赖接口
/// 定义数据库操作的各个生命周期钩子
/// </summary>
public interface ISqlSugarDbContextDependencies
{
/// <summary>
/// 执行顺序
/// 获取执行顺序
/// </summary>
int ExecutionOrder { get; }
/// <summary>
/// SqlSugar客户端配置时触发
/// </summary>
/// <param name="sqlSugarClient">SqlSugar客户端实例</param>
void OnSqlSugarClientConfig(ISqlSugarClient sqlSugarClient);
/// <summary>
/// 数据执行后触发
/// </summary>
/// <param name="oldValue">原始值</param>
/// <param name="entityInfo">实体信息</param>
void DataExecuted(object oldValue, DataAfterModel entityInfo);
/// <summary>
/// 数据执行前触发
/// </summary>
/// <param name="oldValue">原始值</param>
/// <param name="entityInfo">实体信息</param>
void DataExecuting(object oldValue, DataFilterModel entityInfo);
void OnLogExecuting(string sql, SugarParameter[] pars);
void OnLogExecuted(string sql, SugarParameter[] pars);
/// <summary>
/// SQL执行前触发
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="parameters">SQL参数</param>
void OnLogExecuting(string sql, SugarParameter[] parameters);
/// <summary>
/// SQL执行后触发
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="parameters">SQL参数</param>
void OnLogExecuted(string sql, SugarParameter[] parameters);
/// <summary>
/// 实体服务配置
/// </summary>
/// <param name="propertyInfo">属性信息</param>
/// <param name="entityColumnInfo">实体列信息</param>
void EntityService(PropertyInfo propertyInfo, EntityColumnInfo entityColumnInfo);
}

View File

@@ -6,84 +6,242 @@ using Volo.Abp.Uow;
namespace Yi.Framework.SqlSugarCore.Abstractions
{
public interface ISqlSugarRepository<TEntity>:IRepository<TEntity>,IUnitOfWorkEnabled where TEntity : class, IEntity,new ()
/// <summary>
/// SqlSugar仓储接口
/// </summary>
/// <typeparam name="TEntity">实体类型</typeparam>
public interface ISqlSugarRepository<TEntity> : IRepository<TEntity>, IUnitOfWorkEnabled
where TEntity : class, IEntity, new()
{
#region 访
/// <summary>
/// 获取SqlSugar客户端实例
/// </summary>
ISqlSugarClient _Db { get; }
/// <summary>
/// 获取查询构造器
/// </summary>
ISugarQueryable<TEntity> _DbQueryable { get; }
/// <summary>
/// 异步获取数据库上下文
/// </summary>
Task<ISqlSugarClient> GetDbContextAsync();
/// <summary>
/// 获取删除操作构造器
/// </summary>
Task<IDeleteable<TEntity>> AsDeleteable();
Task<IInsertable<TEntity>> AsInsertable(List<TEntity> insertObjs);
Task<IInsertable<TEntity>> AsInsertable(TEntity insertObj);
Task<IInsertable<TEntity>> AsInsertable(TEntity[] insertObjs);
/// <summary>
/// 获取插入操作构造器
/// </summary>
Task<IInsertable<TEntity>> AsInsertable(TEntity entity);
/// <summary>
/// 获取批量插入操作构造器
/// </summary>
Task<IInsertable<TEntity>> AsInsertable(List<TEntity> entities);
/// <summary>
/// 获取查询构造器
/// </summary>
Task<ISugarQueryable<TEntity>> AsQueryable();
/// <summary>
/// 获取SqlSugar客户端
/// </summary>
Task<ISqlSugarClient> AsSugarClient();
/// <summary>
/// 获取租户操作接口
/// </summary>
Task<ITenant> AsTenant();
Task<IUpdateable<TEntity>> AsUpdateable(List<TEntity> updateObjs);
Task<IUpdateable<TEntity>> AsUpdateable(TEntity updateObj);
/// <summary>
/// 获取更新操作构造器
/// </summary>
Task<IUpdateable<TEntity>> AsUpdateable();
Task<IUpdateable<TEntity>> AsUpdateable(TEntity[] updateObjs);
#region
//单查
/// <summary>
/// 获取实体更新操作构造器
/// </summary>
Task<IUpdateable<TEntity>> AsUpdateable(TEntity entity);
/// <summary>
/// 获取批量更新操作构造器
/// </summary>
Task<IUpdateable<TEntity>> AsUpdateable(List<TEntity> entities);
#endregion
#region
/// <summary>
/// 根据主键获取实体
/// </summary>
Task<TEntity> GetByIdAsync(dynamic id);
Task<TEntity> GetSingleAsync(Expression<Func<TEntity, bool>> whereExpression);
Task<TEntity> GetFirstAsync(Expression<Func<TEntity, bool>> whereExpression);
Task<bool> IsAnyAsync(Expression<Func<TEntity, bool>> whereExpression);
Task<int> CountAsync(Expression<Func<TEntity, bool>> whereExpression);
#endregion
/// <summary>
/// 获取满足条件的单个实体
/// </summary>
Task<TEntity> GetSingleAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// 获取满足条件的第一个实体
/// </summary>
Task<TEntity> GetFirstAsync(Expression<Func<TEntity, bool>> predicate);
#region
//多查
/// <summary>
/// 判断是否存在满足条件的实体
/// </summary>
Task<bool> IsAnyAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// 获取满足条件的实体数量
/// </summary>
Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// 获取所有实体
/// </summary>
Task<List<TEntity>> GetListAsync();
Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> whereExpression);
/// <summary>
/// 获取满足条件的所有实体
/// </summary>
Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate);
#endregion
#region
/// <summary>
/// 获取分页数据
/// </summary>
Task<List<TEntity>> GetPageListAsync(
Expression<Func<TEntity, bool>> predicate,
int pageIndex,
int pageSize);
/// <summary>
/// 获取排序的分页数据
/// </summary>
Task<List<TEntity>> GetPageListAsync(
Expression<Func<TEntity, bool>> predicate,
int pageIndex,
int pageSize,
Expression<Func<TEntity, object>>? orderByExpression = null,
OrderByType orderByType = OrderByType.Asc);
#region
//分页查
Task<List<TEntity>> GetPageListAsync(Expression<Func<TEntity, bool>> whereExpression, int pageNum, int pageSize);
Task<List<TEntity>> GetPageListAsync(Expression<Func<TEntity, bool>> whereExpression, int pageNum, int pageSize, Expression<Func<TEntity, object>>? orderByExpression = null, OrderByType orderByType = OrderByType.Asc);
#endregion
#region
//插入
Task<bool> InsertAsync(TEntity insertObj);
Task<bool> InsertOrUpdateAsync(TEntity data);
Task<bool> InsertOrUpdateAsync(List<TEntity> datas);
Task<int> InsertReturnIdentityAsync(TEntity insertObj);
Task<long> InsertReturnBigIdentityAsync(TEntity insertObj);
Task<long> InsertReturnSnowflakeIdAsync(TEntity insertObj);
Task<TEntity> InsertReturnEntityAsync(TEntity insertObj);
Task<bool> InsertRangeAsync(List<TEntity> insertObjs);
#region
/// <summary>
/// 插入实体
/// </summary>
Task<bool> InsertAsync(TEntity entity);
/// <summary>
/// 插入或更新实体
/// </summary>
Task<bool> InsertOrUpdateAsync(TEntity entity);
/// <summary>
/// 批量插入或更新实体
/// </summary>
Task<bool> InsertOrUpdateAsync(List<TEntity> entities);
/// <summary>
/// 插入实体并返回自增主键
/// </summary>
Task<int> InsertReturnIdentityAsync(TEntity entity);
/// <summary>
/// 插入实体并返回长整型自增主键
/// </summary>
Task<long> InsertReturnBigIdentityAsync(TEntity entity);
/// <summary>
/// 插入实体并返回雪花ID
/// </summary>
Task<long> InsertReturnSnowflakeIdAsync(TEntity entity);
/// <summary>
/// 插入实体并返回实体
/// </summary>
Task<TEntity> InsertReturnEntityAsync(TEntity entity);
/// <summary>
/// 批量插入实体
/// </summary>
Task<bool> InsertRangeAsync(List<TEntity> entities);
#endregion
#region
/// <summary>
/// 更新实体
/// </summary>
Task<bool> UpdateAsync(TEntity entity);
/// <summary>
/// 批量更新实体
/// </summary>
Task<bool> UpdateRangeAsync(List<TEntity> entities);
/// <summary>
/// 条件更新指定列
/// </summary>
Task<bool> UpdateAsync(
Expression<Func<TEntity, TEntity>> columns,
Expression<Func<TEntity, bool>> predicate);
#region
//更新
Task<bool> UpdateAsync(TEntity updateObj);
Task<bool> UpdateRangeAsync(List<TEntity> updateObjs);
Task<bool> UpdateAsync(Expression<Func<TEntity, TEntity>> columns, Expression<Func<TEntity, bool>> whereExpression);
#endregion
#region
//删除
Task<bool> DeleteAsync(TEntity deleteObj);
Task<bool> DeleteAsync(List<TEntity> deleteObjs);
Task<bool> DeleteAsync(Expression<Func<TEntity, bool>> whereExpression);
#region
/// <summary>
/// 删除实体
/// </summary>
Task<bool> DeleteAsync(TEntity entity);
/// <summary>
/// 批量删除实体
/// </summary>
Task<bool> DeleteAsync(List<TEntity> entities);
/// <summary>
/// 条件删除
/// </summary>
Task<bool> DeleteAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// 根据主键删除
/// </summary>
Task<bool> DeleteByIdAsync(dynamic id);
Task<bool> DeleteByIdsAsync(dynamic[] ids);
#endregion
/// <summary>
/// 根据主键批量删除
/// </summary>
Task<bool> DeleteByIdsAsync(dynamic[] ids);
#endregion
}
public interface ISqlSugarRepository<TEntity, TKey> : ISqlSugarRepository<TEntity>,IRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>, new()
{
/// <summary>
/// SqlSugar仓储接口(带主键)
/// </summary>
/// <typeparam name="TEntity">实体类型</typeparam>
/// <typeparam name="TKey">主键类型</typeparam>
public interface ISqlSugarRepository<TEntity, TKey> :
ISqlSugarRepository<TEntity>,
IRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>, new()
{
}
}

View File

@@ -6,12 +6,17 @@ using System.Threading.Tasks;
namespace Yi.Framework.SqlSugarCore.Abstractions
{
/// <summary>
/// SqlSugar数据库上下文提供者接口
/// </summary>
/// <typeparam name="TDbContext">数据库上下文类型</typeparam>
public interface ISugarDbContextProvider<TDbContext>
where TDbContext : ISqlSugarDbContext
{
/// <summary>
/// 异步获取数据库上下文实例
/// </summary>
/// <returns>数据库上下文实例</returns>
Task<TDbContext> GetDbContextAsync();
}
}

View File

@@ -6,6 +6,10 @@ using System.Threading.Tasks;
namespace Yi.Framework.SqlSugarCore.Abstractions
{
/// <summary>
/// 忽略CodeFirst特性
/// 标记此特性的实体类将不会被CodeFirst功能扫描
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class IgnoreCodeFirstAttribute : Attribute
{

View File

@@ -3,7 +3,10 @@
<ItemGroup>
<PackageReference Include="SqlSugarCoreNoDrive" Version="$(SqlSugarVersion)" />
<!-- <PackageReference Include="SqlSugarCoreNoDrive" Version="$(SqlSugarVersion)" />-->
<PackageReference Include="SqlSugarCore" Version="$(SqlSugarVersion)" />
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="$(AbpVersion)" />
</ItemGroup>

View File

@@ -3,9 +3,13 @@ using Yi.Framework.Core;
namespace Yi.Framework.SqlSugarCore.Abstractions
{
/// <summary>
/// SqlSugar Core抽象层模块
/// 提供SqlSugar ORM的基础抽象接口和类型定义
/// </summary>
[DependsOn(typeof(YiFrameworkCoreModule))]
public class YiFrameworkSqlSugarCoreAbstractionsModule : AbpModule
{
// 模块配置方法可在此添加
}
}

View File

@@ -2,18 +2,34 @@
namespace Yi.Framework.SqlSugarCore
{
public class AsyncLocalDbContextAccessor
/// <summary>
/// 异步本地数据库上下文访问器
/// 用于在异步流中保存和访问数据库上下文
/// </summary>
public sealed class AsyncLocalDbContextAccessor
{
private readonly AsyncLocal<ISqlSugarDbContext?> _currentScope;
/// <summary>
/// 获取单例实例
/// </summary>
public static AsyncLocalDbContextAccessor Instance { get; } = new();
/// <summary>
/// 获取或设置当前数据库上下文
/// </summary>
public ISqlSugarDbContext? Current
{
get => _currentScope.Value;
set => _currentScope.Value = value;
}
public AsyncLocalDbContextAccessor()
/// <summary>
/// 初始化异步本地数据库上下文访问器
/// </summary>
private AsyncLocalDbContextAccessor()
{
_currentScope = new AsyncLocal<ISqlSugarDbContext?>();
}
private readonly AsyncLocal<ISqlSugarDbContext> _currentScope;
}
}
}

View File

@@ -18,208 +18,237 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.SqlSugarCore;
/// <summary>
/// 默认SqlSugar数据库上下文实现
/// </summary>
public class DefaultSqlSugarDbContext : SqlSugarDbContext
{
protected DbConnOptions Options => LazyServiceProvider.LazyGetRequiredService<IOptions<DbConnOptions>>().Value;
protected ICurrentUser CurrentUser => LazyServiceProvider.GetRequiredService<ICurrentUser>();
protected IGuidGenerator GuidGenerator => LazyServiceProvider.LazyGetRequiredService<IGuidGenerator>();
protected ILoggerFactory Logger => LazyServiceProvider.LazyGetRequiredService<ILoggerFactory>();
protected ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService<ICurrentTenant>();
protected IDataFilter DataFilter => LazyServiceProvider.LazyGetRequiredService<IDataFilter>();
public IUnitOfWorkManager UnitOfWorkManager => LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>();
protected virtual bool IsMultiTenantFilterEnabled => DataFilter?.IsEnabled<IMultiTenant>() ?? false;
protected virtual bool IsSoftDeleteFilterEnabled => DataFilter?.IsEnabled<ISoftDelete>() ?? false;
#region Protected Properties
protected IEntityChangeEventHelper EntityChangeEventHelper =>
/// <summary>
/// 数据库连接配置选项
/// </summary>
protected DbConnOptions DbOptions => LazyServiceProvider.LazyGetRequiredService<IOptions<DbConnOptions>>().Value;
/// <summary>
/// 当前用户服务
/// </summary>
protected ICurrentUser CurrentUserService => LazyServiceProvider.GetRequiredService<ICurrentUser>();
/// <summary>
/// GUID生成器
/// </summary>
protected IGuidGenerator GuidGeneratorService => LazyServiceProvider.LazyGetRequiredService<IGuidGenerator>();
/// <summary>
/// 日志工厂
/// </summary>
protected ILoggerFactory LoggerFactory => LazyServiceProvider.LazyGetRequiredService<ILoggerFactory>();
/// <summary>
/// 当前租户服务
/// </summary>
protected ICurrentTenant CurrentTenantService => LazyServiceProvider.LazyGetRequiredService<ICurrentTenant>();
/// <summary>
/// 数据过滤服务
/// </summary>
protected IDataFilter DataFilterService => LazyServiceProvider.LazyGetRequiredService<IDataFilter>();
/// <summary>
/// 工作单元管理器
/// </summary>
protected IUnitOfWorkManager UnitOfWorkManagerService => LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>();
/// <summary>
/// 实体变更事件帮助类
/// </summary>
protected IEntityChangeEventHelper EntityChangeEventHelperService =>
LazyServiceProvider.LazyGetService<IEntityChangeEventHelper>(NullEntityChangeEventHelper.Instance);
public DefaultSqlSugarDbContext(IAbpLazyServiceProvider lazyServiceProvider) : base(lazyServiceProvider)
/// <summary>
/// 是否启用多租户过滤
/// </summary>
protected virtual bool IsMultiTenantFilterEnabled => DataFilterService?.IsEnabled<IMultiTenant>() ?? false;
/// <summary>
/// 是否启用软删除过滤
/// </summary>
protected virtual bool IsSoftDeleteFilterEnabled => DataFilterService?.IsEnabled<ISoftDelete>() ?? false;
#endregion
/// <summary>
/// 构造函数
/// </summary>
public DefaultSqlSugarDbContext(IAbpLazyServiceProvider lazyServiceProvider)
: base(lazyServiceProvider)
{
}
/// <summary>
/// 自定义数据过滤器
/// </summary>
protected override void CustomDataFilter(ISqlSugarClient sqlSugarClient)
{
// 配置软删除过滤器
if (IsSoftDeleteFilterEnabled)
{
sqlSugarClient.QueryFilter.AddTableFilter<ISoftDelete>(u => u.IsDeleted == false);
sqlSugarClient.QueryFilter.AddTableFilter<ISoftDelete>(entity => !entity.IsDeleted);
}
// 配置多租户过滤器
if (IsMultiTenantFilterEnabled)
{
//表达式里只能有具体值,不能运算
var expressionCurrentTenant = CurrentTenant.Id ?? null;
sqlSugarClient.QueryFilter.AddTableFilter<IMultiTenant>(u => u.TenantId == expressionCurrentTenant);
var currentTenantId = CurrentTenantService.Id;
sqlSugarClient.QueryFilter.AddTableFilter<IMultiTenant>(entity => entity.TenantId == currentTenantId);
}
}
/// <summary>
/// 数据执行前的处理
/// </summary>
public override void DataExecuting(object oldValue, DataFilterModel entityInfo)
{
//审计日志
HandleAuditFields(oldValue, entityInfo);
HandleEntityEvents(entityInfo);
HandleDomainEvents(entityInfo);
}
#region Private Methods
/// <summary>
/// 处理审计字段
/// </summary>
private void HandleAuditFields(object oldValue, DataFilterModel entityInfo)
{
switch (entityInfo.OperationType)
{
case DataFilterType.UpdateByObject:
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModificationTime)))
{
if (!DateTime.MinValue.Equals(oldValue))
{
entityInfo.SetValue(DateTime.Now);
}
}
else if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModifierId)))
{
if (typeof(Guid?) == entityInfo.EntityColumnInfo.PropertyInfo.PropertyType)
{
if (CurrentUser.Id != null)
{
entityInfo.SetValue(CurrentUser.Id);
}
}
}
HandleUpdateAuditFields(oldValue, entityInfo);
break;
case DataFilterType.InsertByObject:
if (entityInfo.PropertyName.Equals(nameof(IEntity<Guid>.Id)))
{
//类型为guid
if (typeof(Guid) == entityInfo.EntityColumnInfo.PropertyInfo.PropertyType)
{
//主键为空或者为默认最小值
if (Guid.Empty.Equals(oldValue))
{
entityInfo.SetValue(GuidGenerator.Create());
}
}
}
else if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreationTime)))
{
//为空或者为默认最小值
if (DateTime.MinValue.Equals(oldValue))
{
entityInfo.SetValue(DateTime.Now);
}
}
else if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreatorId)))
{
//类型为guid
if (typeof(Guid?) == entityInfo.EntityColumnInfo.PropertyInfo.PropertyType)
{
if (CurrentUser.Id is not null)
{
entityInfo.SetValue(CurrentUser.Id);
}
}
}
else if (entityInfo.PropertyName.Equals(nameof(IMultiTenant.TenantId)))
{
if (CurrentTenant.Id is not null)
{
entityInfo.SetValue(CurrentTenant.Id);
}
}
HandleInsertAuditFields(oldValue, entityInfo);
break;
}
}
/// <summary>
/// 处理更新时的审计字段
/// </summary>
private void HandleUpdateAuditFields(object oldValue, DataFilterModel entityInfo)
{
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModificationTime)))
{
entityInfo.SetValue(DateTime.MinValue.Equals(oldValue) ? null : DateTime.Now);
}
else if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModifierId))
&& entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(Guid?))
{
entityInfo.SetValue(Guid.Empty.Equals(oldValue) ? null : CurrentUserService.Id);
}
}
//实体变更领域事件
/// <summary>
/// 处理插入时的审计字段
/// </summary>
private void HandleInsertAuditFields(object oldValue, DataFilterModel entityInfo)
{
if (entityInfo.PropertyName.Equals(nameof(IEntity<Guid>.Id)))
{
if (typeof(Guid) == entityInfo.EntityColumnInfo.PropertyInfo.PropertyType)
{
if (Guid.Empty.Equals(oldValue))
{
entityInfo.SetValue(GuidGeneratorService.Create());
}
}
}
else if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreationTime)))
{
if (DateTime.MinValue.Equals(oldValue))
{
entityInfo.SetValue(DateTime.Now);
}
}
else if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreatorId)))
{
if (typeof(Guid?) == entityInfo.EntityColumnInfo.PropertyInfo.PropertyType)
{
if (CurrentUserService.Id is not null)
{
entityInfo.SetValue(CurrentUserService.Id);
}
}
}
else if (entityInfo.PropertyName.Equals(nameof(IMultiTenant.TenantId)))
{
if (CurrentTenantService.Id is not null)
{
entityInfo.SetValue(CurrentTenantService.Id);
}
}
}
/// <summary>
/// 处理实体变更事件
/// </summary>
private void HandleEntityEvents(DataFilterModel entityInfo)
{
// 实体变更领域事件
switch (entityInfo.OperationType)
{
case DataFilterType.InsertByObject:
if (entityInfo.PropertyName == nameof(IEntity<object>.Id))
{
EntityChangeEventHelper.PublishEntityCreatedEvent(entityInfo.EntityValue);
EntityChangeEventHelperService.PublishEntityCreatedEvent(entityInfo.EntityValue);
}
break;
case DataFilterType.UpdateByObject:
if (entityInfo.PropertyName == nameof(IEntity<object>.Id))
{
//软删除,发布的是删除事件
if (entityInfo.EntityValue is ISoftDelete softDelete)
{
if (softDelete.IsDeleted == true)
{
EntityChangeEventHelper.PublishEntityDeletedEvent(entityInfo.EntityValue);
EntityChangeEventHelperService.PublishEntityDeletedEvent(entityInfo.EntityValue);
}
else
{
EntityChangeEventHelperService.PublishEntityUpdatedEvent(entityInfo.EntityValue);
}
}
else
{
EntityChangeEventHelper.PublishEntityUpdatedEvent(entityInfo.EntityValue);
EntityChangeEventHelperService.PublishEntityUpdatedEvent(entityInfo.EntityValue);
}
}
break;
case DataFilterType.DeleteByObject:
// if (entityInfo.PropertyName == nameof(IEntity<object>.Id))
// {
//这里sqlsugar有个特殊删除会返回批量的结果
//这里sqlsugar有第二个特殊删除事件是行级事件
if (entityInfo.EntityValue is IEnumerable entityValues)
if (entityInfo.EntityValue is IEnumerable entityValues)
{
foreach (var entityValue in entityValues)
{
foreach (var entityValue in entityValues)
{
EntityChangeEventHelper.PublishEntityDeletedEvent(entityValue);
}
EntityChangeEventHelperService.PublishEntityDeletedEvent(entityValue);
}
// }
}
break;
}
//实体领域事件-所有操作类型
}
/// <summary>
/// 处理领域事件
/// </summary>
private void HandleDomainEvents(DataFilterModel entityInfo)
{
// 实体领域事件-所有操作类型
if (entityInfo.PropertyName == nameof(IEntity<object>.Id))
{
var eventReport = CreateEventReport(entityInfo.EntityValue);
var eventReport = CreateEventReport(entityInfo.EntityValue);
PublishEntityEvents(eventReport);
}
}
public override void OnLogExecuting(string sql, SugarParameter[] pars)
{
if (Options.EnabledSqlLog)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("==========Yi-SQL执行:==========");
sb.AppendLine(UtilMethods.GetSqlString(DbType.SqlServer, sql, pars));
sb.AppendLine("===============================");
Logger.CreateLogger<DefaultSqlSugarDbContext>().LogDebug(sb.ToString());
}
}
public override void OnLogExecuted(string sql, SugarParameter[] pars)
{
if (Options.EnabledSqlLog)
{
var sqllog = $"=========Yi-SQL耗时{SqlSugarClient.Ado.SqlExecutionTime.TotalMilliseconds}毫秒=====";
Logger.CreateLogger<SqlSugarDbContext>().LogDebug(sqllog.ToString());
}
}
public override void EntityService(PropertyInfo propertyInfo, EntityColumnInfo entityColumnInfo)
{
if (propertyInfo.Name == nameof(IHasConcurrencyStamp.ConcurrencyStamp)) //带版本号并发更新
{
entityColumnInfo.IsEnableUpdateVersionValidation = true;
}
if (propertyInfo.PropertyType == typeof(ExtraPropertyDictionary))
{
entityColumnInfo.IsIgnore = true;
}
if (propertyInfo.Name == nameof(Entity<object>.Id))
{
entityColumnInfo.IsPrimarykey = true;
}
}
/// <summary>
/// 创建领域事件报告
/// </summary>
@@ -276,16 +305,58 @@ public class DefaultSqlSugarDbContext : SqlSugarDbContext
{
foreach (var localEvent in changeReport.DomainEvents)
{
UnitOfWorkManager.Current?.AddOrReplaceLocalEvent(
UnitOfWorkManagerService.Current?.AddOrReplaceLocalEvent(
new UnitOfWorkEventRecord(localEvent.EventData.GetType(), localEvent.EventData, localEvent.EventOrder)
);
}
foreach (var distributedEvent in changeReport.DistributedEvents)
{
UnitOfWorkManager.Current?.AddOrReplaceDistributedEvent(
UnitOfWorkManagerService.Current?.AddOrReplaceDistributedEvent(
new UnitOfWorkEventRecord(distributedEvent.EventData.GetType(), distributedEvent.EventData, distributedEvent.EventOrder)
);
}
}
#endregion
public override void OnLogExecuting(string sql, SugarParameter[] pars)
{
if (DbOptions.EnabledSqlLog)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("==========Yi-SQL执行:==========");
sb.AppendLine(UtilMethods.GetSqlString(DbType.SqlServer, sql, pars));
sb.AppendLine("===============================");
LoggerFactory.CreateLogger<DefaultSqlSugarDbContext>().LogDebug(sb.ToString());
}
}
public override void OnLogExecuted(string sql, SugarParameter[] pars)
{
if (DbOptions.EnabledSqlLog)
{
var sqllog = $"=========Yi-SQL耗时{SqlSugarClient.Ado.SqlExecutionTime.TotalMilliseconds}毫秒=====";
LoggerFactory.CreateLogger<SqlSugarDbContext>().LogDebug(sqllog.ToString());
}
}
public override void EntityService(PropertyInfo propertyInfo, EntityColumnInfo entityColumnInfo)
{
if (propertyInfo.Name == nameof(IHasConcurrencyStamp.ConcurrencyStamp)) //带版本号并发更新
{
entityColumnInfo.IsEnableUpdateVersionValidation = true;
}
if (propertyInfo.PropertyType == typeof(ExtraPropertyDictionary))
{
entityColumnInfo.IsIgnore = true;
}
if (propertyInfo.Name == nameof(Entity<object>.Id))
{
entityColumnInfo.IsPrimarykey = true;
}
}
}

View File

@@ -1,12 +1,9 @@
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Nito.AsyncEx;
using SqlSugar;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Linq;
@@ -21,34 +18,42 @@ namespace Yi.Framework.SqlSugarCore.Repositories
public ISugarQueryable<TEntity> _DbQueryable => _Db.Queryable<TEntity>();
private ISugarDbContextProvider<ISqlSugarDbContext> _sugarDbContextProvider;
private readonly ISugarDbContextProvider<ISqlSugarDbContext> _dbContextProvider;
public IAbpLazyServiceProvider LazyServiceProvider { get; set; }
protected DbConnOptions? Options => LazyServiceProvider?.LazyGetService<IOptions<DbConnOptions>>().Value;
/// <summary>
/// 异步查询执行器
/// </summary>
public IAsyncQueryableExecuter AsyncExecuter { get; }
/// <summary>
/// 是否启用变更追踪
/// </summary>
public bool? IsChangeTrackingEnabled => false;
public SqlSugarRepository(ISugarDbContextProvider<ISqlSugarDbContext> sugarDbContextProvider)
public SqlSugarRepository(ISugarDbContextProvider<ISqlSugarDbContext> dbContextProvider)
{
_sugarDbContextProvider = sugarDbContextProvider;
_dbContextProvider = dbContextProvider;
}
/// <summary>
/// 获取DB
/// 获取数据库上下文
/// </summary>
/// <returns></returns>
public virtual async Task<ISqlSugarClient> GetDbContextAsync()
{
var db = (await _sugarDbContextProvider.GetDbContextAsync()).SqlSugarClient;
return db;
var dbContext = await _dbContextProvider.GetDbContextAsync();
return dbContext.SqlSugarClient;
}
/// <summary>
/// 获取简单Db
/// 获取简单数据库客户端
/// </summary>
/// <returns></returns>
public virtual async Task<SimpleClient<TEntity>> GetDbSimpleClientAsync()
{
var db = await GetDbContextAsync();
return new SimpleClient<TEntity>(db);
var dbContext = await GetDbContextAsync();
return new SimpleClient<TEntity>(dbContext);
}
#region Abp模块
@@ -166,7 +171,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
{
return (await GetDbSimpleClientAsync()).AsInsertable(insertObj);
}
public virtual async Task<IInsertable<TEntity>> AsInsertable(TEntity[] insertObjs)
{
return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs);
@@ -259,6 +264,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
{
var entity = await GetByIdAsync(id);
if (entity == null) return false;
//反射赋值
ReflexHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, entity);
return await UpdateAsync(entity);
@@ -374,20 +380,24 @@ namespace Yi.Framework.SqlSugarCore.Repositories
public virtual async Task<bool> UpdateAsync(TEntity updateObj)
{
if (typeof(TEntity).IsAssignableTo<IHasConcurrencyStamp>())//带版本号乐观锁更新
if (Options is not null && Options.EnabledConcurrencyException)
{
try
if (typeof(TEntity).IsAssignableTo<IHasConcurrencyStamp>()) //带版本号乐观锁更新
{
int num = await (await GetDbSimpleClientAsync())
.Context.Updateable(updateObj).ExecuteCommandWithOptLockAsync(true);
return num>0;
}
catch (VersionExceptions ex)
{
throw new AbpDbConcurrencyException($"{ex.Message}[更新失败ConcurrencyStamp不是最新版本],entityInfo{updateObj}", ex);
try
{
int num = await (await GetDbSimpleClientAsync())
.Context.Updateable(updateObj).ExecuteCommandWithOptLockAsync(true);
return num > 0;
}
catch (VersionExceptions ex)
{
throw new AbpDbConcurrencyException(
$"{ex.Message}[更新失败ConcurrencyStamp不是最新版本],entityInfo{updateObj}", ex);
}
}
}
return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj);
}

View File

@@ -7,35 +7,47 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.SqlSugarCore
namespace Yi.Framework.SqlSugarCore;
/// <summary>
/// SqlSugar Core扩展方法
/// </summary>
public static class SqlSugarCoreExtensions
{
public static class SqlSugarCoreExtensions
/// <summary>
/// 添加数据库上下文
/// </summary>
/// <typeparam name="TDbContext">数据库上下文类型</typeparam>
/// <param name="services">服务集合</param>
/// <param name="serviceLifetime">服务生命周期</param>
/// <returns>服务集合</returns>
public static IServiceCollection AddYiDbContext<TDbContext>(
this IServiceCollection services,
ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
where TDbContext : class, ISqlSugarDbContextDependencies
{
/// <summary>
/// 新增db对象可支持多个
/// </summary>
/// <param name="service"></param>
/// <param name="serviceLifetime"></param>
/// <typeparam name="TDbContext"></typeparam>
/// <returns></returns>
public static IServiceCollection AddYiDbContext<TDbContext>(this IServiceCollection service, ServiceLifetime serviceLifetime = ServiceLifetime.Transient) where TDbContext : class, ISqlSugarDbContextDependencies
{
service.AddTransient<ISqlSugarDbContextDependencies, TDbContext>();
return service;
}
/// <summary>
/// 新增db对象可支持多个
/// </summary>
/// <param name="service"></param>
/// <param name="options"></param>
/// <typeparam name="TDbContext"></typeparam>
/// <returns></returns>
public static IServiceCollection AddYiDbContext<TDbContext>(this IServiceCollection service, Action<DbConnOptions> options) where TDbContext : class, ISqlSugarDbContextDependencies
{
service.Configure<DbConnOptions>(options.Invoke);
service.AddYiDbContext<TDbContext>();
return service;
}
services.Add(new ServiceDescriptor(
typeof(ISqlSugarDbContextDependencies),
typeof(TDbContext),
serviceLifetime));
return services;
}
/// <summary>
/// 添加数据库上下文并配置选项
/// </summary>
/// <typeparam name="TDbContext">数据库上下文类型</typeparam>
/// <param name="services">服务集合</param>
/// <param name="configureOptions">配置选项委托</param>
/// <returns>服务集合</returns>
public static IServiceCollection AddYiDbContext<TDbContext>(
this IServiceCollection services,
Action<DbConnOptions> configureOptions)
where TDbContext : class, ISqlSugarDbContextDependencies
{
services.Configure(configureOptions);
services.AddYiDbContext<TDbContext>();
return services;
}
}

View File

@@ -5,44 +5,78 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.SqlSugarCore;
/// <summary>
/// SqlSugar数据库上下文基类
/// </summary>
public abstract class SqlSugarDbContext : ISqlSugarDbContextDependencies
{
/// <summary>
/// 服务提供者
/// </summary>
protected IAbpLazyServiceProvider LazyServiceProvider { get; }
public SqlSugarDbContext(IAbpLazyServiceProvider lazyServiceProvider)
/// <summary>
/// 数据库客户端实例
/// </summary>
protected ISqlSugarClient SqlSugarClient { get; private set; }
/// <summary>
/// 执行顺序
/// </summary>
public virtual int ExecutionOrder => 0;
protected SqlSugarDbContext(IAbpLazyServiceProvider lazyServiceProvider)
{
this.LazyServiceProvider = lazyServiceProvider;
LazyServiceProvider = lazyServiceProvider;
}
protected ISqlSugarClient SqlSugarClient { get;private set; }
public int ExecutionOrder => 0;
public void OnSqlSugarClientConfig(ISqlSugarClient sqlSugarClient)
/// <summary>
/// 配置SqlSugar客户端
/// </summary>
public virtual void OnSqlSugarClientConfig(ISqlSugarClient sqlSugarClient)
{
SqlSugarClient = sqlSugarClient;
CustomDataFilter(sqlSugarClient);
}
/// <summary>
/// 自定义数据过滤器
/// </summary>
protected virtual void CustomDataFilter(ISqlSugarClient sqlSugarClient)
{
}
/// <summary>
/// 数据执行后事件
/// </summary>
public virtual void DataExecuted(object oldValue, DataAfterModel entityInfo)
{
}
/// <summary>
/// 数据执行前事件
/// </summary>
public virtual void DataExecuting(object oldValue, DataFilterModel entityInfo)
{
}
/// <summary>
/// SQL执行前事件
/// </summary>
public virtual void OnLogExecuting(string sql, SugarParameter[] pars)
{
}
/// <summary>
/// SQL执行后事件
/// </summary>
public virtual void OnLogExecuted(string sql, SugarParameter[] pars)
{
}
/// <summary>
/// 实体服务配置
/// </summary>
public virtual void EntityService(PropertyInfo propertyInfo, EntityColumnInfo entityColumnInfo)
{
}

View File

@@ -4,26 +4,52 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.SqlSugarCore;
/// <summary>
/// SqlSugar数据库上下文创建上下文
/// </summary>
public class SqlSugarDbContextCreationContext
{
public static SqlSugarDbContextCreationContext Current => _current.Value;
private static readonly AsyncLocal<SqlSugarDbContextCreationContext> _current = new AsyncLocal<SqlSugarDbContextCreationContext>();
private static readonly AsyncLocal<SqlSugarDbContextCreationContext> CurrentContextHolder =
new AsyncLocal<SqlSugarDbContextCreationContext>();
/// <summary>
/// 获取当前上下文
/// </summary>
public static SqlSugarDbContextCreationContext Current => CurrentContextHolder.Value!;
/// <summary>
/// 连接字符串名称
/// </summary>
public string ConnectionStringName { get; }
/// <summary>
/// 连接字符串
/// </summary>
public string ConnectionString { get; }
public DbConnection ExistingConnection { get; internal set; }
/// <summary>
/// 现有数据库连接
/// </summary>
public DbConnection? ExistingConnection { get; internal set; }
public SqlSugarDbContextCreationContext(string connectionStringName, string connectionString)
/// <summary>
/// 构造函数
/// </summary>
public SqlSugarDbContextCreationContext(
string connectionStringName,
string connectionString)
{
ConnectionStringName = connectionStringName;
ConnectionString = connectionString;
}
/// <summary>
/// 使用指定的上下文
/// </summary>
public static IDisposable Use(SqlSugarDbContextCreationContext context)
{
var previousValue = Current;
_current.Value = context;
return new DisposeAction(() => _current.Value = previousValue);
var previousContext = Current;
CurrentContextHolder.Value = context;
return new DisposeAction(() => CurrentContextHolder.Value = previousContext);
}
}

View File

@@ -13,216 +13,226 @@ using Check = Volo.Abp.Check;
namespace Yi.Framework.SqlSugarCore
{
/// <summary>
/// SqlSugar数据库上下文工厂类
/// 负责创建和配置SqlSugar客户端实例
/// </summary>
public class SqlSugarDbContextFactory : ISqlSugarDbContext
{
#region Properties
/// <summary>
/// SqlSugar 客户端
/// SqlSugar客户端实例
/// </summary>
public ISqlSugarClient SqlSugarClient { get; private set; }
/// <summary>
/// 延迟服务提供者
/// </summary>
private IAbpLazyServiceProvider LazyServiceProvider { get; }
private ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService<ICurrentTenant>();
public DbConnOptions Options => LazyServiceProvider.LazyGetRequiredService<IOptions<DbConnOptions>>().Value;
/// <summary>
/// 租户配置包装器
/// </summary>
private TenantConfigurationWrapper TenantConfigurationWrapper =>
LazyServiceProvider.LazyGetRequiredService<TenantConfigurationWrapper>();
private ISerializeService SerializeService => LazyServiceProvider.LazyGetRequiredService<ISerializeService>();
/// <summary>
/// 当前租户信息
/// </summary>
private ICurrentTenant CurrentTenant =>
LazyServiceProvider.LazyGetRequiredService<ICurrentTenant>();
/// <summary>
/// 数据库连接配置选项
/// </summary>
private DbConnOptions DbConnectionOptions =>
LazyServiceProvider.LazyGetRequiredService<IOptions<DbConnOptions>>().Value;
/// <summary>
/// 序列化服务
/// </summary>
private ISerializeService SerializeService =>
LazyServiceProvider.LazyGetRequiredService<ISerializeService>();
/// <summary>
/// SqlSugar上下文依赖项集合
/// </summary>
private IEnumerable<ISqlSugarDbContextDependencies> SqlSugarDbContextDependencies =>
LazyServiceProvider.LazyGetRequiredService<IEnumerable<ISqlSugarDbContextDependencies>>();
/// <summary>
/// 连接配置缓存字典
/// </summary>
private static readonly ConcurrentDictionary<string, ConnectionConfig> ConnectionConfigCache = new();
#endregion
/// <summary>
/// 构造函数
/// </summary>
/// <param name="lazyServiceProvider">延迟服务提供者</param>
public SqlSugarDbContextFactory(IAbpLazyServiceProvider lazyServiceProvider)
{
LazyServiceProvider = lazyServiceProvider;
var connectionString = GetCurrentConnectionString();
var connectionConfig =BuildConnectionConfig(action: options =>
// 异步获取租户配置
var tenantConfiguration = AsyncHelper.RunSync(async () => await TenantConfigurationWrapper.GetAsync());
// 构建数据库连接配置
var connectionConfig = BuildConnectionConfig(options =>
{
options.ConnectionString = connectionString;
options.DbType = GetCurrentDbType();
options.ConnectionString = tenantConfiguration.GetCurrentConnectionString();
options.DbType = GetCurrentDbType(tenantConfiguration.GetCurrentConnectionName());
});
// var connectionConfig = ConnectionConfigCache.GetOrAdd(connectionString, (_) =>
// BuildConnectionConfig(action: options =>
// {
// options.ConnectionString = connectionString;
// options.DbType = GetCurrentDbType();
// }));
SqlSugarClient = new SqlSugarClient(connectionConfig);
//生命周期以下都可以直接使用sqlsugardb了
// Aop及多租户连接字符串和类型需要单独设置
// Aop操作不能进行缓存
SetDbAop(SqlSugarClient);
// 创建SqlSugar客户端实例
SqlSugarClient = new SqlSugarClient(connectionConfig);
// 配置数据库AOP
ConfigureDbAop(SqlSugarClient);
}
/// <summary>
/// 构建Aop-sqlsugaraop在多租户模式中需单独设置
/// 配置数据库AOP操作
/// </summary>
/// <param name="sqlSugarClient"></param>
protected virtual void SetDbAop(ISqlSugarClient sqlSugarClient)
/// <param name="sqlSugarClient">SqlSugar客户端实例</param>
protected virtual void ConfigureDbAop(ISqlSugarClient sqlSugarClient)
{
//替换默认序列化
// 配置序列化服务
sqlSugarClient.CurrentConnectionConfig.ConfigureExternalServices.SerializeService = SerializeService;
//将所有ISqlSugarDbContextDependencies进行累加
// 初始化AOP事件处理器
Action<string, SugarParameter[]> onLogExecuting = null;
Action<string, SugarParameter[]> onLogExecuted = null;
Action<object, DataFilterModel> dataExecuting = null;
Action<object, DataAfterModel> dataExecuted = null;
Action<ISqlSugarClient> onSqlSugarClientConfig = null;
Action<ISqlSugarClient> onClientConfig = null;
// 按执行顺序聚合所有依赖项的AOP处理器
foreach (var dependency in SqlSugarDbContextDependencies.OrderBy(x => x.ExecutionOrder))
{
onLogExecuting += dependency.OnLogExecuting;
onLogExecuted += dependency.OnLogExecuted;
dataExecuting += dependency.DataExecuting;
dataExecuted += dependency.DataExecuted;
onSqlSugarClientConfig += dependency.OnSqlSugarClientConfig;
onClientConfig += dependency.OnSqlSugarClientConfig;
}
//最先存放db操作
onSqlSugarClientConfig(sqlSugarClient);
// 配置SqlSugar客户端
onClientConfig?.Invoke(sqlSugarClient);
sqlSugarClient.Aop.OnLogExecuting =onLogExecuting;
// 设置AOP事件
sqlSugarClient.Aop.OnLogExecuting = onLogExecuting;
sqlSugarClient.Aop.OnLogExecuted = onLogExecuted;
sqlSugarClient.Aop.DataExecuting =dataExecuting;
sqlSugarClient.Aop.DataExecuted =dataExecuted;
sqlSugarClient.Aop.DataExecuting = dataExecuting;
sqlSugarClient.Aop.DataExecuted = dataExecuted;
}
/// <summary>
/// 构建连接配置
/// 构建数据库连接配置
/// </summary>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
protected virtual ConnectionConfig BuildConnectionConfig(Action<ConnectionConfig>? action = null)
/// <param name="configAction">配置操作委托</param>
/// <returns>连接配置对象</returns>
protected virtual ConnectionConfig BuildConnectionConfig(Action<ConnectionConfig> configAction = null)
{
var dbConnOptions = Options;
#region options
var dbConnOptions = DbConnectionOptions;
// 验证数据库类型配置
if (dbConnOptions.DbType is null)
{
throw new ArgumentException("DbType配置为空");
throw new ArgumentException("未配置数据库类型(DbType)");
}
var slavaConFig = new List<SlaveConnectionConfig>();
// 配置读写分离
var slaveConfigs = new List<SlaveConnectionConfig>();
if (dbConnOptions.EnabledReadWrite)
{
if (dbConnOptions.ReadUrl is null)
{
throw new ArgumentException("读写分离为空");
throw new ArgumentException("启用读写分离但未配置读库连接字符串");
}
var readCon = dbConnOptions.ReadUrl;
readCon.ForEach(s =>
{
//如果是动态saas分库这里的连接串都不能写死需要动态添加这里只配置共享库的连接
slavaConFig.Add(new SlaveConnectionConfig() { ConnectionString = s });
});
slaveConfigs.AddRange(dbConnOptions.ReadUrl.Select(url =>
new SlaveConnectionConfig { ConnectionString = url }));
}
#endregion
#region config
var connectionConfig = new ConnectionConfig()
// 创建连接配置
var connectionConfig = new ConnectionConfig
{
ConfigId = ConnectionStrings.DefaultConnectionStringName,
DbType = dbConnOptions.DbType ?? DbType.Sqlite,
ConnectionString = dbConnOptions.Url,
IsAutoCloseConnection = true,
SlaveConnectionConfigs = slavaConFig,
//设置codefirst非空值判断
ConfigureExternalServices = new ConfigureExternalServices
{
// 处理表
EntityNameService = (type, entity) =>
{
if (dbConnOptions.EnableUnderLine && !entity.DbTableName.Contains('_'))
entity.DbTableName = UtilMethods.ToUnderLine(entity.DbTableName); // 驼峰转下划线
},
EntityService = (c, p) =>
{
if (new NullabilityInfoContext()
.Create(c).WriteState is NullabilityState.Nullable)
{
p.IsNullable = true;
}
if (dbConnOptions.EnableUnderLine && !p.IsIgnore && !p.DbColumnName.Contains('_'))
p.DbColumnName = UtilMethods.ToUnderLine(p.DbColumnName); // 驼峰转下划线
//将所有ISqlSugarDbContextDependencies的EntityService进行累加
//额外的实体服务需要这里配置,
Action<PropertyInfo, EntityColumnInfo> entityService = null;
foreach (var dependency in SqlSugarDbContextDependencies.OrderBy(x => x.ExecutionOrder))
{
entityService += dependency.EntityService;
}
entityService(c, p);
}
},
//这里多租户有个坑,这里配置是无效的
// AopEvents = new AopEvents
// {
// DataExecuted = DataExecuted,
// DataExecuting = DataExecuting,
// OnLogExecuted = OnLogExecuted,
// OnLogExecuting = OnLogExecuting
// }
SlaveConnectionConfigs = slaveConfigs,
ConfigureExternalServices = CreateExternalServices(dbConnOptions)
};
if (action is not null)
{
action.Invoke(connectionConfig);
}
#endregion
// 应用额外配置
configAction?.Invoke(connectionConfig);
return connectionConfig;
}
/// <summary>
/// db切换多库支持
/// 创建外部服务配置
/// </summary>
/// <returns></returns>
protected virtual string GetCurrentConnectionString()
private ConfigureExternalServices CreateExternalServices(DbConnOptions dbConnOptions)
{
var connectionStringResolver = LazyServiceProvider.LazyGetRequiredService<IConnectionStringResolver>();
var connectionString =
AsyncHelper.RunSync(() => connectionStringResolver.ResolveAsync());
if (string.IsNullOrWhiteSpace(connectionString))
return new ConfigureExternalServices
{
Check.NotNull(Options.Url, "dbUrl未配置");
}
return connectionString!;
}
protected virtual DbType GetCurrentDbType()
{
if (CurrentTenant.Name is not null)
{
var dbTypeFromTenantName = GetDbTypeFromTenantName(CurrentTenant.Name);
if (dbTypeFromTenantName is not null)
EntityNameService = (type, entity) =>
{
return dbTypeFromTenantName.Value;
}
}
if (dbConnOptions.EnableUnderLine && !entity.DbTableName.Contains('_'))
{
entity.DbTableName = UtilMethods.ToUnderLine(entity.DbTableName);
}
},
EntityService = (propertyInfo, columnInfo) =>
{
// 配置空值处理
if (new NullabilityInfoContext().Create(propertyInfo).WriteState
is NullabilityState.Nullable)
{
columnInfo.IsNullable = true;
}
Check.NotNull(Options.DbType, "默认DbType未配置");
return Options.DbType!.Value;
// 处理下划线命名
if (dbConnOptions.EnableUnderLine && !columnInfo.IsIgnore
&& !columnInfo.DbColumnName.Contains('_'))
{
columnInfo.DbColumnName = UtilMethods.ToUnderLine(columnInfo.DbColumnName);
}
// 聚合所有依赖项的实体服务
Action<PropertyInfo, EntityColumnInfo> entityService = null;
foreach (var dependency in SqlSugarDbContextDependencies.OrderBy(x => x.ExecutionOrder))
{
entityService += dependency.EntityService;
}
entityService?.Invoke(propertyInfo, columnInfo);
}
};
}
//根据租户name进行匹配db类型: Test_Sqlite[来自AI]
/// <summary>
/// 获取当前数据库类型
/// </summary>
/// <param name="tenantName">租户名称</param>
/// <returns>数据库类型</returns>
protected virtual DbType GetCurrentDbType(string tenantName)
{
return tenantName == ConnectionStrings.DefaultConnectionStringName
? DbConnectionOptions.DbType!.Value
: GetDbTypeFromTenantName(tenantName)
?? throw new ArgumentException($"无法从租户名称{tenantName}中解析数据库类型");
}
/// <summary>
/// 从租户名称解析数据库类型
/// 格式TenantName@DbType
/// </summary>
private DbType? GetDbTypeFromTenantName(string name)
{
if (string.IsNullOrWhiteSpace(name))
@@ -230,60 +240,50 @@ namespace Yi.Framework.SqlSugarCore
return null;
}
// 查找下划线的位置
int underscoreIndex = name.LastIndexOf('_');
if (underscoreIndex == -1 || underscoreIndex == name.Length - 1)
var atIndex = name.LastIndexOf('@');
if (atIndex == -1 || atIndex == name.Length - 1)
{
return null;
}
// 提取 枚举 部分
string enumString = name.Substring(underscoreIndex + 1);
// 尝试将 尾缀 转换为枚举
if (Enum.TryParse<DbType>(enumString, out DbType result))
{
return result;
}
// 条件不满足时返回 null
return null;
var dbTypeString = name[(atIndex + 1)..];
return Enum.TryParse<DbType>(dbTypeString, out var dbType)
? dbType
: throw new ArgumentException($"不支持的数据库类型: {dbTypeString}");
}
/// <summary>
/// 备份数据库
/// </summary>
public virtual void BackupDataBase()
{
string directoryName = "database_backup";
string fileName = DateTime.Now.ToString($"yyyyMMdd_HHmmss") + $"_{SqlSugarClient.Ado.Connection.Database}";
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
const string backupDirectory = "database_backup";
var fileName = $"{DateTime.Now:yyyyMMdd_HHmmss}_{SqlSugarClient.Ado.Connection.Database}";
Directory.CreateDirectory(backupDirectory);
switch (Options.DbType)
switch (DbConnectionOptions.DbType)
{
case DbType.MySql:
//MySql
SqlSugarClient.DbMaintenance.BackupDataBase(SqlSugarClient.Ado.Connection.Database,
$"{Path.Combine(directoryName, fileName)}.sql"); //mysql 只支持.net core
SqlSugarClient.DbMaintenance.BackupDataBase(
SqlSugarClient.Ado.Connection.Database,
Path.Combine(backupDirectory, $"{fileName}.sql"));
break;
case DbType.Sqlite:
//Sqlite
SqlSugarClient.DbMaintenance.BackupDataBase(null, $"{fileName}.db"); //sqlite 只支持.net core
SqlSugarClient.DbMaintenance.BackupDataBase(
null,
$"{fileName}.db");
break;
case DbType.SqlServer:
//SqlServer
SqlSugarClient.DbMaintenance.BackupDataBase(SqlSugarClient.Ado.Connection.Database,
$"{Path.Combine(directoryName, fileName)}.bak" /*服务器路径*/); //第一个参数库名
SqlSugarClient.DbMaintenance.BackupDataBase(
SqlSugarClient.Ado.Connection.Database,
Path.Combine(backupDirectory, $"{fileName}.bak"));
break;
default:
throw new NotImplementedException("其他数据库备份未实现");
throw new NotImplementedException($"数据库类型 {DbConnectionOptions.DbType} 的备份操作尚未实现");
}
}
}

View File

@@ -63,14 +63,14 @@ public class SqlSugarNonPublicSerializer : ISerializeService
// 调用 SerializeObject 方法序列化对象
T json = (T)methods.MakeGenericMethod(typeof(T))
.Invoke(null, new object[] { value, null });
return json;
.Invoke(null, new object[] { value, null! });
return json!;
}
var jSetting = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
ContractResolver =new NonPublicPropertiesResolver() //替换默认解析器使能支持protect
};
return JsonConvert.DeserializeObject<T>(value, jSetting);
return JsonConvert.DeserializeObject<T>(value, jSetting)!;
}
}

View File

@@ -0,0 +1,112 @@
using Microsoft.Extensions.Options;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.SqlSugarCore;
/// <summary>
/// 租户配置包装器
/// </summary>
public class TenantConfigurationWrapper : ITransientDependency
{
private readonly IAbpLazyServiceProvider _serviceProvider;
private ICurrentTenant CurrentTenantService =>
_serviceProvider.LazyGetRequiredService<ICurrentTenant>();
private ITenantStore TenantStoreService =>
_serviceProvider.LazyGetRequiredService<ITenantStore>();
private DbConnOptions DbConnectionOptions =>
_serviceProvider.LazyGetRequiredService<IOptions<DbConnOptions>>().Value;
/// <summary>
/// 构造函数
/// </summary>
public TenantConfigurationWrapper(IAbpLazyServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
/// <summary>
/// 获取租户配置信息
/// </summary>
public async Task<TenantConfiguration?> GetAsync()
{
if (!DbConnectionOptions.EnabledSaasMultiTenancy)
{
return await TenantStoreService.FindAsync(ConnectionStrings.DefaultConnectionStringName);
}
return await GetTenantConfigurationByCurrentTenant();
}
private async Task<TenantConfiguration?> GetTenantConfigurationByCurrentTenant()
{
// 通过租户ID查找
if (CurrentTenantService.Id.HasValue)
{
var config = await TenantStoreService.FindAsync(CurrentTenantService.Id.Value);
if (config == null)
{
throw new ApplicationException($"未找到租户信息,租户Id:{CurrentTenantService.Id}");
}
return config;
}
// 通过租户名称查找
if (!string.IsNullOrEmpty(CurrentTenantService.Name))
{
var config = await TenantStoreService.FindAsync(CurrentTenantService.Name);
if (config == null)
{
throw new ApplicationException($"未找到租户信息,租户名称:{CurrentTenantService.Name}");
}
return config;
}
// 返回默认配置
return await TenantStoreService.FindAsync(ConnectionStrings.DefaultConnectionStringName);
}
/// <summary>
/// 获取当前连接字符串
/// </summary>
/// <returns></returns>
public async Task<string> GetCurrentConnectionStringAsync()
{
return (await GetAsync()).ConnectionStrings.Default!;
}
/// <summary>
/// 获取当前连接名
/// </summary>
/// <returns></returns>
public async Task<string> GetCurrentConnectionNameAsync()
{
return (await GetAsync()).Name;
}
}
public static class TenantConfigurationExtensions
{
/// <summary>
/// 获取当前连接字符串
/// </summary>
/// <returns></returns>
public static string GetCurrentConnectionString(this TenantConfiguration tenantConfiguration)
{
return tenantConfiguration.ConnectionStrings.Default!;
}
/// <summary>
/// 获取当前连接名
/// </summary>
/// <returns></returns>
public static string GetCurrentConnectionName(this TenantConfiguration tenantConfiguration)
{
return tenantConfiguration.Name;
}
}

View File

@@ -8,10 +8,20 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.SqlSugarCore.Uow
{
/// <summary>
/// SqlSugar数据库API实现
/// </summary>
public class SqlSugarDatabaseApi : IDatabaseApi
{
/// <summary>
/// 数据库上下文
/// </summary>
public ISqlSugarDbContext DbContext { get; }
/// <summary>
/// 初始化SqlSugar数据库API
/// </summary>
/// <param name="dbContext">数据库上下文</param>
public SqlSugarDatabaseApi(ISqlSugarDbContext dbContext)
{
DbContext = dbContext;

View File

@@ -3,33 +3,48 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.SqlSugarCore.Uow
{
/// <summary>
/// SqlSugar事务API实现
/// </summary>
public class SqlSugarTransactionApi : ITransactionApi, ISupportsRollback
{
private ISqlSugarDbContext _sqlsugarDbContext;
private readonly ISqlSugarDbContext _dbContext;
public SqlSugarTransactionApi(ISqlSugarDbContext sqlsugarDbContext)
public SqlSugarTransactionApi(ISqlSugarDbContext dbContext)
{
_sqlsugarDbContext = sqlsugarDbContext;
_dbContext = dbContext;
}
/// <summary>
/// 获取数据库上下文
/// </summary>
public ISqlSugarDbContext GetDbContext()
{
return _sqlsugarDbContext;
return _dbContext;
}
/// <summary>
/// 提交事务
/// </summary>
public async Task CommitAsync(CancellationToken cancellationToken = default)
{
await _sqlsugarDbContext.SqlSugarClient.Ado.CommitTranAsync();
}
public void Dispose()
{
_sqlsugarDbContext.SqlSugarClient.Ado.Dispose();
await _dbContext.SqlSugarClient.Ado.CommitTranAsync();
}
/// <summary>
/// 回滚事务
/// </summary>
public async Task RollbackAsync(CancellationToken cancellationToken = default)
{
await _sqlsugarDbContext.SqlSugarClient.Ado.RollbackTranAsync();
await _dbContext.SqlSugarClient.Ado.RollbackTranAsync();
}
/// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
_dbContext.SqlSugarClient.Ado.Dispose();
}
}
}

View File

@@ -13,130 +13,121 @@ namespace Yi.Framework.SqlSugarCore.Uow
{
public class UnitOfWorkSqlsugarDbContextProvider<TDbContext> : ISugarDbContextProvider<TDbContext> where TDbContext : ISqlSugarDbContext
{
/// <summary>
/// 日志记录器
/// </summary>
public ILogger<UnitOfWorkSqlsugarDbContextProvider<TDbContext>> Logger { get; set; }
/// <summary>
/// 服务提供者
/// </summary>
public IServiceProvider ServiceProvider { get; set; }
/// <summary>
/// 数据库上下文访问器实例
/// </summary>
private static AsyncLocalDbContextAccessor ContextInstance => AsyncLocalDbContextAccessor.Instance;
protected readonly IUnitOfWorkManager UnitOfWorkManager;
protected readonly IConnectionStringResolver ConnectionStringResolver;
protected readonly ICancellationTokenProvider CancellationTokenProvider;
protected readonly ICurrentTenant CurrentTenant;
private readonly TenantConfigurationWrapper _tenantConfigurationWrapper;
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly IConnectionStringResolver _connectionStringResolver;
private readonly ICancellationTokenProvider _cancellationTokenProvider;
private readonly ICurrentTenant _currentTenant;
public UnitOfWorkSqlsugarDbContextProvider(
IUnitOfWorkManager unitOfWorkManager,
IConnectionStringResolver connectionStringResolver,
ICancellationTokenProvider cancellationTokenProvider,
ICurrentTenant currentTenant
)
ICurrentTenant currentTenant,
TenantConfigurationWrapper tenantConfigurationWrapper)
{
UnitOfWorkManager = unitOfWorkManager;
ConnectionStringResolver = connectionStringResolver;
CancellationTokenProvider = cancellationTokenProvider;
CurrentTenant = currentTenant;
_unitOfWorkManager = unitOfWorkManager;
_connectionStringResolver = connectionStringResolver;
_cancellationTokenProvider = cancellationTokenProvider;
_currentTenant = currentTenant;
_tenantConfigurationWrapper = tenantConfigurationWrapper;
Logger = NullLogger<UnitOfWorkSqlsugarDbContextProvider<TDbContext>>.Instance;
}
/// <summary>
/// 获取数据库上下文
/// </summary>
public virtual async Task<TDbContext> GetDbContextAsync()
{
var connectionStringName = ConnectionStrings.DefaultConnectionStringName;
//获取当前连接字符串,未多租户时,默认为空
var connectionString = await ResolveConnectionStringAsync(connectionStringName);
// 获取当前租户配置
var tenantConfiguration = await _tenantConfigurationWrapper.GetAsync();
// 获取连接字符串信息
var connectionStringName = tenantConfiguration.GetCurrentConnectionName();
var connectionString = tenantConfiguration.GetCurrentConnectionString();
var dbContextKey = $"{this.GetType().Name}_{connectionString}";
var unitOfWork = UnitOfWorkManager.Current;
if (unitOfWork == null )
var unitOfWork = _unitOfWorkManager.Current;
if (unitOfWork == null)
{
//var dbContext = (TDbContext)ServiceProvider.GetRequiredService<ISqlSugarDbContext>();
//如果不启用工作单元创建一个新的db不开启事务即可
//return dbContext;
//2024-11-30改回强制性使用工作单元否则容易造成歧义
throw new AbpException("DbContext 只能在工作单元内工作当前DbContext没有工作单元如需创建新线程并发操作请手动创建工作单元");
throw new AbpException(
"DbContext 只能在工作单元内工作当前DbContext没有工作单元如需创建新线程并发操作请手动创建工作单元");
}
//尝试当前工作单元获取db
// 尝试从当前工作单元获取数据库API
var databaseApi = unitOfWork.FindDatabaseApi(dbContextKey);
//当前没有db创建一个新的db
// 当前没有数据库API则创建新的
if (databaseApi == null)
{
//db根据连接字符串来创建
databaseApi = new SqlSugarDatabaseApi(
await CreateDbContextAsync(unitOfWork, connectionStringName, connectionString)
await CreateDbContextAsync(unitOfWork, connectionStringName, connectionString)
);
//await Console.Out.WriteLineAsync(">>>----------------实例化了db"+ ((SqlSugarDatabaseApi)databaseApi).DbContext.SqlSugarClient.ContextID.ToString());
//创建的db加入到当前工作单元中
unitOfWork.AddDatabaseApi(dbContextKey, databaseApi);
}
return (TDbContext)((SqlSugarDatabaseApi)databaseApi).DbContext;
}
protected virtual async Task<TDbContext> CreateDbContextAsync(IUnitOfWork unitOfWork, string connectionStringName, string connectionString)
/// <summary>
/// 创建数据库上下文
/// </summary>
protected virtual async Task<TDbContext> CreateDbContextAsync(
IUnitOfWork unitOfWork,
string connectionStringName,
string connectionString)
{
var creationContext = new SqlSugarDbContextCreationContext(connectionStringName, connectionString);
//将连接key进行传值
using (SqlSugarDbContextCreationContext.Use(creationContext))
{
var dbContext = await CreateDbContextAsync(unitOfWork);
return dbContext;
return await CreateDbContextAsync(unitOfWork);
}
}
/// <summary>
/// 根据工作单元创建数据库上下文
/// </summary>
protected virtual async Task<TDbContext> CreateDbContextAsync(IUnitOfWork unitOfWork)
{
return unitOfWork.Options.IsTransactional
? await CreateDbContextWithTransactionAsync(unitOfWork)
: unitOfWork.ServiceProvider.GetRequiredService<TDbContext>();
}
/// <summary>
/// 创建带事务的数据库上下文
/// </summary>
protected virtual async Task<TDbContext> CreateDbContextWithTransactionAsync(IUnitOfWork unitOfWork)
{
//事务key
var transactionApiKey = $"SqlsugarCore_{SqlSugarDbContextCreationContext.Current.ConnectionString}";
//尝试查找事务
var transactionApiKey = $"SqlSugarCore_{SqlSugarDbContextCreationContext.Current.ConnectionString}";
var activeTransaction = unitOfWork.FindTransactionApi(transactionApiKey) as SqlSugarTransactionApi;
//该db还没有进行开启事务
if (activeTransaction == null)
{
//获取到db添加事务即可
var dbContext = unitOfWork.ServiceProvider.GetRequiredService<TDbContext>();
var transaction = new SqlSugarTransactionApi(
dbContext
);
var transaction = new SqlSugarTransactionApi(dbContext);
unitOfWork.AddTransactionApi(transactionApiKey, transaction);
await dbContext.SqlSugarClient.Ado.BeginTranAsync();
return dbContext;
}
else
{
return (TDbContext)activeTransaction.GetDbContext();
}
return (TDbContext)activeTransaction.GetDbContext();
}
protected virtual async Task<string> ResolveConnectionStringAsync(string connectionStringName)
{
if (typeof(TDbContext).IsDefined(typeof(IgnoreMultiTenancyAttribute), false))
{
using (CurrentTenant.Change(null))
{
return await ConnectionStringResolver.ResolveAsync(connectionStringName);
}
}
return await ConnectionStringResolver.ResolveAsync(connectionStringName);
}
}
}

View File

@@ -10,130 +10,185 @@ using Volo.Abp.Data;
using Volo.Abp.Domain;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;
using Volo.Abp.MultiTenancy.ConfigurationStore;
using Yi.Framework.SqlSugarCore.Abstractions;
using Yi.Framework.SqlSugarCore.Repositories;
using Yi.Framework.SqlSugarCore.Uow;
namespace Yi.Framework.SqlSugarCore
{
/// <summary>
/// SqlSugar Core模块
/// </summary>
[DependsOn(typeof(AbpDddDomainModule))]
public class YiFrameworkSqlSugarCoreModule : AbpModule
{
public override Task ConfigureServicesAsync(ServiceConfigurationContext context)
{
var service = context.Services;
var configuration = service.GetConfiguration();
var services = context.Services;
var configuration = services.GetConfiguration();
// 配置数据库连接选项
ConfigureDbOptions(services, configuration);
// 配置GUID生成器
ConfigureGuidGenerator(services);
// 注册仓储和服务
RegisterRepositories(services);
return Task.CompletedTask;
}
private void ConfigureDbOptions(IServiceCollection services, IConfiguration configuration)
{
var section = configuration.GetSection("DbConnOptions");
Configure<DbConnOptions>(section);
var dbConnOptions = new DbConnOptions();
section.Bind(dbConnOptions);
//很多人遗漏了这一点,不同的数据库,对于主键的使用规约不一样,需要根据数据库进行判断
SequentialGuidType guidType;
switch (dbConnOptions.DbType)
{
case DbType.MySql:
case DbType.PostgreSQL:
guidType= SequentialGuidType.SequentialAsString;
break;
case DbType.SqlServer:
guidType = SequentialGuidType.SequentialAtEnd;
break;
case DbType.Oracle:
guidType = SequentialGuidType.SequentialAsBinary;
break;
default:
guidType = SequentialGuidType.SequentialAtEnd;
break;
}
// 配置默认连接字符串
Configure<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = dbConnOptions.Url;
});
// 配置默认租户
ConfigureDefaultTenant(services, dbConnOptions);
}
private void ConfigureGuidGenerator(IServiceCollection services)
{
var dbConnOptions = services.GetConfiguration()
.GetSection("DbConnOptions")
.Get<DbConnOptions>();
var guidType = GetSequentialGuidType(dbConnOptions?.DbType);
Configure<AbpSequentialGuidGeneratorOptions>(options =>
{
options.DefaultSequentialGuidType = guidType;
});
service.TryAddScoped<ISqlSugarDbContext, SqlSugarDbContextFactory>();
//不开放sqlsugarClient
//service.AddTransient<ISqlSugarClient>(x => x.GetRequiredService<ISqlsugarDbContext>().SqlSugarClient);
service.AddTransient(typeof(IRepository<>), typeof(SqlSugarRepository<>));
service.AddTransient(typeof(IRepository<,>), typeof(SqlSugarRepository<,>));
service.AddTransient(typeof(ISqlSugarRepository<>), typeof(SqlSugarRepository<>));
service.AddTransient(typeof(ISqlSugarRepository<,>), typeof(SqlSugarRepository<,>));
service.AddTransient(typeof(ISugarDbContextProvider<>), typeof(UnitOfWorkSqlsugarDbContextProvider<>));
//替换Sqlsugar默认序列化器用来解决.Select()不支持嵌套对象/匿名对象的非公有访问器 值无法绑定,如Id属性
context.Services.AddSingleton<ISerializeService, SqlSugarNonPublicSerializer>();
var dbConfig = section.Get<DbConnOptions>();
//将默认db传递给abp连接字符串模块
Configure<AbpDbConnectionOptions>(x => { x.ConnectionStrings.Default = dbConfig.Url; });
context.Services.AddYiDbContext<DefaultSqlSugarDbContext>();
return Task.CompletedTask;
}
private void RegisterRepositories(IServiceCollection services)
{
services.TryAddTransient<ISqlSugarDbContext, SqlSugarDbContextFactory>();
services.AddTransient(typeof(IRepository<>), typeof(SqlSugarRepository<>));
services.AddTransient(typeof(IRepository<,>), typeof(SqlSugarRepository<,>));
services.AddTransient(typeof(ISqlSugarRepository<>), typeof(SqlSugarRepository<>));
services.AddTransient(typeof(ISqlSugarRepository<,>), typeof(SqlSugarRepository<,>));
services.AddTransient(typeof(ISugarDbContextProvider<>), typeof(UnitOfWorkSqlsugarDbContextProvider<>));
services.AddSingleton<ISerializeService, SqlSugarNonPublicSerializer>();
services.AddYiDbContext<DefaultSqlSugarDbContext>();
}
private void ConfigureDefaultTenant(IServiceCollection services, DbConnOptions dbConfig)
{
Configure<AbpDefaultTenantStoreOptions>(options =>
{
var tenants = options.Tenants.ToList();
// 规范化租户名称
foreach (var tenant in tenants)
{
tenant.NormalizedName = tenant.Name.Contains("@")
? tenant.Name.Substring(0, tenant.Name.LastIndexOf("@"))
: tenant.Name;
}
// 添加默认租户
tenants.Insert(0, new TenantConfiguration
{
Id = Guid.Empty,
Name = ConnectionStrings.DefaultConnectionStringName,
NormalizedName = ConnectionStrings.DefaultConnectionStringName,
ConnectionStrings = new ConnectionStrings
{
{ ConnectionStrings.DefaultConnectionStringName, dbConfig.Url }
},
IsActive = true
});
options.Tenants = tenants.ToArray();
});
}
private SequentialGuidType GetSequentialGuidType(DbType? dbType)
{
return dbType switch
{
DbType.MySql or DbType.PostgreSQL => SequentialGuidType.SequentialAsString,
DbType.SqlServer => SequentialGuidType.SequentialAtEnd,
DbType.Oracle => SequentialGuidType.SequentialAsBinary,
_ => SequentialGuidType.SequentialAtEnd
};
}
public override async Task OnPreApplicationInitializationAsync(ApplicationInitializationContext context)
{
//进行CodeFirst
var service = context.ServiceProvider;
var options = service.GetRequiredService<IOptions<DbConnOptions>>().Value;
var serviceProvider = context.ServiceProvider;
var options = serviceProvider.GetRequiredService<IOptions<DbConnOptions>>().Value;
var logger = serviceProvider.GetRequiredService<ILogger<YiFrameworkSqlSugarCoreModule>>();
var logger = service.GetRequiredService<ILogger<YiFrameworkSqlSugarCoreModule>>();
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("==========Yi-SQL配置:==========");
sb.AppendLine($"数据库连接字符串:{options.Url}");
sb.AppendLine($"数据库类型:{options.DbType.ToString()}");
sb.AppendLine($"是否开启种子数据:{options.EnabledDbSeed}");
sb.AppendLine($"是否开启CodeFirst{options.EnabledCodeFirst}");
sb.AppendLine($"是否开启Saas多租户{options.EnabledSaasMultiTenancy}");
sb.AppendLine("===============================");
logger.LogInformation(sb.ToString());
// 记录配置信息
LogConfiguration(logger, options);
// 初始化数据库
if (options.EnabledCodeFirst)
{
CodeFirst(service);
await InitializeDatabase(serviceProvider);
}
// 初始化种子数据
if (options.EnabledDbSeed)
{
await DataSeedAsync(service);
await InitializeSeedData(serviceProvider);
}
}
private void CodeFirst(IServiceProvider service)
private void LogConfiguration(ILogger logger, DbConnOptions options)
{
var moduleContainer = service.GetRequiredService<IModuleContainer>();
var db = service.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient;
var logMessage = new StringBuilder()
.AppendLine()
.AppendLine("==========Yi-SQL配置:==========")
.AppendLine($"数据库连接字符串:{options.Url}")
.AppendLine($"数据库类型:{options.DbType}")
.AppendLine($"是否开启种子数据:{options.EnabledDbSeed}")
.AppendLine($"是否开启CodeFirst{options.EnabledCodeFirst}")
.AppendLine($"是否开启Saas多租户{options.EnabledSaasMultiTenancy}")
.AppendLine("===============================")
.ToString();
//尝试创建数据库
logger.LogInformation(logMessage);
}
private async Task InitializeDatabase(IServiceProvider serviceProvider)
{
var moduleContainer = serviceProvider.GetRequiredService<IModuleContainer>();
var db = serviceProvider.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient;
// 创建数据库
db.DbMaintenance.CreateDatabase();
List<Type> types = new List<Type>();
foreach (var module in moduleContainer.Modules)
{
types.AddRange(module.Assembly.GetTypes()
.Where(x => x.GetCustomAttribute<IgnoreCodeFirstAttribute>() == null)
.Where(x => x.GetCustomAttribute<SugarTable>() != null)
.Where(x => x.GetCustomAttribute<SplitTableAttribute>() is null));
}
// 获取需要创建表的实体类型
var entityTypes = moduleContainer.Modules
.SelectMany(m => m.Assembly.GetTypes())
.Where(t => t.GetCustomAttribute<IgnoreCodeFirstAttribute>() == null
&& t.GetCustomAttribute<SugarTable>() != null
&& t.GetCustomAttribute<SplitTableAttribute>() == null)
.ToList();
if (types.Count > 0)
if (entityTypes.Any())
{
db.CopyNew().CodeFirst.InitTables(types.ToArray());
db.CopyNew().CodeFirst.InitTables(entityTypes.ToArray());
}
}
private async Task DataSeedAsync(IServiceProvider service)
private async Task InitializeSeedData(IServiceProvider serviceProvider)
{
var dataSeeder = service.GetRequiredService<IDataSeeder>();
var dataSeeder = serviceProvider.GetRequiredService<IDataSeeder>();
await dataSeeder.SeedAsync();
}
}

View File

@@ -0,0 +1,21 @@
using Yi.Framework.Rbac.Domain.Shared.Dtos;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
public class AiUserRoleMenuDto:UserRoleMenuDto
{
/// <summary>
/// 是否绑定服务号
/// </summary>
public bool IsBindFuwuhao { get; set; }
/// <summary>
/// 是否为VIP用户
/// </summary>
public bool IsVip { get; set; }
/// <summary>
/// VIP到期时间
/// </summary>
public DateTime? VipExpireTime { get; set; }
}

View File

@@ -0,0 +1,22 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement;
/// <summary>
/// 公告缓存 DTO
/// </summary>
public class AnnouncementCacheDto
{
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; } = string.Empty;
/// <summary>
/// 公告日志列表
/// </summary>
public List<AnnouncementLogDto> Logs { get; set; } = new List<AnnouncementLogDto>();
/// <summary>
/// 跳转链接
/// </summary>
public string? Url { get; set; }
}

View File

@@ -0,0 +1,44 @@
using Yi.Framework.AiHub.Domain.Shared.Enums;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement;
/// <summary>
/// 公告日志 DTO
/// </summary>
public class AnnouncementLogDto
{
/// <summary>
/// 标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 内容列表
/// </summary>
public List<string> Content { get; set; } = new List<string>();
/// <summary>
/// 图片url
/// </summary>
public string? ImageUrl { get; set; }
/// <summary>
/// 开始时间(系统公告时间、活动开始时间)
/// </summary>
public DateTime StartTime { get; set; }
/// <summary>
/// 活动结束时间
/// </summary>
public DateTime? EndTime { get; set; }
/// <summary>
/// 公告类型(系统、活动)
/// </summary>
public AnnouncementTypeEnum Type{ get; set; }
/// <summary>
/// 跳转链接
/// </summary>
public string? Url { get; set; }
}

View File

@@ -0,0 +1,17 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Announcement;
/// <summary>
/// 公告输出 DTO
/// </summary>
public class AnnouncementOutput
{
/// <summary>
/// 版本号
/// </summary>
public string Version { get; set; } = string.Empty;
/// <summary>
/// 公告日志列表
/// </summary>
public List<AnnouncementLogDto> Logs { get; set; } = new List<AnnouncementLogDto>();
}

View File

@@ -0,0 +1,93 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
/// <summary>
/// 翻牌任务状态输出
/// </summary>
public class CardFlipStatusOutput
{
/// <summary>
/// 本周总翻牌次数
/// </summary>
public int TotalFlips { get; set; }
/// <summary>
/// 剩余免费次数
/// </summary>
public int RemainingFreeFlips { get; set; }
/// <summary>
/// 剩余赠送次数
/// </summary>
public int RemainingBonusFlips { get; set; }
/// <summary>
/// 剩余邀请解锁次数
/// </summary>
public int RemainingInviteFlips { get; set; }
/// <summary>
/// 是否可以翻牌
/// </summary>
public bool CanFlip { get; set; }
/// <summary>
/// 用户的邀请码
/// </summary>
public string? MyInviteCode { get; set; }
/// <summary>
/// 本周邀请人数
/// </summary>
public int InvitedCount { get; set; }
/// <summary>
/// 翻牌记录
/// </summary>
public List<CardFlipRecord> FlipRecords { get; set; } = new();
/// <summary>
/// 下次可翻牌提示
/// </summary>
public string? NextFlipTip { get; set; }
/// <summary>
/// 当前用户是否已经填写过邀请码
/// </summary>
public bool IsFilledInviteCode { get; set; }
}
/// <summary>
/// 翻牌记录
/// </summary>
public class CardFlipRecord
{
/// <summary>
/// 翻牌序号1-10
/// </summary>
public int FlipNumber { get; set; }
/// <summary>
/// 是否已翻
/// </summary>
public bool IsFlipped { get; set; }
/// <summary>
/// 是否中奖
/// </summary>
public bool IsWin { get; set; }
/// <summary>
/// 奖励金额token数
/// </summary>
public long? RewardAmount { get; set; }
/// <summary>
/// 翻牌类型描述
/// </summary>
public string? FlipTypeDesc { get; set; }
/// <summary>
/// 在翻牌顺序中的位置1-10表示第几个翻
/// </summary>
public int FlipOrderIndex { get; set; }
}

View File

@@ -0,0 +1,12 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
/// <summary>
/// 翻牌输入
/// </summary>
public class FlipCardInput
{
/// <summary>
/// 翻牌序号1-10
/// </summary>
public int FlipNumber { get; set; }
}

View File

@@ -0,0 +1,32 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
/// <summary>
/// 翻牌输出
/// </summary>
public class FlipCardOutput
{
/// <summary>
/// 翻牌序号1-10
/// </summary>
public int FlipNumber { get; set; }
/// <summary>
/// 是否中奖
/// </summary>
public bool IsWin { get; set; }
/// <summary>
/// 奖励金额token数
/// </summary>
public long? RewardAmount { get; set; }
/// <summary>
/// 奖励描述
/// </summary>
public string? RewardDesc { get; set; }
/// <summary>
/// 剩余可翻次数
/// </summary>
public int RemainingFlips { get; set; }
}

View File

@@ -0,0 +1,48 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
/// <summary>
/// 邀请码信息输出
/// </summary>
public class InviteCodeOutput
{
/// <summary>
/// 我的邀请码
/// </summary>
public string? MyInviteCode { get; set; }
/// <summary>
/// 本周邀请人数
/// </summary>
public int InvitedCount { get; set; }
/// <summary>
/// 是否已被邀请
/// </summary>
public bool IsInvited { get; set; }
/// <summary>
/// 邀请历史记录
/// </summary>
public List<InvitationHistoryItem> InvitationHistory { get; set; } = new();
}
/// <summary>
/// 邀请历史记录项
/// </summary>
public class InvitationHistoryItem
{
/// <summary>
/// 被邀请人昵称(脱敏)
/// </summary>
public string InvitedUserName { get; set; } = string.Empty;
/// <summary>
/// 邀请时间
/// </summary>
public DateTime InvitationTime { get; set; }
/// <summary>
/// 本周所在
/// </summary>
public string WeekDescription { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,12 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
/// <summary>
/// 使用邀请码输入
/// </summary>
public class UseInviteCodeInput
{
/// <summary>
/// 邀请码
/// </summary>
public string InviteCode { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,12 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.DailyTask;
/// <summary>
/// 领取任务奖励输入
/// </summary>
public class ClaimTaskRewardInput
{
/// <summary>
/// 任务等级1=1000w任务2=3000w任务
/// </summary>
public int TaskLevel { get; set; }
}

View File

@@ -0,0 +1,58 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.DailyTask;
/// <summary>
/// 每日任务状态输出
/// </summary>
public class DailyTaskStatusOutput
{
/// <summary>
/// 今日消耗的尊享包Token数
/// </summary>
public long TodayConsumedTokens { get; set; }
/// <summary>
/// 任务列表
/// </summary>
public List<DailyTaskItem> Tasks { get; set; } = new();
}
/// <summary>
/// 每日任务项
/// </summary>
public class DailyTaskItem
{
/// <summary>
/// 任务等级1=1000w任务2=3000w任务
/// </summary>
public int Level { get; set; }
/// <summary>
/// 任务名称
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// 任务描述
/// </summary>
public string Description { get; set; } = string.Empty;
/// <summary>
/// 任务要求的Token消耗量
/// </summary>
public long RequiredTokens { get; set; }
/// <summary>
/// 奖励的Token数量
/// </summary>
public long RewardTokens { get; set; }
/// <summary>
/// 任务状态0=未完成1=可领取2=已领取
/// </summary>
public int Status { get; set; }
/// <summary>
/// 任务进度百分比0-100
/// </summary>
public decimal Progress { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.FileMaster;
public class VerifyNextInput
{
/// <summary>
/// 文件数
/// </summary>
public int FileCount { get; set; }
/// <summary>
/// 文件夹数
/// </summary>
public int DirectoryCount { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Fuwuhao;
public class QrCodeOutput
{
/// <summary>
/// Qrcode url
/// </summary>
public string QrCodeUrl { get; set; }
/// <summary>
/// 场景值
/// </summary>
public string Scene { get; set; }
}

View File

@@ -0,0 +1,21 @@
using Yi.Framework.AiHub.Domain.Shared.Enums.Fuwuhao;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Fuwuhao;
public class QrCodeResultOutput
{
/// <summary>
/// 返回状态
/// </summary>
public SceneResultEnum SceneResult { get; set; } = SceneResultEnum.Wait;
/// <summary>
/// 如果是已登录返回token
/// </summary>
public string? Token { get; set; }
/// <summary>
/// 刷新token
/// </summary>
public string? RefreshToken { get; set; }
}

View File

@@ -0,0 +1,16 @@
using Yi.Framework.AiHub.Domain.Shared.Enums.Fuwuhao;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Fuwuhao;
public class SceneCacheDto
{
public SceneResultEnum SceneResult { get; set; } = SceneResultEnum.Wait;
public SceneTypeEnum SceneType { get; set; }
/// <summary>
/// 如果是绑定类型需要用户id
/// </summary>
public Guid? UserId { get; set; }
}

View File

@@ -0,0 +1,13 @@
using Volo.Abp.Application.Dtos;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
public class MessageDto : FullAuditedEntityDto<Guid>
{
public Guid UserId { get; set; }
public Guid SessionId { get; set; }
public string Content { get; set; }
public string Role { get; set; }
public string ModelId { get; set; }
public string Remark { get; set; }
}

View File

@@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
using Yi.Framework.Ddd.Application.Contracts;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
public class MessageGetListInput:PagedAllResultRequestDto
{
[Required]
public Guid SessionId { get; set; }
}

View File

@@ -0,0 +1,65 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
public class ModelGetListOutput
{
/// <summary>
/// 模型ID
/// </summary>
public Guid Id { get; set; }
/// <summary>
/// 模型分类
/// </summary>
public string Category { get; set; }
/// <summary>
/// 模型id
/// </summary>
public string ModelId { get; set; }
/// <summary>
/// 模型名称
/// </summary>
public string ModelName { get; set; }
/// <summary>
/// 模型描述
/// </summary>
public string? ModelDescribe { get; set; }
/// <summary>
/// 模型价格
/// </summary>
public double ModelPrice { get; set; }
/// <summary>
/// 模型类型
/// </summary>
public string ModelType { get; set; }
/// <summary>
/// 模型展示状态
/// </summary>
public string ModelShow { get; set; }
/// <summary>
/// 系统提示
/// </summary>
public string SystemPrompt { get; set; }
/// <summary>
/// API 主机地址
/// </summary>
public string ApiHost { get; set; }
/// <summary>
/// API 密钥
/// </summary>
public string ApiKey { get; set; }
/// <summary>
/// 备注信息
/// </summary>
public string? Remark { get; set; }
}

View File

@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
using Yi.Framework.AiHub.Domain.Shared.Enums;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
/// <summary>
/// 创建订单输入DTO
/// </summary>
public class CreateOrderInput
{
/// <summary>
/// 商品类型
/// </summary>
[Required]
public GoodsTypeEnum GoodsType { get; set; }
public string? ReturnUrl{ get; set; }
}

View File

@@ -0,0 +1,22 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
/// <summary>
/// 创建订单输出DTO
/// </summary>
public class CreateOrderOutput
{
/// <summary>
/// 订单ID
/// </summary>
public Guid OrderId { get; set; }
/// <summary>
/// 商家订单号
/// </summary>
public string OutTradeNo { get; set; }
/// <summary>
/// 支付页面HTML内容
/// </summary>
public object PaymentPageHtml { get; set; }
}

View File

@@ -0,0 +1,16 @@
using Yi.Framework.AiHub.Domain.Shared.Enums;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
/// <summary>
/// 获取商品列表输入DTO
/// </summary>
public class GetGoodsListInput
{
/// <summary>
/// 商品类别(可选)
/// 如果不传,则返回所有商品
/// 如果传了则只返回指定类别的商品VIP服务或尊享包
/// </summary>
public GoodsCategoryType? GoodsCategoryType { get; set; }
}

View File

@@ -0,0 +1,55 @@
using Yi.Framework.AiHub.Domain.Shared.Enums;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
/// <summary>
/// 商品列表输出DTO
/// </summary>
public class GoodsListOutput
{
/// <summary>
/// 商品名称
/// </summary>
public string GoodsName { get; set; }
/// <summary>
/// 商品原价
/// </summary>
public decimal OriginalPrice { get; set; }
/// <summary>
/// 商品参考价格
/// </summary>
public decimal ReferencePrice { get; set; }
/// <summary>
/// 商品实际价格(折扣后的价格)
/// </summary>
public decimal GoodsPrice { get; set; }
/// <summary>
/// 折扣金额(仅尊享包)
/// </summary>
public decimal? DiscountAmount { get; set; }
/// <summary>
/// 商品类别
/// </summary>
public string GoodsCategory { get; set; }
/// <summary>
/// 商品备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 折扣说明(仅尊享包)
/// </summary>
public string? DiscountDescription { get; set; }
/// <summary>
/// 商品类型
/// </summary>
public GoodsTypeEnum GoodsType { get; set; }
}

View File

@@ -0,0 +1,12 @@
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.Pay;
/// <summary>
/// 查询订单状态输入DTO
/// </summary>
public class QueryOrderStatusInput
{
/// <summary>
/// 商家订单号
/// </summary>
public string OutTradeNo { get; set; }
}

Some files were not shown because too many files have changed in this diff Show More