You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
9.3 KiB
C#

using System.Net;
using DS.Module.Core;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Op.Dtos.TaskInteraction;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Entity.TaskInteraction;
using DS.WMS.Core.Op.Interface.TaskInteraction;
using Mapster;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.OpApi.Controllers
{
/// <summary>
/// 海运出口任务API
/// </summary>
public class SeaExportTaskController : ApiController
{
readonly ISeaExportTaskService taskService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="service"></param>
public SeaExportTaskController(ISeaExportTaskService service)
{
taskService = service;
}
/// <summary>
/// 获取业务的任务信息
/// </summary>
/// <param name="businessId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <param name="taskTypes">任务类型名称(支持多个,可选参数)</param>
/// <returns></returns>
/// <remarks>/GetTasks?taskTypes=任务类型1&amp;taskTypes=任务类型2</remarks>
[HttpGet, Route("GetTasks")]
public async Task<DataResult<List<BusinessTaskDto>>> GetTasksAsync(
[FromQuery] long businessId, [FromQuery] BusinessType businessType, [FromQuery] params string[] taskTypes)
{
TaskBaseTypeEnum[]? types = null;
if (taskTypes?.Length > 0)
types = taskTypes.Select(Enum.Parse<TaskBaseTypeEnum>).ToArray();
return await taskService.GetTasks(businessId, businessType, types);
}
/// <summary>
/// 获取指定业务的任务日志
/// </summary>
/// <param name="logService"></param>
/// <param name="businessId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
[HttpGet, Route("GetLogs")]
public async Task<DataResult<List<BusinessTaskLog>>> GetLogsAsync([FromServices] ITaskLogService logService,
[FromQuery] long businessId, [FromQuery] BusinessType businessType)
{
return await logService.ReadLogAsync(businessId, businessType);
}
/// <summary>
/// 触发自动订舱
/// </summary>
/// <param name="actionService"></param>
/// <param name="businessId">业务ID</param>
/// <param name="businessType">业务类型(可空,默认=海运出口)</param>
/// <returns></returns>
[HttpPost, Route("AutomaticBooking")]
public async Task<DataResult> AutomaticBookingAsync([FromServices] IActionManagerService actionService,
[FromQuery] long businessId, [FromQuery] BusinessType businessType = BusinessType.OceanShippingExport)
{
return await actionService.AutomaticBooking(businessId, businessType);
}
/// <summary>
/// 运行任务动作
/// </summary>
/// <param name="actionService"></param>
/// <param name="request">任务信息</param>
/// <returns></returns>
[HttpPost, Route("RunTaskAction")]
public async Task<DataResult> RunTaskActionAsync([FromServices] IActionManagerService actionService, [FromBody] TaskRequest request)
{
var result = await taskService.GetTasks(request.BusinessId, request.BusinessType, request.TaskType);
if (result.Data?.Count > 0)
return await actionService.TriggerActionAsync(result.Data[0].Adapt<BusinessTask>(), false);
return DataResult.FailedWithDesc(MultiLanguageConst.EmptyData);
}
/// <summary>
/// 创建服务项目任务
/// </summary>
/// <param name="businessId">业务ID</param>
/// <param name="businessType">业务类型(可空,默认=海运出口)</param>
/// <returns></returns>
[HttpPost, Route("CreateSubTask")]
public async Task<IActionResult> CreateSubTaskAsync([FromQuery] long businessId,
[FromQuery] BusinessType businessType = BusinessType.OceanShippingExport)
{
HttpStatusCode statusCode = HttpStatusCode.NoContent;
try
{
await taskService.CreateSubTaskAsync(new BusinessTask
{
BusinessId = businessId,
BusinessType = businessType
});
}
catch
{
statusCode = HttpStatusCode.InternalServerError;
}
return new StatusCodeResult((int)statusCode);
}
/// <summary>
/// 创建关联任务
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost, Route("CreateTask")]
public async Task<DataResult> CreateTaskAsync([FromBody] TaskCreationRequest request)
{
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await taskService.CreateTaskAsync(request);
}
/// <summary>
/// 批量创建关联任务
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <remarks>使用【Ids】字段指定多个业务ID</remarks>
[HttpPost, Route("CreateMultipleTask")]
public async Task<DataResult> CreateMultipleTaskAsync([FromBody] TaskCreationRequest request)
{
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await taskService.CreateMultipleTaskAsync(request);
}
/// <summary>
/// 设置任务状态
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost, Route("SetTaskStatus")]
public async Task<DataResult> SetTaskStatusAsync([FromBody] TaskUpdateRequest request)
{
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await taskService.SetTaskStatusAsync(request);
}
/// <summary>
/// 手动发起任务审核(用于二次审核)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost, Route("SubmitAudit")]
public async Task<DataResult> SubmitAuditAsync(TaskRequest request)
{
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await taskService.SubmitAuditAsync(request);
}
/// <summary>
/// 任务审核
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost, Route("Audit")]
public async virtual Task<DataResult> AuditAsync([FromBody] TaskAuditRequest request)
{
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await taskService.AuditAsync(request);
}
/// <summary>
/// 撤销审核任务(目前仅支持单票)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost, Route("Withdraw")]
public async virtual Task<DataResult> AuditAsync([FromBody] TaskRequest request)
{
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await taskService.WithdrawAsync(request);
}
/// <summary>
/// 审批完成回调更新(无需客户端手动调用)
/// </summary>
/// <param name="callback">回调信息</param>
/// <returns></returns>
[HttpPost, Route("UpdateBusiness")]
public async Task<IActionResult> UpdateBusinessAsync([FromBody] FlowCallback callback)
{
await taskService.UpdateBusinessAsync(callback);
return StatusCode((int)HttpStatusCode.NoContent);
}
/// <summary>
/// 通知审批执行人变更(无需客户端手动调用)
/// </summary>
/// <param name="callback">回调信息</param>
/// <returns></returns>
[HttpPost, Route("MarkerChanged")]
public async Task<IActionResult> MarkerChangedAsync([FromBody] MarkerChangedCallback callback)
{
await taskService.MarkerChangedAsync(callback);
return StatusCode((int)HttpStatusCode.NoContent);
}
/// <summary>
/// 删除任务(内部调试用)
/// </summary>
/// <param name="id">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <param name="taskType">任务类型(为空时删除全部任务)</param>
/// <returns></returns>
[HttpPost, Route("Delete")]
public async Task<DataResult> Delete(long id, BusinessType? businessType, TaskBaseTypeEnum? taskType = null)
{
return await taskService.DeleteAsync(id, businessType, "API请求删除任务", taskType.HasValue ? [taskType.Value] : []);
}
}
}