wxw
2024-12-11 0651efda1f08d417c82994887c68dfea2c9b4235
Wms/Wms/Controllers/UpApiController.cs
@@ -33,8 +33,9 @@
        private readonly IStockCheckServer _stockCheckSvc;//盘点单Svc 
        private readonly IProcurePlanServer _procurePlanSvc;//采购单Svs
        private readonly IRcsServer _rcsserver;//RCS相关任务
        private readonly INoticeServer _noticeSvc;//二楼单据相关
        public UpApiController(IOptions<ApiUrlConfig> setting,IExportNoticeServer exNoticeSvc,IArrivalNoticeServer arrivalNoticeServer,IStockCheckServer stockCheckSvc, IProcurePlanServer procurePlanSvc,IRcsServer rcsserver)
        public UpApiController(IOptions<ApiUrlConfig> setting,IExportNoticeServer exNoticeSvc,IArrivalNoticeServer arrivalNoticeServer,IStockCheckServer stockCheckSvc, IProcurePlanServer procurePlanSvc,IRcsServer rcsserver, INoticeServer noticeSvc)
        {
            _config = setting.Value;
            _exNoticeSvc = exNoticeSvc;
@@ -42,7 +43,7 @@
            _stockCheckSvc = stockCheckSvc;
            _procurePlanSvc = procurePlanSvc;
            _rcsserver = rcsserver;
            _noticeSvc = noticeSvc;
        }
        #endregion
