Startup.cs 5.9 KB

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