using System;
using System.Threading.Tasks;
using XYY.TaskTrack.Standard;
using XYY.TaskTrack.Standard.TaskModel;

namespace XYY.WindowsService.MQ
{
    public interface IFinanceQuotationJobSub : IBaseConsumer<FinanceQuotation>
    {

    }

    public class FinanceQuotationJobSub : IFinanceQuotationJobSub
    {

        public FinanceQuotationJobSub()
        {
            //我们直接使用api推送内容，减少服务依赖
        }

        public async Task Consume(FinanceQuotation message)
        {
            try
            {
                RestSharp.RestClient client = new RestSharp.RestClient("http://120.24.149.148:9521/api/FinanceQuotation/SendNowCustomerQuotaion");
                RestSharp.RestRequest request = new RestSharp.RestRequest(RestSharp.Method.POST);
                request.AddJsonBody(message);
                var response = client.Execute(request);
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    Console.WriteLine(message.CustomerName + " " + message.EntryTime + "消息推送成功");
                }
                else
                {
                    Console.WriteLine(message.CustomerName + " " + message.EntryTime
                        + "消息推送错误" + (response.Content ?? response.ErrorMessage));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(message.CustomerName + " " + message.EntryTime + "消息推送错误:" + ex.Message);
            }
        }
    }
}