|
|
@@ -0,0 +1,137 @@
|
|
|
+using System;
|
|
|
+using System.Threading;
|
|
|
+using System.Linq;
|
|
|
+using System.Data;
|
|
|
+using Library;
|
|
|
+using MySystem.Models;
|
|
|
+using System.Collections.Generic;
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// 广电卡交易数据导入
|
|
|
+/// </summary>
|
|
|
+namespace MySystem
|
|
|
+{
|
|
|
+ public class SIMPosMerchantTradeService
|
|
|
+ {
|
|
|
+ public readonly static SIMPosMerchantTradeService Instance = new SIMPosMerchantTradeService();
|
|
|
+ private SIMPosMerchantTradeService()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Start()//启动
|
|
|
+ {
|
|
|
+ Thread thread = new Thread(ImportPostDo);
|
|
|
+ thread.IsBackground = true;
|
|
|
+ thread.Start();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ImportPostDo()
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string data = RedisDbconn.Instance.RPop<string>("SIMPosMerchantTradeQueue");
|
|
|
+ if (!string.IsNullOrEmpty(data))
|
|
|
+ {
|
|
|
+ string[] dataList = data.Split("#cut#");
|
|
|
+ string _ExcelPath = dataList[0];
|
|
|
+ string _Kind = dataList[1];
|
|
|
+ string checkKey = dataList[2];
|
|
|
+ string Operator = dataList[3]; // 操作人
|
|
|
+ int SuccessCount = 0;
|
|
|
+ int DoCount = 0;
|
|
|
+ string FullExcelPath = function.getPath(_ExcelPath);
|
|
|
+ FullExcelPath = FullExcelPath.Replace("//", "/");
|
|
|
+ DataTable list = new PublicFunction().ExcelToDataTable(FullExcelPath);
|
|
|
+ int TotalCount = list.Rows.Count;
|
|
|
+ while (DoCount < list.Rows.Count)
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ //导入人工已退
|
|
|
+ if (_Kind == "1")
|
|
|
+ {
|
|
|
+ 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 = dr[0].ToString().Replace("机具SN:", "");// 退押机具Sn
|
|
|
+ string Statuss = dr[1].ToString(); // 结果
|
|
|
+ string SeoDescription = dr[2].ToString();// 备注
|
|
|
+ int Status = 0;
|
|
|
+ if (Statuss == "SUCCESS")//成功
|
|
|
+ {
|
|
|
+ Status = 1;
|
|
|
+ }
|
|
|
+ if (Statuss == "FAIL")//失败
|
|
|
+ {
|
|
|
+ Status = 2;
|
|
|
+ }
|
|
|
+ var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
|
|
|
+ var merchantDepositReturns = db.MerchantDepositReturns.FirstOrDefault(m => m.MerchantId == pos.BindMerchantId && m.Status == 0) ?? new MerchantDepositReturns();
|
|
|
+ if (merchantDepositReturns.Id == 0)
|
|
|
+ {
|
|
|
+ RedisDbconn.Instance.AddList("ErrList" + checkKey, "以下操作失败,机具" + PosSn + ',' + "对应的退押订单" + merchantDepositReturns.SeoKeyword + "该订单未找到或不符合规则");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //失败
|
|
|
+ if (Status == 2)
|
|
|
+ {
|
|
|
+ var posm = db.PosMerchantInfo.FirstOrDefault(m => m.Id == merchantDepositReturns.MerchantId) ?? new PosMerchantInfo();
|
|
|
+ posm.StandardStatus = 101;
|
|
|
+ }
|
|
|
+ merchantDepositReturns.Status = Status;
|
|
|
+ merchantDepositReturns.UpdateDate = DateTime.Now;
|
|
|
+ merchantDepositReturns.SeoDescription = SeoDescription;
|
|
|
+ merchantDepositReturns.SeoTitle = Operator;
|
|
|
+ SuccessCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DoCount += Size;
|
|
|
+ db.SaveChanges();
|
|
|
+ tran.Commit();
|
|
|
+ if (DoCount >= list.Rows.Count)
|
|
|
+ {
|
|
|
+ RedisDbconn.Instance.Set("SIMPosMerchantTradeCheckImport:" + checkKey, "success|" + SuccessCount);
|
|
|
+ RedisDbconn.Instance.SetExpire("SIMPosMerchantTradeCheckImport:" + checkKey, 60000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ DoCount = list.Rows.Count;
|
|
|
+ function.WriteLog(ex.ToString(), "导入首台服务费退还结果");
|
|
|
+ tran.Rollback();
|
|
|
+ ErrorMsg msg = new ErrorMsg()
|
|
|
+ {
|
|
|
+ Time = DateTime.Now,
|
|
|
+ ErrorContent = ex.ToString(),
|
|
|
+ };
|
|
|
+ function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(msg), "导入首台服务费退还结果Excel文件异常");
|
|
|
+ }
|
|
|
+ tran.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Thread.Sleep(5000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "后台导入Excel文件队列异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|