修复bug

This commit is contained in:
18942506660
2024-10-17 11:57:22 +08:00
parent 7499682041
commit a1716aa75a
10 changed files with 189 additions and 26 deletions

View File

@@ -31,6 +31,7 @@ using Google.Protobuf.Collections;
using NPOI.SS.Formula.Functions;
using System.Text.Json;
using WMS.Web.Core.Dto.LingXing;
using WMS.Web.Domain.Services.Public;
namespace WMS.Web.Api.Controllers
{
@@ -61,11 +62,13 @@ namespace WMS.Web.Api.Controllers
private readonly IRedisConcurrentProcessService _redisConcurrentProcessService;
private IInStockService _inStockService;
private readonly ILingXingService _lingXingService;
private readonly IProductInventoryService _productInventoryService;
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)
IWebHostEnvironment env, IMaterialService materialService, IOutStockRepositories outStockRepositories, IInStockService inStockService, ILingXingService lingXingService
, IProductInventoryService productInventoryService)
{
_inStockService = inStockService;
_redisConcurrentProcessService = redisConcurrentProcessService;
@@ -90,6 +93,7 @@ namespace WMS.Web.Api.Controllers
_outStockRepositories = outStockRepositories;
_env = env;
_lingXingService = lingXingService;
_productInventoryService = productInventoryService;
}
[HttpGet]
@@ -109,8 +113,11 @@ namespace WMS.Web.Api.Controllers
//string str = "{\"code\":0,\"message\":\"success\",\"error_details\":[],\"request_id\":\"7A739491-8740-01AC-304E-0203AF887AE2\",\"response_time\":\"2024-10-16 17:58:57\",\"data\":[{\"wid\":437,\"type\":1,\"name\":\"ORICO_OD\",\"is_delete\":0}],\"total\":1}";
//var ss=JsonConvert.DeserializeObject<LingXingResponse<LingXingStockResponse>>(str);
//var b = System.Text.Json.JsonSerializer.Deserialize<LingXingResponse<LingXingStockResponse>>(str);
await _lingXingService.GetStock();
//await _productInventoryService.LingXing();
//var s = await _lingXingService.GetStock();
//string str = string.Join(",", s.Data.Select(s => s.Id).ToList());
var sd= await _lingXingService.GetInventory(new LingXingInventoryRequest() { wid = "437" });
string sdsdf = sd.Message;
//List<string> list = new List<string>();
//list.Add("GD-02-15");
//list.Add("GD-01-15");

View File

@@ -4044,11 +4044,6 @@
id
</summary>
</member>
<member name="P:WMS.Web.Core.Dto.LingXing.LingXingStockResponse.JType">
<summary>
id
</summary>
</member>
<member name="P:WMS.Web.Core.Dto.LingXing.LingXingStockResponse.Name">
<summary>
name

View File

@@ -14,7 +14,7 @@ namespace WMS.Web.Core.Dto.LingXing
/// <summary>
/// 仓库Id 1,3,234,33
/// </summary>
[JsonProperty("offset")]
[JsonProperty("wid")]
public string wid { get; set; }
}
}

View File

@@ -6,7 +6,7 @@ using System.Text.Json.Serialization;
namespace WMS.Web.Core.Dto.LingXing
{
public class LingXingResponse<T>
public class LingXingResponse
{
public LingXingResponse() { }
[JsonProperty("code")]
@@ -18,6 +18,6 @@ namespace WMS.Web.Core.Dto.LingXing
[JsonProperty("total")]
public int Total { get; set; }
[JsonProperty("data")]
public List<T> Data { get; set; }
public object Data { get; set; }
}
}

View File

@@ -0,0 +1,16 @@

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core.Internal.Results;
namespace WMS.Web.Domain.IService
{
public interface IProductInventoryService
{
Task<Result> LingXing();
Task<Result> Erp();
Task<Result> JuShuiTan();
}
}

View File

@@ -0,0 +1,131 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using NPOI.POIFS.FileSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using WMS.Web.Core.Dto.Erp;
using WMS.Web.Core.Dto.Login;
using WMS.Web.Core.Internal.Results;
using WMS.Web.Domain.Entitys;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Domain.IService;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Domain.Values;
namespace WMS.Web.Domain.Services
{
public class ProductInventoryService : IProductInventoryService
{
private readonly IErpService _erpService;
private readonly ISingleDataService _singleDataService;
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
private readonly IProductInventoryRepositories _repositories;
private readonly ILingXingService _lingXingService;
private readonly IBasicsRepositories _basicsRepositories;
public readonly IBasicsRepositories _transactionRepositories;
public ProductInventoryService(IErpService erpService,
ISingleDataService singleDataService,
IErpBasicDataExtendService erpBasicDataExtendService,
IProductInventoryRepositories repositories,
ILingXingService lingXingService,
IBasicsRepositories basicsRepositories,
IBasicsRepositories transactionRepositories)
{
_erpService = erpService;
_singleDataService = singleDataService;
_erpBasicDataExtendService = erpBasicDataExtendService;
_repositories = repositories;
_lingXingService = lingXingService;
_basicsRepositories = basicsRepositories;
_transactionRepositories = transactionRepositories;
}
public Task<Result> Erp()
{
throw new NotImplementedException();
}
public Task<Result> JuShuiTan()
{
throw new NotImplementedException();
}
public async Task<Result> LingXing()
{
//获取单点配置
var r = await _basicsRepositories.GetUcStockByHeadOfficeAsync("", 1);
var listNames = r.Where(w =>
w.ManagementSystem == 3 && !string.IsNullOrEmpty(w.WarehouseCodeOfLingxing))
.Select(s => s.WarehouseCodeOfLingxing)
.ToList();
//获取领星仓库
var resStock = await _lingXingService.GetStock();
if (!resStock.IsSuccess) return resStock;
var ids = resStock.Data.Where(w => listNames.Contains(w.Name)).Select(s => s.Id).ToList();
string strIds = string.Join(",", ids);
//获取领星库存
var resInventory = await _lingXingService.GetInventory(new Core.Dto.LingXing.LingXingInventoryRequest() { wid = strIds });
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));
if (m == null) continue;
//找仓库
var l_stock = resStock.Data.FirstOrDefault(f => f.Id == item.StockId);
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.LingXing,
MaterialNumber = m.MaterialNumber,
Customer = item.SellerId,
OrgCode = stock.Code,
StockCode = stock.ErpOrgCode,
Qty = item.Product_Valid_Num,
BeforeQty = item.Product_Total
};
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();
}
}
}

