Browse Source

剥离广电卡商户信息推送线程

lcl 3 months ago
parent
commit
f8bf12fd2e

+ 3 - 3
AppStart/Helper/SycnSpServer/SycnSpBindService.cs

@@ -101,7 +101,7 @@ namespace MySystem
                 {
                     WebCMSEntities spdb = new WebCMSEntities();
                     PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
-                    DateTime start = DateTime.Now.AddDays(-100);
+                    DateTime start = DateTime.Now.AddDays(-365);
                     int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/BindRecordId.txt")));
                     var Binds = spdb.BindRecord.Where(m => m.Id >= StartId && m.CreateTime >= start && m.ProductType == "14" && m.Status == 1).OrderByDescending(m => m.Id).Take(20).ToList();
                     foreach (var Bind in Binds)
@@ -142,7 +142,7 @@ namespace MySystem
                         }
                         catch (Exception ex)
                         {
-                            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常");
+                            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP广电卡绑定数据到MAIN异常");
                         }
                     }
                     spdb.SaveChanges();
@@ -152,7 +152,7 @@ namespace MySystem
                 }
                 catch (Exception ex)
                 {
-                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP绑定数据到MAIN异常");
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP广电卡绑定数据到MAIN异常");
                 }
                 Thread.Sleep(1000);
             }

+ 75 - 11
AppStart/Helper/SycnSpServer/SycnSpMerchantService.cs

@@ -32,20 +32,20 @@ namespace MySystem
                     DateTime start = DateTime.Now.AddDays(-100);
                     DateTime end = DateTime.Now.AddMinutes(-2);
                     int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/MerchantsId.txt")));
-                    var Mers = spdb.Merchants.Where(m => m.Id >= StartId && m.CreateTime >= start && m.CreateTime <= end && m.Status == 1).OrderByDescending(m => m.Id).Take(20).ToList();
+                    var Mers = spdb.Merchants.Where(m => m.Id >= StartId && m.CreateTime >= start && m.CreateTime <= end && m.Status == 1 && m.ProductType != "14").OrderByDescending(m => m.Id).Take(20).ToList();
                     // var Mers = spdb.Merchants.Where(m => m.Id == 765841).ToList();
                     foreach (var Mer in Mers)
                     {
                         var tran = db.Database.BeginTransaction();
                         try
                         {
-                            if(Mer.Field2 != "解绑" && Mer.Field2 != "UNBIND")
+                            if (Mer.Field2 != "解绑" && Mer.Field2 != "UNBIND")
                             {
-                                if(Utils.Instance.IsWifi(int.Parse(Mer.ProductType)))
+                                if (Utils.Instance.IsWifi(int.Parse(Mer.ProductType)))
                                 {
                                     Mer.MerNo = Mer.SnNo;
                                     PosPushDataNewHelper.Bind(Mer);
-                                    if(function.CheckNull(Mer.AgentName).StartsWith("YCJG"))
+                                    if (function.CheckNull(Mer.AgentName).StartsWith("YCJG"))
                                     {
                                         PosPushDataNewHelper.Deposit(new ActivateRecord()
                                         {
@@ -57,28 +57,28 @@ namespace MySystem
                                         });
                                     }
                                 }
-                                else if(Mer.ProductType == "12" || Mer.ProductType == "30")
+                                else if (Mer.ProductType == "12" || Mer.ProductType == "30")
                                 {
                                     MerchantRecord merInfo = new MerchantRecord();
-                                    if(Mer.ProductType == "12") merInfo = spdb.MerchantRecord.FirstOrDefault(m => m.MerNo == Mer.MerNo);
-                                    if(Mer.ProductType == "30") 
+                                    if (Mer.ProductType == "12") merInfo = spdb.MerchantRecord.FirstOrDefault(m => m.MerNo == Mer.MerNo);
+                                    if (Mer.ProductType == "30")
                                     {
                                         merInfo = spdb.MerchantRecord.FirstOrDefault(m => m.Field3 == Mer.MerNo);
-                                        if(merInfo == null) merInfo = spdb.MerchantRecord.FirstOrDefault(m => m.MerNo == Mer.MerNo);
+                                        if (merInfo == null) merInfo = spdb.MerchantRecord.FirstOrDefault(m => m.MerNo == Mer.MerNo);
                                     }
-                                    if(merInfo != null)
+                                    if (merInfo != null)
                                     {
                                         Mer.MerNo = merInfo.MerNo;
                                         Mer.MerIdcardNo = merInfo.LegalIdCard;
                                         Mer.MerName = merInfo.MerName;
-                                        if(Mer.ProductType == "30")
+                                        if (Mer.ProductType == "30")
                                         {
                                             Mer.MerMobile = merInfo.Field2;
                                         }
                                         PosPushDataNewHelper.Bind(Mer);
                                     }
                                 }
-                                else if(!Utils.Instance.IsHaoDa(int.Parse(Mer.ProductType)))
+                                else if (!Utils.Instance.IsHaoDa(int.Parse(Mer.ProductType)))
                                 {
                                     PosPushDataNewHelper.Bind(Mer);
                                 }
@@ -134,5 +134,69 @@ namespace MySystem
                 }
             }
         }
