123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using MySystem.Models;
- using System;
- using System.Linq;
- namespace MySystem
- {
- public class StoreChangeHistoryHelper
- {
- public readonly static StoreChangeHistoryHelper Instance = new StoreChangeHistoryHelper();
- private StoreChangeHistoryHelper()
- { }
- public string Start()
- {
- bool op = true;
- WebCMSEntities db = new WebCMSEntities();
- string result = "success";
- int total = 0;
- while (op)
- {
- StoreChangeHistory PopData = new StoreChangeHistory();
- try
- {
- //获取apserver待同步的数据,执行入库
- PopData = TendisDbconn.Instance.RPop<StoreChangeHistory>("Pop:StoreChangeHistory");
- if (PopData != null)
- {
- // StoreChangeHistory checkExist = db.StoreChangeHistory.FirstOrDefault(m => m.Id == PopData.Id);
- // if (checkExist != null)
- // {
- // checkExist = PopData;
- // }
- // else
- // {
- db.StoreChangeHistory.Add(PopData);
- // }
- if (total >= 20)
- {
- total = 0;
- db.SaveChanges();
- }
- }
- else
- {
- db.SaveChanges();
- op = false;
- }
- }
- catch (Exception ex)
- {
- ErrorMsg msg = new ErrorMsg();
- msg.Obj = PopData;
- msg.Time = DateTime.Now;
- msg.ErrorContent = ex.ToString();
- TendisDbconn.Instance.AddList("Pop:StoreChangeHistory:Error", msg);
- result = "有异常,请查看Pop:StoreChangeHistory:Error队列";
- }
- }
- db.Dispose();
- return result;
- }
- }
- }
|