using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Core.Standard.Data.Infrastructure;
using XYY.Model.Standard.Finance;
using Dapper;
namespace XYY.Data.Standard.Finance
{
    public interface ILogistics_ExpressFeeBaseRepository : IBaseRepository<Logistics_ExpressFeeBase>
    {
        public Task<List<Logistics_ExpressZone>> QueryZone(int expressId);
        public Task<List<Logistics_ExpressFeeBase>> QueryFeeBase(string CustomerId, string ExpressId);
    }
    public class Logistics_ExpressFeeBaseRepository : BaseRepository<Logistics_ExpressFeeBase>, ILogistics_ExpressFeeBaseRepository
    {


        public Logistics_ExpressFeeBaseRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }

        public async Task<List<Logistics_ExpressZone>> QueryZone(int expressId)
        {
            if (expressId == 48)
            {
                string sql = @"select 二字代码 as CountryCode,分区 as Zone from logistics_fedexzone(nolock)";
                return (await _unitOfWork.QueryBySqlAsync<Logistics_ExpressZone>(sql)).ToList();
            }
            else if (expressId == 50)
            {
                string sql = @"select Code as CountryCode,分区 as Zone from Logistics_ExpressDHLZone(nolock)";
                return (await _unitOfWork.QueryBySqlAsync<Logistics_ExpressZone>(sql)).ToList();
            }
            else
            {
                return null;
            }
        }
        public async Task<List<Logistics_ExpressFeeBase>> QueryFeeBase(string CustomerId, string ExpressId)
        {
            string sql = $"select *from Logistics_ExpressFeeBase(nolock) where  ExpressId={ExpressId} and CustomerId={CustomerId} order by EnableTime desc ";
            return (await _unitOfWork.QueryBySqlAsync<Logistics_ExpressFeeBase>(sql)).ToList();
        }
    }


}
