Commit f53b3492 by 泽锋 李

手工销量导入算法修改

parent abaf7e62
...@@ -26,7 +26,7 @@ namespace AutoGeneratePurchaseAdvise ...@@ -26,7 +26,7 @@ namespace AutoGeneratePurchaseAdvise
//PurchaseAdviseServices.Generate(DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"))); //PurchaseAdviseServices.Generate(DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")));
//PurchaseAdviseServices.Generate(DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 12:00:00"))); //PurchaseAdviseServices.Generate(DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 12:00:00")));
//PurchaseAdviseServices.Generate(DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 09:00:00"))); //PurchaseAdviseServices.GenerateTemp(DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 15:05:00")));
} }
catch (Exception ex) catch (Exception ex)
{ {
......
...@@ -490,6 +490,164 @@ and t1.quantity_init_advise>=0 and ( t3.buyer_name in ('张莹霞1') and t1.ware ...@@ -490,6 +490,164 @@ and t1.quantity_init_advise>=0 and ( t3.buyer_name in ('张莹霞1') and t1.ware
} }
public static void ImportDetailedTemp(int mainID, DateTime date)
{
//RedundancyDeduction("QYBLZZ", "GZBLWH");
//RedundancyDeduction("GZBLWH", "QYBLZZ");
// 生成采购建议 (只补缺货的不管)
var datas1 = _connection.Query<dc_auto_purchase_advise_detailed>(@"select * from (
select
t1.bailun_sku,
t1.warehouse_code as 'source_warehouse_code',
(case when t8.group_id=2 then 'GZBLWH' else t1.warehouse_code end ) as 'warehouse_code',
t1.quantity_init_advise as 'quantity_init_advise', -- 原始采购建议数量 new
(
case
when t6.buyer_name in ('张莹霞') then ( case when t1.quantity_init_advise>0 then greatest(t1.quantity_init_advise,t6.moq) else 0 end) -- (张莹霞的sku取moq下单)
when t7.sum_quantity_init_advise>=t7.max_moq then t1.quantity_init_advise-- 如果商品的下单总量达到moq了,就直接下单
when t7.sku_count=1 then t7.max_moq -- 如果该商品只有一个sku需要下单,则直接下一个moq
else
FLOOR(
GREATEST(t1.quantity_init_advise,0) +
(
(ifnull(t7.max_moq,0)-GREATEST(ifnull(t7.sum_quantity_init_advise,0),0))
*
((case when t1.history_fourteenday_sales>0 then t1.history_fourteenday_sales else 1 end ) / (case when ifnull(t7.sum_history_fourteenday_sales,0) >0 then t7.sum_history_fourteenday_sales else 1 end) )
)
)-- 如果以上条件都不满足,则计算该sku需要摊分多少moq余下的任务
end
) as 'quantity_final_advise', -- 计算moq之后的数量 new
ifnull(t7.product_inner_code,'') as 'product_inner_code', -- 内部商品编码 new
t7.sum_quantity_init_advise as 'goods_quantity_init_advise', -- 商品本次的建议下单数量 new
t7.max_moq as 'goods_moq', -- 商品的moq new
ifnull(t7.sku_codes,'') as 'good_sku_codes', -- 商品涉及的下单所有sku new
t7.sum_history_fourteenday_sales as 'goods_history_fourteenday_sales', -- 商品的最近14日总日均销量
t1.history_fourteenday_sales as 'history_fourteenday_sales', -- sku的最近14日日均
0 as 'quantity_actual', -- 真实下单数量
@main_id as 'main_id',
t2.forecast_formula as 'forecast_formula',
t2.fit_forecast_formula as 'fit_forecast_formula',
t1.turnover_days,
t1.supplier_delivery,
t1.inspection_delivery,
t1.transfer_delivery,
t1.sales_upper_limit,
0 as 'ispush',
(case when t1.quantity_out_stock>0 then 2 when t1.`status` then 1 else 3 end) as 'type',
t6.suppliers_id,
t1.quantity_out_stock,
(
case when t6.buyer_name in ('张莹霞','张莹霞1') and t1.warehouse_code='GZBLWH' then 1
else 0
end
) as 'purchase_type_jit',
t1.auto_replace_logistics_task_id,
tr_task.logistics_code,
tr_task.logistics_name,
tr_task.transport_type as 'task_transport_type',
tr_task.remarks as 'replace_logistics_remarks'
from dc_auto_turnover as t1
left join dc_auto_sales as t2 on t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
left join dc_auto_config_sku_warehouse as t5 on t1.bailun_sku = t5.bailun_sku and t1.warehouse_code = t5.warehouse_code
left join dc_base_sku as t6 on t1.bailun_sku = t6.bailun_sku
left join view_goods_moq as t7 on t6.product_inner_code = t7.product_inner_code and t1.warehouse_code = t7.warehouse_code and t6.suppliers_id = t7.suppliers_id
left join dc_auto_jit_tag as t8 on t1.tag_id = t8.id
left join dc_auto_replace_logistics_task as tr_task on t1.auto_replace_logistics_task_id = tr_task.id
where t1.gmt_modified>=@btime
and t6.`status`=2
-- and (t1.history_fourteenday_sales>0 or t1.quantity_out_stock>0 )
and ( t5.`status`=0 or t5.`status` is null )
-- and t7.sum_quantity_init_advise>0
and (
( ( t6.buyer_name not in ('赵美聪','甄杰靖','张莹霞','张莹霞1','冯兆欣') or t1.warehouse_code not in ('GZBLWH','GZBLYS') ) and t1.warehouse_code!='BLGZ03' )
or
( t1.tag_id > 0 and t8.is_eliminate = 0 )
) -- 非jit 或者 jit 备货
) as t1 where t1.quantity_final_advise>0
", new { main_id = mainID, btime = date }, commandTimeout: 0).ToList();
foreach (var item in datas1)
{
_connection.Insert(item);
}
// 凑单sku(初始建议数没有) 如果下单数只有一个,改为2 ( 只补缺货的不管 )
_connection.Execute(@" update dc_auto_purchase_advise_detailed as t1,
dc_base_sku as t2
set t1.quantity_final_advise=2
where t2.`status`=2 and t1.bailun_sku = t2.bailun_sku and t1.quantity_final_advise=1 and t1.quantity_init_advise<=0 and ( t2.buyer_name not in ('赵美聪','甄杰靖','张莹霞','张莹霞1') or t1.warehouse_code!='GZBLWH' ) and t1.main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0);
// 初始建议数为1,,系统建议数为1时 改为3 ( 只补缺货的不管 )
_connection.Execute(@" update dc_auto_purchase_advise_detailed as t1,
dc_base_sku as t2
set quantity_final_advise=3
where t2.`status`=2 and t1.bailun_sku = t2.bailun_sku and quantity_final_advise=1 and quantity_init_advise=1 and ( t2.buyer_name not in ('赵美聪','甄杰靖','张莹霞','张莹霞1') or t1.warehouse_code!='GZBLWH' ) and main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0);
//张莹霞1 and 广州01 去掉缺货数
_connection.Execute(@" update dc_auto_purchase_advise_detailed as t1,
dc_mid_transit as t2 ,
dc_base_sku as t3
set t1.quantity_final_advise=GREATEST(0,t1.quantity_final_advise-t2.quantity_out_stock)
where t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code and t1.bailun_sku=t3.bailun_sku
and t1.quantity_init_advise>=0 and ( t3.buyer_name in ('张莹霞1') and t1.warehouse_code='GZBLWH' ) and t1.main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0);
// 调整因为舍弃小数导致的moq不足
var datas = _connection.Query<dc_auto_purchase_advise_detailed>(" select * from dc_auto_purchase_advise_detailed where main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0).AsList();
if (datas != null && datas.Count > 0)
{
foreach (var itemGoods in datas.GroupBy(s => new { s.suppliers_id, s.product_inner_code, s.warehouse_code }))
{
// 判断总建议采购数是否达到了moq
var difference = itemGoods.Max(s => s.goods_moq) - itemGoods.Sum(s => s.quantity_final_advise);
if (difference > 0)
{
// 把最大的那条记录找出来,加给他
var max_data = itemGoods.OrderByDescending(s => s.history_fourteenday_sales).FirstOrDefault();
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new
{
quantity_final_advise = max_data.quantity_final_advise + difference,
id = max_data.id
});
}
else if (difference < 0)
{
// 由于上面的补单规则,会导致超出moq . 有超出的部分,把补单的(初始建议数为负数)按销量排序,逐个消减
var abatement = 0 - difference;
foreach (var item in itemGoods.Where(s => s.quantity_init_advise < 0).OrderBy(s => s.goods_history_fourteenday_sales))
{
if (abatement >= item.quantity_final_advise)
{
_connection.Execute(" delete from dc_auto_purchase_advise_detailed where id=@id ", new { id = item.id });
abatement -= item.quantity_final_advise;
}
else
{
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new { id = item.id, quantity_final_advise = item.quantity_final_advise - abatement });
abatement = 0;
}
if (abatement <= 0)
{
break;
}
}
}
}
}
//ImportShoujiShortageDetailed(mainID);
}
/// <summary> /// <summary>
/// 把流水号装换成4位数字符串形式 /// 把流水号装换成4位数字符串形式
/// </summary> /// </summary>
......
...@@ -771,7 +771,7 @@ namespace AutoTurnOver.Services ...@@ -771,7 +771,7 @@ namespace AutoTurnOver.Services
// 取开始结束时间 // 取开始结束时间
var btime = DateTime.Parse(col.ColumnName.Substring(2,10)); var btime = DateTime.Parse(col.ColumnName.Substring(2,10));
var etime = DateTime.Parse(col.ColumnName.Substring(13,10)); var etime = DateTime.Parse(col.ColumnName.Substring(13,10));
var s_sales = (sales / ((int)Math.Ceiling((etime - btime).TotalDays))); var s_sales =( (sales / ((int)Math.Ceiling((etime - btime).TotalDays)) ) + 1);
while (btime.ToDayHome()<= etime.ToDayEnd()) while (btime.ToDayHome()<= etime.ToDayEnd())
{ {
var new_data = new sales_day_config_input_dto var new_data = new sales_day_config_input_dto
......
...@@ -39,7 +39,30 @@ namespace AutoTurnOver.Services ...@@ -39,7 +39,30 @@ namespace AutoTurnOver.Services
} }
public static void GenerateTemp(DateTime date)
{
try
{
// 检查是否有可以切换渠道的sku
//purchase_advise.ReplaceLogistics(date);
//等待后台重算任务
//purchase_advise.WaitReplaceLogisticsTask();
// 创建一个采购计划
var mainID = purchase_advise.Add(new dc_auto_purchase_advise { create_time = DateTime.Now, no = purchase_advise.GenerateOrderNo(), buy_sys_plan_no = "Generate" });
if (mainID == null) throw new Exception("创建采购建议失败");
purchase_advise.ImportDetailedTemp(mainID.Value, date);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
......
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