From 733c975cd8647f6d006736f1863bad731e32e6fb Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期日, 26 十月 2025 17:15:52 +0800
Subject: [PATCH] 上传最新代码,ERP接口,MES接口优化,WMS业务优化等

---
 项目代码/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs |  861 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 749 insertions(+), 112 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
index 1f7d0db..5c52f40 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs"
@@ -1,4 +1,7 @@
-锘縰sing OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+锘縰sing Autofac.Core;
+using Microsoft.IdentityModel.Tokens;
+using Newtonsoft.Json;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
 using SqlSugar;
 using System;
 using System.Collections;
@@ -19,8 +22,12 @@
 using WIDESEA_Core.Helper;
 using WIDESEA_DTO;
 using WIDESEA_DTO.Basic;
+using WIDESEA_DTO.ERP;
+using WIDESEA_DTO.MES;
 using WIDESEA_DTO.Task;
+using WIDESEA_External.Model;
 using WIDESEA_Model.Models;
+using WIDESEA_TaskInfoRepository;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -53,7 +60,7 @@
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�");
                 }
-                if (stockInfo.StockStatus != StockStatusEmun.閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt())
+                if (stockInfo.StockStatus != StockStatusEmun.MES浣欐枡閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt())
                 {
                     return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱");
                 }
@@ -81,22 +88,6 @@
                 if (stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt())
                 {
                     stockInfo.StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt();
-                }
-                else if (stockInfo.StockStatus == StockStatusEmun.MES閫�搴�.ObjToInt())
-                {
-                    newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt();
-                }
-                else if (stockInfo.StockStatus == StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt())
-                {
-                    //todo 灏忔墭鐩樻殏鏃舵湭鍚敤
-                    if (stockInfo.PalletType == PalletTypeEnum.MediumPallet.ObjToInt())
-                    {
-                        newTask.TaskType = TaskTypeEnum.MesPalletLargeReturn.ObjToInt();
-                    }
-                    else
-                    {
-                        newTask.TaskType = TaskTypeEnum.MesPalletSmallReturn.ObjToInt();
-                    }
                 }
                 else
                 {
@@ -131,7 +122,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 });
@@ -142,39 +138,43 @@
                 {
                     return content.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
                 }
-                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
-                if (stockInfo == null)
-                {
-                    return content.Error($"鏈壘鍒扮粍鐩樹俊鎭�");
-                }
-                if (stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt())
+                if (stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鑰佸巶閫�搴�.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.鍗氭�濋�氱粍鐩樻殏瀛�.ObjToInt())
                 {
                     return content.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱");
                 }
+                //鍒嗛厤宸烽亾
                 string rowWay = AssignYLRoadwayNo(stockInfo.PalletCode);
                 if (string.IsNullOrEmpty(rowWay))
                 {
                     return content.Error($"鏈壘鍒板彲鍒嗛厤宸烽亾");
                 }
+                //鐢熸垚浠诲姟
                 Dt_Task newTask = new Dt_Task()
                 {
                     CurrentAddress = stationCode,
                     Grade = 0,
                     NextAddress = "",
-                    PalletCode = palletCode,
+                    PalletCode = stockInfo.PalletCode,
+                    RfidCode=stockInfo.RfidCode,
                     Roadway = rowWay,
                     SourceAddress = stationCode,
                     TargetAddress = "",
-                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
+                    TaskType = stationCode=="307" ? TaskTypeEnum.PaperOldYLBackInbound.ObjToInt() : TaskTypeEnum.Inbound.ObjToInt(),
                     TaskStatus = TaskStatusEnum.New.ObjToInt(),
                     WarehouseId = stockInfo.WarehouseId,
                     PalletType = stockInfo.PalletType,
+                    TaskLength = (int)stockInfo.MaterielWide
                 };
-
+                //鏇存柊鐘舵��
                 if (stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt())
                 {
                     stockInfo.StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt();
                 }
+                else
+                {
+                    stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+                }
+                //鏁版嵁鏇存柊
                 _unitOfWorkManage.BeginTran();
                 int taskId = BaseDal.AddData(newTask);
                 newTask.TaskId = taskId;
@@ -191,6 +191,311 @@
             }
             return content;
         }
