Commit 75a6d55e by 泽锋 李

fix

parent b5d28489
......@@ -1601,299 +1601,7 @@ left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
return obj;
}
/// <summary>
/// 查询调拨单在途
/// </summary>
/// <param name="sku">sku</param>
/// <param name="warehouse_code">仓库编码</param>
/// <returns></returns>
public static List<order_transfer_full_link_dto> FullLinkTransferList(dc_base_stock_search_dto search_data, List<bailun_category_new_dto> categoryModels, ref int total)
{
DynamicParameters parameters = new DynamicParameters();
var sql = "";
if (search_data.isSum || search_data.is_warehouse_sum)
{
sql = @"
select
sum(ifnull(t1.quantity_purchase,0)) as 'quantity_purchase',
sum(ifnull(t1.`quantity_arrival`,0)) as 'quantity_arrival',
sum(ifnull(t1.`quantity_inbound`,0)) as 'quantity_inbound',
sum(ifnull(t1.`quantity_not_inbound`,0)) as 'quantity_not_inbound'
from dc_base_purchase_details as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
";
if ((categoryModels != null && categoryModels.Count >= 1) || !string.IsNullOrWhiteSpace(search_data.buyer_name) || search_data.product_type > 0)
{
sql += " left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku ";
}
if (search_data.has_tort != null)
{
sql += " left join dc_base_tort as t9 on t1.bailun_sku = t9.bailun_sku ";
}
if (search_data.monitor_status != null)
{
sql += " left join dc_auto_config_sku_warehouse as t10 on t1.bailun_sku = t10.bailun_sku and t1.warehouse_code = t10.warehouse_code ";
}
sql += " where t1.`status` not in (-1,4) and t1.has_delete =0 and t1.quantity_not_inbound > 0 ";
}
else
{
sql = @"
select t1.bailun_sku,
t1.warehouse_code as 'warehouse_code',
t2.warehouse_name as 'warehouse_name',
t3.sku_title_cn as 'product_title',
t3.buyer_name as 'buyer_name',
t3.product_type_desc as 'product_type_desc',
t4.usable_stock as 'stock',
t5.quantity_transfer as 'quantity_transfer',
t5.quantity_transfer_order as 'quantity_transfer_order',
t5.quantity_transfer_temp_schedule as 'quantity_transfer_temp_schedule',
t5.quantity_transfer_temporary_storage as 'quantity_transfer_temporary_storage',
t6.history_sevenday_sales as 'history_sevenday_sales',
t6.history_fourteenday_sales as 'history_fourteenday_sales',
t6.history_thirtyday_sales as 'history_thirtyday_sales',
t7.type as 'forecast_type',
t1.purchase_id as 'purchase_id',
t1.quantity_purchase as 'quantity_purchase',
t1.`status` as 'purchase_status',
t1.`last_signtime` as 'last_signtime',
t1.`quantity_arrival` as 'quantity_arrival',
t1.`quantity_inbound` as 'quantity_inbound',
t1.`quantity_not_inbound` as 'quantity_not_inbound',
t1.`arrivaldate` as 'purchase_arrivaldate',
t8.`status` as 'prod_status',
t8.distribution_quantity as 'prod_distribution_quantity',
( t8.order_quantity - t8.distribution_quantity) as 'prod_not_distribution_quantity',
t8.prod_quantity as 'prod_quantity'
from dc_base_purchase_details as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku
left join dc_base_stock as t4 on t1.bailun_sku = t4.bailun_sku and t1.warehouse_code = t4.warehouse_code
left join dc_mid_transit as t5 on t1.bailun_sku = t5.bailun_sku and t1.warehouse_code = t5.warehouse_code
left join dc_auto_turnover as t6 on t1.bailun_sku = t6.bailun_sku and t1.warehouse_code = t6.warehouse_code
left join dc_auto_forecast_fluctuation as t7 on t1.bailun_sku = t7.bailun_sku and t1.warehouse_code = t7.warehouse_code
left join dc_base_prod_order as t8 on t1.bailun_sku = t8.bailun_sku and t1.purchase_id = t8.purchase_no
";
if (search_data.has_tort != null)
{
sql += " left join dc_base_tort as t9 on t1.bailun_sku = t9.bailun_sku ";
}
if (search_data.monitor_status != null)
{
sql += " left join dc_auto_config_sku_warehouse as t10 on t1.bailun_sku = t10.bailun_sku and t1.warehouse_code = t10.warehouse_code ";
}
sql += " where t1.`status` not in (-1,4) and t1.has_delete =0 and t1.quantity_not_inbound > 0 and t8.is_delete=0 ";
}
var countSql = @"
select
count(1)
from
dc_base_purchase_details as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
";
if ((categoryModels != null && categoryModels.Count >= 1) || !string.IsNullOrWhiteSpace(search_data.buyer_name) || search_data.product_type > 0)
{
countSql += " left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku ";
}
if (search_data.has_tort != null)
{
countSql += " left join dc_base_tort as t9 on t1.bailun_sku = t9.bailun_sku ";
}
if (search_data.monitor_status != null)
{
countSql += " left join dc_auto_config_sku_warehouse as t10 on t1.bailun_sku = t10.bailun_sku and t1.warehouse_code = t10.warehouse_code ";
}
countSql += " where t1.`status` not in (-1,4) and t1.has_delete =0 and t1.quantity_not_inbound > 0 ";
parameters.Add("time", DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
if (search_data.f_start_date != null)
{
sql += " and t4.`first_inbound_date`>=@f_start_date ";
countSql += " and t4.`first_inbound_date`>=@f_start_date ";
parameters.Add("f_start_date", search_data.f_start_date.Value.ToString("yyyy-MM-dd 00:00:00"));
}
if (search_data.f_end_date != null)
{
sql += " and t4.`first_inbound_date`<=@f_end_date ";
countSql += " and t4.`first_inbound_date`<=@f_end_date ";
parameters.Add("f_end_date", search_data.f_end_date.Value.ToString("yyyy-MM-dd 23:59:59"));
}
if (search_data.start_date != null && search_data.end_date != null)
{
sql += " and t4.bailun_sku_warehouse_code in (select t_re.bailun_sku_warehouse_code from dc_base_stock_record_effective as t_re where t_re.stock_time >=@start_date and t_re.stock_time <=@end_date ) ";
countSql += " and t4.bailun_sku_warehouse_code in (select t_re.bailun_sku_warehouse_code from dc_base_stock_record_effective as t_re where t_re.stock_time >=@start_date and t_re.stock_time <=@end_date ) ";
parameters.Add("start_date", search_data.start_date.Value.ToString("yyyy-MM-dd 00:00:00"));
parameters.Add("end_date", search_data.end_date.Value.ToString("yyyy-MM-dd 23:59:59"));
}
if (categoryModels != null && categoryModels.Count >= 1)
{
sql += " and t3.category_simple_id in ( " + string.Join(",", categoryModels.Select(s => s.id).Distinct()) + ")";
countSql += " and t3.category_simple_id in ( " + string.Join(",", categoryModels.Select(s => s.id).Distinct()) + ")";
}
if (!string.IsNullOrWhiteSpace(search_data.buyer_name))
{
sql += " and t3.buyer_name = @buyer_name ";
countSql += " and t3.buyer_name = @buyer_name ";
parameters.Add("buyer_name", search_data.buyer_name);
}
if (search_data.product_type > 0)
{
sql += " and t3.product_type = @product_type ";
countSql += " and t3.product_type = @product_type ";
parameters.Add("product_type", search_data.product_type);
}
if (search_data.monitor_status == 1)
{
sql += " and t10.`status`=1 ";
countSql += " and t10.`status`=1 ";
}
if (search_data.monitor_status == 0)
{
sql += " and ( t10.`status`=0 or t10.`status` is null ) ";
countSql += " and ( t10.`status`=0 or t10.`status` is null ) ";
}
if (search_data.has_tort != null)
{
if (search_data.has_tort == 0)
{
sql += " and t9.id is null ";
countSql += " and t9.id is null ";
}
else if (search_data.has_tort == 1)
{
sql += " and t9.id is not null ";
countSql += " and t9.id is not null ";
}
}
if (!string.IsNullOrWhiteSpace(search_data.warehousetype))
{
sql += " and t2.hq_type = @hq_type ";
countSql += " and t2.hq_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;
case 3:
sql += " and t3.product_inner_code like @product_inner_code ";
countSql += " and t3.product_inner_code like @product_inner_code ";
parameters.Add("product_inner_code", $"%{search_data.key_words}%");
break;
case 4:
sql += " and t3.sku_title_cn like @sku_title_cn ";
countSql += " and t3.sku_title_cn like @sku_title_cn ";
parameters.Add("sku_title_cn", $"%{search_data.key_words}%");
break;
case 5:
sql += " and t3.product_inner_code = @product_inner_code ";
countSql += " and t3.product_inner_code = @product_inner_code ";
parameters.Add("product_inner_code", $"{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 (!string.IsNullOrWhiteSpace(search_data.supplier_name))
{
sql += " and t3.suppliers_name =@suppliers_name ";
parameters.Add("suppliers_name", search_data.supplier_name);
}
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.QueryFirst<int>(countSql, parameters, commandTimeout: 0);
}
}
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<full_link_purchase_dto>(sql, parameters, buffered: false, commandTimeout: 0).AsList();
foreach (var item in obj)
{
item.history_sevenday_sales = (item.history_sevenday_sales ?? 0).Round1();
item.history_fourteenday_sales = (item.history_fourteenday_sales ?? 0).Round1();
item.history_thirtyday_sales = (item.history_thirtyday_sales ?? 0).Round1();
}
return obj;
}
}
......
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