Commit c402fcc9 by guanzhenshan

1、完成动态库存分析

2、完成逻辑仓趋势图
parent 0a37b6b9
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.LogicWareHouse.Models
{
public class mCash
{
//t2.bailun_sku,t2.warehouse_code,t2.pay_amount_30,t2.income_amount_30
public string bailun_sku { get; set; }
public string warehouse_code { get; set; }
public decimal? pay_amount_30 { get; set; }
public decimal? income_amount_30 { get; set; }
}
}
......@@ -7,22 +7,23 @@ namespace Bailun.DC.LogicWareHouse
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("进入 每日同步SKU仓库库存+销量统计信息");
new Services().Save();
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Services>();
});
await builder.RunConsoleAsync();
}
//static void Main(string[] args)
//static async Task Main(string[] args)
//{
// //new Services().Save();
// new Services().SaleWHDailySnaps();
// Console.WriteLine("进入 每日同步SKU仓库库存+销量统计信息");
// new Services().Save();
// var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
// {
// services.AddHostedService<Services>();
// });
// await builder.RunConsoleAsync();
//}
static void Main(string[] args)
{
//new Services().Save();
//new Services().SaleWHDailySnaps();
new Services().UpdateSemiSale();
}
}
}
......@@ -270,6 +270,22 @@ namespace Bailun.DC.LogicWareHouse
}
var sql = @"update dc_skuwarehouse_stock_sales t1
join dc_semi_stock_sales_shipping t2 on t2.warehouse_name=t1.warehouse_name and t1.bailun_sku=t2.sku
set t1.quantity_purchase=t2.on_the_way_count,t1.purchase_amount=t2.on_the_way_amount,t1.oneday_total_sales=t2.sales_1,t1.amount_onedaysale=t2.stock_amount_1,t1.sevenday_total_sales=t2.sales_7,t1.fourteenday_total_sales=t2.sales_14,t1.thirtyday_total_sales=t2.sales_30,t1.nostockcount=t2.out_of_stock,t1.noshippingcount=t2.need_quantity,t1.quantity_tuneout_30days=t2.out_stock_30,t1.quantity_tunein_30days=t2.put_stock_30;";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var result = cn.Execute(sql);
Console.WriteLine("更新逻辑仓库半成品销量成功,受影响行数:" + result);
}
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 结束同步半成品销量任务");
}
......@@ -303,7 +319,7 @@ namespace Bailun.DC.LogicWareHouse
{
Console.WriteLine("开始执行更新现金流方法 "+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString + "Allow User Variables=True;"))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
......@@ -312,13 +328,20 @@ namespace Bailun.DC.LogicWareHouse
cn.Execute("update dc_skuwarehouse_stock_sales set cash_in_30days=0,cash_out_30days=0,cash_net = 0");
var sql = @"update dc_skuwarehouse_stock_sales t1
join dc_base_stock t2 on (t2.pay_amount_30>0 or t2.income_amount_30>0) and t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code
set t1.cash_in_30days=t2.income_amount_30,t1.cash_out_30days=t2.pay_amount_30,t1.cash_net = t2.income_amount_30-t2.pay_amount_30";
var list = cn.Query<mCash>("select t2.bailun_sku,t2.warehouse_code,t2.pay_amount_30,t2.income_amount_30 from dc_base_stock t2 where (t2.pay_amount_30>0 or t2.income_amount_30>0)");
foreach(var item in list)
{
cn.Execute("update dc_skuwarehouse_stock_sales set cash_in_30days=" + item.income_amount_30 + ",cash_out_30days=" + item.pay_amount_30 + ",cash_net=" + (item.income_amount_30 - item.pay_amount_30) + " where bailun_sku='" + item.bailun_sku + "' and warehouse_code='" + item.warehouse_code + "'");
Console.WriteLine(item.bailun_sku + "&" + item.warehouse_code);
}
var result = cn.Execute(sql);
//var sql = @"update dc_skuwarehouse_stock_sales t1
// join dc_base_stock t2 on (t2.pay_amount_30>0 or t2.income_amount_30>0) and t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code
// set t1.cash_in_30days=t2.income_amount_30,t1.cash_out_30days=t2.pay_amount_30,t1.cash_net = t2.income_amount_30-t2.pay_amount_30";
Console.WriteLine("更新30天现金流的记录数有:" + result);
//var result = cn.Execute(sql);
Console.WriteLine("更新30天现金流的记录数有:" + list.Count());
}
Console.WriteLine(" 更新现金流方法 已完成 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
......@@ -335,7 +358,7 @@ namespace Bailun.DC.LogicWareHouse
var list = new List<mLogicWarehouse>();
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString + "Allow User Variables=True;"))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models.Warehouse
{
public class dc_mid_logic_wh_statistic
{
public int id { get; set; }
public string warehouse_code { get; set; }
public string warehouse_name { get; set; }
public int days { get; set; }
public string hq_type { get; set; }
public string usable_stock { get; set; }
public string amount_stock { get; set; }
public string quantity_purchase { get; set; }
public string purchase_amount { get; set; }
public string quantity_transfer { get; set; }
public string amount_transit { get; set; }
public string oneday_total_sales { get; set; }
public string amount_onedaysale { get; set; }
public string sevenday_total_sales { get; set; }
public string fourteenday_total_sales { get; set; }
public string thirtyday_total_sales { get; set; }
public string quantity_tuneout_onway { get; set; }
public string quantity_tuneout_30days { get; set; }
public string quantity_tunein_30days { get; set; }
public string nostockcount { get; set; }
public string noshippingcount { get; set; }
public DateTime lastupdatetime { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models.Warehouse
{
public class mDynamicStockAnalyse
{
public string warehouse_code { get; set; }
public int less15days_skucount { get; set; }
public int less15days { get; set; }
public decimal less15days_amount { get; set; }
public int fifteen_30_days_skucount { get; set; }
public int fifteen_30_days { get; set; }
public decimal fifteen_30_days_amount { get; set; }
public int thirty_45_days_skucount { get; set; }
public int thirty_45_days { get; set; }
public decimal thirty_45_days_amount { get; set; }
public int fortyfive_60_days_skucount { get; set; }
public int fortyfive_60_days { get; set; }
public decimal fortyfive_60_days_amount { get; set; }
public int sixty_90_days_skucount { get; set; }
public int sixty_90_days { get; set; }
public decimal sixty_90_days_amount { get; set; }
public int ninty_120_days_skucount { get; set; }
public int ninty_120_days { get; set; }
public decimal ninty_120_days_amount { get; set; }
public int onetwozero_180_days_skucount { get; set; }
public int onetwozero_180_days { get; set; }
public decimal onetwozero_180_days_amount { get; set; }
public int morethen_180_days_skucount { get; set; }
public int morethen_180_days { get; set; }
public decimal morethen_180_days_amount { get; set; }
}
}
......@@ -1105,6 +1105,116 @@ namespace Bailun.DC.Services
}
}
/// <summary>
/// 获取逻辑仓的每日数据,用于显示趋势图
/// </summary>
/// <param name="warehouse_code"></param>
/// <param name="columnname"></param>
/// <returns></returns>
public string GetMidLogicWarehouseStatistic(string warehouse_code, string columnname)
{
var sql = "select "+columnname+ " from dc_mid_logic_wh_statistic where warehouse_code='"+warehouse_code+"'";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
return cn.QueryFirstOrDefault<string>(sql);
}
}
#region 动态库存分析
public List<mDynamicStockAnalyse> ListDynamicStockAnalyse(string warehouse_code, int isfinish)
{
var sql = "";
if (isfinish == 1) //成品
{
sql = $@"select t1.warehouse_code,
sum(case when t1.available_days<15 then 1 else 0 end) as less15days_skucount,
sum(case when t1.available_days<15 then t1.usable_stock+t1.occupy_stock else 0 end) as less15days,
sum(case when t1.available_days<15 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as less15days_amount,
sum(case when t1.available_days>=15 and t1.available_days<30 then 1 else 0 end) as fifteen_30_days_skucount,
sum(case when t1.available_days>=15 and t1.available_days<30 then t1.usable_stock+t1.occupy_stock else 0 end) as fifteen_30_days,
sum(case when t1.available_days>=15 and t1.available_days<30 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as fifteen_30_days_amount,
sum(case when t1.available_days>=30 and t1.available_days<45 then 1 else 0 end) as thirty_45_days_skucount,
sum(case when t1.available_days>=30 and t1.available_days<45 then t1.usable_stock+t1.occupy_stock else 0 end) as thirty_45_days,
sum(case when t1.available_days>=30 and t1.available_days<45 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as thirty_45_days_amount,
sum(case when t1.available_days>=45 and t1.available_days<60 then 1 else 0 end) as fortyfive_60_days_skucount,
sum(case when t1.available_days>=45 and t1.available_days<60 then t1.usable_stock+t1.occupy_stock else 0 end) as fortyfive_60_days,
sum(case when t1.available_days>=45 and t1.available_days<60 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as fortyfive_60_days_amount,
sum(case when t1.available_days>=60 and t1.available_days<90 then 1 else 0 end) as sixty_90_days_skucount,
sum(case when t1.available_days>=60 and t1.available_days<90 then t1.usable_stock+t1.occupy_stock else 0 end) as sixty_90_days,
sum(case when t1.available_days>=60 and t1.available_days<90 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as sixty_90_days_amount,
sum(case when t1.available_days>=90 and t1.available_days<120 then 1 else 0 end) as ninty_120_days_skucount,
sum(case when t1.available_days>=90 and t1.available_days<120 then t1.usable_stock+t1.occupy_stock else 0 end) as ninty_120_days,
sum(case when t1.available_days>=90 and t1.available_days<120 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as ninty_120_days_amount,
sum(case when t1.available_days>=120 and t1.available_days<180 then 1 else 0 end) as onetwozero_180_days_skucount,
sum(case when t1.available_days>=120 and t1.available_days<180 then t1.usable_stock+t1.occupy_stock else 0 end) as onetwozero_180_days,
sum(case when t1.available_days>=120 and t1.available_days<180 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as onetwozero_180_days_amount,
sum(case when t1.available_days>=180 then 1 else 0 end) as morethen_180_days_skucount,
sum(case when t1.available_days>=180 then t1.usable_stock+t1.occupy_stock else 0 end) as morethen_180_days,
sum(case when t1.available_days>=180 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as morethen_180_days_amount
from dc_base_stock t1 left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
where t1.available_days>0 and t1.warehouse_code='{warehouse_code}'
group by t1.warehouse_code";
}
else if(isfinish==0) //半成品
{
sql = $@"select t1.warehouse_id as warehouse_code,
sum(case when t1.available_days<15 then 1 else 0 end) as less15days_skucount,
sum(case when t1.available_days<15 then t1.stock else 0 end) as less15days,
sum(case when t1.available_days<15 then (t1.stock)*t1.buyer_price else 0 end) as less15days_amount,
sum(case when t1.available_days>=15 and t1.available_days<30 then 1 else 0 end) as fifteen_30_days_skucount,
sum(case when t1.available_days>=15 and t1.available_days<30 then t1.stock else 0 end) as fifteen_30_days,
sum(case when t1.available_days>=15 and t1.available_days<30 then (t1.stock)*t1.buyer_price else 0 end) as fifteen_30_days_amount,
sum(case when t1.available_days>=30 and t1.available_days<45 then 1 else 0 end) as thirty_45_days_skucount,
sum(case when t1.available_days>=30 and t1.available_days<45 then t1.stock else 0 end) as thirty_45_days,
sum(case when t1.available_days>=30 and t1.available_days<45 then (t1.stock)*t1.buyer_price else 0 end) as thirty_45_days_amount,
sum(case when t1.available_days>=45 and t1.available_days<60 then 1 else 0 end) as fortyfive_60_days_skucount,
sum(case when t1.available_days>=45 and t1.available_days<60 then t1.stock else 0 end) as fortyfive_60_days,
sum(case when t1.available_days>=45 and t1.available_days<60 then (t1.stock)*t1.buyer_price else 0 end) as fortyfive_60_days_amount,
sum(case when t1.available_days>=60 and t1.available_days<90 then 1 else 0 end) as sixty_90_days_skucount,
sum(case when t1.available_days>=60 and t1.available_days<90 then t1.stock else 0 end) as sixty_90_days,
sum(case when t1.available_days>=60 and t1.available_days<90 then (t1.stock)*t1.buyer_price else 0 end) as sixty_90_days_amount,
sum(case when t1.available_days>=90 and t1.available_days<120 then 1 else 0 end) as ninty_120_days_skucount,
sum(case when t1.available_days>=90 and t1.available_days<120 then t1.stock else 0 end) as ninty_120_days,
sum(case when t1.available_days>=90 and t1.available_days<120 then (t1.stock)*t1.buyer_price else 0 end) as ninty_120_days_amount,
sum(case when t1.available_days>=120 and t1.available_days<180 then 1 else 0 end) as onetwozero_180_days_skucount,
sum(case when t1.available_days>=120 and t1.available_days<180 then t1.stock else 0 end) as onetwozero_180_days,
sum(case when t1.available_days>=120 and t1.available_days<180 then (t1.stock)*t1.buyer_price else 0 end) as onetwozero_180_days_amount,
sum(case when t1.available_days>=180 then 1 else 0 end) as morethen_180_days_skucount,
sum(case when t1.available_days>=180 then t1.stock else 0 end) as morethen_180_days,
sum(case when t1.available_days>=180 then (t1.stock)*t1.buyer_price else 0 end) as morethen_180_days_amount
from dc_semi_stock_sales_shipping t1
where t1.available_days>0 and t1.warehouse_id={warehouse_code}
group by t1.warehouse_id";
}
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var list = cn.Query<mDynamicStockAnalyse>(sql).ToList();
return list;
}
}
#endregion
#region Api
......
......@@ -1507,6 +1507,115 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
return Json(list);
}
/// <summary>
/// 动态库存分析
/// </summary>
/// <param name="warehouse_code"></param>
/// <returns></returns>
public ActionResult DynamicStockAnalyse(string warehouse_code,string warehouse_name)
{
ViewBag.warehouse_code = warehouse_code;
ViewBag.warehouse_name = warehouse_name;
return View();
}
/// <summary>
/// 动态库存分析Json
/// </summary>
/// <param name="warehouse_code">仓库编码</param>
/// <returns></returns>
[HttpPost]
public JsonResult DynamicStockAnalyseJson(string warehouse_code)
{
//区分半成品仓和成品仓
int code = 0;
int.TryParse(warehouse_code, out code);
var obj = new Models.Warehouse.mDynamicStockAnalyse();
var _service = new Services.WareHouseServices();
if (code > 0) //半成品仓
{
obj = _service.ListDynamicStockAnalyse(warehouse_code, 0).FirstOrDefault();
}
else
{
//成品仓
obj = _service.ListDynamicStockAnalyse(warehouse_code, 1).FirstOrDefault();
}
//组装数据并输出
var list = new List<Tuple<string, string, string, string>>();
if (obj != null)
{
list.Add(new Tuple<string, string, string, string>("可销售天数少于15天", obj.less15days_skucount.ToString("N0"), obj.less15days.ToString("N0"), obj.less15days_amount.ToString("N2")));
list.Add(new Tuple<string, string, string, string>("可销售天数15-30天", obj.fifteen_30_days_skucount.ToString("N0"), obj.fifteen_30_days.ToString("N0"), obj.fifteen_30_days_amount.ToString("N2")));
list.Add(new Tuple<string, string, string, string>("可销售天数30-45天", obj.thirty_45_days_skucount.ToString("N0"), obj.thirty_45_days.ToString("N0"), obj.thirty_45_days_amount.ToString("N2")));
list.Add(new Tuple<string, string, string, string>("可销售天数45-60天", obj.fortyfive_60_days_skucount.ToString("N0"), obj.fortyfive_60_days.ToString("N0"), obj.fortyfive_60_days_amount.ToString("N2")));
list.Add(new Tuple<string, string, string, string>("可销售天数60-90天", obj.sixty_90_days_skucount.ToString("N0"), obj.sixty_90_days.ToString("N0"), obj.sixty_90_days_amount.ToString("N2")));
list.Add(new Tuple<string, string, string, string>("可销售天数90-120天", obj.ninty_120_days_skucount.ToString("N0"), obj.ninty_120_days.ToString("N0"), obj.ninty_120_days_amount.ToString("N2")));
list.Add(new Tuple<string, string, string, string>("可销售天数120-180天", obj.onetwozero_180_days_skucount.ToString("N0"), obj.onetwozero_180_days.ToString("N0"), obj.onetwozero_180_days_amount.ToString("N2")));
list.Add(new Tuple<string, string, string, string>("可销售天数180天以上", obj.morethen_180_days_skucount.ToString("N0"), obj.morethen_180_days.ToString("N0"), obj.morethen_180_days_amount.ToString("N2")));
}
return Json(new
{
success = true,
msg = "",
data = list
});
}
/// <summary>
/// 逻辑仓仓库的字段趋势图
/// </summary>
/// <param name="warehouse_code"></param>
/// <param name="key"></param>
/// <returns></returns>
public ActionResult WarehouseTrendChart(string warehouse_code,string key,string titlename)
{
ViewBag.warehouse_code = warehouse_code;
ViewBag.key = key;
ViewBag.titlename = titlename;
return View();
}
/// <summary>
/// 逻辑仓仓库的字段趋势图
/// </summary>
/// <param name="warehouse_code"></param>
/// <param name="key"></param>
/// <returns></returns>
[HttpPost]
public JsonResult WarehouseTrendChartJson(string warehouse_code,string key)
{
var obj = new Services.WareHouseServices().GetMidLogicWarehouseStatistic(warehouse_code, key);
var listval = new List<string>();
var listdate = new List<string>();
if (!string.IsNullOrEmpty(obj))
{
listval = obj.Split(',').ToList();
for(var i=1;i< listval.Count+1;i++)
{
listdate.Insert(0,DateTime.Now.AddDays(-i).ToString("yyyy-MM-dd"));
}
}
return Json(new {
success = true,
msg = "",
val = listval,
dates = listdate,
});
}
}
class SkuCategory_Col
......

@{
ViewData["Title"] = "动态库存分析";
Layout = "~/Pages/Shared/_MainLayout.cshtml";
ViewBag.Nav = new string[] { "逻辑仓库", "动态库存分析" };
}
<div class="row">
<div class="col-sm-12">
<div class="ibox-content m-b-sm border-bottom" style="display:none;">
<form id="toolbar">
<div class="form-inline" style="line-height:40px;">
<div class="form-group">
<label>平台类型:</label>
<select id="platform" name="platform" class="form-control">
<option value="">选择平台</option>
</select>
</div>
<div class="form-group">
<label>&nbsp;</label>
<button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
</div>
</div>
</form>
</div>
<div class="ibox-content m-b-sm border-bottom">
<table id="roletable" class="table table-hover table-bordered table-condensed table-striped">
<thead>
<tr>
<th></th>
<th>SKU数</th>
<th>库存件数</th>
<th>库存金额</th>
</tr>
</thead>
<tbody id="tb"></tbody>
</table>
</div>
</div>
</div>
@section scripts{
<script>
$(document).ready(function () {
list();
})
function list() {
$.submit({
type:'POST',
url: '@Url.Content("~/Reports/Warehouse/DynamicStockAnalyseJson")',
paramData: 'warehouse_code=@(ViewBag.warehouse_code)',
func: function (result) {
if (result.success) {
$('#tb').html('');
for (var i in result.data) {
var s = '<tr>';
s += '<td>' + result.data[i].item1 + '</td>';
s += '<td>' + result.data[i].item2 + '</td>';
s += '<td>' + result.data[i].item3 + '</td>';
s += '<td>' + result.data[i].item4 + '</td>';
$('#tb').append(s);
}
}
}
})
}
</script>
}

@{
ViewData["Title"] = "仓库数据趋势图";
Layout = "~/Pages/Shared/_MainLayout.cshtml";
ViewBag.Nav = new string[] { "逻辑仓库", "仓库数据趋势图" };
}
<div class="row">
<div class="col-sm-12">
@*<div class="ibox-content m-b-sm border-bottom">
</div>*@
<div class="ibox-content m-b-sm border-bottom">
<div id="echart-contain" style="width:100%;height:480px;">
</div>
</div>
</div>
</div>
@section scripts{
<script src="~/js/echarts.min.js"></script>
<script type="text/javascript">
var titlename = '@ViewBag.titlename';
$(document).ready(function () {
list();
})
function list() {
$.submit({
type:'POST',
url: '@Url.Content("~/Reports/Warehouse/WarehouseTrendChartJson")',
paramData: 'warehouse_code=@(ViewBag.warehouse_code)&key=@(ViewBag.key)',
func: function (result) {
if (result.success) {
var arrval = new Array();
var arrname = new Array();
for (var i = 0; i < result.val.length;i++)
{
arrval.push(result.val[i]);
arrname.push(result.dates[i]);
}
showchart(arrval, arrname);
}
else {
alert(result.msg);
}
}
})
}
function showchart(arrval, arrname) {
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('echart-contain'));
option = {
title: {
text: '趋势图'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: [titlename]
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: arrname
},
yAxis: {
type: 'value'
},
series: [
{
name: titlename,
type: 'line',
stack: '总量',
data: arrval
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
}
</script>
}
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