+        private readonly static object lockerYLBoxing = new object();
+        /// <summary>
+        /// 鍘熸枡璇锋眰
+        /// </summary>
+        /// <param name="palletCode">RFID淇℃伅</param>
+        /// <returns></returns>
+        public WebResponseContent YLPurchaseBoxing(string palletCode, decimal weight = 0, decimal thickness = 0, decimal wide = 0)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                lock (lockerYLBoxing)
+                {
+                    Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.RfidCode == palletCode);
+                    if (stockInfoOld != null && stockInfoOld.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt())
+                    {
+                        UpdateStock(stockInfoOld, weight, thickness, wide);
+                        return content.OK($"涓存椂鍏ュ簱{stockInfoOld.RfidCode}");
+                    }
+                    else if (stockInfoOld != null && stockInfoOld.MaterielInvOrgId == MaterielInvOrgEnum.鑰佸巶.ObjToInt() && stockInfoOld.StockStatus == StockStatusEmun.鑰佸巶閫�搴�.ObjToInt())
+                    {
+                        UpdateStock(stockInfoOld, weight, thickness, wide);
+                        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}宸茬粦瀹歊FID{yLInboundCache.RfidCode}");
+                    }
+                    else
+                    {
+                        Dt_StockInfo ExistStockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == yLInboundCache.BarCode);
+                        if (ExistStockInfo != null && ExistStockInfo.MaterielInvOrgId == MaterielInvOrgEnum.鑰佸巶.ObjToInt() && ExistStockInfo.StockStatus == StockStatusEmun.鍗氭�濋�氱粍鐩樻殏瀛�.ObjToInt())
+                        {
+                            yLInboundCache.RfidCode = palletCode;
+                            yLInboundCache.BindStatus = WhetherEnum.True.ObjToInt();
+                            ExistStockInfo.RfidCode = palletCode;
+                            _unitOfWorkManage.BeginTran();
+                            //鏇存柊缁勭洏淇℃伅
+                            UpdateStock(ExistStockInfo, weight, thickness, wide);
+                            _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
+                            _unitOfWorkManage.CommitTran();
+                            return content.OK($"鍗氭�濋�氬簱瀛樿浆瀛榹ExistStockInfo.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,
+                                CheckWeight=weight,
+                                CheckThickness=thickness,
+                                CheckWide=wide,
+                                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("缁戝畾鎴愬姛");
+                }
+                
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        public void UpdateStock(Dt_StockInfo stockInfo, decimal weight = 0, decimal thickness = 0, decimal wide = 0)
+        {
+            stockInfo.CheckWeight = weight;
+            stockInfo.CheckThickness = thickness;
+            stockInfo.CheckWide = wide;
+            _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+        }
+        /// <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)
+                {
+                    BSTResponse<BSTStockInfoDTO> bSTResponse = _invokeERPService.BSTStockAsync(palletCode).DeserializeObject<BSTResponse<BSTStockInfoDTO>>();
+                    if (bSTResponse.Code == 500)
+                    {
+                        return content.Error($"鏈壘鍒版潯鐮亄palletCode}閲囪喘淇℃伅骞朵竴鏈烢RP搴撳瓨涔熶笉瀛樺湪");
+                    }
+                    BSTStockInfoDTO bSTStockInfoDTO=bSTResponse.Data;
+                    if (bSTStockInfoDTO==null)
+                    {
+                        return content.Error($"涓�鏈烢RP鏈繑鍥瀧palletCode}鐨勫簱瀛樹俊鎭�");
+                    }
+                    Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterialSourceId == bSTStockInfoDTO.MaterialId);
+                    if (materielInfo==null)
+                    {
+                        return content.Error($"鏈壘鍒版潯鐮亄palletCode}鐗╂枡淇℃伅{bSTStockInfoDTO.MaterialNo}");
+                    }
+                    //鐢熸垚搴撳瓨缁勭洏淇℃伅
+                    Dt_StockInfo stockInfo = new Dt_StockInfo()
+                    {
+                        MaterielInvOrgId = materielInfo.MaterielInvOrgId,
+                        PalletCode = palletCode,
+                        RfidCode = "",
+                        LocationCode = "",
+                        PalletType = 1,
+                        WarehouseId = materielInfo.WarehouseId,
+                        StockAttribute = materielInfo.MaterielSourceType,
+                        StockStatus = StockStatusEmun.鍗氭�濋�氱粍鐩樻殏瀛�.ObjToInt(),
+                        MaterielSpec = materielInfo.MaterielSpec,
+                        Unit = materielInfo.MaterielUnit,
+                        MaterielThickness = bSTStockInfoDTO.Thick,
+                        MaterielWide = bSTStockInfoDTO.W,
+                        MaterielWeight = bSTStockInfoDTO.Qty,
+                        MaterielCode = materielInfo.MaterielCode,
+                        MaterielName = materielInfo.MaterielName,
+                        StockLength = bSTStockInfoDTO.StockMeter,
+                        MaterielId = materielInfo.MaterialSourceId
+                    };
+                    if (bSTStockInfoDTO.W > 1200)
+                    {
+                        stockInfo.PalletType = 2;
+                    }
+                    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>(stockInfo);
+                        yLInboundCache.Id = Id;
+                        _unitOfWorkManage.BeginTran();
+                        //鏂板缁勭洏淇℃伅
+                        _stockRepository.StockInfoRepository.AddData(stockInfo);
+                        _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
+                        WebResponseContent webResponse = YLPurchasePush();
+                        if (!webResponse.Status)
+                        {
+                            throw new Exception(webResponse.Message);
+                        }
+                        _unitOfWorkManage.CommitTran();
+                        return content.OK("鎴愬姛", yLInboundCache);
+                    }
+                    else
+                    {
+                        return content.Error($"涓婂嵎鏉$爜{yLInboundCache.BarCode}杩樻湭杩涜缁戝畾");
+                    }
+                    
+                }
+                else
+                {
+                    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;
+                        _unitOfWorkManage.BeginTran();
+                        _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
+                        WebResponseContent webResponse = YLPurchasePush();
+                        if (!webResponse.Status)
+                        {
+                            throw new Exception(webResponse.Message);
+                        }
+                        _unitOfWorkManage.CommitTran();
+                        return content.OK("鎴愬姛", yLInboundCache);
+                    }
+                    else
+                    {
+                        return content.Error($"涓婂嵎鏉$爜{yLInboundCache.BarCode}杩樻湭杩涜缁戝畾");
+                    }
+                }
+                
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+            
+        }
+        /// <summary>
+        /// 鎺ㄩ�佽嚦WCS鍘熸枡绾夸綋鍚姩
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent YLPurchasePush()
+        {
+            try
+            {
+                string url = AppSettings.Get("WCS");
+                if (string.IsNullOrEmpty(url))
+                {
+                    throw new Exception($"鏈壘鍒癢CSAApi鍦板潃,璇锋鏌ラ厤缃枃浠�");
+                }
+                string response = HttpHelper.Post($"{url}/api/Task/YLPurchasePush?code=406");
+
+                return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("杩斿洖閿欒");
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+        /// <summary>
+        /// 鍘熸枡鍒嗛厤宸烽亾
+        /// </summary>
+        /// <param name="palletCode">鏉$爜鍙�</param>
+        /// <returns></returns>
+        /// <exception cref="Exception"></exception>
         public string AssignYLRoadwayNo(string palletCode)
         {
             try
@@ -208,16 +513,39 @@
                 }
 
                 string roadwayNo = "";
-                if (stockInfo.MaterielThickness > 800)
+                
+                if (stockInfo.MaterielInvOrgId==MaterielInvOrgEnum.鏂板巶.ObjToInt())
                 {
-                    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("YL")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
-                    roadwayNo = locationCounts.OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
-                    if (stockInfo.MaterielWide > 2200)
+                    //闄愬埗鐩村緞
+                    if (stockInfo.MaterielThickness >= 300 && stockInfo.MaterielThickness <= 1300 && stockInfo.MaterielWide >= 700 && stockInfo.MaterielWide <= 2700)
                     {
-                        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=="SC02_YL").GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
-                        roadwayNo = locationCounts.OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
+                        //鑾峰彇鍒嗛厤
+                        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);
                     }
                 }
