聚水潭接口对接
This commit is contained in:
@@ -63,12 +63,13 @@ namespace WMS.Web.Api.Controllers
|
||||
private IInStockService _inStockService;
|
||||
private readonly ILingXingService _lingXingService;
|
||||
private readonly IProductInventoryService _productInventoryService;
|
||||
private readonly IJuShuiTanService _juShuiTanService;
|
||||
public TestController(IErpService erpService, IInStockTaskService inStockTaskService, IBoxInventoryRepositories boxInventoryRepositories, IRedisConcurrentProcessService redisConcurrentProcessService,
|
||||
IBasicsRepositories transactionRepositories, IOpsService opsService, IBoxService boxService, IBasicsRepositories basicsRepositories, IMemoryCache memoryCache,
|
||||
IOutStockTaskRepositories outStockTaskRepositories, IOutStockTaskService outStockTaskService, IOptions<AppOptions> options, ILoginService loginService, ISendMessageService sendMessageService,
|
||||
ITakeStockService takeStockService, ITakeStockRepositories takeStockRepositories, IOutStockService outStockService, IInStockTaskRepositories inStockTaskRepositories,
|
||||
IWebHostEnvironment env, IMaterialService materialService, IOutStockRepositories outStockRepositories, IInStockService inStockService, ILingXingService lingXingService
|
||||
, IProductInventoryService productInventoryService)
|
||||
, IProductInventoryService productInventoryService, IJuShuiTanService juShuiTanService)
|
||||
{
|
||||
_inStockService = inStockService;
|
||||
_redisConcurrentProcessService = redisConcurrentProcessService;
|
||||
@@ -94,6 +95,7 @@ namespace WMS.Web.Api.Controllers
|
||||
_env = env;
|
||||
_lingXingService = lingXingService;
|
||||
_productInventoryService = productInventoryService;
|
||||
_juShuiTanService = juShuiTanService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -108,10 +110,12 @@ namespace WMS.Web.Api.Controllers
|
||||
//var m2 = my2.Object;
|
||||
//var md = m2.code;
|
||||
|
||||
List<(string orgCode, string stockCode)> request = new List<(string orgCode, string stockCode)>();
|
||||
request.Add(("101", "CK001"));
|
||||
request.Add(("101", "CK002"));
|
||||
var list = await _erpService.BillQueryForInventory(request);
|
||||
//List<(string orgCode, string stockCode)> request = new List<(string orgCode, string stockCode)>();
|
||||
//request.Add(("101", "CK001"));
|
||||
//request.Add(("101", "CK002"));
|
||||
//var list = await _erpService.BillQueryForInventory(request);
|
||||
|
||||
await _juShuiTanService.GetTest();
|
||||
|
||||
//LingXingResponse<LingXingStockResponse> r = new LingXingResponse<LingXingStockResponse>();
|
||||
|
||||
|
||||
@@ -51,6 +51,12 @@
|
||||
"AppId": "ak_QGK2J8TssERmu",
|
||||
"AppSecret": "n/HUKD2wVdTbvhnFZbVBPw=="
|
||||
},
|
||||
"JuShuiTanOptions": {
|
||||
"Url": "https://openapi.jushuitan.com",
|
||||
"AppKey": "17231841286c45f99eb9acf445404349",
|
||||
"AppSecret": "5ce9641ae6db4abb8b96eea7df6a81e9",
|
||||
"AccessToken": "4605358c37374780a8a4395e6cdb1c3f" //一年后过期(2025/10/18)
|
||||
},
|
||||
"Qiniu": {
|
||||
"AccessKey": "dOsTum4a5qvhPTBbZRPX0pIOU7PZWRX7htKjztms",
|
||||
"SecretKey": "KFxsGbnErkALFfeGdMa8QWTdodJbamMX0iznLe-q",
|
||||
|
||||
@@ -3979,6 +3979,92 @@
|
||||
wms箱ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryRequst.page_index">
|
||||
<summary>
|
||||
页码
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryRequst.page_size">
|
||||
<summary>
|
||||
页条数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryRequst.wms_co_id">
|
||||
<summary>
|
||||
仓库Id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryRequst.modified_begin">
|
||||
<summary>
|
||||
开始时间
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryRequst.modified_end">
|
||||
<summary>
|
||||
结算时间
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryResponse.sku_id">
|
||||
<summary>
|
||||
商品
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryResponse.qty">
|
||||
<summary>
|
||||
总量
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryResponse.ky_qty">
|
||||
<summary>
|
||||
可用数:可用数[同步线上的库存数]=
|
||||
主仓实际库存-订单占有数+虚拟库存+采购在途(业务设置)+进货仓(业务设置)+销退仓库存(业务设置)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryResponse.order_lock">
|
||||
<summary>
|
||||
订单占有数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryResponse.virtual_qty">
|
||||
<summary>
|
||||
虚拟库存
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryResponse.purchase_qty">
|
||||
<summary>
|
||||
采购在途
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryResponse.return_qty">
|
||||
<summary>
|
||||
销退仓库存
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanInventoryResponse.in_qty">
|
||||
<summary>
|
||||
进货仓
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanStockRequst.page_index">
|
||||
<summary>
|
||||
页码
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanStockRequst.page_size">
|
||||
<summary>
|
||||
页条数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanStockResponse.Id">
|
||||
<summary>
|
||||
仓库id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.JuShuiTan.JuShuiTanStockResponse.Name">
|
||||
<summary>
|
||||
仓库名
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Core.Dto.LingXing.LingXingInventoryRequest">
|
||||
<summary>
|
||||
领星即时库存
|
||||
|
||||
@@ -5821,6 +5821,25 @@
|
||||
<param name="list"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Services.ProductInventoryService.Erp">
|
||||
<summary>
|
||||
金蝶
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Services.ProductInventoryService.JuShuiTan">
|
||||
<summary>
|
||||
聚水潭
|
||||
</summary>
|
||||
<returns></returns>
|
||||
<exception cref="T:System.NotImplementedException"></exception>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Services.ProductInventoryService.LingXing">
|
||||
<summary>
|
||||
领星
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Services.Public.ErpBaseDataSync">
|
||||
<summary>
|
||||
同步erp基础数据
|
||||
@@ -6299,6 +6318,11 @@
|
||||
<param name="timeoutSecond"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Services.Public.JuShuiTanService.PostUrl(System.String,System.String)">
|
||||
<summary>
|
||||
调用接口
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Services.Public.LingXingService">
|
||||
<summary>
|
||||
领星服务接口
|
||||
|
||||
36
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanInventoryRequst.cs
Normal file
36
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanInventoryRequst.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto.JuShuiTan
|
||||
{
|
||||
public class JuShuiTanInventoryRequst
|
||||
{
|
||||
/// <summary>
|
||||
/// 页码
|
||||
/// </summary>
|
||||
[JsonProperty("page_index")]
|
||||
public int page_index { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// 页条数
|
||||
/// </summary>
|
||||
[JsonProperty("page_size")]
|
||||
public int page_size { get; set; } = 30;
|
||||
/// <summary>
|
||||
/// 仓库Id
|
||||
/// </summary>
|
||||
[JsonProperty("wms_co_id")]
|
||||
public int wms_co_id { get; set; }
|
||||
/// <summary>
|
||||
/// 开始时间
|
||||
/// </summary>
|
||||
[JsonProperty("modified_begin")]
|
||||
public string modified_begin { get; set; }
|
||||
/// <summary>
|
||||
/// 结算时间
|
||||
/// </summary>
|
||||
[JsonProperty("modified_end")]
|
||||
public string modified_end { get; set; }
|
||||
}
|
||||
}
|
||||
55
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanInventoryResponse.cs
Normal file
55
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanInventoryResponse.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Ubiety.Dns.Core.Common;
|
||||
|
||||
namespace WMS.Web.Core.Dto.JuShuiTan
|
||||
{
|
||||
public class JuShuiTanInventoryResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品
|
||||
/// </summary>
|
||||
[JsonProperty("sku_id")]
|
||||
public string sku_id { get; set; }
|
||||
[JsonProperty("wms_co_id")]
|
||||
public int wms_co_id { get; set; }
|
||||
/// <summary>
|
||||
/// 总量
|
||||
/// </summary>
|
||||
[JsonProperty("qty")]
|
||||
public int? qty { get; set; }
|
||||
/// <summary>
|
||||
/// 可用数:可用数[同步线上的库存数]=
|
||||
/// 主仓实际库存-订单占有数+虚拟库存+采购在途(业务设置)+进货仓(业务设置)+销退仓库存(业务设置)
|
||||
/// </summary>
|
||||
[JsonProperty("ky_qty")]
|
||||
public int ky_qty { get; set; }
|
||||
/// <summary>
|
||||
/// 订单占有数
|
||||
/// </summary>
|
||||
[JsonProperty("order_lock")]
|
||||
public int? order_lock { get; set; }
|
||||
/// <summary>
|
||||
/// 虚拟库存
|
||||
/// </summary>
|
||||
[JsonProperty("virtual_qty")]
|
||||
public int? virtual_qty { get; set; }
|
||||
/// <summary>
|
||||
/// 采购在途
|
||||
/// </summary>
|
||||
[JsonProperty("purchase_qty")]
|
||||
public int? purchase_qty { get; set; }
|
||||
/// <summary>
|
||||
/// 销退仓库存
|
||||
/// </summary>
|
||||
[JsonProperty("return_qty")]
|
||||
public int? return_qty { get; set; }
|
||||
/// <summary>
|
||||
/// 进货仓
|
||||
/// </summary>
|
||||
[JsonProperty("in_qty")]
|
||||
public int? in_qty { get; set; }
|
||||
}
|
||||
}
|
||||
21
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanStockRequst.cs
Normal file
21
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanStockRequst.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto.JuShuiTan
|
||||
{
|
||||
public class JuShuiTanStockRequst
|
||||
{
|
||||
/// <summary>
|
||||
/// 页码
|
||||
/// </summary>
|
||||
[JsonProperty("page_index")]
|
||||
public int page_index { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// 页条数
|
||||
/// </summary>
|
||||
[JsonProperty("page_size")]
|
||||
public int page_size { get; set; } = 30;
|
||||
}
|
||||
}
|
||||
13
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanStockResResponse.cs
Normal file
13
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanStockResResponse.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto.JuShuiTan
|
||||
{
|
||||
public class JuShuiTanStockResResponse
|
||||
{
|
||||
public int code { get; set; }
|
||||
public string msg { get; set; }
|
||||
public object data { get; set; }
|
||||
}
|
||||
}
|
||||
21
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanStockResponse.cs
Normal file
21
src/WMS.Web.Core/Dto/JuShuiTan/JuShuiTanStockResponse.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto.JuShuiTan
|
||||
{
|
||||
public class JuShuiTanStockResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 仓库id
|
||||
/// </summary>
|
||||
[JsonProperty("wms_co_id")]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 仓库名
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
16
src/WMS.Web.Domain/IService/Public/IJuShuiTanService.cs
Normal file
16
src/WMS.Web.Domain/IService/Public/IJuShuiTanService.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.JuShuiTan;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
|
||||
namespace WMS.Web.Domain.IService.Public
|
||||
{
|
||||
public interface IJuShuiTanService
|
||||
{
|
||||
Task GetTest();
|
||||
Task<Result<List<JuShuiTanStockResponse>>> GetStock();
|
||||
Task<Result<List<JuShuiTanInventoryResponse>>> GetInventory(List<int> StockId);
|
||||
}
|
||||
}
|
||||
14
src/WMS.Web.Domain/Options/JuShuiTanOptions.cs
Normal file
14
src/WMS.Web.Domain/Options/JuShuiTanOptions.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Domain.Options
|
||||
{
|
||||
public class JuShuiTanOptions
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public string AppKey { get; set; }
|
||||
public string AppSecret { get; set; }
|
||||
public string AccessToken { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -27,13 +27,15 @@ namespace WMS.Web.Domain.Services
|
||||
private readonly ILingXingService _lingXingService;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
public readonly IBasicsRepositories _transactionRepositories;
|
||||
public readonly IJuShuiTanService _juShuiTanService;
|
||||
public ProductInventoryService(IErpService erpService,
|
||||
ISingleDataService singleDataService,
|
||||
IErpBasicDataExtendService erpBasicDataExtendService,
|
||||
IProductInventoryRepositories repositories,
|
||||
ILingXingService lingXingService,
|
||||
IBasicsRepositories basicsRepositories,
|
||||
IBasicsRepositories transactionRepositories)
|
||||
IBasicsRepositories transactionRepositories,
|
||||
IJuShuiTanService juShuiTanService)
|
||||
{
|
||||
_erpService = erpService;
|
||||
_singleDataService = singleDataService;
|
||||
@@ -42,9 +44,13 @@ namespace WMS.Web.Domain.Services
|
||||
_lingXingService = lingXingService;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_transactionRepositories = transactionRepositories;
|
||||
_juShuiTanService = juShuiTanService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 金蝶
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> Erp()
|
||||
{
|
||||
//获取单点配置
|
||||
@@ -93,12 +99,85 @@ namespace WMS.Web.Domain.Services
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
|
||||
public Task<Result> JuShuiTan()
|
||||
/// <summary>
|
||||
/// 聚水潭
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<Result> JuShuiTan()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
//获取单点配置
|
||||
var r = await _basicsRepositories.GetUcStockByHeadOfficeAsync("", 1);
|
||||
var listNames = r.Where(w =>
|
||||
w.ManagementSystem == 2 && !string.IsNullOrEmpty(w.WarehouseCodeOfJushuitan))
|
||||
.Select(s => s.WarehouseCodeOfJushuitan)
|
||||
.ToList();
|
||||
//获取领星仓库
|
||||
var resStock = await _juShuiTanService.GetStock();
|
||||
if (!resStock.IsSuccess) return resStock;
|
||||
|
||||
var ids = resStock.Data.Where(w => listNames.Contains(w.Name)).Select(s => s.Id).ToList();
|
||||
//获取领星库存
|
||||
var resInventory = await _juShuiTanService.GetInventory(ids);
|
||||
if (!resInventory.IsSuccess) return resStock;
|
||||
|
||||
//物料
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
List<ProductInventory> inventoryList = new List<ProductInventory>();
|
||||
foreach (var item in resInventory.Data)
|
||||
{
|
||||
//如果物料不匹配 过滤
|
||||
var m = materials.FirstOrDefault(f => f.Specifications.Equals(item.sku_id));
|
||||
if (m == null) continue;
|
||||
//找仓库
|
||||
var l_stock = resStock.Data.FirstOrDefault(f => f.Id == item.wms_co_id);
|
||||
if (l_stock == null) continue;
|
||||
var stock = r.FirstOrDefault(f => f.WarehouseCodeOfLingxing.Equals(l_stock.Name));
|
||||
if (stock == null) continue;
|
||||
|
||||
var entity = new ProductInventory()
|
||||
{
|
||||
Type = ProductInventoryType.JushuiTan,
|
||||
MaterialNumber = m.MaterialNumber,
|
||||
Customer = "",
|
||||
OrgCode = stock.Code,
|
||||
StockCode = stock.ErpOrgCode,
|
||||
Qty = item.ky_qty,
|
||||
BeforeQty = item.qty ?? 0
|
||||
};
|
||||
inventoryList.Add(entity);
|
||||
}
|
||||
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
|
||||
Result res_Rollback = Result.ReSuccess();
|
||||
bool isSuccess = true;
|
||||
//修改库存
|
||||
//先删除之前的再添加
|
||||
if (res_Rollback.IsSuccess)
|
||||
{
|
||||
isSuccess = await _repositories.Delete(ProductInventoryType.LingXing, false);
|
||||
if (isSuccess == false) res_Rollback = Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
if (res_Rollback.IsSuccess)
|
||||
{
|
||||
isSuccess = await _repositories.AddRange(inventoryList, false);
|
||||
if (isSuccess == false) res_Rollback = Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
//提交事务
|
||||
isSuccess = _transactionRepositories.CommitTransaction(res_Rollback.IsSuccess ? false : true, _transaction);
|
||||
if (!res_Rollback.IsSuccess) return res_Rollback;
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
/// <summary>
|
||||
/// 领星
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> LingXing()
|
||||
{
|
||||
//获取单点配置
|
||||
|
||||
218
src/WMS.Web.Domain/Services/Public/JuShuiTanService.cs
Normal file
218
src/WMS.Web.Domain/Services/Public/JuShuiTanService.cs
Normal file
@@ -0,0 +1,218 @@
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.JuShuiTan;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
using WMS.Web.Domain.IService.Public;
|
||||
using WMS.Web.Domain.Options;
|
||||
|
||||
namespace WMS.Web.Domain.Services.Public
|
||||
{
|
||||
public class JuShuiTanService : IJuShuiTanService
|
||||
{
|
||||
private readonly IHttpClientService _httpClientService;
|
||||
private readonly ILogger<JuShuiTanService> _logger;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
private int hours = 10;//过期时间 默认10小时
|
||||
private readonly JuShuiTanOptions _option;
|
||||
|
||||
public JuShuiTanService(IHttpClientService httpClientService, ILogger<JuShuiTanService> logger,
|
||||
IMemoryCache memoryCache, IOptions<JuShuiTanOptions> option)
|
||||
{
|
||||
this._memoryCache = memoryCache;
|
||||
this._httpClientService = httpClientService;
|
||||
this._logger = logger;
|
||||
_option = option?.Value;
|
||||
}
|
||||
public async Task GetTest()
|
||||
{
|
||||
//await GetStock();
|
||||
var list = new List<int>();
|
||||
list.Add(10923342);
|
||||
await GetInventory(list);
|
||||
}
|
||||
|
||||
public async Task<Result<List<JuShuiTanStockResponse>>> GetStock()
|
||||
{
|
||||
List<JuShuiTanStockResponse> list = new List<JuShuiTanStockResponse>();
|
||||
|
||||
JuShuiTanStockRequst request = new JuShuiTanStockRequst();
|
||||
var resContent = PostUrl("/open/wms/partner/query", JsonConvert.SerializeObject(request));
|
||||
JObject resData = JObject.Parse(resContent);
|
||||
|
||||
if (Convert.ToInt32(resData["code"]) != 0)
|
||||
_logger.LogInformation($"聚水潭获取仓库失败:{resData["msg"].ToString()}");
|
||||
string json = resData["data"]["datas"].ToString();
|
||||
var datas = JsonConvert.DeserializeObject<List<JuShuiTanStockResponse>>(json);
|
||||
list.AddRange(datas);
|
||||
|
||||
int count = Convert.ToInt32(resData["data"]["page_count"]);
|
||||
for (int i = 1; i < count; i++)
|
||||
{
|
||||
request.page_index++;
|
||||
resContent = PostUrl("/open/wms/partner/query", JsonConvert.SerializeObject(request));
|
||||
resData = JObject.Parse(resContent);
|
||||
|
||||
if (Convert.ToInt32(resData["code"]) != 0)
|
||||
_logger.LogInformation($"聚水潭获取仓库失败:{resData["msg"].ToString()}");
|
||||
json = resData["data"]["datas"].ToString();
|
||||
datas = JsonConvert.DeserializeObject<List<JuShuiTanStockResponse>>(json);
|
||||
list.AddRange(datas);
|
||||
}
|
||||
return Result<List<JuShuiTanStockResponse>>.ReSuccess(list);
|
||||
}
|
||||
|
||||
|
||||
public async Task<Result<List<JuShuiTanInventoryResponse>>> GetInventory(List<int> StockId)
|
||||
{
|
||||
List<JuShuiTanInventoryResponse> list = new List<JuShuiTanInventoryResponse>();
|
||||
foreach (var id in StockId)
|
||||
{
|
||||
JuShuiTanInventoryRequst request = new JuShuiTanInventoryRequst();
|
||||
request.wms_co_id = id;//10923342;
|
||||
request.page_size = 100;
|
||||
request.modified_begin = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
request.modified_end = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
var resContent = PostUrl("/open/inventory/query", JsonConvert.SerializeObject(request));
|
||||
JObject resData = JObject.Parse(resContent);
|
||||
|
||||
if (Convert.ToInt32(resData["code"]) != 0)
|
||||
_logger.LogInformation($"聚水潭获取即时库存失败:{resData["msg"].ToString()}");
|
||||
string json = resData["data"]["inventorys"].ToString();
|
||||
var datas = JsonConvert.DeserializeObject<List<JuShuiTanInventoryResponse>>(json);
|
||||
list.AddRange(datas);
|
||||
|
||||
int count = Convert.ToInt32(resData["data"]["page_count"]);
|
||||
for (int i = 1; i < count; i++)
|
||||
{
|
||||
request.page_index++;
|
||||
resContent = PostUrl("/open/inventory/query", JsonConvert.SerializeObject(request));
|
||||
resData = JObject.Parse(resContent);
|
||||
|
||||
if (Convert.ToInt32(resData["code"]) != 0)
|
||||
_logger.LogInformation($"聚水潭获取即时库存失败:{resData["msg"].ToString()}");
|
||||
json = resData["data"]["inventorys"].ToString();
|
||||
datas = JsonConvert.DeserializeObject<List<JuShuiTanInventoryResponse>>(json);
|
||||
list.AddRange(datas);
|
||||
}
|
||||
}
|
||||
//主仓实际库存-订单占有数+虚拟库存+采购在途(业务设置)+进货仓(业务设置)+销退仓库存(业务设置)
|
||||
foreach (var item in list)
|
||||
{
|
||||
item.qty = item.qty == null ? 0 : item.qty;
|
||||
item.ky_qty = (item.qty ?? 0) - (item.order_lock ?? 0) + (item.virtual_qty ?? 0)
|
||||
+ (item.purchase_qty ?? 0) + (item.in_qty ?? 0) + (item.return_qty ?? 0);
|
||||
}
|
||||
var resList = list.Where(w => w.qty > 0 || w.ky_qty > 0).ToList();
|
||||
return Result<List<JuShuiTanInventoryResponse>>.ReSuccess(resList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调用接口
|
||||
/// </summary>
|
||||
private string PostUrl(string urlStr, string biz)
|
||||
{
|
||||
Hashtable ht = new Hashtable();
|
||||
System.DateTime starttime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
|
||||
string time = Math.Floor((System.DateTime.Now - starttime).TotalSeconds).ToString();
|
||||
string app_key = _option.AppKey;// "17231841286c45f99eb9acf445404349";
|
||||
string app_secret = _option.AppSecret;// "5ce9641ae6db4abb8b96eea7df6a81e9";
|
||||
string access_token = _option.AccessToken;// "4605358c37374780a8a4395e6cdb1c3f";
|
||||
|
||||
|
||||
//string biz = "{\"modified_begin\":\"2022-06-10 00:00:00\",\"modified_end\":\"2022-06-12 00:00:00\",\"page_index\":1,\"page_size\":30}";
|
||||
|
||||
ht.Add("access_token", access_token);
|
||||
ht.Add("app_key", app_key);
|
||||
ht.Add("biz", biz);
|
||||
ht.Add("charset", "utf-8");
|
||||
ht.Add("timestamp", time);
|
||||
ht.Add("version", "2");
|
||||
string sign = getSign(app_secret, ht);
|
||||
ht.Add("sign", sign);
|
||||
string posturl = _option.Url + urlStr;
|
||||
Encoding datacode = Encoding.UTF8;
|
||||
string paramData = GetParamData(ht);
|
||||
return PostWebRequest(posturl, paramData, datacode);
|
||||
}
|
||||
|
||||
string getSign(string signKey, Hashtable param)
|
||||
{
|
||||
|
||||
ArrayList keys = new ArrayList(param.Keys);
|
||||
keys.Sort(); //按字母顺序进行排序
|
||||
string resultStr = "";
|
||||
foreach (string key in keys)
|
||||
{
|
||||
if (key != null && key != "" && key != "sign")
|
||||
{
|
||||
resultStr = resultStr + key + param[key];
|
||||
}
|
||||
}
|
||||
resultStr = signKey + resultStr;
|
||||
MD5 md5 = MD5.Create();
|
||||
byte[] rstRes = md5.ComputeHash(Encoding.UTF8.GetBytes(resultStr));
|
||||
string hex = BitConverter.ToString(rstRes, 0).Replace("-", string.Empty).ToLower();
|
||||
|
||||
return hex;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private string PostWebRequest(string postUrl, string paramData, Encoding dataEncode)
|
||||
{
|
||||
string ret = string.Empty;
|
||||
try
|
||||
{
|
||||
|
||||
byte[] byteArray = dataEncode.GetBytes(paramData);
|
||||
//转化
|
||||
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
|
||||
webReq.Method = "POST";
|
||||
webReq.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
||||
webReq.ContentLength = byteArray.Length;
|
||||
|
||||
Stream newStream = webReq.GetRequestStream();
|
||||
newStream.Write(byteArray, 0, byteArray.Length);
|
||||
//写入参数
|
||||
newStream.Close();
|
||||
|
||||
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
|
||||
StreamReader sr = new StreamReader(response.GetResponseStream(), dataEncode);
|
||||
ret = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
response.Close();
|
||||
newStream.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private string GetParamData(Hashtable ht)
|
||||
{
|
||||
string str = "";
|
||||
foreach (DictionaryEntry items in ht)
|
||||
{
|
||||
|
||||
str += items.Key.ToString() + "=" + System.Web.HttpUtility.UrlEncode(items.Value.ToString(), System.Text.Encoding.UTF8) + "&";
|
||||
}
|
||||
|
||||
return str.Substring(0, str.Length - 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,8 @@ namespace WMS.Web.Repositories.DependencyInjection
|
||||
Services.Configure<SmsOptions>(Configuration.GetSection("SmsOptions"));
|
||||
Services.AddOptions<lingXingOptions>();
|
||||
Services.Configure<lingXingOptions>(Configuration.GetSection("LingXingOptions"));
|
||||
|
||||
Services.AddOptions<JuShuiTanOptions>();
|
||||
Services.Configure<JuShuiTanOptions>(Configuration.GetSection("JuShuiTanOptions"));
|
||||
|
||||
|
||||
}
|
||||
@@ -349,7 +350,7 @@ namespace WMS.Web.Repositories.DependencyInjection
|
||||
Services.AddTransient<IRedisConcurrentProcessService, RedisConcurrentProcessService>();
|
||||
Services.AddTransient<ILingXingService, LingXingService>();
|
||||
Services.AddTransient<IProductInventoryService, ProductInventoryService>();
|
||||
|
||||
Services.AddTransient<IJuShuiTanService, JuShuiTanService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user