| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + content, "补原始数据");
- string[] data = content.Split('|');
- string jsonString = data[2];
- int BrandId = int.Parse(data[1]);
- string Kind = data[0];
- WebCMSEntities db = new WebCMSEntities();
- string key = "kxs_" + Kind + "_list_" + BrandId;
- function.WriteLog(key, "补原始数据");
- JobMqMsg obj = RedisDbconn.Instance.GetList<JobMqMsg>("GetSpData", 1, 1000).FirstOrDefault(m => m.OrderString.Contains(key));
- if(obj != null)
- {
- function.WriteLog("找到job", "补原始数据");
- PublicImportDataService.Instance.InsertData(key, jsonString, obj, BrandId);
- function.WriteLog("执行完毕", "补原始数据");
- }
- db.Dispose();
- }
- catch(Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "补原始数据异常");
- }
- }
- else
- {
- Thread.Sleep(5000);
- }
- }
- }
-
- }
|