+                else
+                {
+                    //闄愬埗
+                    if (stockInfo.MaterielThickness >= 800 && stockInfo.MaterielThickness <= 1500 && stockInfo.MaterielWide >= 700 && stockInfo.MaterielWide <= 2500)
+                    {
+                        bool LayerLimit = false;
+                        if (stockInfo.MaterielThickness>1300)
+                        {
+                            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("YL") && !x.RoadwayNo.Contains("YLDual") && (LayerLimit ? x.Columns>=56 : x.Columns<=55)).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
+                        if (stockInfo.MaterielWide > 2200)
+                        {
+                            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 == "SC02_YL" && (LayerLimit ? x.Columns >= 56 : x.Columns <= 55)).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
+                        }
+
+                        roadwayNo = HandleRoadway(locationCounts, warehouse);
+                    }
+                }
+                
                 return !string.IsNullOrEmpty(roadwayNo) ? (roadwayNo) : throw new Exception("鏈壘鍒板彲鍒嗛厤宸烽亾");
             }
             catch (Exception ex)
@@ -226,27 +554,45 @@
                 throw new Exception(ex.Message);
             }
         }
+        //澶勭悊鍒嗛厤宸烽亾 浠诲姟鏁伴噺
+        public string HandleRoadway(List<LocationCount> locationCounts, Dt_Warehouse warehouse)
+        {
+            //宸烽亾浠诲姟鍒嗛厤鏁伴噺
+            List<LocationCount> useLocationCounts = Db.Queryable<Dt_Task>().Where(x => x.WarehouseId == warehouse.WarehouseId
+            && locationCounts.Select(j => j.RoadwayNo).Distinct().Contains(x.Roadway)
+            && TaskInboundTypes.Contains(x.TaskType)).GroupBy(x => x.Roadway).Select(x => new LocationCount { RoadwayNo = x.Roadway, Count = SqlFunc.AggregateCount(x) }).ToList();
+            foreach (var item in locationCounts)
+            {
+                LocationCount? count = useLocationCounts.FirstOrDefault(x => x.RoadwayNo == item.RoadwayNo);
+                if (count != null)
+                {
+                    item.Count -= count.Count;
+                }
+            }
+            return locationCounts.Where(x => x.Count > 0).OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
+        }
         /// <summary>
         /// 鍏ュ簱瀹屾垚
         /// </summary>
         public WebResponseContent InboundTaskCompleted(Dt_Task task)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
                 Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == task.WarehouseId);
