|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text.Json;
|
|
|
|
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.Shared.Domain;
|
|
|
|
using Win_in.Sfs.Shared.Domain.Shared;
|
|
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.Pda.Controllers.Jobs;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
[ApiController]
|
|
|
|
[Route($"{PdaHostConst.ROOT_ROUTE}job/deliver")]
|
|
|
|
|
|
|
|
public class DeliverJobController : AbpController
|
|
|
|
{
|
|
|
|
private readonly IDeliverJobAppService _deliverJobAppService;
|
|
|
|
|
|
|
|
private readonly IUserWorkGroupAppService _userWorkGroupAppService;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="deliverJobAppService"></param>
|
|
|
|
/// <param name="userWorkGroupAppService"></param>
|
|
|
|
public DeliverJobController(
|
|
|
|
IDeliverJobAppService deliverJobAppService
|
|
|
|
, IUserWorkGroupAppService userWorkGroupAppService)
|
|
|
|
{
|
|
|
|
_userWorkGroupAppService = userWorkGroupAppService;
|
|
|
|
_deliverJobAppService = deliverJobAppService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取发货任务详情
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
|
|
|
public virtual async Task<ActionResult<DeliverJobDTO>> GetAsync(Guid id)
|
|
|
|
{
|
|
|
|
var result = await _deliverJobAppService.GetAsync(id).ConfigureAwait(false);
|
|
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取列表 筛选
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sfsRequestDTO"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("list")]
|
|
|
|
public virtual async Task<PagedResultDto<DeliverJobDTO>> GetListAsync(SfsJobRequestInputBase sfsRequestDTO)
|
|
|
|
{
|
|
|
|
var list = await _deliverJobAppService.GetPagedListByFilterAsync(sfsRequestDTO, true).ConfigureAwait(false);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取列表
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="pageSize"></param>
|
|
|
|
/// <param name="pageIndex"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("list")]
|
|
|
|
public virtual async Task<PagedResultDto<DeliverJobDTO>> GetListAsync(int pageSize, int pageIndex)
|
|
|
|
{
|
|
|
|
var wlgCodes = await _userWorkGroupAppService.GetCodsOfCurrentUserAsync().ConfigureAwait(false);
|
|
|
|
_ = 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(DeliverJobDTO.Priority)} ASC",
|
|
|
|
Condition = new Condition
|
|
|
|
{
|
|
|
|
Filters = new List<Filter>
|
|
|
|
{
|
|
|
|
// new(nameof(DeliverJobDTO.WorkGroupCode),jsonCodes,"In"),
|
|
|
|
new(nameof(DeliverJobDTO.JobStatus),jsonStatus,"In")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var list = await _deliverJobAppService.GetPagedListByFilterAsync(request, true).ConfigureAwait(false);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据Job Number 获取发货任务列表
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="jobNumber"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("by-number/{jobNumber}")]
|
|
|
|
public virtual async Task<ActionResult<DeliverJobDTO>> GetByNumberAsync(string jobNumber)
|
|
|
|
{
|
|
|
|
var jobDto = await _deliverJobAppService.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 (jobDto.JobStatus == EnumJobStatus.Doing && jobDto.AcceptUserId != CurrentUser.Id)
|
|
|
|
{
|
|
|
|
return new NotFoundObjectResult($"任务正在被 {jobDto.AcceptUserName} 处理");
|
|
|
|
}
|
|
|
|
return jobDto;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <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<string> status = new List<string>() { EnumJobStatus.Open.ToString(), EnumJobStatus.Doing.ToString() };
|
|
|
|
var jsonStatus = JsonSerializer.Serialize(status);
|
|
|
|
|
|
|
|
var request = new SfsJobRequestInputBase
|
|
|
|
{
|
|
|
|
Sorting = $"{nameof(DeliverJobDTO.Priority)} ASC",
|
|
|
|
Condition = new Condition
|
|
|
|
{
|
|
|
|
Filters = new List<Filter>
|
|
|
|
{
|
|
|
|
new(nameof(DeliverJobDTO.WorkGroupCode),jsonCodes,"In"),
|
|
|
|
new(nameof(DeliverJobDTO.JobStatus),jsonStatus,"In")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var count = await _deliverJobAppService.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 _deliverJobAppService.AcceptAsync(id).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 取消承接任务
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("cancel-take/{id}")]
|
|
|
|
public virtual async Task CancelTakeAsync(Guid id)
|
|
|
|
{
|
|
|
|
await _deliverJobAppService.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] DeliverJobDTO dto)
|
|
|
|
{
|
|
|
|
await _deliverJobAppService.CompleteAsync(id, dto).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|