using System;
using System.Collections.Generic;
using System.Threading;
using System.Linq;
using System.Data;
using MySystem;
using MySystem.SpModels;
using Library;

public class TmpHelper
{
    public readonly static TmpHelper Instance = new TmpHelper();
    private TmpHelper()
    {
    }

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

    private void DoWorks()
    {
        try
        {
            DoSomething();
        }
        catch (Exception ex)
        {
            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "tmp重推交易数据异常");
        }
    }

    public void DoSomething()
    {
        Dictionary<string, string> dic = new Dictionary<string, string>();
        string[] data = function.ReadInstance("/tmpdata/mer.txt").Split('\n');
        foreach(string sub in data)
        {
            string[] item = sub.Split('|');
            dic.Add(item[0], item[1]);
        }
        List<TradeRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TradeRecord>>(function.ReadInstance("/tmpdata/trade.json"));
        foreach (TradeRecord trade in list)
        {
            if (dic.ContainsKey(trade.MerNo))
            {
                trade.MerNo = dic[trade.MerNo];
                trade.TradeSerialNo = trade.TradeSerialNo + "a";
                PosPushDataNewHelper.Trade(trade);
                Thread.Sleep(500);
            }
        }
    }
}