wangxinhui
14 小时以前 39d468b76e60c05ffcdf749f7ed1d3c443d542f8
ÏîÄ¿´úÂë/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs
@@ -43,54 +43,105 @@
        /// <param name="stationCode"></param>
        /// <param name="palletCode"></param>
        /// <returns></returns>
        public WebResponseContent DeviceRequestInboundTaskSimple(string stationCode)
        public WebResponseContent DeviceRequestInboundTaskSimple(string stationCode, string startPoint = "")
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == stationCode);
                if (task != null)
                {
                    PushTasksToWCS(new List<Dt_Task> { task });
                    return WebResponseContent.Instance.OK($"该托盘已生成任务", _mapper.Map<WMSTaskDTO>(task));
                    return content.OK($"该托盘已生成任务", _mapper.Map<WMSTaskDTO>(task));
                }
                Dt_ProStockInfo stockInfo = BaseDal.Db.Queryable<Dt_ProStockInfo>().Where(x => x.PalletCode == stationCode).Includes(x => x.proStockInfoDetails).First(); ;
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
                    return content.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库");
                    return content.Error($"该托盘状态不正确,不可申请入库");
                }
                Dt_Task newTask = new Dt_Task()
                {
                    CurrentAddress = stationCode,
                    Grade = 0,
                    NextAddress = "",
                    PalletCode = stationCode,
                    Roadway = "",
                    SourceAddress = stationCode,
                    TargetAddress = "",
                    TaskType = TaskTypeEnum.InProduct.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType,
                };
                stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                stockInfo.proStockInfoDetails.ForEach(x =>
                {
                    x.ProStockDetailStatus = StockStatusEmun.入库确认.ObjToInt();
                });
                _unitOfWorkManage.BeginTran();
                int taskId = BaseDal.AddData(newTask);
                newTask.TaskId = taskId;
                _stockRepository.ProStockInfoRepository.UpdateData(stockInfo);
                _stockRepository.ProStockInfoDetailRepository.UpdateData(stockInfo.proStockInfoDetails);
                _unitOfWorkManage.CommitTran();
                WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
                if (startPoint.IsNullOrEmpty())
                {
                    Dt_Task newTask = new Dt_Task()
                    {
                        CurrentAddress = stationCode,
                        Grade = 0,
                        NextAddress = "",
                        PalletCode = stationCode,
                        Roadway = "",
                        SourceAddress = stationCode,
                        TargetAddress = "",
                        TaskType = TaskTypeEnum.InProduct.ObjToInt(),
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
                        WarehouseId = stockInfo.WarehouseId,
                        PalletType = stockInfo.PalletType,
                    };
                    _unitOfWorkManage.BeginTran();
                    int taskId = BaseDal.AddData(newTask);
                    newTask.TaskId = taskId;
                    _stockRepository.ProStockInfoRepository.UpdateData(stockInfo);
                    _stockRepository.ProStockInfoDetailRepository.UpdateData(stockInfo.proStockInfoDetails);
                    _unitOfWorkManage.CommitTran();
                    WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
                return WebResponseContent.Instance.OK(data: wMSTaskDTO);
                    return content.OK(data: wMSTaskDTO);
                }
                else
                {
                    Dt_AGVStationInfo agvstation = _basicRepository.AGVStationInfoRepository.QueryFirst(x => x.AGVStationCode == startPoint);
                    if (agvstation == null)
                    {
                        return content.Error($"起点错误{startPoint}");
                    }
                    if (agvstation.StationArea != StationAreaEnum.二楼成品库缓存区.ToString())
                    {
                        return content.Error($"起点站点区域错误{agvstation.StationArea}");
                    }
                    //判断当前点位是否重复
                    Dt_Task taskOldPoint = BaseDal.QueryFirst(x => x.SourceAddress == startPoint && (x.TaskStatus == TaskStatusEnum.New.ObjToInt() || x.TaskStatus == TaskStatusEnum.AGV_Executing.ObjToInt()));
                    if (taskOldPoint != null)
                    {
                        return content.Error($"站点{startPoint}已存在任务");
                    }
                    //分配巷道
                    string roadWay = AssignCPRoadwayNo();
                    Dt_ProStockInfoDetail? proStockInfoDetail = stockInfo.proStockInfoDetails.FirstOrDefault();
                    //生成任务
                    Dt_Task newTask = new Dt_Task()
                    {
                        CurrentAddress = startPoint,
                        Grade = 0,
                        NextAddress = "",
                        PalletCode = stockInfo.PalletCode,
                        Roadway = roadWay,
                        SourceAddress = startPoint,
                        TargetAddress = "",
                        TaskType = TaskTypeEnum.Inbound2ndFloor.ObjToInt(),
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
                        WarehouseId = stockInfo.WarehouseId,
                        PalletType = stockInfo.PalletType,
                        MaterielCode = proStockInfoDetail.ProductCode,
                        OrderNo = stockInfo.ProInOrderNo,
                        Quantity = stockInfo.proStockInfoDetails.Sum(x=>x.StockQty),
                    };
                    _unitOfWorkManage.BeginTran();
                    int taskId = BaseDal.AddData(newTask);
                    newTask.TaskId = taskId;
                    _stockRepository.ProStockInfoRepository.UpdateData(stockInfo);
                    _stockRepository.ProStockInfoDetailRepository.UpdateData(stockInfo.proStockInfoDetails);
                    _unitOfWorkManage.CommitTran();
                    //推送任务
                    PushTasksToWCS(new List<Dt_Task> { newTask }, "AGV");
                    return content.OK("创建入库成功");
                }
            }
            catch (Exception ex)
            {
@@ -888,7 +939,8 @@
                    //限制
                    if (stockInfo.CheckThickness >= 800 && stockInfo.CheckThickness <= 1500 && stockInfo.MaterielWide >= 700 && stockInfo.MaterielWide <= 2500)
                    {
                        bool LayerLimit = stockInfo.CheckThickness > 1300;
                        bool LayerLimit1 = stockInfo.CheckThickness >= 1200;
                        bool LayerLimit2 = stockInfo.CheckThickness > 1300;
                        bool RoadwayLimit = stockInfo.MaterielWide > 2200;
                        bool RoadwayType = stockInfo.PalletType == LocationTypeEnum.MediumPallet.ObjToInt();
                        var query = Db.Queryable<Dt_LocationInfo>()
@@ -899,7 +951,11 @@
                            .Select(x => new { x.RoadwayNo, x.Columns });
                        // æ ¹æ®æ¡ä»¶è¿‡æ»¤
                        if (LayerLimit)
                        if (LayerLimit1)
                        {
                            query = query.Where(x => x.RoadwayNo != "SC03_YLDual");
                        }
                        if (LayerLimit2)
                        {
                            query = query.Where(x => x.Columns >= 56 && !x.RoadwayNo.Contains("YLDual"));
                        }
@@ -975,7 +1031,7 @@
                {
                    item.Count -= count.Count;
                }
                if (item.Count >= 50 && count?.Count<=2)
                if (item.Count >= 50 && count?.Count<=1)
                {
                    return item.RoadwayNo;
                }
@@ -1225,12 +1281,17 @@
                    return WebResponseContent.Instance.OK(data: task.TargetAddress);
                }
                Dt_StockInfo? stockInfo = null;
                Dt_ProStockInfo? proStockInfo = null;
                if (roadwayNo.Contains("YL"))
                {
                    stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x=>x.PalletCode==task.PalletCode);
                }
                else
                {
                    proStockInfo = Db.Queryable<Dt_ProStockInfo>().Where(x => x.PalletCode == task.PalletCode).Includes(x=>x.proStockInfoDetails).First();
                }
                //分配货位
                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId, stockInfo);
                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId, stockInfo, proStockInfo);
                if (locationInfo == null)
                {
                    return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位");
@@ -1884,6 +1945,16 @@
                {
                    return content.Error("传入信息为空");
                }
                // åªè¿”回重复的 BarCode åˆ—表
                var repeatBarCodeList = proInDTOs
                    .GroupBy(x => x.BarCode)
                    .Where(g => g.Count() > 1)
                    .Select(g => g.Key)
                    .ToList();
                if (repeatBarCodeList.Count>0)
                {
                    return content.Error($"传入{repeatBarCodeList.FirstOrDefault()}箱码数据重复,请检查传入数据");
                }
                //获取所有成品,半成品信息
                List<Dt_MESProInOrderInfo> proInOrderInfosOld = _inboundRepository.MESProInOrderInfoRepository.QueryData();
                //获取所有物料信息
@@ -2158,16 +2229,28 @@
                throw new Exception(ex.Message);
            }
        }
        public WebResponseContent BoxingInBound(string stationCode,List<string> barCodes)
        /// <summary>
        /// æˆå“ç»„盘
        /// </summary>
        /// <returns></returns>
        public WebResponseContent BoxingInBound(string stationCode, int heightNum, List<string> barCodes, int type = 0)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (stationCode.IsNullOrEmpty())
                {
                    return content.Error($"托盘条码不能为空");
                }
                if (barCodes==null || barCodes.Count<=0)
                {
                    return content.Error($"箱码不能为空");
                }
                //获取成品库存
                Dt_ProStockInfo proStockInfoOld = _stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == stationCode);
                if (proStockInfoOld != null)
                {
                    return content.Error($"托盘{stationCode}已存在");
                    return content.Error($"托盘条码{stationCode}已存在");
                }
                //获取条码信息
                List<Dt_MESProInOrderInfo> proInOrderInfos = _inboundRepository.MESProInOrderInfoRepository.QueryData(x=> barCodes.Contains(x.BarCode));
