Startup.cs 3.6 KB

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