|
@ -21,8 +21,9 @@ namespace Win_in.Sfs.Wms.Store.Application; |
|
|
|
|
|
|
|
|
[Authorize] |
|
|
[Authorize] |
|
|
[Route($"{StoreConsts.RootPath}material-request")] |
|
|
[Route($"{StoreConsts.RootPath}material-request")] |
|
|
|
|
|
public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialRequest, MaterialRequestDTO, |
|
|
public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialRequest, MaterialRequestDTO, SfsStoreRequestInputBase, MaterialRequestEditInput, MaterialRequestDetail, MaterialRequestDetailDTO, SfsStoreRequestInputBase, MaterialRequestImportInput>, |
|
|
SfsStoreRequestInputBase, MaterialRequestEditInput, MaterialRequestDetail, MaterialRequestDetailDTO, |
|
|
|
|
|
SfsStoreRequestInputBase, MaterialRequestImportInput>, |
|
|
IMaterialRequestAppService |
|
|
IMaterialRequestAppService |
|
|
{ |
|
|
{ |
|
|
private readonly IMaterialRequestManager _materialRequestManager; |
|
|
private readonly IMaterialRequestManager _materialRequestManager; |
|
@ -33,20 +34,65 @@ public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialR |
|
|
|
|
|
|
|
|
private readonly IAreaAppService _areaApp; |
|
|
private readonly IAreaAppService _areaApp; |
|
|
|
|
|
|
|
|
|
|
|
private readonly ILocationAppService _locationAppService; |
|
|
|
|
|
|
|
|
|
|
|
private readonly IItemBasicAppService _itemBasicAppService; |
|
|
|
|
|
|
|
|
public MaterialRequestAppService( |
|
|
public MaterialRequestAppService( |
|
|
IMaterialRequestRepository repository, |
|
|
IMaterialRequestRepository repository, |
|
|
IMaterialRequestManager materialRequestManager, |
|
|
IMaterialRequestManager materialRequestManager, |
|
|
IPreparationPlanManager preparationPlanManager, |
|
|
IPreparationPlanManager preparationPlanManager, |
|
|
IItemStoreRelationAppService itemStoreRelationApp, |
|
|
IItemStoreRelationAppService itemStoreRelationApp, |
|
|
IAreaAppService areaApp) |
|
|
IAreaAppService areaApp |
|
|
|
|
|
, ILocationAppService locationAppService |
|
|
|
|
|
, IItemBasicAppService itemBasicAppService) |
|
|
: base(repository, materialRequestManager) |
|
|
: base(repository, materialRequestManager) |
|
|
{ |
|
|
{ |
|
|
_materialRequestManager = materialRequestManager; |
|
|
_materialRequestManager = materialRequestManager; |
|
|
_preparationPlanManager = preparationPlanManager; |
|
|
_preparationPlanManager = preparationPlanManager; |
|
|
_itemStoreRelationApp = itemStoreRelationApp; |
|
|
_itemStoreRelationApp = itemStoreRelationApp; |
|
|
_areaApp = areaApp; |
|
|
_areaApp = areaApp; |
|
|
|
|
|
_locationAppService = locationAppService; |
|
|
|
|
|
_itemBasicAppService = itemBasicAppService; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#region 东阳使用
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用来重写 导入数据时可以加工数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dictionary"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
protected override async Task<Dictionary<MaterialRequest, EntityState>> ImportProcessingEntityAsync( |
|
|
|
|
|
Dictionary<MaterialRequest, EntityState> dictionary) |
|
|
|
|
|
{ |
|
|
|
|
|
var addList = dictionary.Where(p => p.Value == EntityState.Added).Select(p => p.Key); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var materialRequest in addList) |
|
|
|
|
|
{ |
|
|
|
|
|
materialRequest.Worker = CurrentUser.GetUserName(); |
|
|
|
|
|
materialRequest.CreatorId = CurrentUser.Id; |
|
|
|
|
|
foreach (var detail in materialRequest.Details) |
|
|
|
|
|
{ |
|
|
|
|
|
var locationDto= await _locationAppService.GetByCodeAsync(detail.ToLocationCode).ConfigureAwait(false); |
|
|
|
|
|
var itemBasicDto=await _itemBasicAppService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
detail.ToLocationArea = locationDto.AreaCode; |
|
|
|
|
|
detail.ToLocationErpCode = locationDto.ErpLocationCode; |
|
|
|
|
|
detail.ToLocationGroup = locationDto.LocationGroupCode; |
|
|
|
|
|
detail.ToWarehouseCode = locationDto.WarehouseCode; |
|
|
|
|
|
detail.ItemDesc1 = itemBasicDto.Desc1; |
|
|
|
|
|
detail.ItemDesc2= itemBasicDto.Desc2; |
|
|
|
|
|
detail.ItemName= itemBasicDto.Name; |
|
|
|
|
|
detail.Uom = itemBasicDto.BasicUom; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return await base.ImportProcessingEntityAsync(dictionary).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
[HttpPost("")] |
|
|
[HttpPost("")] |
|
|
//[Authorize(MaterialRequestPermissions.Create)]
|
|
|
//[Authorize(MaterialRequestPermissions.Create)]
|
|
|
public override async Task<MaterialRequestDTO> CreateAsync(MaterialRequestEditInput input) |
|
|
public override async Task<MaterialRequestDTO> CreateAsync(MaterialRequestEditInput input) |
|
@ -142,10 +188,7 @@ public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialR |
|
|
{ |
|
|
{ |
|
|
var prodPreparationPlan = await _preparationPlanManager.GetByNumberAsync(number).ConfigureAwait(false); |
|
|
var prodPreparationPlan = await _preparationPlanManager.GetByNumberAsync(number).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
var materialRequestCreateInput = new MaterialRequestEditInput() |
|
|
var materialRequestCreateInput = new MaterialRequestEditInput { Worker = CurrentUser.GetUserName() }; |
|
|
{ |
|
|
|
|
|
Worker = CurrentUser.GetUserName(), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var preparationPlanDetail in prodPreparationPlan.Details) |
|
|
foreach (var preparationPlanDetail in prodPreparationPlan.Details) |
|
|
{ |
|
|
{ |
|
@ -176,7 +219,8 @@ public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialR |
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
private async Task<List<MaterialRequest>> CheckExistByPreparationPlanAsync(string preparationPlanNumber) |
|
|
private async Task<List<MaterialRequest>> CheckExistByPreparationPlanAsync(string preparationPlanNumber) |
|
|
{ |
|
|
{ |
|
|
var entities = await _repository.GetListAsync(c => c.PreparationPlanNumber == preparationPlanNumber).ConfigureAwait(false); |
|
|
var entities = await _repository.GetListAsync(c => c.PreparationPlanNumber == preparationPlanNumber) |
|
|
|
|
|
.ConfigureAwait(false); |
|
|
return entities; |
|
|
return entities; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -199,7 +243,6 @@ public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialR |
|
|
bool includeDetails = false, |
|
|
bool includeDetails = false, |
|
|
CancellationToken cancellationToken = default) |
|
|
CancellationToken cancellationToken = default) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
Expression<Func<MaterialRequest, bool>> expression = p => p.Type == type; |
|
|
Expression<Func<MaterialRequest, bool>> expression = p => p.Type == type; |
|
|
if (requestInput.Condition.Filters?.Count > 0) |
|
|
if (requestInput.Condition.Filters?.Count > 0) |
|
|
{ |
|
|
{ |
|
@ -210,8 +253,7 @@ public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialR |
|
|
requestInput.Sorting, includeDetails, cancellationToken).ConfigureAwait(false); |
|
|
requestInput.Sorting, includeDetails, cancellationToken).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#region 导入
|
|
|
#region import
|
|
|
|
|
|
|
|
|
|
|
|
//protected override async Task CheckImportInputBusinessAsync(MaterialRequestImportInput importInput, EnumImportMethod importMethod)
|
|
|
//protected override async Task CheckImportInputBusinessAsync(MaterialRequestImportInput importInput, EnumImportMethod importMethod)
|
|
|
//{
|
|
|
//{
|
|
@ -227,7 +269,14 @@ public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialR |
|
|
// CheckTransactionType(EnumTransInOut.In, EnumInventoryStatus.OK, transactionType, item, location);
|
|
|
// CheckTransactionType(EnumTransInOut.In, EnumInventoryStatus.OK, transactionType, item, location);
|
|
|
//}
|
|
|
//}
|
|
|
|
|
|
|
|
|
protected override async Task ValidateImportModelAsync(MaterialRequestImportInput model, List<ValidationResult> validationRresult) |
|
|
/// <summary>
|
|
|
|
|
|
/// 导入验证
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <param name="validationRresult"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
protected override async Task ValidateImportModelAsync(MaterialRequestImportInput model, |
|
|
|
|
|
List<ValidationResult> validationRresult) |
|
|
{ |
|
|
{ |
|
|
_ = new Dictionary<string, string>(); |
|
|
_ = new Dictionary<string, string>(); |
|
|
_ = await CheckItemBasicAsync(model, validationRresult).ConfigureAwait(false); |
|
|
_ = await CheckItemBasicAsync(model, validationRresult).ConfigureAwait(false); |
|
@ -236,11 +285,14 @@ public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialR |
|
|
await CheckStoreRelationAsync(model, validationRresult).ConfigureAwait(false); |
|
|
await CheckStoreRelationAsync(model, validationRresult).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#region 校验
|
|
|
|
|
|
|
|
|
protected override async Task<bool> ValidateImportEntities(Dictionary<MaterialRequest, EntityState> dict) |
|
|
protected override async Task<bool> ValidateImportEntities(Dictionary<MaterialRequest, EntityState> dict) |
|
|
{ |
|
|
{ |
|
|
foreach (var entity in dict.Keys) |
|
|
foreach (var entity in dict.Keys) |
|
|
{ |
|
|
{ |
|
|
var tranType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.Issue, EnumTransSubType.None).ConfigureAwait(false); |
|
|
var tranType = await TransactionTypeAclService |
|
|
|
|
|
.GetByTransTypeAsync(EnumTransType.Issue, EnumTransSubType.None).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
Check.NotNull(tranType, "事务类型", "事务类型不存在"); |
|
|
Check.NotNull(tranType, "事务类型", "事务类型不存在"); |
|
|
|
|
|
|
|
@ -250,84 +302,71 @@ public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialR |
|
|
entity.AutoHandle = tranType.AutoHandleRequest; |
|
|
entity.AutoHandle = tranType.AutoHandleRequest; |
|
|
entity.DirectCreateNote = tranType.DirectCreateNote; |
|
|
entity.DirectCreateNote = tranType.DirectCreateNote; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return await base.ValidateImportEntities(dict).ConfigureAwait(false); |
|
|
return await base.ValidateImportEntities(dict).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected async Task<ItemBasicDTO> CheckItemBasicAsync(MaterialRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
protected async Task<ItemBasicDTO> CheckItemBasicAsync(MaterialRequestImportInput importInput, |
|
|
|
|
|
List<ValidationResult> validationRresult) |
|
|
{ |
|
|
{ |
|
|
var item = await ItemBasicAclService.GetByCodeAsync(importInput.ItemCode).ConfigureAwait(false); |
|
|
var item = await ItemBasicAclService.GetByCodeAsync(importInput.ItemCode).ConfigureAwait(false); |
|
|
if (item == null) |
|
|
if (item == null) |
|
|
{ |
|
|
{ |
|
|
validationRresult.Add(new ValidationResult($"物品代码{importInput.ItemCode}不存在", new string[] { "物品代码" })); |
|
|
validationRresult.Add(new ValidationResult($"物品代码{importInput.ItemCode}不存在", new[] { "物品代码" })); |
|
|
} |
|
|
} |
|
|
else if (item.StdPackQty == 0) |
|
|
else if (item.StdPackQty == 0) |
|
|
{ |
|
|
{ |
|
|
validationRresult.Add(new ValidationResult($"物品代码{importInput.ItemCode}的标准包装不存在", new string[] { "标准包装" })); |
|
|
validationRresult.Add( |
|
|
|
|
|
new ValidationResult($"物品代码{importInput.ItemCode}的物品信息中标准包装等于0或不存在", new[] { "标准包装" })); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return item; |
|
|
return item; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected async Task<LocationDTO> CheckLocationAsync(MaterialRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
protected async Task<LocationDTO> CheckLocationAsync(MaterialRequestImportInput importInput, |
|
|
|
|
|
List<ValidationResult> validationRresult) |
|
|
{ |
|
|
{ |
|
|
var location = await LocationAclService.GetByCodeAsync(importInput.ToLocationCode).ConfigureAwait(false); |
|
|
var location = await _locationAppService.GetByCodeAsync(importInput.ToLocationCode).ConfigureAwait(false); |
|
|
if (location == null) |
|
|
if (location == null) |
|
|
{ |
|
|
{ |
|
|
validationRresult.Add(new ValidationResult($"目标库位{importInput.ToLocationCode}不存在", new string[] { "目标库位" })); |
|
|
validationRresult.Add(new ValidationResult($"目标库位{importInput.ToLocationCode}不存在", new[] { "目标库位" })); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return location; |
|
|
return location; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected async Task CheckAreaAsync(MaterialRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
protected async Task CheckAreaAsync(MaterialRequestImportInput importInput, |
|
|
|
|
|
List<ValidationResult> validationRresult) |
|
|
{ |
|
|
{ |
|
|
var area = await _areaApp.GetByCodeAsync(importInput.FromLocationArea).ConfigureAwait(false); |
|
|
var area = await _areaApp.GetByCodeAsync(importInput.FromLocationArea).ConfigureAwait(false); |
|
|
if (area == null) |
|
|
if (area == null) |
|
|
{ |
|
|
{ |
|
|
validationRresult.Add(new ValidationResult($"调出库区{importInput.FromLocationArea}不存在", new string[] { "调出库区" })); |
|
|
validationRresult.Add(new ValidationResult($"调出库区{importInput.FromLocationArea}不存在", new[] { "调出库区" })); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected async Task CheckStoreRelationAsync(MaterialRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
protected async Task CheckStoreRelationAsync(MaterialRequestImportInput importInput, |
|
|
|
|
|
List<ValidationResult> validationRresult) |
|
|
{ |
|
|
{ |
|
|
var itemStoreRelation = await _itemStoreRelationApp.GetFirstAsync(importInput.ItemCode, importInput.ToLocationCode).ConfigureAwait(false); |
|
|
var itemStoreRelation = await _itemStoreRelationApp |
|
|
|
|
|
.GetFirstAsync(importInput.ItemCode, importInput.ToLocationCode).ConfigureAwait(false); |
|
|
if (itemStoreRelation == null) |
|
|
if (itemStoreRelation == null) |
|
|
{ |
|
|
{ |
|
|
validationRresult.Add(new ValidationResult($"物品代码{importInput.ItemCode}与目标库位{importInput.ToLocationCode}不存在对应关", new string[] { "物品库位对应关系" })); |
|
|
validationRresult.Add(new ValidationResult( |
|
|
} |
|
|
$"物品代码{importInput.ItemCode}与目标库位{importInput.ToLocationCode}不存在对应关", new[] { "物品库位对应关系" })); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected override async Task SaveImportAsync(Dictionary<MaterialRequest, EntityState> dict) |
|
|
|
|
|
{ |
|
|
|
|
|
var entityList = dict.Keys.ToList(); |
|
|
|
|
|
foreach (var entity in entityList) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var detail in entity.Details) |
|
|
|
|
|
{ |
|
|
|
|
|
var item = await ItemBasicAclService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
if (item != null) |
|
|
|
|
|
{ |
|
|
|
|
|
detail.ItemName = item.Name; |
|
|
|
|
|
detail.ItemDesc1 = item.Desc1; |
|
|
|
|
|
detail.ItemDesc2 = item.Desc2; |
|
|
|
|
|
detail.StdPackQty = item.StdPackQty; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var location = await LocationAclService.GetByCodeAsync(detail.ToLocationCode).ConfigureAwait(false); |
|
|
#endregion
|
|
|
|
|
|
|
|
|
if (location != null) |
|
|
|
|
|
{ |
|
|
|
|
|
detail.ToLocationErpCode = location.ErpLocationCode; |
|
|
|
|
|
detail.ToWarehouseCode = location.WarehouseCode; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
await base.SaveImportAsync(dict).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据类型 获取叫料申请
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("list/by-type/{type}")] |
|
|
[HttpGet("list/by-type/{type}")] |
|
|
|
|
|
|
|
|
public virtual async Task<List<MaterialRequestDTO>> GetListByTypeAsync(string type) |
|
|
public virtual async Task<List<MaterialRequestDTO>> GetListByTypeAsync(string type) |
|
|
{ |
|
|
{ |
|
|
var entities = await _repository.GetListAsync(c => c.Type == type).ConfigureAwait(false); |
|
|
var entities = await _repository.GetListAsync(c => c.Type == type).ConfigureAwait(false); |
|
@ -335,6 +374,5 @@ public class MaterialRequestAppService : SfsStoreRequestAppServiceBase<MaterialR |
|
|
var dtos = ObjectMapper.Map<List<MaterialRequest>, List<MaterialRequestDTO>>(entities); |
|
|
var dtos = ObjectMapper.Map<List<MaterialRequest>, List<MaterialRequestDTO>>(entities); |
|
|
|
|
|
|
|
|
return dtos; |
|
|
return dtos; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|