Commit bc959d00 by 泽锋 李

fix

parent 85b5af1e
......@@ -1881,7 +1881,7 @@ where t1.gmt_modified>=@btime and t1.gmt_modified<=@etime
bailun_sku = bailun_sku,
warehouse_code = warehouse_code
}) ?? new dc_base_head_transport_config { };
data.transport_type = dc_base_head_transport_config_data.head_transport;
data.transport_type = dc_base_head_transport_config_data.head_transport??"";
dc_report_profit_analysis sales_data = _connection.QueryFirstOrDefault<dc_report_profit_analysis>(@" select
sum( case when paid_time>=@btime2 and paid_time<=@etime1 then bailun_sku_quantity_ordered else 0 end ) as 'sales_avg_7',
sum( case when paid_time>=@btime3 and paid_time<=@etime1 then bailun_sku_quantity_ordered else 0 end ) as 'sales_avg_30',
......@@ -1991,6 +1991,123 @@ order by t1.gmt_modified asc
new_task_synchro_log.status = 1;
conn.Update(new_task_synchro_log);
}
/// <summary>
/// 查询供应链调拨在途
/// </summary>
/// <param name="sku">sku</param>
/// <param name="warehouse_code">仓库编码</param>
/// <returns></returns>
public static List<dc_report_profit_analysis> ProfitAnalysis(dc_base_stock_search_dto search_data, ref int total)
{
DynamicParameters parameters = new DynamicParameters();
var sql = "";
sql = @" select * from dc_report_profit_analysis as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
where 1=1
";
var countSql = @"
select
count(1)
from dc_report_profit_analysis as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
where 1=1
";
if (!string.IsNullOrWhiteSpace(search_data.warehousetype))
{
sql += " and t1.warehouse_type = @hq_type ";
countSql += " and t1.warehouse_type = @hq_type ";
parameters.Add("hq_type", search_data.warehousetype);
}
if (search_data.warehousearea > 0)
{
sql += " and t2.area_id = @area_id ";
countSql += " and t2.area_id = @area_id ";
parameters.Add("area_id", search_data.warehousearea);
}
if (search_data.searchType > 0 && !string.IsNullOrWhiteSpace(search_data.key_words))
{
switch (search_data.searchType)
{
case 1:
sql += " and t1.bailun_sku in @bailun_skus ";
countSql += " and t1.bailun_sku in @bailun_skus ";
parameters.Add("bailun_skus", search_data.key_words.Split(','));
break;
case 2:
sql += " and t1.bailun_sku like @bailun_sku ";
countSql += " and t1.bailun_sku like @bailun_sku ";
parameters.Add("bailun_sku", $"%{search_data.key_words}%");
break;
}
}
if (!string.IsNullOrWhiteSpace(search_data.warehousecode))
{
sql += " and t1.warehouse_code=@warehouse_code ";
countSql += " and t1.warehouse_code=@warehouse_code ";
parameters.Add("warehouse_code", search_data.warehousecode);
}
if (search_data.isSum)
{
total = 0;
}
else
{
if (search_data.is_warehouse_sum)
{
countSql += " group by t1.warehouse_code ";
sql += " group by t1.warehouse_code ";
total = _connection.Query<int>(countSql, parameters, commandTimeout: 0).Count();
}
else
{
if (search_data.limit > 1000)
{
total = 0;
}
else
{
total = _connection.Query<int>(countSql, parameters, commandTimeout: 0).Count();
}
}
if (string.IsNullOrWhiteSpace(search_data.sort))
{
search_data.sort = " t1.`ocean_purchase_amount` ";
search_data.order = "desc";
}
if (!string.IsNullOrEmpty(search_data.sort) && !string.IsNullOrEmpty(search_data.order))
{
sql += " order by " + search_data.sort;
if (!string.IsNullOrEmpty(search_data.order))
{
sql += " " + search_data.order;
}
else
{
sql += " asc";
}
}
sql += " limit " + search_data.offset + "," + search_data.limit;
}
var obj = _connection.Query<dc_report_profit_analysis>(sql, parameters, buffered: false, commandTimeout: 0).AsList();
return obj;
}
}
}
\ No newline at end of file
......@@ -685,5 +685,99 @@ namespace AutoTurnOver.Services
return DB.dc_auto_turnover.TransferProfitList(bailun_sku, warehouse_code);
}
public List<dc_report_profit_analysis> ProfitAnalysis(dc_base_stock_search_dto search_data, ref int total)
{
return DB.dc_auto_turnover.ProfitAnalysis(search_data, ref total);
}
public string ProfitAnalysisExport(dc_base_stock_search_dto search_data)
{
try
{
var fileName = AppContext.BaseDirectory + $@"周转利润分析-{DateTime.Now.ToString("yyyyMMddHHmmss")}{Guid.NewGuid()}.csv";
int page = 1;
int rows = 100000;
while (true)
{
int total = 0;
search_data.offset = (page - 1) * rows;
search_data.limit = rows;
var list = ProfitAnalysis(search_data, ref total);
if (list == null || list.Count <= 0) break;
DataTable table = new DataTable();
string[] cols = new string[] { "sku", "国家", "仓库类型", "仓库", "默认调拨方式", "180天日均", "90天日均", "30天日均","7天日均", "采购单价", "实际建议周转数",
"实际建议周转金额", "实际周转数", "实际周转运费", "实际运费单价", "海运周转数(推荐海运)", "海运周转金额", "海运周转运费", "空运周转数(推荐空运)", "空运周转金额",
"空运周转运费", "实际-海运周转采购金额差值" ,"实际-空运运费差值", "实际-空运周转采购金额差值", "海运-空运运费差值", "海运-空运周转采购金额差值", "安全库存数量", "空运周转天数",
"海运周转天数", "30天预测销量海运运费-实际周转运费金额", "30天预测销量空运运费-实际周转运费金额", "30天预测销量空运运费-海运周转运费金额"
, "差值(实际-海运)/实际周转采购金额占比" , "差值(海运-空运)/实际周转采购金额占比" , "差值(空运-实际)/实际周转采购金额占比"
, "海运与实际运费差额/库存差额" , "空运与实际运费差额/库存差额" , "30天销量海运与实际运费差额/库存差额" , "30天销量空运与实际运费差额/库存差额" , "补海运周转数" , "补海运周转金额"
};
foreach (var item in cols)
{
table.Columns.Add(item);
}
foreach (var itemData in list)
{
DataRow row = table.NewRow();
row["sku"] = itemData.bailun_sku;
row["国家"] = itemData.country;
row["仓库类型"] = itemData.warehouse_type;
row["默认调拨方式"] = itemData.transport_type;
row["180天日均"] = itemData.transport_type;
row["90天日均"] = itemData.transport_type;
row["30天日均"] = itemData.transport_type;
row["7天日均"] = itemData.transport_type;
row["采购单价"] = itemData.transport_type;
row["实际建议周转数"] = itemData.transport_type;
row["实际建议周转金额"] = itemData.transport_type;
row["实际周转数"] = itemData.transport_type;
row["实际周转运费"] = itemData.transport_type;
row["实际运费单价"] = itemData.transport_type;
row["海运周转数(推荐海运)"] = itemData.transport_type;
row["海运周转金额"] = itemData.transport_type;
row["海运周转运费"] = itemData.transport_type;
row["空运周转数(推荐空运)"] = itemData.transport_type;
row["空运周转金额"] = itemData.transport_type;
row["空运周转运费"] = itemData.transport_type;
row["实际-海运周转采购金额差值"] = itemData.transport_type;
row["实际-空运运费差值"] = itemData.transport_type;
row["实际-空运周转采购金额差值"] = itemData.transport_type;
row["海运-空运运费差值"] = itemData.transport_type;
row["海运-空运周转采购金额差值"] = itemData.transport_type;
row["安全库存数量"] = itemData.transport_type;
row["空运周转天数"] = itemData.transport_type;
row["海运周转天数"] = itemData.transport_type;
row["30天预测销量海运运费-实际周转运费金额"] = itemData.transport_type;
row["30天预测销量空运运费-实际周转运费金额"] = itemData.transport_type;
row["30天预测销量空运运费-海运周转运费金额"] = itemData.transport_type;
row["差值(实际-海运)/实际周转采购金额占比"] = itemData.transport_type;
row["差值(海运-空运)/实际周转采购金额占比"] = itemData.transport_type;
row["差值(空运-实际)/实际周转采购金额占比"] = itemData.transport_type;
table.Rows.Add(row);
}
CsvFileHelper.SaveCSV(table, fileName, page == 1);
page++;
}
return fileName;
}
catch (Exception)
{
throw;
}
}
}
}
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