Commit a78735c4 by lizefeng

新增缺货推送服务

parent aaf812d8
......@@ -27,7 +27,10 @@ t4.estimated_arrival_time,
t4.purchase_id,
t3.sku_title_cn,
(case when ( ifnull(t4.count,0)>0) and now()>t4.estimated_arrival_time then 1 else 0 end) as 'is_overdue',
t4.deliver_name
t4.deliver_name,
t2.history_sevenday_sales,
t2.history_fourteenday_sales,
t2.history_thirtyday_sales
from
dc_auto_forecast_fluctuation as t1
inner JOIN dc_auto_turnover as t2 on t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
......@@ -40,7 +43,10 @@ where 1 = 1
else
{
sql = @"
select t1.*,t3.sku_title_cn from dc_auto_forecast_fluctuation as t1
select t1.*,t3.sku_title_cn,
t2.history_sevenday_sales,
t2.history_fourteenday_sales,
t2.history_thirtyday_sales from dc_auto_forecast_fluctuation as t1
inner JOIN dc_auto_turnover as t2 on t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku
left join dc_base_warehouse as dbw on t1.warehouse_code = dbw.warehouse_code
......
......@@ -447,6 +447,49 @@ where ( t_db.hq_type!='国内仓' or t2.buyer_name not in ('张莹霞','张莹
}
/// <summary>
/// 缺货推送
/// </summary>
public static List<dc_auto_shortage_push> ShortagePush()
{
var conn = _connection;
var shortage_list = new List<dc_auto_shortage_push>();
// 缺货推送
string sql = @"select
t1.bailun_sku,
t1.warehouse_code,
now() as 'push_date',
1 as 'type'
from dc_mid_transit as t1
left join dc_base_sku as t2 on t1.bailun_sku = t2.bailun_sku
left join dc_base_warehouse as t_db on t1.warehouse_code = t_db.warehouse_code
left join china_warehouse_stock as t3 on t1.bailun_sku = t3.bailun_sku and t_db.hq_type='国内仓'
left join china_warehouse_unshipped as t4 on t1.bailun_sku = t4.bailun_sku and t_db.hq_type='国内仓'
where ( t_db.hq_type!='国内仓' or t2.buyer_name not in ('张莹霞','张莹霞1') ) and t_db.hq_type!='fba仓' and (case when t_db.hq_type='国内仓' then (ifnull(t4.sum_unshipped_quantity,0) - ifnull(t3.sum_usable_stock,0)) else t1.quantity_out_stock end )>0
and not exists ( select * from dc_auto_shortage_push where dc_auto_shortage_push.warehouse_code = t1.warehouse_code and dc_auto_shortage_push.bailun_sku = t1.bailun_sku )";
shortage_list.AddRange(conn.Query<dc_auto_shortage_push>(sql,commandTimeout: 0));
// 0库存推送
string no_library_sql = @"select t1.bailun_sku,
t1.warehouse_code,
now() as 'push_date',
2 as 'type' from dc_base_stock as t1 where t1.usable_stock<=0 and t1.bailun_sku!=''
and not exists ( select * from dc_auto_shortage_push where dc_auto_shortage_push.warehouse_code = t1.warehouse_code and dc_auto_shortage_push.bailun_sku = t1.bailun_sku )";
shortage_list.AddRange(conn.Query<dc_auto_shortage_push>(no_library_sql,commandTimeout: 0));
return shortage_list;
}
public static void AddShortagePush(IEnumerable<dc_auto_shortage_push> datas)
{
var conn = _connection;
foreach (var item in datas)
{
conn.Insert(item);
}
}
/// <summary>
/// 回货速改
/// </summary>
/// <param name="m"></param>
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.ApiDto
{
public class ShortagePush_RequestDto
{
public List<ShortagePush_Item_RequestDto> amisSkuInfos { get; set;}
}
public class ShortagePush_Item_RequestDto
{
public string sku { get; set; }
public string warehouseCode { get; set; }
}
public class ShortagePush_ResponseDto
{
public bool isSucceeded { get; set; }
public string message { get; set; }
public List<ShortagePush_Item_RequestDto> objData { get; set;}
public string redirectUrl { get; set; }
}
}
......@@ -118,6 +118,21 @@ namespace AutoTurnOver.Models
public string buyer_name { get; set; }
public string deliver_name { get; set; }
/// <summary>
/// 最近7日日均
/// </summary>
public decimal history_sevenday_sales { get; set; }
/// <summary>
/// 最近14日日均
/// </summary>
public decimal history_fourteenday_sales { get; set; }
/// <summary>
/// 最近30日日均
/// </summary>
public decimal history_thirtyday_sales { get; set; }
}
public class dc_auto_forecast_fluctuation_search_dto
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
/// <summary>
/// 缺货推送
/// </summary>
public class dc_auto_shortage_push
{
public int id { get; set; }
public string bailun_sku { get; set; }
public string warehouse_code { get; set; }
/// <summary>
/// 推送时间
/// </summary>
public DateTime push_date { get; set; }
/// <summary>
/// 类型
///1 = 缺货
///2 = 0 库存
/// </summary>
public int type { get; set; }
}
}
......@@ -193,9 +193,9 @@ namespace AutoTurnOver.Services
});
throw;
}
}
......@@ -338,7 +338,7 @@ namespace AutoTurnOver.Services
/// <returns></returns>
public static List<crm_message_custom_template_dto> MessageCustomTemplateList()
{
string url = ConfigHelper.GetValue("Crm_Message_Custom_Template");
string resultStr = HttpHelper.Request(url, RequestType.POST, "", timeout: 1000 * 60 * 60 * 24);
var result = resultStr.ToObj<crm_api_result_dto<List<crm_message_custom_template_dto>>>();
......@@ -360,7 +360,7 @@ namespace AutoTurnOver.Services
{
//查询采购建议明细
string url = ConfigHelper.GetValue("CRM_SendMessage");
string resultStr = HttpHelper.Request(url, RequestType.POST, data.ToJson(), timeout: 1000 * 60 * 60 * 24,entype:"application/json");
string resultStr = HttpHelper.Request(url, RequestType.POST, data.ToJson(), timeout: 1000 * 60 * 60 * 24, entype: "application/json");
var result = resultStr.ToObj<crm_api_result_null_dto>();
if (result == null)
{
......@@ -373,5 +373,47 @@ namespace AutoTurnOver.Services
return;
}
/// <summary>
/// 缺货推送 (分页推送)
/// </summary>
public static List<ShortagePush_Item_RequestDto> ShortagePush(List<dc_auto_shortage_push> datas)
{
var err_datas = new List<ShortagePush_Item_RequestDto>();
if (datas.Count <= 0) return new List<ShortagePush_Item_RequestDto>() ;
int page = 1;
int rows = 1000;
int totalPage = (int)Math.Ceiling(datas.Count * 1.0 / rows);
while (page <= totalPage)
{
var result = ShortagePushApi(new ShortagePush_RequestDto { amisSkuInfos = datas.Skip((page - 1) * rows).Take(rows).Select(s=>new ShortagePush_Item_RequestDto {
sku = s.bailun_sku,
warehouseCode = s.warehouse_code
}).ToList()} );
if(!result.isSucceeded && result.objData.Count >= 1)
{
err_datas.AddRange(result.objData);
}
page++;
}
return err_datas;
}
/// <summary>
/// 缺货推送
/// </summary>
private static ShortagePush_ResponseDto ShortagePushApi(ShortagePush_RequestDto data)
{
string url = ConfigHelper.GetValue("PPS_ShortagePush");
string resultStr = HttpHelper.Request(url, RequestType.POST, data.ToJson(), timeout: 1000 * 60 * 60 * 24, entype: "application/json");
var result = resultStr.ToObj<ShortagePush_ResponseDto>();
if (result == null)
{
throw new Exception("刊登系统异常: 推送失败");
}
return result;
}
}
}
......@@ -442,6 +442,16 @@ namespace AutoTurnOver.Services
return result_data;
}
/// <summary>
/// 缺货推送
/// </summary>
public void ShortagePush()
{
var datas = report.ShortagePush();
var err_datas = ApiServices.ShortagePush(datas);
// 记录推送状态
report.AddShortagePush(datas.Where(s=> !err_datas.Any(e=>e.warehouseCode==s.warehouse_code && s.bailun_sku==e.sku )));
}
}
}
......@@ -19,7 +19,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoTurnOver.Purchase.Avera
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGeneratePurchaseAdvise", "AutoGeneratePurchaseAdvise\AutoGeneratePurchaseAdvise.csproj", "{350405A0-13DF-4F20-8B3F-0AB923BE9DFF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResetOutofstock", "ResetOutofstock\ResetOutofstock.csproj", "{6DD5D4C8-5DAC-4327-9C8A-08B6CCD6713D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ResetOutofstock", "ResetOutofstock\ResetOutofstock.csproj", "{6DD5D4C8-5DAC-4327-9C8A-08B6CCD6713D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortagePush", "ShortagePush\ShortagePush.csproj", "{87123947-1F13-4EBE-8667-AEB2CFB07738}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -59,6 +61,10 @@ Global
{6DD5D4C8-5DAC-4327-9C8A-08B6CCD6713D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DD5D4C8-5DAC-4327-9C8A-08B6CCD6713D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DD5D4C8-5DAC-4327-9C8A-08B6CCD6713D}.Release|Any CPU.Build.0 = Release|Any CPU
{87123947-1F13-4EBE-8667-AEB2CFB07738}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87123947-1F13-4EBE-8667-AEB2CFB07738}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87123947-1F13-4EBE-8667-AEB2CFB07738}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87123947-1F13-4EBE-8667-AEB2CFB07738}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -67,6 +73,7 @@ Global
{DD5C8D24-7098-4708-A1AC-ACFBB5EBBD6C} = {C1F6DDE1-217D-43D6-81B5-91A7E78A7876}
{350405A0-13DF-4F20-8B3F-0AB923BE9DFF} = {C1F6DDE1-217D-43D6-81B5-91A7E78A7876}
{6DD5D4C8-5DAC-4327-9C8A-08B6CCD6713D} = {C1F6DDE1-217D-43D6-81B5-91A7E78A7876}
{87123947-1F13-4EBE-8667-AEB2CFB07738} = {C1F6DDE1-217D-43D6-81B5-91A7E78A7876}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {09B3C433-2F6E-498C-AB7C-2931F260C5CE}
......
......@@ -62,7 +62,7 @@ namespace AutoTurnOver.Controllers
var list = service.List(m, 0, int.MaxValue, ref total, order, sort);
DataTable table = new DataTable();
string[] cols = new string[] { "Sku","中文名称","仓库编码","仓库名称","最近3日日均","异常类型","开始时间",
string[] cols = new string[] { "Sku","中文名称","仓库编码","仓库名称","最近3日日均","最近7日日均","最近14日日均","最近30日日均","异常类型","开始时间",
"总缺货数","在途数量","采购员","预计到货","bi 采购单号","供应商","逾期状态",
"结束时间","是否确认","确认人","预计解决时间",
"处理方案","是否解决"
......@@ -81,6 +81,9 @@ namespace AutoTurnOver.Controllers
row["仓库编码"] = itemData.warehouse_code;
row["仓库名称"] = itemData.warehouse_name;
row["最近3日日均"] = itemData.avg_sales_three;
row["最近7日日均"] = itemData.history_sevenday_sales;
row["最近14日日均"] = itemData.history_fourteenday_sales;
row["最近30日日均"] = itemData.history_thirtyday_sales;
row["异常类型"] = itemData.bailun_sku;
row["开始时间"] = itemData.typeStr;
......
......@@ -26,5 +26,6 @@
"Lms_GetLogistics": "http://lms.bailuntec.com/api/DataInfo/ApiLogistics/GetLogistics",
"Pams_PlatformList": "http://pams.bailuntec.com/Api/GetPlatformSites?type=1",
"Crm_Message_Custom_Template": "http://crm.bailuntec.com/api/MessageCustomTemplateList",
"CRM_SendMessage": "http://kefu.bailuntec.com/api/SendMessage"
"CRM_SendMessage": "http://kefu.bailuntec.com/api/SendMessage",
"PPS_ShortagePush": ""
}
......@@ -8,5 +8,6 @@
"Port": "6379",
"Password": "",
"Defaultdatabase": "0"
}
},
"PPS_ShortagePush": "http://bltpro.bailuntec.com/api/EbayTask/PushSkuEditQtyTask"
}
{
"ConnectionStrings": {
"Default": "server=10.0.8.15;port=3306;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;"
}
},
"PPS_ShortagePush": "http://10.0.6.8:8002/api/EbayTask/PushSkuEditQtyTask"
}
\ No newline at end of file
FROM microsoft/dotnet:2.1-runtime-alpine 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-alpine AS build
WORKDIR /src
COPY ShortagePush/ShortagePush.csproj ShortagePush/
COPY AutoTurnOver.Services/AutoTurnOver.Services.csproj AutoTurnOver.Services/
COPY AutoTurnOver.DB/AutoTurnOver.DB.csproj AutoTurnOver.DB/
COPY AutoTurnOver.Utility/AutoTurnOver.Utility.csproj AutoTurnOver.Utility/
COPY AutoTurnOver.Models/AutoTurnOver.Models.csproj AutoTurnOver.Models/
RUN dotnet restore ShortagePush/ShortagePush.csproj
COPY . .
WORKDIR /src/ShortagePush
RUN dotnet build ShortagePush.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish ShortagePush.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ShortagePush.dll"]
using AutoTurnOver.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;
namespace ShortagePush
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("推送缺货数据服务");
new ReportServices().ShortagePush();
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ShortagePushBackgroundService>();
});
await builder.RunConsoleAsync();
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutoTurnOver.Services\AutoTurnOver.Services.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.dev.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.prod.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
using AutoTurnOver.Services;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ShortagePush
{
public class ShortagePushBackgroundService : 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 == 15 && now.Minute == 1)
{
Console.WriteLine($"开始推送缺货数据任务,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
new ReportServices().ShortagePush();
Console.WriteLine($"结束推送缺货数据任务,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public override void Dispose()
{
base.Dispose();
_timer?.Dispose();
}
}
}
{
"ConnectionStrings": {
"Default": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;"
},
"Pams_GetAccountToken": "http://pams.bailuntec.com/Api/GetAccountToken",
"redis": {
"HostName": "127.0.0.1",
"Port": "6379",
"Password": "SpaceHorse1",
"Defaultdatabase": "0"
}
}
{
"ConnectionStrings": {
"Default": "server=gz-cdb-kp7s5i79.sql.tencentcdb.com;port=61691;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;"
},
"Pams_GetAccountToken": "http://pams.bailuntec.com/Api/GetAccountToken",
"redis": {
"HostName": "127.0.0.1",
"Port": "6379",
"Password": "",
"Defaultdatabase": "0"
},
"PPS_ShortagePush": "http://bltpro.bailuntec.com/api/EbayTask/PushSkuEditQtyTask"
}
{
"ConnectionStrings": {
"Default": "server=10.0.8.15;port=3306;database=bailun_datacenter;uid=root;password=#7kfnymAM$Y9-Ntf;"
},
"PPS_ShortagePush": "http://10.0.6.8:8002/api/EbayTask/PushSkuEditQtyTask"
}
\ No newline at end of file
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