-                if (warehouse.WarehouseCode == WarehouseEnum.LLDCP.ToString()) //鎴愬搧瀹屾垚
+                if (warehouse.WarehouseCode == WarehouseEnum.LLDCP.ToString() || warehouse.WarehouseCode == WarehouseEnum.LLDFL.ToString()) //鎴愬搧/杈呮枡瀹屾垚
                 {
                     Dt_LocationInfo locationInfoEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                     if (locationInfoEnd == null)
                     {
-                        return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
+                        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();
                     }
-                    Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+                    Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x => x.PalletCode == task.PalletCode).Includes(x=>x.proStockInfoDetails).First();
                     if (proStockInfo != null && proStockInfo.StockStatus == StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt())
                     {
                         task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
@@ -262,24 +608,46 @@
                         BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.浜哄伐瀹屾垚 : WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚);
                         _unitOfWorkManage.CommitTran();
                     }
+                    else if (proStockInfo != null && proStockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt())
+                    {
+                        task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+                        proStockInfo.proStockInfoDetails.ForEach(x =>
+                        {
+                            x.ProStockDetailStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                        });
+                        _unitOfWorkManage.BeginTran();
+                        if (agvstation != null)
+                        {
+                            _agvStationInfoRepository.UpdateData(agvstation);
+                        }
+                        proStockInfo.LocationCode = locationInfoEnd.LocationCode;
+                        proStockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                        _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo);
+                        _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfo.proStockInfoDetails);
+                        _basicService.LocationInfoService.UpdateLocationStatus(locationInfoEnd, proStockInfo.PalletType, LocationStatusEnum.InStock, proStockInfo.WarehouseId);
+                        BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.浜哄伐瀹屾垚 : WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚);
+                        _unitOfWorkManage.CommitTran();
+                    }
                     else
                     {
-                        return WebResponseContent.Instance.Error($"鏈壘鍒板搴斿簱瀛樹俊鎭�");
+                        return content.Error($"鏈壘鍒板搴斿簱瀛樹俊鎭�");
                     }
                 }
                 else//鍘熸枡搴撳畬鎴�
                 {
+                    //鑾峰彇搴撳瓨
                     Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode);
                     if (stockInfo == null)
                     {
-                        return WebResponseContent.Instance.Error($"鏈壘鍒板搴斿簱瀛樹俊鎭�");
+                        return content.Error($"鏈壘鍒板搴斿簱瀛樹俊鎭�");
                     }
+                    //鑾峰彇璐т綅淇℃伅
                     Dt_LocationInfo locationInfoEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                     if (locationInfoEnd == null)
                     {
-                        return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
+                        return content.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
                     }
-                    
+                    //鏇存柊鐘舵��
                     task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                     _unitOfWorkManage.BeginTran();
                     if (task.TaskType == TaskTypeEnum.InPick.ObjToInt())
@@ -289,18 +657,41 @@
                     }
                     stockInfo.LocationCode = locationInfoEnd.LocationCode;
                     stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                    if (task.TaskType!=TaskTypeEnum.Inbound.ObjToInt())
+                    {
+                        stockInfo.IsFull = WhetherEnum.True.ObjToInt();
+                    }
                     _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                     _basicService.LocationInfoService.UpdateLocationStatus(locationInfoEnd, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId);
                     BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.浜哄伐瀹屾垚 : WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚);
+                    //涓婃姤鑰佸巶ERP
+                    if (stockInfo.MaterielInvOrgId == MaterielInvOrgEnum.鑰佸巶.ObjToInt())
+                    {
+                        int Qty = Convert.ToInt32(stockInfo.MaterielWeight);
+                        BSTPurchaseUpModel bSTPurchaseUpModel = new BSTPurchaseUpModel()
+                        {
+                            Barcode = stockInfo.PalletCode,
+                            BarcodeQty = Qty,
+                            Rfid = stockInfo.RfidCode,
+                            RfidUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
+                        };
+                        BSTResponse<object> bSTResponse = _invokeERPService.BSTPurchaseUp(bSTPurchaseUpModel).DeserializeObject<BSTResponse<object>>();
+                        if (bSTResponse.Code == 500)
+                        {
+                            throw new Exception($"BST涓�鏈烢RP鍚屾鍏ュ簱淇℃伅澶辫触,閿欒淇℃伅锛歿bSTResponse.Msg}");
+                        }
+                        content.Message = bSTResponse.Msg;
+                    }
                     _unitOfWorkManage.CommitTran();
                 }
-                return WebResponseContent.Instance.OK();
+                return content.OK();
             }
             catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
-                return WebResponseContent.Instance.Error(ex.Message);
+                content.Error(ex.Message);
             }
+            return content;
         }
         /// <summary>
         /// 鍒嗛厤鎴愬搧宸烽亾
