huangxiaoqiang
2026-02-06 b3f28f51ef169d246f42fd4fa4656cff2bcfe05d
完善组盘/换盘/拆盘接口及机器人业务流程

本次提交主要内容如下:

- 扩展 ConfigKey 枚举,新增组盘、换盘、拆盘相关接口枚举值及注释;
- 重构 RobotJob.cs,优化机器人任务完成后的处理逻辑,按任务类型分别调用 MES/WMS 组盘、换盘、拆盘接口,并根据接口返回状态调整机器人动作;
- 新增 StockController,提供组盘、换盘、拆盘接口,支持 GET/POST,允许匿名访问,调用对应服务方法处理库存操作;
- 增强机器人与 WMS/MES 的库存业务流程,提升系统库存操作的灵活性和完整性。
已添加1个文件
已修改2个文件
118 ■■■■■ 文件已修改
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/HttpEnum/ConfigKey.cs 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockController.cs 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/HttpEnum/ConfigKey.cs
@@ -19,6 +19,24 @@
        MES_API_Base,
        MES_API_Url,
        MES_API_Timeout
        MES_API_Timeout,
        #region WMS接口
        /// <summary>
        /// ç»„盘
        /// </summary>
        GroupPalletAsync,
        /// <summary>
        /// æ¢ç›˜
        /// </summary>
        ChangePalletAsync,
        /// <summary>
        /// æ‹†ç›˜
        /// </summary>
        SplitPalletAsync
        #endregion
    }
}
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
@@ -1,7 +1,13 @@
using Quartz;
using HslCommunication;
using Newtonsoft.Json;
using Quartz;
using System.Collections.Concurrent;
using System.Net.Sockets;
using System.Text.Json;
using WIDESEAWCS_Common.HttpEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.Http;
using WIDESEAWCS_DTO.Stock;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
@@ -123,6 +129,7 @@
        /// <returns></returns>
        private async Task<string?> _TcpSocket_MessageReceived(string message, bool isJson, TcpClient client, RobotSocketState state)
        {
            WebResponseContent content = new WebResponseContent();
            string messageLower = message.ToLowerInvariant();
            if (IsSimpleCommand(messageLower, state))
@@ -146,12 +153,38 @@
                        if (cmd.StartsWith("pickfinished"))
                        {
                            StockDTO stockDTO = new StockDTO
                            {
                                SourceLineNo = state.CurrentTask?.RobotSourceAddressLineCode,
                                SourcePalletNo = state.CurrentTask?.RobotSourceAddressPalletCode,
                                TargetPalletNo = state.CurrentTask?.RobotTargetAddressPalletCode,
                                TargetLineNo = state.CurrentTask?.RobotTargetAddressLineCode,
                                Details = positions
                                        .Where(x => x > 0)
                                        .OrderBy(x => x)
                                        .Select((x, idx) => new StockDetailDTO
                                        {
                                            Quantity = state.CurrentTask?.RobotTaskTotalNum ?? 1,
                                            Channel = x > 0 ? x : throw new ArgumentOutOfRangeException(nameof(x), "Channel must be positive"),
                                            CellBarcode = state.CellBarcode[idx]
                                        })
                                        .ToList()
                            };
                            state.LastPickPositions = positions;
                            var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), state.CurrentTask?.RobotTaskType == 2 ? nameof(ConfigKey.ChangePalletAsync) : nameof(ConfigKey.SplitPalletAsync));
                            content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                            if (content.Status)
                            {
                            state.CurrentAction = "PickFinished";
                            }
                        }
                        else if (cmd.StartsWith("putfinished"))
                        {
                            state.LastPutPositions = positions;
                            if (state.CurrentTask?.RobotTaskType == 1)
                            {
                            // å‘送数据给WMS组盘/换盘
                            StockDTO stockDTO = new StockDTO
                            {
@@ -170,10 +203,17 @@
                                    })
                                    .ToList()
                            };
                                var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), nameof(ConfigKey.GroupPalletAsync));
                                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                                if (content.Status)
                                {
                            state.CurrentAction = "PutFinished";
                        }
                    }
                }
                    }
                }
                catch { }
                return null;
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockController.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,56 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WIDESEA_Core;
using WIDESEA_Core.BaseController;
using WIDESEA_DTO.Stock;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
namespace WIDESEA_WMSServer.Controllers.Stock
{
    /// <summary>
    /// åº“å­˜
    /// </summary>
    [Route("api/Stock")]
    [ApiController]
    public class StockController : ApiBaseController<IStockService, Dt_StockInfo>
    {
        public StockController(IStockService service) : base(service)
        {
        }
        /// <summary>
        /// ç»„盘
        /// </summary>
        /// <param name="stock"></param>
        /// <returns></returns>
        [HttpGet,HttpPost,Route("GroupPalletAsync"), AllowAnonymous]
        public async Task<bool> GroupPallet([FromBody]StockDTO stock)
        {
            return await Service.GroupPallet(stock);
        }
        /// <summary>
        /// æ¢ç›˜
        /// </summary>
        /// <param name="stock"></param>
        /// <returns></returns>
        [HttpGet, HttpPost, Route("ChangePalletAsync"),AllowAnonymous]
        public async Task<bool> ChangePallet([FromBody] StockDTO stock)
        {
            return await Service.ChangePallet(stock);
        }
        /// <summary>
        /// æ‹†ç›˜
        /// </summary>
        /// <param name="stock"></param>
        /// <returns></returns>
        [HttpGet, HttpPost, Route("SplitPalletAsync"), AllowAnonymous]
        public async Task<bool> SplitPallet([FromBody] StockDTO stock)
        {
            return await Service.SplitPallet(stock);
        }
    }
}