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_auto_sales GetByTurnOverId(int id,string sku, string warehousecode)
        {
            var sql = "select * from dc_auto_turnover where 1=1 ";
            if (id > 0)
            {
                sql += " and id= "+id;

            }
            else
            {
                sql += " and bailun_sku='"+ sku+ "' and warehouse_code='"+ warehousecode+"' ";
            }
            var objTurnOver = _connection.QueryFirstOrDefault<Models.dc_auto_turnover>(sql);

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

            return new dc_auto_sales();
        }

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

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

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

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


    }
}
