feat: 新增任务接口路由

This commit is contained in:
橙子
2024-08-12 23:23:29 +08:00
parent c122863e45
commit 9530350d06
11 changed files with 190 additions and 18 deletions

View File

@@ -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<Guid>
{
/// <summary>
/// 任务名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remarks { get; set; }
/// <summary>
/// 任务类型
/// </summary>
public AssignmentTypeEnum AssignmentType { get; set; }
/// <summary>
/// 总共步骤数
/// </summary>
public int TotalStepNumber { get; set; }
/// <summary>
/// 前置任务id
/// </summary>
public Guid? PreAssignmentId { get; set; }
/// <summary>
/// 任务奖励的钱钱数量
/// </summary>
public decimal RewardsMoneyNumber { get; set; }
public int OrderNum { get; set; }
}

View File

@@ -4,5 +4,21 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment;
public class AssignmentGetListInput public class AssignmentGetListInput
{ {
/// <summary>
/// 任务查询条件
/// </summary>
public AssignmentQueryStateEnum? AssignmentQueryState { get; set; }
}
public enum AssignmentQueryStateEnum
{
/// <summary>
/// 正在进行
/// </summary>
Progress,
/// <summary>
/// 已结束
/// </summary>
End
} }

View File

@@ -1,8 +1,38 @@
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Yi.Framework.Bbs.Domain.Shared.Enums;
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment; namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment;
public class AssignmentGetListOutputDto:EntityDto<Guid> public class AssignmentGetListOutputDto:EntityDto<Guid>
{ {
/// <summary>
/// 当前步骤数
/// </summary>
public int CurrentStepNumber { get; set; }
/// <summary>
/// 总共步骤数
/// </summary>
public int TotalStepNumber { get; set; }
/// <summary>
/// 任务状态
/// </summary>
public AssignmentStateEnum AssignmentState { get; set; }
/// <summary>
/// 任务奖励的钱钱数量
/// </summary>
public decimal RewardsMoneyNumber { get; set; }
/// <summary>
/// 任务过期时间
/// </summary>
public DateTime? ExpireTime { get; set; }
public DateTime? CompleteTime { get; set; }
public DateTime CreationTime { get; }
public int OrderNum { get; set; }
} }

View File

@@ -1,10 +1,11 @@
using Microsoft.AspNetCore.Authorization; using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.Users; using Volo.Abp.Users;
using Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment; using Yi.Framework.Bbs.Application.Contracts.Dtos.Assignment;
using Yi.Framework.Bbs.Domain.Managers; using Yi.Framework.Bbs.Domain.Managers;
using Yi.Framework.Bbs.Domain.Shared.Enums;
namespace Yi.Framework.Bbs.Application.Services; namespace Yi.Framework.Bbs.Application.Services;
@@ -26,26 +27,49 @@ public class AssignmentService : ApplicationService
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
[HttpPost("assignment/accept/{id}")] [HttpPost("assignment/accept/{id}")]
public async Task AcceptAsync(Guid id) public async Task AcceptAsync([FromRoute]Guid id)
{ {
await _assignmentManager.AcceptAsync(CurrentUser.GetId(), id); await _assignmentManager.AcceptAsync(CurrentUser.GetId(), id);
} }
/// <summary> /// <summary>
/// 接收任务奖励 /// 领取任务奖励
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
[HttpPost("assignment/receive-rewards/{id}")] [HttpPost("assignment/complete/{id}")]
public async Task ReceiveRewardsAsync(Guid id) public async Task ReceiveRewardsAsync([FromRoute]Guid id)
{ {
await _assignmentManager.ReceiveRewardsAsync(id); await _assignmentManager.ReceiveRewardsAsync(id);
} }
/// <summary> /// <summary>
/// 查任务 /// 查看可接受的任务
/// </summary> /// </summary>
public async Task<PagedResultDto<AssignmentGetListOutputDto>> GetListAsync(AssignmentGetListInput input) /// <returns></returns>
[HttpGet("assignment/receive")]
public async Task<List<AssignmentDefineGetListOutputDto>> GetCanReceiveListAsync()
{ {
throw new NotImplementedException(); var entities = await _assignmentManager.GetCanReceiveListAsync(CurrentUser.GetId());
var output = entities.Adapt<List<AssignmentDefineGetListOutputDto>>();
return output;
}
/// <summary>
/// 查询接受的任务
/// </summary>
[HttpGet("assignment")]
public async Task<List<AssignmentGetListOutputDto>> 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<List<AssignmentGetListOutputDto>>();
return output;
} }
} }

