Commit 99c821f0 by guanzhenshan

sku发货重量差异服务

parent cb0b84ee
.dockerignore
.env
.git
.gitignore
.vs
.vscode
docker-compose.yml
docker-compose.*.yml
*/bin
*/obj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="1.60.6" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
<PackageReference Include="MySql.Data" Version="8.0.16" />
</ItemGroup>
</Project>
FROM microsoft/dotnet:2.1-runtime AS base
WORKDIR /app
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY Bailun.DC.SaveSkuDeliverWeighDiff/Bailun.DC.SaveSkuDeliverWeighDiff.csproj Bailun.DC.SaveSkuDeliverWeighDiff/
RUN dotnet restore Bailun.DC.SaveSkuDeliverWeighDiff/Bailun.DC.SaveSkuDeliverWeighDiff.csproj
COPY . .
WORKDIR /src/Bailun.DC.SaveSkuDeliverWeighDiff
RUN dotnet build Bailun.DC.SaveSkuDeliverWeighDiff.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Bailun.DC.SaveSkuDeliverWeighDiff.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Bailun.DC.SaveSkuDeliverWeighDiff.dll"]
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.SaveSkuDeliverWeighDiff.Models
{
public class mDiffWeigh
{
public string pick_order_id { get; set; }
public string bailun_sku { get; set; }
public decimal weight { get; set; }
public decimal bailun_sku_outbound_weight { get; set; }
public decimal diffweigh { get; set; }
}
}
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Bailun.DC.SaveSkuDeliverWeighDiff
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("保存sku每日发货重量异常数据。");
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
services.AddHostedService<SkuDeliverWeighServices>();
});
await builder.RunConsoleAsync();
}
}
}
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Dapper;
using MySql.Data.MySqlClient;
namespace Bailun.DC.SaveSkuDeliverWeighDiff
{
public class SkuDeliverWeighServices: BackgroundService
{
private Timer _timer;
private readonly string cn_str = "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;";
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 == 1 && now.Minute == 1)
{
Save(DateTime.Parse(now.AddDays(-1).ToString("yyyy-MM-dd")));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void Save(DateTime day)
{
var sql = $@"select t1.pick_order_id,t1.bailun_sku,t2.weight,t1.bailun_sku_outbound_weight,(t2.weight-t1.bailun_sku_outbound_weight) as diffweigh from dc_base_oms_pick t1
join dc_base_sku t2 on t1.bailun_sku = t2.bailun_sku and t2.has_delete = 0
where t1.shipping_status = 'TotalShipping' and t1.has_delete = 0 and t1.shipping_time >= '{day.ToString("yyyy-MM-dd")}' and t1.shipping_time < '{day.AddDays(1).ToString("yyyy-MM-dd")}'";
using (var cn = new MySqlConnection(cn_str))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var list = cn.Query<Models.mDiffWeigh>(sql).AsList();
var index = 1;
var str = "";
while (list.Count >= index)
{
var item = list[index - 1];
str += $"insert dc_mid_skudeliver_weighdiff (day,pick_order_id,bailun_sku,weight,bailun_sku_outbound_weight,diffweigh,createtime) values ('{day.ToString("yyyy-MM-dd")}','{item.pick_order_id}','{item.bailun_sku}',{item.weight},{item.bailun_sku_outbound_weight},{item.diffweigh},'{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}');";
if (index / 2000 == 0 || index == list.Count)
{
cn.Execute(str);
str = "";
}
index++;
}
}
}
public override void Dispose()
{
base.Dispose();
_timer?.Dispose();
}
}
}
...@@ -13,6 +13,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.DC.Models", "Bailun. ...@@ -13,6 +13,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.DC.Models", "Bailun.
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.Common", "Bailun.DC.Common\Bailun.DC.Common.csproj", "{95F558EC-586B-4989-AF11-328FC29128FE}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.Common", "Bailun.DC.Common\Bailun.DC.Common.csproj", "{95F558EC-586B-4989-AF11-328FC29128FE}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Windows Console", "Windows Console", "{AE2CE86A-8538-4142-920F-684DCF47C064}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.SaveSkuDeliverWeighDiff", "Bailun.DC.SaveSkuDeliverWeighDiff\Bailun.DC.SaveSkuDeliverWeighDiff.csproj", "{75536DAE-6ADD-463C-954E-55C95A991293}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -39,10 +43,17 @@ Global ...@@ -39,10 +43,17 @@ Global
{95F558EC-586B-4989-AF11-328FC29128FE}.Debug|Any CPU.Build.0 = Debug|Any CPU {95F558EC-586B-4989-AF11-328FC29128FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95F558EC-586B-4989-AF11-328FC29128FE}.Release|Any CPU.ActiveCfg = Release|Any CPU {95F558EC-586B-4989-AF11-328FC29128FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95F558EC-586B-4989-AF11-328FC29128FE}.Release|Any CPU.Build.0 = Release|Any CPU {95F558EC-586B-4989-AF11-328FC29128FE}.Release|Any CPU.Build.0 = Release|Any CPU
{75536DAE-6ADD-463C-954E-55C95A991293}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75536DAE-6ADD-463C-954E-55C95A991293}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75536DAE-6ADD-463C-954E-55C95A991293}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75536DAE-6ADD-463C-954E-55C95A991293}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{75536DAE-6ADD-463C-954E-55C95A991293} = {AE2CE86A-8538-4142-920F-684DCF47C064}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6E53AF28-A282-4FB0-A769-EAEA9769C02A} SolutionGuid = {6E53AF28-A282-4FB0-A769-EAEA9769C02A}
EndGlobalSection EndGlobalSection
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
<PropertyGroup Label="Globals">
<ProjectVersion>2.1</ProjectVersion>
<DockerTargetOS>Linux</DockerTargetOS>
<ProjectGuid>92040d69-5f88-4efd-973b-18949bceed2b</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
<None Include=".dockerignore" />
</ItemGroup>
</Project>
\ No newline at end of file
version: '3.4'
services:
bailun.dc.saveskudeliverweighdiff:
image: ${DOCKER_REGISTRY}bailundcsaveskudeliverweighdiff
build:
context: .
dockerfile: Bailun.DC.SaveSkuDeliverWeighDiff/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