using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Common.Standard;
using XYY.Core.Standard.Data.Infrastructure;
using XYY.Model.Standard.Finance;
using Dapper;
using Nest;

namespace XYY.Data.Standard.Finance
{
    public interface IFinance_ServiceSurchargeRepository : IBaseRepository<Finance_ServiceSurcharge>
    {
        Task<List<Finance_ServiceSurchargeLog>> GetLogs(int Id);
        Task<List<ZoneInfo>> GetZoneInfos(int ExpressId);
    }
    public class Finance_ServiceSurchargeRepository : BaseRepository<Finance_ServiceSurcharge>, IFinance_ServiceSurchargeRepository
    {
        public Finance_ServiceSurchargeRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {

        }

        public async Task<List<Finance_ServiceSurchargeLog>> GetLogs(int Id)
        {
            return (await _unitOfWork.QueryAsync<Finance_ServiceSurchargeLog>(x => x.Id == Id)).ToList();
        }
        public async Task<List<ZoneInfo>> GetZoneInfos(int ExpressId)
        {
            string sql = string.Empty;
            List<int> ExpressIds = new List<int>() { 48, 50 };//48：fedex;50:dhl
            if (ExpressIds.Contains(ExpressId))
            {
                if (ExpressId == 48)
                {
                    sql = "select 二字代码 [code],分区 [zone] from Logistics_FedexZone ";
                }
                else if (ExpressId == 50)
                {
                    sql = "select code [code],REPLACE(分区,'区','') [zone] from Logistics_ExpressDHLZone ";
                }
                 return (await _unitOfWork.QueryBySqlAsync<ZoneInfo>(sql)).ToList();
            }
            else
            {
                throw new Exception("快递当前仅允许批量调整Fedex/DHL附加费");
            }
        }
    }
    public class ZoneInfo
    {
        public string zone { get; set; }
        public string code { get; set; }
    }
}
