Commit 79993391 by 泽锋 李

fix

parent e2707c45
......@@ -11,6 +11,8 @@ using AutoTurnOver.Models.stock;
using AutoTurnOver.Utility;
using AutoTurnOver.Models.Report;
using System.Threading;
using Newtonsoft.Json;
using AutoTurnOver.Models.auto;
namespace AutoTurnOver.DB
{
......@@ -136,7 +138,7 @@ from dc_auto_turnover as dat
if (m.monitor_status != null)
{
sqlCount += " left join dc_auto_config_sku_warehouse as t5 on dat.bailun_sku = t5.bailun_sku and dat.warehouse_code = t5.warehouse_code ";
}
}
if (m.storage_capacity_status != null)
{
sqlCount += " left join dc_base_storage_capacity_config as t16 on dat.bailun_sku = t16.bailun_sku and dat.warehouse_code = t16.warehouse_code ";
......@@ -220,7 +222,7 @@ from dc_auto_turnover as dat
whereSql += " and t16.`status` is null ";
sqlCount += " and t16.`status` is null ";
}
if (m.is_mother_sku == 1)
{
whereSql += " and dat.`is_mother_sku`=1 ";
......@@ -289,7 +291,7 @@ from dc_auto_turnover as dat
break;
case 8:
var mother_sku_warehouse_codes = _connection.Query<string>(@" select mother_sku_warehouse_code from dc_base_mother_sku_map as tm where tm.bailun_sku = @bailun_sku ", new { bailun_sku = m.key_words }).ToList();
if(mother_sku_warehouse_codes!=null && mother_sku_warehouse_codes.Count >= 1)
if (mother_sku_warehouse_codes != null && mother_sku_warehouse_codes.Count >= 1)
{
whereSql += " and dat.bailun_sku_warehouse_code in @bailun_sku_warehouse_codes";
sqlCount += " and dat.bailun_sku_warehouse_code in @bailun_sku_warehouse_codes";
......@@ -300,7 +302,7 @@ from dc_auto_turnover as dat
whereSql += " and 1=2 ";
sqlCount += " and 1=2 ";
}
break;
default: break;
}
......@@ -445,7 +447,7 @@ from dc_auto_turnover as dat
}
else
{
total = _connection.QuerySingleOrDefault<int>(sqlCount, parameters, commandTimeout: 0);
//Console.WriteLine(sqlCount);
//设置默认排序字段
......@@ -470,12 +472,13 @@ from dc_auto_turnover as dat
var obj = _connection.Query<Models.dc_auto_turnover_list_dto>(sql+ whereSql+ limit_sql, parameters, commandTimeout: 0).AsList();
var obj = _connection.Query<Models.dc_auto_turnover_list_dto>(sql + whereSql + limit_sql, parameters, commandTimeout: 0).AsList();
//Console.WriteLine(sql);
if(obj!=null && obj.Count >= 1)
if (obj != null && obj.Count >= 1)
{
var storage_capacity_configs = _connection.Query<dc_base_storage_capacity_config>(" select * from dc_base_storage_capacity_config where bailun_sku_warehouse_code in @bailun_sku_warehouse_codes ",new {
bailun_sku_warehouse_codes = obj.Select(s=>$"{s.bailun_sku}{s.warehouse_code}").ToList()
var storage_capacity_configs = _connection.Query<dc_base_storage_capacity_config>(" select * from dc_base_storage_capacity_config where bailun_sku_warehouse_code in @bailun_sku_warehouse_codes ", new
{
bailun_sku_warehouse_codes = obj.Select(s => $"{s.bailun_sku}{s.warehouse_code}").ToList()
}).ToList();
foreach (var item in obj)
......@@ -493,7 +496,7 @@ from dc_auto_turnover as dat
item.history_fourteenday_sales_amazon = item.history_fourteenday_sales_amazon.Round1();
item.history_thirtyday_sales_amazon = item.history_thirtyday_sales_amazon.Round1();
var storage_capacity_config = storage_capacity_configs.FirstOrDefault(s=>s.bailun_sku_warehouse_code== $"{item.bailun_sku}{item.warehouse_code}")??new dc_base_storage_capacity_config { };
var storage_capacity_config = storage_capacity_configs.FirstOrDefault(s => s.bailun_sku_warehouse_code == $"{item.bailun_sku}{item.warehouse_code}") ?? new dc_base_storage_capacity_config { };
item.storage_capacity_status = storage_capacity_config.status;
}
......@@ -501,10 +504,11 @@ from dc_auto_turnover as dat
if (obj.Count <= 200)
{
// 查询所有映射
var map_datas = _connection.Query<dc_base_mother_sku_map>(" select * from dc_base_mother_sku_map where mother_sku_warehouse_code in @mother_sku_warehouse_codes ",new {
mother_sku_warehouse_codes = obj.Select(s=>s.bailun_sku_warehouse_code).ToList()
var map_datas = _connection.Query<dc_base_mother_sku_map>(" select * from dc_base_mother_sku_map where mother_sku_warehouse_code in @mother_sku_warehouse_codes ", new
{
mother_sku_warehouse_codes = obj.Select(s => s.bailun_sku_warehouse_code).ToList()
}).ToList();
if(map_datas!=null && map_datas.Count >= 1)
if (map_datas != null && map_datas.Count >= 1)
{
var map_turn_datas = _connection.Query<dc_auto_turnover_list_dto>(sql + " and dat.bailun_sku_warehouse_code in @bailun_sku_warehouse_codes ", new { bailun_sku_warehouse_codes = map_datas.Select(s => s.bailun_sku_warehouse_code).ToList() });
foreach (var item in obj)
......@@ -512,10 +516,10 @@ from dc_auto_turnover as dat
item.maps = map_turn_datas.Where(s => map_datas.Any(v => v.mother_sku_warehouse_code == item.bailun_sku_warehouse_code && s.bailun_sku_warehouse_code == v.bailun_sku_warehouse_code)).ToList();
}
}
}
}
return obj;
}
catch (Exception ex)
......@@ -1418,8 +1422,8 @@ where t1.gmt_modified>=@btime and t1.gmt_modified<=@etime
modalData.product_count_3 = average_warehouse_data.product_count_3;
modalData.order_count = average_warehouse_data.order_count;
modalData.order_count_3 = average_warehouse_data.order_count_3;
modalData.order_count_3_radio = modalData.order_count<=0?0 : modalData.order_count_3 / modalData.order_count;
modalData.product_count_3_radio = modalData.product_count <= 0?0 : modalData.product_count_3 / modalData.product_count;
modalData.order_count_3_radio = modalData.order_count <= 0 ? 0 : modalData.order_count_3 / modalData.order_count;
modalData.product_count_3_radio = modalData.product_count <= 0 ? 0 : modalData.product_count_3 / modalData.product_count;
datas.FirstOrDefault(s => s.name == "空运调拨票数占比").days.Add(new transfer_profit_dto.day_dto
{
......@@ -1450,12 +1454,12 @@ where t1.gmt_modified>=@btime and t1.gmt_modified<=@etime
});
modalData.transfer_days_air = result_air.transfer_delivery + (result_air.abroad_inbound_delivery) + (result_air.transfer_bale_delivery);
modalData.transfer_days = result.transfer_delivery + (result.abroad_inbound_delivery)+ (result.transfer_bale_delivery);
modalData.transfer_days = result.transfer_delivery + (result.abroad_inbound_delivery) + (result.transfer_bale_delivery);
modalData.transfer_days_ocean = result_ocean.transfer_delivery + (result_ocean.abroad_inbound_delivery) + (result_ocean.transfer_bale_delivery);
modalData.transfer_sales = sales_details.Where((s,a_index)=> a_index > 7 && a_index <= (7+ modalData.transfer_days)).Sum();
modalData.transfer_sales_air = sales_details_air.Where((s,a_index)=> a_index > 7 && a_index <= (7+ modalData.transfer_days_air)).Sum();
modalData.transfer_sales_ocean = sales_details_ocean.Where((s,a_index)=> a_index > 7 && a_index <= (7+ modalData.transfer_days_ocean)).Sum();
modalData.transfer_sales = sales_details.Where((s, a_index) => a_index > 7 && a_index <= (7 + modalData.transfer_days)).Sum();
modalData.transfer_sales_air = sales_details_air.Where((s, a_index) => a_index > 7 && a_index <= (7 + modalData.transfer_days_air)).Sum();
modalData.transfer_sales_ocean = sales_details_ocean.Where((s, a_index) => a_index > 7 && a_index <= (7 + modalData.transfer_days_ocean)).Sum();
//30天周转数
modalData.quantity_final_advise_30 = sales30;
......@@ -1511,9 +1515,9 @@ where t1.gmt_modified>=@btime and t1.gmt_modified<=@etime
modalData.transfer_order_days = result.transfer_order_days;
modalData.sail_days = result.transfer_sail_days;
modalData.turnover_days_air = result_air.turnover_days;
modalData.purchase_create_order_days_air = result_air.purchase_create_order_days;
modalData.payment_before_delivery_air = result_air.payment_before_delivery;
......@@ -1522,7 +1526,7 @@ where t1.gmt_modified>=@btime and t1.gmt_modified<=@etime
modalData.transfer_delivery_air = result_air.transfer_delivery;
modalData.abroad_inbound_delivery_air = result_air.abroad_inbound_delivery;
modalData.transfer_bale_delivery_air = result_air.transfer_bale_delivery;
modalData.sail_days_air = result_air.transfer_sail_days;
modalData.sail_days_air = result_air.transfer_sail_days;
modalData.transfer_order_days_air = result_air.transfer_order_days;
datas.FirstOrDefault(s => s.name == "空运周转天数").days.Add(new transfer_profit_dto.day_dto
{
......@@ -1592,7 +1596,7 @@ where t1.gmt_modified>=@btime and t1.gmt_modified<=@etime
formula = $" 【实际周转数】 = 采购+调拨在途 ({quantity_transfer + quantity_purchase}) + 在库 ({dc_stock_data}) "
});
modalData.freight_price = dc_base_transfer_freight_data.freight;
modalData.freight_price = dc_base_transfer_freight_data.freight;
datas.FirstOrDefault(s => s.name == "实际周转运费").days.Add(new transfer_profit_dto.day_dto
{
date = this_time,
......@@ -1611,7 +1615,7 @@ where t1.gmt_modified>=@btime and t1.gmt_modified<=@etime
val = modalData.turnover_amount,
formula = $" "
});
modalData.turnover_sales_ocean = result_ocean.turnover_sales;
modalData.quantity_final_advise_ocean = (int)Math.Round(result_ocean.turnover_sales + result_ocean.quantity_safe_inventory);
datas.FirstOrDefault(s => s.name == "海运周转数(推荐海运)").days.Add(new transfer_profit_dto.day_dto
......@@ -2008,7 +2012,7 @@ where t1.gmt_modified>=@btime and t1.gmt_modified<=@etime
}
index++;
......@@ -2096,7 +2100,7 @@ where t1.gmt_modified>=@btime and t1.gmt_modified<=@etime
profit_data.forecast_daily_weighted_sales_air = profit_data.turnover_days_air <= 0 ? 0 : Math.Round(profit_data.turnover_sales_air / profit_data.turnover_days_air);
var formula_json = profit_data.ToJson();
dc_report_profit_analysis data = formula_json.ToObj<dc_report_profit_analysis>();
data.bailun_sku = bailun_sku;
data.formula_json = formula_json;
data.warehouse_code = warehouse_code;
......@@ -2136,14 +2140,14 @@ from dc_base_oms_sku where bailun_sku=@bailun_sku and warehouse_code=@warehouse_
etime1 = DateTime.Now.AddDays(-1).ToDayEnd(),
}, commandTimeout: 0) ?? 0) / 180;
data.id = _connection.QueryFirstOrDefault<int?>(" select id from dc_report_profit_analysis where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code ", new
{
bailun_sku = bailun_sku,
warehouse_code = warehouse_code
}) ?? 0;
data.update_time = DateTime.Now;
if (data.id > 0)
{
......@@ -2197,7 +2201,7 @@ from dc_base_oms_sku where bailun_sku=@bailun_sku and warehouse_code=@warehouse_
var datas = conn.Query<sku_warehouse_code_dto>($@" select t1.bailun_sku,t1.warehouse_code from dc_auto_turnover as t1 left join dc_base_warehouse as t2 on t1.warehouse_code =t2.warehouse_code
where t2.hq_type not in ('国内仓') and t1.gmt_modified>=@btime and t1.gmt_modified <=@etime and t1.daily_weighted_sales>1
order by t1.gmt_modified asc
limit {(page - 1) * rows},{rows} ", new { btime = new_task_synchro_log.start_time, etime = new_task_synchro_log.end_time },commandTimeout:0).ToList();
limit {(page - 1) * rows},{rows} ", new { btime = new_task_synchro_log.start_time, etime = new_task_synchro_log.end_time }, commandTimeout: 0).ToList();
if (datas.Count <= 0) { break; }
page++;
foreach (var orderItem in datas)
......@@ -2239,7 +2243,7 @@ order by t1.gmt_modified asc
sql = @"
";
}
else
{
......@@ -2558,7 +2562,7 @@ left join dc_auto_turnover as dat on dat.warehouse_code = ta.warehouse_code and
var obj = _connection.Query<dc_report_profit_analysis_dto>(sql, parameters, buffered: false, commandTimeout: 0).AsList();
if (m.isSum)
{
return new List<dc_report_profit_analysis_dto>() {
return new List<dc_report_profit_analysis_dto>() {
new dc_report_profit_analysis_dto {
sales_avg_180 =obj.Sum(s=>s.sales_avg_180),
sales_avg_90 =obj.Sum(s=>s.sales_avg_90),
......@@ -2590,7 +2594,7 @@ left join dc_auto_turnover as dat on dat.warehouse_code = ta.warehouse_code and
{
return obj;
}
}
......@@ -2640,10 +2644,112 @@ left join dc_auto_turnover as dat on dat.warehouse_code = ta.warehouse_code and
datas.Add(item_data);
_connection.Insert(item_data);
}
}
}
}
/// <summary>
/// 刷新 每日配置销量
/// </summary>
public static void Synchrofull_stock_use_days_turnover_sales()
{
if (DateTime.Now.Hour < 8)
{
return;
}
var task_name = $"Synchrofull_stock_use_days_turnover_sales_v1";
var conn = MyMySqlConnection._connection; ;
// 查询最后一次成功抓取的记录
var last_task_synchro_log = conn.QuerySingleOrDefault<task_synchro_log>(" select * from task_synchro_log where task_name=@task_name and status=1 order by end_time desc limit 1 ", new { task_name = task_name });
var new_task_synchro_log = new task_synchro_log
{
create_date = DateTime.Now,
end_time = DateTime.Now.AddMinutes(-2),
status = 0,
task_name = task_name
};
if (last_task_synchro_log != null)
{
new_task_synchro_log.start_time = last_task_synchro_log.end_time.AddMinutes(-1);
}
else
{
new_task_synchro_log.start_time = DateTime.Now.AddYears(-1);
}
new_task_synchro_log.id = conn.Insert(new_task_synchro_log) ?? 0;
int count = 0;
int page = 1;
int rows = 1000;
var now = DateTime.Now;
while (true)
{
var datas = conn.Query<Models.dc_auto_turnover>($@" select t1.* from dc_auto_turnover as t1
where t1.gmt_modified>=@btime and t1.gmt_modified <=@etime
order by t1.gmt_modified asc
limit {(page - 1) * rows},{rows} ", new { btime = new_task_synchro_log.start_time, etime = new_task_synchro_log.end_time }, commandTimeout: 0).ToList();
if (datas.Count <= 0) { break; }
page++;
foreach (var orderItem in datas)
{
try
{
set_full_stock_use_days_turnover_sales(orderItem);
count++;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
}
new_task_synchro_log.count = count;
new_task_synchro_log.status = 1;
conn.Update(new_task_synchro_log);
}
/// <summary>
/// 设置 在途加在库可用天数的总销量
/// </summary>
public static void set_full_stock_use_days_turnover_sales(Models.dc_auto_turnover data)
{
var sales_day_configs = _connection.Query<sales_day_config>(" select * from sales_day_config where bailun_sku_warehouse_code =@bailun_sku_warehouse_code ", new
{
bailun_sku_warehouse_code = data.bailun_sku_warehouse_code
}).ToList();
var sales_day_config_details_list = new List<decimal>();
var sales_details_list = data.sales_details.Replace("[","").Replace("]","").Split(',').Select(s=>decimal.Parse(s)).ToList();
var thisDate = DateTime.Now.ToDayHome();
var thisEnd = thisDate.AddDays(data.turnover_days).ToDayEnd();
var index = 7;
while (thisDate <= thisEnd)
{
var date_str = thisDate.ToString("yyyy-MM-dd");
sales_day_config_details_list.Add((sales_day_configs.FirstOrDefault(s => s.date_str == date_str) ?? new sales_day_config()
{
sales = sales_details_list.Count - 1 >= index ? sales_details_list[index] : 0
}).sales);
thisDate = thisDate.AddDays(1);
index++;
}
data.sales_day_config_details = sales_day_config_details_list.ToJson();
_connection.Execute(" update dc_auto_turnover set sales_day_config_details=@sales_day_config_details where id=@id ", new
{
id = data.id,
sales_day_config_details = data.sales_day_config_details
});
}
}
}
\ No newline at end of file
......@@ -22,6 +22,11 @@ namespace AutoTurnOver.Models
public int id { get; set; }
/// <summary>
/// 供应链长度的配置销量明细
/// </summary>
public string sales_day_config_details { get; set; }
/// <summary>
/// 建议单单号
/// </summary>
[Description(@"建议单单号")]
......@@ -827,19 +832,23 @@ namespace AutoTurnOver.Models
return forecast_average_day <=0?0: (int)Math.Ceiling((usable_stock??0) / forecast_average_day);
}
}
public string sales_day_config_details { get; set; }
public string full_stock_use_days_turnover_sales { get
public string full_stock_use_days_turnover_sales {
get
{
try
{
var details = JsonConvert.DeserializeObject <List<decimal>>(sales_details).Select(s => (int)Math.Ceiling(s)).ToList();
return details.Where((s, index) => index>=7 && index<= (full_stock_use_days + 7-1) ).Sum().ToString();
var details = JsonConvert.DeserializeObject<List<decimal>>(sales_day_config_details).Select(s => (int)Math.Ceiling(s)).ToList();
return details.Where((s, index) => index <= (full_stock_use_days - 1)).Sum().ToString();
}
catch (Exception ex)
{
return ex.Message;
}
} }
}
}
/// <summary>
/// 库存可买日期
......
......@@ -35,6 +35,7 @@ namespace ResetOutofstock
//dc_base_transfer_extend_dao.SynchroLmsTransferOrder();
//dc_base_full_link_wait_order_dao.ResetDatas();
//dc_base_mother_sku_dao.GenerateData();
dc_auto_turnover.Synchrofull_stock_use_days_turnover_sales();
}
catch (Exception ex)
{
......
......@@ -303,6 +303,26 @@ namespace ResetOutofstock
{
try
{
Console.WriteLine($"开始刷新 增量刷新周转扩展字段,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
dc_auto_turnover.Synchrofull_stock_use_days_turnover_sales();
Console.WriteLine($"结束刷新 增量刷新周转扩展字段,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
catch (Exception ex)
{
Console.WriteLine("增量刷新周转利润分析:"+ex.Message);
Console.WriteLine("增量刷新周转利润分析:"+ex.StackTrace);
}
Thread.Sleep(10 * 60 * 1000);
}
});
Task.Factory.StartNew(() =>
{
while (true)
{
try
{
Console.WriteLine($"开始刷新 增量刷新母sku周转数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
dc_base_mother_sku_dao.SynchroCalculationTurnOver();
Console.WriteLine($"结束刷新 增量刷新母sku周转数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
......
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