wangxinhui
2025-10-17 ce40df5daffae0d17b4e9fa7cb6d677afaa4d66f
ÏîÄ¿´úÂë/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs
@@ -1,4 +1,6 @@
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using Autofac.Core;
using Microsoft.IdentityModel.Tokens;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using SqlSugar;
using System;
using System.Collections;
@@ -116,7 +118,12 @@
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.RfidCode == palletCode);
                if (stockInfo == null)
                {
                    return content.Error($"未找到组盘信息");
                }
                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == stockInfo.PalletCode);
                if (task != null)
                {
                    PushTasksToWCS(new List<Dt_Task> { task });
@@ -126,11 +133,6 @@
                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
                {
                    return content.Error($"该站点已有未执行的任务");
                }
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (stockInfo == null)
                {
                    return content.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.老厂退库.ObjToInt())
                {
@@ -148,7 +150,8 @@
                    CurrentAddress = stationCode,
                    Grade = 0,
                    NextAddress = "",
                    PalletCode = palletCode,
                    PalletCode = stockInfo.PalletCode,
                    RfidCode=stockInfo.RfidCode,
                    Roadway = rowWay,
                    SourceAddress = stationCode,
                    TargetAddress = "",
@@ -184,82 +187,106 @@
            }
            return content;
        }
        private readonly static object lockerYLBoxing = new object();
        /// <summary>
        /// åŽŸæ–™è¯·æ±‚ç»„ç›˜
        /// åŽŸæ–™è¯·æ±‚
        /// </summary>
        /// <param name="palletCode">RFID信息</param>
        /// <returns></returns>
        public WebResponseContent YLPurchaseBoxing(string palletCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (stockInfoOld != null && stockInfoOld.MaterielInvOrgId==MaterielInvOrgEnum.新厂.ObjToInt())
                lock (lockerYLBoxing)
                {
                    return content.OK($"新厂临时入库{stockInfoOld.PalletCode}");
                }
                else if (stockInfoOld != null && stockInfoOld.MaterielInvOrgId==MaterielInvOrgEnum.老厂.ObjToInt() && stockInfoOld.StockStatus == StockStatusEmun.老厂退库.ObjToInt())
                {
                    return content.OK($"老厂临时退库{stockInfoOld.PalletCode}");
                }
                else if (stockInfoOld != null)
                {
                    return content.Error($"条码{stockInfoOld.PalletCode}信息已存在");
                    Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.RfidCode == palletCode);
                    if (stockInfoOld != null && stockInfoOld.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                    {
                        return content.OK($"临时入库{stockInfoOld.RfidCode}");
                    }
                    else if (stockInfoOld != null && stockInfoOld.MaterielInvOrgId == MaterielInvOrgEnum.老厂.ObjToInt() && stockInfoOld.StockStatus == StockStatusEmun.老厂退库.ObjToInt())
                    {
                        return content.OK($"老厂退库{stockInfoOld.RfidCode}");
                    }
                    else if (stockInfoOld != null)
                    {
                        return content.Error("RFID信息已存在");
                    }
                    #region å¤„理采购绑定RFID逻辑
                    Dt_YLInboundCache? yLInboundCache = _inboundRepository.YLInboundCacheRepository.QueryData(x => x.InvOrg == MaterielInvOrgEnum.老厂.ToString()).FirstOrDefault();
                    if (yLInboundCache == null)
                    {
                        return content.Error("未找到原料缓存条码信息");
                    }
                    if (yLInboundCache.BindStatus == WhetherEnum.True.ObjToInt())
                    {
                        return content.Error($"原料缓存条码{yLInboundCache.BarCode}已绑定RFID{yLInboundCache.RfidCode}");
                    }
                    else
                    {
                        //获取采购信息
                        Dt_PurchaseBSTOrderDetail purchaseBSTOrderDetail = _purchaseBSTOrderDetailRepository.QueryFirst(x => x.Barcode == yLInboundCache.BarCode);
                        if (purchaseBSTOrderDetail == null)
                        {
                            return content.Error($"未找到条码{yLInboundCache.BarCode}采购信息");
                        }
                        if (purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus != InOrderStatusEnum.未开始.ObjToInt())
                        {
                            return content.Error($"采购{purchaseBSTOrderDetail.Barcode}信息已入库或入库中");
                        }
                        else
                        {
                            purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus = InOrderStatusEnum.入库中.ObjToInt();
                            purchaseBSTOrderDetail.RfidCode = palletCode;
                        }
                        //获取采购主单
                        Dt_PurchaseBSTOrder purchaseBSTOrder = _purchaseBSTOrderRepository.QueryFirst(x => x.Id == purchaseBSTOrderDetail.PurchaseBSTOrderId);
                        //获取物料
                        Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterialSourceId == purchaseBSTOrderDetail.MaterialId);
                        //生成库存组盘信息
                        Dt_StockInfo stockInfo = new Dt_StockInfo()
                        {
                            MaterielInvOrgId = materielInfo.MaterielInvOrgId,
                            PalletCode = purchaseBSTOrderDetail.Barcode,
                            RfidCode = palletCode,
                            LocationCode = "",
                            PalletType = 1,
                            WarehouseId = materielInfo.WarehouseId,
                            StockAttribute = materielInfo.MaterielSourceType,
                            StockStatus = StockStatusEmun.组盘暂存.ObjToInt(),
                            MaterielSpec = materielInfo.MaterielSpec,
                            Unit = materielInfo.MaterielUnit,
                            MaterielThickness = purchaseBSTOrderDetail.MaterialThick,
                            MaterielWide = purchaseBSTOrderDetail.MaterialWide,
                            MaterielWeight = purchaseBSTOrderDetail.DeliveryQty,
                            MaterielCode = materielInfo.MaterielCode,
                            MaterielName = materielInfo.MaterielName,
                            StockLength = purchaseBSTOrderDetail.ProcurementLength,
                            MaterielId = purchaseBSTOrderDetail.MaterialId
                        };
                        if (purchaseBSTOrderDetail.MaterialWide > 1200)
                        {
                            stockInfo.PalletType = 2;
                        }
                        yLInboundCache.RfidCode = palletCode;
                        yLInboundCache.BindStatus = WhetherEnum.True.ObjToInt();
                        _unitOfWorkManage.BeginTran();
                        //新增组盘信息
                        _stockRepository.StockInfoRepository.AddData(stockInfo);
                        if (purchaseBSTOrder.PurchaseOrderStatus == InOrderStatusEnum.未开始.ObjToInt())
                        {
                            purchaseBSTOrder.PurchaseOrderStatus = InOrderStatusEnum.入库中.ObjToInt();
                            _purchaseBSTOrderRepository.UpdateData(purchaseBSTOrder);
                        }
                        _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
                        _purchaseBSTOrderDetailRepository.UpdateData(purchaseBSTOrderDetail);
                        _unitOfWorkManage.CommitTran();
                    }
                    #endregion
                    content.OK("绑定成功");
                }
                
                //获取采购信息
                Dt_PurchaseBSTOrderDetail purchaseBSTOrderDetail = _purchaseBSTOrderDetailRepository.QueryFirst(x=>x.Barcode== palletCode);
                if (purchaseBSTOrderDetail == null)
                {
                    return content.Error($"未找到条码{palletCode}采购信息");
                }
                if (purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus!=InOrderStatusEnum.未开始.ObjToInt())
                {
                    return content.Error($"采购{purchaseBSTOrderDetail.Barcode}信息已入库或入库中");
                }
                else
                {
                    purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus = InOrderStatusEnum.入库中.ObjToInt();
                }
                //获取采购主单
                Dt_PurchaseBSTOrder purchaseBSTOrder = _purchaseBSTOrderRepository.QueryFirst(x=>x.Id==purchaseBSTOrderDetail.PurchaseBSTOrderId);
                //获取物料
                Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterialSourceId == purchaseBSTOrderDetail.MaterialId);
                //生成库存组盘信息
                Dt_StockInfo stockInfo = new Dt_StockInfo()
                {
                    MaterielInvOrgId = materielInfo.MaterielInvOrgId,
                    PalletCode = purchaseBSTOrderDetail.Barcode,
                    LocationCode = "",
                    PalletType = 1,
                    WarehouseId = materielInfo.WarehouseId,
                    StockAttribute = materielInfo.MaterielSourceType,
                    StockStatus = StockStatusEmun.组盘暂存.ObjToInt(),
                    MaterielSpec = materielInfo.MaterielSpec,
                    Unit = materielInfo.MaterielUnit,
                    MaterielThickness = purchaseBSTOrderDetail.MaterialThick,
                    MaterielWide = purchaseBSTOrderDetail.MaterialWide,
                    MaterielWeight = purchaseBSTOrderDetail.DeliveryQty,
                    MaterielCode = materielInfo.MaterielCode,
                    MaterielName = materielInfo.MaterielName,
                    StockLength= purchaseBSTOrderDetail.ProcurementLength,
                    MaterielId= purchaseBSTOrderDetail.MaterialId
                };
                if (purchaseBSTOrderDetail.MaterialWide > 1200)
                {
                    stockInfo.PalletType = 2;
                }
                _unitOfWorkManage.BeginTran();
                //新增组盘信息
                _stockRepository.StockInfoRepository.AddData(stockInfo);
                if (purchaseBSTOrder.PurchaseOrderStatus==InOrderStatusEnum.未开始.ObjToInt())
                {
                    purchaseBSTOrder.PurchaseOrderStatus = InOrderStatusEnum.入库中.ObjToInt();
                    _purchaseBSTOrderRepository.UpdateData(purchaseBSTOrder);
                }
                _purchaseBSTOrderDetailRepository.UpdateData(purchaseBSTOrderDetail);
                _unitOfWorkManage.CommitTran();
                content.OK("请求成功");
            }
            catch (Exception ex)
            {
@@ -267,8 +294,74 @@
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// åŽŸæ–™é‡‡è´­ç»‘å®šRFID
        /// </summary>
        /// <param name="palletCode">纸卷条码</param>
        /// <param name="rfidCode">纸卷RIFD</param>
        /// <returns></returns>
        public WebResponseContent PurchaseBoxing(string palletCode)
        {
            WebResponseContent content=new WebResponseContent();
            try
            {
                if (string.IsNullOrEmpty(palletCode))
                {
                    return content.Error("条码不能为空");
                }
                Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (stockInfoOld != null)
                {
                    return content.Error("条码信息库存中已存在");
                }
                //获取采购信息
                Dt_PurchaseBSTOrderDetail purchaseBSTOrderDetail = _purchaseBSTOrderDetailRepository.QueryFirst(x => x.Barcode == palletCode);
                if (purchaseBSTOrderDetail == null)
                {
                    return content.Error($"未找到条码{palletCode}采购信息");
                }
                if (purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus != InOrderStatusEnum.未开始.ObjToInt())
                {
                    return content.Error($"条码{palletCode}采购信息已入库或入库中");
                }
                Dt_YLInboundCache? yLInboundCache = _inboundRepository.YLInboundCacheRepository.QueryData(x=>x.InvOrg==MaterielInvOrgEnum.老厂.ToString()).FirstOrDefault();
                if (yLInboundCache == null)
                {
                    return content.Error("未找到原料条码缓存信息");
                }
                int Id = yLInboundCache.Id;
                if (yLInboundCache.BarCode==palletCode)
                {
                    return content.Error($"条码{palletCode}已扫码");
                }
                else if (yLInboundCache.BarCode != palletCode && yLInboundCache.BindStatus==WhetherEnum.True.ObjToInt())
                {
                    yLInboundCache = _mapper.Map<Dt_YLInboundCache>(purchaseBSTOrderDetail);
                    yLInboundCache.Id = Id;
                    _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
                    return content.OK("成功", yLInboundCache);
                }
                else
                {
                    return content.Error($"上卷条码{yLInboundCache.BarCode}还未进行绑定");
                }
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
            
        }
        /// <summary>
        /// åŽŸæ–™åˆ†é…å··é“
        /// </summary>
        /// <param name="palletCode">条码号</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public string AssignYLRoadwayNo(string palletCode)
        {
            try
@@ -292,13 +385,8 @@
                    //限制直径
                    if (stockInfo.MaterielThickness >= 300 && stockInfo.MaterielThickness <= 1300 && stockInfo.MaterielWide >= 700 && stockInfo.MaterielWide <= 2700)
                    {
                        bool LayerLimit = false;
                        if (stockInfo.MaterielThickness >= 800)
                        {
                            LayerLimit = true;
                        }
                        //获取分配
                        List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("YLDual")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
                        List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("YLDual") && (stockInfo.PalletType == LocationTypeEnum.MediumPallet.ObjToInt() ? x.LocationType == LocationTypeEnum.MediumPallet.ObjToInt(): x.LocationType == LocationTypeEnum.SmallPallet.ObjToInt())).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
                        roadwayNo = HandleRoadway(locationCounts, warehouse);
                    }
@@ -365,7 +453,7 @@
                    {
                        return content.Error($"未找到对应的终点货位信息");
                    }
                    Dt_AGVStationInfo agvstation = _agvStationInfoRepository.QueryFirst(x => x.AGVStationCode == task.SourceAddress && ( x.StationArea == AGVStationAreaEnum.AreaA.ObjToInt() || x.StationArea == AGVStationAreaEnum.AreaC.ObjToInt()));
                    Dt_AGVStationInfo agvstation = _agvStationInfoRepository.QueryFirst(x => x.AGVStationCode == task.SourceAddress && ( x.StationArea == nameof(AGVStationAreaEnum.一楼月台码头) || x.StationArea == nameof(AGVStationAreaEnum.一楼无纺织布) || x.StationArea == nameof(AGVStationAreaEnum.一楼无纺淋膜) || x.StationArea == nameof(AGVStationAreaEnum.一楼无纺淋膜)));
                    if (agvstation != null)
                    {
                        agvstation.IsOccupied = WhetherEnum.False.ObjToInt();
@@ -446,7 +534,7 @@
                        {
                            Barcode = stockInfo.PalletCode,
                            BarcodeQty = Qty,
                            Rfid = stockInfo.PalletCode,
                            Rfid = stockInfo.RfidCode,
                            RfidUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                        };
                        BSTResponse bSTResponse = _invokeERPService.BSTPurchaseUp(bSTPurchaseUpModel).DeserializeObject<BSTResponse>();
@@ -520,8 +608,13 @@
                {
                    return WebResponseContent.Instance.OK(data: task.TargetAddress);
                }
                Dt_StockInfo? stockInfo = null;
                if (roadwayNo.Contains("YL"))
                {
                    stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x=>x.PalletCode==task.PalletCode);
                }
                //分配货位
                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId);
                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId, stockInfo);
                if (locationInfo == null)
                {
                    return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位");
@@ -637,7 +730,7 @@
        /// è¾…æ–™/成品临时入库
        /// </summary>
        /// <returns></returns>
        public WebResponseContent InboundFLOrCPTask(string barCode, string startPoint,string matCode,int matCount)
        public WebResponseContent InboundFLOrCPTask(string barCode, string startPoint,string matCode,int matCount, int oneCount)
        {
            lock (_lockerFLorCP)
            {
@@ -682,15 +775,21 @@
                    //获取成品库
                    WarehouseEnum warehouseEnum = materielInfo.MaterielSourceType == MaterielTypeEnum.成品.ObjToInt() ? WarehouseEnum.LLDCP : WarehouseEnum.LLDFL;
                    Dt_ProStockInfoDetail proStockInfoDetail = new Dt_ProStockInfoDetail()
                    List<Dt_ProStockInfoDetail> proStockInfoDetails = new List<Dt_ProStockInfoDetail>();
                    for (int i = 0; i < matCount; i++)
                    {
                        ProductCode = materielInfo.MaterielCode,
                        ProductName= materielInfo.MaterielName,
                        ProductSpec=materielInfo.MaterielSpec,
                        ProductUnit=materielInfo.MaterielUnit,
                        StockQty = matCount,
                        ProStockDetailStatus = StockStatusEmun.手动组盘入库确认.ObjToInt()
                    };
                        Dt_ProStockInfoDetail proStockInfoDetail = new Dt_ProStockInfoDetail()
                        {
                            ProductCode = materielInfo.MaterielCode,
                            ProductName = materielInfo.MaterielName,
                            ProductSpec = materielInfo.MaterielSpec,
                            ProductUnit = materielInfo.MaterielUnit,
                            StockQty = oneCount,
                            ProStockDetailStatus = StockStatusEmun.手动组盘入库确认.ObjToInt()
                        };
                        proStockInfoDetails.Add(proStockInfoDetail);
                    }
                    Dt_ProStockInfo proStockInfo = new Dt_ProStockInfo()
                    {
                        PalletCode = barCode,
@@ -699,7 +798,7 @@
                        LocationCode = "",
                        WarehouseId = warehouseEnum.ObjToInt(),
                        StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt(),
                        proStockInfoDetails = new List<Dt_ProStockInfoDetail> { proStockInfoDetail }
                        proStockInfoDetails = proStockInfoDetails
                    };
                    Dt_Task newTask = new Dt_Task()
@@ -755,6 +854,10 @@
                {
                    return content.Error("未找到物料信息");
                }
                if (materielInfo.MaterielSourceType != MaterielTypeEnum.原材料.ObjToInt())
                {
                    return content.Error($"物料信息不符合{MaterielTypeEnum.原材料}");
                }
                Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == barcode);
                if (stockInfoOld != null)
                {
@@ -796,7 +899,7 @@
                    TaskType = TaskTypeEnum.PrintYLBackInbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = warehouseId,
                    PalletType = 1,
                    PalletType = stockInfo.PalletType,
                    TaskLength= wide
                };
                _unitOfWorkManage.BeginTran();
@@ -882,7 +985,7 @@
                    TaskType = TaskTypeEnum.PrintYLInbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = warehouseId,
                    PalletType = 1,
                    PalletType = stockInfo.PalletType,
                    TaskLength = wide
                };
                _unitOfWorkManage.BeginTran();