using Kingdee.CDP.WebApi.SDK; using Microsoft.EntityFrameworkCore; using Oracle.ManagedDataAccess.Client; using RB_MES_API.Models; using RB_MES_API.Models.Cloud; using RB_MES_API.Models.Pangu; using RB_MES_APICore.Models; using RB_MES_APICore.Models.Cloud; namespace RB_MES_API.Context { /// /// 沃比数据库实体 /// public class RBContext : DbContext { public void ConfigureServices(IServiceCollection services) { //var connectionString = ConnectionString.GetConfig("ConnectionStrings", "RBConn"); var connectionString = ApiSettingsHelper.GetConfig("RBConn"); services.AddDbContextPool(options => { options.UseSqlServer(connectionString, sqlServerOptionsAction: sqlOptions => { sqlOptions.CommandTimeout(600); sqlOptions.MaxBatchSize(32767); }); }); } /// /// 构造RBContext /// /// public RBContext(DbContextOptions options) : base(options) { } //在Startup中使用AddDbContext注册数据库连接时使用!!! //protected override void OnConfiguring(DbContextOptionsBuilder contextOptionsBuilder) //{ // string connnstr = ConnectionString.GetConfig("ConnectionStrings", "RBConn"); // contextOptionsBuilder.UseSqlServer(connnstr); //} /// /// Model /// /// protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().ToTable("r_ERPPutOperationAnchor"); modelBuilder.Entity().ToTable("r_FormIDType"); modelBuilder.Entity().ToTable("r_FunctionList"); modelBuilder.Entity().ToTable("r_SelectJoinID"); //modelBuilder.Entity().ToTable("r_MesRequestJson"); modelBuilder.Entity().ToTable("RBLog"); modelBuilder.Entity().ToTable("r_BillConvertes"); modelBuilder.Entity().ToTable("r_ReceiveStockBillTypes"); modelBuilder.Entity().ToTable("r_SystemProfiles"); modelBuilder.Entity().ToTable("r_CloudBillQuery"); modelBuilder.Entity().ToTable("r_ClumnConvert"); modelBuilder.Entity().ToTable("r_DataSaveBatch"); modelBuilder.Entity().ToTable("r_ReciveDataBack"); modelBuilder.Entity().ToTable("r_LockPRD_MO"); //英搏尔项目特有的 modelBuilder.Entity().ToTable("r_CustomServices"); modelBuilder.Entity().ToTable("r_BillTypeRules"); modelBuilder.Entity().ToTable("t_AuthorizationInfo"); modelBuilder.Entity().ToTable("r_ApiHostServices"); modelBuilder.Entity().HasKey(c => new { c.FCategoryID, c.FKey }); modelBuilder.Entity().HasIndex(c => new { c.FFunctionID, c.FDocType }); modelBuilder.Entity().HasIndex(c => c.FDocType); modelBuilder.Entity().HasIndex(c => new { c.FDateTime, c.FDocType }); modelBuilder.Entity().HasIndex(c => new { c.FReceiveID, c.FPageID, c.FK3FiledName }).IsUnique(); modelBuilder.Entity().HasIndex(c => new { c.FFunctionID, c.ErpBillTypeID }).IsUnique(); modelBuilder.Entity().HasIndex(c => c.FFormIDTypeID).IsUnique(); modelBuilder.Entity().HasIndex(c => c.FFunctionID); modelBuilder.Entity().HasIndex(c => new { c.FDocType, c.FErpID, c.FSeq }).IsUnique(); modelBuilder.Entity().HasIndex(c => new { c.ERP_MO, c.MO_SEQ }); modelBuilder.Entity().HasIndex(c => new { c.FPostTypeID, c.FSBillTypeNumber }); //相关表名称的和类的对应 base.OnModelCreating(modelBuilder); } /// /// 用于检测单据是否已经进行过推送 /// public DbSet r_ERPPutOperationAnchor { get; set; } /// /// 查询接口字段转换,可用于各种接口的字段转换 /// public DbSet r_FormIDType { get; set; } /// /// 接口类型定义表 /// public DbSet r_FunctionList { get; set; } /// /// 查询类接口定义 /// public DbSet r_SelectJoinID { get; set; } /// /// 沃比系统接收接口日志,防止重复传单 /// //public DbSet r_MesRequestJson { get; set; } /// /// 沃比系统错误日志,包含程序错误 /// public DbSet RBLog { get; set; } /// /// 接收单据类型接口传参定义 /// public DbSet r_BillConvertes { get; set; } /// /// 接收单据类型定义 /// public DbSet r_ReceiveStockBillTypes { get; set; } /// /// 系统文件,包含各种参数定义 /// public DbSet r_SystemProfiles { get; set; } /// /// ExecuteBillQuery接口JSON格式数据字段 /// public DbSet r_CloudBillQuery { get; set; } /// /// 查询接口字段转换,可用于各种接口的字段转换 /// public DbSet r_ClumnConvert { get; set; } /// /// 批量推送单据到CLOUD配置 /// public DbSet r_DataSaveBatch { get; set; } /// /// 向ERP推单备份 /// public DbSet r_ReciveDataBack { get; set; } /// /// 向ERP推单备份 /// public DbSet r_LockPRD_MO { get; set; } /// /// Cloud自定义接口配置 /// public DbSet r_CustomServices { get; set; } /// /// 接收单据类型定义 /// public DbSet r_BillTypeRules { get; set; } /// /// 调用外部接口鉴权相关信息 /// public DbSet t_AuthorizationInfo { get; set; } /// /// 使用定时任务的列表 /// public DbSet r_ApiHostServices { get; set; } } }