This commit is contained in:
2025-10-15 16:19:02 +08:00

View File

@ -7,19 +7,16 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.ObjectMapping;
namespace KonSoft.Admin.ApplicationServices
{
public class OrderAppService : ApplicationService, IOrderAppService
public class OrderAppService(IOrderRepository orderRepository) : ApplicationService, IOrderAppService
{
private readonly IOrderRepository _orderRepository;
private readonly IOrderRepository _orderRepository = orderRepository;
public OrderAppService(IOrderRepository orderRepository)
{
_orderRepository = orderRepository;
}
/// <summary>
/// 分配师傅
/// </summary>
@ -45,6 +42,7 @@ namespace KonSoft.Admin.ApplicationServices
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.Cancel(reason);
}
/// <summary>
/// 完成订单
/// </summary>
@ -56,6 +54,7 @@ namespace KonSoft.Admin.ApplicationServices
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.CompleteService();
}
/// <summary>
/// 确认订单
/// </summary>
@ -67,6 +66,7 @@ namespace KonSoft.Admin.ApplicationServices
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.ConfirmCompletion();
}
/// <summary>
/// 创建订单
/// </summary>
@ -83,6 +83,34 @@ namespace KonSoft.Admin.ApplicationServices
await _orderRepository.InsertAsync(order);
return ObjectMapper.Map<Order, OrderDto>(order);
}
/// <summary>
/// 根据订单ID删除订单
/// </summary>
/// <param name="id">订单ID</param>
public async Task DeleteAsync(Guid id)
{
// 根据ID删除订单
await _orderRepository.DeleteAsync(x => x.Id == id);
}
/// <summary>
/// 修改订单信息
/// </summary>
/// <param name="input">订单DTO对象</param>s
public async Task EditAsync(OrderDto input)
{
// 根据ID查询订单如果不存在则抛出异常【修改前端必然看到了,数据若查不到提示自定义异常信息】
var order = await _orderRepository.FindAsync(o => o.Id == input.Id) ??
throw new BusinessException("订单找不到").WithData("Id", input.Id);
// 将输入的DTO字段映射到订单实体
ObjectMapper.Map(input, order);
// 更新订单
await _orderRepository.UpdateAsync(order);
}
/// <summary>
/// 支付
/// </summary>
@ -94,6 +122,7 @@ namespace KonSoft.Admin.ApplicationServices
{
throw new NotImplementedException();
}
/// <summary>
/// 开始订单
/// </summary>
@ -106,10 +135,28 @@ namespace KonSoft.Admin.ApplicationServices
order.StartService();
}
/// <summary>
/// 根据订单ID获取单个订单
/// </summary>
public async Task<OrderDto> GetAsync(Guid id)
{
// 根据ID从数据库查询订单
var order = await _orderRepository.GetAsync(o => o.Id == id);
// 转换为OrderDto返回
return ObjectMapper.Map<Order, OrderDto>(order);
}
/// <summary>
/// 获取所有订单列表
/// </summary>
public async Task<List<OrderDto>> GetListAsync()
{
// 查询所有订单
var orders = await _orderRepository.GetListAsync();
// 转换为OrderDto列表返回
return ObjectMapper.Map<List<Order>, List<OrderDto>>(orders);
}
}
}