Startup.cs 5.1 KB

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