修复bug
This commit is contained in:
131
src/WMS.Web.Domain/Services/ProductInventoryService.cs
Normal file
131
src/WMS.Web.Domain/Services/ProductInventoryService.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user