diff --git a/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/OrderAppService.cs b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/OrderAppService.cs
index 5883752..c22394b 100644
--- a/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/OrderAppService.cs
+++ b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/OrderAppService.cs
@@ -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;
- }
///
/// 分配师傅
///
@@ -27,7 +24,7 @@ namespace KonSoft.Admin.ApplicationServices
///
///
///
- public async Task AssignAsync(Guid orderId, Guid workerId)
+ public async Task AssignAsync(Guid orderId, Guid workerId)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.AssignWorker(workerId);
@@ -45,6 +42,7 @@ namespace KonSoft.Admin.ApplicationServices
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.Cancel(reason);
}
+
///
/// 完成订单
///
@@ -56,6 +54,7 @@ namespace KonSoft.Admin.ApplicationServices
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.CompleteService();
}
+
///
/// 确认订单
///
@@ -67,6 +66,7 @@ namespace KonSoft.Admin.ApplicationServices
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.ConfirmCompletion();
}
+
///
/// 创建订单
///
@@ -83,6 +83,34 @@ namespace KonSoft.Admin.ApplicationServices
await _orderRepository.InsertAsync(order);
return ObjectMapper.Map(order);
}
+
+ ///
+ /// 根据订单ID删除订单
+ ///
+ /// 订单ID
+ public async Task DeleteAsync(Guid id)
+ {
+ // 根据ID删除订单
+ await _orderRepository.DeleteAsync(x => x.Id == id);
+ }
+
+ ///
+ /// 修改订单信息
+ ///
+ /// 订单DTO对象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);
+ }
+
///
/// 支付
///
@@ -94,6 +122,7 @@ namespace KonSoft.Admin.ApplicationServices
{
throw new NotImplementedException();
}
+
///
/// 开始订单
///
@@ -106,10 +135,28 @@ namespace KonSoft.Admin.ApplicationServices
order.StartService();
}
+ ///
+ /// 根据订单ID获取单个订单
+ ///
public async Task GetAsync(Guid id)
{
+ // 根据ID从数据库查询订单
var order = await _orderRepository.GetAsync(o => o.Id == id);
+
+ // 转换为OrderDto返回
return ObjectMapper.Map(order);
}
+
+ ///
+ /// 获取所有订单列表
+ ///
+ public async Task> GetListAsync()
+ {
+ // 查询所有订单
+ var orders = await _orderRepository.GetListAsync();
+
+ // 转换为OrderDto列表返回
+ return ObjectMapper.Map, List>(orders);
+ }
}
-}
+}
\ No newline at end of file