using System;
using System.Collections.Generic;
using Library;
using LitJson;
using System.Linq;
using System.Data;
using System.Threading;
using MySystem.PxcModels;

namespace MySystem
{
    public class TmpService
    {
        public readonly static TmpService Instance = new TmpService();
        private TmpService()
        { }

        public void Start()
        {
            Thread th = new Thread(SetLkbDeposit);
            th.IsBackground = true;
            th.Start();
        }

        private void SetLkbDeposit()
        {
            while (true)
            {
                try
                {
                    string content = RedisDbconn.Instance.RPop<string>("SetLkbDepositQueue");
                    if (!string.IsNullOrEmpty(content))
                    {
                        string[] data = content.Split('|');
                        PublicImportDataService.Instance.LkbSetDeposit(data[0], decimal.Parse(data[1]));
                    }
                    else
                    {
                        Thread.Sleep(2000);
                    }
                }
                catch (Exception ex)
                {
                    function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "商城订单余额支付异常");
                    Thread.Sleep(2000);
                }
            }
        }







        public void dosomething()
        {
            string content = function.ReadInstance("jk299.txt");
            string[] SnNos = content.Split('\n');
            int count = SnNos.Length;
            int index = 0;
            foreach(string SnNo in SnNos)
            {
                index += 1;
                PublicImportDataService.Instance.LkbSetDeposit(SnNo, 299);
                function.WritePage("/look/", "progress.txt", index + "/" + count);
                function.WritePage("/look/", "sn.txt", SnNo);
                Thread.Sleep(100);
            }

            content = function.ReadInstance("jk0.txt");
            SnNos = content.Split('\n');
            count = SnNos.Length;
            index = 0;
            foreach(string SnNo in SnNos)
            {
                index += 1;
                PublicImportDataService.Instance.LkbSetDeposit(SnNo, 0);
                function.WritePage("/look/", "progress.txt", index + "/" + count);
                function.WritePage("/look/", "sn.txt", SnNo);
                Thread.Sleep(100);
            }
        }
    }
}