修复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

@@ -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

@@ -56,7 +56,7 @@ namespace WMS.Web.Domain.Services.Public
formData.Add(new StringContent(_option.AppSecret), "appSecret");
var res = await _httpClientService.PostAsync<dynamic>(_option.Url + endStr, formData, null);
if (res.code != "200")
{
_logger.LogInformation($"领星获取授权失败:{res.msg}");
@@ -72,13 +72,13 @@ namespace WMS.Web.Domain.Services.Public
public async Task<Result<List<LingXingStockResponse>>> GetStock()
{
var request = new LingXingRequest();
var resUrl =await GetStr<LingXingRequest>("/erp/sc/data/local_inventory/warehouse", request);
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);
if (res.Code!=0) return Result<List<LingXingStockResponse>>.ReFailure(ResultCodes.LingXingDataError);
return Result<List<LingXingStockResponse>>.ReSuccess(res.Data);
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(JsonConvert.DeserializeObject<List<LingXingStockResponse>>(res.Data.ToString()));
}
/// <summary>
/// 获取即使库存
@@ -88,19 +88,31 @@ 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)
public async Task<Result<string>> GetStr<T>(string urlStr, T data)
{
var res = await Login();
if (!res.IsSuccess)return res;
if (!res.IsSuccess) return res;
LxSignInfo lxSign = new LxSignInfo();
@@ -131,7 +143,7 @@ namespace WMS.Web.Domain.Services.Public
//KeyValueInfo<string, string> keys = new KeyValueInfo<string, string>();
//keys.Key = item.Name;
//keys.Value = JsonConvert.SerializeObject(ssdata[$"{item.Name}"]);
//if (ssdata[$"{item.Name}"] == null) { list.Add(keys); continue; }
//if (string.IsNullOrEmpty(ssdata[$"{item.Name}"].ToString()))
//{