View File

@@ -16,8 +16,8 @@ namespace Yi.Framework.Bbs.Domain.Managers;
public class AssignmentManager : DomainService public class AssignmentManager : DomainService
{ {
private readonly IEnumerable<IAssignmentProvider> _assignmentProviders; private readonly IEnumerable<IAssignmentProvider> _assignmentProviders;
private readonly ISqlSugarRepository<AssignmentAggregateRoot> _assignmentRepository; public readonly ISqlSugarRepository<AssignmentAggregateRoot> _assignmentRepository;
private readonly ISqlSugarRepository<AssignmentDefineAggregateRoot> _assignmentDefineRepository; public readonly ISqlSugarRepository<AssignmentDefineAggregateRoot> _assignmentDefineRepository;
private readonly ILocalEventBus _localEventBus; private readonly ILocalEventBus _localEventBus;
public AssignmentManager(IEnumerable<IAssignmentProvider> assignmentProviders, public AssignmentManager(IEnumerable<IAssignmentProvider> assignmentProviders,
@@ -92,7 +92,7 @@ public class AssignmentManager : DomainService
} }
output.DistinctBy(x => x.Id); output.DistinctBy(x => x.Id);
throw new NotImplementedException(); return output;
} }
@@ -134,6 +134,5 @@ public class AssignmentManager : DomainService
{ {
await _assignmentRepository._Db.Updateable(needUpdateEntities).ExecuteCommandAsync(); await _assignmentRepository._Db.Updateable(needUpdateEntities).ExecuteCommandAsync();
} }
} }
} }

View File

@@ -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; namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
/// <summary> /// <summary>
/// 每日任务提供者 /// 每日任务提供者
/// </summary> /// </summary>
[ExposeServices(typeof(IAssignmentProvider))]
public class DailyProvider : TimerProvider public class DailyProvider : TimerProvider
{ {
protected override AssignmentTypeEnum AssignmentType => AssignmentTypeEnum.Daily; protected override AssignmentTypeEnum AssignmentType => AssignmentTypeEnum.Daily;

View File

@@ -5,11 +5,12 @@ namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
/// <summary> /// <summary>
/// 新手任务提供者 /// 新手任务提供者
/// </summary> /// </summary>
public class NoviceProvider : IAssignmentProvider public class NoviceProvider : IAssignmentProvider
{ {
public Task<List<AssignmentDefineAggregateRoot>> GetCanReceiveListAsync(AssignmentContext context) public async Task<List<AssignmentDefineAggregateRoot>> GetCanReceiveListAsync(AssignmentContext context)
{ {
//新手任务是要有前置依赖关系的,链表类型依赖 //新手任务是要有前置依赖关系的,链表类型依赖
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }

View File

@@ -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; namespace Yi.Framework.Bbs.Domain.Managers.AssignmentProviders;
/// <summary> /// <summary>
/// 每周任务提供者 /// 每周任务提供者
/// </summary> /// </summary>
[ExposeServices(typeof(IAssignmentProvider))]
public class WeeklyProvider : TimerProvider public class WeeklyProvider : TimerProvider
{ {
protected override AssignmentTypeEnum AssignmentType => AssignmentTypeEnum.Weekly; protected override AssignmentTypeEnum AssignmentType => AssignmentTypeEnum.Weekly;

View File

@@ -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
});
}

View File

@@ -156,6 +156,14 @@ const router = createRouter({
title: "银行", title: "银行",
}, },
}, },
{
name: "assignment",
path: "assignment",
component: () => import("../views/assignment/Index.vue"),
meta: {
title: "任务",
},
},
], ],
}, },

View File

@@ -0,0 +1,18 @@
<script setup>
import {getCanReceiveAssignment} from '@/apis/assignmentApi'
import {onMounted, ref} from "vue";
const canReceiveAssignmentList=ref([]);
onMounted( async ()=>{
const {data:canReceiveAssignmentListData}= await getCanReceiveAssignment();
canReceiveAssignmentList.value=canReceiveAssignmentListData;
});
</script>
<template>
<div>
<div v-for="item in canReceiveAssignmentList">{{item}}</div>
</div>
</template>