using System; using System.Threading; using System.Linq; using System.Data; using Library; using MySystem.Models; using System.Collections.Generic; namespace MySystem { public class ExcelCheckFeeHelper { public readonly static ExcelCheckFeeHelper Instance = new ExcelCheckFeeHelper(); private ExcelCheckFeeHelper() { } public void Start()//启动 { Thread thread = new Thread(ImportPostDo); thread.IsBackground = true; thread.Start(); } public void ImportPostDo() { while (true) { string data = RedisDbconn.Instance.RPop("ExcelCheckFee"); if (!string.IsNullOrEmpty(data)) { string[] dataList = data.Split("#cut#"); string _ExcelPath = dataList[0]; string BrandId = dataList[1]; string Operator = dataList[2]; // 操作人 int DoCount = 0; string FullExcelPath = function.getPath(_ExcelPath); FullExcelPath = FullExcelPath.Replace("//", "/"); DataTable list = new PublicFunction().ExcelToDataTable(FullExcelPath); while (DoCount < list.Rows.Count) { WebCMSEntities db = new WebCMSEntities(); var tran = db.Database.BeginTransaction(); try { int Size = 100; if (list.Rows.Count - DoCount < 100) { Size = list.Rows.Count - DoCount; } Dictionary storeData = new Dictionary(); for (int i = DoCount; i < DoCount + Size; i++) { DataRow dr = list.Rows[i]; string posSn = ""; string feeRate = ""; string feeAmt = ""; if(BrandId == "7") //盛付通 { posSn = dr[0].ToString(); feeRate = dr[1].ToString(); feeAmt = dr[2].ToString(); if(feeAmt != "0") feeAmt = feeAmt.TrimEnd('0'); } AddData(db, posSn, feeRate, feeAmt); } DoCount += Size; tran.Commit(); } catch (Exception ex) { DoCount = list.Rows.Count; tran.Rollback(); function.WriteLog(ex.ToString(), "导入机具交易核对费率异常"); } tran.Dispose(); db.Dispose(); } } else { Thread.Sleep(5000); } } } public void AddData(WebCMSEntities db, string posSn, string feeRate, string feeAmt) { if(feeRate != "0.63" && feeRate != "0.6") { return; } PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == posSn); if(pos != null) { bool op = false; if(pos.BrandId == 12 || pos.BrandId == 13) { if(feeRate == "0.63" && pos.UpFeeFlag == 1 && pos.DownFeeFlag == 0) //稳定期 { op = true; } else if(feeRate == "0.63" && pos.DownFeeFlag == 1 && pos.DownFee == 0.63M) //稳定期A { op = true; } else if(feeRate == "0.6" && pos.DownFeeFlag == 0 && pos.DownFee == 0M) //扶持期 { op = true; } else if(feeRate == "0.6" && pos.DownFeeFlag == 1 && pos.DownFee == 0.6M) //稳定期B { op = true; } } else { if(feeRate == "0.63" && feeAmt == "3" && pos.UpFeeFlag == 1 && pos.DownFeeFlag == 0) //稳定期 { op = true; } else if(feeRate == "0.63" && feeAmt == "0" && pos.DownFeeFlag == 1 && pos.DownFee == 0.63M) //稳定期A { op = true; } else if(feeRate == "0.6" && feeAmt == "0" && pos.DownFeeFlag == 0 && pos.DownFee == 0M) //扶持期 { op = true; } else if(feeRate == "0.6" && feeAmt == "0" && pos.DownFeeFlag == 1 && pos.DownFee == 0.6M) //稳定期B { op = true; } } if(!op) { DateTime check = DateTime.Now.AddHours(-1); if(!db.PosFeeWarningRecord.Any(m => m.PosSn == posSn && m.CreateDate >= check)) { db.PosFeeWarningRecord.Add(new PosFeeWarningRecord() { CreateDate = DateTime.Now, UpdateDate = DateTime.Now, DownFee = pos.DownFee, DownFeeFlag = pos.DownFeeFlag, UpFeeFlag = pos.UpFeeFlag, TradeFeeAmt = feeAmt, TradeFeeRate = feeRate, PosSn = posSn, PosId = pos.Id, BrandId = pos.BrandId, }); db.SaveChanges(); } } } } } }