using CMS.Plugin.HIAWms.Domain;
|
using CMS.Plugin.HIAWms.Domain.WmsMaterials;
|
using CMS.Plugin.HIAWms.Domain.Shared.WmsMaterials;
|
using Microsoft.EntityFrameworkCore;
|
using Volo.Abp;
|
using Volo.Abp.EntityFrameworkCore.Modeling;
|
using CMS.Plugin.HIAWms.Domain.Shared.Enums;
|
|
namespace CMS.Plugin.HIAWms.EntityFrameworkCore.Extensions;
|
|
/// <summary>
|
/// EfCore扩展
|
/// </summary>
|
public static partial class CMSPluginEfCoreExtensions
|
{
|
/// <summary>
|
/// Includes the details.
|
/// </summary>
|
/// <param name="queryable">The queryable.</param>
|
/// <param name="include">if set to <c>true</c> [include].</param>
|
/// <returns></returns>
|
public static IQueryable<WmsMaterial> IncludeDetails(this IQueryable<WmsMaterial> queryable, bool include = true)
|
{
|
if (!include)
|
{
|
return queryable;
|
}
|
|
return queryable;
|
}
|
|
/// <summary>
|
/// Configures the wmsmaterial.
|
/// </summary>
|
/// <param name="builder">The builder.</param>
|
public static void ConfigureWmsMaterial(this ModelBuilder builder)
|
{
|
Check.NotNull(builder, nameof(builder));
|
|
builder.Entity<WmsMaterial>(b =>
|
{
|
// 配置表名和注释
|
b.ToTable((CMSPluginDbProperties.DbTablePrefix + "_WmsMaterials").ToLower(),
|
CMSPluginDbProperties.DbSchema)
|
.HasComment("物料基础信息表");
|
|
b.ConfigureByConvention();
|
|
// 主键配置(FullAuditedAggregateRoot<Guid> 已默认包含 Id)
|
b.HasKey(x => x.Id);
|
|
// 字段配置
|
b.Property(x => x.MaterialNo)
|
.HasMaxLength(64)
|
.IsRequired()
|
.HasComment("物料编码(唯一标识)");
|
|
b.Property(x => x.MaterialName)
|
.HasMaxLength(128)
|
.IsRequired()
|
.HasComment("物料名称");
|
|
b.Property(x => x.PurchaseType)
|
.HasComment("采购类型(枚举值)");
|
|
b.Property(x => x.MaterialType)
|
.HasComment("物料类型(枚举值)");
|
|
b.Property(x => x.PrimaryUnit)
|
.HasMaxLength(20)
|
.HasComment("主单位(如:kg、m、个)");
|
|
b.Property(x => x.Standard)
|
.HasMaxLength(128)
|
.HasComment("规格/标准(如:GB/T 8163-2018)");
|
|
b.Property(x => x.OuterDiameter)
|
.HasColumnType("decimal(18,2)")
|
.HasComment("外径(单位:mm)");
|
|
b.Property(x => x.WallThickness)
|
.HasColumnType("decimal(18,2)")
|
.HasComment("壁厚(单位:mm)");
|
|
b.Property(x => x.MaterialQuality)
|
.HasMaxLength(64)
|
.HasComment("材质(如:304不锈钢)");
|
|
b.Property(x => x.Length)
|
.HasColumnType("decimal(18,2)")
|
.HasComment("长度(单位:m)");
|
|
b.Property(x => x.IsMainBranch)
|
.HasDefaultValue(YesNoEnum.N)
|
.HasComment("是否为主支管");
|
|
b.Property(x => x.Factory)
|
.HasMaxLength(64)
|
.HasComment("生产工厂");
|
|
b.Property(x => x.Certification)
|
.HasMaxLength(128)
|
.HasComment("证书编号");
|
b.Property(x => x.MaterialModel)
|
.HasMaxLength(128)
|
.HasComment("型号");
|
|
// 冗余字段配置
|
b.Property(x => x.RedundantField1)
|
.HasMaxLength(256)
|
.IsRequired(false)
|
.HasComment("冗余字段1 - 预留扩展用途");
|
|
b.Property(x => x.RedundantField2)
|
.HasMaxLength(256)
|
.IsRequired(false)
|
.HasComment("冗余字段2 - 预留扩展用途");
|
|
b.Property(x => x.RedundantField3)
|
.HasMaxLength(256)
|
.IsRequired(false)
|
.HasComment("冗余字段3 - 预留扩展用途");
|
|
// 其他通用字段
|
b.Property(x => x.Sort)
|
.HasDefaultValue(0)
|
.HasComment("排序");
|
|
b.Property(x => x.Remark)
|
.HasMaxLength(500)
|
.IsRequired(false)
|
.HasComment("备注");
|
|
b.Property(x => x.IsDisabled)
|
.IsRequired(false)
|
.HasDefaultValue(false)
|
.HasComment("是否禁用");
|
|
// 索引配置
|
b.HasIndex(x => x.MaterialNo).IsUnique(); // 物料编码唯一索引
|
b.HasIndex(x => x.MaterialName); // 物料名称普通索引
|
b.HasIndex(x => x.PurchaseType); // 采购类型索引(如需查询过滤)
|
b.HasIndex(x => x.MaterialType); // 物料类型索引(如需查询过滤)
|
|
b.ApplyObjectExtensionMappings();
|
});
|
}
|
}
|