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.
323 lines
12 KiB
323 lines
12 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Application.Dtos;
|
|
using Volo.Abp.AspNetCore.Mvc;
|
|
using Win_in.Sfs.Auth.Application.Contracts;
|
|
using Win_in.Sfs.Basedata.Application.Contracts;
|
|
using Win_in.Sfs.FileStorage.Application.Contracts;
|
|
using Win_in.Sfs.Shared.Domain;
|
|
using Win_in.Sfs.Shared.Domain.Shared;
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
|
|
namespace Win_in.Sfs.Wms.Pda.Controllers.Jobs;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route($"{PdaHostConst.ROOT_ROUTE}job/purchase-receipt")]
|
|
|
|
public class PurchaseReceiptJobController : AbpController
|
|
{
|
|
private readonly ISupplierAppService _supplierAppService;
|
|
private readonly IPurchaseReceiptRequestAppService _purchaseReceiptRequestAppService;
|
|
private readonly IPurchaseReceiptJobAppService _purchaseReceiptJobAppService;
|
|
private readonly IFileAppService _fileAppService;
|
|
|
|
private readonly IUserWorkGroupAppService _userWorkGroupAppService;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="purchaseReceiptJobAppService"></param>
|
|
/// <param name="userWorkGroupAppService"></param>
|
|
/// <param name="purchaseReceiptRequestAppService"></param>
|
|
/// <param name="supplierAppService"></param>
|
|
/// <param name="fileAppService"></param>
|
|
public PurchaseReceiptJobController(
|
|
IPurchaseReceiptJobAppService purchaseReceiptJobAppService
|
|
, IUserWorkGroupAppService userWorkGroupAppService
|
|
, IPurchaseReceiptRequestAppService purchaseReceiptRequestAppService
|
|
, ISupplierAppService supplierAppService
|
|
, IFileAppService fileAppService)
|
|
{
|
|
_userWorkGroupAppService = userWorkGroupAppService;
|
|
_purchaseReceiptJobAppService = purchaseReceiptJobAppService;
|
|
_purchaseReceiptRequestAppService = purchaseReceiptRequestAppService;
|
|
_supplierAppService = supplierAppService;
|
|
_fileAppService = fileAppService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取采购收获任务详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{id}")]
|
|
|
|
public virtual async Task<ActionResult<PurchaseReceiptJobDTO>> GetAsync(Guid id)
|
|
{
|
|
var result = await _purchaseReceiptJobAppService.GetAsync(id).ConfigureAwait(false);
|
|
|
|
var supplier = await _supplierAppService.GetByCodeAsync(result.SupplierCode).ConfigureAwait(false);
|
|
result.SupplierName = supplier.Name;
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="pageSize"></param>
|
|
/// <param name="pageIndex"></param>
|
|
/// <param name="isTimeWindowSorting">是否窗口时间排序</param>
|
|
/// <param name="isToday">是否今天</param>
|
|
/// <returns></returns>
|
|
[HttpGet("list")]
|
|
public virtual async Task<PagedResultDto<PurchaseReceiptJobDTO>> GetListAsync(int pageSize, int pageIndex, bool isTimeWindowSorting, bool isToday)
|
|
{
|
|
var wlgCodes = await _userWorkGroupAppService.GetCodsOfCurrentUserAsync().ConfigureAwait(false);
|
|
var jsonCodes = JsonSerializer.Serialize(wlgCodes);
|
|
|
|
List<string> status = new List<string>() { EnumJobStatus.Open.ToString(), EnumJobStatus.Doing.ToString() };
|
|
var jsonStatus = JsonSerializer.Serialize(status);
|
|
|
|
var request = new SfsJobRequestInputBase
|
|
{
|
|
MaxResultCount = pageSize,
|
|
SkipCount = (pageIndex - 1) * pageSize,
|
|
Sorting = $"{nameof(PurchaseReceiptJobDTO.Priority)} ASC",
|
|
Condition = new Condition
|
|
{
|
|
Filters = new List<Filter>
|
|
{
|
|
new(nameof(PurchaseReceiptJobDTO.WorkGroupCode),jsonCodes,"In"),
|
|
new(nameof(PurchaseReceiptJobDTO.JobStatus),jsonStatus,"In")
|
|
}
|
|
}
|
|
};
|
|
|
|
if (isToday)//只看当日
|
|
{
|
|
request.Condition.Filters.Add(new Filter(nameof(PurchaseReceiptJobDTO.PlanArriveDate), Clock.Now.ToString("yyyy-MM-dd"), ">=", "And"));
|
|
}
|
|
if (isTimeWindowSorting)//窗口时间排序
|
|
{
|
|
request.Sorting = $"{nameof(PurchaseReceiptJobDTO.TimeWindow)} ASC";
|
|
}
|
|
|
|
var list = await _purchaseReceiptJobAppService.GetPagedListByFilterAsync(request, true).ConfigureAwait(false);
|
|
|
|
////拼接供应商名称
|
|
//foreach (var purchaseReceiptJob in list.Items)
|
|
//{
|
|
// var supplier = await _supplierAppService.GetByTypeAsync(purchaseReceiptJob.SupplierCode);
|
|
// purchaseReceiptJob.SupplierName = supplier.Name;
|
|
//}
|
|
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取列表 筛选
|
|
/// </summary>
|
|
/// <param name="sfsRequestDTO"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("list")]
|
|
public virtual async Task<PagedResultDto<PurchaseReceiptJobDTO>> GetListAsync(SfsJobRequestInputBase sfsRequestDTO)
|
|
{
|
|
var list = await _purchaseReceiptJobAppService.GetPagedListByFilterAsync(sfsRequestDTO, true).ConfigureAwait(false);
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据Number 获取收货任务
|
|
/// </summary>
|
|
/// <param name="jobNumber"></param>
|
|
/// <param name="isToday"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("by-number")]
|
|
public virtual async Task<ActionResult<PurchaseReceiptJobDTO>> GetJobByNumberAsync(string jobNumber, bool isToday)
|
|
{
|
|
var jobDto = await _purchaseReceiptJobAppService.GetByNumberAsync(jobNumber).ConfigureAwait(false);
|
|
if (jobDto == null)
|
|
{
|
|
throw new UserFriendlyException($"未找到编号为 {jobNumber} 的任务");
|
|
}
|
|
|
|
var wlgCodes = await _userWorkGroupAppService.GetCodsOfCurrentUserAsync().ConfigureAwait(false);
|
|
if (!wlgCodes.Contains(jobDto.WorkGroupCode))
|
|
{
|
|
return new NotFoundObjectResult($"任务属于工作组 {jobDto.WorkGroupCode}");
|
|
}
|
|
if (!wlgCodes.Any(r => r == jobDto.WorkGroupCode))
|
|
{
|
|
return new NotFoundObjectResult($"任务属于工作组 {jobDto.WorkGroupCode}");
|
|
}
|
|
if (jobDto.JobStatus == EnumJobStatus.Doing && jobDto.AcceptUserId != CurrentUser.Id)
|
|
{
|
|
return new NotFoundObjectResult($"任务正在被 {jobDto.AcceptUserName} 处理");
|
|
}
|
|
if (isToday)//只看当日
|
|
{
|
|
if (jobDto.PlanArriveDate.ToString("yyyy-MM-dd") == Clock.Now.ToString("yyyy-MM-dd"))
|
|
{
|
|
return jobDto;
|
|
}
|
|
return new NotFoundObjectResult($"不是当天的收货任务");
|
|
}
|
|
return jobDto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据ASN Number 获取收货任务列表
|
|
/// </summary>
|
|
/// <param name="asnNumber"></param>
|
|
/// <param name="isToday"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("list/by-asn")]
|
|
public virtual async Task<PagedResultDto<PurchaseReceiptJobDTO>> GetListByAsnNumberAsync(string asnNumber, bool isToday)
|
|
{
|
|
var wlgCodes = await _userWorkGroupAppService.GetCodsOfCurrentUserAsync().ConfigureAwait(false);
|
|
var jsonWlgCodes = JsonSerializer.Serialize(wlgCodes);
|
|
|
|
var status = new List<int>() { (int)EnumJobStatus.Open, (int)EnumJobStatus.Doing };
|
|
var jsonStatus = JsonSerializer.Serialize(status);
|
|
|
|
var requestInput = new SfsJobRequestInputBase
|
|
{
|
|
MaxResultCount = 100,
|
|
SkipCount = 0,
|
|
Sorting = $"{nameof(PurchaseReceiptJobDTO.Priority)} ASC",
|
|
Condition = new Condition
|
|
{
|
|
Filters = new List<Filter>
|
|
{
|
|
new(nameof(PurchaseReceiptJobDTO.AsnNumber),asnNumber),
|
|
new(nameof(IssueJobDTO.WorkGroupCode),jsonWlgCodes,"In"),
|
|
new(nameof(IssueJobDTO.JobStatus),jsonStatus,"In"),
|
|
}
|
|
}
|
|
};
|
|
if (isToday)//只看当日
|
|
{
|
|
requestInput.Condition.Filters.Add(new Filter(nameof(PurchaseReceiptJobDTO.PlanArriveDate), Clock.Now.ToString("yyyy-MM-dd"), ">=", "And"));
|
|
}
|
|
var list = await _purchaseReceiptJobAppService.GetPagedListByFilterAsync(requestInput, true).ConfigureAwait(false);
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取任务数量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("count")]
|
|
public virtual async Task<ActionResult<long>> CountAsync()
|
|
{
|
|
var wlgCodes = await _userWorkGroupAppService.GetCodsOfCurrentUserAsync().ConfigureAwait(false);
|
|
var jsonCodes = JsonSerializer.Serialize(wlgCodes);
|
|
|
|
List<int> status = new List<int>() { (int)EnumJobStatus.Open, (int)EnumJobStatus.Doing };
|
|
var jsonStatus = JsonSerializer.Serialize(status);
|
|
|
|
var request = new SfsJobRequestInputBase
|
|
{
|
|
Sorting = $"{nameof(PurchaseReceiptJobDTO.Priority)} ASC",
|
|
Condition = new Condition
|
|
{
|
|
Filters = new List<Filter>
|
|
{
|
|
new(nameof(PurchaseReceiptJobDTO.WorkGroupCode),jsonCodes,"In"),
|
|
new(nameof(PurchaseReceiptJobDTO.JobStatus),jsonStatus,"In")
|
|
}
|
|
}
|
|
};
|
|
|
|
var count = await _purchaseReceiptJobAppService.GetCountByFilterAsync(request).ConfigureAwait(false);
|
|
|
|
return Ok(count);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 承接任务
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("take/{id}")]
|
|
public virtual async Task TakeAsync(Guid id)
|
|
{
|
|
await _purchaseReceiptJobAppService.AcceptAsync(id).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 承接任务
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("cancel-take/{id}")]
|
|
public virtual async Task CancelTakeAsync(Guid id)
|
|
{
|
|
await _purchaseReceiptJobAppService.CancelAcceptAsync(id).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行任务
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("finish/{id}")]
|
|
public virtual async Task FinishAsync(Guid id, [FromBody] PurchaseReceiptJobDTO dto)
|
|
{
|
|
await _purchaseReceiptJobAppService.CompleteAsync(id, dto).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 【设置】所有 待检状态的 收货记录为 合格
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("set-inspect-status-ok-by-inspect/{id}")]
|
|
public virtual async Task<List<PurchaseReceiptJobDetailDTO>> SetInspectStatusOkByNoInspect(Guid id)
|
|
{
|
|
return await _purchaseReceiptJobAppService.SetInspectWithNotInspectAsync(id).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 【保存】目检 结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("save-detail-inspect/{id}")]
|
|
public virtual async Task<PurchaseReceiptJobDetailDTO> SaveDetailAsync(Guid id, PurchaseReceiptJobDetailSaveInput purchaseReceiptJobDetailSaveInput)
|
|
{
|
|
return await _purchaseReceiptJobAppService.SaveDetailInspectAsync(id, purchaseReceiptJobDetailSaveInput).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 【重置】目检 结果
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="detailId"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("reset-detail-inspect/{id}")]
|
|
public virtual async Task ResetDetailAsync(Guid id, Guid detailId)
|
|
{
|
|
await _purchaseReceiptJobAppService.ResetDetailInspectAsync(id, detailId).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 【重置】多个 目检 结果
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="detailIdsGuids"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("reset-many-detail-inspect/{id}")]
|
|
public virtual async Task ResetDetailAsync(Guid id, List<Guid> detailIdsGuids)
|
|
{
|
|
await _purchaseReceiptJobAppService.ResetManyDetailAsync(id, detailIdsGuids).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|