@@ -403,24 +404,95 @@
            }
        }
        //RCS叫桶
        #region 二楼业务
        /// <summary>
        /// RCS叫桶
        /// </summary>
        /// <param name="pallmsg"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetPalletNo(Pallnetmsg pallmsg)
        {
            var Pallnet = "";
            var locate = "";
            var result = new ErpModel { Success = -1, Message = "",};
            var logStr = $@".\log\AGV\AGV申请叫桶" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
            var result = new ErpModel { Success = -1, Message = "", };
            try
            {
                if (pallmsg.lotno != null)
                var jsonData = JsonConvert.SerializeObject(pallmsg);
                LogFile.SaveLogToFile($"AGV申请叫桶:( {jsonData} ),", logStr);
                if (string.IsNullOrWhiteSpace(pallmsg.Location))
                {
                    _rcsserver.GetPalletNo(pallmsg.warehouseno, pallmsg.type, pallmsg.lotno, out Pallnet, out locate);
                    result.Message = "叫料位置为空!";
                    return Ok(result);
                }
                else
                if (string.IsNullOrWhiteSpace(pallmsg.Type))
                {
                    _rcsserver.GetPalletNo(pallmsg.warehouseno, pallmsg.type, out Pallnet, out locate);
                    result.Message = "任务类型为空!";
                    return Ok(result);
                }
                _rcsserver.GetPalletNo(pallmsg ,_config.AgvHost + _config.GenAgvSchedulingTask);
                result.Success = 0;
                result.Message = "叫桶成功!";
                return Ok(result);
            }
            catch (Exception e)
            {
                LogFile.SaveLogToFile($"AGV申请叫桶异常:( {e.Message} ),", logStr);
                result.Message = e.Message;
                return Ok(result);
            }
        }
        /// <summary>
        /// 将净桶改为脏桶并拉到脏桶区
        /// </summary>
        /// <param name="pallmsg"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult ChangePalletStatus(Pallnetmsg pallmsg)
        {
            var result = new ErpModel { Success = -1, Message = "", };
            try
            {
                if (string.IsNullOrWhiteSpace(pallmsg.PalletNo))
                {
                    result.Message = "桶编号不能为空!";
                    return Ok(result);
                }
                _rcsserver.ChangePalletStatus(pallmsg.PalletNo, _config.AgvHost + _config.GenAgvSchedulingTask);
                result.Success = 0;
                result.Message = "操作成功!";
                return Ok(result);
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                return Ok(result);
            }
        }
        /// <summary>
        /// MES下发清洗锁定脏桶
        /// </summary>
        /// <param name="pallmsg"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult CleanPallet(Pallnetmsg pallmsg)
        {
            var result = new ErpModel { Success = -1, Message = "", };
            try
            {
                if (string.IsNullOrWhiteSpace(pallmsg.Location))
                {
                    result.Message = "叫料位置为空!";
                    return Ok(result);
                }
                if (string.IsNullOrWhiteSpace(pallmsg.PalletNo))
                {
                    result.Message = "桶号为空!";
                    return Ok(result);
                }
                _rcsserver.CleanPallet(pallmsg, _config.AgvHost + _config.GenAgvSchedulingTask);
                result.Success = 0;
                result.Message = "叫桶成功!";
                return Ok(result);
@@ -431,50 +503,166 @@
                return Ok(result);
            }
        }
        //RCS申请储位
        /// <summary>
        /// RCS申请储位
        /// </summary>
        /// <param name="pallmsg"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult ApplyLocatNo(Pallnetmsg pallmsg)
        {
            var lotno = "";
            var logStr = $@".\log\AGV\AGV申请储位" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
            var result = new ErpModel { Success = -1, Message = "" };
            try
            {
                _rcsserver.ApplyLocatNo(pallmsg.palletno,pallmsg.type, out lotno);
                var jsonData = JsonConvert.SerializeObject(pallmsg);
                LogFile.SaveLogToFile($"AGV申请储位:( {jsonData} ),", logStr);
                if (string.IsNullOrWhiteSpace(pallmsg.Location))
                {
                    result.Message = "申请位置为空!";
                    return Ok(result);
                }
                if (string.IsNullOrWhiteSpace(pallmsg.Type))
                {
                    result.Message = "任务类型为空!";
                    return Ok(result);
                }
                if (string.IsNullOrWhiteSpace(pallmsg.PalletNo))
                {
                    result.Message = "申请托盘号为空!";
                    return Ok(result);
                }
                _rcsserver.ApplyLocatNo(pallmsg, _config.AgvHost + _config.GenAgvSchedulingTask);
                result.Success = 0;
                result.Message = "申请储位成功!";
                return Ok(result);
            }
            catch (Exception e)
            {
                LogFile.SaveLogToFile($"AGV申请储位异常:( {e.Message} ),", logStr);
                result.Message = e.Message;
                return Ok(result);
            }
        }
        //下发调度RCS任务
        //RCS申请储位
        /// <summary>
        /// 入库单据下发
        /// </summary>
        /// <param name="model">入库单信息</param>
        /// <returns></returns>
        //[Authorize]
        [HttpPost]
        public IActionResult genAgvSchedulingTask(AgvTask agvtask)
        public IActionResult CreateAsnWork(AsnInfo model)
        {
            var lotno = "";
            var url = "";
            genAgvSchedulingTaskRep chrep = new genAgvSchedulingTaskRep();
            var result = new ErpModel { Success = -1, Message = "" };
            try
            {
                _rcsserver.genAgvSchedulingTask(agvtask,url,ref chrep);
                result.Success = 0;
                result.Message = "申请储位成功!";
                /*var claimsIdentity = this.User.Identity as ClaimsIdentity;
                if (claimsIdentity == null)
                {
                    throw new Exception("未获取到用户信息");
                }
                string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                if (string.IsNullOrWhiteSpace(UserId))
                {
                    throw new Exception("未获取到用户信息");
                }*/
                result = _noticeSvc.CreateAsnWork(model);
                return Ok(result);
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                return Ok(result);
            }
        }
        /// <summary>
        /// Agv任务完成反馈
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult agvCallBack(AgvTaskDto model)
        {
            var result = new ErpModel { Success = -1, Message = "" };
            try
            {
                //记录log
                var logStr = $@".\log\AGV\任务执行通知" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                var jsonData = JsonConvert.SerializeObject(model);
                LogFile.SaveLogToFile($"任务执行通知:( {jsonData} ),", logStr);
                if (string.IsNullOrEmpty(model.reqCode))
                {
                    return Ok(new AgvResultModel { code = "-1", message = "请求失败,reqCode参数异常", reqCode = model.reqCode });
                }
                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"://任务结束
                        result = _noticeSvc.RCSFinishTask(model.reqCode, "1");
                        return Ok(result);
                    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)
            {
                return Ok(new AgvResultModel { code = "-1", message = ex.Message, reqCode = model.reqCode });
            }
        }
        /// <summary>
        /// 出库单据下发
        /// </summary>
        /// <param name="model">出库单信息</param>
        /// <returns></returns>
        //[Authorize]
        [HttpPost]
        public IActionResult CreateSoWork(SoInfo model)
        {
            try
            {
                /*var claimsIdentity = this.User.Identity as ClaimsIdentity;
                if (claimsIdentity == null)
                {
                    throw new Exception("未获取到用户信息");
                }
                string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                if (string.IsNullOrWhiteSpace(UserId))
                {
                    throw new Exception("未获取到用户信息");
                }*/
                SoResInfo result = _noticeSvc.CreateSoWork(model);
                return Ok(result);
            }
            catch (Exception e)
            {
                return Ok(new ErpModel { Success = -1, Message = e.Message });
            }
        }
        #endregion
        //箱码信息 手持组托用 (赋码或追溯下发到wms)
        //质检结果下发接口