Commit 7147ca99 by guanzhenshan

增加同步仓库信息服务

parent 316510e7
......@@ -4,7 +4,6 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="Dapper.SimpleCRUD" Version="2.2.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.6" />
<PackageReference Include="MySql.Data" Version="8.0.20" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bailun.DC.Common\Bailun.DC.Common.csproj" />
</ItemGroup>
</Project>
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.SyncWarehouseInfo/Bailun.DC.SyncWarehouseInfo.csproj Bailun.DC.SyncWarehouseInfo/
COPY Bailun.DC.Common/Bailun.DC.Common.csproj Bailun.DC.Common/
RUN dotnet restore Bailun.DC.SyncWarehouseInfo/Bailun.DC.SyncWarehouseInfo.csproj
COPY . .
WORKDIR /src/Bailun.DC.SyncWarehouseInfo
RUN dotnet build Bailun.DC.SyncWarehouseInfo.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Bailun.DC.SyncWarehouseInfo.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Bailun.DC.SyncWarehouseInfo.dll"]
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.SyncWarehouseInfo.Models
{
public class dc_base_warehouse
{
public int id { get; set; }
public DateTime gmt_create { get; set; }
public DateTime gmt_modified { get; set; }
public string warehouse_code { get; set; }
public string warehouse_name { get; set; }
public string warehouse_extend_name { get; set; }
public string functions { get; set; }
public string warehouse_old_code { get; set; }
public string system_flag { get; set; }
public int bailun_account_id { get; set; }
public string bailun_account { get; set; }
public string hq_type { get; set; }
public int type_id { get; set; }
public string type_name { get; set; }
public int area_id { get; set; }
public string area_name { get; set; }
public int warehouse_id { get; set; }
public string warehouse_type_ex { get; set; }
public int company_id { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.SyncWarehouseInfo.Models
{
public class mResult_Request
{
public bool isSuccess { get; set; }
public string message { get; set; }
public int code { get; set; }
public string errorData { get; set; }
public List<mData> data { get; set; }
}
public class mData
{
public int id { get; set; }
public string code { get; set; }
public string oldCode { get; set; }
public string name { get; set; }
public string extendName { get; set; }
public mArea area { get; set; }
public string systemFlag { get; set; }
public int accountId { get; set; }
public string account { get; set; }
public string hqType { get; set; }
public int typeId { get; set; }
public string typeName { get; set; }
public List<mFunction> functions { get; set; }
}
public class mArea
{
public int id { get; set; }
public string name { get; set; }
public string enCountry { get; set; }
}
public class mFunction
{
public int id { get; set; }
public string name { get; set; }
public string enCountry { get; set; }
}
}
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;
namespace Bailun.DC.SyncWarehouseInfo
{
class Program
{
/// <summary>
/// 同步仓库基础数据
/// </summary>
/// <param name="args"></param>
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!");
// Services _service = new Services();
// _service.Init();
//}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Bailun.DC.SyncWarehouseInfo.Models;
using Newtonsoft.Json;
using Dapper;
using MySql.Data.MySqlClient;
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
namespace Bailun.DC.SyncWarehouseInfo
{
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 == 58) //凌晨23:58分启动
{
Console.WriteLine("开始启动 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Init();
Console.WriteLine("任务运行完成 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
protected string url = "http://api.wms.bailuntec.com/api/services/app/WarehouseService/SearchWarehouse";
public Services()
{
Dapper.SimpleCRUD.SetDialect(SimpleCRUD.Dialect.MySQL);
}
public void Init()
{
var result = Bailun.DC.Common.HttpHelper.NetHelper.HttpPostJson(url, Newtonsoft.Json.JsonConvert.SerializeObject(new { data =new { } }));
var json = JsonConvert.DeserializeObject<mResult_Request>(result);
if (json.isSuccess)
{
Save(json.data);
}
}
public void Save(List<mData> list)
{
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
foreach (var item in list)
{
if (item.id == 0)
{
continue;
}
var accountname = "";
if (item.accountId > 0)
{
accountname = cn.QueryFirstOrDefault<string>("select account_name+'-'+site_en as acount from dc_base_company_account where account_id=" + item.accountId);
}
var m = cn.QueryFirstOrDefault<dc_base_warehouse>("select * from dc_base_warehouse where warehouse_code='" + item.code+"'");
if (m == null)
{
m = new dc_base_warehouse
{
area_id = item.area.id,
area_name = item.area.name,
bailun_account = accountname,
bailun_account_id = item.accountId,
company_id = 0,
functions = JsonConvert.SerializeObject(item.functions),
gmt_create = DateTime.Now,
gmt_modified = DateTime.Now,
hq_type = item.hqType,
system_flag = item.systemFlag,
type_id = item.typeId,
type_name = item.typeName,
warehouse_code = item.code,
warehouse_name = item.name,
warehouse_extend_name = item.extendName,
warehouse_id = item.id,
warehouse_old_code = item.oldCode,
warehouse_type_ex = "0"
};
cn.Insert(m);
}
else
{
m.area_id = item.area.id;
m.area_name = item.area.name;
m.bailun_account = accountname;
m.bailun_account_id = item.accountId;
m.company_id = 0;
m.functions = JsonConvert.SerializeObject(item.functions);
m.gmt_modified = DateTime.Now;
m.hq_type = item.hqType;
m.system_flag = item.systemFlag;
m.type_id = item.typeId;
m.type_name = item.typeName;
m.warehouse_code = item.code;
m.warehouse_name = item.name;
m.warehouse_extend_name = item.extendName;
m.warehouse_id = item.id;
m.warehouse_old_code = item.oldCode;
m.warehouse_type_ex = "0";
cn.Update(m);
}
}
}
}
}
}
......@@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.SyncLogisticInfo"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.DailyBorrowFee", "Bailun.DC.DailyBorrowFee\Bailun.DC.DailyBorrowFee.csproj", "{BABF8256-64D9-42F4-8008-B8AC51F3692E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.SyncWarehouseInfo", "Bailun.DC.SyncWarehouseInfo\Bailun.DC.SyncWarehouseInfo.csproj", "{6559BFAB-3A8F-47B6-89CC-8E9FB4F89EF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -167,6 +169,10 @@ Global
{BABF8256-64D9-42F4-8008-B8AC51F3692E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BABF8256-64D9-42F4-8008-B8AC51F3692E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BABF8256-64D9-42F4-8008-B8AC51F3692E}.Release|Any CPU.Build.0 = Release|Any CPU
{6559BFAB-3A8F-47B6-89CC-8E9FB4F89EF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6559BFAB-3A8F-47B6-89CC-8E9FB4F89EF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6559BFAB-3A8F-47B6-89CC-8E9FB4F89EF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6559BFAB-3A8F-47B6-89CC-8E9FB4F89EF1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -192,6 +198,7 @@ Global
{9FE5546F-871B-4A06-90A3-2B1567EA3E26} = {AE2CE86A-8538-4142-920F-684DCF47C064}
{70BEDA08-20D6-4EDF-8653-72595618E3CE} = {AE2CE86A-8538-4142-920F-684DCF47C064}
{BABF8256-64D9-42F4-8008-B8AC51F3692E} = {AE2CE86A-8538-4142-920F-684DCF47C064}
{6559BFAB-3A8F-47B6-89CC-8E9FB4F89EF1} = {AE2CE86A-8538-4142-920F-684DCF47C064}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6E53AF28-A282-4FB0-A769-EAEA9769C02A}
......
......@@ -139,3 +139,10 @@ services:
context: .
dockerfile: Bailun.DC.SyncLogisticInfo/Dockerfile
bailun.dc.syncwarehouseinfo:
image: ${DOCKER_REGISTRY}bailundcsyncwarehouseinfo
build:
context: .
dockerfile: Bailun.DC.SyncWarehouseInfo/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