@@ -310,17 +701,12 @@
         {
             try
             {
-                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == 2);
-                if (warehouse == null)
-                {
-                    throw new Exception($"鏈壘鍒板贩閬撳搴斾粨搴撲俊鎭�");
-                }
-
                 string roadwayNo = "";
-                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("CP")).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 == WarehouseEnum.LLDCP.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("CP")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList();
                 //绛涢�夊綋鍓嶅叆搴撲换鍔′腑宸插垎閰嶅贩閬撲换鍔℃暟閲�
-                List<LocationCount> useLocationCounts = Db.Queryable<Dt_Task>().Where(x => x.WarehouseId == warehouse.WarehouseId 
-                && locationCounts.Select(j=>j.RoadwayNo).Contains(x.Roadway)
+                List<LocationCount> useLocationCounts = Db.Queryable<Dt_Task>().Where(x => (x.WarehouseId == WarehouseEnum.LLDCP.ObjToInt()|| x.WarehouseId == WarehouseEnum.LLDFL.ObjToInt())
+                && locationCounts.Select(j=>j.RoadwayNo).Distinct().Contains(x.Roadway)
                 && TaskInboundTypes.Contains(x.TaskType)).GroupBy(x => x.Roadway).Select(x => new LocationCount { RoadwayNo = x.Roadway, Count = SqlFunc.AggregateCount(x) }).ToList();
                 foreach (var item in locationCounts)
                 {
@@ -330,7 +716,8 @@
                         item.Count -= count.Count;
                     }
                 }
-                roadwayNo = locationCounts.OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
+                //閫氳繃鍙敤璐т綅鏁伴噺鎺掑簭锛屾渶澶氱殑浼樺厛鍒嗛厤
+                roadwayNo = locationCounts.Where(x=>x.Count>0).OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? "";
                 return !string.IsNullOrEmpty(roadwayNo) ? (roadwayNo) : throw new Exception("鏈壘鍒板彲鍒嗛厤宸烽亾");
             }
             catch (Exception ex)
@@ -339,6 +726,7 @@
                 throw new Exception(ex.Message);
             }
         }
+        
         /// <summary>
         /// 鍏ュ簱浠诲姟鐢宠鍒嗛厤璐т綅
         /// </summary>
@@ -359,8 +747,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($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
@@ -376,7 +769,6 @@
                 {
                     task.TaskStatus = TaskStatusEnum.SC_Execute.ObjToInt();
                 }
-                
 
                 LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
                 //鏇存柊閿佸畾璐т綅
@@ -393,54 +785,7 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="taskNum"></param>
-        /// <param name="roadwayNo"></param>
-        /// <param name="heightType"></param>
-        /// <returns></returns>
-        public WebResponseContent AssignInboundTaskLocationByHeight(int taskNum, string roadwayNo, int heightType)
-        {
-            try
-            {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-                if (task == null)
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鍏ュ簱浠诲姟");
-                }
-
-                if (_basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress) != null)
-                {
-                    return WebResponseContent.Instance.OK(data: task.TargetAddress);
-                }
-
-                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId, heightType: heightType);
-                if (locationInfo == null)
-                {
-                    return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
-                }
-
-                task.Roadway = roadwayNo;
-                task.TargetAddress = locationInfo.LocationCode;
-                task.TaskStatus = TaskStatusEnum.SC_Execute.ObjToInt();
-
-                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
-
-                _unitOfWorkManage.BeginTran();
-                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation);
-                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, task.PalletType, LocationStatusEnum.Lock, task.WarehouseId);
-                BaseDal.UpdateData(task);
-                _unitOfWorkManage.CommitTran();
-                return WebResponseContent.Instance.OK(data: locationInfo.LocationCode);
-            }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                return WebResponseContent.Instance.Error(ex.Message);
-            }
-        }
+        
         /// <summary>
         /// 绌烘鍥炲簱
         /// </summary>
@@ -479,15 +824,13 @@
                 //鍒嗛厤宸烽亾
                 string roadWay=AssignCPRoadwayNo();
                 
-                //鑾峰彇鎴愬搧搴�
-                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.LLDCP.ToString());
                 Dt_ProStockInfo proStockInfo = new Dt_ProStockInfo()
                 {
                     PalletCode=barCode,
                     ProStockAttribute=ProStockAttributeEnum.绌烘墭.ObjToInt(),
                     PalletType=1,
                     LocationCode="",
-                    WarehouseId=warehouse.WarehouseId,
+                    WarehouseId= WarehouseEnum.LLDFL.ObjToInt(),
                     StockStatus=StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt()
                 }; 
 
@@ -502,7 +845,7 @@
                     TargetAddress = "",
                     TaskType = TaskTypeEnum.EmptyProductBack.ObjToInt(),
                     TaskStatus = TaskStatusEnum.New.ObjToInt(),
-                    WarehouseId = warehouse.WarehouseId,
+                    WarehouseId = WarehouseEnum.LLDFL.ObjToInt(),
                     PalletType = 1
                 };
                 _unitOfWorkManage.BeginTran();
@@ -520,6 +863,117 @@
                 content.Error(ex.Message);
             }
             return content;
