add: 师傅实体和服务类型

This commit is contained in:
于鹏
2025-10-06 15:58:11 +08:00
parent a1038f1b7b
commit ff0ec31ed0
18 changed files with 321 additions and 7 deletions

View File

@ -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]

View File

@ -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; }
}
}

View File

@ -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; }

View File

@ -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<ServiceCategoryDto> Children { get; set; } = new List<ServiceCategoryDto>();
}
}

View File

@ -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<Guid>
{
public string Name { get; set; }
public string Phone { get; set; }
public List<Guid> SkillCategoryIds { get; set; } = new(); // 擅长服务类型
}
}

View File

@ -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<ServiceCategoryDto> CreateAsync(CreateServiceCategoryDto input);
Task DeleteAsync(Guid id);
Task<List<ServiceCategoryDto>> GetTreeAsync();
}
}

View File

@ -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
{
}
}

View File

@ -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
{
}
}

View File

@ -15,5 +15,6 @@ public class AdminApplicationAutoMapperProfile : Profile
CreateMap<Order, OrderDto>();
//CreateMap<CreateOrderDto, Order>();
CreateMap<AddressDto, AddressInfo>();
CreateMap<ServiceCategoryDto, ServiceCategory>();
}
}

View File

@ -78,7 +78,7 @@ namespace KonSoft.Admin.ApplicationServices
// 生成订单号 TODO
var orderSN = "SN001";
var address = ObjectMapper.Map<AddressDto, AddressInfo>(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, OrderDto>(order);

View File

@ -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<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();
}
}
}

View File

@ -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<Worker, WorkerDto, Guid>, IWorkerAppService
{
public WorkerAppService(IRepository<Worker, Guid> repository) : base(repository)
{
}
}
}

View File

@ -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
{
/// <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;
}
}
}

View File

@ -36,7 +36,9 @@ namespace KonSoft.Admin.Entities
/// <summary>
/// 服务项目ID
/// </summary>
public Guid ServiceId { get; private set; }
public Guid ServiceCategoryId { get; private set; }
public virtual ServiceCategory ServiceCategory { get; private set; }
/// <summary>
/// 服务预约时间
@ -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;

View File

@ -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<Guid>
{
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();
}
}
}

View File

@ -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
{
/// <summary>
/// 家政人员
/// </summary>
public class Worker : FullAuditedAggregateRoot<Guid>
{
public string Name { get; private set; }
public string Phone { get; private set; }
public decimal Rating { get; private set; } // 评分
public List<Guid> SkillCategoryIds { get; private set; } = new List<Guid>();
public Worker() { }
public void UpdateRating(decimal newRating)
{
Rating = newRating;
}
public bool CanPerform(Guid serviceCategoryId)
{
return SkillCategoryIds.Contains(serviceCategoryId);
}
}
}

View File

@ -56,6 +56,8 @@ public class AdminDbContext :
#region
public DbSet<Order> Order { get; set; }
public DbSet<Worker> Worker { get; set; }
public DbSet<ServiceCategory> ServiceCategory { get; set; }
#endregion
public AdminDbContext(DbContextOptions<AdminDbContext> options)

View File

@ -18,7 +18,7 @@ namespace KonSoft.Admin.EntityFrameworkCore.Configures
builder.Entity<Order>(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<Worker>(b =>
{
b.ToTable(AdminConsts.DbTablePrefix + nameof(Worker) + AdminConsts.DbSchema);
});
builder.Entity<ServiceCategory>(b =>
{
b.ToTable(AdminConsts.DbTablePrefix + nameof(ServiceCategory) + AdminConsts.DbSchema);
});
}