266 lines
8.9 KiB
C#
266 lines
8.9 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Debug;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using WMS.Web.Domain.Entitys;
|
|
using WMS.Web.Repositories.Configuration.Log;
|
|
|
|
namespace WMS.Web.Repositories.Configuration
|
|
{
|
|
/// <summary>
|
|
/// db上下文
|
|
/// </summary>
|
|
public class RepositoryDbContext : DbContext
|
|
{
|
|
[Obsolete]
|
|
public readonly LoggerFactory LoggerFactory = new LoggerFactory(new[] { new DebugLoggerProvider() });
|
|
public RepositoryDbContext(DbContextOptions<RepositoryDbContext> options) : base(options)
|
|
{
|
|
}
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
LoggerFactory.AddProvider(new EFCoreLoggerProvider());
|
|
base.OnConfiguring(optionsBuilder);
|
|
optionsBuilder.UseLoggerFactory(LoggerFactory).EnableSensitiveDataLogging();
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
|
|
//改箱
|
|
builder.Entity<ChangeBoxRecord>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_changebox_record");
|
|
ent.HasKey(x => x.Id);
|
|
|
|
ent.Property(f => f.SerialNumbers).HasConversion(
|
|
v => JsonConvert.SerializeObject(v),
|
|
v => JsonConvert.DeserializeObject<List<string>>(v));
|
|
});
|
|
//移箱
|
|
builder.Entity<MoveBoxRecord>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_movebox_record");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
|
|
//序列号操作记录
|
|
builder.Entity<SerialNumberOperate>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_serialnumberoperate");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
|
|
//序列号操作记录
|
|
builder.Entity<ErpOpsSyncDate>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_sync_date");
|
|
});
|
|
|
|
|
|
#region 出库单
|
|
builder.Entity<OutStock>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_outstock");
|
|
ent.HasKey(x => x.Id);
|
|
|
|
ent.HasMany(p => p.Details)
|
|
.WithOne()
|
|
.HasForeignKey(p => p.Fid)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
builder.Entity<OutStockDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_outstock_details");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
#endregion
|
|
|
|
#region 出库任务单
|
|
builder.Entity<OutStockTask>(ent =>
|
|
{
|
|
ent.ToTable("t_erp_outstock_task");
|
|
ent.HasKey(x => x.Id);
|
|
|
|
ent.HasMany(p => p.Details)
|
|
.WithOne()
|
|
.HasForeignKey(p => p.Fid)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
builder.Entity<OutStockTaskDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_erp_outstock_task_details");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
#endregion
|
|
|
|
#region 盘点单
|
|
builder.Entity<TakeStock>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_takestock");
|
|
ent.HasKey(x => x.Id);
|
|
|
|
//ent.HasMany(p => p.Details)
|
|
// .WithOne()
|
|
// .HasForeignKey(p => p.Fid)
|
|
// .OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
builder.Entity<TakeStockDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_takestock_details");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
#endregion
|
|
|
|
#region 入库单
|
|
builder.Entity<InStock>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_instock");
|
|
ent.HasKey(x => x.Id);
|
|
|
|
ent.HasMany(p => p.Details)
|
|
.WithOne()
|
|
.HasForeignKey(p => p.Fid)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
builder.Entity<InStockDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_instock_details");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
# endregion
|
|
|
|
#region 入库任务单
|
|
builder.Entity<InStockTask>(ent =>
|
|
{
|
|
ent.ToTable("t_erp_instock_task");
|
|
ent.HasKey(x => x.Id);
|
|
ent.HasMany(p => p.Details)
|
|
.WithOne()
|
|
.HasForeignKey(p => p.Fid)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
ent.HasMany(p => p.Boxs)
|
|
.WithOne()
|
|
.HasForeignKey(p => p.TaskId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
builder.Entity<InStockTaskBox>(ent =>
|
|
{
|
|
ent.ToTable("t_erp_instock_task_box");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
builder.Entity<InStockTaskDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_erp_instock_task_details");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
#endregion
|
|
|
|
#region 出入库回退记录
|
|
builder.Entity<BackRecord>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_back_record");
|
|
ent.HasKey(x => x.Id);
|
|
|
|
ent.HasMany(p => p.Details)
|
|
.WithOne()
|
|
.HasForeignKey(p => p.Fid)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
builder.Entity<BackRecordDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_back_record_details");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
#endregion
|
|
|
|
#region 箱库存
|
|
builder.Entity<BoxInventory>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_box_inventory");
|
|
ent.HasKey(x => x.Id);
|
|
|
|
ent.HasMany(p => p.Details)
|
|
.WithOne()
|
|
.HasForeignKey(p => p.Fid)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
builder.Entity<BoxInventoryDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_box_inventory_details");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
# endregion
|
|
|
|
#region 即时库存相关
|
|
builder.Entity<InventoryDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_inventory_details");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
builder.Entity<InventoryInOutDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_wms_inventory_inout_details");
|
|
ent.HasKey(x => x.Id);
|
|
});
|
|
#endregion
|
|
|
|
#region 箱信息
|
|
builder.Entity<Box>(ent =>
|
|
{
|
|
ent.ToTable("t_ops_box");
|
|
ent.HasKey(x => x.Id);
|
|
|
|
ent.HasMany(p => p.Details)
|
|
.WithOne()
|
|
.HasForeignKey(p => p.Fid)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
builder.Entity<BoxDetails>(ent =>
|
|
{
|
|
ent.ToTable("t_ops_box_details");
|
|
ent.HasKey(x => x.Id);
|
|
|
|
ent.Property(f => f.SerialNumbers).HasConversion(
|
|
v => JsonConvert.SerializeObject(v),
|
|
v => JsonConvert.DeserializeObject<List<string>>(v));
|
|
});
|
|
#endregion
|
|
|
|
|
|
|
|
base.OnModelCreating(builder);
|
|
}
|
|
|
|
public DbSet<ErpOpsSyncDate> ErpOpsSyncDate { get; set; }
|
|
public DbSet<SerialNumberOperate> SerialNumberOperate { get; set; }
|
|
public DbSet<ChangeBoxRecord> ChangeBoxRecord { get; set; }
|
|
public DbSet<MoveBoxRecord> MoveBoxRecord { get; set; }
|
|
public DbSet<OutStock> OutStock { get; set; }
|
|
public DbSet<OutStockTask> OutStockTask { get; set; }
|
|
public DbSet<TakeStock> TakeStock { get; set; }
|
|
public DbSet<OutStockDetails> OutStockDetails { get; set; }
|
|
public DbSet<OutStockTaskDetails> OutStockTaskDetails { get; set; }
|
|
public DbSet<TakeStockDetails> TakeStockDetails { get; set; }
|
|
public DbSet<InStock> Instock { get; set; }
|
|
public DbSet<InStockDetails> InStockDetails { get; set; }
|
|
public DbSet<InStockTask> InStockTask { get; set; }
|
|
public DbSet<InStockTaskBox> InstockTaskBox { get; set; }
|
|
public DbSet<InStockTaskDetails> InStockTaskDetails { get; set; }
|
|
public DbSet<BackRecord> BackRecord { get; set; }
|
|
public DbSet<BackRecordDetails> BackRecordDetails { get; set; }
|
|
public DbSet<BoxInventory> BoxInventory { get; set; }
|
|
public DbSet<BoxInventoryDetails> BoxInventoryDetails { get; set; }
|
|
public DbSet<InventoryDetails> InventoryDetails { get; set; }
|
|
public DbSet<InventoryInOutDetails> InventoryInOutDetails { get; set; }
|
|
|
|
public DbSet<Box> Box { get; set; }
|
|
public DbSet<BoxDetails> BoxDetails { get; set; }
|
|
}
|
|
}
|