View File

@@ -75,10 +75,10 @@ namespace WMS.Web.Domain.Services.Public
var resUrl = await GetStr<LingXingRequest>("/erp/sc/data/local_inventory/warehouse", request);
if (!resUrl.IsSuccess) return Result<List<LingXingStockResponse>>.ReFailure(ResultCodes.LingXingUrlError);
var res = await _httpClientService.PostAsync<LingXingResponse<LingXingStockResponse>>(resUrl.Data, JsonConvert.SerializeObject(request), null);
var res = await _httpClientService.PostAsync<LingXingResponse>(resUrl.Data, JsonConvert.SerializeObject(request), null);
if (res.Code != 0) return Result<List<LingXingStockResponse>>.ReFailure(ResultCodes.LingXingDataError);
return Result<List<LingXingStockResponse>>.ReSuccess(res.Data);
return Result<List<LingXingStockResponse>>.ReSuccess(JsonConvert.DeserializeObject<List<LingXingStockResponse>>(res.Data.ToString()));
}
/// <summary>
/// 获取即使库存
@@ -88,13 +88,25 @@ namespace WMS.Web.Domain.Services.Public
/// <exception cref="NotImplementedException"></exception>
public async Task<Result<List<LingXingInventoryResponse>>> GetInventory(LingXingInventoryRequest dto)
{
var resUrl = await GetStr<LingXingRequest>("/erp/sc/routing/data/local_inventory/inventoryDetails", dto);
var resUrl = await GetStr<LingXingInventoryRequest>("/erp/sc/routing/data/local_inventory/inventoryDetails", dto);
if (!resUrl.IsSuccess) return Result<List<LingXingInventoryResponse>>.ReFailure(ResultCodes.LingXingUrlError);
var res = await _httpClientService.PostAsync<LingXingResponse<LingXingInventoryResponse>>(resUrl.Data, JsonConvert.SerializeObject(dto), null);
List<LingXingInventoryResponse> list = new List<LingXingInventoryResponse>();
var res = await _httpClientService.PostAsync<LingXingResponse>(resUrl.Data, JsonConvert.SerializeObject(dto), null);
if (res.Code != 0) return Result<List<LingXingInventoryResponse>>.ReFailure(ResultCodes.LingXingDataError);
list.AddRange(JsonConvert.DeserializeObject<List<LingXingInventoryResponse>>(res.Data.ToString()));
return Result<List<LingXingInventoryResponse>>.ReSuccess(res.Data);
int num = res.Total / 800;
for (int i = 1; i <= num; i++)
{
dto.offset = i;
if (i == num) dto.length = res.Total - (num * 800);
resUrl = await GetStr<LingXingInventoryRequest>("/erp/sc/routing/data/local_inventory/inventoryDetails", dto);
if (!resUrl.IsSuccess) return Result<List<LingXingInventoryResponse>>.ReFailure(ResultCodes.LingXingUrlError);
res = await _httpClientService.PostAsync<LingXingResponse>(resUrl.Data, JsonConvert.SerializeObject(dto), null);
if (res.Code != 0) return Result<List<LingXingInventoryResponse>>.ReFailure(ResultCodes.LingXingDataError);
list.AddRange(JsonConvert.DeserializeObject<List<LingXingInventoryResponse>>(res.Data.ToString()));
}
return Result<List<LingXingInventoryResponse>>.ReSuccess(list.Where(w => w.Product_Total > 0 && w.Product_Valid_Num > 0).ToList());
}
#region
public async Task<Result<string>> GetStr<T>(string urlStr, T data)

View File

@@ -348,7 +348,7 @@ namespace WMS.Web.Repositories.DependencyInjection
Services.AddTransient<IMaterialService, MaterialService>();
Services.AddTransient<IRedisConcurrentProcessService, RedisConcurrentProcessService>();
Services.AddTransient<ILingXingService, LingXingService>();
Services.AddTransient<IProductInventoryService, ProductInventoryService>();
}
}

View File

@@ -8,6 +8,7 @@ using WMS.Web.Core.Dto.Inventory;
using WMS.Web.Core.Dto.MoveBoxRecord;
using WMS.Web.Core.Dto.OutStock;
using WMS.Web.Core.Dto.OutStockTask;
using WMS.Web.Core.Dto.ProductInventory;
using WMS.Web.Core.Dto.TakeStock;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Repositories;
@@ -57,6 +58,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddTransient<IAllFielRepositories<InventoryInOutDetailsQueryRequest>, InventoryInOutDetailsRepositories>();
services.AddTransient<IAllFielRepositories<BoxInventoryQueryRequest>, BoxInventoryRepositories>();
services.AddTransient<IAllFielRepositories<BackRecordQueryRequest>, BackRecordRepositories>();
services.AddTransient<IAllFielRepositories<ProductInventoryQueryRequest>, ProductInventoryRepositories>();
#endregion