+
+
+
+
+
+
+        public void StartSim()
+        {
+            Thread th = new Thread(StartSimDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartSimDo()
+        {
+            while (true)
+            {
+                try
+                {
+                    WebCMSEntities spdb = new WebCMSEntities();
+                    PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                    DateTime start = DateTime.Now.AddDays(-365);
+                    DateTime end = DateTime.Now.AddMinutes(-2);
+                    int StartId = 400000;
+                    var Mers = spdb.Merchants.Where(m => m.Id >= StartId && m.CreateTime >= start && m.CreateTime <= end && m.Status == 1 && m.ProductType == "14").OrderByDescending(m => m.Id).Take(20).ToList();
+                    foreach (var Mer in Mers)
+                    {
+                        var tran = db.Database.BeginTransaction();
+                        try
+                        {
+                            if (Mer.Field2 != "解绑" && Mer.Field2 != "UNBIND")
+                            {
+                                if (!Utils.Instance.IsHaoDa(int.Parse(Mer.ProductType)))
+                                {
+                                    PosPushDataNewHelper.Bind(Mer);
+                                }
+                            }
+                            Merchants edit = spdb.Merchants.FirstOrDefault(m => m.Id == Mer.Id);
+                            if (edit != null)
+                            {
+                                edit.Status = 2;
+                                spdb.SaveChanges();
+                            }
+                            tran.Commit();
+                        }
+                        catch (Exception ex)
+                        {
+                            tran.Rollback();
+                            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Mer.Id, "同步SP广电卡商户数据到MAIN异常");
+                        }
+                        tran.Dispose();
+                    }
+                    spdb.SaveChanges();
+                    spdb.Dispose();
+                    db.SaveChanges();
+                    db.Dispose();
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP广电卡商户数据到MAIN异常");
+                }
+                Thread.Sleep(1000);
+            }
+        }
     }
 }

+ 1 - 0
Startup.cs

@@ -172,6 +172,7 @@ namespace MySystem
                 SycnSpBindZkbService.Instance.Start(); //同步吱客宝SP绑定数据
                 SycnSpBindService.Instance.StartSim(); //同步SP广电卡绑定数据
                 SycnSpMerchantService.Instance.Start(); //同步SP商户数据
+                SycnSpMerchantService.Instance.StartSim(); //同步SP广电卡商户数据
                 SycnSpActiveService.Instance.Start(); //同步SP激活数据
                 SycnSpTradeService.Instance.Start(); //同步SP交易数据
                 SycnSpTradeTmpService.Instance.Start(); //同步SP交易数据