You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
6.7 KiB
179 lines
6.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.Guids;
|
|
using Volo.Abp.Validation;
|
|
using Win_in.Sfs.Shared.Application;
|
|
using Win_in.Sfs.Shared.Framework;
|
|
using Win_in.Sfs.Wms.DataExchange.Application.Contracts;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Shared;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Application
|
|
{
|
|
|
|
[Authorize(OutgoingDataPermissions.Default)]
|
|
[Route($"{DataExchangeConsts.RouteRoot}/outgoing-exchange-data")]
|
|
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.WmsWebApi)]
|
|
|
|
public class OutgoingDataAppService :
|
|
SfsCrudAppServiceBase<OutgoingData, OutgoingDataDTO, Guid, OutgoingDataRequestInput, OutgoingDataCreateInput, OutgoingDataUpdateInput>,
|
|
IOutgoingDataAppService
|
|
{
|
|
private new readonly IOutgoingDataRepository _repository;
|
|
private readonly IOutgoingDataManager _outgoingDataManager;
|
|
private readonly ISnowflakeIdGenerator _snowflakeIdGenerator;
|
|
|
|
public OutgoingDataAppService(
|
|
IOutgoingDataRepository repository,
|
|
IDistributedCache<OutgoingDataDTO> cache,
|
|
IOutgoingDataManager outgoingDataManager,
|
|
ISnowflakeIdGenerator snowflakeIdGenerator
|
|
) : base(repository, cache)
|
|
{
|
|
_repository = repository;
|
|
_outgoingDataManager = outgoingDataManager;
|
|
_snowflakeIdGenerator = snowflakeIdGenerator;
|
|
}
|
|
[HttpPost("add")]
|
|
public override async Task<OutgoingDataDTO> CreateAsync(OutgoingDataCreateInput input)
|
|
{
|
|
input.Number = await _snowflakeIdGenerator.CreateAsync();
|
|
return await base.CreateAsync(input);
|
|
}
|
|
[HttpPost("update-effective-date")]
|
|
public virtual async Task UpdateEffectiveDateAsync(List<Guid> ids, DateTime newDate)
|
|
{
|
|
var validStatus = new List<EnumExchangeDataStatus>
|
|
{
|
|
EnumExchangeDataStatus.Ready,
|
|
EnumExchangeDataStatus.Error,
|
|
EnumExchangeDataStatus.Hold,
|
|
};
|
|
var list = await GetListAndCheckStatusAsync(ids, validStatus);
|
|
foreach (var OutgoingData in list.Where(p => validStatus.Contains(p.Status)))
|
|
{
|
|
OutgoingData.SetEffectiveDate(newDate);
|
|
}
|
|
await _repository.UpdateManyAsync(list);
|
|
}
|
|
[HttpPost("reset")]
|
|
public virtual async Task ResetAsync(List<Guid> ids, string remark)
|
|
{
|
|
var validStatus = new List<EnumExchangeDataStatus>
|
|
{
|
|
EnumExchangeDataStatus.Processing,
|
|
EnumExchangeDataStatus.Error,
|
|
EnumExchangeDataStatus.Hold,
|
|
};
|
|
var list = await GetListAndCheckStatusAsync(ids, validStatus);
|
|
foreach (var outgoingData in list.Where(p => validStatus.Contains(p.Status)))
|
|
{
|
|
outgoingData.Take(remark);
|
|
}
|
|
await _repository.UpdateManyAsync(list);
|
|
}
|
|
[HttpPost("take")]
|
|
public virtual async Task TakeAsync(List<Guid> ids, string remark)
|
|
{
|
|
var validStatus = new List<EnumExchangeDataStatus>
|
|
{
|
|
EnumExchangeDataStatus.Ready,
|
|
};
|
|
var list = await GetListAndCheckStatusAsync(ids, validStatus);
|
|
foreach (var outgoingData in list.Where(p => validStatus.Contains(p.Status)))
|
|
{
|
|
outgoingData.Take(remark);
|
|
}
|
|
await _repository.UpdateManyAsync(list);
|
|
}
|
|
[HttpPost("hold")]
|
|
public virtual async Task HoldAsync(List<Guid> ids, string remark)
|
|
{
|
|
var validStatus = new List<EnumExchangeDataStatus>
|
|
{
|
|
EnumExchangeDataStatus.Ready,
|
|
EnumExchangeDataStatus.Processing,
|
|
EnumExchangeDataStatus.Error,
|
|
};
|
|
var list = await GetListAndCheckStatusAsync(ids, validStatus);
|
|
foreach (var outgoingData in list.Where(p => validStatus.Contains(p.Status)))
|
|
{
|
|
outgoingData.Hold(remark);
|
|
}
|
|
await _repository.UpdateManyAsync(list);
|
|
}
|
|
|
|
[HttpGet("")]
|
|
public virtual async Task<List<OutgoingDataDTO>> GetNewList()
|
|
{
|
|
var list = await _outgoingDataManager.GetReadyListAsync();
|
|
foreach (var outgoingData in list)
|
|
{
|
|
outgoingData.Take();
|
|
}
|
|
var dtos = ObjectMapper.Map<List<OutgoingData>, List<OutgoingDataDTO>>(list);
|
|
return dtos;
|
|
}
|
|
|
|
[HttpPost("complete")]
|
|
public virtual async Task CompleteAsync(Guid id, OutgoingDataUpdateInput updateInput)
|
|
{
|
|
var validStatus = new List<EnumExchangeDataStatus>
|
|
{
|
|
EnumExchangeDataStatus.Processing,
|
|
};
|
|
var update = ObjectMapper.Map<OutgoingDataUpdateInput, OutgoingData>(updateInput);
|
|
var entity = await _repository.GetAsync(id);
|
|
await CheckStatus(entity, validStatus);
|
|
if (update.Status == EnumExchangeDataStatus.Success)
|
|
{
|
|
entity.SetSuccess(update.Remark);
|
|
await _outgoingDataManager.FileAndDeleteAsync(entity);
|
|
}
|
|
else
|
|
{
|
|
entity.SetError(update.ErrorCode, update.ErrorMessage);
|
|
await _repository.UpdateAsync(entity);
|
|
}
|
|
}
|
|
|
|
private Task CheckStatus(List<OutgoingData> list, List<EnumExchangeDataStatus> validStatusList)
|
|
{
|
|
var result = new AbpValidationResult();
|
|
foreach (var OutgoingData in list)
|
|
{
|
|
if (!validStatusList.Contains(OutgoingData.Status))
|
|
{
|
|
result.Errors.Add(new ValidationResult($"{OutgoingData.Number} 状态错误"));
|
|
}
|
|
}
|
|
|
|
if (result.Errors.Any())
|
|
{
|
|
throw new AbpValidationException(result.Errors);
|
|
}
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private Task CheckStatus(OutgoingData entity, List<EnumExchangeDataStatus> validStatusList)
|
|
{
|
|
return CheckStatus(new List<OutgoingData> { entity }, validStatusList);
|
|
}
|
|
|
|
private async Task<List<OutgoingData>> GetListAndCheckStatusAsync(List<Guid> ids, List<EnumExchangeDataStatus> validStatus)
|
|
{
|
|
var list = await _repository.GetListAsync(p => ids.Contains(p.Id));
|
|
await CheckStatus(list, validStatus);
|
|
return list;
|
|
}
|
|
|
|
}
|
|
}
|
|
|