Commit 437ead6d by guanzhenshan

增加同步调拨单详情服务

parent 56a951fc
<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.5" />
<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.AllotOrderDetail/Bailun.DC.AllotOrderDetail.csproj Bailun.DC.AllotOrderDetail/
RUN dotnet restore Bailun.DC.AllotOrderDetail/Bailun.DC.AllotOrderDetail.csproj
COPY . .
WORKDIR /src/Bailun.DC.AllotOrderDetail
RUN dotnet build Bailun.DC.AllotOrderDetail.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Bailun.DC.AllotOrderDetail.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Bailun.DC.AllotOrderDetail.dll"]
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.AllotOrderDetail.Models
{
public class AllotInfo
{
/// <summary>
/// 调拨单id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 调拨单号
/// </summary>
public string Code { get; set; }
/// <summary>
/// 计划单号
/// </summary>
public string ScheduleCode { get; set; }
/// <summary>
/// ShipmentId
/// </summary>
public string ShipmentId { get; set; }
/// <summary>
/// 调拨单状态
/// </summary>
public int StateId { get; set; }
/// <summary>
///
/// </summary>
public int AllocateCargoState { get; set; }
/// <summary>
///
/// </summary>
public string ShipmentStatus { get; set; }
/// <summary>
/// 发货仓库名称
/// </summary>
public string SourceWareName { get; set; }
/// <summary>
/// 起始仓库编码
/// </summary>
public string SourceWareNo { get; set; }
/// <summary>
/// 目的仓库编码
/// </summary>
public string TargetWareNo { get; set; }
/// <summary>
/// 目的仓名称
/// </summary>
public string TargetWareName { get; set; }
/// <summary>
/// 发货要求
/// </summary>
public string SendRequire { get; set; }
/// <summary>
/// 创建人
/// </summary>
public string CreateUserName { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreationTime { get; set; }
/// <summary>
/// 商品类型
/// </summary>
public string ProductType { get; set; }
/// <summary>
/// 调拨类型
/// </summary>
public int ScheduleType { get; set; }
/// <summary>
/// 调拨类型(1-fba调拨单,2-普通调拨单)
/// </summary>
public int TransferType { get; set; }
/// <summary>
/// 采购单号
/// </summary>
public string PurchaseCode { get; set; }
/// <summary>
/// 目的仓地址
/// </summary>
public string TargetWareAddress { get; set; }
/// <summary>
/// 特殊问题
/// </summary>
public string SpecialProblem { get; set; }
/// <summary>
/// 预计到货时间
/// </summary>
public DateTime ExpectArrivalTime { get; set; }
/// <summary>
/// 运输方式
/// </summary>
public string TransportType { get; set; }
/// <summary>
/// 是否锁仓
/// </summary>
public bool IsLockedPosition { get; set; }
/// <summary>
/// 入库单号
/// </summary>
public string ReceiptNo { get; set; }
/// <summary>
/// 物流编码
/// </summary>
public string LogisticsCode { get; set; }
/// <summary>
/// 物流名称
/// </summary>
public string LogisticsName { get; set; }
/// <summary>
/// 打包要求
/// </summary>
public string PackRequirements { get; set; }
/// <summary>
///
/// </summary>
public List<AllotOrderProductItemOutputDto> AllotOrderProducts { get; set; }
/// <summary>
/// 最后更新时间戳
/// </summary>
public DateTime TimeStamp { get; set; }
/// <summary>
/// 是否异常
/// </summary>
public bool IsException { get; set; }
/// <summary>
/// 是否已删除
/// </summary>
public bool IsDeleted { get; set; }
/// <summary>
/// 调拨单预估费用
/// </summary>
public decimal EstimatedCost { get; set; }
/// <summary>
/// 跟踪号
/// </summary>
public List<string> TrackingNo { get; set; }
/// <summary>
/// 渠道名称
/// </summary>
public List<string> ChannelName { get; set; }
}
public class AllotOrderProductItemOutputDto
{
/// <summary>
/// 商品名称
/// </summary>
public string ProductName { get; set; }
/// <summary>
/// 产品库sku
/// </summary>
public string Sku { get; set; }
/// <summary>
/// 发货总数
/// </summary>
public int DeliveryCount { get; set; }
/// <summary>
/// 入库总数
/// </summary>
public int StorageCount { get; set; }
}
public class Result_Allot
{
public bool isSuccess { get; set; }
public Result_Allot_data data {get;set;}
public string message { get; set; }
public int code { get; set; }
public string errorData { get; set; }
}
public class Result_Allot_data
{
public List<AllotInfo> items { get; set; }
public Result_Allot_page pageItem { get; set; }
}
public class Result_Allot_page {
public int total { get; set; }
public int currentPage { get; set; }
public int pageSize { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.AllotOrderDetail.Models
{
/// <summary>
/// 调拨单详情
/// </summary>
public class dc_base_transfer_info
{
public int id { get; set; }
public int dataid { get; set; }
public string code { get; set; }
public string schedulecode { get; set; }
public string shipmentid { get; set; }
public int stateid { get; set; }
public int allocatecargostate { get; set; }
public string shipmentstatus { get; set; }
public string sourcewarename { get; set; }
public string sourcewareno { get; set; }
public string targetwareno { get; set; }
public string targetwarename { get; set; }
public string sendrequire { get; set; }
public string createusername { get; set; }
public DateTime creationtime { get; set; }
public string producttype { get; set; }
public int? scheduletype { get; set; }
public int? transfertype { get; set; }
public string purchasecode { get; set; }
public string targetwareaddress { get; set; }
public string specialproblem { get; set; }
public DateTime? expectarrivaltime { get; set; }
public string transporttype { get; set; }
public int islockedposition { get; set; }
public string receiptno { get; set; }
public string targetwareaddressinfo { get; set; }
public string logisticscode { get; set; }
public string logisticsname { get; set; }
public string packrequirements { get; set; }
public DateTime timestamp { get; set; }
public int isexception { get; set; }
public int isdeleted { get; set; }
public decimal? skuweight { get; set; }
public string skuweightStr { get; set; }
public decimal? sinnleticketmaxweight { get; set; }
public decimal? singleboxmaxweight { get; set; }
public decimal? singleboxminweight { get; set; }
public decimal? estimatedcost { get; set; }
public string trackingno { get; set; }
public string channelname { get; set; }
public DateTime dc_createtime { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.AllotOrderDetail.Models
{
/// <summary>
/// 调拨单详情 sku信息
/// </summary>
public class dc_base_transfer_info_skus
{
public int id { get; set; }
public int dataid { get; set; }
public string transferno { get; set; }
public string productname { get; set; }
public string sku { get; set; }
public int deliverycount { get; set; }
public int storagecount { get; set; }
public DateTime createtime { get; set; }
}
}
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;
namespace Bailun.DC.AllotOrderDetail
{
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)
//{
// var service = new Services();
// service.Init();
//}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using Dapper;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
using System.Threading;
using Bailun.DC.AllotOrderDetail.Models;
namespace Bailun.DC.AllotOrderDetail
{
public class Services : BackgroundService
{
static string url = "http://api.wms.bailuntec.com/api/services/app/AllotOrderService/SearchAllotOrderDataListPage";
static DateTime endtime;
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.Minute==30)
{
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);
}
}
public void Init()
{
var page = 1;
var rows = 1000;
var starttime = DateTime.Now;
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
var sql = "select * from dc_base_transfer_info order by timestamp desc limit 1";
var result = cn.QueryFirstOrDefault<Models.dc_base_transfer_info>(sql);
if (result == null)
{
starttime = DateTime.Parse("2018-12-05");
}
else
{
starttime = result.timestamp;
}
}
}
endtime = DateTime.Now;
starttime = starttime.AddMinutes(-3);
var total = -1;
while (total == -1 || total > page * rows)
{
total = 0;
var data = new
{
Data = new {
Page = new {
page = page,
rows = rows
},
StartTime = starttime.ToString("yyyy-MM-dd HH:mm:ss"),
EndTime = endtime.ToString("yyyy-MM-dd HH:mm:ss"),
},
};
var str = Common.HttpHelper.NetHelper.HttpPostJson(url, Newtonsoft.Json.JsonConvert.SerializeObject(data));
var json = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.Result_Allot>(str);
if (json.isSuccess && json.data.items.Count > 0)
{
total = json.data.pageItem.total;
//保存数据
Save(json.data.items);
Console.WriteLine("时间:" + starttime.ToString("yyyy-MM-dd HH:mm:ss") + "-" + endtime.ToString("yyyy-MM-dd HH:mm:ss") + ",页码:" + page + ",请求记录数:" + json.data.items.Count);
page++;
}
else
{
Console.WriteLine("时间:" + starttime.ToString("yyyy-MM-dd HH:mm:ss") + "-" + endtime.ToString("yyyy-MM-dd HH:mm:ss") + ",页码:" + page + ",请求记录数:0");
}
}
}
public void Save(List<Models.AllotInfo> list)
{
Dapper.SimpleCRUD.SetDialect(SimpleCRUD.Dialect.MySQL);
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
foreach (var item in list)
{
cn.Execute("delete from dc_base_transfer_info where dataid="+item.Id);
var m = new Models.dc_base_transfer_info
{
dataid = item.Id,
allocatecargostate = item.AllocateCargoState,
channelname = string.Join(",",item.ChannelName),
code = item.Code,
createusername = item.CreateUserName,
creationtime = item.CreationTime,
dc_createtime = DateTime.Now,
estimatedcost = item.EstimatedCost,
expectarrivaltime = item.ExpectArrivalTime,
isdeleted = item.IsDeleted?1:0,
isexception = item.IsException?1:0,
islockedposition = item.IsLockedPosition?1:0,
logisticscode = item.LogisticsCode,
logisticsname = item.LogisticsName,
packrequirements = item.PackRequirements,
producttype = item.ProductType,
purchasecode = item.PurchaseCode,
receiptno = item.ReceiptNo,
schedulecode = item.ScheduleCode,
scheduletype = item.ScheduleType,
sendrequire = item.SendRequire,
shipmentid = item.ShipmentId,
shipmentstatus = item.ShipmentStatus,
singleboxmaxweight = 0,
singleboxminweight = 0,
sinnleticketmaxweight = 0,
sourcewarename = item.SourceWareName,
sourcewareno = item.SourceWareNo,
specialproblem = item.SpecialProblem,
targetwareaddress = item.TargetWareAddress,
targetwareaddressinfo = item.TargetWareAddress,
targetwarename = item.TargetWareName,
targetwareno = item.TargetWareNo,
timestamp = item.TimeStamp,
trackingno = string.Join(",",item.TrackingNo),
transfertype = item.TransferType,
transporttype = item.TransportType,
stateid = item.StateId,
skuweight = 0,
skuweightStr = "",
};
cn.Insert<Models.dc_base_transfer_info>(m);
cn.Execute("delete from dc_base_transfer_info_skus where dataid=" + item.Id);
foreach (var sku in item.AllotOrderProducts)
{
var s = new Models.dc_base_transfer_info_skus {
createtime = DateTime.Now,
dataid = item.Id,
deliverycount = sku.DeliveryCount,
productname = sku.ProductName,
sku = sku.Sku,
storagecount = sku.StorageCount,
transferno = item.Code
};
cn.Insert<dc_base_transfer_info_skus>(s);
}
}
}
}
}
}
...@@ -51,7 +51,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.DC.DailySelfProduceP ...@@ -51,7 +51,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.DC.DailySelfProduceP
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.DC.DailyPlatformAccountBalance", "Bailun.DC.DailyPlatformAccountBalance\Bailun.DC.DailyPlatformAccountBalance.csproj", "{7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.DC.DailyPlatformAccountBalance", "Bailun.DC.DailyPlatformAccountBalance\Bailun.DC.DailyPlatformAccountBalance.csproj", "{7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.AllotOrderDetail", "..\Bailun.DC.AllotOrderDetail\Bailun.DC.AllotOrderDetail.csproj", "{979DA036-4955-4747-9806-F3ECC4A260E5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bailun.DC.AllotOrderDetail", "Bailun.DC.AllotOrderDetail\Bailun.DC.AllotOrderDetail.csproj", "{9FE5546F-871B-4A06-90A3-2B1567EA3E26}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -151,10 +151,10 @@ Global ...@@ -151,10 +151,10 @@ Global
{7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9}.Debug|Any CPU.Build.0 = Debug|Any CPU {7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9}.Release|Any CPU.ActiveCfg = Release|Any CPU {7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9}.Release|Any CPU.Build.0 = Release|Any CPU {7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9}.Release|Any CPU.Build.0 = Release|Any CPU
{979DA036-4955-4747-9806-F3ECC4A260E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9FE5546F-871B-4A06-90A3-2B1567EA3E26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{979DA036-4955-4747-9806-F3ECC4A260E5}.Debug|Any CPU.Build.0 = Debug|Any CPU {9FE5546F-871B-4A06-90A3-2B1567EA3E26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{979DA036-4955-4747-9806-F3ECC4A260E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {9FE5546F-871B-4A06-90A3-2B1567EA3E26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{979DA036-4955-4747-9806-F3ECC4A260E5}.Release|Any CPU.Build.0 = Release|Any CPU {9FE5546F-871B-4A06-90A3-2B1567EA3E26}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -177,7 +177,7 @@ Global ...@@ -177,7 +177,7 @@ Global
{5163B1E9-43F8-4E5A-B4A9-546F5375515E} = {AE2CE86A-8538-4142-920F-684DCF47C064} {5163B1E9-43F8-4E5A-B4A9-546F5375515E} = {AE2CE86A-8538-4142-920F-684DCF47C064}
{A8E6DCD5-9F45-41D3-9297-FB104772B11C} = {AE2CE86A-8538-4142-920F-684DCF47C064} {A8E6DCD5-9F45-41D3-9297-FB104772B11C} = {AE2CE86A-8538-4142-920F-684DCF47C064}
{7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9} = {AE2CE86A-8538-4142-920F-684DCF47C064} {7EA89BAB-0D45-4959-8AB2-9F08FDB3D7F9} = {AE2CE86A-8538-4142-920F-684DCF47C064}
{979DA036-4955-4747-9806-F3ECC4A260E5} = {AE2CE86A-8538-4142-920F-684DCF47C064} {9FE5546F-871B-4A06-90A3-2B1567EA3E26} = {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