| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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<string>("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<string, int> storeData = new Dictionary<string, int>();
- 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();
- }
- }
- }
- }
- }
- }
|