编辑 | blame | 历史 | 原始文档

MES 托盘进站出站集成实现计划

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: 在 TaskService 的入库完成/出库完成方法中集成 MES 进站/出站调用,新增空托盘入库/出库完成方法。

Architecture:ExecuteWithinTransactionAsync 事务内添加 MES 调用,MES 失败则事务回滚。

Tech Stack: ASP.NET Core 6.0, IMesService, ExecuteWithinTransactionAsync


任务总览

任务 方法 操作
Task 1 InboundFinishTaskAsync 添加 InboundInContainer 调用
Task 2 OutboundFinishTaskAsync 添加 OutboundInContainer 调用
Task 3 InboundFinishTaskTrayAsync(新增) 空托盘入库完成,无需 MES
Task 4 OutboundFinishTaskTrayAsync(新增) 空托盘出库完成,无需 MES

任务前置条件

TaskService 需注入 IMesService。检查现有构造函数是否已有:
csharp private readonly IMesService _mesService;

如果不存在,需添加。


Task 1: 修改 InboundFinishTaskAsync 添加 MES 进站调用

Files:
- Modify: WIDESEA_TaskInfoService/TaskService.csInboundFinishTaskAsync 方法,约第 215 行)

  • [ ] Step 1: 查看当前代码确认上下文

读取 TaskService.cs 第 199-240 行,确认 CompleteTaskAsync 调用的位置。

  • [ ] Step 2: 在 CompleteTaskAsync 之前添加 MES InboundInContainer 调用

return await CompleteTaskAsync(task); 之前添加:

// 调用MES托盘进站
var inboundRequest = new InboundInContainerRequest
{
    EquipmentCode = "STK-GROUP-001",
    ResourceCode = "STK-GROUP-001",
    LocalTime = DateTime.Now,
    ContainerCode = taskDto.PalletCode
};
var inboundResult = _mesService.InboundInContainer(inboundRequest);
if (inboundResult == null || inboundResult.Data == null || !inboundResult.Data.IsSuccess)
{
    return content.Error($"任务完成失败:MES进站失败: {inboundResult?.Data?.Msg ?? inboundResult?.ErrorMessage ?? "未知错误"}");
}
  • [ ] Step 3: 添加 using 引用(如果需要)

确认文件顶部已有 using WIDESEA_IBasicService;using WIDESEA_DTO.MES;。如果没有,添加。

  • [ ] Step 4: 构建验证
cd WIDESEA_WMSServer && dotnet build WIDESEA_TaskInfoService/WIDESEA_TaskInfoService.csproj

确认无编译错误。

  • [ ] Step 5: 提交
git add WIDESEA_TaskInfoService/TaskService.cs
git commit -m "feat(TaskService): InboundFinishTaskAsync添加MES进站调用"

Task 2: 修改 OutboundFinishTaskAsync 添加 MES 出站调用

Files:
- Modify: WIDESEA_TaskInfoService/TaskService.csOutboundFinishTaskAsync 方法,约第 258 行)

  • [ ] Step 1: 查看当前代码确认上下文

读取 TaskService.cs 第 258-280 行,确认 CompleteTaskAsync 调用的位置。

  • [ ] Step 2: 在 CompleteTaskAsync 之前添加 MES OutboundInContainer 调用

return await CompleteTaskAsync(task); 之前添加:

// 调用MES托盘出站
var outboundRequest = new OutboundInContainerRequest
{
    EquipmentCode = "STK-GROUP-001",
    ResourceCode = "STK-GROUP-001",
    LocalTime = DateTime.Now,
    ContainerCode = taskDto.PalletCode,
    ParamList = new List<ParamItem>()
};
var outboundResult = _mesService.OutboundInContainer(outboundRequest);
if (outboundResult == null || outboundResult.Data == null || !outboundResult.Data.IsSuccess)
{
    return content.Error($"任务完成失败:MES出站失败: {outboundResult?.Data?.Msg ?? outboundResult?.ErrorMessage ?? "未知错误"}");
}
  • [ ] Step 3: 构建验证
cd WIDESEA_WMSServer && dotnet build WIDESEA_TaskInfoService/WIDESEA_TaskInfoService.csproj

确认无编译错误。

  • [ ] Step 4: 提交
git add WIDESEA_TaskInfoService/TaskService.cs
git commit -m "feat(TaskService): OutboundFinishTaskAsync添加MES出站调用"

Task 3: 新增 InboundFinishTaskTrayAsync 空托盘入库完成方法

Files:
- Modify: WIDESEA_TaskInfoService/TaskService.cs(在 InboundFinishTaskTrayAsync 方法之后添加新方法)

  • [ ] Step 1: 查看现有 InboundFinishTaskTrayAsync 方法位置

读取 TaskService.cs 第 330-350 行,确认 CreateTaskInboundTrayAsync 之后的位置。

  • [ ] Step 2: 添加新方法 InboundFinishTaskTrayAsync

CreateTaskInboundTrayAsync 方法之后添加:

