Startup.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.AspNetCore.Http.Features;
  7. using Microsoft.AspNetCore.StaticFiles;
  8. using Microsoft.Extensions.Configuration;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using Microsoft.Extensions.Hosting;
  11. namespace MySystem
  12. {
  13. public class Startup
  14. {
  15. public Startup(IConfiguration configuration)
  16. {
  17. Configuration = configuration;
  18. }
  19. public IConfiguration Configuration { get; }
  20. // This method gets called by the runtime. Use this method to add services to the container.
  21. public void ConfigureServices(IServiceCollection services)
  22. {
  23. services.AddControllersWithViews();
  24. services.AddRouting(options =>
  25. {
  26. options.LowercaseUrls = true;
  27. });
  28. services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  29. services.AddCors(option => option.AddPolicy("cors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().SetIsOriginAllowed(_ => true)));
  30. services.AddMvc(options =>
  31. {
  32. options.EnableEndpointRouting = false;
  33. options.Filters.Add(typeof(GlobalExceptions));
  34. });
  35. services.AddSession(options =>
  36. {
  37. // 设置 Session 过期时间
  38. options.IdleTimeout = TimeSpan.FromHours(1);
  39. options.Cookie.HttpOnly = true;
  40. });
  41. services.Configure<FormOptions>(x =>
  42. {
  43. x.MultipartBodyLengthLimit = 50 * 1024 * 1024;//不到300M
  44. });
  45. string appkey = Configuration["Setting:AppKey"];
  46. string appid = Configuration["Setting:AppId"];
  47. string checkurl = Configuration["Setting:CheckUrl"];
  48. string serviceurl = Configuration["Setting:WebServiceUrl"];
  49. string schemeurl = Configuration["Setting:DbSchemeUrl"];
  50. MySystemLib.SystemPublicFuction.appkey = appkey;
  51. MySystemLib.SystemPublicFuction.appid = appid;
  52. MySystemLib.SystemPublicFuction.checkurl = checkurl;
  53. MySystemLib.SystemPublicFuction.appcheck = "success";
  54. string conn = Configuration["Setting:SqlConnStr"];
  55. Dictionary<string, Dictionary<string, string>> tables = new Dictionary<string, Dictionary<string, string>>();
  56. System.Data.DataTable tablecollection = Library.CustomerSqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = 'KxsMainServer'", conn);
  57. foreach (System.Data.DataRow subtable in tablecollection.Rows)
  58. {
  59. Dictionary<string, string> Columns = new Dictionary<string, string>();
  60. System.Data.DataTable columncollection = Library.CustomerSqlConn.dtable("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = 'KxsMainServer' and TABLE_NAME='" + subtable["TABLE_NAME"].ToString() + "'", conn);
  61. foreach (System.Data.DataRow column in columncollection.Rows)
  62. {
  63. string datatype = column["DATA_TYPE"].ToString();
  64. if (datatype == "decimal")
  65. {
  66. datatype = "numeric";
  67. }
  68. Columns.Add(column["COLUMN_NAME"].ToString(), datatype);
  69. }
  70. tables.Add(subtable["TABLE_NAME"].ToString(), Columns);
  71. }
  72. MySystemLib.SystemPublicFuction.dbtables = tables;
  73. }
  74. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  75. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  76. {
  77. if (env.IsDevelopment())
  78. {
  79. app.UseDeveloperExceptionPage();
  80. // app.UseExceptionHandler("/Home/Error");
  81. Library.ConfigurationManager.EnvironmentFlag = 1;
  82. }
  83. else
  84. {
  85. app.UseExceptionHandler("/Home/Error");
  86. app.UseHsts();
  87. Library.ConfigurationManager.EnvironmentFlag = 2;
  88. }
  89. Library.function.WritePage("/", "WebRootPath.txt", env.WebRootPath);
  90. app.UseStaticFiles();
  91. app.UseStaticFiles(new StaticFileOptions
  92. {
  93. ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
  94. {
  95. { ".apk", "application/vnd.android.package-archive" }
  96. })
  97. });
  98. app.UseCors("cors");
  99. app.UseAuthentication();
  100. app.UseRouting();
  101. app.UseAuthorization();
  102. app.UseSession();
  103. app.UseEndpoints(endpoints =>
  104. {
  105. endpoints.MapControllerRoute(
  106. name: "default",
  107. pattern: "{controller=Home}/{action=Index}/{Id?}");
  108. });
  109. //必须打开的
  110. StatService.Instance.StartEverDayV2(); //实时统计交易额
  111. StatService.Instance.StartOther(); //补充统计交易额
  112. StatService.Instance.StartPosActNum(); //实时统计激活数
  113. StatService.Instance.StartNewUserNum(); //实时统计新增创客数
  114. StatService.Instance.StatProfit(); //实时统计创客收益
  115. StatHelpProfitService.Instance.StartUserTrade();
  116. StatHelpProfitService.Instance.ResetMaxTradeAmount(); //每月重置助利宝最大交易总额
  117. OperateService.Instance.Start(); //统计运营中心发货量
  118. OperateService.Instance.StartPosActNum(); //统计运营中心激活量
  119. OperateService.Instance.StartPosCouponSaleNum(); //统计运营中心机具券销售量
  120. StatNewService.Instance.StartStat(); //实时统计交易额RDS
  121. StatNewService.Instance.StartMer(); //实时统计商户交易额到RDS
  122. StatNewService.Instance.StartAct(); //统计激活数到RDS
  123. AddRecordService.Instance.StartTradeRecord(); //RDS交易记录队列
  124. AddRecordService.Instance.StartUserAccountRecord(); //RDS收支明细队列
  125. // AddRecordService.Instance.StartSpBindRecord(); //RDSSP绑定记录队列
  126. // AddRecordService.Instance.StartSpMerchants(); //RDSSP商户信息队列
  127. // AddRecordService.Instance.StartSpActivateRecord(); //RDSSP激活押金记录队列
  128. // AddRecordService.Instance.StartSpTradeRecord(); //RDSSP交易记录队列
  129. StatNewService.Instance.CreateTable(); //创建RDS分表
  130. ProfitService.Instance.AddTradeDaySummary(); //补TradeDaySummary数据
  131. ProfitService.Instance.AddUserAccountRecord(); //补UserAccountRecord数据
  132. ProfitService.Instance.AddProfitRecord(); //补ProfitRecord数据
  133. ProfitService.Instance.AddSubsidyRecord(); //补SubsidyRecord数据
  134. //必须打开的
  135. }
  136. }
  137. }