mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-05-18 19:48:23 +00:00
Migration from Amazon MWS to Selling Partner API
This commit is contained in:
@@ -1,158 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Sku
|
||||
{
|
||||
class GetSku : Connection
|
||||
{
|
||||
private Dictionary<string, Model.Sku.Sku> cache;
|
||||
protected GetSku (string sqlConnection) : base(sqlConnection)
|
||||
{
|
||||
Default();
|
||||
}
|
||||
protected List<Model.Sku.Sku> BySkuNumberList(List<string> skuNumberList, bool forceRequery = false)
|
||||
{
|
||||
if (skuNumberList == null || !skuNumberList.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var getList = new List<string>();
|
||||
foreach(string item in skuNumberList)
|
||||
{
|
||||
if (forceRequery || !cache.ContainsKey(item))
|
||||
{
|
||||
getList.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// update the cache
|
||||
CacheUpdate(getList);
|
||||
|
||||
// build the return list
|
||||
var returnList = new List<Model.Sku.Sku>();
|
||||
foreach (string item in skuNumberList)
|
||||
{
|
||||
if (cache.ContainsKey(item))
|
||||
{
|
||||
returnList.Add(cache[item]);
|
||||
}
|
||||
}
|
||||
|
||||
//return the list
|
||||
if (returnList.Any())
|
||||
{
|
||||
return returnList;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
protected void CacheClear()
|
||||
{
|
||||
cache.Clear();
|
||||
}
|
||||
private void CacheUpdate(List<string> skuNumberList)
|
||||
{
|
||||
// build the sql string
|
||||
string sqlString = @"
|
||||
SELECT
|
||||
skuSkuID
|
||||
,skuSkuNumber
|
||||
,skuAmazonFNSKU
|
||||
,skuActive
|
||||
FROM tblSku
|
||||
WHERE 1 = 1";
|
||||
|
||||
// build dictionary of parameters and skunumbers
|
||||
var dicSkuNumberByParameterString = new Dictionary<string, string>();
|
||||
int count = 0;
|
||||
foreach (string item in skuNumberList)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(item))
|
||||
{
|
||||
count = count + 1;
|
||||
string parameterString = "@skuNumber" + count;
|
||||
dicSkuNumberByParameterString.Add(parameterString, item);
|
||||
}
|
||||
}
|
||||
|
||||
if (dicSkuNumberByParameterString.Any())
|
||||
{
|
||||
count = 0;
|
||||
foreach (var item in dicSkuNumberByParameterString)
|
||||
{
|
||||
count = count + 1;
|
||||
if (count == 1)
|
||||
{
|
||||
sqlString = sqlString + @"
|
||||
AND ( skuSkuNumber = " + item.Key;
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlString = sqlString + @"
|
||||
OR skuSkuNumber = " + item.Key;
|
||||
}
|
||||
}
|
||||
sqlString = sqlString + " )";
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sqlString = sqlString + @"
|
||||
ORDER BY skuSkuNumber";
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
|
||||
{
|
||||
if (dicSkuNumberByParameterString.Any())
|
||||
{
|
||||
foreach (var item in dicSkuNumberByParameterString)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (!reader.HasRows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
var sku = new Model.Sku.Sku();
|
||||
|
||||
int tablePk = reader.GetInt32(0);
|
||||
sku.SkuNumber = reader.GetString(1);
|
||||
if (!reader.IsDBNull(2)) { sku.AmazonFNSKU = reader.GetString(2); }
|
||||
sku.IsActive = reader.GetBoolean(3);
|
||||
|
||||
// update cache
|
||||
if (cache.ContainsKey(sku.SkuNumber))
|
||||
{
|
||||
cache.Remove(sku.SkuNumber);
|
||||
}
|
||||
cache.Add(sku.SkuNumber, sku);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void Default()
|
||||
{
|
||||
cache = new Dictionary<string, Model.Sku.Sku>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
{
|
||||
public class CreatePricingDetail : Connection
|
||||
{
|
||||
public CreatePricingDetail(string sqlConnectionString) : base(sqlConnectionString)
|
||||
public CreatePricingDetail()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
{ return; }
|
||||
|
||||
using (var scope = new TransactionScope())
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
using (var conn = new SqlConnection(SqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@ namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
{
|
||||
public class ReadParameter : Connection
|
||||
{
|
||||
public ReadParameter(string sqlConnectionString) : base(sqlConnectionString)
|
||||
public ReadParameter() : base()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<Model.Sku.Price.SkuPriceParameter> Execute()
|
||||
public List<Model.Sku.Price.SkuRepriceInfo> Execute()
|
||||
{
|
||||
string stringSql = @"
|
||||
SELECT
|
||||
@@ -71,17 +71,17 @@ namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
) b
|
||||
INNER JOIN tblSku ON b.SkuID = tblSku.skuSkuID)
|
||||
INNER JOIN tblProduct ON tblSku.skuProductID = tblProduct.prdProductID)
|
||||
LEFT JOIN tblAmazonFeeEstimate ON tblProduct.prdProductID = tblAmazonFeeEstimate.ProductIdentifier )
|
||||
LEFT JOIN tblAmazonFeeEstimate ON tblProduct.prdProductID = tblAmazonFeeEstimate.ProductID )
|
||||
INNER JOIN tblProductCategory ON tblProduct.ProductCategoryID = tblProductCategory.ProductCategoryID)
|
||||
INNER JOIN tblAccountTaxCode ON tblSku.AccountTaxCodeID = tblAccountTaxCode.AccountTaxCodeID
|
||||
INNER JOIN tblSkuCondition ON tblSku.skuSkuConditionID = tblSkuCondition.scnSkuConditionID
|
||||
";
|
||||
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
using (var conn = new SqlConnection())
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
var invPricing = conn.Query<Model.Sku.Price.SkuPriceParameter>(stringSql).ToList();
|
||||
var invPricing = conn.Query<Model.Sku.Price.SkuRepriceInfo>(stringSql).ToList();
|
||||
|
||||
if (invPricing != null || invPricing.Any())
|
||||
{
|
||||
@@ -95,4 +95,3 @@ namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
{
|
||||
public class ReadPricingDetail : Connection
|
||||
{
|
||||
public ReadPricingDetail(string sqlConnectionString) : base(sqlConnectionString)
|
||||
public ReadPricingDetail()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||
|
||||
public List<Model.Sku.Price.PriceInfo> Read(List<string> skuNumberList, string orderChannel)
|
||||
{
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
using (var conn = new SqlConnection(SqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Sku
|
||||
{
|
||||
public class ReadSku : Connection
|
||||
{
|
||||
private SqlWhereBuilder sqlWhere = new SqlWhereBuilder();
|
||||
|
||||
public ReadSku()
|
||||
{
|
||||
}
|
||||
|
||||
public List<Model.Sku.Sku> BySkuNumber(List<string> skuNumberList)
|
||||
{
|
||||
var returnList = new List<Model.Sku.Sku>();
|
||||
|
||||
if (!skuNumberList.Any())
|
||||
{
|
||||
return returnList;
|
||||
}
|
||||
|
||||
// build the sql string
|
||||
string sqlString = @"
|
||||
SELECT
|
||||
skuSkuNumber
|
||||
,skuAmazonFNSKU
|
||||
,skuActive
|
||||
FROM tblSku
|
||||
WHERE ";
|
||||
|
||||
sqlWhere.Innit();
|
||||
sqlWhere.In("skuSkuNumber", skuNumberList);
|
||||
sqlString += sqlWhere.SqlWhereString;
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
|
||||
{
|
||||
sqlWhere.AddParametersToSqlCommand(cmd);
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var sku = new Model.Sku.Sku();
|
||||
|
||||
sku.SkuNumber = reader.GetString(0);
|
||||
if (!reader.IsDBNull(1)) { sku.AmazonFNSKU = reader.GetString(1); }
|
||||
sku.IsActive = reader.GetBoolean(2);
|
||||
|
||||
returnList.Add(sku);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,19 @@ using Dapper;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Sku
|
||||
{
|
||||
public class ReadSkuConditionInfo : Connection
|
||||
{
|
||||
public ReadSkuConditionInfo(string sqlConnectionString): base(sqlConnectionString)
|
||||
{
|
||||
public class ReadSkuConditionInfo : Connection
|
||||
{
|
||||
private Data.Database.SqlWhereBuilder sqlWhere = new SqlWhereBuilder();
|
||||
|
||||
}
|
||||
public ReadSkuConditionInfo()
|
||||
{
|
||||
|
||||
public List<Model.Sku.SkuConditionInfo> Read(List<int> conditionIdList)
|
||||
{
|
||||
string sql = @"
|
||||
SELECT scnSkuConditionID AS SkuConditionId
|
||||
}
|
||||
|
||||
public List<Model.Sku.SkuConditionInfo> ByConditionCode(List<string> conditionCodeList)
|
||||
{
|
||||
string sql = @"
|
||||
SELECT SkuConditionCode
|
||||
,scnTitleShort AS TitleShort
|
||||
,scnSkuNumberSuffix AS SkuConditionNumber
|
||||
,BaseType AS AmazonBaseType
|
||||
@@ -30,22 +32,64 @@ namespace bnhtrade.Core.Data.Database.Sku
|
||||
,scnDescription AS Description
|
||||
FROM tblSkuCondition";
|
||||
|
||||
if (conditionIdList != null || !conditionIdList.Any())
|
||||
if (conditionCodeList != null || !conditionCodeList.Any())
|
||||
{
|
||||
sql += @"
|
||||
WHERE scnSkuConditionID IN @conditionIdList
|
||||
WHERE SkuConditionCode IN @conditionIdList
|
||||
";
|
||||
}
|
||||
|
||||
using (var conn = new SqlConnection(sqlConnectionString))
|
||||
using (var conn = new SqlConnection(SqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
var paramter = new DynamicParameters();
|
||||
paramter.Add("@conditionIdList", conditionIdList);
|
||||
paramter.Add("@conditionIdList", conditionCodeList);
|
||||
|
||||
return conn.Query<Model.Sku.SkuConditionInfo>(sql, paramter).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrives list of condition codes for a given list of sku numbers.
|
||||
/// </summary>
|
||||
/// <param name="skuNumberList">SKU number list</param>
|
||||
/// <returns>Dictionary with sku number as key and condition code as value</returns>
|
||||
public Dictionary<string, string> ReadSkuConditionCode(List<string> skuNumberList)
|
||||
{
|
||||
var returnList = new Dictionary<string, string>();
|
||||
|
||||
if (skuNumberList == null || !skuNumberList.Any())
|
||||
{
|
||||
return returnList;
|
||||
}
|
||||
|
||||
sqlWhere.In("tblSku.skuSkuNumber", skuNumberList);
|
||||
|
||||
string sql = @"
|
||||
SELECT tblSku.skuSkuNumber, tblSkuCondition.SkuConditionCode
|
||||
FROM tblSku INNER JOIN tblSkuCondition ON tblSku.skuSkuConditionID = tblSkuCondition.scnSkuConditionID
|
||||
WHERE " + sqlWhere.SqlWhereString;
|
||||
|
||||
using (var conn = new SqlConnection(SqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (var cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
sqlWhere.AddParametersToSqlCommand(cmd);
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
returnList.Add(reader.GetString(0), reader.GetString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user