Merge pull request 'add: 师傅实体和服务类型' (#4) from dv_onion into master
Reviewed-on: #4
This commit is contained in:
@ -12,7 +12,7 @@ namespace KonSoft.Admin.Dtos
|
|||||||
[Required]
|
[Required]
|
||||||
public Guid CustomerId { get; set; }
|
public Guid CustomerId { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public Guid ServiceId { get; set; }
|
public Guid ServiceCategoryId { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime ServiceTime { get; set; }
|
public DateTime ServiceTime { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
|
|||||||
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,7 +13,7 @@ namespace KonSoft.Admin.Dtos
|
|||||||
public string OrderSN { get; set; }
|
public string OrderSN { get; set; }
|
||||||
public Guid CustomerId { get; set; }
|
public Guid CustomerId { get; set; }
|
||||||
public Guid? WorkerId { get; set; }
|
public Guid? WorkerId { get; set; }
|
||||||
public Guid ServiceId { get; set; }
|
public ServiceCategoryDto? ServiceCategory { get; set; }
|
||||||
public DateTime ServiceTime { get; set; }
|
public DateTime ServiceTime { get; set; }
|
||||||
public OrderStatus Status { get; set; }
|
public OrderStatus Status { get; set; }
|
||||||
public decimal Amount { get; set; }
|
public decimal Amount { get; set; }
|
||||||
|
|||||||
@ -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>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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(); // 擅长服务类型
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -15,5 +15,6 @@ public class AdminApplicationAutoMapperProfile : Profile
|
|||||||
CreateMap<Order, OrderDto>();
|
CreateMap<Order, OrderDto>();
|
||||||
//CreateMap<CreateOrderDto, Order>();
|
//CreateMap<CreateOrderDto, Order>();
|
||||||
CreateMap<AddressDto, AddressInfo>();
|
CreateMap<AddressDto, AddressInfo>();
|
||||||
|
CreateMap<ServiceCategoryDto, ServiceCategory>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,7 +78,7 @@ namespace KonSoft.Admin.ApplicationServices
|
|||||||
// 生成订单号 TODO
|
// 生成订单号 TODO
|
||||||
var orderSN = "SN001";
|
var orderSN = "SN001";
|
||||||
var address = ObjectMapper.Map<AddressDto, AddressInfo>(input.Address);
|
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);
|
await _orderRepository.InsertAsync(order);
|
||||||
return ObjectMapper.Map<Order, OrderDto>(order);
|
return ObjectMapper.Map<Order, OrderDto>(order);
|
||||||
|
|||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -36,7 +36,9 @@ namespace KonSoft.Admin.Entities
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务项目ID
|
/// 服务项目ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid ServiceId { get; private set; }
|
public Guid ServiceCategoryId { get; private set; }
|
||||||
|
|
||||||
|
public virtual ServiceCategory ServiceCategory { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务预约时间
|
/// 服务预约时间
|
||||||
@ -74,12 +76,12 @@ namespace KonSoft.Admin.Entities
|
|||||||
protected Order() { }
|
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)
|
: base(id)
|
||||||
{
|
{
|
||||||
OrderSN = orderSN;
|
OrderSN = orderSN;
|
||||||
CustomerId = customerId;
|
CustomerId = customerId;
|
||||||
ServiceId = serviceId;
|
ServiceCategoryId = serviceCategoryId;
|
||||||
ServiceTime = serviceTime;
|
ServiceTime = serviceTime;
|
||||||
Amount = amount;
|
Amount = amount;
|
||||||
Address = address;
|
Address = address;
|
||||||
|
|||||||
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
34
modules/admin/src/KonSoft.Admin.Domain/Entities/Worker.cs
Normal file
34
modules/admin/src/KonSoft.Admin.Domain/Entities/Worker.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -56,6 +56,8 @@ public class AdminDbContext :
|
|||||||
|
|
||||||
#region 订单
|
#region 订单
|
||||||
public DbSet<Order> Order { get; set; }
|
public DbSet<Order> Order { get; set; }
|
||||||
|
public DbSet<Worker> Worker { get; set; }
|
||||||
|
public DbSet<ServiceCategory> ServiceCategory { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public AdminDbContext(DbContextOptions<AdminDbContext> options)
|
public AdminDbContext(DbContextOptions<AdminDbContext> options)
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace KonSoft.Admin.EntityFrameworkCore.Configures
|
|||||||
|
|
||||||
builder.Entity<Order>(b =>
|
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 =>
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user