Commit d20cc292 by 泽锋 李

新增库存销量报表的备份服务

parent 6f2e798b
......@@ -1699,7 +1699,7 @@ Truncate table dc_base_oms_sku_outofstock_temp;
}
catch (Exception ex)
{
Console.WriteLine("加载缺货订单异常"+ex.Message);
Console.WriteLine("加载缺货订单异常" + ex.Message);
}
}
......@@ -3578,13 +3578,16 @@ where t1.bailun_sku = t2.bailun_sku and t1.bailun_sku = t3.bailun_sku and t1.wee
if (tag == "出单sku数量占比")
{
datas = datas.Where(s => s.is_order == 1).ToList();
} else if (tag == "不出单数量sku占比")
}
else if (tag == "不出单数量sku占比")
{
datas = datas.Where(s => s.is_order == 0).ToList();
}else if (tag == "出单sku库存数量占比")
}
else if (tag == "出单sku库存数量占比")
{
datas = datas.Where(s => s.is_order == 1).ToList();
}else if (tag == "不出单sku库存数量占比")
}
else if (tag == "不出单sku库存数量占比")
{
datas = datas.Where(s => s.is_order == 0).ToList();
}
......@@ -3769,7 +3772,7 @@ GROUP BY t_ps.sku,t_p.targetwareno
set t1.first_trans_date = t2.min_time
where t1.bailun_sku =t2.bailun_sku and t1.warehouse_code =t2.warehouse_code;
", new { btime = btime3 },commandTimeout: 0);
", new { btime = btime3 }, commandTimeout: 0);
var btime = DateTime.Now.AddDays(-7).GetWeekFirstDayMon().ToDayHome();
var etime = btime.GetWeekLastDaySun().ToDayEnd();
......@@ -3807,7 +3810,7 @@ left join dc_base_stock_first_date as t4 on t1.bailun_sku =t4.bailun_sku and t1.
where ( t2.hq_type='第三方仓库' ) and t3.buyer_name not in('张莹霞','张莹霞1','黄镜洁','古艳洋1','赵美聪','赵美聪1','赵美聪_独立站','李华娟','甄杰靖','秦振荣')
and t_p.`isdeleted`=0 and t_p.creationtime>=@btime and t_p.creationtime<=@etime
GROUP BY t_ps.sku ,t_p.targetwareno", new { btime, etime, week_tag, eonthFirstDate }, commandTimeout: 0).ToList();
if(temp1!=null && temp1.Count >= 1)
if (temp1 != null && temp1.Count >= 1)
{
dc_report_purchase_week_datas.AddRange(temp1);
}
......@@ -3872,7 +3875,7 @@ GROUP BY t_p.bailun_sku ,t_p.warehouse_into_code", new { btime, etime, week_tag,
dc_report_purchase_week_datas.AddRange(temp3);
}
if(dc_report_purchase_week_datas!=null && dc_report_purchase_week_datas.Count >= 1)
if (dc_report_purchase_week_datas != null && dc_report_purchase_week_datas.Count >= 1)
{
foreach (var item in dc_report_purchase_week_datas)
{
......@@ -4035,7 +4038,8 @@ left join dc_base_country as t3 on t2.area_name = t3.`name`
where t2.hq_type='fba仓'").ToList();
foreach (var item in datas)
{
var data = new dc_auto_fastest_storage() {
var data = new dc_auto_fastest_storage()
{
bailun_sku = item.bailun_sku,
warehouse_code = item.warehouse_code,
purchase_days = (item.supplier_delivery + item.payment_before_delivery + item.inspection_delivery),
......@@ -4043,15 +4047,16 @@ where t2.hq_type='fba仓'").ToList();
country_code = item.country_code,
trans_days = 15
};
var lms_avgs = ApiUtility.GetLmsOrderTransferAvg(new Models.ApiDto.api_lms_order_transfer_sku_requst_dto {warehouse_code = item.warehouse_code, transfer_type_val = 3, country = item.country_code}).Where(s=>s.avg_put_days!=null).ToList();
if (lms_avgs != null && lms_avgs.Count>=1)
var lms_avgs = ApiUtility.GetLmsOrderTransferAvg(new Models.ApiDto.api_lms_order_transfer_sku_requst_dto { warehouse_code = item.warehouse_code, transfer_type_val = 3, country = item.country_code }).Where(s => s.avg_put_days != null).ToList();
if (lms_avgs != null && lms_avgs.Count >= 1)
{
data.trans_days = (int)Math.Round( lms_avgs.Min(s => s.avg_sign_days + s.avg_put_days.Value),0);
data.trans_days = (int)Math.Round(lms_avgs.Min(s => s.avg_sign_days + s.avg_put_days.Value), 0);
}
data.id = _connection.QueryFirstOrDefault<int?>(" select id from dc_auto_fastest_storage where warehouse_code=@warehouse_code and bailun_sku=@bailun_sku ",new {
data.id = _connection.QueryFirstOrDefault<int?>(" select id from dc_auto_fastest_storage where warehouse_code=@warehouse_code and bailun_sku=@bailun_sku ", new
{
warehouse_code = item.warehouse_code,
bailun_sku = item.bailun_sku
})??0;
}) ?? 0;
if (data.id <= 0)
{
_connection.Insert(data);
......@@ -4125,24 +4130,24 @@ dc_base_warehouse as t2
set t1.quantity_transfer_temp_schedule=0
where t1.warehouse_code =t2.warehouse_code and t2.hq_type not in ('国内仓','fba仓')
");
if (temp_p_datas2!=null && temp_p_datas2.Count >= 1)
if (temp_p_datas2 != null && temp_p_datas2.Count >= 1)
{
temp_p_datas.AddRange(temp_p_datas2);
// 刷到实时缺货表里面
foreach (var item in temp_p_datas2.GroupBy(s=>new { s.bailun_sku ,s.warehouse_code}))
foreach (var item in temp_p_datas2.GroupBy(s => new { s.bailun_sku, s.warehouse_code }))
{
_connection.Execute("update dc_mid_transit set quantity_transfer_temp_schedule=@quantity_transfer_temp_schedule where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code ", new
{
bailun_sku = item.Key.bailun_sku,
warehouse_code = item.Key.warehouse_code,
quantity_transfer_temp_schedule = item.Sum(v=>v.count)
quantity_transfer_temp_schedule = item.Sum(v => v.count)
});
}
}
// 查询已经有调拨的采购单
foreach (var item in temp_p_datas.GroupBy(s=>s.purchase_id))
foreach (var item in temp_p_datas.GroupBy(s => s.purchase_id))
{
foreach (var itemSku in item.AsEnumerable())
{
......@@ -4277,7 +4282,8 @@ truncate table dc_report_goods_temp;
var rows = 1000;
while (true)
{
var datas = _connection.Query<SynchroReportGoodsStockDataDto>($" select t2.product_code,t1.warehouse_code from dc_base_stock as t1 left join dc_base_sku as t2 on t1.bailun_sku = t2.bailun_sku where t1.gmt_modified>=@start_time and t1.gmt_modified<=@end_time limit {(page-1)*rows},{rows} ",new {
var datas = _connection.Query<SynchroReportGoodsStockDataDto>($" select t2.product_code,t1.warehouse_code from dc_base_stock as t1 left join dc_base_sku as t2 on t1.bailun_sku = t2.bailun_sku where t1.gmt_modified>=@start_time and t1.gmt_modified<=@end_time limit {(page - 1) * rows},{rows} ", new
{
end_time = new_task_synchro_log.end_time,
start_time = new_task_synchro_log.start_time
}).ToList();
......@@ -4289,7 +4295,8 @@ truncate table dc_report_goods_temp;
foreach (var item in datas)
{
var dc_report_goods_data = _connection.QuerySingleOrDefault<dc_report_goods>(" select * from dc_report_goods where product_code=@product_code and warehouse_code=@warehouse_code ",new {
var dc_report_goods_data = _connection.QuerySingleOrDefault<dc_report_goods>(" select * from dc_report_goods where product_code=@product_code and warehouse_code=@warehouse_code ", new
{
product_code = item.product_code,
warehouse_code = item.warehouse_code
});
......@@ -4420,7 +4427,7 @@ where (t1.gmt_purchase_modified>=@start_time and t1.gmt_purchase_modified<=@end_
countSql += " and t1.warehouse_code=@warehouse_code ";
parameters.Add("warehouse_code", searchData.warehouse_code);
}
if (searchData.warehousearea>0)
if (searchData.warehousearea > 0)
{
sql += " and t2.area_id=@area_id ";
countSql += " and t2.area_id=@area_id ";
......@@ -4529,11 +4536,11 @@ truncate table dc_report_goods_platform_temp;
}
if (!string.IsNullOrWhiteSpace(searchData.platform_type))
{
if ("amzon".Equals(searchData.platform_type,StringComparison.OrdinalIgnoreCase))
if ("amzon".Equals(searchData.platform_type, StringComparison.OrdinalIgnoreCase))
{
sql += " and t1.platform_type in @platform_types ";
countSql += " and t1.platform_type in @platform_types ";
parameters.Add("platform_types", new List<string> { "Amazon","FBA"});
parameters.Add("platform_types", new List<string> { "Amazon", "FBA" });
}
else
{
......@@ -4560,5 +4567,169 @@ truncate table dc_report_goods_platform_temp;
total = _connection.QueryFirstOrDefault<int>(countSql, parameters);
return _connection.Query<dc_report_goods_platform>(sql, parameters).AsList();
}
/// <summary>
/// 生成每周库存报表
/// </summary>
public static void GenerateWeekTagStockDatas()
{
var btime = DateTime.Now.AddDays(-7).GetWeekFirstDayMon().ToDayHome();
var etime = btime.GetWeekLastDaySun().ToDayEnd();
var week_tag = $"{btime.ToString("MM-dd")} ~ {etime.ToString("MM-dd")}";
List<dc_report_tag_stock_week_search_dto> searchs = new List<dc_report_tag_stock_week_search_dto>() {
new dc_report_tag_stock_week_search_dto{ tag="fba仓",hq_type="fba仓"},
new dc_report_tag_stock_week_search_dto{ tag="fba仓 au",hq_type="fba仓",area_name ="澳大利亚"},
new dc_report_tag_stock_week_search_dto{ tag="fba仓 ca",hq_type="fba仓",area_name ="加拿大"},
new dc_report_tag_stock_week_search_dto{ tag="fba仓 de",hq_type="fba仓",area_name ="德国"},
new dc_report_tag_stock_week_search_dto{ tag="fba仓 es",hq_type="fba仓",area_name ="西班牙"},
new dc_report_tag_stock_week_search_dto{ tag="fba仓 fr",hq_type="fba仓",area_name ="法国"},
new dc_report_tag_stock_week_search_dto{ tag="fba仓 it",hq_type="fba仓",area_name ="意大利"},
new dc_report_tag_stock_week_search_dto{ tag="fba仓 uk",hq_type="fba仓",area_name ="英国"},
new dc_report_tag_stock_week_search_dto{ tag="fba仓 us",hq_type="fba仓",area_name ="美国"},
new dc_report_tag_stock_week_search_dto{ tag="第三方仓库",hq_type="第三方仓库"},
new dc_report_tag_stock_week_search_dto{ tag="第三方仓库 美国",hq_type="第三方仓库",area_name ="美国"},
new dc_report_tag_stock_week_search_dto{ tag="第三方仓库 英国",hq_type="第三方仓库",area_name ="英国"},
new dc_report_tag_stock_week_search_dto{ tag="国内仓广州01",warehouse_code ="GZBLWH"},
new dc_report_tag_stock_week_search_dto{ tag="美容类 fba 仓",hq_type="fba仓",product_type_desc ="甲油胶,精油,香水油,其他美容"},
new dc_report_tag_stock_week_search_dto{ tag="美容类 第三方仓库",hq_type="第三方仓库",product_type_desc ="甲油胶,精油,香水油,其他美容"},
new dc_report_tag_stock_week_search_dto{ tag="美容类 国内仓",hq_type="国内仓",product_type_desc ="甲油胶,精油,香水油,其他美容"},
new dc_report_tag_stock_week_search_dto{ tag="美容类 fba 仓",hq_type="fba仓",product_type_desc ="推荐普货,精准普货"},
new dc_report_tag_stock_week_search_dto{ tag="美容类 第三方仓库",hq_type="第三方仓库",product_type_desc ="推荐普货,精准普货"},
new dc_report_tag_stock_week_search_dto{ tag="美容类 国内仓",hq_type="国内仓",product_type_desc ="推荐普货,精准普货"},
};
List<dc_report_tag_stock_week> datas = new List<dc_report_tag_stock_week>();
foreach (var item in searchs)
{
var val1 = GetWeekTagField1Val(item);
var val2= GetWeekTagField2Val(item, btime,etime);
datas.Add( new dc_report_tag_stock_week
{
week_str = week_tag,
date = btime,
field = "可用库存数",
tag = item.tag,
val = val1.v1??0
});
datas.Add(new dc_report_tag_stock_week
{
week_str = week_tag,
date = btime,
field = "可用库存金额",
tag = item.tag,
val = val1.v2 ?? 0
});
datas.Add(new dc_report_tag_stock_week
{
week_str = week_tag,
date = btime,
field = "周总消耗成本",
tag = item.tag,
val = val2.v1 ?? 0
});
datas.Add(new dc_report_tag_stock_week
{
week_str = week_tag,
date = btime,
field = "周库存周转率(销售产品成本/库存金额比率)",
tag = item.tag,
val = val1.v1 > 0 ?Math.Round((val2.v1 ?? 0)/(val1.v2 ?? 0),4): 0
}); ;
}
foreach (var item in datas)
{
item.id = _connection.QueryFirstOrDefault<int?>(" select * from dc_report_tag_stock_week where week_str=@week_str and tag=@tag and field=@field ",new {
week_str=item.week_str,
tag = item.tag,
field = item.field
}) ?? 0;
if (item.id<=0)
{
_connection.Insert(item);
}
else
{
_connection.Update(item);
}
}
}
/// <summary>
/// 取库存数
/// </summary>
/// <returns></returns>
public static dc_report_tag_stock_week_temp_dto GetWeekTagField1Val(dc_report_tag_stock_week_search_dto search)
{
var sql = @" select sum(t1.usable_stock) as 'v1',sum(t1.usable_stock * t2.unit_price ) as 'v2' from dc_base_stock as t1
left join dc_base_sku as t2 on t1.bailun_sku = t2.bailun_sku
left join dc_base_warehouse as t3 on t1.warehouse_code = t3.warehouse_code
where 1=1 ";
DynamicParameters parameters = new DynamicParameters();
if (!string.IsNullOrWhiteSpace(search.hq_type))
{
sql += " and t3.hq_type=@hq_type ";
parameters.Add("hq_type", search.hq_type);
}
if (!string.IsNullOrWhiteSpace(search.product_type_desc))
{
sql += " and t2.product_type_desc in @product_type_desc ";
parameters.Add("product_type_desc", search.product_type_desc.Split(',').ToList());
}
if (!string.IsNullOrWhiteSpace(search.area_name))
{
sql += " and t3.area_name=@area_name ";
parameters.Add("area_name", search.area_name);
}
if (!string.IsNullOrWhiteSpace(search.warehouse_code))
{
sql += " and t1.warehouse_code=@warehouse_code ";
parameters.Add("warehouse_code", search.warehouse_code);
}
return _connection.QueryFirstOrDefault<dc_report_tag_stock_week_temp_dto>(sql, parameters,commandTimeout:0);
}
/// <summary>
/// 取销售额
/// </summary>
/// <returns></returns>
public static dc_report_tag_stock_week_temp_dto GetWeekTagField2Val(dc_report_tag_stock_week_search_dto search, DateTime btime, DateTime etime)
{
var sql = @" select sum(t1.cost_product * t1.bailun_sku_quantity_shipped) as 'v1' from dc_base_oms_sku_30 as t1
left join dc_base_sku as t2 on t1.bailun_sku = t2.bailun_sku
left join dc_base_warehouse as t3 on t1.warehouse_code = t3.warehouse_code
where t1.paid_time>=@btime and t1.paid_time<=@etime ";
DynamicParameters parameters = new DynamicParameters();
parameters.Add("btime", btime);
parameters.Add("etime", etime);
if (!string.IsNullOrWhiteSpace(search.hq_type))
{
sql += " and t3.hq_type=@hq_type ";
parameters.Add("hq_type", search.hq_type);
}
if (!string.IsNullOrWhiteSpace(search.warehouse_code))
{
sql += " and t1.warehouse_code=@warehouse_code ";
parameters.Add("warehouse_code", search.warehouse_code);
}
if (!string.IsNullOrWhiteSpace(search.product_type_desc))
{
sql += " and t2.product_type_desc in @product_type_desc ";
parameters.Add("product_type_desc", search.product_type_desc.Split(',').ToList());
}
if (!string.IsNullOrWhiteSpace(search.area_name))
{
sql += " and t3.area_name=@area_name ";
parameters.Add("area_name", search.area_name);
}
return _connection.QueryFirstOrDefault<dc_report_tag_stock_week_temp_dto>(sql,parameters,commandTimeout:0);
}
public class dc_report_tag_stock_week_temp_dto
{
public decimal? v1 { get; set; }
public decimal? v2 { get; set; }
}
}
}
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
public class dc_report_tag_stock_week
{
public int id { get; set; }
public string week_str { get; set; }
public DateTime date { get; set; }
public string tag { get; set; }
public string field { get; set; }
public decimal val { get; set; }
}
public class dc_report_tag_stock_week_search_dto
{
public string hq_type { get; set; }
public string area_name { get; set; }
public string product_type_desc { get; set; }
public string warehouse_code { get; set; }
public string tag { get; set; }
}
}
......@@ -17,8 +17,7 @@ namespace ResetOutofstock
{
var now = DateTime.Now;
report.GenerateWeekTagStockDatas();
}
catch (Exception ex)
{
......
......@@ -79,6 +79,12 @@ namespace ResetOutofstock
report.PurchaseWeekBackUp();
Console.WriteLine($"结束 备份上周采购库存,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
if (now.Hour == 4 && now.Minute == 15)
{
Console.WriteLine($"开始 备份上周库存销量报表,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
report.GenerateWeekTagStockDatas();
Console.WriteLine($"结束 备份上周库存销量报表,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
}
if (now.Hour==8 && now.Minute == 10)
......
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