/// <summary>
/// 空托盘入库完成
/// </summary>
public async Task<WebResponseContent> InboundFinishTaskTrayAsync(CreateTaskDto taskDto)
{
    try
    {
        var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode);
        if (task == null) return WebResponseContent.Instance.Error("未找到对应的任务");

        var location = await _locationInfoService.GetLocationInfo(task.Roadway, task.TargetAddress);
        if (location == null) return WebResponseContent.Instance.Error("未找到对应的货位");

        var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
        if (stockInfo == null) return WebResponseContent.Instance.Error("未找到对应库存信息");

        return await ExecuteWithinTransactionAsync(async () =>
        {
            stockInfo.LocationCode = location.LocationCode;
            stockInfo.LocationId = location.Id;
            stockInfo.StockStatus = StockStatusEmun.空托盘库存.GetHashCode();

            location.LocationStatus = LocationStatusEnum.InStock.GetHashCode();

            var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
            var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
            if (!updateLocationResult || !updateStockResult)
                return WebResponseContent.Instance.Error("任务完成失败");

            var deleteResult = await BaseDal.DeleteDataAsync(task);
            if (!deleteResult) return WebResponseContent.Instance.Error("任务完成失败");

            return WebResponseContent.Instance.OK("任务完成");
        });
    }
    catch (Exception ex)
    {
        return WebResponseContent.Instance.Error($"完成任务失败: {ex.Message}");
    }
}
  • [ ] Step 3: 构建验证
cd WIDESEA_WMSServer && dotnet build WIDESEA_TaskInfoService/WIDESEA_TaskInfoService.csproj

确认无编译错误。

  • [ ] Step 4: 提交
git add WIDESEA_TaskInfoService/TaskService.cs
git commit -m "feat(TaskService): 新增InboundFinishTaskTrayAsync空托盘入库完成方法"

Task 4: 新增 OutboundFinishTaskTrayAsync 空托盘出库完成方法

Files:
- Modify: WIDESEA_TaskInfoService/TaskService.cs(在 OutboundFinishTaskTrayAsync 方法之后添加新方法)

  • [ ] Step 1: 查看现有 GetOutBoundTrayTaskAsync 方法位置

读取 TaskService.cs 第 357-393 行,确认 GetOutBoundTrayTaskAsync 之后的位置。

  • [ ] Step 2: 添加新方法 OutboundFinishTaskTrayAsync

GetOutBoundTrayTaskAsync 方法之后添加:

/// <summary>
/// 空托盘出库完成
/// </summary>
public async Task<WebResponseContent> OutboundFinishTaskTrayAsync(CreateTaskDto taskDto)
{
    try
    {
        var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode);
        if (task == null) return WebResponseContent.Instance.Error("未找到对应的任务");

        var location = await _locationInfoService.GetLocationInfo(task.Roadway, task.SourceAddress);
        if (location == null) return WebResponseContent.Instance.Error("未找到对应的货位");

        var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
        if (stockInfo == null) return WebResponseContent.Instance.Error("未找到对应库存信息");

        return await ExecuteWithinTransactionAsync(async () =>
        {
            stockInfo.LocationId = 0;
            stockInfo.LocationCode = null;
            stockInfo.StockStatus = StockStatusEmun.出库完成.GetHashCode();

            location.LocationStatus = LocationStatusEnum.Free.GetHashCode();

            var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
            var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
            if (!updateLocationResult || !updateStockResult)
                return WebResponseContent.Instance.Error("任务完成失败");

            var deleteResult = await BaseDal.DeleteDataAsync(task);
            if (!deleteResult) return WebResponseContent.Instance.Error("任务完成失败");

            return WebResponseContent.Instance.OK("任务完成");
        });
    }
    catch (Exception ex)
    {
        return WebResponseContent.Instance.Error($"完成任务失败: {ex.Message}");
    }
}
  • [ ] Step 3: 构建验证
cd WIDESEA_WMSServer && dotnet build WIDESEA_TaskInfoService/WIDESEA_TaskInfoService.csproj

确认无编译错误。

  • [ ] Step 4: 提交
git add WIDESEA_TaskInfoService/TaskService.cs
git commit -m "feat(TaskService): 新增OutboundFinishTaskTrayAsync空托盘出库完成方法"

Task 5: 整体构建验证

  • [ ] Step 1: 构建整个解决方案
cd WIDESEA_WMSServer && dotnet build WIDESEA_WMSServer.sln

确认无编译错误、无警告。


验证检查清单

  • [ ] InboundFinishTaskAsyncInboundInContainerCompleteTaskAsync 之前
  • [ ] OutboundFinishTaskAsyncOutboundInContainerCompleteTaskAsync 之前
  • [ ] 所有 MES 调用检查 mesResult.Data?.IsSuccess
  • [ ] 错误信息格式:"任务完成失败:MES{操作}失败: {错误信息}"
  • [ ] InboundFinishTaskTrayAsyncOutboundFinishTaskTrayAsync 新增方法签名正确
  • [ ] 解决方案构建无错误