Startup.cs 5.0 KB

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