chore 优化代码
This commit is contained in:
		| @ -1,7 +1,4 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Text; | ||||
| using KonSoft.Admin.Localization; | ||||
| using KonSoft.Admin.Localization; | ||||
| using Volo.Abp.Application.Services; | ||||
|  | ||||
| namespace KonSoft.Admin; | ||||
| @ -14,4 +11,4 @@ public abstract class AdminAppService : ApplicationService | ||||
|     { | ||||
|         LocalizationResource = typeof(AdminResource); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -17,4 +17,4 @@ public class AdminApplicationAutoMapperProfile : Profile | ||||
|         CreateMap<AddressDto, AddressInfo>(); | ||||
|         CreateMap<ServiceCategoryDto, ServiceCategory>(); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -18,14 +18,11 @@ namespace KonSoft.Admin; | ||||
|     typeof(AbpTenantManagementApplicationModule), | ||||
|     typeof(AbpFeatureManagementApplicationModule), | ||||
|     typeof(AbpSettingManagementApplicationModule) | ||||
|     )] | ||||
| )] | ||||
| public class AdminApplicationModule : AbpModule | ||||
| { | ||||
|     public override void ConfigureServices(ServiceConfigurationContext context) | ||||
|     { | ||||
|         Configure<AbpAutoMapperOptions>(options => | ||||
|         { | ||||
|             options.AddMaps<AdminApplicationModule>(); | ||||
|         }); | ||||
|         Configure<AbpAutoMapperOptions>(options => { options.AddMaps<AdminApplicationModule>(); }); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -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); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,102 @@ | ||||
| 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; | ||||
|  | ||||
| public class ProductAppAppService(IProductRepository repository) : ApplicationService, IProductAppService | ||||
| { | ||||
|     private readonly IProductRepository repository = repository; | ||||
|  | ||||
|     /// <summary> | ||||
|     ///     创建产品 | ||||
|     /// </summary> | ||||
|     public async Task CreateAsync(CreateProductDto input) | ||||
|     { | ||||
|         var id = Guid.NewGuid(); | ||||
|         var product = new Product(id, input.Name, input.Code, input.Price, input.Description, input.Type, | ||||
|             input.ParentId, input.Status, input.Order); | ||||
|         await repository.InsertAsync(product); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     ///     删除 | ||||
|     /// </summary> | ||||
|     public async Task DeleteAsync(Guid id) | ||||
|     { | ||||
|         await repository.DeleteAsync(x => x.Id == id); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     ///     查询 | ||||
|     /// </summary> | ||||
|     public async Task<ProductDto> GetAsync(Guid id) | ||||
|     { | ||||
|         var product = await repository.GetAsync(x => x.Id == id); | ||||
|         return ObjectMapper.Map<Product, ProductDto>(product); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     ///     查询集合 | ||||
|     /// </summary> | ||||
|     /// <param name="input"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task<PagedResultDto<ProductDto>> GetListAsync(PagedResultRequestDto input) | ||||
|     { | ||||
|         var query = await repository.GetPageRootListAsync(input.SkipCount, input.MaxResultCount, | ||||
|             x => x.ParentId == null); | ||||
|         var all = await repository.GetListAsync(x => x.ParentId != null); | ||||
|         foreach (var item in query) | ||||
|         { | ||||
|             BuildChildren(item, all); | ||||
|         } | ||||
|  | ||||
|         var totalCount = await repository.CountAsync(x => x.ParentId == null); | ||||
|  | ||||
|         var productDtos = ObjectMapper.Map<List<Product>, List<ProductDto>>(query); | ||||
|  | ||||
|         return new PagedResultDto<ProductDto>(totalCount, productDtos); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     ///     修改 | ||||
|     /// </summary> | ||||
|     /// <param name="input"></param> | ||||
|     /// <returns></returns> | ||||
|     public async Task UpdateAsync(UpdateProductDto input) | ||||
|     { | ||||
|         // 根据ID查询订单,如果不存在则抛出异常【修改前端必然看到了,数据若查不到提示自定义异常信息】 | ||||
|         var order = await repository.FindAsync(o => o.Id == input.Id) ?? | ||||
|                     throw new BusinessException("商品找不到").WithData("Id", input.Id); | ||||
|  | ||||
|         // 将输入的DTO字段映射到订单实体 | ||||
|         ObjectMapper.Map(input, order); | ||||
|  | ||||
|         // 更新订单 | ||||
|         await repository.UpdateAsync(order); | ||||
|     } | ||||
|  | ||||
|     private static void BuildChildren(Product parent, List<Product> all) | ||||
|     { | ||||
|         var children = all | ||||
|             .Where(x => x.ParentId == parent.Id) | ||||
|             .OrderBy(x => x.Order) | ||||
|             .ToList(); | ||||
|  | ||||
|         parent.Children = children; | ||||
|  | ||||
|         foreach (var child in children) | ||||
|         { | ||||
|             BuildChildren(child, all); // 递归 | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,100 +0,0 @@ | ||||
| using KonSoft.Admin.Dtos; | ||||
| using KonSoft.Admin.Entities; | ||||
| using KonSoft.Admin.IApplicationServices; | ||||
| using KonSoft.Admin.Repositories; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Threading.Tasks; | ||||
| using Volo.Abp; | ||||
| using Volo.Abp.Application.Dtos; | ||||
| using Volo.Abp.Application.Services; | ||||
| using Volo.Abp.Domain.Repositories; | ||||
|  | ||||
| namespace KonSoft.Admin.ApplicationServices | ||||
| { | ||||
|     public class ProductAppService(IProductRepository repository) : ApplicationService, IProductService | ||||
|     { | ||||
|         private readonly IProductRepository repository = repository; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// 创建产品 | ||||
|         /// </summary> | ||||
|         public async Task CreateAsync(CreateProductDto input) | ||||
|         { | ||||
|             var id = Guid.NewGuid(); | ||||
|             var product = new Product(id, input.Name, input.Code, input.Price, input.Description, input.Type, input.ParentId, input.Status, input.Order); | ||||
|             await repository.InsertAsync(product); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// 删除 | ||||
|         /// </summary> | ||||
|         public async Task DeleteAsync(Guid id) | ||||
|         { | ||||
|             await repository.DeleteAsync(x => x.Id == id); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// 查询 | ||||
|         /// </summary> | ||||
|         public async Task<ProductDto> GetAsync(Guid id) | ||||
|         { | ||||
|             var product = await repository.GetAsync(x => x.Id == id); | ||||
|             return ObjectMapper.Map<Product, ProductDto>(product); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// 查询集合 | ||||
|         /// </summary> | ||||
|         /// <param name="input"></param> | ||||
|         /// <returns></returns> | ||||
|         public async Task<PagedResultDto<ProductDto>> GetListAsync(PagedResultRequestDto input) | ||||
|         { | ||||
|             var query = await repository.GetPageRootListAsync(input.SkipCount, input.MaxResultCount, x => x.ParentId == null); | ||||
|             var all = await repository.GetListAsync(x => x.ParentId != null); | ||||
|             foreach (var item in query) | ||||
|             { | ||||
|                 BuildChildren(item, all); | ||||
|             } | ||||
|             var totalCount = await repository.CountAsync(x => x.ParentId == null); | ||||
|  | ||||
|             var productDtos = ObjectMapper.Map<List<Product>, List<ProductDto>>(query); | ||||
|  | ||||
|             return new PagedResultDto<ProductDto>(totalCount, productDtos); | ||||
|         } | ||||
|  | ||||
|         private static void BuildChildren(Product parent, List<Product> all) | ||||
|         { | ||||
|             var children = all | ||||
|                 .Where(x => x.ParentId == parent.Id) | ||||
|                 .OrderBy(x => x.Order) | ||||
|                 .ToList(); | ||||
|  | ||||
|             parent.Children = children; | ||||
|  | ||||
|             foreach (var child in children) | ||||
|             { | ||||
|                 BuildChildren(child, all); // 递归 | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// 修改 | ||||
|         /// </summary> | ||||
|         /// <param name="input"></param> | ||||
|         /// <returns></returns> | ||||
|         public async Task UpdateAsync(UpdateProductDto input) | ||||
|         { | ||||
|             // 根据ID查询订单,如果不存在则抛出异常【修改前端必然看到了,数据若查不到提示自定义异常信息】 | ||||
|             var order = await repository.FindAsync(o => o.Id == input.Id) ?? | ||||
|                 throw new BusinessException("商品找不到").WithData("Id", input.Id); | ||||
|  | ||||
|             // 将输入的DTO字段映射到订单实体 | ||||
|             ObjectMapper.Map(input, order); | ||||
|  | ||||
|             // 更新订单 | ||||
|             await repository.UpdateAsync(order); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,75 +1,77 @@ | ||||
| using KonSoft.Admin.Dtos; | ||||
| using KonSoft.Admin.Entities; | ||||
| using KonSoft.Admin.IApplicationServices; | ||||
| using System; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| using KonSoft.Admin.Dtos; | ||||
| using KonSoft.Admin.Entities; | ||||
| using KonSoft.Admin.IApplicationServices; | ||||
| using Volo.Abp.Application.Services; | ||||
| using Volo.Abp.Domain.Repositories; | ||||
|  | ||||
| namespace KonSoft.Admin.ApplicationServices | ||||
| namespace KonSoft.Admin.ApplicationServices; | ||||
|  | ||||
| public class ServiceCategoryAppService : ApplicationService, IServiceCategoryAppService | ||||
| { | ||||
|     public class ServiceCategoryAppService : ApplicationService, IServiceCategoryAppService | ||||
|     private readonly IRepository<ServiceCategory, Guid> _repository; | ||||
|  | ||||
|  | ||||
|     public ServiceCategoryAppService(IRepository<ServiceCategory, Guid> repository) | ||||
|     { | ||||
|         private readonly IRepository<ServiceCategory, Guid> _repository; | ||||
|  | ||||
|  | ||||
|         public ServiceCategoryAppService(IRepository<ServiceCategory, Guid> repository) | ||||
|         { | ||||
|             _repository = repository; | ||||
|         } | ||||
|  | ||||
|         public async Task<ServiceCategoryDto> CreateAsync(CreateServiceCategoryDto input) | ||||
|         { | ||||
|             ServiceCategory parent = null; | ||||
|             if (input.ParentId.HasValue) | ||||
|             { | ||||
|                 parent = await _repository.GetAsync(input.ParentId.Value); | ||||
|             } | ||||
|  | ||||
|             var category = new ServiceCategory(Guid.NewGuid(), input.Name); | ||||
|             category.SetParent(parent); | ||||
|  | ||||
|  | ||||
|             await _repository.InsertAsync(category); | ||||
|  | ||||
|  | ||||
|             return ObjectMapper.Map<ServiceCategory, ServiceCategoryDto>(category); | ||||
|         } | ||||
|  | ||||
|         public async Task DeleteAsync(Guid id) | ||||
|         { | ||||
|             var hasChildren = await _repository.AnyAsync(c => c.ParentId == id); | ||||
|             if (hasChildren) throw new InvalidOperationException("存在子节点无法删除!"); | ||||
|  | ||||
|  | ||||
|             await _repository.DeleteAsync(o => o.Id == id); | ||||
|         } | ||||
|  | ||||
|         public async Task<List<ServiceCategoryDto>> GetTreeAsync() | ||||
|         { | ||||
|             var allCategories = await _repository.GetListAsync(); | ||||
|  | ||||
|             // 构建树 | ||||
|             var lookup = allCategories.ToDictionary(c => c.Id, c => ObjectMapper.Map<ServiceCategory, ServiceCategoryDto>(c)); | ||||
|             var rootList = new List<ServiceCategoryDto>(); | ||||
|  | ||||
|  | ||||
|             foreach (var dto in lookup.Values) | ||||
|             { | ||||
|                 if (dto.ParentId.HasValue && lookup.ContainsKey(dto.ParentId.Value)) | ||||
|                 { | ||||
|                     lookup[dto.ParentId.Value].Children.Add(dto); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     rootList.Add(dto); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             return rootList.OrderBy(c => c.Name).ToList(); | ||||
|         } | ||||
|         _repository = repository; | ||||
|     } | ||||
| } | ||||
|  | ||||
|     public async Task<ServiceCategoryDto> CreateAsync(CreateServiceCategoryDto input) | ||||
|     { | ||||
|         ServiceCategory parent = null; | ||||
|         if (input.ParentId.HasValue) | ||||
|         { | ||||
|             parent = await _repository.GetAsync(input.ParentId.Value); | ||||
|         } | ||||
|  | ||||
|         var category = new ServiceCategory(Guid.NewGuid(), input.Name); | ||||
|         category.SetParent(parent); | ||||
|  | ||||
|  | ||||
|         await _repository.InsertAsync(category); | ||||
|  | ||||
|  | ||||
|         return ObjectMapper.Map<ServiceCategory, ServiceCategoryDto>(category); | ||||
|     } | ||||
|  | ||||
|     public async Task DeleteAsync(Guid id) | ||||
|     { | ||||
|         var hasChildren = await _repository.AnyAsync(c => c.ParentId == id); | ||||
|         if (hasChildren) | ||||
|         { | ||||
|             throw new InvalidOperationException("存在子节点无法删除!"); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         await _repository.DeleteAsync(o => o.Id == id); | ||||
|     } | ||||
|  | ||||
|     public async Task<List<ServiceCategoryDto>> GetTreeAsync() | ||||
|     { | ||||
|         var allCategories = await _repository.GetListAsync(); | ||||
|  | ||||
|         // 构建树 | ||||
|         var lookup = | ||||
|             allCategories.ToDictionary(c => c.Id, c => ObjectMapper.Map<ServiceCategory, ServiceCategoryDto>(c)); | ||||
|         var rootList = new List<ServiceCategoryDto>(); | ||||
|  | ||||
|  | ||||
|         foreach (var dto in lookup.Values) | ||||
|         { | ||||
|             if (dto.ParentId.HasValue && lookup.ContainsKey(dto.ParentId.Value)) | ||||
|             { | ||||
|                 lookup[dto.ParentId.Value].Children.Add(dto); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 rootList.Add(dto); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return rootList.OrderBy(c => c.Name).ToList(); | ||||
|     } | ||||
| } | ||||
| @ -1,20 +0,0 @@ | ||||
| using KonSoft.Admin.Dtos; | ||||
| using KonSoft.Admin.Entities; | ||||
| using KonSoft.Admin.IApplicationServices; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| using Volo.Abp.Application.Services; | ||||
| using Volo.Abp.Domain.Repositories; | ||||
|  | ||||
| namespace KonSoft.Admin.ApplicationServices | ||||
| { | ||||
|     public class WorkerAppService : CrudAppService<Worker, WorkerDto, Guid>, IWorkerAppService | ||||
|     { | ||||
|         public WorkerAppService(IRepository<Worker, Guid> repository) : base(repository) | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,27 +0,0 @@ | ||||
| using KonSoft.Admin.Entities; | ||||
| using KonSoft.Admin.IApplicationServices; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| using Volo.Abp.Application.Services; | ||||
| using Volo.Abp.Domain.Repositories; | ||||
|  | ||||
| namespace KonSoft.Admin.ApplicationServices | ||||
| { | ||||
|     /// <summary> | ||||
|     /// 分配家政人员 TODO | ||||
|     /// </summary> | ||||
|     public class WorkerAssignmentService : ApplicationService, IWorkerAssignmentService | ||||
|     { | ||||
|         private readonly IRepository<Worker, Guid> _workerRepository; | ||||
|         private readonly IRepository<Order, Guid> _orderRepository; | ||||
|  | ||||
|         public WorkerAssignmentService(IRepository<Worker, Guid> workerRepository, IRepository<Order, Guid> orderRepository) | ||||
|         { | ||||
|             _workerRepository = workerRepository; | ||||
|             _orderRepository = orderRepository; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,2 +1,3 @@ | ||||
| using System.Runtime.CompilerServices; | ||||
| [assembly:InternalsVisibleToAttribute("KonSoft.Admin.Application.Tests")] | ||||
|  | ||||
| [assembly: InternalsVisibleToAttribute("KonSoft.Admin.Application.Tests")] | ||||
		Reference in New Issue
	
	Block a user