Commit 73a6c0dd by guanzhenshan

增加每月发货收入服务(自发货的)

parent 13645833
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models
{
public class dc_month_shipping_incoming
{
/// <summary>
///
/// </summary>
public int id { get; set; }
/// <summary>
/// 平台类型
/// </summary>
public string platform_type { get; set; }
/// <summary>
/// 币种
/// </summary>
public string currency { get; set; }
/// <summary>
/// 金额
/// </summary>
public decimal amount { get; set; }
/// <summary>
/// 财务分类
/// </summary>
public string financecategoryname { get; set; }
/// <summary>
/// 月份
/// </summary>
public string month { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime createtime { get; set; }
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.78" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" />
<PackageReference Include="MySql.Data" Version="8.0.22" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bailun.DC.Common\Bailun.DC.Common.csproj" />
<ProjectReference Include="..\Bailun.DC.Models\Bailun.DC.Models.csproj" />
</ItemGroup>
</Project>
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Bailun.DC.MonthShippingIncoming/Bailun.DC.MonthShippingIncoming.csproj", "Bailun.DC.MonthShippingIncoming/"]
COPY ["Bailun.DC.Common/Bailun.DC.Common.csproj", "Bailun.DC.Common/"]
COPY ["Bailun.DC.Models/Bailun.DC.Models.csproj", "Bailun.DC.Models/"]
RUN dotnet restore "Bailun.DC.MonthShippingIncoming/Bailun.DC.MonthShippingIncoming.csproj"
COPY . .
WORKDIR "/src/Bailun.DC.MonthShippingIncoming"
RUN dotnet build "Bailun.DC.MonthShippingIncoming.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Bailun.DC.MonthShippingIncoming.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Bailun.DC.MonthShippingIncoming.dll"]
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.MonthShippingIncoming.Model
{
public class mPlatformIncoming
{
public string platform_type { get; set; }
public string order_currency { get; set; }
public string financecategoryname { get; set; }
public decimal amount_sales { get; set; }
}
}
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;
namespace Bailun.DC.MonthShippingIncoming
{
class Program
{
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("Hello World!");
// var _service = new Services();
// _service.Init(DateTime.Parse("2020-12-01"));
//}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using Dapper;
using Bailun.DC.Common;
using Bailun.DC.Models;
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
namespace Bailun.DC.MonthShippingIncoming
{
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.Day == 1 && now.Hour == 1 && now.Minute == 45 && now.Second == 1) //每个月的1日1点45分启动
{
Console.WriteLine("开始启动 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var start = DateTime.Parse(now.AddMonths(-1).ToShortDateString());
Init(start);
Console.WriteLine("任务运行完成 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public void Init(DateTime day)
{
var list = new List<dc_month_shipping_incoming>();
//获取订单数据
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString_read))
{
if(cn.State== System.Data.ConnectionState.Closed)
{
cn.Open();
}
var sql = $@"select sum(t2.amount_sales*t1.quantity_shipped) as amount_sales,if(t6.financecategoryname is null,'',t6.financecategoryname) as financecategoryname,t2.order_currency,t2.platform_type from dc_base_oms_pick t1
join dc_base_oms_sku t2 on t1.bailun_order_id = t2.bailun_order_id and t1.bailun_sku=t2.bailun_sku and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and ((t2.platform_type!='FBA' and t2.bailun_order_status!='CantHandle') or t2.platform_type='FBA') and t2.has_scalp = 0 and t2.has_innersale = 0 and t2.has_delete=0 and t2.company_id=1
left join dc_base_sku t5 on t2.bailun_sku=t5.bailun_sku
left join dc_base_sku_finance_category t6 on t6.bailuncategoryid=t5.bailun_category_id
where t1.has_delete=0 and t1.shipping_status = 'TotalShipping' and t1.company_id=1 and t1.shipping_time>='{day.ToString("yyyy-MM-dd")}' and t1.shipping_time<'{day.AddMonths(1).ToString("yyyy-MM-dd")}'
group by t6.financecategoryname,t2.order_currency,t2.platform_type";
var obj = cn.Query<Model.mPlatformIncoming>(sql, null, null, true, 2 * 60).AsList();
foreach(var item in obj)
{
list.Add(new dc_month_shipping_incoming {
amount = item.amount_sales,
createtime =DateTime.Now,
currency = item.order_currency,
financecategoryname = item.financecategoryname,
month = day.ToString("yyyy-MM"),
platform_type = item.platform_type,
});
}
}
if(list.Count>0)
{
var sql = "insert dc_month_shipping_incoming (amount,createtime,currency,financecategoryname,month,platform_type) values ";
foreach(var item in list)
{
sql += $"({item.amount},'{item.createtime.ToString("yyyy-MM-dd HH:mm:ss")}','{item.currency}','{item.financecategoryname}','{item.month}','{item.platform_type}'),";
}
sql = sql.Substring(0, sql.Length - 1);
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if(cn.State== System.Data.ConnectionState.Closed)
{
cn.Open();
}
cn.Execute("delete from dc_month_shipping_incoming where month='"+day.ToString("yyyy-MM")+"'");
cn.Execute(sql);
}
}
}
}
}
...@@ -77,6 +77,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.DC.BalanceSheet4K", ...@@ -77,6 +77,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.DC.BalanceSheet4K",
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.DailyInventorySummary", "Bailun.DC.DailyInventorySummary\Bailun.DC.DailyInventorySummary.csproj", "{692343B9-C7D6-4F8A-9580-BE048F4E1A40}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.DailyInventorySummary", "Bailun.DC.DailyInventorySummary\Bailun.DC.DailyInventorySummary.csproj", "{692343B9-C7D6-4F8A-9580-BE048F4E1A40}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.MonthShippingIncoming", "Bailun.DC.MonthShippingIncoming\Bailun.DC.MonthShippingIncoming.csproj", "{22B454F8-2315-4013-8170-F8FB5AD51BB8}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -227,6 +229,10 @@ Global ...@@ -227,6 +229,10 @@ Global
{692343B9-C7D6-4F8A-9580-BE048F4E1A40}.Debug|Any CPU.Build.0 = Debug|Any CPU {692343B9-C7D6-4F8A-9580-BE048F4E1A40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{692343B9-C7D6-4F8A-9580-BE048F4E1A40}.Release|Any CPU.ActiveCfg = Release|Any CPU {692343B9-C7D6-4F8A-9580-BE048F4E1A40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{692343B9-C7D6-4F8A-9580-BE048F4E1A40}.Release|Any CPU.Build.0 = Release|Any CPU {692343B9-C7D6-4F8A-9580-BE048F4E1A40}.Release|Any CPU.Build.0 = Release|Any CPU
{22B454F8-2315-4013-8170-F8FB5AD51BB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22B454F8-2315-4013-8170-F8FB5AD51BB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22B454F8-2315-4013-8170-F8FB5AD51BB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22B454F8-2315-4013-8170-F8FB5AD51BB8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -262,6 +268,7 @@ Global ...@@ -262,6 +268,7 @@ Global
{0BDF5631-AA7C-4548-84ED-740D861D569E} = {AE2CE86A-8538-4142-920F-684DCF47C064} {0BDF5631-AA7C-4548-84ED-740D861D569E} = {AE2CE86A-8538-4142-920F-684DCF47C064}
{935E0EAE-B824-4507-9D32-6F7F959B140A} = {AE2CE86A-8538-4142-920F-684DCF47C064} {935E0EAE-B824-4507-9D32-6F7F959B140A} = {AE2CE86A-8538-4142-920F-684DCF47C064}
{692343B9-C7D6-4F8A-9580-BE048F4E1A40} = {AE2CE86A-8538-4142-920F-684DCF47C064} {692343B9-C7D6-4F8A-9580-BE048F4E1A40} = {AE2CE86A-8538-4142-920F-684DCF47C064}
{22B454F8-2315-4013-8170-F8FB5AD51BB8} = {AE2CE86A-8538-4142-920F-684DCF47C064}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6E53AF28-A282-4FB0-A769-EAEA9769C02A} SolutionGuid = {6E53AF28-A282-4FB0-A769-EAEA9769C02A}
......
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