@@ -2188,7 +2271,7 @@
                    };
                    proStockInfoDetails.Add(proStockInfoDetail);
                }
                Dt_ProStockInfo proStockInfo = new Dt_ProStockInfo()
                {
                    PalletCode = stationCode,
@@ -2198,13 +2281,25 @@
                    LocationCode = "",
                    WarehouseId = materielInfo.WarehouseId,
                    StockStatus = StockStatusEmun.组盘暂存.ObjToInt(),
                    ProHeight = heightNum,
                    proStockInfoDetails = proStockInfoDetails
                };
                _unitOfWorkManage.BeginTran();
                BaseDal.Db.InsertNav(proStockInfo).Include(x => x.proStockInfoDetails).ExecuteCommand();
                if (type != 0)
                {
                    proInOrderInfos.ForEach(x =>
                    {
                        x.MESProInStatus = InOrderStatusEnum.入库完成.ObjToInt();
                    });
                    _inboundRepository.MESProInOrderInfoRepository.UpdateData(proInOrderInfos);
                }
                _unitOfWorkManage.CommitTran();
                content.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
@@ -2325,5 +2420,29 @@
            }
            return content;
        }
        /// <summary>
        /// äºŒæ¥¼æˆå“PDA扫码校验
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public WebResponseContent CodeAnalysis(string barcode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (barcode.IsNullOrEmpty())
                    return content.Error("传入箱码不能为空");
                //获取条码状态
                Dt_MESProInOrderInfo proInOrderInfo = Db.Queryable<Dt_MESProInOrderInfo>().Where(x => x.BarCode == barcode && x.MESProInStatus == (int)InOrderStatusEnum.未开始).OrderByDescending(x => x.CreateDate).First();
                if (proInOrderInfo==null)
                    return content.Error($"箱码{barcode}状态不可入库,请检查箱码数据");
                return content.OK("成功", new { proInOrderInfo.BarCode, proInOrderInfo.ProductOrderNo, proInOrderInfo.MaterialCode, proInOrderInfo.ProQuantity });
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
    }
}