+        }
+        private readonly static object _lockerFLorCP = new object();
+        /// <summary>
+        /// 杈呮枡/鎴愬搧涓存椂鍏ュ簱
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent InboundFLOrCPTask(string barCode, string startPoint,string matCode,int matCount, int oneCount)
+        {
+            lock (_lockerFLorCP)
+            {
+                WebResponseContent content = new WebResponseContent();
+                try
+                {
+                    if (matCount<1 || oneCount < 1)
+                    {
+                        return content.Error("鐗╂枡鎬绘暟鎴栧崟涓暟閲忎笉鑳藉皬浜�1");
+                    }
+                    //string palletCode = @"^C\d{5}$";  // 姝e垯琛ㄨ揪寮�
+                    //bool isValid = Regex.IsMatch(barCode, palletCode);
+                    //if (!isValid)
+                    //{
+                    //    return content.Error($"妗嗙爜鏍煎紡閿欒{barCode}");
+                    //}
+                    //鑾峰彇鐗╂枡
+                    Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == matCode && x.MaterielInvOrgId == MaterielInvOrgEnum.鏂板巶.ObjToInt() && (x.WarehouseId==WarehouseEnum.LLDCP.ObjToInt() || x.WarehouseId == WarehouseEnum.LLDFL.ObjToInt()));
+                    if (materielInfo == null)
+                    {
+                        return content.Error($"鏈壘鍒扮墿鏂欎俊鎭瘂matCode}");
+                    }
+                    Dt_AGVStationInfo agvstation = _agvStationInfoRepository.QueryFirst(x => x.AGVStationCode == startPoint);
+                    if (agvstation == null)
+                    {
+                        return content.Error($"璧风偣閿欒{startPoint}");
+                    }
+                    //鍒ゆ柇褰撳墠鐐逛綅鏄惁閲嶅
+                    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}宸插瓨鍦ㄤ换鍔�");
+                    }
+                    Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == barCode);
+                    if (taskOld != null)
+                    {
+                        return content.Error($"鎵樼洏{barCode}浠诲姟宸插瓨鍦�");
+                    }
+                    Dt_ProStockInfo proStockInfoOld = _stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode);
+                    if (proStockInfoOld != null)
+                    {
+                        return content.Error($"鎵樼洏{barCode}宸插瓨鍦�");
+                    }
+                    //鍒嗛厤宸烽亾
+                    string roadWay = AssignCPRoadwayNo();
+
+                    //鑾峰彇鎴愬搧搴�
+                    WarehouseEnum warehouseEnum = materielInfo.MaterielSourceType == MaterielTypeEnum.鎴愬搧.ObjToInt() ? WarehouseEnum.LLDCP : WarehouseEnum.LLDFL;
+                    List<Dt_ProStockInfoDetail> proStockInfoDetails = new List<Dt_ProStockInfoDetail>();
+                    for (int i = 0; i < matCount; i++)
+                    {
+                        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,
+                        ProStockAttribute = materielInfo.MaterielSourceType,
+                        PalletType = 1,
+                        LocationCode = "",
+                        WarehouseId = warehouseEnum.ObjToInt(),
+                        StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt(),
+                        proStockInfoDetails = proStockInfoDetails
+                    };
+
+                    Dt_Task newTask = new Dt_Task()
+                    {
+                        CurrentAddress = startPoint,
+                        Grade = 0,
+                        NextAddress = "",
+                        PalletCode = barCode,
+                        Roadway = roadWay,
+                        SourceAddress = startPoint,
+                        TargetAddress = "",
+                        TaskType = TaskTypeEnum.Inbound.ObjToInt(),
+                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                        WarehouseId = warehouseEnum.ObjToInt(),
+                        PalletType = 1
+                    };
+                    _unitOfWorkManage.BeginTran();
+                    int taskId = BaseDal.AddData(newTask);
+                    BaseDal.Db.InsertNav(proStockInfo).Include(x => x.proStockInfoDetails).ExecuteCommand();
+                    newTask.TaskId = taskId;
+                    _unitOfWorkManage.CommitTran();
+                    //鎺ㄩ�佷换鍔�
+                    PushTasksToWCS(new List<Dt_Task> { newTask }, "AGV");
+                    content.OK("鍙戦�佹垚鍔�");
+                }
+                catch (Exception ex)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    content.Error(ex.Message);
+                }
+                return content;
+            }
         }
         /// <summary>
         /// 鍗板埛浣欐枡閫�鏂欎换鍔�
@@ -542,6 +996,10 @@
                 if (materielInfo == null)
                 {
                     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)
@@ -581,10 +1039,10 @@
                     Roadway = "",
                     SourceAddress = address,
                     TargetAddress = "",
-                    TaskType = TaskTypeEnum.PrintBackInbound.ObjToInt(),
+                    TaskType = TaskTypeEnum.PrintYLBackInbound.ObjToInt(),
                     TaskStatus = TaskStatusEnum.New.ObjToInt(),
                     WarehouseId = warehouseId,
