Commit b00acaba by guanzhenshan

完成每日发生额统计的计算服务

parent ac91917e
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
......
using System; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;
namespace Bailun.DC.HappenAmount namespace Bailun.DC.HappenAmount
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{ {
Console.WriteLine("Hello World!"); Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Services>();
});
await builder.RunConsoleAsync();
} }
//static void Main(string[] args)
//{
// Console.WriteLine("Hello World!");
// new Services().Init(DateTime.Parse("2019-08-01"), DateTime.Parse("2019-08-02"));
//}
} }
} }
...@@ -5,11 +5,44 @@ using Bailun.DC.Models; ...@@ -5,11 +5,44 @@ using Bailun.DC.Models;
using System.Linq; using System.Linq;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using Dapper; using Dapper;
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
namespace Bailun.DC.HappenAmount namespace Bailun.DC.HappenAmount
{ {
public class Services public class Services : BackgroundService
{ {
private Timer _timer;
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
_timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));
return Task.CompletedTask;
}
private void DoWork(object state)
{
try
{
var now = DateTime.Now;
if (now.Hour == 23 && now.Minute == 59) //每天 23:59分启动
{
Console.WriteLine("开始启动 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Init(DateTime.Parse(now.ToShortDateString()),now);
Console.WriteLine("任务运行完成 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public void Init(DateTime start,DateTime end) public void Init(DateTime start,DateTime end)
{ {
...@@ -91,15 +124,15 @@ namespace Bailun.DC.HappenAmount ...@@ -91,15 +124,15 @@ namespace Bailun.DC.HappenAmount
//已付款 //已付款
sqlpay = $"select sum(cashier_paymoneyrmb) cashier_paymoneyrmb from dc_base_finance_cashier where cashier_type=1 and cashier_status=1 and sourcecode in ('newCost','oldbuy') and type_name='销售费用/物流费' and cashier_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and cashier_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'"; sqlpay = $"select sum(cashier_paymoneyrmb) cashier_paymoneyrmb from dc_base_finance_cashier where cashier_type=1 and cashier_status=1 and sourcecode in ('newCost','oldbuy') and type_name='销售费用/物流费' and cashier_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and cashier_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'";
m.hl_amount_pay += cn.QueryFirstOrDefault<decimal>(sqlpay, null, null, 2 * 60); m.hl_amount_pay += cn.QueryFirstOrDefault<decimal?>(sqlpay, null, null, 2 * 60)??0;
//发生额 //发生额
//销售额 //销售额
sqlsales = $"select sum(cost_first*bailun_sku_quantity_ordered) as cost_first from dc_base_oms_sku where paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and paid_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and bailun_order_status!='Canceled' and cost_first>0 and has_scalp=0 and has_delete=0 and has_innersale=0 and company_id=1"; sqlsales = $"select sum(cost_first*bailun_sku_quantity_ordered) as cost_first from dc_base_oms_sku where paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and paid_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and bailun_order_status!='Canceled' and cost_first>0 and has_scalp=0 and has_delete=0 and has_innersale=0 and company_id=1";
m.hl_amount_sales += cn.QueryFirstOrDefault<decimal>(sqlsales, null, null, 2 * 60); m.hl_amount_sales += cn.QueryFirstOrDefault<decimal?>(sqlsales, null, null, 2 * 60)??0;
#endregion #endregion
...@@ -112,11 +145,11 @@ namespace Bailun.DC.HappenAmount ...@@ -112,11 +145,11 @@ namespace Bailun.DC.HappenAmount
sqlhappen = $@"select sum(t2.cost_tail*t1.quantity_shipped) from dc_base_oms_pick t1 sqlhappen = $@"select sum(t2.cost_tail*t1.quantity_shipped) from dc_base_oms_pick t1
join dc_base_oms_sku t2 on t1.bailun_sku = t2.bailun_sku and t1.origin_order_id = t2.origin_order_id and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.has_delete = 0 and t2.has_innersale = 0 and t2.company_id = 1 and t2.cost_tail > 0 join dc_base_oms_sku t2 on t1.bailun_sku = t2.bailun_sku and t1.origin_order_id = t2.origin_order_id and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.has_delete = 0 and t2.has_innersale = 0 and t2.company_id = 1 and t2.cost_tail > 0
where t1.shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time < '{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.has_delete = 0 and t1.company_id = 1 and t1.shipping_status = 'TotalShipping'"; where t1.shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time < '{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.has_delete = 0 and t1.company_id = 1 and t1.shipping_status = 'TotalShipping'";
m.tl_amount_happen += cn.QueryFirstOrDefault<decimal>(sqlhappen,null,null,2*60); m.tl_amount_happen += cn.QueryFirstOrDefault<decimal?>(sqlhappen,null,null,2*60)??0;
//销售额 //销售额
sqlsales = $"select sum(cost_logistics*bailun_sku_quantity_ordered) from dc_base_oms_sku t1 where paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and paid_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and bailun_order_status!='Canceled' and has_scalp=0 and has_delete=0 and has_innersale=0 and company_id=1 and cost_logistics>0"; sqlsales = $"select sum(cost_logistics*bailun_sku_quantity_ordered) from dc_base_oms_sku t1 where paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and paid_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and bailun_order_status!='Canceled' and has_scalp=0 and has_delete=0 and has_innersale=0 and company_id=1 and cost_logistics>0";
m.tl_amount_sales += cn.QueryFirstOrDefault<decimal>(sqlsales, null, null, 2 * 60); m.tl_amount_sales += cn.QueryFirstOrDefault<decimal?>(sqlsales, null, null, 2 * 60)??0;
#endregion #endregion
...@@ -124,25 +157,41 @@ namespace Bailun.DC.HappenAmount ...@@ -124,25 +157,41 @@ namespace Bailun.DC.HappenAmount
//付款额 //付款额
sqlpay = $"select sum(cashier_paymoneyrmb) cashier_paymoneyrmb from dc_base_finance_cashier where cashier_type=1 and cashier_status=1 and sourcecode ='Buy' and cashier_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and cashier_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'"; sqlpay = $"select sum(cashier_paymoneyrmb) cashier_paymoneyrmb from dc_base_finance_cashier where cashier_type=1 and cashier_status=1 and sourcecode ='Buy' and cashier_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and cashier_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'";
m.tos_amount_pay += cn.QueryFirstOrDefault<decimal>(sqlpay, null, null, 2 * 60); m.tos_amount_pay += cn.QueryFirstOrDefault<decimal?>(sqlpay, null, null, 2 * 60)??0;
//发生额 //发生额
sqlhappen = $"select sum(unit_price*quantity_purchase) from dc_base_purchase_details where status>-1 and create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and ispush=0";
m.tos_amount_happen += cn.QueryFirstOrDefault<decimal?>(sqlhappen, null, null, 2 * 60)??0;
//销售额 //销售额
sqlsales = $@"select sum(t1.quantity_shipped*t2.bailun_sku_unit_price) from
(select quantity_shipped, origin_order_id, bailun_sku from dc_base_oms_pick where has_delete = 0 and shipping_status = 'TotalShipping' and shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and shipping_time < '{end.ToString("yyyy-MM-dd HH:mm:ss")}') t1
join dc_base_oms_sku t2 on t1.origin_order_id = t2.origin_order_id and t1.bailun_sku = t2.bailun_sku and t2.has_delete = 0";
m.tos_amount_sales += cn.QueryFirstOrDefault<decimal?>(sqlsales, null, null, 2 * 60)??0;
#endregion #endregion
#region 二级供应商 #region 二级供应商
//付款额 //付款额 取财务系统—出纳单列表当期费用系统中广州百伦,香港百伦对广州哈倪蔓生物科技有限公司、 广州拉古娜生物科技有限公司、 HONGKONG KULE INTERNATIONAL TRADING LIMITED、LEIKESAER INFORMATION SERVICE LIMITED、 广州市花都区花城滋柔贸易商行的应付账款付款金额
sqlpay = $@"select sum(cashier_paymoneyrmb) from dc_base_finance_cashier where cashier_type=1 and cashier_status=1 and cashier_time>='2019-08-17' and cashier_time<'2019-08-19' and companymain_value_from in (1,2) and tradeb_bjectname in ('广州哈倪蔓生物科技有限公司','广州拉古娜生物科技有限公司','HONGKONG KULE INTERNATIONAL TRADING LIMITED','LEIKESAER INFORMATION SERVICE LIMITED','广州市花都区花城滋柔贸易商行')";
m.ss_amount_pay += cn.QueryFirstOrDefault<decimal?>(sqlpay, null, null, 2 * 60)??0;
//发生额 //发生额
//销售额
//销售额
m.ss_amount_sales += m.tos_amount_sales;
#endregion #endregion
cn.Execute("delete from dc_daily_happen_amount where day='" + m.day.ToString("yyyy-MM-dd") + "'");
var result = cn.Insert(m);
if (!result.HasValue || result.Value <= 0)
{
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"保存失败,请重试!");
}
} }
} }
......
...@@ -7,23 +7,23 @@ namespace Bailun.DC.SkuProfitService ...@@ -7,23 +7,23 @@ namespace Bailun.DC.SkuProfitService
{ {
class Program class Program
{ {
//static async Task Main(string[] args) static async Task Main(string[] args)
//{
// Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
// var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
// {
// services.AddHostedService<Services>();
// });
// await builder.RunConsoleAsync();
//}
static void Main(string[] args)
{ {
Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Services>();
});
var _service = new Services(); await builder.RunConsoleAsync();
_service.Save();
} }
//static void Main(string[] args)
//{
// Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
// var _service = new Services();
// _service.Save();
//}
} }
} }
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