Startup.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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(
  54. typeof(AdoSmartOpsLayoutItem),
  55. typeof(AdoSmartOpsHomeModule),
  56. typeof(AdoSmartOpsKpiMaster),
  57. typeof(AdoSmartOpsDashboardPageConfig),
  58. typeof(AdoSmartOpsDashboardWidget),
  59. typeof(AdoSmartOpsImprovementPlan));
  60. AidopTenantMigration.MigrateOldTenantId(dbS4);
  61. AidopKpiMasterSeed.EnsureSeed(dbS4);
  62. AidopKpiMasterSeed.EnsureSeed(dbS4, 1300000000888);
  63. var kpiTenantIds = dbS4.Queryable<AdoSmartOpsKpiMaster>()
  64. .Select(x => x.TenantId)
  65. .Distinct()
  66. .ToList();
  67. foreach (var tenantId in kpiTenantIds.Where(x => x > 0))
  68. AidopKpiMasterSeed.EnsureSeed(dbS4, tenantId!.Value);
  69. AidopImprovementApprovalSeed.EnsureSeed(dbS4);
  70. }
  71. catch (Exception ex)
  72. {
  73. Trace.TraceWarning("Ai-DOP CodeFirst/S4 seed: " + ex);
  74. }
  75. if (!env.IsDevelopment())
  76. return;
  77. // 客户/物料/优先级等;远端若已是遗留表(已有主键),CodeFirst 会报 Multiple primary key,不可让启动失败。
  78. try
  79. {
  80. using var scope = app.ApplicationServices.CreateScope();
  81. var db = scope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  82. db.CodeFirst.InitTables(
  83. typeof(AdoS0CustMaster),
  84. typeof(AdoS0ItemMaster),
  85. typeof(AdoS0ItemSubstituteDetail),
  86. typeof(AdoS0PriorityCode),
  87. typeof(AdoS0ProductStructureMaster),
  88. typeof(AdoS0ProductStructureOp),
  89. typeof(AdoS0StdOpMaster),
  90. typeof(AdoS0LineMaster),
  91. typeof(AdoS0MfgRoutingOpDetail),
  92. typeof(AdoS0MfgPersonSkillAssignment),
  93. typeof(AdoS0MfgWorkOrderControl),
  94. typeof(AdoS0MfgPersonSkill),
  95. typeof(AdoS0MfgLinePost),
  96. typeof(AdoS0MfgWorkCenter),
  97. typeof(AdoS0MfgLineMaterial),
  98. typeof(AdoS0ProcessFlowCard),
  99. typeof(AdoS0OrderScheduleCycle),
  100. typeof(AdoS0MfgElementParam),
  101. typeof(AdoS0MfgMaterialProcessElement),
  102. typeof(AdoS0MfgPreprocessElement),
  103. typeof(AdoS0MfgPreprocessElementParam),
  104. typeof(AdoS0ImageType),
  105. typeof(AdoS0QualitySegmentImage),
  106. typeof(AdoS0QmsQualityBaseType),
  107. typeof(AdoS0QmsFqcInspectionSpec),
  108. typeof(AdoS0QmsFqcInspectionSpecEntry),
  109. typeof(AdoS0QmsOqcInspectionSpec),
  110. typeof(AdoS0QmsOqcInspectionSpecEntry),
  111. typeof(AdoS0CategoryLeadTime),
  112. typeof(AdoS0MaterialPlanCycle),
  113. typeof(AdoS0SrmPurchase),
  114. typeof(AdoS8Exception),
  115. typeof(AdoS8ExceptionTimeline),
  116. typeof(AdoS8DecisionRecord),
  117. typeof(AdoS8Evidence),
  118. typeof(AdoS8SceneConfig),
  119. typeof(AdoS8AlertRule),
  120. typeof(AdoS8NotificationLayer),
  121. typeof(AdoS8DataSource),
  122. typeof(AdoS8WatchRule),
  123. typeof(AdoS8RolePermissionConfig),
  124. typeof(AdoS8NotificationLog),
  125. typeof(AdoS8DashboardCellConfig),
  126. typeof(AdoS8ExceptionType),
  127. typeof(AdoS8DetectionLog),
  128. typeof(ContractReview),
  129. typeof(ContractReviewFlow),
  130. typeof(ProductDesign),
  131. typeof(ProductDesignBom),
  132. typeof(ProductDesignRouting)
  133. );
  134. }
  135. catch (Exception ex)
  136. {
  137. Trace.TraceWarning("Ai-DOP Development CodeFirst (S0/S8/Order demo tables): " + ex);
  138. }
  139. }
  140. }