chore 优化代码

This commit is contained in:
2025-10-16 10:30:51 +08:00
parent f1c609b4be
commit 1f5bc3e971
367 changed files with 2705 additions and 3083 deletions

View File

@ -1,165 +1,166 @@
using KonSoft.Admin.Dtos;
using KonSoft.Admin.Entities;
using KonSoft.Admin.IApplicationServices;
using KonSoft.Admin.Repositories;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using KonSoft.Admin.Dtos;
using KonSoft.Admin.Entities;
using KonSoft.Admin.IApplicationServices;
using KonSoft.Admin.IRepositories;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace KonSoft.Admin.ApplicationServices
namespace KonSoft.Admin.ApplicationServices;
public class OrderAppService(IOrderRepository orderRepository) : ApplicationService, IOrderAppService
{
public class OrderAppService(IOrderRepository orderRepository) : ApplicationService, IOrderAppService
private readonly IOrderRepository _orderRepository = orderRepository;
/// <summary>
/// 分配师傅
/// </summary>
/// <param name="orderId"></param>
/// <param name="workerId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task AssignAsync(Guid orderId, Guid workerId)
{
private readonly IOrderRepository _orderRepository = orderRepository;
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.AssignWorker(workerId);
}
/// <summary>
/// 分配师傅
/// </summary>
/// <param name="orderId"></param>
/// <param name="workerId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task AssignAsync(Guid orderId, Guid workerId)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.AssignWorker(workerId);
}
/// <summary>
/// 取消订单
/// </summary>
/// <param name="orderId"></param>
/// <param name="reason"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task CancelAsync(Guid orderId, string reason)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.Cancel(reason);
}
/// <summary>
/// 取消订单
/// </summary>
/// <param name="orderId"></param>
/// <param name="reason"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task CancelAsync(Guid orderId, string reason)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.Cancel(reason);
}
/// <summary>
/// 完成订单
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task CompleteServiceAsync(Guid orderId)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.CompleteService();
}
/// <summary>
/// 完成订单
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task CompleteServiceAsync(Guid orderId)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.CompleteService();
}
/// <summary>
/// 确认订单
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task ConfirmAsync(Guid orderId)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.ConfirmCompletion();
}
/// <summary>
/// 确认订单
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task ConfirmAsync(Guid orderId)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.ConfirmCompletion();
}
/// <summary>
/// 创建订单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<OrderDto> CreateAsync(CreateOrderDto input)
{
// 生成订单号 TODO
var orderSN = "SN001";
var address = ObjectMapper.Map<AddressDto, AddressInfo>(input.Address);
var order = new Order(Guid.NewGuid(), orderSN, input.CustomerId, input.ServiceCategoryId, input.ServiceTime,
input.Amount, address, input.Remark);
/// <summary>
/// 创建订单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<OrderDto> CreateAsync(CreateOrderDto input)
{
// 生成订单号 TODO
var orderSN = "SN001";
var address = ObjectMapper.Map<AddressDto, AddressInfo>(input.Address);
var order = new Order(Guid.NewGuid(), orderSN, input.CustomerId, input.ServiceCategoryId, input.ServiceTime, input.Amount, address, input.Remark);
await _orderRepository.InsertAsync(order);
return ObjectMapper.Map<Order, OrderDto>(order);
}
await _orderRepository.InsertAsync(order);
return ObjectMapper.Map<Order, OrderDto>(order);
}
/// <summary>
/// 根据订单ID删除订单
/// </summary>
/// <param name="id">订单ID</param>
public async Task DeleteAsync(params Guid[] ids)
{
// 根据ID删除订单
await _orderRepository.DeleteAsync(x => ids.Contains(x.Id));
}
/// <summary>
/// 根据订单ID删除订单
/// </summary>
/// <param name="id">订单ID</param>
public async Task DeleteAsync(params Guid[] ids)
{
// 根据ID删除订单
await _orderRepository.DeleteAsync(x => ids.Contains(x.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);
/// <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);
// 将输入的DTO字段映射到订单实体
ObjectMapper.Map(input, order);
// 更新订单
await _orderRepository.UpdateAsync(order);
}
// 更新订单
await _orderRepository.UpdateAsync(order);
}
/// <summary>
/// 支付
/// </summary>
/// <param name="orderId"></param>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public Task<OrderDto> PayAsync(Guid orderId, PayOrderDto input)
{
throw new NotImplementedException();
}
/// <summary>
/// 支付
/// </summary>
/// <param name="orderId"></param>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public Task<OrderDto> PayAsync(Guid orderId, PayOrderDto input)
{
throw new NotImplementedException();
}
/// <summary>
/// 开始订单
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task StartServiceAsync(Guid orderId)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.StartService();
}
/// <summary>
/// 开始订单
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task StartServiceAsync(Guid orderId)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
order.StartService();
}
/// <summary>
/// 根据订单ID获取单个订单
/// </summary>
public async Task<OrderDto> GetAsync(Guid id)
{
// 根据ID从数据库查询订单
var order = await _orderRepository.GetAsync(o => o.Id == id);
/// <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);
}
// 转换为OrderDto返回
return ObjectMapper.Map<Order, OrderDto>(order);
}
/// <summary>
/// 获取所有订单列表
/// </summary>
public async Task<PagedResultDto<OrderDto>> GetListAsync(PagedResultRequestDto input)
{
// 查询所有订单
var orders = await _orderRepository.GetPagedListAsync(input.SkipCount, input.MaxResultCount, "Id");
/// <summary>
/// 获取所有订单列表
/// </summary>
public async Task<PagedResultDto<OrderDto>> GetListAsync(PagedResultRequestDto input)
{
// 查询所有订单
var orders = await _orderRepository.GetPagedListAsync(input.SkipCount, input.MaxResultCount, "Id");
var totalCount = await _orderRepository.CountAsync();
var totalCount = await _orderRepository.CountAsync();
var orderDtos = ObjectMapper.Map<List<Order>, List<OrderDto>>(orders);
var orderDtos = ObjectMapper.Map<List<Order>, List<OrderDto>>(orders);
return new PagedResultDto<OrderDto>(totalCount, orderDtos);
}
return new PagedResultDto<OrderDto>(totalCount, orderDtos);
}
}