Startup.cs 6.6 KB

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