using Furion.DatabaseAccessor;
|
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel.DataAnnotations;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace FlexJobApi.Core
|
{
|
/// <summary>
|
/// 部门
|
/// </summary>
|
public class Department : CommonEntity<MasterDbContextLocator>, IEntityTypeBuilder<Department>, IIsDisabled
|
{
|
public Department()
|
{
|
Children = [];
|
}
|
|
/// <summary>
|
/// 上级Id
|
/// </summary>
|
public Guid? ParentId { get; set; }
|
|
/// <summary>
|
/// 上级
|
/// </summary>
|
public Department Parent { get; set; }
|
|
/// <summary>
|
/// 下级
|
/// </summary>
|
public List<Department> Children { get; set; }
|
|
/// <summary>
|
/// 部门路径
|
/// </summary>
|
public string Path { get; set; }
|
|
/// <summary>
|
/// 企业Id
|
/// </summary>
|
public Guid EnterpriseId { get; set; }
|
|
/// <summary>
|
/// 企业
|
/// </summary>
|
public Enterprise Enterprise { get; set; }
|
|
/// <summary>
|
/// 名称
|
/// </summary>
|
[Required]
|
public string Name { get; set; }
|
|
/// <summary>
|
/// 备注
|
/// </summary>
|
public string Remark { get; set; }
|
|
/// <summary>
|
/// 是否禁用
|
/// </summary>
|
public bool IsDisabled { get; set; }
|
|
public void Configure(EntityTypeBuilder<Department> entityBuilder, DbContext dbContext, Type dbContextLocator)
|
{
|
entityBuilder
|
.HasMany(x => x.Children)
|
.WithOne(x => x.Parent)
|
.HasForeignKey(x => x.ParentId)
|
.OnDelete(DeleteBehavior.ClientSetNull);
|
}
|
}
|
}
|