Startup.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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.Entity.S8.OrderFlow;
  10. using Admin.NET.Plugin.AiDOP.Order;
  11. using Admin.NET.Plugin.AiDOP.DataPlatform.Executors;
  12. using Admin.NET.Plugin.AiDOP.DataPlatform.HotWatch;
  13. using Admin.NET.Plugin.AiDOP.Entity.DataPlatform;
  14. using Admin.NET.Plugin.AiDOP.Infrastructure;
  15. using Admin.NET.Plugin.AiDOP.MaterialWarehouse;
  16. using Admin.NET.Plugin.AiDOP.WorkOrder;
  17. using Microsoft.AspNetCore.Builder;
  18. using Microsoft.AspNetCore.Hosting;
  19. using Microsoft.AspNetCore.Mvc;
  20. using Microsoft.Extensions.DependencyInjection;
  21. using Microsoft.Extensions.Hosting;
  22. using SqlSugar;
  23. namespace Admin.NET.Plugin.AiDOP;
  24. /// <summary>
  25. /// AiDOP 插件启动配置(按需扩展 DI)
  26. /// </summary>
  27. [AppStartup(900)]
  28. public class Startup : AppStartup
  29. {
  30. public void ConfigureServices(IServiceCollection services)
  31. {
  32. services.AddHttpClient();
  33. services.AddHttpClient("AidopChatBI.DeepSeek");
  34. services.AddScoped<DeepSeekChatClient>();
  35. services.AddScoped<ChatBIService>();
  36. services.AddConfigurableOptions<S8ActiveFlowWatchOptions>();
  37. services.AddConfigurableOptions<S8MasterDataOptions>();
  38. services.AddConfigurableOptions<AidopPickBillOptions>();
  39. services.AddConfigurableOptions<AidopStockOptions>();
  40. services.AddConfigurableOptions<AidopInventoryOptions>();
  41. services.AddTransient<IInventoryBalanceReader, InventoryBalanceReader>();
  42. services.AddTransient<IInventoryTransactionReader, StdInventoryTransactionReader>();
  43. // WP9:IPickBillCreator 唯一实现为 Facade(避免 Local/Mes 多实现竞注)
  44. services.AddTransient<IPickBillCreator, PickBillCreatorFacade>();
  45. services.AddScoped<AdoS0ExceptionFilter>();
  46. services.AddScoped<AdoS0ResultFilter>();
  47. services.AddScoped<AdoS0ReferenceChecker>();
  48. services.Configure<MvcOptions>(options =>
  49. {
  50. options.Filters.AddService<AdoS0ExceptionFilter>();
  51. options.Filters.AddService<AdoS0ResultFilter>();
  52. });
  53. // MDP 出站事件驱动:入队 Pulse → 立即推送;Period Job 仅兜底
  54. services.AddHostedService<MdpOutboxPushWorker>();
  55. services.AddHostedService<MdpHotWatchWorker>();
  56. services.AddHostedService<Admin.NET.Plugin.AiDOP.DataPlatform.S1Refresh.S1DashboardRebuildWorker>();
  57. services.AddHostedService<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.ModuleRebuildWorker>();
  58. services.AddSingleton<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildCapability, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.ModuleRebuildCapability>();
  59. services.AddTransient<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildJobStore, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.ModuleRebuildJobStore>();
  60. services.AddTransient<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildLock, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.ModuleRebuildLock>();
  61. services.AddTransient<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildHandler, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.S1ModuleRebuildHandler>();
  62. services.AddTransient<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildHandler, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.S2ModuleRebuildHandler>();
  63. services.AddTransient<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildHandler, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.S3ModuleRebuildHandler>();
  64. services.AddTransient<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildHandler, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.S4ModuleRebuildHandler>();
  65. services.AddTransient<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildHandler, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.S5ModuleRebuildHandler>();
  66. services.AddTransient<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildHandler, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.S6ModuleRebuildHandler>();
  67. services.AddTransient<Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.IModuleRebuildHandler, Admin.NET.Plugin.AiDOP.DataPlatform.MdpRebuild.S7ModuleRebuildHandler>();
  68. // S8-DATASET-FOUNDATION-HARDENING-2:S8 取数底座的接口映射显式注册
  69. // (与上方 IModuleRebuildLock 同一先例:本项目不依赖 ITransient 自动按接口注册)。
  70. // IS8DatasetDefinitionSource / IS8MonitoringDataProvider 本批**刻意不注册任何实现**——
  71. // Catalog 与 Registry 均能正确处理空集合,这是"尚未接生产数据集"的预期状态。
  72. services.AddTransient<Admin.NET.Plugin.AiDOP.Service.S8.Rules.DataAccess.IS8DatasetCatalog, Admin.NET.Plugin.AiDOP.Service.S8.Rules.DataAccess.S8DatasetCatalog>();
  73. services.AddTransient<Admin.NET.Plugin.AiDOP.Service.S8.Rules.DataAccess.IS8LegacySqlDataProvider, Admin.NET.Plugin.AiDOP.Service.S8.Rules.DataAccess.S8LegacySqlDataProvider>();
  74. }
  75. /// <summary>
  76. /// 开发环境下为 Demo 表执行 CodeFirst(表已存在则跳过变更,行为取决于 SqlSugar 配置)。
  77. /// </summary>
  78. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  79. {
  80. try
  81. {
  82. AidopMenuLinkSync.EnsureLinked(app.ApplicationServices);
  83. }
  84. catch (Exception ex)
  85. {
  86. Trace.TraceWarning("Ai-DOP AidopMenuLinkSync: " + ex);
  87. }
  88. try
  89. {
  90. using var scopeS4 = app.ApplicationServices.CreateScope();
  91. var dbS4 = scopeS4.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  92. dbS4.CodeFirst.InitTables(
  93. typeof(AdoSmartOpsLayoutItem),
  94. typeof(AdoSmartOpsHomeModule),
  95. typeof(AdoSmartOpsKpiMaster),
  96. typeof(AdoSmartOpsDashboardPageConfig),
  97. typeof(AdoSmartOpsDashboardWidget),
  98. typeof(AdoSmartOpsImprovementPlan),
  99. typeof(AdoMdpHotWatch),
  100. typeof(Admin.NET.Plugin.AiDOP.Entity.SmartOps.AdoS1DashboardRebuildJob),
  101. typeof(Admin.NET.Plugin.AiDOP.Entity.SmartOps.AdoModuleDashboardRebuildJob),
  102. typeof(Admin.NET.Plugin.AiDOP.Entity.SmartOps.AdoMdpRebuildLock),
  103. typeof(AdoTenantMenuSuppression));
  104. AidopTenantMigration.MigrateOldTenantId(dbS4);
  105. AidopKpiMasterSeed.EnsureSeed(dbS4);
  106. AidopKpiMasterSeed.EnsureSeed(dbS4, 1300000000888);
  107. var kpiTenantIds = dbS4.Queryable<AdoSmartOpsKpiMaster>()
  108. .Select(x => x.TenantId)
  109. .Distinct()
  110. .ToList();
  111. foreach (var tenantId in kpiTenantIds.Where(x => x > 0))
  112. AidopKpiMasterSeed.EnsureSeed(dbS4, tenantId!.Value);
  113. AidopImprovementApprovalSeed.EnsureSeed(dbS4);
  114. Admin.NET.Plugin.AiDOP.Infrastructure.IqcInspBillFlowSeed.EnsureSeed(dbS4);
  115. Admin.NET.Plugin.AiDOP.Infrastructure.IpqcInspectionFlowSeed.EnsureSeed(dbS4);
  116. Admin.NET.Plugin.AiDOP.Infrastructure.S6ProcessInspectionFlowSeed.EnsureSeed(dbS4);
  117. Admin.NET.Plugin.AiDOP.Infrastructure.FqcInspBillFlowSeed.EnsureSeed(dbS4);
  118. }
  119. catch (Exception ex)
  120. {
  121. Trace.TraceWarning("Ai-DOP CodeFirst/S4 seed: " + ex);
  122. }
  123. if (!env.IsDevelopment())
  124. return;
  125. // 客户/物料/优先级等;远端若已是遗留表(已有主键),CodeFirst 会报 Multiple primary key,不可让启动失败。
  126. try
  127. {
  128. using var scope = app.ApplicationServices.CreateScope();
  129. var db = scope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  130. db.CodeFirst.InitTables(
  131. typeof(AdoS0CustMaster),
  132. typeof(AdoS0ItemMaster),
  133. typeof(AdoS0ItemSubstituteDetail),
  134. typeof(AdoS0PriorityCode),
  135. typeof(AdoS0ProductStructureOp),
  136. typeof(AdoS0StdOpMaster),
  137. typeof(AdoS0LineMaster),
  138. typeof(AdoS0MfgRoutingOpDetail),
  139. typeof(AdoS0MfgPersonSkillAssignment),
  140. typeof(AdoS0MfgWorkOrderControl),
  141. typeof(AdoS0MfgPersonSkill),
  142. typeof(AdoS0MfgLinePost),
  143. typeof(AdoS0MfgWorkCenter),
  144. typeof(AdoS0MfgLineMaterial),
  145. typeof(AdoS0ProcessFlowCard),
  146. typeof(AdoS0OrderScheduleCycle),
  147. typeof(AdoS0MfgElementParam),
  148. typeof(AdoS0MfgMaterialProcessElement),
  149. typeof(AdoS0MfgPreprocessElement),
  150. typeof(AdoS0MfgPreprocessElementParam),
  151. typeof(AdoS0ImageType),
  152. typeof(AdoS0QualitySegmentImage),
  153. typeof(AdoS0QmsQualityBaseType),
  154. typeof(AdoS0QmsFqcInspectionSpec),
  155. typeof(AdoS0QmsFqcInspectionSpecEntry),
  156. typeof(AdoS0QmsOqcInspectionSpec),
  157. typeof(AdoS0QmsOqcInspectionSpecEntry),
  158. typeof(AdoS0CategoryLeadTime),
  159. typeof(AdoS0MaterialPlanCycle),
  160. typeof(AdoS0SrmPurchase),
  161. typeof(AdoS8Exception),
  162. typeof(AdoS8ExceptionTimeline),
  163. typeof(AdoS8DecisionRecord),
  164. typeof(AdoS8Evidence),
  165. typeof(AdoS8SceneConfig),
  166. typeof(AdoS8AlertRule),
  167. typeof(AdoS8NotificationLayer),
  168. typeof(AdoS8DataSource),
  169. typeof(AdoS8WatchRule),
  170. typeof(AdoS8RolePermissionConfig),
  171. typeof(AdoS8NotificationLog),
  172. typeof(AdoS8DashboardCellConfig),
  173. typeof(AdoS8ExceptionType),
  174. typeof(AdoS8DetectionLog),
  175. typeof(AdoS8RuleDetectionState),
  176. typeof(AdoS8Dimension),
  177. typeof(AdoS8DimensionNode),
  178. typeof(AdoS8ConfigDraft),
  179. typeof(AdoS8MonitorObject),
  180. typeof(AdoS8MonitorMetric),
  181. typeof(AdoS8OrderFlowOrder),
  182. typeof(AdoS8OrderFlowStage),
  183. typeof(AdoS8OrderFlowSnapshot),
  184. typeof(AdoS8OrderFlowSubstep),
  185. typeof(AdoS8OrderFlowSubstepUnit),
  186. typeof(AdoS8OrderFlowProcurementPivot),
  187. typeof(ContractReview),
  188. typeof(ContractReviewFlow),
  189. typeof(ProductDesign),
  190. typeof(ProductDesignBom),
  191. typeof(ProductDesignRouting)
  192. );
  193. AidopDimensionSeed.EnsureSeed(db);
  194. AidopMonitorDictionarySeed.EnsureSeed(db);
  195. }
  196. catch (Exception ex)
  197. {
  198. Trace.TraceWarning("Ai-DOP Development CodeFirst (S0/S8/Order demo tables): " + ex);
  199. }
  200. }
  201. }