|
|
@ -18,429 +18,431 @@ using WmsWebApi.Jsons; |
|
|
|
using WmsWebApi.Options; |
|
|
|
using WmsWebApi.Wms; |
|
|
|
|
|
|
|
namespace WmsWebApi.OtherZll; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 其他领物料
|
|
|
|
/// </summary>
|
|
|
|
[Route("/api/OtherZll")] |
|
|
|
public class OtherZllService : ApplicationService, IOtherZllService |
|
|
|
namespace WmsWebApi.OtherZll |
|
|
|
{ |
|
|
|
private readonly ITsStockDetailRepository _tsStockDetailRepository; |
|
|
|
private readonly ITbProductReceiveRepository _tbProductReceiveRepository; |
|
|
|
private readonly ITbBillRepository _tbBillRepository; |
|
|
|
private readonly ITaPartRepository _taPartRepository; |
|
|
|
private readonly ITaStoreLocationRepository _taStoreLocationRepository; |
|
|
|
private readonly IOtherZllManager _otherZllManager; |
|
|
|
private readonly ITLTransactionRepository _tlTransactionRepository; |
|
|
|
private readonly TmPgWmsUpdate _tmPgWmsUpdate; |
|
|
|
private readonly Volo.Abp.Uow.IUnitOfWorkManager _unitOfWorkManager; |
|
|
|
private readonly IBackgroundJobRequestRetry _backgroundJobRequestRetry; |
|
|
|
private readonly IOtherZllJsonRepository _otherZllJsonRepository; |
|
|
|
private readonly AsyncRetryPolicy _asyncRetryPolicy; |
|
|
|
private readonly OtherZllConfigOptions _otherZllConfigOptions; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 是否是请求重试
|
|
|
|
/// 其他领物料
|
|
|
|
/// </summary>
|
|
|
|
public bool IsRequestRetry { get; set; } = false; |
|
|
|
|
|
|
|
public OtherZllService(ITsStockDetailRepository tsStockDetailRepository, |
|
|
|
ITbProductReceiveRepository tbProductReceiveRepository, |
|
|
|
ITbBillRepository tbBillRepository, |
|
|
|
ITaPartRepository taPartRepository, |
|
|
|
ITaStoreLocationRepository taStoreLocationRepository, |
|
|
|
IOtherZllManager otherZllManager, |
|
|
|
ITLTransactionRepository tlTransactionRepository, |
|
|
|
TmPgWmsUpdate tmPgWmsUpdate, |
|
|
|
Volo.Abp.Uow.IUnitOfWorkManager unitOfWorkManager, |
|
|
|
IBackgroundJobRequestRetry backgroundJobRequestRetry, |
|
|
|
IOtherZllJsonRepository otherZllJsonRepository, |
|
|
|
IOptionsMonitor<CustomConfigOptions> customConfigOptions, |
|
|
|
IOptionsMonitor<OtherZllConfigOptions> otherZllConfigOptions) |
|
|
|
[Route("/api/OtherZll")] |
|
|
|
public class OtherZllService : ApplicationService, IOtherZllService |
|
|
|
{ |
|
|
|
_tsStockDetailRepository = tsStockDetailRepository; |
|
|
|
_tbProductReceiveRepository = tbProductReceiveRepository; |
|
|
|
_tbBillRepository = tbBillRepository; |
|
|
|
_taPartRepository = taPartRepository; |
|
|
|
_taStoreLocationRepository = taStoreLocationRepository; |
|
|
|
_otherZllManager = otherZllManager; |
|
|
|
_tlTransactionRepository = tlTransactionRepository; |
|
|
|
_tmPgWmsUpdate = tmPgWmsUpdate; |
|
|
|
_unitOfWorkManager = unitOfWorkManager; |
|
|
|
_backgroundJobRequestRetry = backgroundJobRequestRetry; |
|
|
|
_otherZllJsonRepository = otherZllJsonRepository; |
|
|
|
_asyncRetryPolicy = Policy.Handle<Exception>() |
|
|
|
.WaitAndRetryAsync(new[] { |
|
|
|
private readonly ITsStockDetailRepository _tsStockDetailRepository; |
|
|
|
private readonly ITbProductReceiveRepository _tbProductReceiveRepository; |
|
|
|
private readonly ITbBillRepository _tbBillRepository; |
|
|
|
private readonly ITaPartRepository _taPartRepository; |
|
|
|
private readonly ITaStoreLocationRepository _taStoreLocationRepository; |
|
|
|
private readonly IOtherZllManager _otherZllManager; |
|
|
|
private readonly ITLTransactionRepository _tlTransactionRepository; |
|
|
|
private readonly TmPgWmsUpdate _tmPgWmsUpdate; |
|
|
|
private readonly Volo.Abp.Uow.IUnitOfWorkManager _unitOfWorkManager; |
|
|
|
private readonly IBackgroundJobRequestRetry _backgroundJobRequestRetry; |
|
|
|
private readonly IOtherZllJsonRepository _otherZllJsonRepository; |
|
|
|
private readonly AsyncRetryPolicy _asyncRetryPolicy; |
|
|
|
private readonly OtherZllConfigOptions _otherZllConfigOptions; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 是否是请求重试
|
|
|
|
/// </summary>
|
|
|
|
public bool IsRequestRetry { get; set; } = false; |
|
|
|
|
|
|
|
public OtherZllService(ITsStockDetailRepository tsStockDetailRepository, |
|
|
|
ITbProductReceiveRepository tbProductReceiveRepository, |
|
|
|
ITbBillRepository tbBillRepository, |
|
|
|
ITaPartRepository taPartRepository, |
|
|
|
ITaStoreLocationRepository taStoreLocationRepository, |
|
|
|
IOtherZllManager otherZllManager, |
|
|
|
ITLTransactionRepository tlTransactionRepository, |
|
|
|
TmPgWmsUpdate tmPgWmsUpdate, |
|
|
|
Volo.Abp.Uow.IUnitOfWorkManager unitOfWorkManager, |
|
|
|
IBackgroundJobRequestRetry backgroundJobRequestRetry, |
|
|
|
IOtherZllJsonRepository otherZllJsonRepository, |
|
|
|
IOptionsMonitor<CustomConfigOptions> customConfigOptions, |
|
|
|
IOptionsMonitor<OtherZllConfigOptions> otherZllConfigOptions) |
|
|
|
{ |
|
|
|
_tsStockDetailRepository = tsStockDetailRepository; |
|
|
|
_tbProductReceiveRepository = tbProductReceiveRepository; |
|
|
|
_tbBillRepository = tbBillRepository; |
|
|
|
_taPartRepository = taPartRepository; |
|
|
|
_taStoreLocationRepository = taStoreLocationRepository; |
|
|
|
_otherZllManager = otherZllManager; |
|
|
|
_tlTransactionRepository = tlTransactionRepository; |
|
|
|
_tmPgWmsUpdate = tmPgWmsUpdate; |
|
|
|
_unitOfWorkManager = unitOfWorkManager; |
|
|
|
_backgroundJobRequestRetry = backgroundJobRequestRetry; |
|
|
|
_otherZllJsonRepository = otherZllJsonRepository; |
|
|
|
_asyncRetryPolicy = Policy.Handle<Exception>() |
|
|
|
.WaitAndRetryAsync(new[] { |
|
|
|
TimeSpan.FromSeconds(1), |
|
|
|
TimeSpan.FromSeconds(5), |
|
|
|
TimeSpan.FromSeconds(5), |
|
|
|
TimeSpan.FromSeconds(5) |
|
|
|
}, (exception, timeSpan, retryCount, context) => |
|
|
|
{ |
|
|
|
Logger.LogInformation($"执行失败,第 {retryCount} 次重试"); |
|
|
|
}); |
|
|
|
_otherZllConfigOptions = otherZllConfigOptions.CurrentValue; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost("add")] |
|
|
|
public async Task<ReturnResult> AddAsync([FromBody] object content) |
|
|
|
{ |
|
|
|
var result = new ReturnResult(); |
|
|
|
List<OtherZllDto> _dtoList; |
|
|
|
bool bTypeErr = false, bErr = false; |
|
|
|
try |
|
|
|
{ |
|
|
|
_dtoList = JsonConvert.DeserializeObject<List<OtherZllDto>>(content.ToString()); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
result.TYPE = 'E'; |
|
|
|
result.MESSAGE = "Json格式不正确,详细信息:" + ex.Message; |
|
|
|
return result; |
|
|
|
}, (exception, timeSpan, retryCount, context) => |
|
|
|
{ |
|
|
|
Logger.LogInformation($"执行失败,第 {retryCount} 次重试"); |
|
|
|
}); |
|
|
|
_otherZllConfigOptions = otherZllConfigOptions.CurrentValue; |
|
|
|
} |
|
|
|
|
|
|
|
if (_dtoList == null || _dtoList.Count() <= 0) |
|
|
|
[HttpPost("add")] |
|
|
|
public async Task<ReturnResult> AddAsync([FromBody] object content) |
|
|
|
{ |
|
|
|
bErr = true; |
|
|
|
result.MESSAGE = "err:没有1000工厂数据"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
WmsWebApiOtherZLLDTO dto = new WmsWebApiOtherZLLDTO(); |
|
|
|
dto.JSON = content.ToString(); |
|
|
|
dto.SetId(GuidGenerator); |
|
|
|
var result = new ReturnResult(); |
|
|
|
List<OtherZllDto> _dtoList; |
|
|
|
bool bTypeErr = false, bErr = false; |
|
|
|
try |
|
|
|
{ |
|
|
|
_dtoList = JsonConvert.DeserializeObject<List<OtherZllDto>>(content.ToString()); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
result.TYPE = 'E'; |
|
|
|
result.MESSAGE = "Json格式不正确,详细信息:" + ex.Message; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
if (_dtoList[0].ZDJLX == "20") |
|
|
|
if (_dtoList == null || _dtoList.Count() <= 0) |
|
|
|
{ |
|
|
|
var _dtoDetails = _dtoList.Where(p => p.WERKS == "1000").ToList(); |
|
|
|
bErr = true; |
|
|
|
result.MESSAGE = "err:没有1000工厂数据"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
if (_dtoDetails != null || _dtoDetails.Count() > 0) |
|
|
|
{ |
|
|
|
if (_otherZllConfigOptions.IsEnableErnamFilter == true) |
|
|
|
{ |
|
|
|
//根据配置文件过滤ERNAM
|
|
|
|
List<string> ernamFilters = _otherZllConfigOptions.ErnamFilters; |
|
|
|
_dtoDetails = _dtoDetails.FindAll(e => ernamFilters.Contains(e.ERNAM)); |
|
|
|
} |
|
|
|
} |
|
|
|
WmsWebApiOtherZLLDTO dto = new WmsWebApiOtherZLLDTO(); |
|
|
|
dto.JSON = content.ToString(); |
|
|
|
dto.SetId(GuidGenerator); |
|
|
|
|
|
|
|
if (_dtoDetails == null || _dtoDetails.Count() == 0) |
|
|
|
{ |
|
|
|
bErr = true; |
|
|
|
result.MESSAGE = "err:没有1000工厂数据"; |
|
|
|
} |
|
|
|
else |
|
|
|
try |
|
|
|
{ |
|
|
|
if (_dtoList[0].ZDJLX == "20") |
|
|
|
{ |
|
|
|
dto.ZLLDJ = _dtoDetails[0].ZLLDJ; |
|
|
|
dto.MBLNR = _dtoDetails[0].MBLNR; |
|
|
|
dto.MJAHR = _dtoDetails[0].MJAHR; |
|
|
|
dto.ZLLR = _dtoDetails[0].ZLLR; |
|
|
|
var _dtoDetails = _dtoList.Where(p => p.WERKS == "1000").ToList(); |
|
|
|
|
|
|
|
var _billNumList = _dtoDetails.Select(p => p.MBLNR).Distinct().ToList(); |
|
|
|
foreach (var _billNum in _billNumList) |
|
|
|
if (_dtoDetails != null || _dtoDetails.Count() > 0) |
|
|
|
{ |
|
|
|
List<TB_BILL> _billList = new List<TB_BILL>(); |
|
|
|
List<TB_PRODUCT_RECEIVE> _recieveList = new List<TB_PRODUCT_RECEIVE>(); |
|
|
|
List<TS_STOCK_DETAIL> _stockList = new List<TS_STOCK_DETAIL>(); |
|
|
|
List<TS_STOCK_DETAIL> _stockUpdateList = new List<TS_STOCK_DETAIL>(); |
|
|
|
List<TS_STOCK_DETAIL> _stockDelList = new List<TS_STOCK_DETAIL>(); |
|
|
|
List<TL_TRANSACTION> _transList = new List<TL_TRANSACTION>(); |
|
|
|
if (_otherZllConfigOptions.IsEnableErnamFilter == true) |
|
|
|
{ |
|
|
|
//根据配置文件过滤ERNAM
|
|
|
|
List<string> ernamFilters = _otherZllConfigOptions.ErnamFilters; |
|
|
|
_dtoDetails = _dtoDetails.FindAll(e => ernamFilters.Contains(e.ERNAM)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var bill = await _tbBillRepository.FirstOrDefaultAsync(p => p.SourceBillNum2 == _billNum); |
|
|
|
if (_dtoDetails == null || _dtoDetails.Count() == 0) |
|
|
|
{ |
|
|
|
bErr = true; |
|
|
|
result.MESSAGE = "err:没有1000工厂数据"; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
dto.ZLLDJ = _dtoDetails[0].ZLLDJ; |
|
|
|
dto.MBLNR = _dtoDetails[0].MBLNR; |
|
|
|
dto.MJAHR = _dtoDetails[0].MJAHR; |
|
|
|
dto.ZLLR = _dtoDetails[0].ZLLR; |
|
|
|
|
|
|
|
if (bill == null) |
|
|
|
var _billNumList = _dtoDetails.Select(p => p.MBLNR).Distinct().ToList(); |
|
|
|
foreach (var _billNum in _billNumList) |
|
|
|
{ |
|
|
|
var newDtoList = _dtoDetails.Where(p => p.MBLNR == _billNum).ToList(); |
|
|
|
List<TB_BILL> _billList = new List<TB_BILL>(); |
|
|
|
List<TB_PRODUCT_RECEIVE> _recieveList = new List<TB_PRODUCT_RECEIVE>(); |
|
|
|
List<TS_STOCK_DETAIL> _stockList = new List<TS_STOCK_DETAIL>(); |
|
|
|
List<TS_STOCK_DETAIL> _stockUpdateList = new List<TS_STOCK_DETAIL>(); |
|
|
|
List<TS_STOCK_DETAIL> _stockDelList = new List<TS_STOCK_DETAIL>(); |
|
|
|
List<TL_TRANSACTION> _transList = new List<TL_TRANSACTION>(); |
|
|
|
|
|
|
|
var tbBill = new TB_BILL |
|
|
|
{ |
|
|
|
BillNum = _billNum + "." + newDtoList[0].ZLLDJ, |
|
|
|
SourceBillNum2 = _billNum, |
|
|
|
BillTime = DateTime.Now, |
|
|
|
StartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
FinishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
OperName = "SAP", |
|
|
|
DetailQty = newDtoList.Count, |
|
|
|
BillType = 201, |
|
|
|
SubBillType = 10100, |
|
|
|
State = 2, |
|
|
|
Remark = "otherzll", |
|
|
|
AccountDate = DateTime.ParseExact(newDtoList[0].BUDAT, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture) |
|
|
|
}; |
|
|
|
_billList.Add(tbBill); |
|
|
|
var bill = await _tbBillRepository.FirstOrDefaultAsync(p => p.SourceBillNum2 == _billNum); |
|
|
|
|
|
|
|
var sumDetailList = newDtoList.Where(p => p.MBLNR == _billNum).GroupBy(x => new { x.MATNR, x.CHARG, x.LGORT1 }). |
|
|
|
Select(group => new |
|
|
|
{ |
|
|
|
MATNR = group.Key.MATNR, |
|
|
|
CHARG = group.Key.CHARG, |
|
|
|
ERFMG = group.Sum(t => t.ERFMG), |
|
|
|
LGORT = group.Key.LGORT1, |
|
|
|
BUDAT = group.FirstOrDefault().BUDAT |
|
|
|
}); |
|
|
|
foreach (var item in sumDetailList) |
|
|
|
if (bill == null) |
|
|
|
{ |
|
|
|
//判断物料信息
|
|
|
|
var part = await _taPartRepository.FirstOrDefaultAsync(p => p.PartCode == item.MATNR); |
|
|
|
if (part == null) |
|
|
|
{ |
|
|
|
//result.TYPE = 'E';
|
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"err:物料 {item.MATNR} 不在WinWMS管理!"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!part.IsDeposit) |
|
|
|
{ |
|
|
|
//result.TYPE = 'E';
|
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"err:物料 {item.MATNR} 不属于其他领用件!"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (string.IsNullOrEmpty(part.DefaultReceiveLocCode)) |
|
|
|
{ |
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"err:物料 {item.MATNR} 未设置收货库位!"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
var newDtoList = _dtoDetails.Where(p => p.MBLNR == _billNum).ToList(); |
|
|
|
|
|
|
|
var partLoc = await _taStoreLocationRepository.FirstOrDefaultAsync(p => p.LocCode == part.DefaultReceiveLocCode); |
|
|
|
if (partLoc == null) |
|
|
|
{ |
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"err:物料 {item.MATNR} 的默认收货库位未配置ERP库位!"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (partLoc.ErpLocCode != item.LGORT) |
|
|
|
{ |
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"物料 {item.MATNR} 减库存!"; |
|
|
|
} |
|
|
|
var _barcode = $"{item.MATNR}_{item.CHARG}"; |
|
|
|
var tmp = (OtherZllDto)newDtoList[0]; |
|
|
|
//插入productrecieve
|
|
|
|
var tbRecieve = new TB_PRODUCT_RECEIVE |
|
|
|
var tbBill = new TB_BILL |
|
|
|
{ |
|
|
|
BillNum = tbBill.BillNum, |
|
|
|
BarCode = _barcode, |
|
|
|
PartCode = item.MATNR, |
|
|
|
Batch = item.CHARG, |
|
|
|
FromLocCode = "", |
|
|
|
ToLocCode = part.DefaultReceiveLocCode, |
|
|
|
Remark = part.QLevel, |
|
|
|
Qty = item.ERFMG, |
|
|
|
GoodQty = item.ERFMG, |
|
|
|
BillNum = _billNum + "." + newDtoList[0].ZLLDJ, |
|
|
|
SourceBillNum2 = _billNum, |
|
|
|
BillTime = DateTime.Now, |
|
|
|
StartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
FinishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
OperName = "SAP", |
|
|
|
DetailQty = newDtoList.Count, |
|
|
|
BillType = 201, |
|
|
|
SubBillType = 10100, |
|
|
|
State = 2, |
|
|
|
ReceiveDate = DateTime.Now, |
|
|
|
ProduceDate = DateTime.Now, |
|
|
|
LineId = tmp.ZLTLX, //领/退类型
|
|
|
|
ShiftName = tmp.ZLLDJ, //单据号
|
|
|
|
TeamName = tmp.ZEILE, //物料凭证中的项目
|
|
|
|
Unit = tmp.ZDJLX, //单据类型
|
|
|
|
TraceBackCode = tmp.MEINS, //基本计量单位
|
|
|
|
Remark = "otherzll", |
|
|
|
AccountDate = DateTime.ParseExact(newDtoList[0].BUDAT, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture) |
|
|
|
}; |
|
|
|
if (partLoc.ErpLocCode != item.LGORT) |
|
|
|
{ |
|
|
|
tbRecieve.FromLocCode = part.DefaultReceiveLocCode; |
|
|
|
tbRecieve.ToLocCode = item.LGORT; |
|
|
|
tbRecieve.Qty = 0 - tbRecieve.Qty; |
|
|
|
} |
|
|
|
_recieveList.Add(tbRecieve); |
|
|
|
//插入ts_stock_detail
|
|
|
|
var tsStock = new TS_STOCK_DETAIL |
|
|
|
_billList.Add(tbBill); |
|
|
|
|
|
|
|
var sumDetailList = newDtoList.Where(p => p.MBLNR == _billNum).GroupBy(x => new { x.MATNR, x.CHARG, x.LGORT1 }). |
|
|
|
Select(group => new |
|
|
|
{ |
|
|
|
MATNR = group.Key.MATNR, |
|
|
|
CHARG = group.Key.CHARG, |
|
|
|
ERFMG = group.Sum(t => t.ERFMG), |
|
|
|
LGORT = group.Key.LGORT1, |
|
|
|
BUDAT = group.FirstOrDefault().BUDAT |
|
|
|
}); |
|
|
|
foreach (var item in sumDetailList) |
|
|
|
{ |
|
|
|
BarCode = _barcode, |
|
|
|
PartCode = item.MATNR, |
|
|
|
Batch = item.CHARG, |
|
|
|
EqptCode = "", |
|
|
|
LocCode = part.DefaultReceiveLocCode, |
|
|
|
AreaCode = partLoc.AreaCode,//"FG",
|
|
|
|
Qty = item.ERFMG, |
|
|
|
UpdateQty = item.ERFMG, |
|
|
|
VendId = "", |
|
|
|
ProduceDate = DateTime.Now, |
|
|
|
OverdueDate = (DateTime.Now).AddDays(part.ValidityDays), |
|
|
|
ReceiveDate = DateTime.Now, |
|
|
|
VendBatch = item.CHARG, |
|
|
|
Remark = "", |
|
|
|
State = EnumStockState.合格, |
|
|
|
Amount = 0, |
|
|
|
VinState = 0, |
|
|
|
//判断物料信息
|
|
|
|
var part = await _taPartRepository.FirstOrDefaultAsync(p => p.PartCode == item.MATNR); |
|
|
|
if (part == null) |
|
|
|
{ |
|
|
|
//result.TYPE = 'E';
|
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"err:物料 {item.MATNR} 不在WinWMS管理!"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!part.IsDeposit) |
|
|
|
{ |
|
|
|
//result.TYPE = 'E';
|
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"err:物料 {item.MATNR} 不属于其他领用件!"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (string.IsNullOrEmpty(part.DefaultReceiveLocCode)) |
|
|
|
{ |
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"err:物料 {item.MATNR} 未设置收货库位!"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
var partLoc = await _taStoreLocationRepository.FirstOrDefaultAsync(p => p.LocCode == part.DefaultReceiveLocCode); |
|
|
|
if (partLoc == null) |
|
|
|
{ |
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"err:物料 {item.MATNR} 的默认收货库位未配置ERP库位!"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (partLoc.ErpLocCode != item.LGORT) |
|
|
|
{ |
|
|
|
bTypeErr = true; |
|
|
|
result.MESSAGE += $"物料 {item.MATNR} 减库存!"; |
|
|
|
} |
|
|
|
var _barcode = $"{item.MATNR}_{item.CHARG}"; |
|
|
|
var tmp = (OtherZllDto)newDtoList[0]; |
|
|
|
//插入productrecieve
|
|
|
|
var tbRecieve = new TB_PRODUCT_RECEIVE |
|
|
|
{ |
|
|
|
BillNum = tbBill.BillNum, |
|
|
|
BarCode = _barcode, |
|
|
|
PartCode = item.MATNR, |
|
|
|
Batch = item.CHARG, |
|
|
|
FromLocCode = "", |
|
|
|
ToLocCode = part.DefaultReceiveLocCode, |
|
|
|
Remark = part.QLevel, |
|
|
|
Qty = item.ERFMG, |
|
|
|
GoodQty = item.ERFMG, |
|
|
|
State = 2, |
|
|
|
ReceiveDate = DateTime.Now, |
|
|
|
ProduceDate = DateTime.Now, |
|
|
|
LineId = tmp.ZLTLX, //领/退类型
|
|
|
|
ShiftName = tmp.ZLLDJ, //单据号
|
|
|
|
TeamName = tmp.ZEILE, //物料凭证中的项目
|
|
|
|
Unit = tmp.ZDJLX, //单据类型
|
|
|
|
TraceBackCode = tmp.MEINS, //基本计量单位
|
|
|
|
}; |
|
|
|
if (partLoc.ErpLocCode != item.LGORT) |
|
|
|
{ |
|
|
|
tbRecieve.FromLocCode = part.DefaultReceiveLocCode; |
|
|
|
tbRecieve.ToLocCode = item.LGORT; |
|
|
|
tbRecieve.Qty = 0 - tbRecieve.Qty; |
|
|
|
} |
|
|
|
_recieveList.Add(tbRecieve); |
|
|
|
//插入ts_stock_detail
|
|
|
|
var tsStock = new TS_STOCK_DETAIL |
|
|
|
{ |
|
|
|
BarCode = _barcode, |
|
|
|
PartCode = item.MATNR, |
|
|
|
Batch = item.CHARG, |
|
|
|
EqptCode = "", |
|
|
|
LocCode = part.DefaultReceiveLocCode, |
|
|
|
AreaCode = partLoc.AreaCode,//"FG",
|
|
|
|
Qty = item.ERFMG, |
|
|
|
UpdateQty = item.ERFMG, |
|
|
|
VendId = "", |
|
|
|
ProduceDate = DateTime.Now, |
|
|
|
OverdueDate = (DateTime.Now).AddDays(part.ValidityDays), |
|
|
|
ReceiveDate = DateTime.Now, |
|
|
|
VendBatch = item.CHARG, |
|
|
|
Remark = "", |
|
|
|
State = EnumStockState.合格, |
|
|
|
Amount = 0, |
|
|
|
VinState = 0, |
|
|
|
|
|
|
|
var stock = await _tsStockDetailRepository.FirstOrDefaultAsync(p => p.BarCode == _barcode |
|
|
|
&& p.LocCode == part.DefaultReceiveLocCode |
|
|
|
&& p.State == EnumStockState.合格); |
|
|
|
if (partLoc.ErpLocCode != item.LGORT)//出库
|
|
|
|
{ |
|
|
|
if (stock == null || stock.Qty - item.ERFMG < 0) |
|
|
|
}; |
|
|
|
|
|
|
|
var stock = await _tsStockDetailRepository.FirstOrDefaultAsync(p => p.BarCode == _barcode |
|
|
|
&& p.LocCode == part.DefaultReceiveLocCode |
|
|
|
&& p.State == EnumStockState.合格); |
|
|
|
if (partLoc.ErpLocCode != item.LGORT)//出库
|
|
|
|
{ |
|
|
|
result.TYPE = 'E'; |
|
|
|
bErr = true; |
|
|
|
result.MESSAGE = $"err:物料 {item.MATNR} 批次 {item.CHARG} 的库存不足!"; |
|
|
|
break; |
|
|
|
if (stock == null || stock.Qty - item.ERFMG < 0) |
|
|
|
{ |
|
|
|
result.TYPE = 'E'; |
|
|
|
bErr = true; |
|
|
|
result.MESSAGE = $"err:物料 {item.MATNR} 批次 {item.CHARG} 的库存不足!"; |
|
|
|
break; |
|
|
|
} |
|
|
|
else if (stock.Qty - item.ERFMG == 0) |
|
|
|
{ |
|
|
|
_stockDelList.Add(tsStock); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
tsStock.Qty = 0 - tsStock.Qty; |
|
|
|
tsStock.UpdateQty = tsStock.Qty; |
|
|
|
_stockUpdateList.Add(tsStock); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (stock.Qty - item.ERFMG == 0) |
|
|
|
else//入库
|
|
|
|
{ |
|
|
|
_stockDelList.Add(tsStock); |
|
|
|
if (stock == null) |
|
|
|
{ |
|
|
|
_stockList.Add(tsStock); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_stockUpdateList.Add(tsStock); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
//插入tl_transaction
|
|
|
|
var tlTrans = new TL_TRANSACTION |
|
|
|
{ |
|
|
|
OperName = "SAP", |
|
|
|
LogTime = tbBill.AccountDate ?? DateTime.Now, |
|
|
|
BillNum = tbBill.BillNum, |
|
|
|
BillType = tbBill.BillType, |
|
|
|
SubBillType = tbBill.SubBillType, |
|
|
|
PartCode = item.MATNR, |
|
|
|
Batch = item.CHARG, |
|
|
|
Qty = item.ERFMG, |
|
|
|
BarCode = _barcode, |
|
|
|
LocCode = part.DefaultReceiveLocCode, |
|
|
|
EqptCode = item.LGORT, |
|
|
|
Remark = "In", |
|
|
|
State = 2, |
|
|
|
TransType = 1 |
|
|
|
}; |
|
|
|
try |
|
|
|
{ |
|
|
|
tsStock.Qty = 0 - tsStock.Qty; |
|
|
|
tsStock.UpdateQty = tsStock.Qty; |
|
|
|
_stockUpdateList.Add(tsStock); |
|
|
|
tlTrans.LogTime = DateTime.ParseExact(item.BUDAT, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); |
|
|
|
} |
|
|
|
} |
|
|
|
else//入库
|
|
|
|
{ |
|
|
|
if (stock == null) |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
_stockList.Add(tsStock); |
|
|
|
tlTrans.LogTime = tbBill.AccountDate ?? DateTime.Now; |
|
|
|
} |
|
|
|
else |
|
|
|
if (partLoc.ErpLocCode != item.LGORT) |
|
|
|
{ |
|
|
|
_stockUpdateList.Add(tsStock); |
|
|
|
tlTrans.Qty = 0 - tlTrans.Qty; |
|
|
|
tlTrans.Remark = "Out"; |
|
|
|
tlTrans.TransType = 0; |
|
|
|
} |
|
|
|
_transList.Add(tlTrans); |
|
|
|
} |
|
|
|
//插入tl_transaction
|
|
|
|
var tlTrans = new TL_TRANSACTION |
|
|
|
{ |
|
|
|
OperName = "SAP", |
|
|
|
LogTime = tbBill.AccountDate ?? DateTime.Now, |
|
|
|
BillNum = tbBill.BillNum, |
|
|
|
BillType = tbBill.BillType, |
|
|
|
SubBillType = tbBill.SubBillType, |
|
|
|
PartCode = item.MATNR, |
|
|
|
Batch = item.CHARG, |
|
|
|
Qty = item.ERFMG, |
|
|
|
BarCode = _barcode, |
|
|
|
LocCode = part.DefaultReceiveLocCode, |
|
|
|
EqptCode = item.LGORT, |
|
|
|
Remark = "In", |
|
|
|
State = 2, |
|
|
|
TransType = 1 |
|
|
|
}; |
|
|
|
try |
|
|
|
{ |
|
|
|
tlTrans.LogTime = DateTime.ParseExact(item.BUDAT, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
if (!bErr) |
|
|
|
{ |
|
|
|
tlTrans.LogTime = tbBill.AccountDate ?? DateTime.Now; |
|
|
|
} |
|
|
|
if (partLoc.ErpLocCode != item.LGORT) |
|
|
|
{ |
|
|
|
tlTrans.Qty = 0 - tlTrans.Qty; |
|
|
|
tlTrans.Remark = "Out"; |
|
|
|
tlTrans.TransType = 0; |
|
|
|
if (_recieveList.Count > 0) |
|
|
|
{ |
|
|
|
await _tbBillRepository.AddManyAsync(_billList); |
|
|
|
await _tbProductReceiveRepository.AddAsync(_recieveList); |
|
|
|
} |
|
|
|
if (_stockList != null && _stockList.Count() > 0) |
|
|
|
await _tsStockDetailRepository.AddAsync(_stockList); |
|
|
|
if (_stockUpdateList != null && _stockUpdateList.Count() > 0) |
|
|
|
await _tmPgWmsUpdate.UpdateTsStock(_stockUpdateList); |
|
|
|
if (_stockDelList != null && _stockDelList.Count() > 0) |
|
|
|
await _tmPgWmsUpdate.DeleteTsStock(_stockDelList); |
|
|
|
await _tlTransactionRepository.AddAsync(_transList); |
|
|
|
} |
|
|
|
_transList.Add(tlTrans); |
|
|
|
} |
|
|
|
if (!bErr) |
|
|
|
else |
|
|
|
{ |
|
|
|
if (_recieveList.Count > 0) |
|
|
|
{ |
|
|
|
await _tbBillRepository.AddManyAsync(_billList); |
|
|
|
await _tbProductReceiveRepository.AddAsync(_recieveList); |
|
|
|
} |
|
|
|
if (_stockList != null && _stockList.Count() > 0) |
|
|
|
await _tsStockDetailRepository.AddAsync(_stockList); |
|
|
|
if (_stockUpdateList != null && _stockUpdateList.Count() > 0) |
|
|
|
await _tmPgWmsUpdate.UpdateTsStock(_stockUpdateList); |
|
|
|
if (_stockDelList != null && _stockDelList.Count() > 0) |
|
|
|
await _tmPgWmsUpdate.DeleteTsStock(_stockDelList); |
|
|
|
await _tlTransactionRepository.AddAsync(_transList); |
|
|
|
result.TYPE = 'E'; |
|
|
|
bErr = true; |
|
|
|
result.MESSAGE = $"err:单据 {_billNum} 已存在"; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
result.TYPE = 'E'; |
|
|
|
bErr = true; |
|
|
|
result.MESSAGE = $"err:单据 {_billNum} 已存在"; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (bErr || bTypeErr) |
|
|
|
{ |
|
|
|
dto.ITYPE = result.MESSAGE; |
|
|
|
} |
|
|
|
} |
|
|
|
if (bErr || bTypeErr) |
|
|
|
else |
|
|
|
{ |
|
|
|
dto.ITYPE = result.MESSAGE; |
|
|
|
result.MESSAGE = "err:非物流领料单"; |
|
|
|
} |
|
|
|
await CurrentUnitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
else |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
result.MESSAGE = "err:非物流领料单"; |
|
|
|
} |
|
|
|
await CurrentUnitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
dto.ITYPE = ex.GetBaseException().Message; |
|
|
|
dto.EnumRetryStatus = Enums.EnumRetryStatus.WaitRetry; |
|
|
|
dto.ITYPE = ex.GetBaseException().Message; |
|
|
|
dto.EnumRetryStatus = Enums.EnumRetryStatus.WaitRetry; |
|
|
|
|
|
|
|
if (IsRequestRetry == false) |
|
|
|
{ |
|
|
|
try |
|
|
|
if (IsRequestRetry == false) |
|
|
|
{ |
|
|
|
await _asyncRetryPolicy.ExecuteAsync(async () => await _backgroundJobRequestRetry.AddBackgroundJobAsync(EnumActionName.OtherZllAdd, content.ToString())); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
throw new Exception("操作数据库失败,请稍后重试。", ex); |
|
|
|
try |
|
|
|
{ |
|
|
|
await _asyncRetryPolicy.ExecuteAsync(async () => await _backgroundJobRequestRetry.AddBackgroundJobAsync(EnumActionName.OtherZllAdd, content.ToString())); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
throw new Exception("操作数据库失败,请稍后重试。", ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
throw new Exception("操作数据库失败,稍后系统自动重试。", ex); |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
if (IsRequestRetry == false) |
|
|
|
throw new Exception("操作数据库失败,稍后系统自动重试。", ex); |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
Logger.LogInformation(dto.JSON); |
|
|
|
try |
|
|
|
{ |
|
|
|
await AddOtherZLLDtoNowUnitOfWorkAsync(dto); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
if (IsRequestRetry == false) |
|
|
|
{ |
|
|
|
Logger.LogInformation(dto.JSON); |
|
|
|
try |
|
|
|
{ |
|
|
|
await _asyncRetryPolicy.ExecuteAsync(async () => await AddJsonNowUnitOfWorkAsync(dto)); |
|
|
|
await AddOtherZLLDtoNowUnitOfWorkAsync(dto); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
Logger.LogError("OtherZll JSON记录失败"); |
|
|
|
Logger.LogError(dto.JSON); |
|
|
|
Logger.LogError(ex.Message); |
|
|
|
try |
|
|
|
{ |
|
|
|
await _asyncRetryPolicy.ExecuteAsync(async () => await AddJsonNowUnitOfWorkAsync(dto)); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
Logger.LogError("OtherZll JSON记录失败"); |
|
|
|
Logger.LogError(dto.JSON); |
|
|
|
Logger.LogError(ex.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task AddOtherZLLDtoNowUnitOfWorkAsync(WmsWebApiOtherZLLDTO wmsWebApiOtherZLLDTO) |
|
|
|
{ |
|
|
|
if (wmsWebApiOtherZLLDTO == null) { return; } |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false)) |
|
|
|
private async Task AddOtherZLLDtoNowUnitOfWorkAsync(WmsWebApiOtherZLLDTO wmsWebApiOtherZLLDTO) |
|
|
|
{ |
|
|
|
await _otherZllManager.AddAsync(wmsWebApiOtherZLLDTO); |
|
|
|
await uow.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (wmsWebApiOtherZLLDTO == null) { return; } |
|
|
|
|
|
|
|
private async Task AddJsonNowUnitOfWorkAsync(WmsWebApiOtherZLLDTO wmsWebApiOtherZLLDTO) |
|
|
|
{ |
|
|
|
if (wmsWebApiOtherZLLDTO == null) { return; } |
|
|
|
using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false)) |
|
|
|
{ |
|
|
|
await _otherZllManager.AddAsync(wmsWebApiOtherZLLDTO); |
|
|
|
await uow.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false)) |
|
|
|
private async Task AddJsonNowUnitOfWorkAsync(WmsWebApiOtherZLLDTO wmsWebApiOtherZLLDTO) |
|
|
|
{ |
|
|
|
await _otherZllJsonRepository.InsertAsync(wmsWebApiOtherZLLDTO); |
|
|
|
await uow.SaveChangesAsync(); |
|
|
|
if (wmsWebApiOtherZLLDTO == null) { return; } |
|
|
|
|
|
|
|
using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false)) |
|
|
|
{ |
|
|
|
await _otherZllJsonRepository.InsertAsync(wmsWebApiOtherZLLDTO); |
|
|
|
await uow.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |