From d8690626baf92a3fd4556360ce5d0d480b800fcc Mon Sep 17 00:00:00 2001 From: mahao Date: Sat, 15 Apr 2023 16:35:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InventoryLabelAppService.cs | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/be/Modules/Label/src/Win_in.Sfs.Label.Application/InventoryLabels/InventoryLabelAppService.cs b/be/Modules/Label/src/Win_in.Sfs.Label.Application/InventoryLabels/InventoryLabelAppService.cs index 04222ca2a..e88e07199 100644 --- a/be/Modules/Label/src/Win_in.Sfs.Label.Application/InventoryLabels/InventoryLabelAppService.cs +++ b/be/Modules/Label/src/Win_in.Sfs.Label.Application/InventoryLabels/InventoryLabelAppService.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; @@ -15,6 +16,7 @@ using Win_in.Sfs.Label.Application.Contracts; using Win_in.Sfs.Label.Domain; using Win_in.Sfs.Label.Domain.Shared; using Win_in.Sfs.Shared.Application.Contracts; +using Win_in.Sfs.Shared.Domain.Shared; namespace Win_in.Sfs.Label.Application; @@ -33,12 +35,14 @@ public class InventoryLabelAppService private new readonly IInventoryLabelRepository _repository; private readonly ISupplierAppService _supplierAppService; private readonly ISupplierItemAppService _supplierItemAppService; + private readonly IItemBasicAppService _itemBasicAppService; public InventoryLabelAppService( IInventoryLabelRepository repository, ILabelDefinitionManager labelDefinitionManager , ISupplierAppService supplierAppService , IItemPackAppService itemPackAppService , ISupplierItemAppService supplierItemAppService + , IItemBasicAppService itemBasicAppService ) : base(repository) { _repository = repository; @@ -46,6 +50,7 @@ public class InventoryLabelAppService _supplierAppService = supplierAppService; _itemPackAppService = itemPackAppService; _supplierItemAppService = supplierItemAppService; + _itemBasicAppService = itemBasicAppService; } [HttpPost("")] @@ -60,6 +65,45 @@ public class InventoryLabelAppService return await base.CreateAsync(input).ConfigureAwait(false); } + /// + /// 按Id获取实体 + /// + /// 实体Id + /// + [HttpGet("{id}")] + public override async Task GetAsync(Guid id) + { + var dto = await base.GetAsync(id).ConfigureAwait(false); + + if (dto != null) + { + var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(dto.ItemCode).ConfigureAwait(false); + if (itemBasicDto != null) + { + switch (itemBasicDto.ValidityUnit) + { + case EnumValidityUnit.Infinite: + dto.ExpireDate = DateTime.MaxValue; + break; + case EnumValidityUnit.Day: + dto.ExpireDate = DateTime.Now.AddDays(itemBasicDto.Validity); + break; + case EnumValidityUnit.WeeK: + dto.ExpireDate = DateTime.Now.AddDays(itemBasicDto.Validity * 7); + break; + case EnumValidityUnit.Month: + dto.ExpireDate = DateTime.Now.AddMonths(itemBasicDto.Validity); + break; + case EnumValidityUnit.None: + default: + break; + } + } + } + + return dto; + } + [HttpPost("many")] [UnitOfWork] public virtual async Task> CreateManyAsync(List inputs) @@ -83,7 +127,7 @@ public class InventoryLabelAppService [UnitOfWork] public virtual async Task> CreateManyByNoCodeAsync(List inputs) { - var entitys= ObjectMapper.Map, List>(inputs); + var entitys = ObjectMapper.Map, List>(inputs); await _repository.InsertManyAsync(entitys).ConfigureAwait(false); return ObjectMapper.Map, List>(entitys); } @@ -133,8 +177,32 @@ public class InventoryLabelAppService dto.SupplierCode = input.SupplierCode; dto.PoNumber = input.PoNumber; dto.Remark = input.Remark; + dto.AsnNumber = input.AsnNumber; dto.FullBarcodeString = dto.Code; + var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(dto.ItemCode).ConfigureAwait(false); + if (itemBasicDto != null) + { + switch (itemBasicDto.ValidityUnit) + { + case EnumValidityUnit.Infinite: + dto.ExpireDate = DateTime.MaxValue; + break; + case EnumValidityUnit.Day: + dto.ExpireDate = DateTime.Now.AddDays(itemBasicDto.Validity); + break; + case EnumValidityUnit.WeeK: + dto.ExpireDate = DateTime.Now.AddDays(itemBasicDto.Validity * 7); + break; + case EnumValidityUnit.Month: + dto.ExpireDate = DateTime.Now.AddMonths(itemBasicDto.Validity); + break; + case EnumValidityUnit.None: + default: + break; + } + } + dtos.Add(dto); } return dtos;