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.

282 lines
11 KiB
C#

using System.Net;
using DS.Module.Core;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.TaskInteraction.Dtos;
using DS.WMS.Core.TaskInteraction.Entity;
using DS.WMS.Core.TaskInteraction.Interface;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
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>
1 month ago
/// 获取任务列表
/// </summary>
/// <param name="businessId">业务ID</param>
1 month ago
/// <param name="businessType">业务类型(可选参数)</param>
/// <param name="withSubTask">是否获取子任务,默认为否</param>
/// <param name="taskTypes">任务类型名称(支持多个,可选参数)</param>
/// <returns></returns>
/// <remarks>/GetTasks?taskTypes=任务类型1&amp;taskTypes=任务类型2</remarks>
1 month ago
[HttpGet, Route("GetTasks")]
public async Task<DataResult<List<BusinessTask>>> GetTasksAsync(long businessId, BusinessType? businessType,
bool withSubTask = false, params string[] taskTypes)
{
TaskBaseTypeEnum[]? types = null;
if (taskTypes?.Length > 0)
types = taskTypes.Select(Enum.Parse<TaskBaseTypeEnum>).ToArray();
return await taskService.GetTasks(businessId, businessType, withSubTask, types);
}
1 month ago
/// <summary>
/// 获取提单确认信息
1 month ago
/// </summary>
/// <param name="businessId">业务ID</param>
/// <param name="businessType">业务类型(可选参数)</param>
1 month ago
/// <returns></returns>
[HttpGet, Route("GetBLConfirmation")]
public async Task<DataResult<BLConfirmation>> GetBLConfirmationAsync(long businessId, BusinessType businessType)
1 month ago
{
return await taskService.GetBLConfirmationAsync(businessId, businessType);
1 month ago
}
/// <summary>
/// 获取指定业务的任务日志
/// </summary>
/// <param name="logService"></param>
/// <param name="businessId">业务ID</param>
1 month ago
/// <param name="businessType">业务类型(可选参数)</param>
/// <returns></returns>
[HttpGet, Route("GetLogs")]
public async Task<DataResult<List<BusinessTaskLog>>> GetLogsAsync([FromServices] ITaskLogService logService,
1 month ago
[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, false, request.TaskType);
if (result.Data?.Count > 0)
{
var task = result.Data[0];
task.BusinessId = request.BusinessId;
task.BusinessType = request.BusinessType;
Dictionary<string, object>? dic = null;
if (request.ExtraData is JObject jobject)
{
dic = [];
foreach (var item in jobject)
dic.Add(item.Key, item.Value?.ToString());
}
return await actionService.TriggerActionAsync(task, false,
request.ExtraData == null ? null : dic);
}
return DataResult.FailedWithDesc(nameof(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("SetSteps")]
1 month ago
public async Task<DataResult> SetStepsAsync([FromBody] TaskRequest request)
{
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await taskService.SetStepsAsync(request);
}
/// <summary>
/// 手动发起任务审核(用于二次审核)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost, Route("SubmitAudit")]
1 month ago
public async Task<DataResult> SubmitAuditAsync([FromBody] TaskRequest request)
{
4 months ago
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)
{
4 months ago
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")]
4 months ago
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] : []);
}
}
}