Commit 18d3b183 by 泽锋 李

动态导出销量预测模板

parent 2834ce15
......@@ -55,6 +55,7 @@ where 1=1 ";
{
sql = @"select dat.*,t2.oneday_sales,t2.forecast_oneday_sales as 'forecast_oneday_sales2',
t4.bailun_category_name,
t3.hq_type as 'warehouse_type',
( case when t5.`status`=0 or t5.`status` is null then 0 else 1 end ) as 'monitor_status',
( case when t12.`status`=0 or t12.`status` is null then 0 else 1 end ) as 'returngoodspush_state',
t4.suppliers_link,
......
......@@ -435,6 +435,7 @@ namespace AutoTurnOver.Models
public class dc_auto_turnover_list_dto
{
public string area_name { get; set; }
public string warehouse_type { get; set; }
public string head_transport_type { get; set; }
public string head_transport_logistics_code { get; set; }
/// <summary>
......
......@@ -730,11 +730,8 @@ namespace AutoTurnOver.Services
index++;
try
{
var bailun_sku = row["sku"].ToString();
var bailun_sku = row["SKU"].ToString();
var warehouse_code = row["仓库编码"].ToString();
var date_str = row["日期"].ToString();
var sales_str = row["销量"].ToString();
var action = row["操作"].ToString();
if (string.IsNullOrWhiteSpace(bailun_sku)) throw new Exception("SKU必填");
if (string.IsNullOrWhiteSpace(warehouse_code)) throw new Exception("warehouse_code必填");
......@@ -742,39 +739,60 @@ namespace AutoTurnOver.Services
if (warehouse_data == null) { throw new Exception("仓库在系统中找不到"); }
var warehouse_name = warehouse_data.warehouse_name;
if (action == "作废")
//if (action == "作废")
//{
// var count = MyMySqlConnection._connection.Execute(" delete from sales_day_config where bailun_sku_warehouse_code=@bailun_sku_warehouse_code ",new {
// bailun_sku_warehouse_code = $"{bailun_sku}{warehouse_code}"
// });
// if (count <= 0)
// {
// throw new Exception("数据不存在");
// }
//}
//else
{
var count = MyMySqlConnection._connection.Execute(" delete from sales_day_config where bailun_sku_warehouse_code=@bailun_sku_warehouse_code ",new {
bailun_sku_warehouse_code = $"{bailun_sku}{warehouse_code}"
});
if (count <= 0)
{
throw new Exception("数据不存在");
}
}
else
{
decimal sales = 0;
if (!decimal.TryParse(sales_str, out sales))
{
throw new Exception("销量格式异常");
}
DateTime date = DateTime.Now;
if (!DateTime.TryParse(date_str, out date))
{
throw new Exception("时间格式异常");
}
var new_data = new sales_day_config_input_dto
var cols = table.Columns;
foreach (DataColumn col in cols)
{
bailun_sku = bailun_sku,
warehouse_code = warehouse_code,
sales = sales,
date = date
};
if (col.ColumnName.Contains("销量") && col.ColumnName.Length>20)
{
decimal sales = 0;
var salesObj = row[col.ColumnName];
if (salesObj != null)
{
if (!decimal.TryParse(salesObj.ToString(), out sales))
{
throw new Exception("销量格式异常");
}
// 取开始结束时间
var btime = DateTime.Parse(col.ColumnName.Substring(2,10));
var etime = DateTime.Parse(col.ColumnName.Substring(13,10));
var s_sales = (sales / ((int)Math.Ceiling((etime - btime).TotalDays)));
while (btime.ToDayHome()<= etime.ToDayEnd())
{
var new_data = new sales_day_config_input_dto
{
bailun_sku = bailun_sku,
warehouse_code = warehouse_code,
sales = s_sales,
date = btime
};
DB.db_config.SaveSalesDayConfig(new_data, user);
btime = btime.AddDays(1);
}
}
}
}
DB.db_config.SaveSalesDayConfig(new_data, user);
}
......
......@@ -113,5 +113,29 @@ namespace AutoTurnOver.Utility
}
return data_set;
}
public static void ExportExcel(DataTable dt, string fileName, string sheetName = null)
{
FileInfo newFile = new FileInfo(fileName);
if (!newFile.Directory.Exists)
{
newFile.Directory.Create();
}
if (newFile.Exists)
{
newFile.Delete();
newFile = new FileInfo(fileName);
}
using (ExcelPackage pck = new ExcelPackage(newFile))
{
ExcelWorksheet worksheet = pck.Workbook.Worksheets.Add("Sheet1");
worksheet.Cells["A1"].LoadFromDataTable(dt, true);
worksheet.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;//水平居中
worksheet.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center;//垂直居中
worksheet.Cells.AutoFitColumns();
pck.Save();
}
}
}
}
......@@ -95,6 +95,70 @@ namespace AutoTurnOver.Controllers
}
/// <summary>
/// 导出销量模板
/// </summary>
/// <returns></returns>
public ActionResult ExportSalesTemplate([FromQuery] Condition_AutoTurnOver m, [FromQuery] int offset, [FromQuery] int limit, [FromQuery] string order, [FromQuery] string sort)
{
try
{
var service = new Services.SkuAutoTurnServices();
int total = 0;
var list = service.List(m, 0, int.MaxValue, ref total, "", "");
var fileName = AppContext.BaseDirectory + $@"Result\RealtimeStock\销量导入模板.xlsx";
var table = new DataTable();
table.Columns.Add("SKU");
table.Columns.Add("标题");
table.Columns.Add("仓库");
table.Columns.Add("仓库编码");
table.Columns.Add("仓库类型");
table.Columns.Add("昨日销量");
table.Columns.Add("7日日均");
table.Columns.Add("14日日均");
table.Columns.Add("30日日均");
var thisDate = DateTime.Now;
for (int i = 0; i < 8; i++)
{
var btime = thisDate.GetWeekFirstDayMon();
var etime = thisDate.AddDays(7);
table.Columns.Add($"预测{btime.ToString("yyyy-MM-dd")}~{etime.ToString("yyyy-MM-dd")}销量");
thisDate = thisDate.AddDays(7);
}
foreach (var item in list)
{
var row = table.NewRow();
row["SKU"] = item.bailun_sku;
row["标题"] = item.sku_title;
row["仓库"] = item.warehouse_name;
row["仓库编码"] = item.warehouse_code;
row["仓库类型"] = item.warehouse_type;
row["昨日销量"] = item.oneday_sales;
row["7日日均"] = item.history_sevenday_sales;
row["14日日均"] = item.history_fourteenday_sales;
row["30日日均"] = item.history_thirtyday_sales;
table.Rows.Add(row);
}
EPPlusHelper.ExportExcel(table, fileName);
var memory = new MemoryStream();
using (var stream = new FileStream(fileName, FileMode.Open))
{
stream.CopyTo(memory);
}
memory.Position = 0;
return File(memory, "text/csv", $"销量导入模板.xlsx");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "----" + ex.StackTrace);
return new ContentResult() { Content = ex.Message + "----" + ex.StackTrace };
}
}
#region 特殊销售设置
/// <summary>
......@@ -471,5 +535,7 @@ namespace AutoTurnOver.Controllers
memory.Position = 0;
return File(memory, "text/csv", "最新预计交期.csv");
}
}
}
\ No newline at end of file
......@@ -4,6 +4,11 @@ RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shang
EXPOSE 80
EXPOSE 443
# RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so
RUN apt-get update
RUN apt-get install -y --no-install-recommends libgdiplus libc6-dev
FROM microsoft/dotnet:2.1-sdk-alpine AS build
WORKDIR /src
COPY ["AutoTurnOver/AutoTurnOver.csproj", "AutoTurnOver/"]
......
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