using System;
using System.Collections.Generic;
using System.Text;
using AutoTurnOver.Models;
using Dapper;

namespace AutoTurnOver.DB
{
    public class SaleVolume:connectionHelper
    {
        /// <summary>
        /// 获取sku销量信息
        /// </summary>
        /// <param name="id">自动周转id</param>
        /// <returns></returns>
        public static dc_sales_volume GetByTurnOverId(int id)
        {
            var sql = "select * from dc_auto_turnover where id="+id;
            var objTurnOver = _connection.QueryFirstOrDefault<Models.dc_auto_turnover>(sql);

            if (objTurnOver != null)
            {
                var sql1 = "select * from dc_sales_volume where bailun_sku='" + objTurnOver.bailun_sku + "' and warehouse_code='"+objTurnOver.warehouse_code+"'";
                return _connection.QueryFirstOrDefault<dc_sales_volume>(sql1);
            }

            return new dc_sales_volume();
        }

        /// <summary>
        /// 获取sku销量详情
        /// </summary>
        /// <param name="id">主键id</param>
        /// <returns></returns>
        public static dc_sales_volume GetById(int id)
        {
            var sql = "select * from dc_sales_volume where id="+id;

            return _connection.QueryFirstOrDefault<dc_sales_volume>(sql);
        }

        /// <summary>
        /// 根据SKU和仓库获取预测销量信息
        /// </summary>
        /// <param name="sku">sku编码</param>
        /// <param name="warehousecode">仓库编码</param>
        /// <returns></returns>
        public static dc_sales_volume GetBySkuWarehouseCode(string sku, string warehousecode)
        {
            var sql = "select * from dc_sales_volume where bailun_sku='"+sku+ "' and warehouse_code='"+warehousecode+"'";

            return _connection.QueryFirstOrDefault<dc_sales_volume>(sql);
        }


    }
}
