Explorar o código

补原始数据队列

lichunlei hai 1 día
pai
achega
dc5338a4e5
Modificáronse 3 ficheiros con 61 adicións e 1 borrados
  1. 1 1
      AppStart/Helper/PublicImportDataService.cs
  2. 59 0
      AppStart/Helper/SourceDataToDb.cs
  3. 1 0
      Startup.cs

+ 1 - 1
AppStart/Helper/PublicImportDataService.cs

@@ -229,7 +229,7 @@ namespace MySystem
             LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\r\n" + header + "\r\n" + content, BrandName + "推送消息");
         }
 
-        private void InsertData(string key, string content, JobMqMsg jobInfo, int BrandId)
+        public void InsertData(string key, string content, JobMqMsg jobInfo, int BrandId)
         {
             string Id = DoQueue(content, jobInfo.BrandInfo, BrandId);
             // 商户入库

+ 59 - 0
AppStart/Helper/SourceDataToDb.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Threading;
+using Library;
+using LitJson;
+using MySystem;
+using MySystem.Models;
+
+public class SourceDataToDb
+{
+    public readonly static SourceDataToDb Instance = new SourceDataToDb();
+    private SourceDataToDb()
+    { }
+
+    public void Start()
+    {
+        Thread th = new Thread(DoWorks);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    public void DoWorks()
+    {
+        while (true)
+        {
+            string content = RedisDbconn.Instance.RPop<string>("DataToDbQueue");
+            if (!string.IsNullOrEmpty(content))
+            {
+                try
+                {
+                    string[] data = content.Split('|');
+                    string jsonString = data[2];
+                    int BrandId = int.Parse(data[1]);
+                    int Kind = int.Parse(data[0]);
+                    WebCMSEntities db = new WebCMSEntities();
+                    string key = "kxs_" + Kind + "_list_" + BrandId;
+                    JobMqMsg obj = RedisDbconn.Instance.GetList<JobMqMsg>("GetSpData", 1, 1000).FirstOrDefault(m => m.OrderString.Contains(key));
+                    if(obj != null)
+                    {
+                        PublicImportDataService.Instance.InsertData(key, content, obj, BrandId);
+                    }
+                    db.Dispose();
+                }
+                catch(Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "接收云长WIFI设备绑定异常");
+                }
+            }
+            else
+            {
+                Thread.Sleep(5000);
+            }
+        }
+    }
+
+    
+}

+ 1 - 0
Startup.cs

@@ -225,6 +225,7 @@ namespace MySystem
             SpNoticeHelper.Instance.Start();
             LogHelper.Instance.Start();
             CheckWifiData.Instance.Start(); //解析wifi设备通知数据
+            SourceDataToDb.Instance.Start(); //补原始数据
             // 必须执行
         }
     }