TestHelper.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5. using System.Data;
  6. using MySystem;
  7. using MySystem.PxcModels;
  8. using Library;
  9. public class TestHelper
  10. {
  11. public readonly static TestHelper Instance = new TestHelper();
  12. private TestHelper()
  13. {
  14. }
  15. public void Start()
  16. {
  17. Thread th = new Thread(setLdFee);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. public void StartEverDay()
  22. {
  23. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  24. DateTime end = DateTime.Parse("2022-04-19 00:00:00");
  25. DateTime check = DateTime.Parse("2022-03-11");
  26. while (check <= end)
  27. {
  28. StatMerchantTrade(check.ToString("yyyy-MM-dd"));
  29. check = check.AddDays(1);
  30. }
  31. }
  32. private void StatMerchantTrade(string date)
  33. {
  34. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "执行商户交易额日志");
  35. WebCMSEntities db = new WebCMSEntities();
  36. try
  37. {
  38. DataTable selfdt = OtherMySqlConn.dtable("select MerchantId,BrandId,DATE_FORMAT(CreateDate,'%Y-%m-%d') as TradeDate,sum(TradeAmount) as TradeAmount from TradeRecord group by MerchantId,BrandId,DATE_FORMAT(CreateDate,'%Y-%m-%d') order by MerchantId,BrandId,DATE_FORMAT(CreateDate,'%Y-%m-%d')");
  39. foreach (DataRow selfDr in selfdt.Rows)
  40. {
  41. int BrandId = int.Parse(selfDr["BrandId"].ToString());
  42. int MerchantId = int.Parse(selfDr["MerchantId"].ToString());
  43. string TradeDate = selfDr["TradeDate"].ToString();
  44. TradeDate = TradeDate.Replace("-", "");
  45. string TradeMonth = TradeDate.Substring(0, 6);
  46. decimal TradeAmount = decimal.Parse(selfDr["TradeAmount"].ToString());
  47. PosMerchantTradeSummay merStat = db.PosMerchantTradeSummay.FirstOrDefault(m => m.MerchantId == MerchantId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.BrandId == BrandId);
  48. if (merStat == null)
  49. {
  50. merStat = db.PosMerchantTradeSummay.Add(new PosMerchantTradeSummay()
  51. {
  52. MerchantId = MerchantId,
  53. TradeMonth = TradeMonth,
  54. TradeDate = TradeDate,
  55. BrandId = BrandId,
  56. }).Entity;
  57. db.SaveChanges();
  58. }
  59. merStat.TradeAmount += TradeAmount;
  60. db.SaveChanges();
  61. }
  62. }
  63. catch (Exception ex)
  64. {
  65. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额");
  66. }
  67. db.Dispose();
  68. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "执行商户交易额日志");
  69. }
  70. private void setLdFee()
  71. {
  72. // DataTable dt = CustomerSqlConn.dtable("select KqMerNo,BrandId from PosMerchantInfo where Id in (select BindMerchantId from PosMachinesTwo where BrandId in (10,11) and DownFeeFlag=1 and BindingTime<'2023-08-06 00:00:00')", "server=rm-2vcs4j67tla603c9d5o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsProfitServer;charset=utf8;");
  73. // foreach(DataRow dr in dt.Rows)
  74. // {
  75. // function.WriteLog(dr["KqMerNo"].ToString(), "临时设置联动费率日志");
  76. // string result = SetDepositPostService.Instance.LDFeeRate(dr["KqMerNo"].ToString(), "0.0063", int.Parse(dr["BrandId"].ToString()), 0);
  77. // function.WriteLog(result + "\n\n", "临时设置联动费率日志");
  78. // }
  79. bool op = true;
  80. while(op)
  81. {
  82. int page = int.Parse(function.CheckInt(function.ReadInstance("/TmpSetLdFee/page.txt")));
  83. if(page < 1) page = 50;
  84. int skip = (page - 1) * 100;
  85. DataTable dt = CustomerSqlConn.dtable("select KqMerNo,BrandId from PosMerchantInfo where Id in (select BindMerchantId from PosMachinesTwo where BrandId in (10,11) and DownFeeFlag=0 and BindingTime<'2023-08-06 00:00:00') limit " + skip + ",100", "server=rm-2vcs4j67tla603c9d5o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsProfitServer;charset=utf8;");
  86. if(dt.Rows.Count > 0)
  87. {
  88. foreach(DataRow dr in dt.Rows)
  89. {
  90. function.WriteLog(dr["KqMerNo"].ToString(), "临时设置联动费率日志");
  91. string result = SetDepositPostService.Instance.LDFeeRate(dr["KqMerNo"].ToString(), "0.0063", int.Parse(dr["BrandId"].ToString()), 3);
  92. function.WriteLog(result + "\n\n", "临时设置联动费率日志");
  93. }
  94. page += 1;
  95. function.WritePage("/TmpSetLdFee/", "page.txt", page.ToString());
  96. }
  97. else
  98. {
  99. op = false;
  100. function.WriteLog("执行结束\n\n", "临时设置联动费率日志");
  101. }
  102. dt.Dispose();
  103. dt.Clear();
  104. }
  105. }
  106. }