1
huanghongfeng
21 小时以前 9b2a125b8e539859774176979fc4956c379f05cc
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
@@ -18,6 +18,11 @@
using WIDESEA_Common.TaskEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.CommonEnum;
using WIDESEA_DTO.ToMes;
using System.Diagnostics;
using WIDESEA_Common.OtherEnum;
using WIDESEA_Core.Const;
namespace WIDESEA_TaskInfoService
{
@@ -40,10 +45,12 @@
                    PushTasksToWCS(new List<Dt_Task> { task });
                    return WebResponseContent.Instance.OK($"该托盘已生成任务", _mapper.Map<WMSTaskDTO>(task));
                }
                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
               /* if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == OutTaskStatusEnum.New.ObjToInt()) != null)
                {
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
                }*/
                //Dt_StockInfo stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
                //if (stockInfo == null)
@@ -63,7 +70,7 @@
                Dt_Warehouse warehouse = _warehouseRepository.QueryFirst(x => x.WarehouseCode == roadwayInfo.RoadwayNo);
                if (warehouse == null)
                {
                    return WebResponseContent.Instance.Error("未找到改仓库");
                    return WebResponseContent.Instance.Error("未找到该仓库");
                }
                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayInfo.RoadwayNo, warehouse.WarehouseId, "");//
                if (locationInfo == null)
@@ -90,12 +97,13 @@
                    Roadway = "1",
                    SourceAddress = "",
                    TargetAddress = locationInfo.LocationCode,
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = 1,
                    TaskType = TaskInboundTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskInStatusEnum.Line_InExecuting.ObjToInt(),
                    WarehouseId = warehouse.WarehouseId,
                    //PalletType = GetPalletType(warehouse, palletCode),//GetPalletType(warehouse, palletCode)
                    Creater = "WCS",
                    CreateDate = DateTime.Now
                    CreateDate = DateTime.Now,
                    Depth = locationInfo.Depth,
                };
                _unitOfWorkManage.BeginTran();
@@ -118,5 +126,151 @@
            }
        }
        /// <summary>
        /// åˆ›å»ºå…¥åº“任务
        /// </summary>
        /// <param name="inboundTask"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public ApiResponse<object> sendEnTask(InOutboundTaskReceived inboundTask)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            try
            {
                List<Dt_Task> AddtaskList = new List<Dt_Task>();
                List<Dt_LocationInfo> Adddt_Locations = new List<Dt_LocationInfo>();
                List<Dt_StockInfo> Adddtstockt = new List<Dt_StockInfo>();
                if (inboundTask.palletInfoList.Count > 0)
                {
                    List<Dt_Task> taskData = BaseDal.QueryData();
                    List<Dt_StockInfo> Stockdata = _stockRepository.QueryData();
                    /*Dt_StationManger dt_Station = _stationMangerService.QueryPlatform(inboundTask.NodeCode);
                    if (dt_Station == null) return MESresponse($"未找到站台信息,站台编号:{inboundTask.NodeCode}", false);*/
                    foreach (PalletInfo palletInfo in inboundTask.palletInfoList)
                    {
                        Dt_LocationInfo location = null;
                        if (palletInfo.locationCode == null || palletInfo.locationCode == "")
                        {
                            location = _basicService.LocationInfoService.GetLocationInfo();//获取到新库位
                        }
                        else
                        {
                            location = _locationInfoRepository.QueryFirst(x => x.LocationCode == palletInfo.locationCode);
                        }
                        if (location == null) return MESresponse($"未找到货位信息,条码:{palletInfo.palletCode}", false);
                        if (location.LocationStatus != (int)LocationStatusEnum.Free) return MESresponse($"托盘条码:{palletInfo.palletCode},查找到的货位:{location.LocationCode},不为空货位!", false);
                        Dt_StockInfo dt_ = Stockdata.Where(x => x.PalletCode == palletInfo.palletCode).FirstOrDefault();
                        if (dt_ == null)
                        {
                            //创建组盘信息
                            var dt_Stock = new Dt_StockInfo
                            {
                                PalletCode = palletInfo.palletCode,
                                PalletType = 1,
                                LocationCode = location.LocationCode,
                                StockStatus = (int)StockStatusEmun.组盘暂存,
                                Creater = "WMS",
                                CreateDate = DateTime.Now,
                                MESsubPalletCode = palletInfo.palletCode,
                            };
                            Adddtstockt.Add(dt_Stock);
                        }
                        else
                        {
                            if(dt_.StockStatus == (int)StockStatusEmun.已入库)
                            {
                                return MESresponse($"该库存条码已入库,不可重复入库,条码:{palletInfo.palletCode}", false);
                            }
                        }
                        string TaregtAddres = "";
                        if (inboundTask.NodeCode !="2011" && inboundTask.NodeCode != "2009")
                        {
                            int nextTaregt = int.Parse(inboundTask.NodeCode);
                            //确认目标站台(固定)
                             TaregtAddres = (nextTaregt + 1).ToString();
                        }
                        else
                        {
                            TaregtAddres = location.RoadwayNo == "SC01" ? "2021" : "2020";
                        }
                        location.LocationStatus = (int)LocationStatusEnum.InStockLock;
                        //生成移动任务
                        Dt_Task dt_Task = new()
                        {
                            PalletCode = palletInfo.palletCode,
                            TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                            Roadway = location.RoadwayNo,
                            TaskType = TaskInboundTypeEnum.Inbound.ObjToInt(),
                            TaskStatus = TaskInStatusEnum.Line_InExecuting.ObjToInt(),
                            SourceAddress = TaregtAddres,
                            TargetAddress = location.LocationCode,
                            CurrentAddress = TaregtAddres,
                            NextAddress = location.LocationCode,
                            Grade = 1,
                            Creater = "MES",
                            Depth = location.Depth,
                            CreateDate = DateTime.Now,
                            MEStaskId = inboundTask.TaskId,
                            MESbusinessId = inboundTask.BusinessId,
                            MESsubPalletCode = palletInfo.subPalletCode,
                            OutboundPlatform = inboundTask.NodeCode
                        };
                        Adddt_Locations.Add(location);
                        AddtaskList.Add(dt_Task);
                    }
                    if (Adddtstockt.Count > 0 && Adddt_Locations.Count > 0 && AddtaskList.Count > 0)
                    {
                        _unitOfWorkManage.BeginTran();
                        _stockRepository.AddData(Adddtstockt);
                        _locationInfoRepository.UpdateData(Adddt_Locations);
                        BaseDal.AddData(AddtaskList);
                        var respon = PushTasksToWCS(AddtaskList, "");
                        if (respon.Status)
                        {
                            _unitOfWorkManage.CommitTran();  //提交事务
                            return MESresponse("", true);
                        }
                        else
                        {
                            _unitOfWorkManage.RollbackTran();  //回滚事务
                            return MESresponse($"下发出库失败,原因:{respon.Message}!", false);
                        }
                    }
                    else
                    {
                        return MESresponse("任务生成失败!", false);
                    }
                }
                else
                {
                    return MESresponse("接收到MES托盘编码列表无数据!", false);
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();  //回滚事务
                return MESresponse($"下发出库失败,原因:{ex.Message}!", false);
                throw;
            }
        }
    }
}