wxw
2025-11-11 cbe2572195c6f1ebe26a269289dba7f516245a1d
Wms/Wms/Controllers/DownApiController.cs
@@ -20,6 +20,8 @@
using WMS.IBLL.IBllTransServer;
using Microsoft.Extensions.Logging;
using ZXing.QrCode.Internal;
using Model.ModelVm.BllCheckVm;
using System.DirectoryServices.Protocols;
namespace Wms.Controllers
{
@@ -682,7 +684,7 @@
                }
                string taskNo = "";
                //具体处理方法
                _rcsserver.GetPalletNo(pallmsg, _config.AgvHost + _config.GenAgvSchedulingTask, out taskNo);
                _rcsserver.GetPalletNo(pallmsg, _config.AgvHost + _config.GenAgvSchedulingTask, _config.MesHost + _config.MesPanClearPallet, out taskNo);
                resultModel = new AgvResultModel { code = "0", message = "叫桶成功!", data = taskNo, reqCode = "" };
                var jsonData2 = JsonConvert.SerializeObject(resultModel);
@@ -729,13 +731,13 @@
                    LogFile.SaveLogToFile($"AGV申请储位-返回报文:( {jsonData3} ),", logStr);
                    return Ok(resultModel);
                }
                if (string.IsNullOrWhiteSpace(pallmsg.PalletNo))
                {
                    resultModel = new AgvResultModel { code = "1", message = "申请桶号为空!", data = "", reqCode = "" };
                    var jsonData3 = JsonConvert.SerializeObject(resultModel);
                    LogFile.SaveLogToFile($"AGV申请储位-返回报文:( {jsonData3} ),", logStr);
                    return Ok(resultModel);
                }
                //if (string.IsNullOrWhiteSpace(pallmsg.PalletNo))
                //{
                //    resultModel = new AgvResultModel { code = "1", message = "申请桶号为空!", data = "", reqCode = "" };
                //    var jsonData3 = JsonConvert.SerializeObject(resultModel);
                //    LogFile.SaveLogToFile($"AGV申请储位-返回报文:( {jsonData3} ),", logStr);
                //    return Ok(resultModel);
                //}
                string taskNo = "";
                //具体处理方法
                _rcsserver.ApplyLocatNo(pallmsg, _config.AgvHost + _config.GenAgvSchedulingTask, out taskNo);
