Commit ad017cbe by 泽锋 李

新增库存监控的计算任务

parent be4c27f2
...@@ -1303,6 +1303,69 @@ truncate table dc_base_purchase_7_temp;", new { time = DateTime.Now.AddDays(-8). ...@@ -1303,6 +1303,69 @@ truncate table dc_base_purchase_7_temp;", new { time = DateTime.Now.AddDays(-8).
} }
/// <summary>
/// 刷新库存监控数据
/// </summary>
public static void ResetStockMonitorData()
{
try
{
_connection.Execute(@" -- 刷新 订单dc_auto_stock_monitor映射表
set session transaction isolation level read uncommitted;
start transaction;
-- 清空视图表的数据
Truncate table dc_auto_stock_monitor_temp;
INSERT into dc_auto_stock_monitor_temp(`bailun_sku`,`china_quantity_out_stock`,`not_china_quantity_out_stock`,
`guangzhou01_usable_stock`,`guangzhou01_transfer_stock`,`haiwai_uk_usable_stock`,`haiwai_uk_transfer`,
`haiwai_us_usable_stock`,`haiwai_us_transfer`,`fba_usable_stock`,`haiwai_usable_stock`,`guangzhou01_history_sevenday_sales`,
`haiwai_uk_history_sevenday_sales`,`haiwai_us_history_sevenday_sales`,`haiwai_fba_history_sevenday_sales`) (
select
t1.bailun_sku,
sum(case when t2.hq_type='国内仓' then t1.quantity_out_stock else 0 end ) as 'china_quantity_out_stock', -- 国内仓总缺货
sum(case when t2.hq_type not in ('国内仓','耗材仓') then t1.quantity_out_stock else 0 end ) as 'not_china_quantity_out_stock', -- 国外仓总缺货
sum(case when t1.warehouse_code='GZBLWH' then t3.usable_stock else 0 end) as 'guangzhou01_usable_stock', -- 广州01 可用库存
sum(case when t1.warehouse_code='GZBLWH' then t1.quantity_purchase + t1.quantity_transfer else 0 end) as 'guangzhou01_transfer_stock', -- 广州01 在途
sum(case when t2.hq_type='第三方仓库' and t2.area_id=6 then t3.usable_stock else 0 end) as 'haiwai_uk_usable_stock', -- 海外仓uk仓 可配库存
sum(case when t2.hq_type='第三方仓库' and t2.area_id=6 then t1.quantity_purchase + t1.quantity_transfer else 0 end) as 'haiwai_uk_transfer', -- 海外仓uk仓 在途库存
sum(case when t2.hq_type='第三方仓库' and t2.area_id=7 then t3.usable_stock else 0 end) as 'haiwai_us_usable_stock', -- 海外仓us仓 可配库存
sum(case when t2.hq_type='第三方仓库' and t2.area_id=7 then t1.quantity_purchase + t1.quantity_transfer else 0 end) as 'haiwai_us_transfer', -- 海外仓us仓 在途库存
sum(case when t2.hq_type='FBA仓' then t3.usable_stock else 0 end) as 'fba_usable_stock', -- fba 可用库存
sum(case when t2.hq_type in ('第三方仓库','FBA仓') then t3.usable_stock else 0 end) as 'haiwai_usable_stock', -- 海外仓可用库存
sum(case when t1.warehouse_code='GZBLWH' then t5.history_sevenday_sales else 0 end) as 'guangzhou01_history_sevenday_sales', -- 广州01 日均
sum(case when t2.hq_type='第三方仓库' and t2.area_id=6 then t5.history_sevenday_sales else 0 end) as 'haiwai_uk_history_sevenday_sales', -- 海外仓uk仓 日均
sum(case when t2.hq_type='第三方仓库' and t2.area_id=7 then t5.history_sevenday_sales else 0 end) as 'haiwai_us_history_sevenday_sales', -- 海外仓us仓 日均
sum(case when t2.hq_type='FBA仓' then t5.history_sevenday_sales else 0 end) as 'haiwai_fba_history_sevenday_sales' -- fba 仓 日均
from dc_mid_transit as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
left join dc_base_stock as t3 on t1.bailun_sku = t3.bailun_sku and t1.warehouse_code = t3.warehouse_code
left join dc_base_sku as t4 on t1.bailun_sku = t4.bailun_sku
left join dc_auto_turnover as t5 on t1.bailun_sku = t5.bailun_sku and t1.warehouse_code = t5.warehouse_code
GROUP BY t1.bailun_sku
);
alter table dc_auto_stock_monitor rename dc_auto_stock_monitorTemp;
alter table dc_auto_stock_monitor_temp rename dc_auto_stock_monitor;
alter table dc_auto_stock_monitorTemp rename dc_auto_stock_monitor_temp;
truncate table dc_auto_stock_monitor_temp; ", commandTimeout: 0);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
_connection.Insert<dc_task_error_log>(new dc_task_error_log
{
date = DateTime.Now,
message = ex.Message,
stack_trace = ex.StackTrace,
task_name = "ResetStockMonitorData"
});
}
}
public static void AddError(dc_task_error_log data) public static void AddError(dc_task_error_log data)
{ {
_connection.Insert(data); _connection.Insert(data);
......
...@@ -32,6 +32,28 @@ namespace ResetOutofstock ...@@ -32,6 +32,28 @@ namespace ResetOutofstock
Thread.Sleep(60 * 60 * 1000); Thread.Sleep(60 * 60 * 1000);
} }
}); });
Task.Factory.StartNew(() => {
while (true)
{
try
{
if (DateTime.Now.Hour >= 8)
{
Console.WriteLine($"开始刷新库存监控数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
report.ResetStockMonitorData();
Console.WriteLine($"结束刷新库存监控数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Thread.Sleep(5 * 60 * 1000);
}
});
return Task.CompletedTask; return Task.CompletedTask;
} }
......
...@@ -12,7 +12,7 @@ namespace ShortagePush ...@@ -12,7 +12,7 @@ namespace ShortagePush
static async Task Main(string[] args) static async Task Main(string[] args)
{ {
Console.WriteLine("推送缺货数据服务"); Console.WriteLine("推送缺货数据服务");
//var datas = report.ShortagePush(true); //var datas = report.ShortagePush();
var builder = new HostBuilder().ConfigureServices((hostContext, services) => var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{ {
services.AddHostedService<ShortagePushBackgroundService>(); services.AddHostedService<ShortagePushBackgroundService>();
......
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