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.AddConfigurableOptions<S8MasterDataOptions>();
  33. services.AddScoped<AdoS0ExceptionFilter>();
  34. services.AddScoped<AdoS0ResultFilter>();
  35. services.AddScoped<AdoS0ReferenceChecker>();
  36. services.Configure<MvcOptions>(options =>
  37. {
  38. options.Filters.AddService<AdoS0ExceptionFilter>();
  39. options.Filters.AddService<AdoS0ResultFilter>();
  40. });
  41. }
  42. /// <summary>
  43. /// 开发环境下为 Demo 表执行 CodeFirst(表已存在则跳过变更,行为取决于 SqlSugar 配置)。
  44. /// </summary>
  45. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  46. {
  47. try
  48. {
  49. AidopMenuLinkSync.EnsureLinked(app.ApplicationServices);
  50. }
  51. catch (Exception ex)
  52. {
  53. Trace.TraceWarning("Ai-DOP AidopMenuLinkSync: " + ex);
  54. }
  55. try
  56. {
  57. using var scopeS4 = app.ApplicationServices.CreateScope();
  58. var dbS4 = scopeS4.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  59. dbS4.CodeFirst.InitTables(
  60. typeof(AdoSmartOpsLayoutItem),
  61. typeof(AdoSmartOpsHomeModule),
  62. typeof(AdoSmartOpsKpiMaster),
  63. typeof(AdoSmartOpsDashboardPageConfig),
  64. typeof(AdoSmartOpsDashboardWidget),
  65. typeof(AdoSmartOpsImprovementPlan));
  66. AidopTenantMigration.MigrateOldTenantId(dbS4);
  67. AidopKpiMasterSeed.EnsureSeed(dbS4);
  68. AidopKpiMasterSeed.EnsureSeed(dbS4, 1300000000888);
  69. var kpiTenantIds = dbS4.Queryable<AdoSmartOpsKpiMaster>()
  70. .Select(x => x.TenantId)
  71. .Distinct()
  72. .ToList();
  73. foreach (var tenantId in kpiTenantIds.Where(x => x > 0))
  74. AidopKpiMasterSeed.EnsureSeed(dbS4, tenantId!.Value);
  75. AidopImprovementApprovalSeed.EnsureSeed(dbS4);
  76. }
  77. catch (Exception ex)
  78. {
  79. Trace.TraceWarning("Ai-DOP CodeFirst/S4 seed: " + ex);
  80. }
  81. if (!env.IsDevelopment())
  82. return;
  83. // 客户/物料/优先级等;远端若已是遗留表(已有主键),CodeFirst 会报 Multiple primary key,不可让启动失败。
  84. try
  85. {
  86. using var scope = app.ApplicationServices.CreateScope();
  87. var db = scope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  88. db.CodeFirst.InitTables(
  89. typeof(AdoS0CustMaster),
  90. typeof(AdoS0ItemMaster),
  91. typeof(AdoS0ItemSubstituteDetail),
  92. typeof(AdoS0PriorityCode),
  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. }