@@ -756,16 +758,20 @@
            }
        }
        /// <summary>
        /// 将净桶改为脏桶并拉到脏桶区
        /// MES将净桶改为脏桶并拉到脏桶区
        /// </summary>
        /// <param name="pallmsg"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult ChangePalletStatus(Pallnetmsg pallmsg)
        {
            var logStr = $@".\log\MES\MES将净桶改为脏桶并拉到脏桶区" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
            var result = new ErpModel { Success = -1, Message = "", };
            try
            {
                var jsonData = JsonConvert.SerializeObject(pallmsg);
                LogFile.SaveLogToFile($"MES将净桶改为脏桶并拉到脏桶区-请求报文:( {jsonData} ),", logStr);
                if (string.IsNullOrWhiteSpace(pallmsg.PalletNo))
                {
                    result.Message = "桶编号不能为空!";
@@ -778,22 +784,28 @@
            }
            catch (Exception e)
            {
                LogFile.SaveLogToFile($"MES将净桶改为脏桶并拉到脏桶区异常:( {e.Message} ),", logStr);
                result.Message = e.Message;
                return Ok(result);
            }
        }
        /// <summary>
        /// MES下发清洗锁定脏桶
        /// MES下发清洗指定脏桶
        /// </summary>
        /// <param name="pallmsg"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult CleanPallet(Pallnetmsg pallmsg)
        {
            var result = new ErpModel { Success = -1, Message = "", };
            var logStr = $@".\log\MES\MES下发清洗指定脏桶" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
            ErpModel result = new ErpModel { Success = -1, Message = "" };
            try
            {
                var jsonData = JsonConvert.SerializeObject(pallmsg);
                LogFile.SaveLogToFile($"MES下发清洗指定脏桶-请求报文:( {jsonData} ),", logStr);
                if (string.IsNullOrWhiteSpace(pallmsg.Location))
                {
                    result.Message = "叫料位置为空!";
@@ -811,6 +823,7 @@
            }
            catch (Exception e)
            {
                LogFile.SaveLogToFile($"MES下发清洗指定脏桶异常:( {e.Message} ),", logStr);
                result.Message = e.Message;
                return Ok(result);
            }
@@ -939,7 +952,7 @@
                LogFile.SaveLogToFile($"AGV任务执行通知-任务结束-请求报文:( {jsonData} ),", logStr);
                //具体处理方法
                _rcsserver.RCSFinishTask(model.taskCode, "1");
                _rcsserver.RCSFinishTask(model.taskCode, "1", "AGV");
                resultModel = new AgvResultModel { code = "0", message = "成功", reqCode = model.reqCode };
@@ -994,56 +1007,6 @@
        }        
        #endregion
        /// <summary>
        /// Agv任务完成反馈
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult agvCallBack(AgvTaskDto model)
        {
            //记录log
            var logStr = $@".\log\AGV\任务执行通知" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
            AgvResultModel resultModel = null;
            try
            {
                var jsonData = JsonConvert.SerializeObject(model);
                LogFile.SaveLogToFile($"任务执行通知-请求报文:( {jsonData} ),", logStr);
                if (string.IsNullOrEmpty(model.taskCode))
                {
                    resultModel = new AgvResultModel { code = "-1", message = "请求失败,taskCode参数异常", reqCode = model.reqCode };
                    var jsonData2 = JsonConvert.SerializeObject(resultModel);
                    LogFile.SaveLogToFile($"任务执行通知-返回报文:( {jsonData2} ),", logStr);
                    return Ok(resultModel);
                }
                switch (model.method)
                {
                    case "start"://任务开始
                        return Ok(new AgvResultModel { code = "0", message = "成功", reqCode = model.reqCode });
                    case "outbin"://走出储位
                        return Ok(new AgvResultModel { code = "0", message = "成功", reqCode = model.reqCode });
                    case "end"://任务结束
                        _rcsserver.RCSFinishTask(model.taskCode, "1");
                        return Ok(new AgvResultModel { code = "0", message = "成功", reqCode = model.reqCode });
                    case "cancel"://任务单取消
                        return Ok(new AgvResultModel { code = "0", message = "成功", reqCode = model.reqCode });
                    case "apply"://CTU料箱取放申请
                        return Ok(new AgvResultModel { code = "0", message = "成功", reqCode = model.reqCode });
                    default:
                        return Ok(new AgvResultModel { code = "-1", message = "请求失败,method任务类型错误", reqCode = model.reqCode });
                }
            }
            catch (Exception ex)
            {
                LogFile.SaveLogToFile($"AGV任务执行通知异常:( {ex.Message} ),", logStr);
                return Ok(new AgvResultModel { code = "-1", message = ex.Message, reqCode = model.reqCode });
            }
        }
        /// <summary>
        /// 出库单据下发
@@ -1076,6 +1039,100 @@
                return Ok(new ErpModel { Success = -1, Message = e.Message });
            }
        }
        /// <summary>
        /// 手动下发小车任务
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult SendAgvTaskWms(CheckTaskVm model)
        {
            try
            {
                //获取当前登录的用户ID
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                if (claimsIdentity == null)
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                if (string.IsNullOrWhiteSpace(userId))
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                _rcsserver.DownTask(model.taskNo, int.Parse(userId), _config.AgvHost + _config.GenAgvSchedulingTask);
                return Ok(new { code = 0, msg = "重新下发已完成", data = "" });
            }
            catch (Exception e)
            {
                return Ok(new { code = 1, msg = e.Message });
            }
        }
        /// <summary>
        /// 手动完成小车任务
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult FinshAgvTaskWms(CheckTaskVm model)
        {
            try
            {
                //获取当前登录的用户ID
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                if (claimsIdentity == null)
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                if (string.IsNullOrWhiteSpace(userId))
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                //具体处理方法
                _rcsserver.RCSFinishTask(model.taskNo, "1", "WMS");
                return Ok(new { code = 0, msg = "重新下发已完成", data = "" });
            }
            catch (Exception e)
            {
                return Ok(new { code = 1, msg = e.Message });
            }
        }
        /// <summary>
        /// 手动取消AGV移库任务
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult CancelAgvTaskWms(CheckTaskVm model)
        {
            try
            {
                //获取当前登录的用户ID
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                if (claimsIdentity == null)
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                if (string.IsNullOrWhiteSpace(userId))
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                _rcsserver.CancelTask(model.taskNo, int.Parse(userId));
                return Ok(new { code = 0, msg = "成功取消任务", data = "" });
            }
            catch (Exception e)
            {
                return Ok(new { code = 1, msg = e.Message });
            }
        }
        #endregion
    }
}