Commit ed64507e by 泽锋 李

新增年度销量增长趋势计算

parent 0a708dd8
...@@ -3779,5 +3779,75 @@ where t1.usable_stock>0 ...@@ -3779,5 +3779,75 @@ where t1.usable_stock>0
group by warehouse_code group by warehouse_code
)",new { record_time = DateTime.Now.AddDays(-1)}); )",new { record_time = DateTime.Now.AddDays(-1)});
} }
/// <summary>
/// 计算年度销量增长趋势
/// </summary>
public static void CalculationSalesTrend()
{
var btime = DateTime.Now.AddYears(-1).ToString("yyyy-01-01 00:00:00");
var datas = _connection.Query<dc_report_sales_trend_year>(@"
select
ifnull(t2.product_type,-1) as 'product_type',
ifnull(t2.product_type_desc,'未知') as 'product_type_desc',
sum(t1.bailun_sku_quantity_ordered) as 'sales',
t1.receipt_country as 'country_code',
date_format(paid_time, '%Y-%m') as 'date_str',
paid_time as 'date',
1 as 'year_growth_rate',
now() as 'create_date',
now() as 'update_date'
from dc_base_oms_sku as t1
left join dc_base_sku as t2 on t1.bailun_sku =t2.bailun_sku
where t1.bailun_order_status != 'Canceled'
and t1.has_delete = 0
and t1.has_scalp = 0
and t1.has_buyer_remark = 0
and t1.has_platsku_remark = 0
and t1.paid_time>='2019-01-01' and t1.paid_time<'2020-01-01'
GROUP BY t2.product_type,t2.product_type_desc,t1.receipt_country,date_format(paid_time, '%Y-%m')
", new { btime },commandTimeout:0).ToList();
foreach (var item in datas)
{
var oldData = _connection.QuerySingleOrDefault<dc_report_sales_trend_year>(" select * from dc_report_sales_trend_year where date_str=@date_str and product_type_desc=@product_type_desc and country_code=@country_code ",new {
country_code = item.country_code,
product_type_desc = item.product_type_desc,
date_str = item.date_str
});
if (oldData != null)
{
item.year_growth_rate = oldData.year_growth_rate;
item.id = oldData.id;
}
var lastMonthDateStr = item.date.AddMonths(-1).ToString("yyyy-MM");
var lastMonthData = datas.FirstOrDefault(s => s.country_code == item.country_code && s.product_type_desc == item.product_type_desc && s.date_str == lastMonthDateStr);
if (lastMonthData != null && lastMonthData.sales > 0)
{
item.month_growth_rate = item.sales / lastMonthData.sales;
}
else
{
item.month_growth_rate = 1;
}
if (item.id > 0)
{
_connection.Update(item);
}
else
{
_connection.Insert(item);
}
}
}
public class product_type_desc_dto
{
public string product_type_desc { get; set; }
public int product_type { get; set; }
}
} }
} }
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.Report
{
public class dc_report_sales_trend_year
{
public int id { get; set; }
public string product_type { get; set; }
public string product_type_desc { get; set; }
public string date_str { get; set; }
public DateTime date { get; set; }
public string country_code { get; set; }
/// <summary>
/// 销量汇总
/// </summary>
public decimal sales { get; set; }
/// <summary>
/// 与上月相比的增长率
/// </summary>
public decimal month_growth_rate { get; set; }
/// <summary>
/// 次年年度增长率
/// </summary>
public decimal year_growth_rate { get; set; }
public DateTime create_date { get; set; }
public DateTime update_date { get; set; }
}
}
...@@ -23,6 +23,7 @@ namespace ResetOutofstock ...@@ -23,6 +23,7 @@ namespace ResetOutofstock
//base_supplier_holiday_time_dao.SynchroData(); //base_supplier_holiday_time_dao.SynchroData();
//report.ResetCashFlowData(); //report.ResetCashFlowData();
//report.StockWeekBackUp(); //report.StockWeekBackUp();
//report.CalculationSalesTrend();
//report.PurchaseWeekBackUp(); //report.PurchaseWeekBackUp();
//report_cash_flow_dao.CalculationTransferOrder(now.AddMonths(-3), DateTime.Parse(now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59"))); //report_cash_flow_dao.CalculationTransferOrder(now.AddMonths(-3), DateTime.Parse(now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
//report_cash_flow_dao.SynchroTransferCost(); //report_cash_flow_dao.SynchroTransferCost();
......
...@@ -15,12 +15,12 @@ namespace ResetOutofstock ...@@ -15,12 +15,12 @@ namespace ResetOutofstock
protected override Task ExecuteAsync(CancellationToken stoppingToken) protected override Task ExecuteAsync(CancellationToken stoppingToken)
{ {
//Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
//{ {
// Console.WriteLine($"开始 刷新财务付现数据 ,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); Console.WriteLine($"开始 初始化年度销量增长趋势 ,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
// dc_report_finance_dao.CalculationCashPayment(DateTime.Now.AddYears(-1)); report.CalculationSalesTrend();
// Console.WriteLine($"结束 刷新财务付现数据,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); Console.WriteLine($"结束 初始化年度销量增长趋势,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
//}); });
//Task.Factory.StartNew(() => //Task.Factory.StartNew(() =>
//{ //{
// Console.WriteLine($"开始 刷新出库退税数据 ,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); // Console.WriteLine($"开始 刷新出库退税数据 ,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
......
...@@ -22,7 +22,13 @@ namespace ResetOutofstock ...@@ -22,7 +22,13 @@ namespace ResetOutofstock
{ {
var now = DateTime.Now; var now = DateTime.Now;
if (now.Hour == 0 && now.Minute == 01) if (now.Month==1 && now.Day==1 && now.Hour == 0 && now.Minute == 01)
{
Console.WriteLine($"开始 刷新年度增长趋势,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
report.CalculationSalesTrend();
Console.WriteLine($"结束 刷新年度增长趋势,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
if (now.Hour == 0 && now.Minute == 02)
{ {
Console.WriteLine($"开始 备份库存,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); Console.WriteLine($"开始 备份库存,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
report.ResetDailyStockWarehouse(); report.ResetDailyStockWarehouse();
......
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