Commit 46ecf317 by 泽锋 李

空运切货,lms接口 fix

parent 7a4f252e
......@@ -932,7 +932,25 @@ select t7_1.warehouse_code,t7_1.bailun_sku,(to_days(t7_1.estimated_arrival_time)
return datas;
}
/// <summary>
/// 备份预测值
/// </summary>
public static void CopyForecast()
{
_connection.Execute(@"REPLACE INTO dc_base_forecast_history(`bailun_sku`,`warehouse_code`,`bailun_sku_warehouse_code`,`date`,`date_str`,`create_date`,`sales`)
(
select
bailun_sku,
warehouse_code,
CONCAT(bailun_sku,warehouse_code) as 'bailun_sku_warehouse_code',
gmt_modified as 'date',
DATE_FORMAT(gmt_modified,'%Y-%m-%d') as 'date_str',
now() as 'create_date',
forecast_oneday_sales as 'sales'
from dc_auto_turnover where gmt_modified>=@btime and gmt_modified<=@etime
)
", new { btime = DateTime.Now.ToDayHome(), etime = DateTime.Now.ToDayEnd() });
}
}
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.DB
{
/// <summary>
/// 历史预测值
/// </summary>
public class dc_base_forecast_history
{
public int id { get; set; }
public string bailun_sku { get; set; }
public string warehouse_code { get; set; }
public string bailun_sku_warehouse_code { get; set; }
public DateTime date { get; set; }
public string date_str { get; set; }
public DateTime create_date { get; set; }
public decimal sales { get; set; }
}
}
......@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using AutoTurnOver.Utility;
namespace AutoTurnOver.DB
{
......@@ -60,7 +61,7 @@ namespace AutoTurnOver.DB
if (logisticsDatas != null && logisticsDatas.Count >= 1)
{
// 查询最快的物流渠道
var avgs = ApiUtility.GetLmsOrderTransferAvg(new Models.ApiDto.api_lms_order_transfer_sku_requst_dto {warehouse_code = item.warehouse_code, country = item.country_code, logistics_code = string.Join(",", logisticsDatas.Select(s=>s.Line_Code)) });
var avgs = ApiUtility.GetLmsOrderTransferAvg(new Models.ApiDto.api_lms_order_transfer_sku_requst_dto {warehouse_code = item.warehouse_code, country = item.country_code, logistics_code = string.Join(",", logisticsDatas.Select(s=>s.Line_Code)) }).Where(s=>s.avg_put_days!=null).ToList();
if (avgs != null)
{
var selectItem = avgs.Where(s=>s.avg_put_days!=null).Where(s => s.avg_put_days + s.avg_sign_days <= item.surplus_allocation_days).OrderByDescending(s => s.avg_sign_days + s.avg_put_days).FirstOrDefault();
......@@ -1823,6 +1824,6 @@ where t1.warehouse_code=@warehousecode and t1.bailun_sku=@sku and t2.create_time
_connection.Delete<dc_auto_purchase_advise_detailed>(id);
}
}
}
......@@ -4018,7 +4018,7 @@ 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 =3, country = item.country_code}).Where(s=>s.avg_put_days!=null).ToList();
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);
......
......@@ -258,7 +258,8 @@ namespace AutoTurnOver.Models.ApiDto
public int orders { get; set; }
public int transfer_type { get; set; }
public string transfer_type { get; set; }
public int? transfer_type_val { get; set; }
public string logistics_code { get; set; }
}
......
......@@ -259,7 +259,7 @@ namespace AutoTurnOver.Services
var lmsAvg = ApiUtility.GetLmsOrderTransferAvg(new Models.ApiDto.api_lms_order_transfer_sku_requst_dto
{
//bailun_sku = skuItem.bailun_sku,
transfer_type = transfer_type,
transfer_type_val = transfer_type,
warehouse_code = skuItem.warehouse_code,
logistics_code = dc_base_head_transport_config_data.logistics_code,
country = base_wa
......
......@@ -72,6 +72,8 @@ namespace AutoTurnOver.Services
}
list.Add(sales != null ? sales.sales_details.ToObj<List<decimal>>().Select(s => (int)Math.Ceiling(s)).ToJson() : "[]");
list.Add(sales != null&& (!string.IsNullOrWhiteSpace(sales.sales_details_formula)) ? sales.sales_details_formula.ToObj<List<string>>().Select(s => s).ToJson() : "[]");
list.Add(sales != null ? sales.sales_explain_details.Replace("[", "").Replace("]", "").Split(',').ToJson() : "[]");
......
......@@ -101,7 +101,7 @@ namespace AutoTurnOver.Controllers
}
var names = new List<string>() { "销量", "计算公式", "计算规则", "预计入库", "可用库存", "预计缺货数量", "特殊销量", "市场因素", "建议下单数量", "人工下单数量" };
var names = new List<string>() { "销量","历史预测", "计算公式", "计算规则", "预计入库", "可用库存", "预计缺货数量", "特殊销量", "市场因素", "建议下单数量", "人工下单数量" };
var turnoverData = new Services.SkuAutoTurnServices().GetModel(sku, warehousecode);
var saleVolumeData = new Services.SaleVolumeServices().GetBySkuWarehouseCode(sku, warehousecode);
var averageTargets = PurchaseAverageTargetServices.GetListByWCode(sku, warehousecode);
......@@ -121,30 +121,63 @@ namespace AutoTurnOver.Controllers
// 累计预计到货
decimal turnoverDatepurchase = 0;
var purchaseList = result[3].ToObj<List<decimal>>();
var purchaseList = result[4].ToObj<List<decimal>>();
for (int i = 7; i < turnoverData.turnover_days + 7; i++)
{
turnoverDatepurchase += purchaseList[i];
}
var forecast_history_btime = turnoverData.gmt_modified.AddDays(-7).ToDayHome();
var forecast_history_etime = turnoverData.gmt_modified.AddDays(-1).ToDayEnd();
// 查询历史预测销量
var forecast_historys = connectionHelper._connection.Query<dc_base_forecast_history>(" select * from dc_base_forecast_history where bailun_sku_warehouse_code=@bailun_sku_warehouse_code and `date`>=@btime and `date`<=@etime ", new
{
bailun_sku_warehouse_code = $"{turnoverData.bailun_sku}{turnoverData.warehouse_code}",
btime = forecast_history_btime,
etime = forecast_history_etime
}).ToList();
var forecast_history_sales = new List<string>();
var this_forecast_history_date = forecast_history_btime;
while (this_forecast_history_date <= forecast_history_etime)
{
var temp_forecast_history = forecast_historys.FirstOrDefault(s => s.date_str == this_forecast_history_date.ToString("yyyy-MM-dd"));
if (temp_forecast_history == null)
{
forecast_history_sales.Add("");
}
else
{
forecast_history_sales.Add(temp_forecast_history.sales.ToString());
}
this_forecast_history_date = this_forecast_history_date.AddDays(1);
}
for (int i = 0; i < weeks.Count - 7; i++)
{
forecast_history_sales.Add("");
}
// 当日预测销量
var turnoverDateSales = (int)result[0].ToObj<List<decimal>>()[turnoverData.turnover_days + 7 - 1];
var buyFormula = new
{
turnoverDateStr = turnoverDate.ToString("yyyy-MM-dd"), // 取值日期
turnoverDateSales = turnoverDateSales, // 当日预测销量
turnoverDateStock = (int)result[4].ToObj<List<decimal>>()[turnoverData.turnover_days + 7 - 1], // 当日预测库存,
turnoverDateStock = (int)result[5].ToObj<List<decimal>>()[turnoverData.turnover_days + 7 - 1], // 当日预测库存,
turnoverDatecumulativeSales = (int)turnoverDatecumulativeSales, // 累计销量
nowStr = DateTime.Now.ToString("yyyy-MM-dd"), // 今天的日期
nowShortage = (int)result[5].ToObj<List<decimal>>()[7], // 今天的实际缺货
nowShortage = (int)result[6].ToObj<List<decimal>>()[7], // 今天的实际缺货
cumulativeShortageDate = turnoverDate.AddDays(-1).ToString("yyyy-MM-dd"),// 一直到周转期前一天的日期
cumulativeShortage = (int)result[5].ToObj<List<decimal>>()[turnoverData.turnover_days + 7 - 1], // 一直到周转期前一天的累计缺货
cumulativeShortage = (int)result[6].ToObj<List<decimal>>()[turnoverData.turnover_days + 7 - 1], // 一直到周转期前一天的累计缺货
average_overdue = Math.Max(0, turnoverData.average_overdue),
nowDateStock = (int)result[4].ToObj<List<decimal>>()[7], // 今天的预测库存
nowDateStock = (int)result[5].ToObj<List<decimal>>()[7], // 今天的预测库存
turnoverDatepurchase = turnoverDatepurchase // 累计预计到货
};
return new JsonResult(new
{
forecast_history_data = forecast_history_sales,
data = result,
weeks = weeks,
sales_day_configs = sales_day_configs,
......
......@@ -98,7 +98,16 @@ namespace ResetOutofstock
report.ResetCashFlowData();
Console.WriteLine($"结束刷新 现金流 sku 报表 ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
if (now.Hour == 21 && now.Minute == 01)
{
Console.WriteLine($"开始拷贝 周转预测值 报表 数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
dc_auto_turnover.CopyForecast();
Console.WriteLine($"结束拷贝 周转预测值 报表 ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
}
......
......@@ -29,6 +29,7 @@ namespace ResetOutofstock
//report.PurchaseWeekBackUp();
//await new TaskDownloadServices().Download();
//daily.ResetFbaExtendSales(DateTime.Now);
}
catch (Exception ex)
{
......
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