Commit bfe08f22 by guanzhenshan

增加同步FBA发货收入明细服务

parent 8fc08aea
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models
{
/// <summary>
/// FBA每月发货明细数据
/// </summary>
public class dc_base_fba_shipping_detail
{
/// <summary>
///
/// </summary>
public int id { get; set; }
/// <summary>
///
/// </summary>
public string month { get; set; }
/// <summary>
///
/// </summary>
public string order_id { get; set; }
/// <summary>
///
/// </summary>
public DateTime shipment_date { get; set; }
/// <summary>
///
/// </summary>
public DateTime reporting_date { get; set; }
/// <summary>
///
/// </summary>
public string sku { get; set; }
/// <summary>
///
/// </summary>
public string currency { get; set; }
/// <summary>
///
/// </summary>
public decimal orderamount { get; set; }
/// <summary>
///
/// </summary>
public DateTime createtime { get; set; }
/// <summary>
/// 销售帐号
/// </summary>
public string account_name { get; set; }
/// <summary>
/// 站点
/// </summary>
public string market { get; set; }
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</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" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bailun.DC.Common\Bailun.DC.Common.csproj" />
<ProjectReference Include="..\Bailun.DC.Models\Bailun.DC.Models.csproj" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.SyncFBAShippingInfo.Model
{
public class response_Data
{
public int code { get; set; }
public string msg { get; set; }
public int count { get; set; }
public List<Models.dc_base_fba_shipping_detail> data { get; set; }
}
}
using System;
namespace Bailun.DC.SyncFBAShippingInfo
{
class Program
{
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 Newtonsoft.Json;
using Bailun.DC.Common;
using Bailun.DC.Models;
using Bailun.DC.SyncFBAShippingInfo.Model;
namespace Bailun.DC.SyncFBAShippingInfo
{
public class Services
{
public void Init(DateTime day)
{
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if(cn.State== System.Data.ConnectionState.Closed)
{
cn.Open();
}
cn.Execute("delete from dc_base_fba_shipping_detail where month = '"+day.ToString("yyyy-MM")+"'");
}
//请求接口获取数据
int count = 0;
int page = 1;
int pagesize = 5000;
while(page==1||(page>1&&count>0))
{
GetPage(page, pagesize, day, ref count);
page++;
}
//生成汇总表
SaveCount(day);
}
private void GetPage(int page,int pagesize,DateTime date,ref int count)
{
try
{
var url = $"http://fund.bailuntec.com/Api/GetAmazonFbaShip?page={page}&limit={pagesize}&date={date.ToString("yyyy-MM-dd")}";
var str = Common.HttpHelper.NetHelper.Request(url);
if (!string.IsNullOrEmpty(str))
{
var json = JsonConvert.DeserializeObject<response_Data>(str);
if (json.data != null && json.data.Count > 0)
{
count = json.data.Count;
var sql = "insert dc_base_fba_shipping_detail (month,order_id,shipment_date,reporting_date,sku,currency,orderamount,createtime,seller_account,website) values ";
foreach (var item in json.data)
{
sql += $"('{date.ToString("yyyy-MM")}','{item.order_id}','{item.shipment_date.ToString("yyyy-MM-dd HH:mm:ss")}','{item.reporting_date.ToString("yyyy-MM-dd HH:mm:ss")}','{item.sku}','{item.currency}',{item.orderamount},'{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}','{item.account_name}','{item.market}'),";
}
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(sql);
Console.WriteLine($"{date.ToString("yyyy-MM-dd")} 保存第{page},每页记录数{pagesize} " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
else
{
count = 0;
}
}
}
catch (Exception ex)
{
Console.WriteLine($"保存第{page}时出现异常,异常信息:{ex.Message}," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine($"暂停10分钟后重跑");
System.Threading.Thread.Sleep(10 * 60);
GetPage(page, pagesize, date, ref count);
}
}
private void SaveCount(DateTime day)
{
}
}
}
......@@ -79,6 +79,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.DailyInventorySum
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.MonthShippingIncoming", "Bailun.DC.MonthShippingIncoming\Bailun.DC.MonthShippingIncoming.csproj", "{22B454F8-2315-4013-8170-F8FB5AD51BB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bailun.DC.SyncFBAShippingInfo", "Bailun.DC.SyncFBAShippingInfo\Bailun.DC.SyncFBAShippingInfo.csproj", "{56375C2F-C51D-481C-9668-208BD0330067}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -233,6 +235,10 @@ Global
{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
{56375C2F-C51D-481C-9668-208BD0330067}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56375C2F-C51D-481C-9668-208BD0330067}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56375C2F-C51D-481C-9668-208BD0330067}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56375C2F-C51D-481C-9668-208BD0330067}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -269,6 +275,7 @@ Global
{935E0EAE-B824-4507-9D32-6F7F959B140A} = {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}
{56375C2F-C51D-481C-9668-208BD0330067} = {AE2CE86A-8538-4142-920F-684DCF47C064}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
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