4 Commitit 242a1eef12 ... 4b547c694c

Tekijä SHA1 Viesti Päivämäärä
  DuGuYang 4b547c694c Merge branch 'feature-dgy-进件区分银联品牌' into feature-dgy-功能测试 6 kuukautta sitten
  DuGuYang a6878befbb 今日获取昨日的交易 6 kuukautta sitten
  DuGuYang 67b8041174 Merge branch 'feature-dgy-进件区分银联品牌' into feature-dgy-功能测试 6 kuukautta sitten
  DuGuYang 156c05ad95 调整获取交易数据 6 kuukautta sitten
2 muutettua tiedostoa jossa 175 lisäystä ja 137 poistoa
  1. 106 86
      Util/HaoDa/GetHaoDaFTPInfoService.cs
  2. 69 51
      Util/HaoDa/TestHaoDaService.cs

+ 106 - 86
Util/HaoDa/GetHaoDaFTPInfoService.cs

@@ -24,15 +24,15 @@ namespace MySystem
 
         public void Start()
         {
-            //半小时执行获取好哒FTP交易数据
-            Thread th = new Thread(GetFTPDataInfoHalfHour);
-            th.IsBackground = true;
-            th.Start();
+            // //半小时执行获取好哒FTP交易数据
+            // Thread th = new Thread(GetFTPDataInfoHalfHour);
+            // th.IsBackground = true;
+            // th.Start();
 
-            //每天凌晨执行获取好哒FTP今日交易数据
-            Thread th1 = new Thread(GetFTPDataInfoToday);
-            th1.IsBackground = true;
-            th1.Start();
+            // //每天凌晨执行获取好哒FTP今日交易数据
+            // Thread th1 = new Thread(GetFTPDataInfoToday);
+            // th1.IsBackground = true;
+            // th1.Start();
 
             //每天凌晨执行获取好哒FTP昨日交易数据
             Thread th2 = new Thread(GetFTPDataInfoYesterday);
@@ -106,6 +106,8 @@ namespace MySystem
                                 TradeDate = DataListInfo[7];
                                 TradeCycle = DataListInfo[8];
 
+                                TradeDate = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2) + " " + TradeDate.Substring(8, 2) + ":" + TradeDate.Substring(10, 2) + ":" + TradeDate.Substring(12, 2);
+
                                 var PayMode = 0;
                                 if (PayWay.Contains("支付宝")) PayMode = 1;
                                 if (PayWay.Contains("微信")) PayMode = 2;
@@ -117,7 +119,7 @@ namespace MySystem
                                     var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
                                     if (orders.Id == 0)
                                     {
-                                        ConsumerOrders consumerOrders = new ConsumerOrders
+                                        var query = db.ConsumerOrders.Add(new ConsumerOrders()
                                         {
                                             Status = 1,
                                             CreateDate = DateTime.Parse(TradeDate),
@@ -129,7 +131,7 @@ namespace MySystem
                                             OrderNo = OrderNo,
                                             MerchantId = merchantAddInfo.Id,
                                             UserId = merchantInfo.UserId
-                                        };
+                                        }).Entity;
                                     }
                                 }
                             }
@@ -144,7 +146,17 @@ namespace MySystem
                 }
                 catch (WebException ex)
                 {
-                    Console.WriteLine("获取好哒FTP文件数据异常: " + ex.Message);
+                    // 如果抛出WebException,则可能是文件不存在
+                    // 根据响应状态码判断是否文件不存在
+                    if (((FtpWebResponse)ex.Response).StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString() + "文件" + filePath + "不存在", "获取好哒FTP文件数据异常"); // 文件不存在,返回false
+                    }
+                    else
+                    {
+                        // 其他错误
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
+                    }
                 }
             }
         }
@@ -217,6 +229,8 @@ namespace MySystem
                                     TradeDate = DataListInfo[7];
                                     TradeCycle = DataListInfo[8];
 
+                                    TradeDate = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2) + " " + TradeDate.Substring(8, 2) + ":" + TradeDate.Substring(10, 2) + ":" + TradeDate.Substring(12, 2);
+
                                     var PayMode = 0;
                                     if (PayWay.Contains("支付宝")) PayMode = 1;
                                     if (PayWay.Contains("微信")) PayMode = 2;
