yanjinhui
2026-03-31 0128fce75a5e7cc9afc4bd89ce1966eb2231b69f
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs
@@ -13,6 +13,7 @@
using WIDESEAWCS_DTO;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_QuartzJob;
namespace WIDESEAWCS_TaskInfoService
{
@@ -201,18 +202,91 @@
        }
        #endregion
        #region 5 è·¨æ¥¼å±‚运输任务创建
        #region 5 è·¨æ¥¼å±‚运输任务创建 ï¼ˆéƒ½æ˜¯ç‚¹åˆ°ç‚¹ï¼‰
        public WebResponseContent CarryTask(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_HKLocationInfo? hKLocationInfo = null;
                Dt_StationInfo? stationInfo = null;
                Dt_Task dt_Task = null;
                //入库 åˆ°ä¸€æ¥¼ä¸‰ä¸ªç«™å°çš„位置
                if (taskType == (int)TaskTypeEnum.Q3RK)
                {
                    //读取光电信号
                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "F1") as OtherDevice;
                    if (device == null) throw new Exception("未找到1楼质检门设备信息");
                    if (!device.IsConnected) throw new Exception("PLC1楼质检门设备连接失败");
                    bool value = device.GetValue<QualityInspectionCommandEnum, bool>(QualityInspectionCommandEnum.R_StockAvailableSymbol, taskDTO.toLocationCode);
                    if (value)
                    {
                        content.Error($"{taskDTO.toLocationCode}站台有货,无法入库");
                    }
                    dt_Task = new Dt_Task()
                    {
                        TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        WMSTaskNum = taskDTO.taskCode,
                        Grade = taskDTO.taskPriority,
                        PalletCode = taskDTO.containerCode,
                        Roadway = hKLocationInfo.RoadwayNo,
                        TaskState = (int)TaskStatusEnum.New,
                        TaskType = taskType,
                        SourceAddress = taskDTO.fromLocationCode,
                        CurrentAddress = taskDTO.fromLocationCode,
                        NextAddress = taskDTO.toLocationCode,
                        TargetAddress = taskDTO.toLocationCode,
                        Creater = "WMS",
                    };
                return WebResponseContent.Instance.OK();
                }
                //出库
                if (taskType == (int)TaskTypeEnum.Q3CK)
                {
                     stationInfo = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.toLocationCode) ?? throw new Exception($"未找到起点库位【{taskDTO.toLocationCode}】!");
                    if (stationInfo.StationName != LocationStatusEnum.InStock.ToString()) throw new Exception($"起点库位【{taskDTO.toLocationCode}】当前库位状态不可出库!");
                    if (stationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"起点库位【{taskDTO.toLocationCode}】绑定料箱号【{stationInfo.PalletCode}】与任务料箱号【{taskDTO.containerCode}】不匹配!");
                        dt_Task = new Dt_Task()
                    {
                        TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        WMSTaskNum = taskDTO.taskCode,
                        //WMSId = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        Grade = taskDTO.taskPriority,
                        PalletCode = taskDTO.containerCode,
                        Roadway = hKLocationInfo.RoadwayNo,
                        TaskState = (int)TaskStatusEnum.New,
                        TaskType = taskType,
                        SourceAddress = taskDTO.fromLocationCode,
                        CurrentAddress = taskDTO.fromLocationCode,
                        NextAddress = taskDTO.toLocationCode,
                        TargetAddress = taskDTO.toLocationCode,
                        Creater = "WMS",
                    };
                }
                try
                {
                    Db.Ado.BeginTran();
                    BaseDal.AddData(dt_Task);
                    _hKLocationInfoService.Repository.UpdateData(hKLocationInfo);
                    _stationInfo.Repository.UpdateData(stationInfo);
                    Db.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                    Db.Ado.RollbackTran();
                throw new Exception(ex.Message);
            }
                return content.OK(data: new
                {
                    taskCode = taskDTO.taskCode,
                    Message = "成功!"
                });
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        #endregion