123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using Library;
- using MySystem.Models;
- using System;
- using System.Linq;
- namespace MySystem
- {
- public class ConsumerOpenIdsHelper
- {
- public readonly static ConsumerOpenIdsHelper Instance = new ConsumerOpenIdsHelper();
- private ConsumerOpenIdsHelper()
- { }
- public string Start()
- {
- bool op = true;
- WebCMSEntities db = new WebCMSEntities();
- string result = "";
- int total = 0;
- while (op)
- {
- ConsumerOpenIds PopData = new ConsumerOpenIds();
- try
- {
- //获取apserver待同步的数据,执行入库
- PopData = RedisDbconn.Instance.RPop<ConsumerOpenIds>("Pop:ConsumerOpenIds");
- if (PopData != null)
- {
- ConsumerOpenIds checkExist = db.ConsumerOpenIds.FirstOrDefault(m => m.OpenId == PopData.OpenId);
- if (checkExist != null)
- {
- checkExist = PopData;
- }
- else
- {
- db.ConsumerOpenIds.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();
- LogHelper.Instance.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(msg), "Pop:ConsumerOpenIds:Error");
- result = "有异常,请查看Pop:ConsumerOpenIds:Error队列";
- }
- }
- db.Dispose();
- return result;
- }
- }
- }
|