Browse Source

过期时间

集成Redis
马昊 2 years ago
parent
commit
d8690626ba
  1. 70
      be/Modules/Label/src/Win_in.Sfs.Label.Application/InventoryLabels/InventoryLabelAppService.cs

70
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);
}
/// <summary>
/// 按Id获取实体
/// </summary>
/// <param name="id">实体Id</param>
/// <returns></returns>
[HttpGet("{id}")]
public override async Task<InventoryLabelDto> 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<List<InventoryLabelDto>> CreateManyAsync(List<InventoryLabelEditInput> inputs)
@ -83,7 +127,7 @@ public class InventoryLabelAppService
[UnitOfWork]
public virtual async Task<List<InventoryLabelDto>> CreateManyByNoCodeAsync(List<InventoryLabelEditInput> inputs)
{
var entitys= ObjectMapper.Map<List<InventoryLabelEditInput>, List<InventoryLabel>>(inputs);
var entitys = ObjectMapper.Map<List<InventoryLabelEditInput>, List<InventoryLabel>>(inputs);
await _repository.InsertManyAsync(entitys).ConfigureAwait(false);
return ObjectMapper.Map<List<InventoryLabel>, List<InventoryLabelDto>>(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;

Loading…
Cancel
Save