优化
This commit is contained in:
@@ -4,10 +4,12 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto;
|
||||
using WMS.Web.Core.Dto.ChangeBoxRecord;
|
||||
@@ -49,6 +51,8 @@ namespace WMS.Web.Domain.Services
|
||||
private readonly IBoxInventoryRepositories _boxInventoryRepositories;
|
||||
private readonly ILogger<InStockService> _logger;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
|
||||
private readonly ConcurrentDictionary<int, SemaphoreSlim> _locks = new ConcurrentDictionary<int, SemaphoreSlim>();
|
||||
public InStockService(IMapper mapper, ISerialNumbersRepositories serialNumbersRepositories, IErpService erpService, IBoxInventoryService boxInventoryService, ISerialNumberService serialNumberService, ILoginService loginService, IBoxRepositories boxRepositories,
|
||||
IBasicsRepositories basicsRepositories, IErpBasicDataExtendService erpBasicDataExtendService, IChangeMoveBoxService changeMoveBoxService, IInStockTaskBoxRepositories inStockTaskBoxRepositories,
|
||||
IInStockRepositories inStockRepositories, IInStockTaskRepositories inStockTaskRepositories, IBoxInventoryRepositories boxInventoryRepositories, ILogger<InStockService> logger, IServiceScopeFactory serviceScopeFactory)
|
||||
@@ -129,29 +133,42 @@ namespace WMS.Web.Domain.Services
|
||||
/// <returns></returns>
|
||||
public async Task<Result> Shelf(PurchaseShelfRequest instock, LoginInDto loginInfo)
|
||||
{
|
||||
IDbContextTransaction _transaction = _basicsRepositories.GetTransaction();
|
||||
bool isRollback = false;
|
||||
bool isTransaction = false;
|
||||
//1.添加入库单:(同步金蝶在save方法里面进行)
|
||||
var save_result = await this.ShelfSave(instock, InstockType.Purchase, loginInfo, isTransaction);
|
||||
if (!save_result.IsSuccess) isRollback = true;
|
||||
var taskId= instock.Details.Select(x => x.TaskId).FirstOrDefault();
|
||||
|
||||
//实体
|
||||
var entity = save_result.Data;
|
||||
|
||||
//提交事务
|
||||
var isSuccess = _basicsRepositories.CommitTransaction(isRollback, _transaction);
|
||||
if (!isSuccess)
|
||||
return save_result;
|
||||
|
||||
//同步金蝶
|
||||
if (entity.Type == InstockType.Purchase)
|
||||
var taskLock = _locks.GetOrAdd(taskId, _ => new SemaphoreSlim(1, 1));
|
||||
await taskLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
OperateRequest oRequest = new OperateRequest();
|
||||
oRequest.Ids.Add(entity.Id);
|
||||
await Sync(oRequest, loginInfo, false);
|
||||
IDbContextTransaction _transaction = _basicsRepositories.GetTransaction();
|
||||
bool isRollback = false;
|
||||
bool isTransaction = false;
|
||||
//1.添加入库单:(同步金蝶在save方法里面进行)
|
||||
var save_result = await this.ShelfSave(instock, InstockType.Purchase, loginInfo, isTransaction);
|
||||
if (!save_result.IsSuccess) isRollback = true;
|
||||
|
||||
//实体
|
||||
var entity = save_result.Data;
|
||||
|
||||
//提交事务
|
||||
var isSuccess = _basicsRepositories.CommitTransaction(isRollback, _transaction);
|
||||
if (!isSuccess)
|
||||
return save_result;
|
||||
|
||||
//同步金蝶
|
||||
if (entity.Type == InstockType.Purchase)
|
||||
{
|
||||
OperateRequest oRequest = new OperateRequest();
|
||||
oRequest.Ids.Add(entity.Id);
|
||||
await Sync(oRequest, loginInfo, false);
|
||||
}
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
return Result.ReSuccess();
|
||||
finally
|
||||
{
|
||||
taskLock.Release();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -189,7 +206,7 @@ namespace WMS.Web.Domain.Services
|
||||
return Result<BoxInStockTaskDto>.ReFailure(ResultCodes.BoxNoData);
|
||||
|
||||
//判断箱不存在所选的物料
|
||||
var isAnyHave = box.Details.Any(x => x.MaterialNumber == dto.MaterialNumber);
|
||||
var isAnyHave = box.Details.Any(x => x.MaterialNumber == dto.MaterialNumber);
|
||||
if (!isAnyHave)
|
||||
return Result<BoxInStockTaskDto>.ReFailure(ResultCodes.Contrast_Purchase_Count_Error);
|
||||
//return Result<BoxInStockTaskDto>.ReFailure(box.BoxBillNo + ResultCodes.BoxNoMaterialError.Item2, ResultCodes.BoxNoMaterialError.Item1);
|
||||
@@ -585,7 +602,7 @@ namespace WMS.Web.Domain.Services
|
||||
return Result<InStockTask>.ReFailure(ResultCodes.InStockTaskBoxIsHaveData);
|
||||
|
||||
//序列号
|
||||
var serialNumbs= await _serialNumbersRepositories.GetEntityListByBoxIds(dto_boxIds);
|
||||
var serialNumbs = await _serialNumbersRepositories.GetEntityListByBoxIds(dto_boxIds);
|
||||
|
||||
//3.组装绑定关系表,要添加的集合
|
||||
var boxEntitys = await _boxRepositories.GetEntityList(dto_boxIds);
|
||||
@@ -596,13 +613,13 @@ namespace WMS.Web.Domain.Services
|
||||
taskBox.TaskId = entity.Id;
|
||||
taskBox.Receiver(staffId);
|
||||
|
||||
var currentBox_serialNumbs= serialNumbs.Where(s => s.BoxId == taskBox.BoxId).ToList();
|
||||
var currentBox_serialNumbs = serialNumbs.Where(s => s.BoxId == taskBox.BoxId).ToList();
|
||||
var current_dto_box_dets = boxEntitys.Where(x => x.Id == item.BoxId).SelectMany(x => x.Details).ToList();
|
||||
taskBox.Details = _mapper.Map<List<InStockTaskBoxDetails>>(current_dto_box_dets);
|
||||
taskBox.Details.ForEach(x =>
|
||||
taskBox.Details.ForEach(x =>
|
||||
{
|
||||
x.ErpDetailId = item.ErpDetailId;
|
||||
x.SerialNumbers= currentBox_serialNumbs.Where(s => s.MaterialNumber == x.MaterialNumber).Select(s => s.SerialNumber).ToList();
|
||||
x.SerialNumbers = currentBox_serialNumbs.Where(s => s.MaterialNumber == x.MaterialNumber).Select(s => s.SerialNumber).ToList();
|
||||
});
|
||||
taskBoxAdd.Add(taskBox);
|
||||
}
|
||||
@@ -680,7 +697,7 @@ namespace WMS.Web.Domain.Services
|
||||
//return Result<ContrastMaterialsResponse>.ReFailure(item.BoxBillNo + ResultCodes.BoxNoMaterialError.Item2, ResultCodes.BoxNoMaterialError.Item1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//3.判断箱里面对应的物料是否存在;不存在就报错
|
||||
foreach (var item in boxs)
|
||||
@@ -799,7 +816,7 @@ namespace WMS.Web.Domain.Services
|
||||
entity.SyncFail(res.result.Message, s.ErpDetailId, loginInfo?.UserInfo?.StaffId ?? 0, res.syncStatus);
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
erpDetails_tags.ForEach(x => { x.SuccessSync = SyncStatus.Fail; });
|
||||
entity.SyncFailAll("同步金蝶失败,金蝶存在已审核的采购入库单", loginInfo?.UserInfo?.StaffId ?? 0);
|
||||
|
||||
Reference in New Issue
Block a user