Startup.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Diagnostics;
  2. using Admin.NET.Plugin.AiDOP.Entity;
  3. using Admin.NET.Plugin.AiDOP.Entity.S0.Manufacturing;
  4. using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
  5. using Admin.NET.Plugin.AiDOP.Entity.S0.Supply;
  6. using Admin.NET.Plugin.AiDOP.Infrastructure;
  7. using Microsoft.AspNetCore.Builder;
  8. using Microsoft.AspNetCore.Hosting;
  9. using Microsoft.AspNetCore.Mvc;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Microsoft.Extensions.Hosting;
  12. using SqlSugar;
  13. namespace Admin.NET.Plugin.AiDOP;
  14. /// <summary>
  15. /// AiDOP 插件启动配置(按需扩展 DI)
  16. /// </summary>
  17. [AppStartup(900)]
  18. public class Startup : AppStartup
  19. {
  20. public void ConfigureServices(IServiceCollection services)
  21. {
  22. services.AddScoped<AdoS0ExceptionFilter>();
  23. services.AddScoped<AdoS0ResultFilter>();
  24. services.Configure<MvcOptions>(options =>
  25. {
  26. options.Filters.AddService<AdoS0ExceptionFilter>();
  27. options.Filters.AddService<AdoS0ResultFilter>();
  28. });
  29. }
  30. /// <summary>
  31. /// 开发环境下为 Demo 表执行 CodeFirst(表已存在则跳过变更,行为取决于 SqlSugar 配置)。
  32. /// </summary>
  33. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  34. {
  35. try
  36. {
  37. AidopMenuLinkSync.EnsureLinked(app.ApplicationServices);
  38. }
  39. catch (Exception ex)
  40. {
  41. Trace.TraceWarning("Ai-DOP AidopMenuLinkSync: " + ex);
  42. }
  43. try
  44. {
  45. using var scopeS4 = app.ApplicationServices.CreateScope();
  46. var dbS4 = scopeS4.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  47. dbS4.CodeFirst.InitTables(typeof(AdoSmartOpsLayoutItem), typeof(AdoSmartOpsHomeModule), typeof(AdoSmartOpsKpiMaster));
  48. AidopTenantMigration.MigrateOldTenantId(dbS4);
  49. AidopKpiMasterSeed.EnsureSeed(dbS4);
  50. AidopKpiMasterSeed.EnsureSeed(dbS4, 1300000000888);
  51. }
  52. catch (Exception ex)
  53. {
  54. Trace.TraceWarning("Ai-DOP CodeFirst/S4 seed: " + ex);
  55. }
  56. if (!env.IsDevelopment())
  57. return;
  58. // 客户/物料/优先级等;前处理要素/前处理要素参数现为独立表 PreprocessElement / PreprocessElementParam。
  59. using var scope = app.ApplicationServices.CreateScope();
  60. var db = scope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  61. db.CodeFirst.InitTables(
  62. typeof(AdoS0CustMaster),
  63. typeof(AdoS0ItemMaster),
  64. typeof(AdoS0ItemSubstituteDetail),
  65. typeof(AdoS0PriorityCode),
  66. typeof(AdoS0ProductStructureMaster),
  67. typeof(AdoS0ProductStructureOp),
  68. typeof(AdoS0StdOpMaster),
  69. typeof(AdoS0LineMaster),
  70. typeof(AdoS0MfgRoutingOpDetail),
  71. typeof(AdoS0MfgPersonSkillAssignment),
  72. typeof(AdoS0MfgWorkOrderControl),
  73. typeof(AdoS0MfgPersonSkill),
  74. typeof(AdoS0MfgLinePost),
  75. typeof(AdoS0MfgLinePostSkill),
  76. typeof(AdoS0MfgWorkCenter),
  77. typeof(AdoS0MfgLineMaterial),
  78. typeof(AdoS0MfgElementParam),
  79. typeof(AdoS0MfgMaterialProcessElement),
  80. typeof(AdoS0MfgPreprocessElement),
  81. typeof(AdoS0MfgPreprocessElementParam),
  82. typeof(AdoS0ImageType),
  83. typeof(AdoS0QualitySegmentImage),
  84. typeof(AdoS0SrmPurchase)
  85. );
  86. }
  87. }