Commit 385e293a by 泽锋 李

体现计算过程

parent 1fffa802
......@@ -84,11 +84,14 @@ namespace AutoTurnOver.DB
foreach (var itemGroup in sku_list.GroupBy(s => new { s.product_inner_code, s.warehouse_code }))
{
int purchase_advise_id = conn.Insert<dc_auto_purchase_advise>(new dc_auto_purchase_advise { buy_sys_plan_no = "自动下首单", create_time = DateTime.Now, no = purchase_advise.MaxNo(), sendtype = itemGroup.Max(v => v.sendtype) }, t) ?? 0;
//记录推送过程
StringBuilder remarks = new StringBuilder();
try
{
var item_warehouse = warehouse_list.FirstOrDefault(s => itemGroup.Key.warehouse_code.Equals(s.warehouse_code, StringComparison.CurrentCultureIgnoreCase));
if (item_warehouse == null)
{
remarks.AppendLine($"仓库编码不存在");
throw new Exception("仓库编码不存在");
}
// 匹配规则
......@@ -99,24 +102,31 @@ namespace AutoTurnOver.DB
);
if (item_rule == null)
{
remarks.AppendLine($"未命中规则");
throw new Exception("未命中规则");
}
remarks.AppendLine($"命中规则 {item_rule.title}");
List<auto_first_order_detailed_dto> data_detailed_list = new List<auto_first_order_detailed_dto>();
if (item_rule.lower_limit_sku_count > 0 && itemGroup.Count() > item_rule.lower_limit_sku_count)
{
remarks.AppendLine($" sku数量不应该超过 {item_rule.lower_limit_sku_count} 个 ");
throw new Exception($" sku数量不应该超过 {item_rule.lower_limit_sku_count} 个 ");
}
if (item_rule.lower_limit_sales > 0 && itemGroup.Max(v => v.product_sales) < item_rule.lower_limit_sales)
{
remarks.AppendLine($" 商品日均不应该低于 {item_rule.lower_limit_sales} 个 ");
throw new Exception($" 商品日均不应该低于 {item_rule.lower_limit_sales} 个 ");
}
// 固定数量
if (item_rule.order_type == 1)
{
remarks.AppendLine($"采用固定数量 {item_rule.quantity} 下单");
var single_sku_count = item_rule.quantity;
foreach (var item in itemGroup.AsEnumerable())
......@@ -131,16 +141,20 @@ namespace AutoTurnOver.DB
// 自动凑moq
if (item_rule.has_collect)
{
remarks.AppendLine($"自动凑moq");
//查询商品moq
var moq = conn.QuerySingleOrDefault<int?>(" select max(moq) from dc_base_sku where product_inner_code=@product_inner_code ", new { product_inner_code = itemGroup.Key.product_inner_code });
if (moq == null)
{
remarks.AppendLine($"未查询到商品moq");
throw new Exception("未查询到商品moq");
}
// 计算差额,补齐 moq
var count_difference = moq - data_detailed_list.Sum(s => s.quantity);
remarks.AppendLine($"补齐moq 差额 {count_difference}");
if (count_difference > 0)
{
var count_difference_index = 0;
......@@ -162,10 +176,13 @@ namespace AutoTurnOver.DB
}
else // 下一个供应链长度
{
remarks.AppendLine($"根据供应链长度下单模式");
// 查询交期
var max_delivery = conn.QuerySingleOrDefault<int?>(" select max(supplier_delivery + `transfer_delivery`) from dc_base_sku where product_inner_code=@product_inner_code ", new { product_inner_code = itemGroup.Key.product_inner_code });
if (max_delivery == null)
{
remarks.AppendLine($"未查询到交期");
throw new Exception("未查询到交期");
}
......@@ -173,9 +190,12 @@ namespace AutoTurnOver.DB
var sum_quantity = max_delivery * (itemGroup.Max(s => s.product_sales) * item_rule.sales_ratio);
if (sum_quantity <= 0)
{
remarks.AppendLine($"经过计算,无需下单");
throw new Exception("经过计算,无需下单");
}
remarks.AppendLine($"经过计算,预计下单数 {sum_quantity}");
foreach (var item in itemGroup.AsEnumerable())
{
data_detailed_list.Add(new auto_first_order_detailed_dto
......@@ -206,6 +226,7 @@ namespace AutoTurnOver.DB
if (data_detailed_list == null || data_detailed_list.Count <= 0)
{
remarks.AppendLine($"计算完发现没有需求");
throw new Exception("计算完发现没有需求");
}
......@@ -264,8 +285,9 @@ namespace AutoTurnOver.DB
type = 4,
product_inner_code = itemGroup.Key.product_inner_code,
good_sku_codes = "",
purchase_type_jit = 3
}, t);
purchase_type_jit = 3,
remarks = remarks.ToString()
}, t); ;
}
}
......
......@@ -36,6 +36,7 @@ namespace AutoTurnOver.Models
/// 日均销量比例
/// </summary>
public decimal sales_ratio { get; set; }
public string title { get; set; }
}
......
......@@ -175,6 +175,7 @@ namespace AutoTurnOver.Models
/// 其他平台的需求
/// </summary>
public decimal? quantity_out_stock_other { get; set; }
public string remarks { get; set; }
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment