222
schangxiang@126.com
2025-05-09 21d4979c92c50a98c2a52b8d6758d4c026e5c41f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using CMS.Plugin.HIAWms.Domain;
using CMS.Plugin.HIAWms.Domain.MyExtension;
using CMS.Plugin.HIAWms.Domain.Shared.Enums;
using CMS.Plugin.HIAWms.Domain.WmsMaterial;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
 
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.MaterialCode)
                .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.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.Property(x => x.IsValid)
            .IsRequired()
            .HasComment("是否有效物料");
            b.Property(x => x.IsSelfMade)
       .IsRequired(false)
       .HasComment("数量");
 
            b.Property(x => x.Num)
       .IsRequired()
       .HasComment("是否有效物料");
            b.Property(x => x.SelfNum)
       .IsRequired(false)
       .HasComment("自有数量");
 
            // 索引配置
            b.HasIndex(x => x.MaterialCode).IsUnique(); // 物料编码唯一索引
            b.HasIndex(x => x.MaterialName);           // 物料名称普通索引
            b.HasIndex(x => x.PurchaseType);           // 采购类型索引(如需查询过滤)
            b.HasIndex(x => x.MaterialType);           // 物料类型索引(如需查询过滤)
 
            //配置通用字段
            b.ConfigureMyCmsEntity();
 
 
            //            b.Property(x => x.CreatorId)
            //  .HasMaxLength(36)
            //  .IsRequired(false)
            //  .HasComment("创建人ID");
            //            b.Property(x => x.CreatorName)
            //            .HasMaxLength(64)
            //            .IsRequired(false)
            //            .HasComment("创建人");
            //            b.Property(x => x.CreationTime)
            //.IsRequired()
            //.HasComment("创建时间");
 
            //            b.Property(x => x.LastModifierName)
            //         .HasMaxLength(64)
            //         .IsRequired(false)
            //         .HasComment("修改人");
            //            b.Property(x => x.LastModifierId)
            //      .HasMaxLength(36)
            //      .IsRequired(false)
            //      .HasComment("修改人ID");
            //            b.Property(x => x.LastModificationTime)
            //  .IsRequired(false)
            //  .HasComment("修改时间");
 
 
            //            b.Property(x => x.IsDeleted)
            //      .IsRequired()
            //      .HasComment("是否删除");
            //            b.Property(x => x.DeleterId)
            //      .HasMaxLength(36)
            //      .IsRequired(false)
            //      .HasComment("删除人ID");
            //            b.Property(x => x.DeletionTime)
            //  .IsRequired(false)
            //  .HasComment("删除时间");
 
 
            //            b.Property(x => x.ExtraProperties)
            //.IsRequired(false)
            //.HasComment("扩展属性");
            //            b.Property(x => x.ConcurrencyStamp)
            //.IsRequired(false)
            // .HasMaxLength(40)
            //.HasComment("并发戳");
            //            // 其他通用字段
            //            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.ApplyObjectExtensionMappings();
        });
    }
}