From ff0ec31ed0937b327cda845985503227e16ba964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E9=B9=8F?= <1069269649@qq.com> Date: Mon, 6 Oct 2025 15:58:11 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E5=B8=88=E5=82=85=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E5=92=8C=E6=9C=8D=E5=8A=A1=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/CreateOrderDto.cs | 2 +- .../Dtos/CreateServiceCategoryDto.cs | 14 ++++ .../Dtos/OrderDto.cs | 2 +- .../Dtos/ServiceCategoryDto.cs | 17 +++++ .../Dtos/WorkerDto.cs | 17 +++++ .../IServiceCategoryAppService.cs | 16 ++++ .../IApplicationServices/IWorkerAppService.cs | 13 ++++ .../IWorkerAssignmentService.cs | 15 ++++ .../AdminApplicationAutoMapperProfile.cs | 1 + .../ApplicationServices/OrderAppService.cs | 2 +- .../ServiceCategoryAppService.cs | 75 +++++++++++++++++++ .../ApplicationServices/WorkerAppService.cs | 20 +++++ .../WorkerAssignmentService.cs | 27 +++++++ .../KonSoft.Admin.Domain/Entities/Order.cs | 8 +- .../Entities/ServiceCategory.cs | 46 ++++++++++++ .../KonSoft.Admin.Domain/Entities/Worker.cs | 34 +++++++++ .../EntityFrameworkCore/AdminDbContext.cs | 2 + ...licationDbContextModelBuilderExtensions.cs | 17 ++++- 18 files changed, 321 insertions(+), 7 deletions(-) create mode 100644 modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/CreateServiceCategoryDto.cs create mode 100644 modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/ServiceCategoryDto.cs create mode 100644 modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/WorkerDto.cs create mode 100644 modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IServiceCategoryAppService.cs create mode 100644 modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IWorkerAppService.cs create mode 100644 modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IWorkerAssignmentService.cs create mode 100644 modules/admin/src/KonSoft.Admin.Application/ApplicationServices/ServiceCategoryAppService.cs create mode 100644 modules/admin/src/KonSoft.Admin.Application/ApplicationServices/WorkerAppService.cs create mode 100644 modules/admin/src/KonSoft.Admin.Application/ApplicationServices/WorkerAssignmentService.cs create mode 100644 modules/admin/src/KonSoft.Admin.Domain/Entities/ServiceCategory.cs create mode 100644 modules/admin/src/KonSoft.Admin.Domain/Entities/Worker.cs diff --git a/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/CreateOrderDto.cs b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/CreateOrderDto.cs index 82a4b50..171abcf 100644 --- a/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/CreateOrderDto.cs +++ b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/CreateOrderDto.cs @@ -12,7 +12,7 @@ namespace KonSoft.Admin.Dtos [Required] public Guid CustomerId { get; set; } [Required] - public Guid ServiceId { get; set; } + public Guid ServiceCategoryId { get; set; } [Required] public DateTime ServiceTime { get; set; } [Required] diff --git a/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/CreateServiceCategoryDto.cs b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/CreateServiceCategoryDto.cs new file mode 100644 index 0000000..73acd6d --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/CreateServiceCategoryDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KonSoft.Admin.Dtos +{ + public class CreateServiceCategoryDto + { + public string Name { get; set; } + public Guid? ParentId { get; set; } + } +} diff --git a/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/OrderDto.cs b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/OrderDto.cs index 9a542bd..6d28e3b 100644 --- a/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/OrderDto.cs +++ b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/OrderDto.cs @@ -13,7 +13,7 @@ namespace KonSoft.Admin.Dtos public string OrderSN { get; set; } public Guid CustomerId { get; set; } public Guid? WorkerId { get; set; } - public Guid ServiceId { get; set; } + public ServiceCategoryDto? ServiceCategory { get; set; } public DateTime ServiceTime { get; set; } public OrderStatus Status { get; set; } public decimal Amount { get; set; } diff --git a/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/ServiceCategoryDto.cs b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/ServiceCategoryDto.cs new file mode 100644 index 0000000..27071cc --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/ServiceCategoryDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KonSoft.Admin.Dtos +{ + public class ServiceCategoryDto + { + public Guid Id { get; set; } + public string Name { get; set; } + public Guid? ParentId { get; set; } + public int Level { get; set; } + public List Children { get; set; } = new List(); + } +} diff --git a/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/WorkerDto.cs b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/WorkerDto.cs new file mode 100644 index 0000000..befee95 --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Application.Contracts/Dtos/WorkerDto.cs @@ -0,0 +1,17 @@ +using KonSoft.Admin.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; + +namespace KonSoft.Admin.Dtos +{ + public class WorkerDto : EntityDto + { + public string Name { get; set; } + public string Phone { get; set; } + public List SkillCategoryIds { get; set; } = new(); // 擅长服务类型 + } +} diff --git a/modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IServiceCategoryAppService.cs b/modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IServiceCategoryAppService.cs new file mode 100644 index 0000000..5db4a45 --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IServiceCategoryAppService.cs @@ -0,0 +1,16 @@ +using KonSoft.Admin.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KonSoft.Admin.IApplicationServices +{ + public interface IServiceCategoryAppService + { + Task CreateAsync(CreateServiceCategoryDto input); + Task DeleteAsync(Guid id); + Task> GetTreeAsync(); + } +} diff --git a/modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IWorkerAppService.cs b/modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IWorkerAppService.cs new file mode 100644 index 0000000..0d22702 --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IWorkerAppService.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; + +namespace KonSoft.Admin.IApplicationServices +{ + public interface IWorkerAppService : IApplicationService + { + } +} diff --git a/modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IWorkerAssignmentService.cs b/modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IWorkerAssignmentService.cs new file mode 100644 index 0000000..a832d6b --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Application.Contracts/IApplicationServices/IWorkerAssignmentService.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KonSoft.Admin.IApplicationServices +{ + public interface IWorkerAssignmentService + { + + + + } +} diff --git a/modules/admin/src/KonSoft.Admin.Application/AdminApplicationAutoMapperProfile.cs b/modules/admin/src/KonSoft.Admin.Application/AdminApplicationAutoMapperProfile.cs index de3045e..1fc6ee0 100644 --- a/modules/admin/src/KonSoft.Admin.Application/AdminApplicationAutoMapperProfile.cs +++ b/modules/admin/src/KonSoft.Admin.Application/AdminApplicationAutoMapperProfile.cs @@ -15,5 +15,6 @@ public class AdminApplicationAutoMapperProfile : Profile CreateMap(); //CreateMap(); CreateMap(); + CreateMap(); } } diff --git a/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/OrderAppService.cs b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/OrderAppService.cs index 238de99..5883752 100644 --- a/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/OrderAppService.cs +++ b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/OrderAppService.cs @@ -78,7 +78,7 @@ namespace KonSoft.Admin.ApplicationServices // 生成订单号 TODO var orderSN = "SN001"; var address = ObjectMapper.Map(input.Address); - var order = new Order(Guid.NewGuid(), orderSN, input.CustomerId, input.ServiceId, input.ServiceTime, input.Amount, address, input.Remark); + 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); diff --git a/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/ServiceCategoryAppService.cs b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/ServiceCategoryAppService.cs new file mode 100644 index 0000000..e3b5fa0 --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/ServiceCategoryAppService.cs @@ -0,0 +1,75 @@ +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 ServiceCategoryAppService : ApplicationService, IServiceCategoryAppService + { + private readonly IRepository _repository; + + + public ServiceCategoryAppService(IRepository repository) + { + _repository = repository; + } + + public async Task 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(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> GetTreeAsync() + { + var allCategories = await _repository.GetListAsync(); + + // 构建树 + var lookup = allCategories.ToDictionary(c => c.Id, c => ObjectMapper.Map(c)); + var rootList = new List(); + + + 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(); + } + } +} diff --git a/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/WorkerAppService.cs b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/WorkerAppService.cs new file mode 100644 index 0000000..5ca999c --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/WorkerAppService.cs @@ -0,0 +1,20 @@ +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, IWorkerAppService + { + public WorkerAppService(IRepository repository) : base(repository) + { + } + } +} diff --git a/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/WorkerAssignmentService.cs b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/WorkerAssignmentService.cs new file mode 100644 index 0000000..28283c8 --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/WorkerAssignmentService.cs @@ -0,0 +1,27 @@ +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 +{ + /// + /// 分配家政人员 TODO + /// + public class WorkerAssignmentService : ApplicationService, IWorkerAssignmentService + { + private readonly IRepository _workerRepository; + private readonly IRepository _orderRepository; + + public WorkerAssignmentService(IRepository workerRepository, IRepository orderRepository) + { + _workerRepository = workerRepository; + _orderRepository = orderRepository; + } + } +} diff --git a/modules/admin/src/KonSoft.Admin.Domain/Entities/Order.cs b/modules/admin/src/KonSoft.Admin.Domain/Entities/Order.cs index d3ac54a..d0d272f 100644 --- a/modules/admin/src/KonSoft.Admin.Domain/Entities/Order.cs +++ b/modules/admin/src/KonSoft.Admin.Domain/Entities/Order.cs @@ -36,7 +36,9 @@ namespace KonSoft.Admin.Entities /// /// 服务项目ID /// - public Guid ServiceId { get; private set; } + public Guid ServiceCategoryId { get; private set; } + + public virtual ServiceCategory ServiceCategory { get; private set; } /// /// 服务预约时间 @@ -74,12 +76,12 @@ namespace KonSoft.Admin.Entities protected Order() { } - public Order(Guid id, string orderSN, Guid customerId, Guid serviceId, DateTime serviceTime, decimal amount, AddressInfo address, string remark = null) + public Order(Guid id, string orderSN, Guid customerId, Guid serviceCategoryId, DateTime serviceTime, decimal amount, AddressInfo address, string remark = null) : base(id) { OrderSN = orderSN; CustomerId = customerId; - ServiceId = serviceId; + ServiceCategoryId = serviceCategoryId; ServiceTime = serviceTime; Amount = amount; Address = address; diff --git a/modules/admin/src/KonSoft.Admin.Domain/Entities/ServiceCategory.cs b/modules/admin/src/KonSoft.Admin.Domain/Entities/ServiceCategory.cs new file mode 100644 index 0000000..6bcb013 --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Domain/Entities/ServiceCategory.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities.Auditing; + +namespace KonSoft.Admin.Entities +{ + public class ServiceCategory : FullAuditedAggregateRoot + { + public string Name { get; private set; } + public Guid? ParentId { get; private set; } + public string Path { get; private set; } + public int Level { get; private set; } + + protected ServiceCategory() { } + + public ServiceCategory(Guid id, string name) + : base(id) + { + Name = name; + } + + public ServiceCategory(Guid id, string name, Guid? parentId = null, string path = null, int level = 0) : base(id) + { + Name = name; + ParentId = parentId; + Path = path ?? id.ToString(); + Level = level; + } + + + public void UpdateName(string name) => Name = name; + + + public void SetParent(ServiceCategory parent) + { + ParentId = parent?.Id; + Level = (parent?.Level ?? 0) + 1; + Path = parent != null ? $"{parent.Path}/{Id}" : Id.ToString(); + } + + + } +} diff --git a/modules/admin/src/KonSoft.Admin.Domain/Entities/Worker.cs b/modules/admin/src/KonSoft.Admin.Domain/Entities/Worker.cs new file mode 100644 index 0000000..94aa33f --- /dev/null +++ b/modules/admin/src/KonSoft.Admin.Domain/Entities/Worker.cs @@ -0,0 +1,34 @@ +using KonSoft.Admin.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities.Auditing; + +namespace KonSoft.Admin.Entities +{ + /// + /// 家政人员 + /// + public class Worker : FullAuditedAggregateRoot + { + public string Name { get; private set; } + public string Phone { get; private set; } + public decimal Rating { get; private set; } // 评分 + public List SkillCategoryIds { get; private set; } = new List(); + + public Worker() { } + + + public void UpdateRating(decimal newRating) + { + Rating = newRating; + } + + public bool CanPerform(Guid serviceCategoryId) + { + return SkillCategoryIds.Contains(serviceCategoryId); + } + } +} diff --git a/modules/admin/src/KonSoft.Admin.EntityFrameworkCore/EntityFrameworkCore/AdminDbContext.cs b/modules/admin/src/KonSoft.Admin.EntityFrameworkCore/EntityFrameworkCore/AdminDbContext.cs index f916b52..5eed71b 100644 --- a/modules/admin/src/KonSoft.Admin.EntityFrameworkCore/EntityFrameworkCore/AdminDbContext.cs +++ b/modules/admin/src/KonSoft.Admin.EntityFrameworkCore/EntityFrameworkCore/AdminDbContext.cs @@ -56,6 +56,8 @@ public class AdminDbContext : #region 订单 public DbSet Order { get; set; } + public DbSet Worker { get; set; } + public DbSet ServiceCategory { get; set; } #endregion public AdminDbContext(DbContextOptions options) diff --git a/modules/admin/src/KonSoft.Admin.EntityFrameworkCore/EntityFrameworkCore/Configures/ApplicationDbContextModelBuilderExtensions.cs b/modules/admin/src/KonSoft.Admin.EntityFrameworkCore/EntityFrameworkCore/Configures/ApplicationDbContextModelBuilderExtensions.cs index 030a2fa..ba7094d 100644 --- a/modules/admin/src/KonSoft.Admin.EntityFrameworkCore/EntityFrameworkCore/Configures/ApplicationDbContextModelBuilderExtensions.cs +++ b/modules/admin/src/KonSoft.Admin.EntityFrameworkCore/EntityFrameworkCore/Configures/ApplicationDbContextModelBuilderExtensions.cs @@ -18,7 +18,7 @@ namespace KonSoft.Admin.EntityFrameworkCore.Configures builder.Entity(b => { - b.ToTable(AdminConsts.DbTablePrefix + "Order" + AdminConsts.DbSchema); + b.ToTable(AdminConsts.DbTablePrefix + nameof(Order) + AdminConsts.DbSchema); b.OwnsOne(o => o.Address, a => { @@ -30,6 +30,21 @@ namespace KonSoft.Admin.EntityFrameworkCore.Configures }); }); + builder.Entity(b => + { + b.ToTable(AdminConsts.DbTablePrefix + nameof(Worker) + AdminConsts.DbSchema); + + + }); + + + builder.Entity(b => + { + b.ToTable(AdminConsts.DbTablePrefix + nameof(ServiceCategory) + AdminConsts.DbSchema); + + + }); + }