From b4de38fbb964945566edf39d67abbf1404ceca3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Mon, 12 Aug 2024 19:43:30 +0800 Subject: [PATCH 01/11] =?UTF-8?q?feat:=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.Bbs.Vue3/src/views/money/Index.vue | 113 ++++++++++++++++++ .../views/money/components/AwardPedestal.vue | 92 ++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 Yi.Bbs.Vue3/src/views/money/Index.vue create mode 100644 Yi.Bbs.Vue3/src/views/money/components/AwardPedestal.vue diff --git a/Yi.Bbs.Vue3/src/views/money/Index.vue b/Yi.Bbs.Vue3/src/views/money/Index.vue new file mode 100644 index 00000000..5284f2ca --- /dev/null +++ b/Yi.Bbs.Vue3/src/views/money/Index.vue @@ -0,0 +1,113 @@ + + + + + + + + {{ item.order }} + + + {{ item.money }} + + + + 关注 + + + + + + + diff --git a/Yi.Bbs.Vue3/src/views/money/components/AwardPedestal.vue b/Yi.Bbs.Vue3/src/views/money/components/AwardPedestal.vue new file mode 100644 index 00000000..b63db5b5 --- /dev/null +++ b/Yi.Bbs.Vue3/src/views/money/components/AwardPedestal.vue @@ -0,0 +1,92 @@ + + + + + + + 第二 + {{ silverUserInfo?.money }} + + + + + + + 第一 + {{ goldUserInfo?.money }} + + + + + + + 第三 + {{ bronzeUserInfo?.money }} + + + + + \ No newline at end of file From c122863e45316fcf2cd38df9eb63d319bda6a740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Mon, 12 Aug 2024 20:05:42 +0800 Subject: [PATCH 02/11] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=AD=89?= =?UTF-8?q?=E7=BA=A7=E6=8E=92=E5=BA=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Managers/LevelManager.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/LevelManager.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/LevelManager.cs index fb9e9806..a9a3ec5f 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/LevelManager.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/LevelManager.cs @@ -19,8 +19,10 @@ namespace Yi.Framework.Bbs.Domain.Managers private IDistributedCache> _levelCache; private IRepository _repository; private ISqlSugarRepository _bbsUserRepository; - public LevelManager( ILocalEventBus localEventBus, - IDistributedCache> levelCache, IRepository repository, ISqlSugarRepository bbsUserRepository) + + public LevelManager(ILocalEventBus localEventBus, + IDistributedCache> levelCache, IRepository repository, + ISqlSugarRepository bbsUserRepository) { _localEventBus = localEventBus; _repository = repository; @@ -35,16 +37,16 @@ namespace Yi.Framework.Bbs.Domain.Managers /// public async Task> GetCacheMapAsync() { - var items = _levelCache.GetOrAdd(LevelConst.LevelCacheKey, () => + var items = _levelCache.GetOrAdd(LevelConst.LevelCacheKey, () => { - var cacheItem = ( _repository.GetListAsync().Result) + var cacheItem = (_repository.GetListAsync().Result) .OrderByDescending(x => x.CurrentLevel).ToList() .Adapt>(); return cacheItem; }); - return items.ToDictionary(x=>x.CurrentLevel); + return items.ToDictionary(x => x.CurrentLevel); } - + /// /// 使用钱钱投喂等级 /// @@ -52,7 +54,7 @@ namespace Yi.Framework.Bbs.Domain.Managers public async Task ChangeLevelByMoneyAsync(Guid userId, int moneyNumber) { //通过用户id获取用户信息的经验和等级 - var userInfo = await _bbsUserRepository.GetAsync(x=>x.UserId==userId); + var userInfo = await _bbsUserRepository.GetAsync(x => x.UserId == userId); //钱钱和经验的比例为1:1 //根据钱钱修改经验 @@ -63,7 +65,7 @@ namespace Yi.Framework.Bbs.Domain.Managers false); //更改最终的经验再变化等级 - var levelList = (await GetCacheMapAsync()).Values; + var levelList = (await GetCacheMapAsync()).Values.OrderByDescending(x => x.CurrentLevel); var currentNewLevel = 1; foreach (var level in levelList) { @@ -73,12 +75,12 @@ namespace Yi.Framework.Bbs.Domain.Managers break; } } - + //这里注意,只更新等级 userInfo.Level = currentNewLevel; userInfo.Experience = currentNewExperience; await _bbsUserRepository._Db.Updateable(userInfo) - .UpdateColumns(it => new { it.Level,it.Experience }) + .UpdateColumns(it => new { it.Level, it.Experience }) .ExecuteCommandAsync(); } } From 9530350d0665a5fd4304a12819f6b60055bf0433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Mon, 12 Aug 2024 23:23:29 +0800 Subject: [PATCH 03/11] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AssignmentDefineGetListOutputDto.cs | 39 +++++++++++++++++ .../Dtos/Assignment/AssignmentGetListInput.cs | 16 +++++++ .../Assignment/AssignmentGetListOutputDto.cs | 30 +++++++++++++ .../Services/AssignmentService.cs | 42 +++++++++++++++---- .../Managers/AssignmentManager.cs | 7 ++-- .../AssignmentProviders/Impl/DailyProvider.cs | 4 +- .../Impl/NoviceProvider.cs | 7 ++-- .../Impl/WeeklyProvider.cs | 4 +- Yi.Bbs.Vue3/src/apis/assignmentApi.js | 33 +++++++++++++++ Yi.Bbs.Vue3/src/router/index.js | 8 ++++ Yi.Bbs.Vue3/src/views/assignment/Index.vue | 18 ++++++++ 11 files changed, 190 insertions(+), 18 deletions(-) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentDefineGetListOutputDto.cs create mode 100644 Yi.Bbs.Vue3/src/apis/assignmentApi.js create mode 100644 Yi.Bbs.Vue3/src/views/assignment/Index.vue diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentDefineGetListOutputDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentDefineGetListOutputDto.cs new file mode 100644 index 00000000..e3a9effc --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentDefineGetListOutputDto.cs @@ -0,0 +1,39 @@ +using Volo.Abp.Application.Dtos; +using Yi.Framework.Bbs.Domain.Shared.Enums; + +namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment; + +public class AssignmentDefineGetListOutputDto : EntityDto +{ + /// + /// 任务名称 + /// + public string Name { get; set; } + + /// + /// 备注 + /// + public string Remarks { get; set; } + + /// + /// 任务类型 + /// + public AssignmentTypeEnum AssignmentType { get; set; } + + /// + /// 总共步骤数 + /// + public int TotalStepNumber { get; set; } + + /// + /// 前置任务id + /// + public Guid? PreAssignmentId { get; set; } + + /// + /// 任务奖励的钱钱数量 + /// + public decimal RewardsMoneyNumber { get; set; } + + public int OrderNum { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListInput.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListInput.cs index 4a0c8910..e999dcd8 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListInput.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListInput.cs @@ -4,5 +4,21 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment; public class AssignmentGetListInput { + /// + /// 任务查询条件 + /// + public AssignmentQueryStateEnum? AssignmentQueryState { get; set; } +} + +public enum AssignmentQueryStateEnum +{ + /// + /// 正在进行 + /// + Progress, + /// + /// 已结束 + /// + End } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs index 27f02734..6a0026ea 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs @@ -1,8 +1,38 @@ using Volo.Abp.Application.Dtos; +using Yi.Framework.Bbs.Domain.Shared.Enums; namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment; public class AssignmentGetListOutputDto:EntityDto { + /// + /// 当前步骤数 + /// + public int CurrentStepNumber { get; set; } + + /// + /// 总共步骤数 + /// + public int TotalStepNumber { get; set; } + + /// + /// 任务状态 + /// + public AssignmentStateEnum AssignmentState { get; set; } + + /// + /// 任务奖励的钱钱数量 + /// + public decimal RewardsMoneyNumber { get; set; } + /// + /// 任务过期时间 + /// + public DateTime? ExpireTime { get; set; } + + public DateTime? CompleteTime { get; set; } + + + public DateTime CreationTime { get; } + public int OrderNum { get; set; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs index d276e478..85f5db7c 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs @@ -1,10 +1,11 @@ -using Microsoft.AspNetCore.Authorization; +using Mapster; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Users; using Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment; using Yi.Framework.Bbs.Domain.Managers; +using Yi.Framework.Bbs.Domain.Shared.Enums; namespace Yi.Framework.Bbs.Application.Services; @@ -26,26 +27,49 @@ public class AssignmentService : ApplicationService /// /// [HttpPost("assignment/accept/{id}")] - public async Task AcceptAsync(Guid id) + public async Task AcceptAsync([FromRoute]Guid id) { await _assignmentManager.AcceptAsync(CurrentUser.GetId(), id); } /// - /// 接收任务奖励 + /// 领取任务奖励 /// /// - [HttpPost("assignment/receive-rewards/{id}")] - public async Task ReceiveRewardsAsync(Guid id) + [HttpPost("assignment/complete/{id}")] + public async Task ReceiveRewardsAsync([FromRoute]Guid id) { await _assignmentManager.ReceiveRewardsAsync(id); } /// - /// 查询任务 + /// 查看可接受的任务 /// - public async Task> GetListAsync(AssignmentGetListInput input) + /// + [HttpGet("assignment/receive")] + public async Task> GetCanReceiveListAsync() { - throw new NotImplementedException(); + var entities = await _assignmentManager.GetCanReceiveListAsync(CurrentUser.GetId()); + var output = entities.Adapt>(); + return output; + } + + /// + /// 查询接受的任务 + /// + [HttpGet("assignment")] + public async Task> GetListAsync([FromQuery]AssignmentGetListInput input) + { + var entities= await _assignmentManager._assignmentRepository._DbQueryable + .Where(x => x.UserId == CurrentUser.GetId()) + .WhereIF(input.AssignmentQueryState == AssignmentQueryStateEnum.Progress, + x => x.AssignmentState == AssignmentStateEnum.Progress) + .WhereIF(input.AssignmentQueryState == AssignmentQueryStateEnum.End, + x => x.AssignmentState == AssignmentStateEnum.Completed || + x.AssignmentState == AssignmentStateEnum.Expired) + .ToListAsync(); + + var output= entities.Adapt>(); + return output; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs index 8ab3e89c..02b5fead 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs @@ -16,8 +16,8 @@ namespace Yi.Framework.Bbs.Domain.Managers; public class AssignmentManager : DomainService { private readonly IEnumerable _assignmentProviders; - private readonly ISqlSugarRepository _assignmentRepository; - private readonly ISqlSugarRepository _assignmentDefineRepository; + public readonly ISqlSugarRepository _assignmentRepository; + public readonly ISqlSugarRepository _assignmentDefineRepository; private readonly ILocalEventBus _localEventBus; public AssignmentManager(IEnumerable assignmentProviders, @@ -92,7 +92,7 @@ public class AssignmentManager : DomainService } output.DistinctBy(x => x.Id); - throw new NotImplementedException(); + return output; } @@ -134,6 +134,5 @@ public class AssignmentManager : DomainService { await _assignmentRepository._Db.Updateable(needUpdateEntities).ExecuteCommandAsync(); } - } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/DailyProvider.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/DailyProvider.cs index a51477a3..e5f7d33b 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/DailyProvider.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/DailyProvider.cs @@ -1,10 +1,12 @@ -using Yi.Framework.Bbs.Domain.Shared.Enums; +using Volo.Abp.DependencyInjection; +using Yi.Framework.Bbs.Domain.Shared.Enums; namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders; /// /// 每日任务提供者 /// +[ExposeServices(typeof(IAssignmentProvider))] public class DailyProvider : TimerProvider { protected override AssignmentTypeEnum AssignmentType => AssignmentTypeEnum.Daily; diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/NoviceProvider.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/NoviceProvider.cs index d4ff0a02..6b2052f8 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/NoviceProvider.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/NoviceProvider.cs @@ -5,11 +5,12 @@ namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders; /// /// 新手任务提供者 /// -public class NoviceProvider : IAssignmentProvider + public class NoviceProvider : IAssignmentProvider { - public Task> GetCanReceiveListAsync(AssignmentContext context) + public async Task> GetCanReceiveListAsync(AssignmentContext context) { //新手任务是要有前置依赖关系的,链表类型依赖 - throw new NotImplementedException(); + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/WeeklyProvider.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/WeeklyProvider.cs index 52d264d8..7ae3d6be 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/WeeklyProvider.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/Impl/WeeklyProvider.cs @@ -1,10 +1,12 @@ -using Yi.Framework.Bbs.Domain.Shared.Enums; +using Volo.Abp.DependencyInjection; +using Yi.Framework.Bbs.Domain.Shared.Enums; namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders; /// /// 每周任务提供者 /// +[ExposeServices(typeof(IAssignmentProvider))] public class WeeklyProvider : TimerProvider { protected override AssignmentTypeEnum AssignmentType => AssignmentTypeEnum.Weekly; diff --git a/Yi.Bbs.Vue3/src/apis/assignmentApi.js b/Yi.Bbs.Vue3/src/apis/assignmentApi.js new file mode 100644 index 00000000..50cc58f5 --- /dev/null +++ b/Yi.Bbs.Vue3/src/apis/assignmentApi.js @@ -0,0 +1,33 @@ +import request from "@/config/axios/service"; + +//接受任务 +export function acceptAssignment(id) { + return request({ + url: `/assignment/accept/${id}`, + method: "post" + }); +} +//领取奖励 +export function receiveAssignment(id) { + return request({ + url: `/assignment/complete/${id}`, + method: "post", + }); +} + +//查询能够领取的任务 +export function getCanReceiveAssignment() { + return request({ + url: `/assignment/receive`, + method: "get", + }); +} + +//查询已领取的任务 +export function getAssignmentList(data) { + return request({ + url: `/assignment`, + method: "get", + params:data + }); +} \ No newline at end of file diff --git a/Yi.Bbs.Vue3/src/router/index.js b/Yi.Bbs.Vue3/src/router/index.js index 9413c399..71e3020e 100644 --- a/Yi.Bbs.Vue3/src/router/index.js +++ b/Yi.Bbs.Vue3/src/router/index.js @@ -156,6 +156,14 @@ const router = createRouter({ title: "银行", }, }, + { + name: "assignment", + path: "assignment", + component: () => import("../views/assignment/Index.vue"), + meta: { + title: "任务", + }, + }, ], }, diff --git a/Yi.Bbs.Vue3/src/views/assignment/Index.vue b/Yi.Bbs.Vue3/src/views/assignment/Index.vue new file mode 100644 index 00000000..4c889bdc --- /dev/null +++ b/Yi.Bbs.Vue3/src/views/assignment/Index.vue @@ -0,0 +1,18 @@ + + + + + + {{item}} + + \ No newline at end of file From 35ebce6a854c6c4cd306ca0ae2b135009395f4a7 Mon Sep 17 00:00:00 2001 From: chenchun Date: Tue, 13 Aug 2024 15:33:03 +0800 Subject: [PATCH 04/11] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E9=9C=80=E6=B1=82=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Assignment/AssignmentGetListInput.cs | 2 +- .../Enums/AssignmentRequirementTypeEnum.cs | 26 +++++++++ .../Assignment/AssignmentAggregateRoot.cs | 13 ++++- .../AssignmentDefineAggregateRoot.cs | 7 ++- .../Managers/AssignmentManager.cs | 11 +++- Yi.Bbs.Vue3/src/views/assignment/Index.vue | 55 +++++++++++++++++-- 6 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentRequirementTypeEnum.cs diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListInput.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListInput.cs index e999dcd8..af308e36 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListInput.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListInput.cs @@ -7,7 +7,7 @@ public class AssignmentGetListInput /// /// 任务查询条件 /// - public AssignmentQueryStateEnum? AssignmentQueryState { get; set; } + public AssignmentQueryStateEnum AssignmentQueryState { get; set; } = AssignmentQueryStateEnum.Progress; } public enum AssignmentQueryStateEnum diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentRequirementTypeEnum.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentRequirementTypeEnum.cs new file mode 100644 index 00000000..04aef002 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentRequirementTypeEnum.cs @@ -0,0 +1,26 @@ +namespace Yi.Framework.Bbs.Domain.Shared.Enums; + +public enum AssignmentRequirementTypeEnum +{ + /// + /// 主题 + /// + Discuss=2, + + /// + /// 评论 + /// + Comment=4, + + /// + /// 更新个人中心 + /// + UpdateProfile=8, + + + /// + /// 点赞 + /// + Agree=16 + +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs index 8b59c859..cb8b6361 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs @@ -38,7 +38,7 @@ public class AssignmentAggregateRoot : AggregateRoot, IHasCreationTime, IO /// /// 任务状态 /// - public AssignmentStateEnum AssignmentState { get; set; } + public AssignmentStateEnum AssignmentState { get; set; } /// /// 任务奖励的钱钱数量 @@ -52,9 +52,9 @@ public class AssignmentAggregateRoot : AggregateRoot, IHasCreationTime, IO public DateTime? CompleteTime { get; set; } - public DateTime CreationTime { get; } + public DateTime CreationTime { get; set; } public int OrderNum { get; set; } - public DateTime? LastModificationTime { get; } + public DateTime? LastModificationTime{ get; set; } public bool IsAllowCompleted() @@ -72,4 +72,11 @@ public class AssignmentAggregateRoot : AggregateRoot, IHasCreationTime, IO return true; } + + public void SetComplete() + { + this.AssignmentState = AssignmentStateEnum.Completed; + this.CompleteTime=DateTime.Now; + + } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentDefineAggregateRoot.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentDefineAggregateRoot.cs index 72d44e8d..52d6aa9e 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentDefineAggregateRoot.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentDefineAggregateRoot.cs @@ -31,6 +31,11 @@ public class AssignmentDefineAggregateRoot: AggregateRoot, IHasCreationTim /// public AssignmentTypeEnum AssignmentType{ get; set; } + /// + /// 任务需求类型 + /// + public AssignmentRequirementTypeEnum AssignmentRequirementType{ get; set; } + /// /// 总共步骤数 /// @@ -46,6 +51,6 @@ public class AssignmentDefineAggregateRoot: AggregateRoot, IHasCreationTim /// public decimal RewardsMoneyNumber { get; set; } - public DateTime CreationTime { get; } + public DateTime CreationTime{ get; set; } public int OrderNum { get; set; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs index 02b5fead..58267821 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs @@ -68,11 +68,18 @@ public class AssignmentManager : DomainService var assignment = await _assignmentRepository.GetByIdAsync(asignmentId); if (assignment.IsAllowCompleted()) { - //设置已完成,并领取奖励,钱钱 - assignment.AssignmentState = AssignmentStateEnum.Completed; //加钱加钱 await _localEventBus.PublishAsync( new MoneyChangeEventArgs { UserId = assignment.UserId, Number = assignment.RewardsMoneyNumber }, false); + + //设置已完成,并领取奖励,钱钱 + assignment.SetComplete(); + await _assignmentRepository.UpdateAsync(assignment); + } + else + { + //不能领取 + throw new UserFriendlyException("该任务无法领取奖励,请检查任务详情"); } } diff --git a/Yi.Bbs.Vue3/src/views/assignment/Index.vue b/Yi.Bbs.Vue3/src/views/assignment/Index.vue index 4c889bdc..2dca2c09 100644 --- a/Yi.Bbs.Vue3/src/views/assignment/Index.vue +++ b/Yi.Bbs.Vue3/src/views/assignment/Index.vue @@ -1,18 +1,61 @@ - + + 可接收任务 - {{item}} + {{item}} + 接收任务 + + + + + 已接收任务 + 切换正在进行 + 切换已结束 + + {{item}} + 领取奖励 + \ No newline at end of file From 96b9cad2f822b4060887be6e1c5f257ceac1db95 Mon Sep 17 00:00:00 2001 From: chenchun Date: Tue, 13 Aug 2024 16:45:56 +0800 Subject: [PATCH 05/11] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E4=BD=93=E7=B3=BB=E6=90=AD=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AssignmentDefineGetListOutputDto.cs | 7 +- .../Assignment/AssignmentGetListOutputDto.cs | 17 +++- .../Services/AssignmentService.cs | 30 ++++--- .../Enums/AssignmentRequirementTypeEnum.cs | 16 ++-- .../Etos/AssignmentEventArgs.cs | 30 +++++++ .../Assignment/AssignmentAggregateRoot.cs | 5 +- ...tHandler.cs => AgreeChangeEventHandler.cs} | 62 +++++++++------ .../EventHandlers/AssignmentEventHandler.cs | 78 +++++++++++++++++++ .../CommentCreatedEventHandler.cs | 5 ++ .../DiscussCreatedEventHandler.cs | 24 ++++-- .../Managers/AssignmentManager.cs | 7 +- Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs | 7 ++ 12 files changed, 233 insertions(+), 55 deletions(-) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/AssignmentEventArgs.cs rename Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/{AgreeChangedEventHandler.cs => AgreeChangeEventHandler.cs} (55%) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AssignmentEventHandler.cs diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentDefineGetListOutputDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentDefineGetListOutputDto.cs index e3a9effc..f651300c 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentDefineGetListOutputDto.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentDefineGetListOutputDto.cs @@ -19,7 +19,12 @@ public class AssignmentDefineGetListOutputDto : EntityDto /// 任务类型 /// public AssignmentTypeEnum AssignmentType { get; set; } - + + /// + /// 任务需求类型 + /// + public AssignmentRequirementTypeEnum AssignmentRequirementType{ get; set; } + /// /// 总共步骤数 /// diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs index 6a0026ea..08677acb 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs @@ -5,7 +5,15 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment; public class AssignmentGetListOutputDto:EntityDto { - + /// + /// 任务名称 + /// + public string Name { get; set; } + + /// + /// 备注 + /// + public string Remarks { get; set; } /// /// 当前步骤数 /// @@ -16,6 +24,11 @@ public class AssignmentGetListOutputDto:EntityDto /// public int TotalStepNumber { get; set; } + + /// + /// 任务需求类型 + /// + public AssignmentRequirementTypeEnum AssignmentRequirementType{ get; set; } /// /// 任务状态 /// @@ -33,6 +46,6 @@ public class AssignmentGetListOutputDto:EntityDto public DateTime? CompleteTime { get; set; } - public DateTime CreationTime { get; } + public DateTime CreationTime { get; set; } public int OrderNum { get; set; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs index 85f5db7c..4b427fc9 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc; using Volo.Abp.Application.Services; using Volo.Abp.Users; using Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment; +using Yi.Framework.Bbs.Domain.Entities.Assignment; using Yi.Framework.Bbs.Domain.Managers; using Yi.Framework.Bbs.Domain.Shared.Enums; @@ -27,7 +28,7 @@ public class AssignmentService : ApplicationService /// /// [HttpPost("assignment/accept/{id}")] - public async Task AcceptAsync([FromRoute]Guid id) + public async Task AcceptAsync([FromRoute] Guid id) { await _assignmentManager.AcceptAsync(CurrentUser.GetId(), id); } @@ -37,7 +38,7 @@ public class AssignmentService : ApplicationService /// /// [HttpPost("assignment/complete/{id}")] - public async Task ReceiveRewardsAsync([FromRoute]Guid id) + public async Task ReceiveRewardsAsync([FromRoute] Guid id) { await _assignmentManager.ReceiveRewardsAsync(id); } @@ -58,18 +59,23 @@ public class AssignmentService : ApplicationService /// 查询接受的任务 /// [HttpGet("assignment")] - public async Task> GetListAsync([FromQuery]AssignmentGetListInput input) + public async Task> GetListAsync([FromQuery] AssignmentGetListInput input) { - var entities= await _assignmentManager._assignmentRepository._DbQueryable - .Where(x => x.UserId == CurrentUser.GetId()) - .WhereIF(input.AssignmentQueryState == AssignmentQueryStateEnum.Progress, - x => x.AssignmentState == AssignmentStateEnum.Progress) - .WhereIF(input.AssignmentQueryState == AssignmentQueryStateEnum.End, - x => x.AssignmentState == AssignmentStateEnum.Completed || - x.AssignmentState == AssignmentStateEnum.Expired) - .ToListAsync(); + var output = await _assignmentManager._assignmentRepository._DbQueryable + .Where(x => x.UserId == CurrentUser.GetId()) + .WhereIF(input.AssignmentQueryState == AssignmentQueryStateEnum.Progress, + x => x.AssignmentState == AssignmentStateEnum.Progress) + .WhereIF(input.AssignmentQueryState == AssignmentQueryStateEnum.End, + x => x.AssignmentState == AssignmentStateEnum.Completed || + x.AssignmentState == AssignmentStateEnum.Expired) + .OrderBy(x=>x.CreationTime) + .LeftJoin((x, define) => x.AssignmentDefineId==define.Id) + .Select((x, define) => new AssignmentGetListOutputDto + { + Id = x.Id + },true) + .ToListAsync(); - var output= entities.Adapt>(); return output; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentRequirementTypeEnum.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentRequirementTypeEnum.cs index 04aef002..4c7c9c88 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentRequirementTypeEnum.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentRequirementTypeEnum.cs @@ -12,15 +12,17 @@ public enum AssignmentRequirementTypeEnum /// Comment=4, - /// - /// 更新个人中心 - /// - UpdateProfile=8, - - /// /// 点赞 /// - Agree=16 + Agree=8, + + /// + /// 更新个人中心 + /// + UpdateProfile=16 + + + } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/AssignmentEventArgs.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/AssignmentEventArgs.cs new file mode 100644 index 00000000..240e7e50 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/AssignmentEventArgs.cs @@ -0,0 +1,30 @@ +using Yi.Framework.Bbs.Domain.Shared.Enums; + +namespace Yi.Framework.Bbs.Domain.Shared.Etos; + +public class AssignmentEventArgs +{ + public AssignmentEventArgs(AssignmentRequirementTypeEnum requirementType, Guid currentUserId,object? args=null) + { + RequirementType = requirementType; + Args = args; + CurrentUserId = currentUserId; + } + + /// + /// 任务需求类型 + /// + public AssignmentRequirementTypeEnum RequirementType { get; set; } + + + /// + /// 任务参数,可空,只需要一个触发点即可 + /// + public object? Args { get; set; } + + + /// + /// 当前用户id + /// + public Guid CurrentUserId { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs index cb8b6361..efdf1dab 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs @@ -48,7 +48,10 @@ public class AssignmentAggregateRoot : AggregateRoot, IHasCreationTime, IO /// 任务过期时间 /// public DateTime? ExpireTime { get; set; } - + /// + /// 任务需求类型 + /// + public AssignmentRequirementTypeEnum AssignmentRequirementType{ get; set; } public DateTime? CompleteTime { get; set; } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AgreeChangedEventHandler.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AgreeChangeEventHandler.cs similarity index 55% rename from Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AgreeChangedEventHandler.cs rename to Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AgreeChangeEventHandler.cs index 573ce9c5..fbad46be 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AgreeChangedEventHandler.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AgreeChangeEventHandler.cs @@ -5,6 +5,7 @@ using Volo.Abp.EventBus.Local; using Yi.Framework.Bbs.Domain.Entities; using Yi.Framework.Bbs.Domain.Entities.Forum; using Yi.Framework.Bbs.Domain.Shared.Consts; +using Yi.Framework.Bbs.Domain.Shared.Enums; using Yi.Framework.Bbs.Domain.Shared.Etos; using Yi.Framework.Rbac.Domain.Entities; using Yi.Framework.SqlSugarCore.Abstractions; @@ -14,20 +15,24 @@ namespace Yi.Framework.Bbs.Domain.EventHandlers /// /// 被点赞 /// - public class AgreeCreatedEventHandler : ILocalEventHandler>, - ITransientDependency + public class AgreeChangeEventHandler : ILocalEventHandler>, + ITransientDependency { private ISqlSugarRepository _userRepository; private ISqlSugarRepository _userInfoRepository; private ISqlSugarRepository _agreeRepository; private ILocalEventBus _localEventBus; - public AgreeCreatedEventHandler(ISqlSugarRepository userInfoRepository, ISqlSugarRepository agreeRepository, ILocalEventBus localEventBus, ISqlSugarRepository userRepository) + + public AgreeChangeEventHandler(ISqlSugarRepository userInfoRepository, + ISqlSugarRepository agreeRepository, ILocalEventBus localEventBus, + ISqlSugarRepository userRepository) { _userInfoRepository = userInfoRepository; _agreeRepository = agreeRepository; _localEventBus = localEventBus; _userRepository = userRepository; } + public async Task HandleEventAsync(EntityCreatedEventData eventData) { var agreeEntity = eventData.Entity; @@ -35,55 +40,66 @@ namespace Yi.Framework.Bbs.Domain.EventHandlers //查询主题的信息 var discussAndAgreeDto = await _agreeRepository._DbQueryable .LeftJoin((agree, discuss) => agree.DiscussId == discuss.Id) - .Select((agree, discuss) => - new - { - DiscussId=discuss.Id, - DiscussTitle = discuss.Title, - DiscussCreatorId = discuss.CreatorId, - }) - .FirstAsync(); + .Select((agree, discuss) => + new + { + DiscussId = discuss.Id, + DiscussTitle = discuss.Title, + DiscussCreatorId = discuss.CreatorId, + }) + .FirstAsync(); //查询点赞者用户 var agreeUser = await _userRepository.GetFirstAsync(x => x.Id == agreeEntity.CreatorId); //给创建者点赞数量+1 await _userInfoRepository._Db.Updateable() - .SetColumns(it => it.AgreeNumber == it.AgreeNumber + 1) - .Where(it => it.UserId == discussAndAgreeDto.DiscussCreatorId) - .ExecuteCommandAsync(); + .SetColumns(it => it.AgreeNumber == it.AgreeNumber + 1) + .Where(it => it.UserId == discussAndAgreeDto.DiscussCreatorId) + .ExecuteCommandAsync(); //通知主题作者,有人点赞 - await _localEventBus.PublishAsync(new BbsNoticeEventArgs(discussAndAgreeDto.DiscussCreatorId!.Value, string.Format(DiscussConst.AgreeNotice, discussAndAgreeDto.DiscussTitle, agreeUser.UserName,discussAndAgreeDto.DiscussId)), false); + await _localEventBus.PublishAsync( + new BbsNoticeEventArgs(discussAndAgreeDto.DiscussCreatorId!.Value, + string.Format(DiscussConst.AgreeNotice, discussAndAgreeDto.DiscussTitle, agreeUser.UserName, + discussAndAgreeDto.DiscussId)), false); + //最后发布任务触发事件 + await _localEventBus.PublishAsync( + new AssignmentEventArgs(AssignmentRequirementTypeEnum.Agree, agreeUser.Id),false); } } + /// /// 取消点赞 /// public class AgreeDeletedEventHandler : ILocalEventHandler>, - ITransientDependency + ITransientDependency { private ISqlSugarRepository _userRepository; private ISqlSugarRepository _agreeRepository; private ILocalEventBus _localEventBus; - public AgreeDeletedEventHandler(ISqlSugarRepository userRepository, ISqlSugarRepository agreeRepository, ILocalEventBus localEventBus) + + public AgreeDeletedEventHandler(ISqlSugarRepository userRepository, + ISqlSugarRepository agreeRepository, ILocalEventBus localEventBus) { _userRepository = userRepository; _agreeRepository = agreeRepository; _localEventBus = localEventBus; } + public async Task HandleEventAsync(EntityDeletedEventData eventData) { var agreeEntity = eventData.Entity; - var userId = await _agreeRepository._DbQueryable.LeftJoin((agree, discuss) => agree.DiscussId == discuss.Id) - .Select((agree, discuss) => discuss.CreatorId).FirstAsync(); + var userId = await _agreeRepository._DbQueryable + .LeftJoin((agree, discuss) => agree.DiscussId == discuss.Id) + .Select((agree, discuss) => discuss.CreatorId).FirstAsync(); //给创建者点赞数量-1 await _userRepository._Db.Updateable() - .SetColumns(it => it.AgreeNumber == it.AgreeNumber - 1) - .Where(it => it.UserId == userId) - .ExecuteCommandAsync(); + .SetColumns(it => it.AgreeNumber == it.AgreeNumber - 1) + .Where(it => it.UserId == userId) + .ExecuteCommandAsync(); } } -} +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AssignmentEventHandler.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AssignmentEventHandler.cs new file mode 100644 index 00000000..9aaa45b4 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AssignmentEventHandler.cs @@ -0,0 +1,78 @@ +using Volo.Abp.DependencyInjection; +using Volo.Abp.EventBus; +using Yi.Framework.Bbs.Domain.Entities.Assignment; +using Yi.Framework.Bbs.Domain.Shared.Enums; +using Yi.Framework.Bbs.Domain.Shared.Etos; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace Yi.Framework.Bbs.Domain.EventHandlers; + +/// +/// 任务系统的领域事件,处理不同任务触发变化 +/// +public class AssignmentEventHandler : ILocalEventHandler, ITransientDependency +{ + private readonly ISqlSugarRepository _repository; + + public AssignmentEventHandler(ISqlSugarRepository repository) + { + _repository = repository; + } + + public async Task HandleEventAsync(AssignmentEventArgs eventData) + { + var currentAssignmentList = await _repository.GetListAsync(x => + x.AssignmentState == AssignmentStateEnum.Progress && x.UserId == eventData.CurrentUserId); + + //如果有接收的任务 + if (currentAssignmentList.Count > 0) + { + switch (eventData.RequirementType) + { + //发表主题 + case AssignmentRequirementTypeEnum.Discuss: + SetCurrentStepNumber(AssignmentRequirementTypeEnum.Discuss, currentAssignmentList); + break; + + //发表评论 + case AssignmentRequirementTypeEnum.Comment: + SetCurrentStepNumber(AssignmentRequirementTypeEnum.Comment, currentAssignmentList); + break; + + //点赞 + case AssignmentRequirementTypeEnum.Agree: + SetCurrentStepNumber(AssignmentRequirementTypeEnum.Agree, currentAssignmentList); + break; + + //更新个人信息 + case AssignmentRequirementTypeEnum.UpdateProfile: + //这里还需判断是否更新了 + break; + default: + throw new ArgumentOutOfRangeException(); + } + + + //更新 + await _repository.UpdateRangeAsync(currentAssignmentList); + } + } + + /// + /// 设置当前进度 + /// + /// + /// + private void SetCurrentStepNumber(AssignmentRequirementTypeEnum requirementType, + List currentAssignmentList) + { + currentAssignmentList.ForEach(x => + { + if (x.AssignmentRequirementType == AssignmentRequirementTypeEnum.Agree && + x.CurrentStepNumber < x.TotalStepNumber) + { + x.CurrentStepNumber += 1; + } + }); + } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/CommentCreatedEventHandler.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/CommentCreatedEventHandler.cs index 0c5f63c3..80ae83df 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/CommentCreatedEventHandler.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/CommentCreatedEventHandler.cs @@ -6,6 +6,7 @@ using Volo.Abp.EventBus.Local; using Yi.Framework.Bbs.Domain.Entities; using Yi.Framework.Bbs.Domain.Entities.Forum; using Yi.Framework.Bbs.Domain.Shared.Consts; +using Yi.Framework.Bbs.Domain.Shared.Enums; using Yi.Framework.Bbs.Domain.Shared.Etos; using Yi.Framework.Rbac.Domain.Entities; using Yi.Framework.SqlSugarCore.Abstractions; @@ -62,6 +63,10 @@ namespace Yi.Framework.Bbs.Domain.EventHandlers await _localEventBus.PublishAsync(new BbsNoticeEventArgs(commentEntity.ParentId, string.Format(DiscussConst.CommentNoticeToReply, disucssDto.DiscussTitle, commentUser.UserName, content,commentEntity.DiscussId)), false); } + + //最后发布任务触发事件 + await _localEventBus.PublishAsync( + new AssignmentEventArgs(AssignmentRequirementTypeEnum.Comment, commentUser.Id),false); } } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/DiscussCreatedEventHandler.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/DiscussCreatedEventHandler.cs index fcebe0f5..9714eaed 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/DiscussCreatedEventHandler.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/DiscussCreatedEventHandler.cs @@ -1,8 +1,11 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities.Events; using Volo.Abp.EventBus; +using Volo.Abp.EventBus.Local; using Yi.Framework.Bbs.Domain.Entities; using Yi.Framework.Bbs.Domain.Entities.Forum; +using Yi.Framework.Bbs.Domain.Shared.Enums; +using Yi.Framework.Bbs.Domain.Shared.Etos; using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.Bbs.Domain.EventHandlers @@ -11,22 +14,31 @@ namespace Yi.Framework.Bbs.Domain.EventHandlers /// 主题创建的领域事件 /// public class DiscussCreatedEventHandler : ILocalEventHandler>, - ITransientDependency + ITransientDependency { private ISqlSugarRepository _userRepository; - public DiscussCreatedEventHandler(ISqlSugarRepository userRepository) + private ILocalEventBus _localEventBus; + + public DiscussCreatedEventHandler(ISqlSugarRepository userRepository, + ILocalEventBus localEventBus) { _userRepository = userRepository; + _localEventBus = localEventBus; } + public async Task HandleEventAsync(EntityCreatedEventData eventData) { var disucussEntity = eventData.Entity; //给创建者发布数量+1 await _userRepository._Db.Updateable() - .SetColumns(it => it.DiscussNumber == it.DiscussNumber + 1) - .Where(it => it.UserId == disucussEntity.CreatorId) - .ExecuteCommandAsync(); + .SetColumns(it => it.DiscussNumber == it.DiscussNumber + 1) + .Where(it => it.UserId == disucussEntity.CreatorId) + .ExecuteCommandAsync(); + + //最后发布任务触发事件 + await _localEventBus.PublishAsync( + new AssignmentEventArgs(AssignmentRequirementTypeEnum.Discuss, disucussEntity.CreatorId!.Value), false); } } -} +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs index 58267821..5b8a8a47 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs @@ -52,6 +52,7 @@ public class AssignmentManager : DomainService entity.CurrentStepNumber = 0; entity.TotalStepNumber = assignmentDefine.TotalStepNumber; entity.RewardsMoneyNumber = assignmentDefine.RewardsMoneyNumber; + entity.AssignmentRequirementType = assignmentDefine.AssignmentRequirementType; entity.ExpireTime = assignmentDefine.AssignmentType.GetExpireTime(); await _assignmentRepository.InsertAsync(entity); } @@ -71,7 +72,7 @@ public class AssignmentManager : DomainService //加钱加钱 await _localEventBus.PublishAsync( new MoneyChangeEventArgs { UserId = assignment.UserId, Number = assignment.RewardsMoneyNumber }, false); - + //设置已完成,并领取奖励,钱钱 assignment.SetComplete(); await _assignmentRepository.UpdateAsync(assignment); @@ -79,7 +80,7 @@ public class AssignmentManager : DomainService else { //不能领取 - throw new UserFriendlyException("该任务无法领取奖励,请检查任务详情"); + throw new UserFriendlyException("该任务没有满足领取条件,请检查任务详情"); } } @@ -98,7 +99,7 @@ public class AssignmentManager : DomainService output.AddRange(await assignmentProvider.GetCanReceiveListAsync(context)); } - output.DistinctBy(x => x.Id); + output = output.DistinctBy(x => x.Id).OrderBy(x => x.OrderNum).ToList(); return output; } diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs index 5ec09a9a..f9557819 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs @@ -7,6 +7,7 @@ using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; using Newtonsoft.Json.Converters; using Volo.Abp.AspNetCore.Authentication.JwtBearer; +using Volo.Abp.AspNetCore.ExceptionHandling; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.AntiForgery; @@ -68,6 +69,12 @@ namespace Yi.Abp.Web optios.AlwaysLogSelectors.Add(x => Task.FromResult(true)); }); + //配置错误处理显示详情 + Configure(options => + { + options.SendExceptionsDetailsToClients = true; + }); + //动态Api Configure(options => { From 23ffd2369493929c4aeeb77aa58a97c926396387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 13 Aug 2024 23:04:17 +0800 Subject: [PATCH 06/11] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E4=BB=BB=E5=8A=A1=E7=95=8C=E9=9D=A2=EF=BC=8C=E5=88=87?= =?UTF-8?q?=E5=9B=BE=E5=B4=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.Bbs.Vue3/src/views/assignment/Index.vue | 104 ++++++++++++------ .../assignment/components/AssignmentCard.vue | 83 ++++++++++++++ 2 files changed, 152 insertions(+), 35 deletions(-) create mode 100644 Yi.Bbs.Vue3/src/views/assignment/components/AssignmentCard.vue diff --git a/Yi.Bbs.Vue3/src/views/assignment/Index.vue b/Yi.Bbs.Vue3/src/views/assignment/Index.vue index 2dca2c09..b003a3e9 100644 --- a/Yi.Bbs.Vue3/src/views/assignment/Index.vue +++ b/Yi.Bbs.Vue3/src/views/assignment/Index.vue @@ -1,61 +1,95 @@ + + + + + + + + + - 可接收任务 - - {{item}} - 接收任务 - + {{ item }} + 领取奖励 + + + + \ No newline at end of file diff --git a/Yi.Bbs.Vue3/src/views/assignment/components/AssignmentCard.vue b/Yi.Bbs.Vue3/src/views/assignment/components/AssignmentCard.vue new file mode 100644 index 00000000..7efcd3cf --- /dev/null +++ b/Yi.Bbs.Vue3/src/views/assignment/components/AssignmentCard.vue @@ -0,0 +1,83 @@ + + + + + + 每日任务 + + {{cardData.name}} + {{cardData.remarks}} + + + + + 过期时间:无限制 + 接受任务 + + + + + + + + \ No newline at end of file From 27051aa01ddc9d1e12764fe771ba02f57ea291b1 Mon Sep 17 00:00:00 2001 From: chenchun Date: Wed, 14 Aug 2024 12:50:28 +0800 Subject: [PATCH 07/11] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=AE=BF=E9=97=AE=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/AccessLogExtensions.cs | 12 ++ .../Extensions/AccessLogMiddleware.cs | 109 ++++++++++++++ .../Services/Analyses/AccessLogService.cs | 37 ++--- .../Caches/AccessLogCacheItem.cs | 20 +++ .../Enums/AccessLogTypeEnum.cs | 14 ++ .../Entities/AccessLogAggregateRoot.cs | 7 +- Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs | 136 +++++++++--------- 7 files changed, 249 insertions(+), 86 deletions(-) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogExtensions.cs create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Caches/AccessLogCacheItem.cs create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AccessLogTypeEnum.cs diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogExtensions.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogExtensions.cs new file mode 100644 index 00000000..54387205 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogExtensions.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Builder; + +namespace Yi.Framework.Bbs.Application.Extensions; + +public static class AccessLogExtensions +{ + public static IApplicationBuilder UseAccessLog(this IApplicationBuilder app) + { + app.UseMiddleware(); + return app; + } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs new file mode 100644 index 00000000..373dcf7b --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs @@ -0,0 +1,109 @@ +using Microsoft.AspNetCore.Http; +using Volo.Abp.Caching; +using Volo.Abp.DependencyInjection; +using Yi.Framework.Bbs.Domain.Entities; +using Yi.Framework.Bbs.Domain.Shared.Caches; +using Yi.Framework.Bbs.Domain.Shared.Enums; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace Yi.Framework.Bbs.Application.Extensions; + +/// +/// 访问日志中间件 +/// 并发最高,采用缓存,默认10分钟才会真正操作一次数据库 +/// +/// 需考虑一致性问题,又不能上锁影响性能 +/// +public class AccessLogMiddleware : IMiddleware, ITransientDependency +{ + private readonly IDistributedCache _accessLogCache; + private readonly ISqlSugarRepository _repository; + + public AccessLogMiddleware(IDistributedCache accessLogCache, + ISqlSugarRepository repository) + { + _accessLogCache = accessLogCache; + _repository = repository; + } + + public async Task InvokeAsync(HttpContext context, RequestDelegate next) + { + await next(context); + + //获取缓存 + var cache = await _accessLogCache.GetAsync(AccessLogCacheConst.Key); + + //当前缓存需赋的值 + long currentNumber = 1; + //最后插入的时间 + DateTime lastInsertTime = DateTime.Now; + //cahce是空,创建缓存,当前数量从数据库中获取 + //不等于空,如果大于当前天,插入数据库(间隔超过10分钟,也插入) + + //获取当前访问数量 + //没有缓存 + if (cache is null) + { + //获取数据库今天最后最后一条数据 + var currentDayEntity = await GetDateAccessLogEntityAsync(); + + //数据库有数据,以数据库数据为准+1 + if (currentDayEntity is not null) + { + currentNumber = currentDayEntity.Number + 1; + } + //数据库没有数据,就是默认的1,重新开始 + } + else + { + //有缓存,根据根据缓存的值来 + currentNumber = cache.Number + 1; + lastInsertTime = cache.LastInsertTime; + + //数据库持久化 + //缓存的日期大于当天的日期,插入到数据库,同时缓存变成0,重新开始统计 + if (cache.LastModificationTime.Date > DateTime.Today) + { + await _repository.InsertAsync(new AccessLogAggregateRoot() + { AccessLogType = AccessLogTypeEnum.Request, Number = currentNumber }); + currentNumber = 0; + } + else + { + if (cache.LastInsertTime <= DateTime.Now - TimeSpan.FromMinutes(10)) + { + //这里还需要判断数据库是否有值,不能之间更新 + + //缓存的时间大于当前数据库时间10分钟之后,更新(减少数据库交互,10分钟才更新一次) + var currentDayEntity = await GetDateAccessLogEntityAsync(); + if (currentDayEntity is null) + { + await _repository.InsertAsync(new AccessLogAggregateRoot() + { AccessLogType = AccessLogTypeEnum.Request, Number = currentNumber }); + } + await _repository.UpdateAsync(currentDayEntity); + } + } + } + + + //覆盖缓存 + var newCache = new AccessLogCacheItem(currentNumber) { LastInsertTime = lastInsertTime }; + await _accessLogCache.SetAsync(AccessLogCacheConst.Key, newCache); + } + + /// + /// 获取今天的统计 + /// + /// + private async Task GetDateAccessLogEntityAsync() + { + //获取数据库今天最后最后一条数据 + var currentDayEntity = await _repository._DbQueryable + .Where(x => x.AccessLogType == AccessLogTypeEnum.Request) + .Where(x => x.CreationTime == DateTime.Today) + .OrderByDescending(x => x.CreationTime) + .FirstAsync(); + return currentDayEntity; + } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/AccessLogService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/AccessLogService.cs index b99e2980..53dd4a07 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/AccessLogService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/AccessLogService.cs @@ -4,6 +4,7 @@ using Volo.Abp.Application.Services; using Yi.Framework.Bbs.Application.Contracts.Dtos.AccessLog; using Yi.Framework.Bbs.Application.Contracts.IServices; using Yi.Framework.Bbs.Domain.Entities; +using Yi.Framework.Bbs.Domain.Shared.Enums; using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.Bbs.Application.Services @@ -11,7 +12,11 @@ namespace Yi.Framework.Bbs.Application.Services public class AccessLogService : ApplicationService, IAccessLogService { private readonly ISqlSugarRepository _repository; - public AccessLogService(ISqlSugarRepository repository) { _repository = repository; } + + public AccessLogService(ISqlSugarRepository repository) + { + _repository = repository; + } public DateTime GetWeekFirst() { @@ -45,16 +50,15 @@ namespace Yi.Framework.Bbs.Application.Services } - - /// /// 获取全部访问流量(3个月) /// + /// /// - public async Task> Get() + public async Task> GetListAsync([FromQuery] AccessLogTypeEnum AccessLogType) { - var entities = await _repository._DbQueryable - .Where(x=>x.CreationTime>=DateTime.Now.AddMonths(-3)) + var entities = await _repository._DbQueryable.Where(x => x.AccessLogType == AccessLogType) + .Where(x => x.CreationTime >= DateTime.Now.AddMonths(-3)) .OrderBy(x => x.CreationTime).ToListAsync(); var output = entities.Adapt>(); output?.ForEach(x => x.CreationTime = x.CreationTime.Date); @@ -62,7 +66,7 @@ namespace Yi.Framework.Bbs.Application.Services } /// - /// 触发 + /// 首页点击触发 /// /// [HttpPost("access-log")] @@ -77,17 +81,20 @@ namespace Yi.Framework.Bbs.Application.Services } else { - await _repository._Db.Updateable().SetColumns(it => it.Number == it.Number + 1).Where(it => it.Id == last.Id).ExecuteCommandAsync(); + await _repository._Db.Updateable().SetColumns(it => it.Number == it.Number + 1) + .Where(it => it.Id == last.Id).ExecuteCommandAsync(); } } /// - /// 获取当前周数据 + /// 获取当前周首页点击数据 /// /// public async Task GetWeekAsync() { - var lastSeven = await _repository._DbQueryable.OrderByDescending(x => x.CreationTime).ToPageListAsync(1, 7); + var lastSeven = await _repository._DbQueryable + .Where(x => x.AccessLogType == AccessLogTypeEnum.HomeClick) + .OrderByDescending(x => x.CreationTime).ToPageListAsync(1, 7); return WeekTimeHandler(lastSeven.ToArray()); } @@ -99,7 +106,8 @@ namespace Yi.Framework.Bbs.Application.Services /// private AccessLogDto[] WeekTimeHandler(AccessLogAggregateRoot[] data) { - data = data.Where(x => x.CreationTime >= GetWeekFirst()).OrderByDescending(x => x.CreationTime).DistinctBy(x => x.CreationTime.DayOfWeek).ToArray(); + data = data.Where(x => x.CreationTime >= GetWeekFirst()).OrderByDescending(x => x.CreationTime) + .DistinctBy(x => x.CreationTime.DayOfWeek).ToArray(); Dictionary processedData = new Dictionary(); @@ -117,8 +125,8 @@ namespace Yi.Framework.Bbs.Application.Services // 如果当天有数据,则更新字典中的值为对应的Number var sss = data.Adapt(); processedData[dayOfWeek] = item.Adapt(); - } + var result = processedData.Values.ToList(); //此时的时间是周日-周一-周二,需要处理 @@ -128,8 +136,5 @@ namespace Yi.Framework.Bbs.Application.Services return result.ToArray(); } - - - } -} +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Caches/AccessLogCacheItem.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Caches/AccessLogCacheItem.cs new file mode 100644 index 00000000..2c2f61ad --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Caches/AccessLogCacheItem.cs @@ -0,0 +1,20 @@ +namespace Yi.Framework.Bbs.Domain.Shared.Caches; + +public class AccessLogCacheItem +{ + public AccessLogCacheItem(long number) + { + Number = number; + } + + public long Number { get; set; } + public DateTime LastModificationTime { get; set; }=DateTime.Now; + + public DateTime LastInsertTime { get; set; }=DateTime.Now; +} + +public class AccessLogCacheConst +{ + + public const string Key = "AccessLog"; +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AccessLogTypeEnum.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AccessLogTypeEnum.cs new file mode 100644 index 00000000..04344ebd --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AccessLogTypeEnum.cs @@ -0,0 +1,14 @@ +namespace Yi.Framework.Bbs.Domain.Shared.Enums; + +public enum AccessLogTypeEnum +{ + /// + /// 首页点击量 + /// + HomeClick, + + /// + /// 接口请求量 + /// + Request +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/AccessLogAggregateRoot.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/AccessLogAggregateRoot.cs index 4eb55a89..b0a0c0ee 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/AccessLogAggregateRoot.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/AccessLogAggregateRoot.cs @@ -1,16 +1,19 @@ using SqlSugar; using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; +using Yi.Framework.Bbs.Domain.Shared.Enums; namespace Yi.Framework.Bbs.Domain.Entities { [SugarTable("AccessLog")] - public class AccessLogAggregateRoot : AggregateRoot, IHasModificationTime, IHasCreationTime + public class AccessLogAggregateRoot : AggregateRoot, IHasCreationTime,IHasModificationTime { [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)] public override Guid Id { get; protected set; } public long Number { get; set; } - public DateTime? LastModificationTime { get; set; } + + public AccessLogTypeEnum AccessLogType { get; set; } public DateTime CreationTime { get; set; } + public DateTime? LastModificationTime { get; set; } } } diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs index f9557819..71b21ed9 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs @@ -26,6 +26,7 @@ using Yi.Framework.AspNetCore.Authentication.OAuth.QQ; using Yi.Framework.AspNetCore.Microsoft.AspNetCore.Builder; using Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection; using Yi.Framework.Bbs.Application; +using Yi.Framework.Bbs.Application.Extensions; using Yi.Framework.ChatHub.Application; using Yi.Framework.CodeGen.Application; using Yi.Framework.Rbac.Application; @@ -39,8 +40,6 @@ namespace Yi.Abp.Web [DependsOn( typeof(YiAbpSqlSugarCoreModule), typeof(YiAbpApplicationModule), - - typeof(AbpAspNetCoreMultiTenancyModule), typeof(AbpAspNetCoreMvcModule), typeof(AbpAutofacModule), @@ -50,11 +49,11 @@ namespace Yi.Abp.Web typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(YiFrameworkAspNetCoreModule), typeof(YiFrameworkAspNetCoreAuthenticationOAuthModule) - - )] + )] public class YiAbpWebModule : AbpModule { private const string DefaultCorsPolicyName = "Default"; + public override Task ConfigureServicesAsync(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); @@ -70,20 +69,23 @@ namespace Yi.Abp.Web }); //配置错误处理显示详情 - Configure(options => - { - options.SendExceptionsDetailsToClients = true; - }); - + Configure(options => { options.SendExceptionsDetailsToClients = true; }); + //动态Api Configure(options => { - options.ConventionalControllers.Create(typeof(YiAbpApplicationModule).Assembly, options => options.RemoteServiceName = "default"); - options.ConventionalControllers.Create(typeof(YiFrameworkRbacApplicationModule).Assembly, options => options.RemoteServiceName = "rbac"); - options.ConventionalControllers.Create(typeof(YiFrameworkBbsApplicationModule).Assembly, options => options.RemoteServiceName = "bbs"); - options.ConventionalControllers.Create(typeof(YiFrameworkChatHubApplicationModule).Assembly, options => options.RemoteServiceName = "chat-hub"); - options.ConventionalControllers.Create(typeof(YiFrameworkTenantManagementApplicationModule).Assembly, options => options.RemoteServiceName = "tenant-management"); - options.ConventionalControllers.Create(typeof(YiFrameworkCodeGenApplicationModule).Assembly, options => options.RemoteServiceName = "code-gen"); + options.ConventionalControllers.Create(typeof(YiAbpApplicationModule).Assembly, + options => options.RemoteServiceName = "default"); + options.ConventionalControllers.Create(typeof(YiFrameworkRbacApplicationModule).Assembly, + options => options.RemoteServiceName = "rbac"); + options.ConventionalControllers.Create(typeof(YiFrameworkBbsApplicationModule).Assembly, + options => options.RemoteServiceName = "bbs"); + options.ConventionalControllers.Create(typeof(YiFrameworkChatHubApplicationModule).Assembly, + options => options.RemoteServiceName = "chat-hub"); + options.ConventionalControllers.Create(typeof(YiFrameworkTenantManagementApplicationModule).Assembly, + options => options.RemoteServiceName = "tenant-management"); + options.ConventionalControllers.Create(typeof(YiFrameworkCodeGenApplicationModule).Assembly, + options => options.RemoteServiceName = "code-gen"); //统一前缀 options.ConventionalControllers.ConventionalControllerSettings.ForEach(x => x.RootPath = "api/app"); @@ -98,22 +100,20 @@ namespace Yi.Abp.Web //设置缓存不要过期,默认滑动20分钟 Configure(cacheOptions => - { - cacheOptions.GlobalCacheEntryOptions.SlidingExpiration = null; - //缓存key前缀 - cacheOptions.KeyPrefix = "Yi:"; - }); - - - Configure(options => { - options.AutoValidate = false; + cacheOptions.GlobalCacheEntryOptions.SlidingExpiration = null; + //缓存key前缀 + cacheOptions.KeyPrefix = "Yi:"; }); + + Configure(options => { options.AutoValidate = false; }); + //Swagger context.Services.AddYiSwaggerGen(options => { - options.SwaggerDoc("default", new OpenApiInfo { Title = "Yi.Framework.Abp", Version = "v1", Description = "集大成者" }); + options.SwaggerDoc("default", + new OpenApiInfo { Title = "Yi.Framework.Abp", Version = "v1", Description = "集大成者" }); }); //跨域 @@ -152,7 +152,7 @@ namespace Yi.Abp.Web //每60秒限制100个请求,滑块添加,分6段 service.AddRateLimiter(_ => { - _.RejectionStatusCode = StatusCodes.Status429TooManyRequests; + _.RejectionStatusCode = StatusCodes.Status429TooManyRequests; _.OnRejected = (context, _) => { if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter)) @@ -160,6 +160,7 @@ namespace Yi.Abp.Web context.HttpContext.Response.Headers.RetryAfter = ((int)retryAfter.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo); } + context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests; context.HttpContext.Response.WriteAsync("Too many requests. Please try again later."); @@ -168,20 +169,20 @@ namespace Yi.Abp.Web //全局使用,链式表达式 _.GlobalLimiter = PartitionedRateLimiter.CreateChained( - PartitionedRateLimiter.Create(httpContext => - { - var userAgent = httpContext.Request.Headers.UserAgent.ToString(); + PartitionedRateLimiter.Create(httpContext => + { + var userAgent = httpContext.Request.Headers.UserAgent.ToString(); - return RateLimitPartition.GetSlidingWindowLimiter - (userAgent, _ => - new SlidingWindowRateLimiterOptions - { - PermitLimit = 1000, - Window = TimeSpan.FromSeconds(60), - SegmentsPerWindow = 6, - QueueProcessingOrder = QueueProcessingOrder.OldestFirst - }); - })); + return RateLimitPartition.GetSlidingWindowLimiter + (userAgent, _ => + new SlidingWindowRateLimiterOptions + { + PermitLimit = 1000, + Window = TimeSpan.FromSeconds(60), + SegmentsPerWindow = 6, + QueueProcessingOrder = QueueProcessingOrder.OldestFirst + }); + })); }); @@ -203,14 +204,15 @@ namespace Yi.Abp.Web options.Events = new JwtBearerEvents { OnMessageReceived = context => - { - var accessToken = context.Request.Query["access_token"]; - if (!string.IsNullOrEmpty(accessToken)) { - context.Token = accessToken; + var accessToken = context.Request.Query["access_token"]; + if (!string.IsNullOrEmpty(accessToken)) + { + context.Token = accessToken; + } + + return Task.CompletedTask; } - return Task.CompletedTask; - } }; }) .AddJwtBearer(TokenTypeConst.Refresh, options => @@ -221,37 +223,32 @@ namespace Yi.Abp.Web ValidateIssuerSigningKey = true, ValidIssuer = refreshJwtOptions.Issuer, ValidAudience = refreshJwtOptions.Audience, - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(refreshJwtOptions.SecurityKey)) + IssuerSigningKey = + new SymmetricSecurityKey(Encoding.UTF8.GetBytes(refreshJwtOptions.SecurityKey)) }; options.Events = new JwtBearerEvents { OnMessageReceived = context => - { - var refresh_token = context.Request.Headers["refresh_token"]; - if (!string.IsNullOrEmpty(refresh_token)) { - context.Token = refresh_token; + var refresh_token = context.Request.Headers["refresh_token"]; + if (!string.IsNullOrEmpty(refresh_token)) + { + context.Token = refresh_token; + return Task.CompletedTask; + } + + var refreshToken = context.Request.Query["refresh_token"]; + if (!string.IsNullOrEmpty(refreshToken)) + { + context.Token = refreshToken; + } + return Task.CompletedTask; } - var refreshToken = context.Request.Query["refresh_token"]; - if (!string.IsNullOrEmpty(refreshToken)) - { - context.Token = refreshToken; - } - - return Task.CompletedTask; - } }; - }) - .AddQQ(options => - { - configuration.GetSection("OAuth:QQ").Bind(options); - }) - .AddGitee(options => - { - configuration.GetSection("OAuth:Gitee").Bind(options); - }); + .AddQQ(options => { configuration.GetSection("OAuth:QQ").Bind(options); }) + .AddGitee(options => { configuration.GetSection("OAuth:Gitee").Bind(options); }); //授权 context.Services.AddAuthorization(); @@ -291,6 +288,9 @@ namespace Yi.Abp.Web //swagger app.UseYiSwagger(); + //流量访问统计,不启用 + //app.UseAccessLog(); + //请求处理 app.UseYiApiHandlinge(); @@ -317,4 +317,4 @@ namespace Yi.Abp.Web return Task.CompletedTask; } } -} +} \ No newline at end of file From b619204c5e9c4cf4d31c5c3ff3ae088b604f3435 Mon Sep 17 00:00:00 2001 From: chenchun Date: Wed, 14 Aug 2024 18:31:37 +0800 Subject: [PATCH 08/11] =?UTF-8?q?feat:=E5=AE=8C=E5=96=84=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assignment/AssignmentGetListOutputDto.cs | 5 +- .../Extensions/AccessLogMiddleware.cs | 112 ++++----------- .../Jobs/AccessLogStoreJob.cs | 72 ++++++++++ .../Services/AssignmentService.cs | 5 +- .../Enums/AssignmentStateEnum.cs | 7 +- .../Assignment/AssignmentAggregateRoot.cs | 10 +- .../EventHandlers/AssignmentEventHandler.cs | 6 +- .../Managers/AssignmentManager.cs | 2 +- .../TimerAbstractProvider.cs | 7 +- Yi.Bbs.Vue3/src/views/assignment/Index.vue | 44 ++++-- .../assignment/components/AssignmentCard.vue | 127 ++++++++++++++---- 11 files changed, 257 insertions(+), 140 deletions(-) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogStoreJob.cs diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs index 08677acb..cdd7baf1 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Assignment/AssignmentGetListOutputDto.cs @@ -23,7 +23,10 @@ public class AssignmentGetListOutputDto:EntityDto /// 总共步骤数 /// public int TotalStepNumber { get; set; } - + /// + /// 任务类型 + /// + public AssignmentTypeEnum AssignmentType { get; set; } /// /// 任务需求类型 diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs index 373dcf7b..7aba4c48 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Extensions/AccessLogMiddleware.cs @@ -1,109 +1,51 @@ -using Microsoft.AspNetCore.Http; +using FreeRedis; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; -using Yi.Framework.Bbs.Domain.Entities; using Yi.Framework.Bbs.Domain.Shared.Caches; -using Yi.Framework.Bbs.Domain.Shared.Enums; -using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.Bbs.Application.Extensions; /// /// 访问日志中间件 /// 并发最高,采用缓存,默认10分钟才会真正操作一次数据库 -/// /// 需考虑一致性问题,又不能上锁影响性能 /// public class AccessLogMiddleware : IMiddleware, ITransientDependency { - private readonly IDistributedCache _accessLogCache; - private readonly ISqlSugarRepository _repository; + /// + /// 缓存前缀 + /// + private string CacheKeyPrefix => LazyServiceProvider.LazyGetRequiredService>() + .Value.KeyPrefix; - public AccessLogMiddleware(IDistributedCache accessLogCache, - ISqlSugarRepository repository) + /// + /// 使用懒加载防止报错 + /// + private IRedisClient RedisClient => LazyServiceProvider.LazyGetRequiredService(); + + /// + /// 属性注入 + /// + public IAbpLazyServiceProvider LazyServiceProvider { get; set; } + + private bool EnableRedisCache { - _accessLogCache = accessLogCache; - _repository = repository; + get + { + var redisEnabled = LazyServiceProvider.LazyGetRequiredService()["Redis:IsEnabled"]; + return redisEnabled.IsNullOrEmpty() || bool.Parse(redisEnabled); + } } public async Task InvokeAsync(HttpContext context, RequestDelegate next) { await next(context); - - //获取缓存 - var cache = await _accessLogCache.GetAsync(AccessLogCacheConst.Key); - - //当前缓存需赋的值 - long currentNumber = 1; - //最后插入的时间 - DateTime lastInsertTime = DateTime.Now; - //cahce是空,创建缓存,当前数量从数据库中获取 - //不等于空,如果大于当前天,插入数据库(间隔超过10分钟,也插入) - - //获取当前访问数量 - //没有缓存 - if (cache is null) + if (EnableRedisCache) { - //获取数据库今天最后最后一条数据 - var currentDayEntity = await GetDateAccessLogEntityAsync(); - - //数据库有数据,以数据库数据为准+1 - if (currentDayEntity is not null) - { - currentNumber = currentDayEntity.Number + 1; - } - //数据库没有数据,就是默认的1,重新开始 + await RedisClient.IncrByAsync($"{CacheKeyPrefix}:{AccessLogCacheConst.Key}:{DateTime.Now.Date}", 1); } - else - { - //有缓存,根据根据缓存的值来 - currentNumber = cache.Number + 1; - lastInsertTime = cache.LastInsertTime; - - //数据库持久化 - //缓存的日期大于当天的日期,插入到数据库,同时缓存变成0,重新开始统计 - if (cache.LastModificationTime.Date > DateTime.Today) - { - await _repository.InsertAsync(new AccessLogAggregateRoot() - { AccessLogType = AccessLogTypeEnum.Request, Number = currentNumber }); - currentNumber = 0; - } - else - { - if (cache.LastInsertTime <= DateTime.Now - TimeSpan.FromMinutes(10)) - { - //这里还需要判断数据库是否有值,不能之间更新 - - //缓存的时间大于当前数据库时间10分钟之后,更新(减少数据库交互,10分钟才更新一次) - var currentDayEntity = await GetDateAccessLogEntityAsync(); - if (currentDayEntity is null) - { - await _repository.InsertAsync(new AccessLogAggregateRoot() - { AccessLogType = AccessLogTypeEnum.Request, Number = currentNumber }); - } - await _repository.UpdateAsync(currentDayEntity); - } - } - } - - - //覆盖缓存 - var newCache = new AccessLogCacheItem(currentNumber) { LastInsertTime = lastInsertTime }; - await _accessLogCache.SetAsync(AccessLogCacheConst.Key, newCache); - } - - /// - /// 获取今天的统计 - /// - /// - private async Task GetDateAccessLogEntityAsync() - { - //获取数据库今天最后最后一条数据 - var currentDayEntity = await _repository._DbQueryable - .Where(x => x.AccessLogType == AccessLogTypeEnum.Request) - .Where(x => x.CreationTime == DateTime.Today) - .OrderByDescending(x => x.CreationTime) - .FirstAsync(); - return currentDayEntity; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogStoreJob.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogStoreJob.cs new file mode 100644 index 00000000..53659519 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogStoreJob.cs @@ -0,0 +1,72 @@ +using FreeRedis; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Quartz; +using Volo.Abp.BackgroundWorkers.Quartz; +using Volo.Abp.Caching; +using Volo.Abp.DependencyInjection; +using Yi.Framework.Bbs.Domain.Entities; +using Yi.Framework.Bbs.Domain.Shared.Caches; +using Yi.Framework.Bbs.Domain.Shared.Enums; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace Yi.Framework.Bbs.Application.Jobs; + +public class AccessLogStoreJob : QuartzBackgroundWorkerBase +{ + private readonly ISqlSugarRepository _repository; + + /// + /// 缓存前缀 + /// + private string CacheKeyPrefix => LazyServiceProvider.LazyGetRequiredService>() + .Value.KeyPrefix; + + /// + /// 使用懒加载防止报错 + /// + private IRedisClient RedisClient => LazyServiceProvider.LazyGetRequiredService(); + + /// + /// 属性注入 + /// + public IAbpLazyServiceProvider LazyServiceProvider { get; set; } + + private bool EnableRedisCache + { + get + { + var redisEnabled = LazyServiceProvider.LazyGetRequiredService()["Redis:IsEnabled"]; + return redisEnabled.IsNullOrEmpty() || bool.Parse(redisEnabled); + } + } + + public AccessLogStoreJob(ISqlSugarRepository repository) + { + _repository = repository; + JobDetail = JobBuilder.Create().WithIdentity(nameof(AccessLogStoreJob)) + .Build(); + //每分钟执行一次 + Trigger = TriggerBuilder.Create().WithIdentity(nameof(AccessLogStoreJob)) + .WithCronSchedule("* * * * *") + .Build(); + } + + public override async Task Execute(IJobExecutionContext context) + { + if (EnableRedisCache) + { + //当天的访问量 + var number = + await RedisClient.GetAsync($"{CacheKeyPrefix}:{AccessLogCacheConst.Key}:{DateTime.Now.Date}"); + + + var entity = await _repository._DbQueryable.Where(x => x.AccessLogType == AccessLogTypeEnum.Request) + .Where(x => x.CreationTime.Date == DateTime.Today) + .FirstAsync(); + // _repository._Db.Storageable(list2).ExecuteCommandAsync(); + + + } + } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs index 4b427fc9..456fdfea 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/AssignmentService.cs @@ -64,9 +64,10 @@ public class AssignmentService : ApplicationService var output = await _assignmentManager._assignmentRepository._DbQueryable .Where(x => x.UserId == CurrentUser.GetId()) .WhereIF(input.AssignmentQueryState == AssignmentQueryStateEnum.Progress, - x => x.AssignmentState == AssignmentStateEnum.Progress) + x => x.AssignmentState == AssignmentStateEnum.Progress|| + x.AssignmentState == AssignmentStateEnum.Completed) .WhereIF(input.AssignmentQueryState == AssignmentQueryStateEnum.End, - x => x.AssignmentState == AssignmentStateEnum.Completed || + x => x.AssignmentState == AssignmentStateEnum.End || x.AssignmentState == AssignmentStateEnum.Expired) .OrderBy(x=>x.CreationTime) .LeftJoin((x, define) => x.AssignmentDefineId==define.Id) diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentStateEnum.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentStateEnum.cs index 8cd23d90..05418cde 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentStateEnum.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Enums/AssignmentStateEnum.cs @@ -15,5 +15,10 @@ public enum AssignmentStateEnum /// /// 已过期 /// - Expired + Expired, + + /// + /// 已结束 + /// + End } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs index efdf1dab..5e8a6dc9 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Assignment/AssignmentAggregateRoot.cs @@ -52,7 +52,7 @@ public class AssignmentAggregateRoot : AggregateRoot, IHasCreationTime, IO /// 任务需求类型 /// public AssignmentRequirementTypeEnum AssignmentRequirementType{ get; set; } - public DateTime? CompleteTime { get; set; } + public DateTime? EndTime { get; set; } public DateTime CreationTime { get; set; } @@ -62,7 +62,7 @@ public class AssignmentAggregateRoot : AggregateRoot, IHasCreationTime, IO public bool IsAllowCompleted() { - return AssignmentState == AssignmentStateEnum.Progress && this.CurrentStepNumber == this.TotalStepNumber; + return AssignmentState == AssignmentStateEnum.Completed && this.CurrentStepNumber == this.TotalStepNumber; } public bool TrySetExpire() @@ -76,10 +76,10 @@ public class AssignmentAggregateRoot : AggregateRoot, IHasCreationTime, IO return true; } - public void SetComplete() + public void SetEnd() { - this.AssignmentState = AssignmentStateEnum.Completed; - this.CompleteTime=DateTime.Now; + this.AssignmentState = AssignmentStateEnum.End; + this.EndTime=DateTime.Now; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AssignmentEventHandler.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AssignmentEventHandler.cs index 9aaa45b4..b9c6d4af 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AssignmentEventHandler.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/AssignmentEventHandler.cs @@ -68,10 +68,14 @@ public class AssignmentEventHandler : ILocalEventHandler, I { currentAssignmentList.ForEach(x => { - if (x.AssignmentRequirementType == AssignmentRequirementTypeEnum.Agree && + if (x.AssignmentRequirementType == requirementType && x.CurrentStepNumber < x.TotalStepNumber) { x.CurrentStepNumber += 1; + if (x.CurrentStepNumber==x.TotalStepNumber) + { + x.AssignmentState = AssignmentStateEnum.Completed; + } } }); } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs index 5b8a8a47..4ee4ad64 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentManager.cs @@ -74,7 +74,7 @@ public class AssignmentManager : DomainService new MoneyChangeEventArgs { UserId = assignment.UserId, Number = assignment.RewardsMoneyNumber }, false); //设置已完成,并领取奖励,钱钱 - assignment.SetComplete(); + assignment.SetEnd(); await _assignmentRepository.UpdateAsync(assignment); } else diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/TimerAbstractProvider.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/TimerAbstractProvider.cs index 527d659b..8a286fa9 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/TimerAbstractProvider.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/AssignmentProviders/TimerAbstractProvider.cs @@ -24,10 +24,11 @@ public abstract class TimerProvider : IAssignmentProvider //2: 存在已完成,但是完成时间是过期的 var assignmentFilterIds = context.CurrentUserAssignments .Where(x => - //正在进行的,要去掉 + //正在进行的,已经完成,要去掉 x.AssignmentState == AssignmentStateEnum.Progress|| - //已完成,但是还没过期,要去掉 - (x.AssignmentState == AssignmentStateEnum.Completed&&!AssignmentType.IsExpire(x.CompleteTime!.Value))) + x.AssignmentState==AssignmentStateEnum.Completed|| + //已结束,但是还没过期,要去掉 + (x.AssignmentState == AssignmentStateEnum.End&&!AssignmentType.IsExpire(x.EndTime!.Value))) .Select(x => x.AssignmentDefineId) .ToList(); diff --git a/Yi.Bbs.Vue3/src/views/assignment/Index.vue b/Yi.Bbs.Vue3/src/views/assignment/Index.vue index b003a3e9..277e9f49 100644 --- a/Yi.Bbs.Vue3/src/views/assignment/Index.vue +++ b/Yi.Bbs.Vue3/src/views/assignment/Index.vue @@ -2,6 +2,7 @@ import {getAssignmentList, getCanReceiveAssignment, acceptAssignment, receiveAssignment} from '@/apis/assignmentApi' import {onMounted, reactive, ref} from "vue"; import AssignmentCard from "./components/AssignmentCard.vue" + const canReceiveAssignmentList = ref([]); const assignmentList = ref([]); @@ -14,7 +15,6 @@ const currentTableSelect = ref("canAccept"); //切换tab const changeClickTable = async (tabName) => { - console.log(tabName,"tabName") switch (tabName) { case "canAccept": const {data: canReceiveAssignmentListData} = await getCanReceiveAssignment(); @@ -47,11 +47,20 @@ const refreshData = async () => { //接收任务 const onClickAcceptAssignment = async (item) => { await acceptAssignment(item.id); + ElMessage({ + type: 'success', + message: '接受任务成功', + }); await refreshData(); } -const onClickReceiveAssignment = async (id) => { - await receiveAssignment(id); +//领取奖励 +const onClickReceiveAssignment = async (item) => { + await receiveAssignment(item.id); + ElMessage({ + type: 'success', + message: '任务奖励领取成功', + }); await refreshData(); } @@ -74,21 +83,32 @@ const changeTab = async (state) => { - - - - - {{ item }} - 领取奖励 + + + + + + + + + + + + + diff --git a/Yi.Bbs.Vue3/src/views/home/Index.vue b/Yi.Bbs.Vue3/src/views/home/Index.vue index a88d9233..1c276fe2 100644 --- a/Yi.Bbs.Vue3/src/views/home/Index.vue +++ b/Yi.Bbs.Vue3/src/views/home/Index.vue @@ -3,10 +3,11 @@ - 点击前往-最新上线《聊天室》 ,现已支持Ai助手,希望能帮助大家 + 点击前往-最新上线《聊天室》 ,现已支持Ai助手,希望能帮助大家 + - + @@ -14,23 +15,23 @@ 'padding-left': i % 3 == 1 ? 0 : 0.2 + 'rem', 'padding-right': i % 3 == 0 ? 0 : 0.2 + 'rem', }"> - + - + - + - + - + @@ -42,7 +43,7 @@ {{ item.name }} - + @@ -97,23 +98,26 @@ - + 切换 + + - - + + - - + + - @@ -129,16 +133,17 @@ - + - + - + @@ -148,14 +153,14 @@ - + - + @@ -164,21 +169,21 @@ - + - + - + @@ -187,8 +192,8 @@
点击前往-最新上线《聊天室》 ,现已支持Ai助手,希望能帮助大家
点击前往-最新上线《聊天室》 ,现已支持Ai助手,希望能帮助大家 +
切换