Commit 25ce5a8f by 泽锋 李

抓取数据时,清理已经删除的数据

parent c7a43f9c
......@@ -1399,7 +1399,7 @@ left join dc_base_prod_order as t8 on t1.bailun_sku = t8.bailun_sku and t1.purc
{
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 ";
sql += " where t1.`status` not in (-1,4) and t1.has_delete =0 and t1.quantity_not_inbound > 0 ";
}
......@@ -1601,7 +1601,296 @@ 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 t2.sku,
t1.targetwareno as 'warehouse_code',
t3.warehouse_name as 'warehouse_name',
t4.sku_title_cn as 'sku_name',
t5.usable_stock as 'stock',
(t2.deliverycount - t2.storagecount) as 'not_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',
t4.buyer_name as 'buyer_name',
t4.product_type_desc as 'product_type_desc',
t7.type as 'forecast_type',
t1.`code` as 'order_no',
t1.transporttype,
t1.dataid,
t8.trackingno,
t8.transfer_no,
t8.box_id,
t8.node_date,
t8.node_name,
(case when t1.expectarrivaltime>'1991-01-01' then t1.expectarrivaltime else null end) as 'expectarrivaltime',
t8.surplus_node_days,
t8.expectarrivaltime as 'node_expectarrivaltime',
t8.logistics_code,
t8.logistics_name
from dc_base_transfer_info as t1
left join dc_base_transfer_info_skus as t2 on t1.dataid =t2.dataid
left join dc_base_warehouse as t3 on t1.targetwareno =t3.warehouse_code
left join dc_base_sku as t4 on t2.sku = t4.bailun_sku
left join dc_base_stock as t5 on t2.sku = t5.bailun_sku and t1.targetwareno = t5.warehouse_code
left join dc_auto_turnover as t6 on t2.sku = t6.bailun_sku and t1.targetwareno = t6.warehouse_code
left join dc_auto_forecast_fluctuation as t7 on t2.sku = t7.bailun_sku and t1.targetwareno = t7.warehouse_code
left join dc_lms_order_transfer_current_node as t8 on t1.dataid = t8.data_id and t2.sku = t8.sku
";
if (search_data.has_tort != null)
{
sql += " left join dc_base_tort as t9 on t2.sku = t9.bailun_sku ";
}
if (search_data.monitor_status != null)
{
sql += " left join dc_auto_config_sku_warehouse as t10 on t2.sku = t10.bailun_sku and t1.targetwareno = t10.warehouse_code ";
}
sql += " where t1.stateid !=5 and t2.deliverycount > t2.storagecount and t1.isdeleted=0 ";
}
var countSql = @"
select
count(1)
from dc_base_transfer_info as t1
left join dc_base_transfer_info_skus as t2 on t1.dataid =t2.dataid
left join dc_base_warehouse as t3 on t1.targetwareno =t3.warehouse_code
left join dc_base_stock as t5 on t2.sku = t5.bailun_sku and t1.targetwareno = t5.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 t4 on t2.sku = t4.bailun_sku ";
}
if (search_data.has_tort != null)
{
countSql += " left join dc_base_tort as t9 on t2.sku = t9.bailun_sku ";
}
if (search_data.monitor_status != null)
{
countSql += " left join dc_auto_config_sku_warehouse as t10 on t2.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 t5.`first_inbound_date`>=@f_start_date ";
countSql += " and t5.`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 t5.`first_inbound_date`<=@f_end_date ";
countSql += " and t5.`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 t5.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 t5.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 t4.category_simple_id in ( " + string.Join(",", categoryModels.Select(s => s.id).Distinct()) + ")";
countSql += " and t4.category_simple_id in ( " + string.Join(",", categoryModels.Select(s => s.id).Distinct()) + ")";
}
if (!string.IsNullOrWhiteSpace(search_data.buyer_name))
{
sql += " and t4.buyer_name = @buyer_name ";
countSql += " and t4.buyer_name = @buyer_name ";
parameters.Add("buyer_name", search_data.buyer_name);
}
if (search_data.product_type > 0)
{
sql += " and t4.product_type = @product_type ";
countSql += " and t4.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 t3.hq_type = @hq_type ";
countSql += " and t3.hq_type = @hq_type ";
parameters.Add("hq_type", search_data.warehousetype);
}
if (search_data.warehousearea > 0)
{
sql += " and t3.area_id = @area_id ";
countSql += " and t3.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 t2.sku in @bailun_skus ";
countSql += " and t2.sku in @bailun_skus ";
parameters.Add("bailun_skus", search_data.key_words.Split(','));
break;
case 2:
sql += " and t2.sku like @bailun_sku ";
countSql += " and t2.sku like @bailun_sku ";
parameters.Add("bailun_sku", $"%{search_data.key_words}%");
break;
case 3:
sql += " and t4.product_inner_code like @product_inner_code ";
countSql += " and t4.product_inner_code like @product_inner_code ";
parameters.Add("product_inner_code", $"%{search_data.key_words}%");
break;
case 4:
sql += " and t4.sku_title_cn like @sku_title_cn ";
countSql += " and t4.sku_title_cn like @sku_title_cn ";
parameters.Add("sku_title_cn", $"%{search_data.key_words}%");
break;
case 5:
sql += " and t4.product_inner_code = @product_inner_code ";
countSql += " and t4.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.targetwareno=@warehouse_code ";
countSql += " and t1.targetwareno=@warehouse_code ";
parameters.Add("warehouse_code", search_data.warehousecode);
}
if (!string.IsNullOrWhiteSpace(search_data.supplier_name))
{
sql += " and t4.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<order_transfer_full_link_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;
}
}
......
......@@ -143,6 +143,9 @@ namespace AutoTurnOver.DB
}
// 清理已经删除的数据
_connection.Execute(" delete from dc_base_prod_order where is_delete=1 ");
new_task_synchro_log.count = count;
new_task_synchro_log.status = 1;
......
......@@ -22,9 +22,18 @@ namespace AutoTurnOver.Models
public string product_type_desc { get; set; }
public int? forecast_type { get; set; }
public string order_no { get; set; }
public string trackingno { get; set; }
public string transporttype { get; set; }
public string dataid { get; set; }
public string channelname { get; set; }
public string trackingno { get; set; }
public string transfer_no { get; set; }
public string box_id { get; set; }
public DateTime? node_date { get; set; }
public string node_name { get; set; }
public DateTime? expectarrivaltime { get; set; }
public decimal? surplus_node_days { get; set; }
public decimal? node_expectarrivaltime { get; set; }
public string logistics_code { get; set; }
public string logistics_name { get; set; }
}
}
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