1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using MySystem.Models;
- using System;
- using System.Linq;
- namespace MySystem
- {
- public class MerchantParamSetHelper
- {
- public readonly static MerchantParamSetHelper Instance = new MerchantParamSetHelper();
- private MerchantParamSetHelper()
- { }
- public string Start()
- {
- bool op = true;
- WebCMSEntities db = new WebCMSEntities();
- string result = "";
- int total = 0;
- while (op)
- {
- MerchantParamSet PopData = new MerchantParamSet();
- try
- {
- //获取apserver待同步的数据,执行入库
- PopData = TendisDbconn.Instance.RPop<MerchantParamSet>("Pop:MerchantParamSet");
- if (PopData != null)
- {
- MerchantParamSet checkExist = db.MerchantParamSet.FirstOrDefault(m => m.Id == PopData.Id);
- if (checkExist != null)
- {
- checkExist = PopData;
- }
- else
- {
- db.MerchantParamSet.Add(PopData);
- }
- total += 1;
- if (total >= 20)
- {
- total = 0;
- db.SaveChanges();
- }
- if (string.IsNullOrEmpty(result)) result = "success";
- }
- else
- {
- if (total > 0)
- {
- 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:MerchantParamSet:Error", msg);
- result = "有异常,请查看Pop:MerchantParamSet:Error队列";
- }
- }
- db.Dispose();
- return result;
- }
- }
- }
|