ExcelCheckFeeHelper.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Threading;
  3. using System.Linq;
  4. using System.Data;
  5. using Library;
  6. using MySystem.Models;
  7. using System.Collections.Generic;
  8. namespace MySystem
  9. {
  10. public class ExcelCheckFeeHelper
  11. {
  12. public readonly static ExcelCheckFeeHelper Instance = new ExcelCheckFeeHelper();
  13. private ExcelCheckFeeHelper()
  14. {
  15. }
  16. public void Start()//启动
  17. {
  18. Thread thread = new Thread(ImportPostDo);
  19. thread.IsBackground = true;
  20. thread.Start();
  21. }
  22. public void ImportPostDo()
  23. {
  24. while (true)
  25. {
  26. string data = RedisDbconn.Instance.RPop<string>("ExcelCheckFee");
  27. if (!string.IsNullOrEmpty(data))
  28. {
  29. string[] dataList = data.Split("#cut#");
  30. string _ExcelPath = dataList[0];
  31. string BrandId = dataList[1];
  32. string Operator = dataList[2]; // 操作人
  33. int DoCount = 0;
  34. string FullExcelPath = function.getPath(_ExcelPath);
  35. FullExcelPath = FullExcelPath.Replace("//", "/");
  36. DataTable list = new PublicFunction().ExcelToDataTable(FullExcelPath);
  37. while (DoCount < list.Rows.Count)
  38. {
  39. WebCMSEntities db = new WebCMSEntities();
  40. var tran = db.Database.BeginTransaction();
  41. try
  42. {
  43. int Size = 100;
  44. if (list.Rows.Count - DoCount < 100)
  45. {
  46. Size = list.Rows.Count - DoCount;
  47. }
  48. Dictionary<string, int> storeData = new Dictionary<string, int>();
  49. for (int i = DoCount; i < DoCount + Size; i++)
  50. {
  51. DataRow dr = list.Rows[i];
  52. string posSn = "";
  53. string feeRate = "";
  54. string feeAmt = "";
  55. if(BrandId == "7") //盛付通
  56. {
  57. posSn = dr[0].ToString();
  58. feeRate = dr[1].ToString();
  59. feeAmt = dr[2].ToString();
  60. if(feeAmt != "0") feeAmt = feeAmt.TrimEnd('0');
  61. }
  62. AddData(db, posSn, feeRate, feeAmt);
  63. }
  64. DoCount += Size;
  65. tran.Commit();
  66. }
  67. catch (Exception ex)
  68. {
  69. DoCount = list.Rows.Count;
  70. tran.Rollback();
  71. function.WriteLog(ex.ToString(), "导入机具交易核对费率异常");
  72. }
  73. tran.Dispose();
  74. db.Dispose();
  75. }
  76. }
  77. else
  78. {
  79. Thread.Sleep(5000);
  80. }
  81. }
  82. }
  83. public void AddData(WebCMSEntities db, string posSn, string feeRate, string feeAmt)
  84. {
  85. if(feeRate != "0.63" && feeRate != "0.6")
  86. {
  87. return;
  88. }
  89. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == posSn);
  90. if(pos != null)
  91. {
  92. bool op = false;
  93. if(pos.BrandId == 12 || pos.BrandId == 13)
  94. {
  95. if(feeRate == "0.63" && pos.UpFeeFlag == 1 && pos.DownFeeFlag == 0) //稳定期
  96. {
  97. op = true;
  98. }
  99. else if(feeRate == "0.63" && pos.DownFeeFlag == 1 && pos.DownFee == 0.63M) //稳定期A
  100. {
  101. op = true;
  102. }
  103. else if(feeRate == "0.6" && pos.DownFeeFlag == 0 && pos.DownFee == 0M) //扶持期
  104. {
  105. op = true;
  106. }
  107. else if(feeRate == "0.6" && pos.DownFeeFlag == 1 && pos.DownFee == 0.6M) //稳定期B
  108. {
  109. op = true;
  110. }
  111. }
  112. else
  113. {
  114. if(feeRate == "0.63" && feeAmt == "3" && pos.UpFeeFlag == 1 && pos.DownFeeFlag == 0) //稳定期
  115. {
  116. op = true;
  117. }
  118. else if(feeRate == "0.63" && feeAmt == "0" && pos.DownFeeFlag == 1 && pos.DownFee == 0.63M) //稳定期A
  119. {
  120. op = true;
  121. }
  122. else if(feeRate == "0.6" && feeAmt == "0" && pos.DownFeeFlag == 0 && pos.DownFee == 0M) //扶持期
  123. {
  124. op = true;
  125. }
  126. else if(feeRate == "0.6" && feeAmt == "0" && pos.DownFeeFlag == 1 && pos.DownFee == 0.6M) //稳定期B
  127. {
  128. op = true;
  129. }
  130. }
  131. if(!op)
  132. {
  133. DateTime check = DateTime.Now.AddHours(-1);
  134. if(!db.PosFeeWarningRecord.Any(m => m.PosSn == posSn && m.CreateDate >= check))
  135. {
  136. db.PosFeeWarningRecord.Add(new PosFeeWarningRecord()
  137. {
  138. CreateDate = DateTime.Now,
  139. UpdateDate = DateTime.Now,
  140. DownFee = pos.DownFee,
  141. DownFeeFlag = pos.DownFeeFlag,
  142. UpFeeFlag = pos.UpFeeFlag,
  143. TradeFeeAmt = feeAmt,
  144. TradeFeeRate = feeRate,
  145. PosSn = posSn,
  146. PosId = pos.Id,
  147. BrandId = pos.BrandId,
  148. });
  149. db.SaveChanges();
  150. }
  151. }
  152. }
  153. }
  154. }
  155. }