Startup.cs 7.2 KB

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