wangxinhui
13 小时以前 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)
            {
@@ -365,9 +416,14 @@
                    throw new Exception($"未找到条码{stockInfoOld.PalletCode}一期ERP库存不存在");
                }
                BSTStockInfoDTO bSTStockInfoDTO = bSTResponse.Data ?? throw new Exception($"一期ERP未返回{stockInfoOld.PalletCode}的库存信息");
                if (stockInfoOld.StockLength <= 0 || bSTStockInfoDTO.StockMeter<=0)
                {
                    throw new Exception($"{stockInfoOld.RfidCode}绑定条码{stockInfoOld.PalletCode}库存为0");
                }
                stockInfoOld.IsPick = WhetherEnum.False.ObjToInt();
                decimal stockLength = bSTStockInfoDTO.StockMeter;
                if (weight != bSTStockInfoDTO.Qty && weight < stockInfoOld.InitialWeight)
                decimal errWeight = Math.Abs(weight - bSTStockInfoDTO.Qty);
                if (weight != bSTStockInfoDTO.Qty && weight < stockInfoOld.InitialWeight && errWeight <= AppSettings.Get("ErrWeight").ObjToInt())
                {
                    Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterialSourceId == stockInfoOld.MaterielId);
                    int gramWeight = (int)(materielInfo.MaterielWeight * 1000);
@@ -376,7 +432,7 @@
                        Paper_code = stockInfoOld.PalletCode,
                        Estimate_weight = bSTStockInfoDTO.Qty,
                        Actual_weight = weight,
                        Error_weight = Math.Abs(weight - bSTStockInfoDTO.Qty),
                        Error_weight = errWeight,
                        Weigh_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        Operator = "LiKu",
                        Width = bSTStockInfoDTO.W,
@@ -397,6 +453,11 @@
                stockInfoOld.StockLength = stockLength;
                stockInfoOld.StockOutLength = 0;
                stockInfoOld.WarehouseId = WarehouseEnum.LLDYL.ObjToInt();
                List<Dt_OutLineView> outLineViewsDel = _outboundRepository.OutLineViewRepository.QueryData(x=>x.PalletCode==stockInfoOld.PalletCode);
                if (outLineViewsDel.Count>0)
                {
                    _outboundRepository.OutLineViewRepository.DeleteData(outLineViewsDel);
                }
                content.OK("成功",data:stockInfoOld);
            }
            catch (Exception ex)
@@ -878,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>()
@@ -889,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"));
                        }
@@ -964,6 +1030,10 @@
                if (count != null)
                {
                    item.Count -= count.Count;
                }
                if (item.Count >= 50 && count?.Count<=1)
                {
                    return item.RoadwayNo;
                }
            }
            return locationCounts.Where(x => x.Count > 0).OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
@@ -1059,7 +1129,7 @@
                            }
                            proInUpModel.PB_INV_PRODUCT_IN= pRODUCT_INItems;
                            string request = _invokeERPService.ERPProInUp(proInUpModel) ?? throw new Exception("成品入库接口请求失败");
                            if (!request.Contains("Success"))
                            if (!request.Contains("success"))
                            {
                                throw new Exception($"成品入库失败");
                            }
@@ -1211,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($"货位分配失败,未找到可分配货位");
@@ -1870,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();
                //获取所有物料信息
@@ -1946,7 +2031,7 @@
                    string request = _invokeERPService.ERPSemiProInUp(
                            new ERPProInUpModel()
                            {
                                PB_INV_PRODUCT_IN= pRODUCT_INItems
                                PB_INV_PRODUCT_IN = pRODUCT_INItems
                            }) ?? throw new Exception("半成品入库接口请求失败");
                    //生成半成品入库
                    List<Dt_MESProInOrderInfo> semiProInOrderInfos = mESProInOrderInfos.Where(x => x.MESProInStatus == InOrderStatusEnum.未开始.ObjToInt() && x.WarehouseId==WarehouseEnum.LLDYL.ObjToInt()).ToList();
@@ -1998,7 +2083,6 @@
                {
                    return content.Error("传入信息为空");
                }
                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData();
                List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>();
                List<Dt_Task> tasks = new List<Dt_Task>();
@@ -2059,7 +2143,7 @@
                        NextAddress = "",
                        PalletCode = item.BarCode,
                        Roadway = "",
                        SourceAddress = CheckPointCode.AGVStationCode,
                        SourceAddress = item.PointCode.StartsWith("YS") ? CheckPointCode.AGVStationCode : CheckPointCode.MESPointCode,
                        TargetAddress = "",
                        TaskType = 0,
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
@@ -2075,10 +2159,11 @@
                        nameof(StationAreaEnum.一楼印刷) => TaskTypeEnum.PrintYLInbound,
                        nameof(StationAreaEnum.一楼分切) => TaskTypeEnum.PartOffInbound,
                        nameof(StationAreaEnum.一楼纸张淋膜) => TaskTypeEnum.PaperFilmInbound,
                        nameof(StationAreaEnum.一楼无纺淋膜) => TaskTypeEnum.WFBYLInbound,
                        nameof(StationAreaEnum.一楼无纺织布) => TaskTypeEnum.WFBYLInbound,
                        nameof(StationAreaEnum.一楼无纺淋膜) => TaskTypeEnum.WFBLMYLInbound,
                        _ => throw new Exception("未找到对应任务")
                    };
                    if (taskTypeEnum == TaskTypeEnum.WFBYLInbound)
                    if (taskTypeEnum == TaskTypeEnum.WFBYLInbound || taskTypeEnum == TaskTypeEnum.WFBLMYLInbound)
                    {
                        Dt_AGVStationInfo? stationInfo = AssignWFBStation(_AGVStationInfos?.Select(x => x.AGVStationCode).ToList()) ?? throw new Exception("未找到可用无纺布暂存架");
                        newTask.NextAddress = stationInfo.AGVStationCode;
@@ -2144,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));
@@ -2174,7 +2271,7 @@
                    };
                    proStockInfoDetails.Add(proStockInfoDetail);
                }
                Dt_ProStockInfo proStockInfo = new Dt_ProStockInfo()
                {
                    PalletCode = stationCode,
@@ -2184,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;
@@ -2311,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;
        }
    }
}