@@ -228,7 +242,7 @@ namespace MySystem
                                         var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
                                         if (orders.Id == 0)
                                         {
-                                            ConsumerOrders consumerOrders = new ConsumerOrders
+                                            var query = db.ConsumerOrders.Add(new ConsumerOrders()
                                             {
                                                 Status = 1,
                                                 CreateDate = DateTime.Parse(TradeDate),
@@ -240,7 +254,7 @@ namespace MySystem
                                                 OrderNo = OrderNo,
                                                 MerchantId = merchantAddInfo.Id,
                                                 UserId = merchantInfo.UserId
-                                            };
+                                            }).Entity;
                                         }
                                     }
                                 }
@@ -255,7 +269,7 @@ namespace MySystem
                     }
                     catch (WebException ex)
                     {
-                        Console.WriteLine("获取好哒FTP文件数据异常: " + ex.Message);
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
                     }
                 }
             }
@@ -281,92 +295,98 @@ namespace MySystem
 
             while (true)
             {
-                if (DateTime.Now.Hour > 0 && DateTime.Now.Hour < 9)
+                string check = function.ReadInstance("/GetFTPDataInfoYesterday/check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt");
+                if (string.IsNullOrEmpty(check))
                 {
-                    try
+                    if (DateTime.Now.Hour > 11 && DateTime.Now.Hour < 24)
                     {
-                        // 创建FtpWebRequest对象
-                        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerAddress + filePath);
-                        request.Method = WebRequestMethods.Ftp.DownloadFile;
-                        request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
+                        try
+                        {
+                            // 创建FtpWebRequest对象
+                            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerAddress + filePath);
+                            request.Method = WebRequestMethods.Ftp.DownloadFile;
+                            request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
 
-                        // 使用WebResponse获取响应
-                        FtpWebResponse response = (FtpWebResponse)request.GetResponse();
+                            // 使用WebResponse获取响应
+                            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
 
-                        // 打开数据流
-                        Stream responseStream = response.GetResponseStream();
-                        using (StreamReader reader = new StreamReader(responseStream))
-                        {
-                            WebCMSEntities db = new WebCMSEntities();
-                            // 读取数据
-                            string fileContents = reader.ReadToEnd();
-                            if (!string.IsNullOrEmpty(fileContents))
+                            // 打开数据流
+                            Stream responseStream = response.GetResponseStream();
+                            using (StreamReader reader = new StreamReader(responseStream))
                             {
-                                var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
-                                var DataList = DataInfo[1].Split('\n');
-                                foreach (var DataListItem in DataList)
+                                WebCMSEntities db = new WebCMSEntities();
+                                // 读取数据
+                                string fileContents = reader.ReadToEnd();
+                                if (!string.IsNullOrEmpty(fileContents))
                                 {
-                                    var DataListInfo = DataListItem.Split(',');
-
-                                    var MerchantNo = ""; // 商户号
-                                    var BaseNo = ""; // 设备号
-                                    var OrderNo = ""; // 订单号
-                                    var PayWay = ""; // 支付方式(微信 支付宝)
-                                    var TradeType = ""; // 交易类型
-                                    var TradeAmount = ""; // 交易金额
-                                    var TradeFee = ""; // 交易手续费
-                                    var TradeDate = ""; // 交易时间
-                                    var TradeCycle = ""; // 结算周期
-
-                                    MerchantNo = DataListInfo[0];
-                                    BaseNo = DataListInfo[1];
-                                    OrderNo = DataListInfo[2];
-                                    PayWay = DataListInfo[3];
-                                    TradeType = DataListInfo[4];
-                                    TradeAmount = DataListInfo[5];
-                                    TradeFee = DataListInfo[6];
-                                    TradeDate = DataListInfo[7];
-                                    TradeCycle = DataListInfo[8];
-
-                                    var PayMode = 0;
-                                    if (PayWay.Contains("支付宝")) PayMode = 1;
-                                    if (PayWay.Contains("微信")) PayMode = 2;
-
-                                    var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MerchantAddInfo();
-                                    if (merchantAddInfo.Id > 0)
+                                    var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
+                                    var DataList = DataInfo[1].Split('\n');
+                                    foreach (var DataListItem in DataList)
                                     {
-                                        var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MerchantInfo();
-                                        var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
-                                        if (orders.Id == 0)
+                                        var DataListInfo = DataListItem.Split(',');
+
+                                        var MerchantNo = ""; // 商户号
+                                        var BaseNo = ""; // 设备号
+                                        var OrderNo = ""; // 订单号
+                                        var PayWay = ""; // 支付方式(微信 支付宝)
+                                        var TradeType = ""; // 交易类型
+                                        var TradeAmount = ""; // 交易金额
+                                        var TradeFee = ""; // 交易手续费
+                                        var TradeDate = ""; // 交易时间
+                                        var TradeCycle = ""; // 结算周期
+
+                                        MerchantNo = DataListInfo[0];
+                                        BaseNo = DataListInfo[1];
+                                        OrderNo = DataListInfo[2];
+                                        PayWay = DataListInfo[3];
+                                        TradeType = DataListInfo[4];
+                                        TradeAmount = DataListInfo[5];
+                                        TradeFee = DataListInfo[6];
+                                        TradeDate = DataListInfo[7];
+                                        TradeCycle = DataListInfo[8];
+
+                                        TradeDate = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2) + " " + TradeDate.Substring(8, 2) + ":" + TradeDate.Substring(10, 2) + ":" + TradeDate.Substring(12, 2);
+
+                                        var PayMode = 0;
+                                        if (PayWay.Contains("支付宝")) PayMode = 1;
+                                        if (PayWay.Contains("微信")) PayMode = 2;
+
+                                        var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MerchantAddInfo();
+                                        if (merchantAddInfo.Id > 0)
                                         {
-                                            ConsumerOrders consumerOrders = new ConsumerOrders
+                                            var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MerchantInfo();
+                                            var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
+                                            if (orders.Id == 0)
                                             {
-                                                Status = 1,
-                                                CreateDate = DateTime.Parse(TradeDate),
-                                                UpdateDate = DateTime.Parse(TradeDate),
-                                                SnNo = BaseNo,
-                                                PayMoney = decimal.Parse(TradeAmount),
-                                                PayMode = PayMode,
-                                                SeoTitle = OrderNo,
-                                                OrderNo = OrderNo,
-                                                MerchantId = merchantAddInfo.Id,
-                                                UserId = merchantInfo.UserId
-                                            };
+                                                var query = db.ConsumerOrders.Add(new ConsumerOrders()
+                                                {
+                                                    Status = 1,
+                                                    CreateDate = DateTime.Parse(TradeDate),
+                                                    UpdateDate = DateTime.Parse(TradeDate),
+                                                    SnNo = BaseNo,
+                                                    PayMoney = decimal.Parse(TradeAmount),
+                                                    PayMode = PayMode,
+                                                    SeoTitle = OrderNo,
+                                                    OrderNo = OrderNo,
+                                                    MerchantId = merchantAddInfo.Id,
+                                                    UserId = merchantInfo.UserId
+                                                }).Entity;
+                                            }
                                         }
                                     }
+                                    db.SaveChanges();
+                                    db.Dispose();
                                 }
-                                db.SaveChanges();
-                                db.Dispose();
-                            }
 
-                            // 关闭响应
-                            response.Close();
-                            Thread.Sleep(1800000);
+                                // 关闭响应
+                                response.Close();
+                                Thread.Sleep(1800000);
+                            }
+                        }
+                        catch (WebException ex)
+                        {
+                            function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
                         }
