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.
197 lines
6.7 KiB
197 lines
6.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.Validation;
|
|
using Win_in.Sfs.Shared.Domain.Shared;
|
|
using Win_in.Sfs.Wms.Job.Domain;
|
|
using Win_in.Sfs.Wms.Job.Domain.Shared;
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
using CountJobCheckInput = Win_in.Sfs.Wms.Job.Application.Contracts.CountJobCheckInput;
|
|
using CountJobCreateRequestInput = Win_in.Sfs.Wms.Job.Application.Contracts.CountJobCreateRequestInput;
|
|
using CountJobDTO = Win_in.Sfs.Wms.Job.Application.Contracts.CountJobDTO;
|
|
using CountJobEditInput = Win_in.Sfs.Wms.Job.Application.Contracts.CountJobEditInput;
|
|
using ICountJobAppService = Win_in.Sfs.Wms.Job.Application.Contracts.ICountJobAppService;
|
|
using SfsJobRequestInputBase = Win_in.Sfs.Wms.Job.Application.Contracts.SfsJobRequestInputBase;
|
|
|
|
namespace Win_in.Sfs.Wms.Job.Application;
|
|
|
|
/// <summary>
|
|
/// 盘点接口
|
|
/// </summary>
|
|
[Authorize]
|
|
[Route($"{JobConsts.RootPath}count-job")]
|
|
|
|
public class CountJobAppService
|
|
: SfsJobAppServiceBase<CountJob, CountJobDetail, CountJobDTO, SfsJobRequestInputBase, CountJobCheckInput, CountJobEditInput>,
|
|
ICountJobAppService
|
|
{
|
|
private readonly ICountJobManager _countJobManager;
|
|
|
|
//private readonly ILocationCapacityAppService _locationCapacityAppService;
|
|
|
|
public CountJobAppService(
|
|
ICountJobRepository repository
|
|
, IDistributedCache<CountJobDTO> cache
|
|
//, ILocationCapacityAppService locationCapacityAppService
|
|
, ICountJobManager countJobManager
|
|
) : base(repository, countJobManager)
|
|
{
|
|
//_locationCapacityAppService = locationCapacityAppService;
|
|
|
|
_countJobManager = countJobManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据条件新增job接口
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("create-with-condition")]
|
|
|
|
public virtual async Task<List<CountJobDTO>> CreateWithConditionAsync(CountJobCreateRequestInput input)
|
|
{
|
|
var entity = ObjectMapper.Map<CountJobCreateRequestInput, CountPlanDTO>(input);
|
|
|
|
var entityList = await _countJobManager.CreateWithConditionAsync(entity, input.PartCondition, input.LocCondition, input.StatusList).ConfigureAwait(false);
|
|
|
|
var dtoList = ObjectMapper.Map<List<CountJob>, List<CountJobDTO>>(entityList);
|
|
return dtoList;
|
|
}
|
|
|
|
public override async Task<CountJobDTO> CompleteAsync(Guid id, CountJobDTO dto)
|
|
{
|
|
var input = new CountJobCheckInput
|
|
{
|
|
JobStatuses = new List<EnumJobStatus>() { EnumJobStatus.Doing },
|
|
};
|
|
|
|
var checkEntity = await _repository.FindAsync(id).ConfigureAwait(false);
|
|
if (checkEntity == null)
|
|
{
|
|
throw new UserFriendlyException($"未找到ID为 {id} 的任务");
|
|
}
|
|
var result = new AbpValidationResult();
|
|
_countJobManager.CheckJobStatus(checkEntity, input.JobStatuses, result);
|
|
if (result.Errors.Any())
|
|
{
|
|
throw new AbpValidationException(result.Errors);
|
|
}
|
|
var entity = ObjectMapper.Map<CountJobDTO, CountJob>(dto);
|
|
await _countJobManager.CompleteAsync(entity, CurrentUser).ConfigureAwait(false);
|
|
return dto;
|
|
}
|
|
|
|
[HttpPost("cancel-by-count-plan/{countPlanNumber}")]
|
|
public virtual async Task CancelByCountPlanAsync(string countPlanNumber)
|
|
{
|
|
var entities = await _repository.GetListAsync(p => p.CountPlanNumber == countPlanNumber).ConfigureAwait(false);
|
|
foreach (var entity in entities)
|
|
{
|
|
await _countJobManager.CancelAsync(entity).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
[HttpPost("close-by-count-plan/{countPlanNumber}")]
|
|
public virtual async Task CloseByCountPlanAsync(string countPlanNumber)
|
|
{
|
|
var entities = await _repository.GetListAsync(p => p.CountPlanNumber == countPlanNumber).ConfigureAwait(false);
|
|
foreach (var entity in entities)
|
|
{
|
|
if (entity.JobStatus != EnumJobStatus.Closed && entity.JobStatus != EnumJobStatus.Cancelled && entity.JobStatus != EnumJobStatus.Done)
|
|
{
|
|
await _countJobManager.CloseAsync(entity).ConfigureAwait(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
//[HttpPost("handle-count-job-async")]
|
|
//public virtual async Task HandleCountJobAsync(Guid guid, CountJobDTO dto)
|
|
//{
|
|
// await base.HandleAsync(guid, dto);
|
|
|
|
// await CurrentUnitOfWork.SaveChangesAsync();
|
|
|
|
// var locList = dto.Details.Select(p => p.LocationCode).Distinct().ToList();
|
|
// //更新库存容量
|
|
// foreach (var loc in locList)
|
|
// {
|
|
// if (!string.IsNullOrEmpty(loc))
|
|
// {
|
|
// await _locationCapacityAppService.SetLocationAutoMaticCalculation(loc);
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
/*
|
|
/// <summary>
|
|
/// 承接任务
|
|
/// </summary>
|
|
/// <param name="jobNumber"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("accept")]
|
|
public override async Task AcceptAsync(string jobNumber)
|
|
{
|
|
var input = new CountJobCheckInput
|
|
{
|
|
JobStatuses = new List<EnumJobStatus>() { EnumJobStatus.New },
|
|
};
|
|
var dto = await CheckAsync(jobNumber, input);
|
|
await _countJobManager.AcceptAsync(dto.Id, CurrentUser.Id ?? Guid.Empty);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行任务,修改实际数量
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("handle")]
|
|
public override async Task HandleAsync(CountJobDTO dto)
|
|
{
|
|
var input = new CountJobCheckInput
|
|
{
|
|
JobStatuses = new List<EnumJobStatus>() { EnumJobStatus.Pending },
|
|
};
|
|
|
|
await CheckAsync(dto.Number, input);
|
|
|
|
var entity = ObjectMapper.Map<CountJobDTO, CountJob>(dto);
|
|
await _countJobManager.HandleAsync(entity, CurrentUser.Id ?? Guid.Empty);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 检查任务是否正确
|
|
/// </summary>
|
|
/// <param name="jobNumber"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="AbpValidationException"></exception>
|
|
[HttpPost("check")]
|
|
public override async Task<CountJobDTO> CheckAsync(string jobNumber, CountJobCheckInput input)
|
|
{
|
|
var result = new AbpValidationResult();
|
|
_countJobManager.CheckFormat(jobNumber);
|
|
var dto = await GetByNumberAsync(jobNumber);
|
|
var entity = ObjectMapper.Map<CountJobDTO, CountJob>(dto);
|
|
_countJobManager.CheckJobStatus(entity, input.JobStatuses, result);
|
|
_countJobManager.CheckDetails(entity, result);
|
|
//TODO 添加其它校验
|
|
if (result.Errors.Any())
|
|
{
|
|
throw new AbpValidationException(result.Errors);
|
|
}
|
|
|
|
return dto;
|
|
}
|
|
*/
|
|
|
|
}
|
|
|