using System;
using System.Threading;
using Library;
using MySystem;
using MySystem.OpModels;

public class OperateAmountRecordService
{
    public readonly static OperateAmountRecordService Instance = new OperateAmountRecordService();
    private OperateAmountRecordService()
    {
    }
    
    public void Start()
    {
        Thread th = new Thread(DoWorks);
        th.IsBackground = true;
        th.Start();
    }

    private void DoWorks()
    {
        while (true)
        {
            try
            {
                string content = RedisDbconn.Instance.RPop<string>("OperateAmountRecordServiceQueue");
                if (!string.IsNullOrEmpty(content))
                {
                    WebCMSEntities db = new WebCMSEntities();
                    function.WriteLog(content, "运营中心额度变更测试");
                    Utils.Instance.OperateAmountChange(db,Newtonsoft.Json.JsonConvert.DeserializeObject<OpAmountItem>(content));
                    db.Dispose(); 
                }
                else
                {
                    Thread.Sleep(5000);
                }
            }
            catch(Exception ex)
            {
                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "运营中心额度变更队列异常");
                Thread.Sleep(30000);
            }
        }
    }
}