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; /// /// 盘点接口 /// [Authorize] [Route($"{JobConsts.RootPath}count-job")] public class CountJobAppService : SfsJobAppServiceBase, ICountJobAppService { private readonly ICountJobManager _countJobManager; //private readonly ILocationCapacityAppService _locationCapacityAppService; public CountJobAppService( ICountJobRepository repository , IDistributedCache cache //, ILocationCapacityAppService locationCapacityAppService , ICountJobManager countJobManager ) : base(repository, countJobManager) { //_locationCapacityAppService = locationCapacityAppService; _countJobManager = countJobManager; } /// /// 根据条件新增job接口 /// /// /// [HttpPost("create-with-condition")] public virtual async Task> CreateWithConditionAsync(CountJobCreateRequestInput input) { var entity = ObjectMapper.Map(input); var entityList = await _countJobManager.CreateWithConditionAsync(entity, input.PartCondition, input.LocCondition, input.StatusList).ConfigureAwait(false); var dtoList = ObjectMapper.Map, List>(entityList); return dtoList; } public override async Task CompleteAsync(Guid id, CountJobDTO dto) { var input = new CountJobCheckInput { JobStatuses = new List() { 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(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); // } // } //} /* /// /// 承接任务 /// /// /// [HttpPost("accept")] public override async Task AcceptAsync(string jobNumber) { var input = new CountJobCheckInput { JobStatuses = new List() { EnumJobStatus.New }, }; var dto = await CheckAsync(jobNumber, input); await _countJobManager.AcceptAsync(dto.Id, CurrentUser.Id ?? Guid.Empty); } /// /// 执行任务,修改实际数量 /// /// /// [HttpPost("handle")] public override async Task HandleAsync(CountJobDTO dto) { var input = new CountJobCheckInput { JobStatuses = new List() { EnumJobStatus.Pending }, }; await CheckAsync(dto.Number, input); var entity = ObjectMapper.Map(dto); await _countJobManager.HandleAsync(entity, CurrentUser.Id ?? Guid.Empty); } /// /// 检查任务是否正确 /// /// /// /// /// [HttpPost("check")] public override async Task CheckAsync(string jobNumber, CountJobCheckInput input) { var result = new AbpValidationResult(); _countJobManager.CheckFormat(jobNumber); var dto = await GetByNumberAsync(jobNumber); var entity = ObjectMapper.Map(dto); _countJobManager.CheckJobStatus(entity, input.JobStatuses, result); _countJobManager.CheckDetails(entity, result); //TODO 添加其它校验 if (result.Errors.Any()) { throw new AbpValidationException(result.Errors); } return dto; } */ }