-                    }
-                    catch (WebException ex)
-                    {
-                        Console.WriteLine("获取好哒FTP文件数据异常: " + ex.Message);
                     }
                 }
             }

+ 69 - 51
Util/HaoDa/TestHaoDaService.cs

@@ -30,7 +30,7 @@ namespace MySystem
         public void StartListen()
         {
             // GetFTPListInfo(); // 获取好哒FTPInfo
-            // GetFTPDataInfo(); //获取好哒FTPDataInfo
+            GetFTPDataInfo(); //获取好哒FTPDataInfo
             //开户意愿申请
             // RedisDbconn.Instance.AddList("AlipayForHaoDaQueue",824);
             // RedisDbconn.Instance.AddList("WeChatForHaoDaQueue",824);
@@ -203,7 +203,7 @@ namespace MySystem
             }
             catch (Exception ex)
             {
-                Console.WriteLine("获取文件出错:" + ex.Message);
+                function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
             }
             return strs;
         }
@@ -240,61 +240,69 @@ namespace MySystem
                     WebCMSEntities db = new WebCMSEntities();
                     // 读取数据
                     string fileContents = reader.ReadToEnd();
-                    var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
-                    var DataList = DataInfo[1].Split('\n');
-                    foreach (var DataListItem in DataList)
+                    if (!string.IsNullOrEmpty(fileContents))
                     {
-                        var DataListInfo = DataListItem.Split(',');
-
-                        var MerchantNo = ""; // 商户号
-                        var BaseNo = ""; // 设备号
-                        var OrderNo = ""; // 订单号
-                        var PayWay = ""; // 支付方式(微信 支付宝)
-                        var TradeType = ""; // 交易类型
-                        var TradeAmount = ""; // 交易金额
-                        var TradeFee = ""; // 交易手续费
-                        var TradeDate = ""; // 交易时间
-                        var TradeCycle = ""; // 结算周期
-
-                        MerchantNo = DataListInfo[0];
-                        BaseNo = DataListInfo[1];
-                        OrderNo = DataListInfo[2];
-                        PayWay = DataListInfo[3];
-                        TradeType = DataListInfo[4];
-                        TradeAmount = DataListInfo[5];
-                        TradeFee = DataListInfo[6];
-                        TradeDate = DataListInfo[7];
-                        TradeCycle = DataListInfo[8];
-
-                        var PayMode = 0;
-                        if (PayWay.Contains("支付宝")) PayMode = 1;
-                        if (PayWay.Contains("微信")) PayMode = 2;
-
-                        var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MerchantAddInfo();
-                        if (merchantAddInfo.Id > 0)
+                        var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
+                        var DataList = DataInfo[1].Split('\n');
+                        foreach (var DataListItem in DataList)
                         {
-                            var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MerchantInfo();
-                            var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
-                            if (orders.Id == 0)
+                            var DataListInfo = DataListItem.Split(',');
+
+                            var MerchantNo = ""; // 商户号
+                            var BaseNo = ""; // 设备号
+                            var OrderNo = ""; // 订单号
+                            var PayWay = ""; // 支付方式(微信 支付宝)
+                            var TradeType = ""; // 交易类型
+                            var TradeAmount = ""; // 交易金额
+                            var TradeFee = ""; // 交易手续费
+                            var TradeDate = ""; // 交易时间
+                            var TradeCycle = ""; // 结算周期
+
+                            MerchantNo = DataListInfo[0];
+                            BaseNo = DataListInfo[1];
+                            OrderNo = DataListInfo[2];
+                            PayWay = DataListInfo[3];
+                            TradeType = DataListInfo[4];
+                            TradeAmount = DataListInfo[5];
+                            TradeFee = DataListInfo[6];
+                            TradeDate = DataListInfo[7];
+                            TradeCycle = DataListInfo[8];
+
+                            TradeDate = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2) + " " + TradeDate.Substring(8, 2) + ":" + TradeDate.Substring(10, 2) + ":" + TradeDate.Substring(12, 2);
+
+                            var PayMode = 0;
+                            if (PayWay.Contains("支付宝")) PayMode = 1;
+                            if (PayWay.Contains("微信")) PayMode = 2;
+
+                            var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MerchantAddInfo();
+                            if (merchantAddInfo.Id > 0)
                             {
-                                ConsumerOrders consumerOrders = new ConsumerOrders
+                                var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MerchantInfo();
+                                var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
+                                if (orders.Id == 0)
                                 {
-                                    Status = 1,
-                                    CreateDate = DateTime.Parse(TradeDate),
-                                    UpdateDate = DateTime.Parse(TradeDate),
-                                    SnNo = BaseNo,
-                                    PayMoney = decimal.Parse(TradeAmount),
-                                    PayMode = PayMode,
-                                    SeoTitle = OrderNo,
-                                    OrderNo = OrderNo,
-                                    MerchantId = merchantAddInfo.Id,
-                                    UserId = merchantInfo.UserId
-                                };
+                                    var query = db.ConsumerOrders.Add(new ConsumerOrders()
+                                    {
+                                        Status = 1,
+                                        CreateDate = DateTime.Parse(TradeDate),
+                                        UpdateDate = DateTime.Parse(TradeDate),
+                                        SnNo = BaseNo,
+                                        PayMoney = decimal.Parse(TradeAmount),
+                                        PayMode = PayMode,
+                                        SeoTitle = OrderNo,
+                                        OrderNo = OrderNo,
+                                        MerchantId = merchantAddInfo.Id,
+                                        UserId = merchantInfo.UserId
+                                    }).Entity;
+                                }
                             }
                         }
+                        db.SaveChanges();
+                        db.Dispose();
                     }
-                    db.SaveChanges();
-                    db.Dispose();
+
+                    // 关闭响应
+                    response.Close();
                 }
 
                 // 关闭响应
@@ -302,7 +310,17 @@ namespace MySystem
             }
             catch (WebException ex)
             {
-                Console.WriteLine("获取好哒FTP文件数据异常: " + ex.Message);
+                // 如果抛出WebException,则可能是文件不存在
+                // 根据响应状态码判断是否文件不存在
+                if (((FtpWebResponse)ex.Response).StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString() + "文件" + filePath + "不存在", "获取好哒FTP文件数据异常"); // 文件不存在,返回false
+                }
+                else
+                {
+                    // 其他错误
+                    function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
+                }
             }
         }