Startup.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.WorkOrder;
  16. using Microsoft.AspNetCore.Builder;
  17. using Microsoft.AspNetCore.Hosting;
  18. using Microsoft.AspNetCore.Mvc;
  19. using Microsoft.Extensions.DependencyInjection;
  20. using Microsoft.Extensions.Hosting;
  21. using SqlSugar;
  22. namespace Admin.NET.Plugin.AiDOP;
  23. /// <summary>
  24. /// AiDOP 插件启动配置(按需扩展 DI)
  25. /// </summary>
  26. [AppStartup(900)]
  27. public class Startup : AppStartup
  28. {
  29. public void ConfigureServices(IServiceCollection services)
  30. {
  31. services.AddHttpClient();
  32. services.AddHttpClient("AidopChatBI.DeepSeek");
  33. services.AddScoped<DeepSeekChatClient>();
  34. services.AddScoped<ChatBIService>();
  35. services.AddConfigurableOptions<S8ActiveFlowWatchOptions>();
  36. services.AddConfigurableOptions<S8MasterDataOptions>();
  37. services.AddConfigurableOptions<AidopPickBillOptions>();
  38. // WP9:IPickBillCreator 唯一实现为 Facade(避免 Local/Mes 多实现竞注)
  39. services.AddTransient<IPickBillCreator, PickBillCreatorFacade>();
  40. services.AddScoped<AdoS0ExceptionFilter>();
  41. services.AddScoped<AdoS0ResultFilter>();
  42. services.AddScoped<AdoS0ReferenceChecker>();
  43. services.Configure<MvcOptions>(options =>
  44. {
  45. options.Filters.AddService<AdoS0ExceptionFilter>();
  46. options.Filters.AddService<AdoS0ResultFilter>();
  47. });
  48. // MDP 出站事件驱动:入队 Pulse → 立即推送;Period Job 仅兜底
  49. services.AddHostedService<MdpOutboxPushWorker>();
  50. services.AddHostedService<MdpHotWatchWorker>();
  51. }
  52. /// <summary>
  53. /// 开发环境下为 Demo 表执行 CodeFirst(表已存在则跳过变更,行为取决于 SqlSugar 配置)。
  54. /// </summary>
  55. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  56. {
  57. try
  58. {
  59. AidopMenuLinkSync.EnsureLinked(app.ApplicationServices);
  60. }
  61. catch (Exception ex)
  62. {
  63. Trace.TraceWarning("Ai-DOP AidopMenuLinkSync: " + ex);
  64. }
  65. try
  66. {
  67. using var scopeS4 = app.ApplicationServices.CreateScope();
  68. var dbS4 = scopeS4.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  69. dbS4.CodeFirst.InitTables(
  70. typeof(AdoSmartOpsLayoutItem),
  71. typeof(AdoSmartOpsHomeModule),
  72. typeof(AdoSmartOpsKpiMaster),
  73. typeof(AdoSmartOpsDashboardPageConfig),
  74. typeof(AdoSmartOpsDashboardWidget),
  75. typeof(AdoSmartOpsImprovementPlan),
  76. typeof(AdoMdpHotWatch));
  77. AidopTenantMigration.MigrateOldTenantId(dbS4);
  78. AidopKpiMasterSeed.EnsureSeed(dbS4);
  79. AidopKpiMasterSeed.EnsureSeed(dbS4, 1300000000888);
  80. var kpiTenantIds = dbS4.Queryable<AdoSmartOpsKpiMaster>()
  81. .Select(x => x.TenantId)
  82. .Distinct()
  83. .ToList();
  84. foreach (var tenantId in kpiTenantIds.Where(x => x > 0))
  85. AidopKpiMasterSeed.EnsureSeed(dbS4, tenantId!.Value);
  86. AidopImprovementApprovalSeed.EnsureSeed(dbS4);
  87. Admin.NET.Plugin.AiDOP.Infrastructure.IqcInspBillFlowSeed.EnsureSeed(dbS4);
  88. Admin.NET.Plugin.AiDOP.Infrastructure.IpqcInspectionFlowSeed.EnsureSeed(dbS4);
  89. Admin.NET.Plugin.AiDOP.Infrastructure.FqcInspBillFlowSeed.EnsureSeed(dbS4);
  90. }
  91. catch (Exception ex)
  92. {
  93. Trace.TraceWarning("Ai-DOP CodeFirst/S4 seed: " + ex);
  94. }
  95. if (!env.IsDevelopment())
  96. return;
  97. // 客户/物料/优先级等;远端若已是遗留表(已有主键),CodeFirst 会报 Multiple primary key,不可让启动失败。
  98. try
  99. {
  100. using var scope = app.ApplicationServices.CreateScope();
  101. var db = scope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  102. db.CodeFirst.InitTables(
  103. typeof(AdoS0CustMaster),
  104. typeof(AdoS0ItemMaster),
  105. typeof(AdoS0ItemSubstituteDetail),
  106. typeof(AdoS0PriorityCode),
  107. typeof(AdoS0ProductStructureOp),
  108. typeof(AdoS0StdOpMaster),
  109. typeof(AdoS0LineMaster),
  110. typeof(AdoS0MfgRoutingOpDetail),
  111. typeof(AdoS0MfgPersonSkillAssignment),
  112. typeof(AdoS0MfgWorkOrderControl),
  113. typeof(AdoS0MfgPersonSkill),
  114. typeof(AdoS0MfgLinePost),
  115. typeof(AdoS0MfgWorkCenter),
  116. typeof(AdoS0MfgLineMaterial),
  117. typeof(AdoS0ProcessFlowCard),
  118. typeof(AdoS0OrderScheduleCycle),
  119. typeof(AdoS0MfgElementParam),
  120. typeof(AdoS0MfgMaterialProcessElement),
  121. typeof(AdoS0MfgPreprocessElement),
  122. typeof(AdoS0MfgPreprocessElementParam),
  123. typeof(AdoS0ImageType),
  124. typeof(AdoS0QualitySegmentImage),
  125. typeof(AdoS0QmsQualityBaseType),
  126. typeof(AdoS0QmsFqcInspectionSpec),
  127. typeof(AdoS0QmsFqcInspectionSpecEntry),
  128. typeof(AdoS0QmsOqcInspectionSpec),
  129. typeof(AdoS0QmsOqcInspectionSpecEntry),
  130. typeof(AdoS0CategoryLeadTime),
  131. typeof(AdoS0MaterialPlanCycle),
  132. typeof(AdoS0SrmPurchase),
  133. typeof(AdoS8Exception),
  134. typeof(AdoS8ExceptionTimeline),
  135. typeof(AdoS8DecisionRecord),
  136. typeof(AdoS8Evidence),
  137. typeof(AdoS8SceneConfig),
  138. typeof(AdoS8AlertRule),
  139. typeof(AdoS8NotificationLayer),
  140. typeof(AdoS8DataSource),
  141. typeof(AdoS8WatchRule),
  142. typeof(AdoS8RolePermissionConfig),
  143. typeof(AdoS8NotificationLog),
  144. typeof(AdoS8DashboardCellConfig),
  145. typeof(AdoS8ExceptionType),
  146. typeof(AdoS8DetectionLog),
  147. typeof(AdoS8RuleDetectionState),
  148. typeof(AdoS8Dimension),
  149. typeof(AdoS8DimensionNode),
  150. typeof(AdoS8ConfigDraft),
  151. typeof(AdoS8MonitorObject),
  152. typeof(AdoS8MonitorMetric),
  153. typeof(AdoS8OrderFlowOrder),
  154. typeof(AdoS8OrderFlowStage),
  155. typeof(AdoS8OrderFlowSnapshot),
  156. typeof(AdoS8OrderFlowSubstep),
  157. typeof(AdoS8OrderFlowSubstepUnit),
  158. typeof(AdoS8OrderFlowProcurementPivot),
  159. typeof(ContractReview),
  160. typeof(ContractReviewFlow),
  161. typeof(ProductDesign),
  162. typeof(ProductDesignBom),
  163. typeof(ProductDesignRouting)
  164. );
  165. AidopDimensionSeed.EnsureSeed(db);
  166. AidopMonitorDictionarySeed.EnsureSeed(db);
  167. }
  168. catch (Exception ex)
  169. {
  170. Trace.TraceWarning("Ai-DOP Development CodeFirst (S0/S8/Order demo tables): " + ex);
  171. }
  172. }
  173. }