Startup.cs 4.9 KB

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