Startup.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.Entity.S8;
  7. using Admin.NET.Plugin.AiDOP.Order;
  8. using Admin.NET.Plugin.AiDOP.Infrastructure;
  9. using Microsoft.AspNetCore.Builder;
  10. using Microsoft.AspNetCore.Hosting;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.Extensions.DependencyInjection;
  13. using Microsoft.Extensions.Hosting;
  14. using SqlSugar;
  15. namespace Admin.NET.Plugin.AiDOP;
  16. /// <summary>
  17. /// AiDOP 插件启动配置(按需扩展 DI)
  18. /// </summary>
  19. [AppStartup(900)]
  20. public class Startup : AppStartup
  21. {
  22. public void ConfigureServices(IServiceCollection services)
  23. {
  24. services.AddHttpClient();
  25. services.AddScoped<AdoS0ExceptionFilter>();
  26. services.AddScoped<AdoS0ResultFilter>();
  27. services.Configure<MvcOptions>(options =>
  28. {
  29. options.Filters.AddService<AdoS0ExceptionFilter>();
  30. options.Filters.AddService<AdoS0ResultFilter>();
  31. });
  32. }
  33. /// <summary>
  34. /// 开发环境下为 Demo 表执行 CodeFirst(表已存在则跳过变更,行为取决于 SqlSugar 配置)。
  35. /// </summary>
  36. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  37. {
  38. try
  39. {
  40. AidopMenuLinkSync.EnsureLinked(app.ApplicationServices);
  41. }
  42. catch (Exception ex)
  43. {
  44. Trace.TraceWarning("Ai-DOP AidopMenuLinkSync: " + ex);
  45. }
  46. try
  47. {
  48. using var scopeS4 = app.ApplicationServices.CreateScope();
  49. var dbS4 = scopeS4.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  50. dbS4.CodeFirst.InitTables(typeof(AdoSmartOpsLayoutItem), typeof(AdoSmartOpsHomeModule), typeof(AdoSmartOpsKpiMaster));
  51. AidopTenantMigration.MigrateOldTenantId(dbS4);
  52. AidopKpiMasterSeed.EnsureSeed(dbS4);
  53. AidopKpiMasterSeed.EnsureSeed(dbS4, 1300000000888);
  54. }
  55. catch (Exception ex)
  56. {
  57. Trace.TraceWarning("Ai-DOP CodeFirst/S4 seed: " + ex);
  58. }
  59. if (!env.IsDevelopment())
  60. return;
  61. // 客户/物料/优先级等;远端若已是遗留表(已有主键),CodeFirst 会报 Multiple primary key,不可让启动失败。
  62. try
  63. {
  64. using var scope = app.ApplicationServices.CreateScope();
  65. var db = scope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  66. db.CodeFirst.InitTables(
  67. typeof(AdoS0CustMaster),
  68. typeof(AdoS0ItemMaster),
  69. typeof(AdoS0ItemSubstituteDetail),
  70. typeof(AdoS0PriorityCode),
  71. typeof(AdoS0ProductStructureMaster),
  72. typeof(AdoS0ProductStructureOp),
  73. typeof(AdoS0StdOpMaster),
  74. typeof(AdoS0LineMaster),
  75. typeof(AdoS0MfgRoutingOpDetail),
  76. typeof(AdoS0MfgPersonSkillAssignment),
  77. typeof(AdoS0MfgWorkOrderControl),
  78. typeof(AdoS0MfgPersonSkill),
  79. typeof(AdoS0MfgLinePost),
  80. typeof(AdoS0MfgLinePostSkill),
  81. typeof(AdoS0MfgWorkCenter),
  82. typeof(AdoS0MfgLineMaterial),
  83. typeof(AdoS0MfgElementParam),
  84. typeof(AdoS0MfgMaterialProcessElement),
  85. typeof(AdoS0MfgPreprocessElement),
  86. typeof(AdoS0MfgPreprocessElementParam),
  87. typeof(AdoS0ImageType),
  88. typeof(AdoS0QualitySegmentImage),
  89. typeof(AdoS0SrmPurchase),
  90. typeof(AdoS8Exception),
  91. typeof(AdoS8ExceptionTimeline),
  92. typeof(AdoS8DecisionRecord),
  93. typeof(AdoS8Evidence),
  94. typeof(AdoS8SceneConfig),
  95. typeof(AdoS8AlertRule),
  96. typeof(AdoS8NotificationLayer),
  97. typeof(AdoS8DataSource),
  98. typeof(AdoS8WatchRule),
  99. typeof(AdoS8RolePermissionConfig),
  100. typeof(AdoS8NotificationLog),
  101. typeof(ContractReview),
  102. typeof(ContractReviewFlow),
  103. typeof(ProductDesign),
  104. typeof(ProductDesignBom),
  105. typeof(ProductDesignRouting)
  106. );
  107. }
  108. catch (Exception ex)
  109. {
  110. Trace.TraceWarning("Ai-DOP Development CodeFirst (S0/S8/Order demo tables): " + ex);
  111. }
  112. }
  113. }