-                    PalletType = 1,
+                    PalletType = stockInfo.PalletType,
                     TaskLength= wide
                 };
                 _unitOfWorkManage.BeginTran();
@@ -667,10 +1125,10 @@
                     Roadway = "",
                     SourceAddress = address,
                     TargetAddress = "",
-                    TaskType = TaskTypeEnum.PrintInbound.ObjToInt(),
+                    TaskType = TaskTypeEnum.PrintYLInbound.ObjToInt(),
                     TaskStatus = TaskStatusEnum.New.ObjToInt(),
                     WarehouseId = warehouseId,
-                    PalletType = 1,
+                    PalletType = stockInfo.PalletType,
                     TaskLength = wide
                 };
                 _unitOfWorkManage.BeginTran();
@@ -689,5 +1147,184 @@
             }
             return content;
         }
+        /// <summary>
+        /// 鎴愬搧/鍗婃垚鍝佷俊鎭悓姝ユ帴鍙�
+        /// </summary>
+        public WebResponseContent ReceiveProCodeInfo(List<MESProInDTO> proInDTOs)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                if (proInDTOs == null || proInDTOs.Count <= 0)
+                {
+                    return content.Error("浼犲叆淇℃伅涓虹┖");
+                }
+                //鑾峰彇鎵�鏈夋垚鍝侊紝鍗婃垚鍝佷俊鎭�
+                List<Dt_MESProInOrderInfo> proInOrderInfos = _inboundRepository.MESProInOrderInfoRepository.QueryData();
+                //鑾峰彇鎵�鏈夌墿鏂欎俊鎭�
+                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x => x.MaterielInvOrgId == MaterielInvOrgEnum.鏂板巶.ObjToInt());
+
+                MESProInDTO? CheckMaterialCode = proInDTOs.FirstOrDefault(x => !materielInfos.Select(x => x.MaterielCode).Contains(x.MaterialCode));
+                if (CheckMaterialCode != null)
+                {
+                    return content.Error($"鐗╂枡缂栫爜{nameof(MESProInDTO.MaterialCode)}:{CheckMaterialCode.MaterialCode}淇℃伅涓嶅瓨鍦�");
+                }
+                //鑾峰彇鎵�鏈堿GV鐐逛綅
+                List<Dt_AGVStationInfo> aGVStationInfos = _agvStationInfoRepository.QueryData(x => !string.IsNullOrEmpty(x.MESPointCode));
+
+                //鍒ゆ柇鏄惁瀛樺湪閲嶅
+                MESProInDTO? proInDTO = proInDTOs.FirstOrDefault(x => x.IsMantissa == false && proInOrderInfos.Select(x => x.BarCode).Contains(x.BarCode));
+                if (proInDTO != null)
+                {
+                    return content.Error($"{proInDTO.ProductOrderNo}鐢熶骇宸ュ崟{proInDTO.BarCode}鏉$爜宸插瓨鍦�");
+                }
+                Dt_MESProInOrderInfo? proInOrderInfo = proInOrderInfos.FirstOrDefault(x => x.MESProInStatus == InOrderStatusEnum.鍏抽棴.ObjToInt() && proInDTOs.Select(x => x.ProductOrderNo).Distinct().Contains(x.ProductOrderNo));
+                if (proInOrderInfo != null)
+                {
+                    return content.Error($"{proInOrderInfo.ProductOrderNo}鐢熶骇宸ュ崟宸插叧闂�");
+                }
+                List<Dt_MESProInOrderInfo> AddMESProInOrders = new List<Dt_MESProInOrderInfo>();
+                foreach (var item in proInDTOs)
+                {
+                    Dt_MaterielInfo materielInfo = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterialCode);
+                    if (materielInfo.MaterielSourceType != MaterielTypeEnum.鎴愬搧.ObjToInt())
+                    {
+                        Dt_AGVStationInfo? CheckPointCode = aGVStationInfos.FirstOrDefault(x => x.MESPointCode == item?.PointCode);
+                        if (CheckPointCode == null)
+                        {
+                            return content.Error($"鍛ㄨ浆浣峽nameof(MESReturnIssueDTO.PointCode)}{item?.PointCode}涓嶅瓨鍦�,浠呮垚鍝佺墿鏂欏彲涓嶄紶");
+                        }
+                    }
+                    Dt_MESProInOrderInfo AddproInOrderInfo = _mapper.Map<Dt_MESProInOrderInfo>(item);
+                    AddproInOrderInfo.WarehouseId = materielInfo.WarehouseId;
+                    AddproInOrderInfo.MESProOrderType = materielInfo.MaterielSourceType;
+                    AddMESProInOrders.Add(AddproInOrderInfo);
+                }
+                List<Dt_Task> tasks = new List<Dt_Task>();
+                _unitOfWorkManage.BeginTran();
+                _inboundRepository.MESProInOrderInfoRepository.AddData(AddMESProInOrders);
+                if (AddMESProInOrders.Where(x => x.MESProOrderType == MaterielTypeEnum.鍗婃垚鍝�.ObjToInt()).Count() > 0)
+                {
+                    //鐢熸垚鍗婃垚鍝佸叆搴�
+                    WebResponseContent webResponse = PrintInbound(AddMESProInOrders.Where(x => x.MESProOrderType == MaterielTypeEnum.鍗婃垚鍝�.ObjToInt()).ToList());
+                    if (!webResponse.Status)
+                    {
+                        throw new Exception(webResponse.Message);
+                    }
+                    tasks = webResponse.Data as List<Dt_Task>;
+                    WebResponseContent taskResponse = PushTasksToWCS(tasks);
+                    if (taskResponse.Status)
+                    {
+                        throw new Exception(taskResponse.Message);
+                    }
+                }
+                _unitOfWorkManage.CommitTran();
+                content.OK("鎺ユ敹鎴愬姛");
+                
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 鍗板埛涓嬫枡MES浠诲姟
+        /// </summary>
+        public WebResponseContent PrintInbound(List<Dt_MESProInOrderInfo> mESProInOrderInfos)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                if (mESProInOrderInfos.Count <= 0)
+                {
+                    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>();
+                //鑾峰彇鎵�鏈堿GV鐐逛綅
+                List<Dt_AGVStationInfo> aGVStationInfos = _agvStationInfoRepository.QueryData(x => !string.IsNullOrEmpty(x.MESPointCode));
+                //鏍规嵁鍗婃垚鍝佷俊鎭懠鍙搴斾换鍔�
+                foreach (var item in mESProInOrderInfos)
+                {
+                    Dt_AGVStationInfo? CheckPointCode = aGVStationInfos.FirstOrDefault(x => x.MESPointCode == item?.PointCode);
+                    Dt_MaterielInfo? materielInfo = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterialCode);
+                    if (materielInfo == null)
+                    {
+                        return content.Error("鏈壘鍒扮墿鏂欎俊鎭�");
+                    }
+                    if (materielInfo.MaterielSourceType != MaterielTypeEnum.鍗婃垚鍝�.ObjToInt())
+                    {
+                        return content.Error($"鏈壘鍒扮墿鏂檣materielInfo.MaterielCode}鍗婃垚鍝佷俊鎭�");
+                    }
+                    Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == item.BarCode);
+                    if (stockInfoOld != null)
+                    {
+                        return content.Error("鎵樼洏淇℃伅宸插瓨鍦�");
+                    }
+                    //鐢熸垚搴撳瓨缁勭洏淇℃伅
+                    Dt_StockInfo stockInfo = new Dt_StockInfo()
+                    {
+                        MaterielInvOrgId = materielInfo.MaterielInvOrgId,
+                        PalletCode = item.BarCode,
+                        LocationCode = "",
+                        PalletType = 1,
+                        WarehouseId = materielInfo.WarehouseId,
+                        StockAttribute = materielInfo.MaterielSourceType,
+                        StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(),
+                        MaterielSpec = materielInfo.MaterielSpec,
+                        Unit = materielInfo.MaterielUnit,
+                        MaterielThickness = item.Thickness,
+                        MaterielWide = item.Wide,
+                        MaterielWeight = item.Weight,
+                        MaterielCode = materielInfo.MaterielCode,
+                        MaterielName = materielInfo.MaterielName,
+                        StockLength=item.ProQuantity
+                    };
+                    if (item.Wide > 1200)
+                    {
+                        stockInfo.PalletType = 2;
+                    }
+                    
+                    //鍗婃垚鍝佸叆搴撲换鍔�
+                    Dt_Task newTask = new Dt_Task()
+                    {
+                        CurrentAddress = CheckPointCode.AGVStationCode,
+                        Grade = 0,
+                        NextAddress = "",
+                        PalletCode = item.BarCode,
+                        Roadway = "",
+                        SourceAddress = CheckPointCode.AGVStationCode,
+                        TargetAddress = "",
+                        TaskType = 0,
+                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                        WarehouseId = materielInfo.WarehouseId,
+                        PalletType = stockInfo.PalletType,
+                        TaskLength = (int)item.Wide
+                    };
+                    TaskTypeEnum taskTypeEnum = CheckPointCode.StationArea switch
+                    {
+                        nameof(AGVStationAreaEnum.涓�妤煎嵃鍒�) => TaskTypeEnum.PrintYLInbound,
+                        _ => throw new Exception("鏈壘鍒板搴斾换鍔�")
+                    };
+                    newTask.TaskType = taskTypeEnum.ObjToInt();
+                    stockInfos.Add(stockInfo);
+                    tasks.Add(newTask);
+                }
+                //鎿嶄綔鍏ュ簱鏁版嵁
+                BaseDal.AddData(tasks);
+                _stockRepository.StockInfoRepository.AddData(stockInfos);
+                //鎺ㄩ�佷换鍔�
+                content.OK("鍙戦�佹垚鍔�",data:tasks);
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
     }
 }

--
Gitblit v1.9.3