Commit 86d19877 by 泽锋 李

新安全库存汇总

parent 98fd447a
......@@ -11,7 +11,7 @@ namespace AutoTurnOver.DB.Base
{
public static class DbHelper
{
public static Page<T> Page<T>(this MySqlConnection conn, string sql, page_search_dto search_data, object param = null, int? commandTimeout = null)
public static Page<T> Page<T>(this MySqlConnection conn, string sql, page_search_dto search_data, object param = null, int? commandTimeout = null,bool isCount = true)
{
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();//开始计时
......@@ -30,38 +30,40 @@ namespace AutoTurnOver.DB.Base
}
item_sql += $" limit {(search_data.page - 1) * search_data.rows},{search_data.rows} ";
result_data.Items = (connectionHelper._connection.Query<T>(item_sql, param, commandTimeout: commandTimeout)).AsList();
var original_sql = sql;
while (true)
result_data.CurrentPage = search_data.page;
if (isCount)
{
Match match = Regex.Match(sql, @"select[\s\S]+from");
if (match.Success)
var original_sql = sql;
while (true)
{
if (match.Groups.Count > 1)
Match match = Regex.Match(sql, @"select[\s\S]+from");
if (match.Success)
{
throw new Exception(" 分页语句解析异常 ");
}
if (match.Groups.Count > 1)
{
throw new Exception(" 分页语句解析异常 ");
}
if (SubstringCount(match.Groups[0].Value, "from") > 1)
{
int remove_Index = match.Groups[0].Value.LastIndexOf("from");
sql = match.Groups[0].Value.Remove(remove_Index);
if (SubstringCount(match.Groups[0].Value, "from") > 1)
{
int remove_Index = match.Groups[0].Value.LastIndexOf("from");
sql = match.Groups[0].Value.Remove(remove_Index);
}
else
{
sql = original_sql.Replace(match.Groups[0].Value, " select count(1) from ");
break;
}
}
else
{
sql = original_sql.Replace(match.Groups[0].Value, " select count(1) from ");
break;
throw new Exception(" 分页语句解析异常 ");
}
}
else
{
throw new Exception(" 分页语句解析异常 ");
}
result_data.TotalItems = connectionHelper._connection.QueryFirstOrDefault<int?>(sql, param, commandTimeout: commandTimeout) ?? 0;
result_data.TotalPages = (int)Math.Ceiling(result_data.TotalItems * 1.0 / search_data.rows);
}
result_data.TotalItems = connectionHelper._connection.QueryFirstOrDefault<int?>(sql, param, commandTimeout: commandTimeout) ?? 0;
result_data.CurrentPage = search_data.page;
result_data.TotalPages = (int)Math.Ceiling(result_data.TotalItems * 1.0 / search_data.rows);
watch.Stop();
result_data.CostTime = watch.ElapsedMilliseconds;
return result_data;
......
......@@ -327,7 +327,8 @@ t8.oneday_sales,
t3.`status` as 'sku_status',
t3.length as 'pack_length',
t3.width as 'pack_width',
t3.height as 'pack_height'
t3.height as 'pack_height',
LEAST(ifnull(t6.quantity_safe_inventory,0),t1.usable_stock) as 'real_quantity_safe_inventory'
from
dc_base_stock as t1
left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku
......
......@@ -5,6 +5,8 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using AutoTurnOver.Models.Base;
using AutoTurnOver.DB.Base;
namespace AutoTurnOver.DB
{
......@@ -2239,5 +2241,63 @@ where t2.buyer_name = '赵美聪'
{
return _connection.Query<platform_type_website_dto>("select platform_type,website from dc_base_oms_sku_7 group by platform_type,website").AsList();
}
/// <summary>
/// 安全库存
/// </summary>
/// <param name="search"></param>
/// <returns></returns>
public static Page<quantity_safe_inventory_dto> GetInventoryStock(quantity_safe_inventory_search_dto search_data)
{
string sql = $@" select t3.hq_type,t3.warehouse_name, t2.warehouse_code,sum( LEAST(ifnull(t1.quantity_safe_inventory,0),t2.usable_stock)) as 'real_quantity_safe_inventory',
sum(t2.usable_stock) as 'usable_stock',
count(t1.bailun_sku) as 'sku_count',
sum(ifnull(t1.quantity_safe_inventory, 0)) as 'quantity_safe_inventory',
sum(LEAST(ifnull(t1.quantity_safe_inventory, 0), t2.usable_stock) * ifnull(t4.unit_price, 0)) as 'real_quantity_safe_inventory_amount'
from dc_base_stock as t2
left join dc_auto_turnover as t1 on t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
left join dc_base_warehouse as t3 on t2.warehouse_code = t3.warehouse_code
left join dc_base_sku as t4 on t2.bailun_sku = t4.bailun_sku
where 1=1
";
string sqlCount = $@" select count(DISTINCT t2.warehouse_code) from dc_base_stock as t2 left join dc_base_warehouse as t3 on t2.warehouse_code = t3.warehouse_code where 1=1 ";
DynamicParameters parameters = new DynamicParameters();
if (search_data != null)
{
if (!string.IsNullOrWhiteSpace(search_data.warehouse_code))
{
sql += " and t2.warehouse_code=@warehouse_code ";
sqlCount += " and t2.warehouse_code=@warehouse_code ";
parameters.Add("warehouse_code", search_data.warehouse_code);
}
else
{
if (search_data.warehousearea > 0)
{
sql += " and t3.area_id = @area_id ";
sqlCount += " and t3.area_id = @area_id ";
parameters.Add("area_id", search_data.warehousearea);
}
if (!string.IsNullOrWhiteSpace(search_data.warehousetype))
{
sql += " and t3.hq_type = @hq_type ";
sqlCount += " and t3.hq_type = @hq_type ";
parameters.Add("hq_type", search_data.warehousetype);
}
}
}
if (!search_data.is_sum)
{
sql += " GROUP BY t1.warehouse_code ";
}
var pageDatas = _connection.Page<quantity_safe_inventory_dto>(sql, search_data, parameters,isCount:false);
if (!search_data.is_sum)
{
pageDatas.TotalItems = connectionHelper._connection.QueryFirstOrDefault<int?>(sqlCount, parameters) ?? 0;
pageDatas.TotalPages = (int)Math.Ceiling(pageDatas.TotalItems * 1.0 / search_data.rows);
}
return pageDatas;
}
}
}
......
......@@ -165,6 +165,10 @@ namespace AutoTurnOver.Models
public class dc_base_stock_dto : dc_base_stock
{
/// <summary>
/// 安全库存
/// </summary>
public decimal real_quantity_safe_inventory { get; set; }
public decimal pack_length { get; set; }
public decimal pack_width { get; set; }
public decimal pack_height { get; set; }
......
using AutoTurnOver.Models.Base;
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
/// <summary>
/// 安全库存
/// </summary>
public class quantity_safe_inventory_dto
{
public string hq_type { get; set; }
public string warehouse_name { get; set; }
public int sku_count { get; set; }
public string warehouse_code { get; set; }
public decimal real_quantity_safe_inventory { get; set; }
public decimal real_quantity_safe_inventory_val { get {
return Math.Round(real_quantity_safe_inventory, 2);
} }
public decimal usable_stock { get; set; }
public decimal usable_stock_val
{
get
{
return Math.Round(usable_stock, 2);
}
}
public decimal quantity_safe_inventory { get; set; }
public decimal quantity_safe_inventory_val
{
get
{
return Math.Round(quantity_safe_inventory, 2);
}
}
public decimal real_quantity_safe_inventory_amount { get; set; }
public string real_quantity_safe_inventory_amount_val
{
get
{
return Math.Round(real_quantity_safe_inventory_amount, 2).ToString("C");
}
}
}
public class quantity_safe_inventory_search_dto: page_search_dto
{
public string warehousetype { get; set; }
public int? warehousearea { get; set; }
public string warehouse_code { get; set; }
public bool is_sum { get; set; }
}
}
......@@ -164,7 +164,7 @@ namespace AutoTurnOver.Services
,"待上架","可配库存","可配库存金额","销售可用库存(聚合)","销售可用库存(私有)","销售可用库存(共享)","在仓库存(共享)","在仓库存(私有)","在仓库存(聚合)","仓库占用(共享)"
,"仓库占用(私有)","仓库占用(聚合)","活动占用","单占用(私有)","订单占用(共享)","订单占用(聚合)","环球更新时间","供应商","采购员","重量","单价","已发货库存","实时缺货","是否侵权",
"过去7日日均销量", "过去14日日均销量", "过去30日日均销量", "过去7日Eaby日均销量", "过去14日Eaby日均销量", "过去30日Eaby日均销量", "过去7日速卖通日均销量", "过去14日速卖通日均销量", "过去30日速卖通日均销量",
"监控状态","开发时间","昨日销量","停售状态","amazon最近7天日均销量","amazon最近14天日均销量","amazon最近30天日均销量","moq","品牌","标签","类型","产品尺寸","包装尺寸"
"监控状态","开发时间","昨日销量","停售状态","amazon最近7天日均销量","amazon最近14天日均销量","amazon最近30天日均销量","moq","品牌","标签","类型","产品尺寸","包装尺寸","安全库存"
};
foreach (var item in cols)
{
......@@ -243,7 +243,9 @@ namespace AutoTurnOver.Services
row["标签"] = itemData.tags;
row["类型"] = itemData.product_type_desc;
row["产品尺寸"] = itemData.product_size;
row["包装尺寸"] = $"{itemData.pack_length}-{itemData.pack_width}-{itemData.pack_height}";
row["安全库存"] = itemData.real_quantity_safe_inventory;
table.Rows.Add(row);
}
......
......@@ -11,6 +11,7 @@ using AutoTurnOver.Models.ApiDto;
using System.Dynamic;
using System.IO;
using System.Threading.Tasks;
using AutoTurnOver.Models.Base;
namespace AutoTurnOver.Services
{
......@@ -760,5 +761,15 @@ namespace AutoTurnOver.Services
}
/// <summary>
/// 安全报表
/// </summary>
/// <param name="search"></param>
/// <returns></returns>
public Page<quantity_safe_inventory_dto> GetInventoryStock(quantity_safe_inventory_search_dto search)
{
return report.GetInventoryStock(search);
}
}
}
......@@ -757,5 +757,66 @@ namespace AutoTurnOver.Controllers
return new JsonResult(list == null || list.Count <= 0 ? new supplier_sales_dto() : list[0]);
}
/// <summary>
/// 安全库存
/// </summary>
/// <param name="supplier_name"></param>
/// <param name="offset"></param>
/// <param name="limit"></param>
/// <param name="order"></param>
/// <param name="sort"></param>
/// <returns></returns>
public JsonResult GetInventoryStock(string warehousetype, int offset, int limit, string order, string sort,int? warehousearea,string warehouse_code)
{
try
{
var m = new quantity_safe_inventory_search_dto
{
warehousetype = warehousetype,
warehousearea = warehousearea,
warehouse_code = warehouse_code,
page = (offset/ limit) + 1,
rows = limit,
sidx = sort,
sord = order,
is_sum = false
};
var services = new ReportServices();
var page_data = services.GetInventoryStock(m);
return new JsonResult(new
{
rows = page_data.Items,
total = page_data.TotalItems
});
}
catch (Exception ex)
{
return new JsonResult(new
{
message = ex.Message,
stack_trace = ex.StackTrace
});
}
}
public JsonResult GetInventoryStockSumFooter(string warehousetype, int offset, int limit, string order, string sort, int? warehousearea, string warehouse_code)
{
var m = new quantity_safe_inventory_search_dto
{
warehousetype = warehousetype,
warehousearea = warehousearea,
warehouse_code = warehouse_code,
page = 1,
rows = 1,
sidx = sort,
sord = order,
is_sum = true
};
var services = new ReportServices();
var list = services.GetInventoryStock(m);
return new JsonResult(list == null || list.Items.Count <= 0 ? new quantity_safe_inventory_dto() : list.Items[0]);
}
}
}
\ No newline at end of file
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