Commit 0b924a27 by guanzhenshan

完成每月销售利润报表的统计服务

parent 56fbc946
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
......
FROM microsoft/dotnet:2.1-runtime AS base
WORKDIR /app
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY Bailun.DC.MonthSaleProfit/Bailun.DC.MonthSaleProfit.csproj Bailun.DC.MonthSaleProfit/
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.MonthSaleProfit/Bailun.DC.MonthSaleProfit.csproj
COPY . .
WORKDIR /src/Bailun.DC.MonthSaleProfit
RUN dotnet build Bailun.DC.MonthSaleProfit.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Bailun.DC.MonthSaleProfit.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Bailun.DC.MonthSaleProfit.dll"]
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;
namespace Bailun.DC.MonthSaleProfit
{
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)
static async Task Main(string[] args)
{
Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
var _services = new Services();
services.AddHostedService<Services>();
});
var start = DateTime.Parse("2019-09-01");
_services.Init(start);
await builder.RunConsoleAsync();
}
//static void Main(string[] args)
//{
// var _services = new Services();
// var start = DateTime.Parse("2019-09-01");
// _services.Init(start);
//}
}
}
......@@ -5,14 +5,45 @@ using MySql.Data.MySqlClient;
using Dapper;
using Bailun.DC.Models;
using Bailun.DC.Common;
using System.Threading;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
namespace Bailun.DC.MonthSaleProfit
{
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.Day==1 && now.Hour==0 && now.Minute==1) //每个月的1日0点1分启动
{
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);
}
}
/// <summary>
/// 每月1日统计
......
......@@ -69,3 +69,10 @@ services:
context: .
dockerfile: Bailun.DC.DailyPurchaseSellStock/Dockerfile
bailun.dc.monthsaleprofit:
image: ${DOCKER_REGISTRY}bailundcmonthsaleprofit
build:
context: .
dockerfile: Bailun.DC.MonthSaleProfit/Dockerfile
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