From ea3b8223434673ca6d911bfcd6cdcafa773cb5f0 Mon Sep 17 00:00:00 2001
From: qinchulong <qinchulong@hnkhzn.com>
Date: 星期一, 03 三月 2025 22:01:01 +0800
Subject: [PATCH] 更新入库逻辑

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/GZJ/GZJJob.cs |   70 ++++++++++++++++++++++++++++++----
 1 files changed, 61 insertions(+), 9 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/GZJ/GZJJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/GZJ/GZJJob.cs"
index 1ebe252..549a68f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/GZJ/GZJJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/GZJ/GZJJob.cs"
@@ -15,6 +15,7 @@
 using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Common.LocationEnum;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Communicator;
 using WIDESEAWCS_Core.BaseRepository;
@@ -43,6 +44,8 @@
         private readonly IRepository<dt_outstockinfo> _outStockRepository;
         private readonly IRepository<dt_batchInfo> _batchInfoRepository;
         private readonly IRepository<Dt_StockInfo> _StockInfoRepository;
+        private readonly IRepository<Dt_LocationInfo> _LocationInfoRepository;
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
 
         WebSocketServer _webSocketServer;
         public GZJJob(ITaskService taskService, WebSocketServer webSocketServer, Idt_ErrormsginfoService errormsginfoService,
@@ -53,7 +56,9 @@
             IRepository<dt_outstockinfo> outStockRepository,
             IRepository<dt_storagemode> storagemodeRepository,
             IRepository<dt_batchInfo> batchInfoRepository,
-            IRepository<Dt_StockInfo> StockInfoRepository)
+            IRepository<Dt_StockInfo> StockInfoRepository,
+            IRepository<Dt_LocationInfo> LocationInfoRepository,
+            IUnitOfWorkManage unitOfWorkManage)
         {
             _taskService = taskService;//娉ㄥ叆
             _webSocketServer = webSocketServer;
@@ -65,6 +70,8 @@
             _outStockRepository = outStockRepository;
             _batchInfoRepository = batchInfoRepository;
             _StockInfoRepository = StockInfoRepository;
+            _LocationInfoRepository = LocationInfoRepository;
+            _unitOfWorkManage = unitOfWorkManage;
         }
 
         public Task Execute(IJobExecutionContext context)
@@ -88,6 +95,7 @@
                         var station=_dt_stationInfoRepository.QueryFirst(v=>v.msg== "涓滆法鏋跺瓙");
                         task.SourceAddress = station.Row + "-" + station.Column + "-1";
                         task.TargetAddress = _locationInfoService.GetInLocation(storagemode.storagemode).LocationCode;
+                        
                         task.Grade = 1;
                         task.Remark = (int)MateTypeEnum.ZiChan;
                     }
@@ -139,10 +147,23 @@
                     {
                         throw new Exception($"瑙勬暣鏈哄綋鍓嶄俊鍙蜂笉婊¤冻鍏ュ簱浠诲姟鐢熸垚鏉′欢");
                     }
+                    //鏌ユ壘鐩搁偦鐨勫簱浣�
+                    Dt_LocationInfo Towlocation = new Dt_LocationInfo();
+                    var Onelocation = _LocationInfoRepository.QueryFirst(v => v.LocationCode == task.TargetAddress);
+                    if (Onelocation.Depth == 1)
+                    {
+                        Towlocation = _LocationInfoRepository.QueryFirst(v => v.Row == Onelocation.Row && v.Column == Onelocation.Column && v.Depth == 2);
+                    }
+                    else
+                    {
+                        Towlocation = _LocationInfoRepository.QueryFirst(v => v.Row == Onelocation.Row && v.Column == Onelocation.Column && v.Depth == 1);
+                    }
+                    task.NextAddress = Towlocation.LocationCode;
                     task.Roadway = "TC01";
                     task.TaskType = (int)TaskInboundTypeEnum.Inbound;
                     task.TaskState = (int)TaskInStatusEnum.InNew;
-
+                    task.PalletCode = "text";
+                    task.CurrentAddress = "text";
                     _dt_taskRepositiry.AddData(task);
 
                     #endregion
@@ -155,16 +176,16 @@
                 try
                 {
                     #region 鐢熸垚鍑哄簱浠诲姟
+                    if (!OHTJob.oHTReadData.R_ZXJ_isWork)
+                    {
+                        throw new Exception($"鏁村舰鏈烘姇鍏ヤ娇鐢ㄤ俊鍙蜂负false");
+                    }
                     var isout = _outStockRepository.QueryFirst(v => v.Id == 1);
                     if (isout.isout != 1)
                     {
                         throw new Exception($"褰撳墠绯荤粺璁剧疆涓轰笉鍑哄簱妯″紡");
                     }
-                    if (!OHTJob.oHTReadData.R_ZXJ_isWork)
-                    {
-                        throw new Exception($"鏁村舰鏈烘姇鍏ヤ娇鐢ㄤ俊鍙蜂负false");
-                    }
-                    if (!OHTJob.oHTReadData.R_ZXJ_TCMode || OHTJob.oHTReadData.R_HC_isReadyWork)
+                    if (!OHTJob.oHTReadData.R_ZXJ_TCMode || !OHTJob.oHTReadData.R_HC_isReadyWork)
                     {
                         throw new Exception($"鏁村舰鏈轰笉灞炰簬澶╄溅涓婃枡妯″紡鎴栧ぉ杞︽斁鏉夸俊鍙蜂负false");
                     }
@@ -177,11 +198,30 @@
                     //鏌ヨ褰撳墠闇�瑕佸嚭搴撶殑鎵规鍙凤紝浠ュ強鍑哄簱鐗╂枡绫诲瀷
                     var batch = _batchInfoRepository.QueryFirst(v => v.Id == 1);
                     //鏌ヨ搴撳瓨鐗╂枡搴撳瓨淇℃伅
-                    var stocks = _StockInfoRepository.QueryData(v => v.Remark == batch.materType && v.BatchNo == batch.OutBatch).OrderBy(v => v.CreateDate).ToList();
+                    var stocks = _StockInfoRepository.QueryData(v => v.Remark == batch.materType && v.BatchNo == batch.OutBatch && v.StockStatus==0)
+                        .OrderBy(v => v.CreateDate).ToList();
                     if (stocks.Count <= 0)
                     {
                         throw new Exception($"褰撳墠搴撳瓨涓病鏈夈�恵batch.materType}銆戯紙0鑷骇 1澶栬喘锛変笖鎵规涓恒�恵batch.OutBatch}銆戠殑鐗╂枡");
                     }
+                    //鏌ヨ璐т綅
+                    var locaOne=_LocationInfoRepository.QueryFirst(v=>v.LocationCode== stocks[0].LocationCode);
+                    //鏌ヨ鐩搁偦鐨勮揣浣�
+                    Dt_LocationInfo locaTow = new Dt_LocationInfo();
+                    if (locaOne.Depth==1) 
+                    {
+                        locaTow = _LocationInfoRepository.QueryFirst(v => v.Row == locaOne.Row &&v.Column== locaOne.Column && v.Depth==2);
+                    }
+                    else
+                    {
+                        locaTow = _LocationInfoRepository.QueryFirst(v => v.Row == locaOne.Row && v.Column == locaOne.Column && v.Depth == 1);
+                    }
+                    locaOne.LocationStatus = (int)LocationStatusEnum.Lock;
+                    locaTow.LocationStatus = (int)LocationStatusEnum.Lock;
+                    //鏌ヨ鐩搁偦鐨勫簱瀛�
+                    var BBstock = _StockInfoRepository.QueryFirst(v=>v.LocationCode== locaTow.LocationCode);
+                    BBstock.StockStatus = 1;
+                    stocks[0].StockStatus = 1;
                     //鏌ヨ缁堢偣绔欏彴淇℃伅
                     var station = _dt_stationInfoRepository.QueryFirst(v => v.msg == "鏁村舰鏈烘斁鏂欎綅");
                     //寮�濮嬪垱寤轰换鍔�
@@ -190,14 +230,26 @@
                     outtask.TaskType = (int)TaskOutboundTypeEnum.Outbound;
                     outtask.TaskState = (int)TaskOutStatusEnum.OutNew;
                     outtask.SourceAddress = stocks[0].LocationCode;
-                    outtask.TargetAddress = station.Row + "-" + station.Column + "-1"; ;
+                    outtask.TargetAddress = station.Row + "-" + station.Column + "-1";
+                    outtask.NextAddress = locaTow.LocationCode;
                     outtask.Grade = 1;
+                    outtask.WMSId = 3;
                     outtask.Remark = batch.materType;
+                    outtask.PalletCode = "text";
+                    outtask.CurrentAddress = "text";
+
+                    _unitOfWorkManage.BeginTran();
+                    _LocationInfoRepository.UpdateData(locaOne);
+                    _LocationInfoRepository.UpdateData(locaTow);
+                    _StockInfoRepository.UpdateData(BBstock);
                     _dt_taskRepositiry.AddData(outtask);
+                    _StockInfoRepository.UpdateData(stocks[0]);
+                    _unitOfWorkManage.CommitTran();
                     #endregion
                 }
                 catch (Exception ex)
                 {
+                    _unitOfWorkManage.RollbackTran();
                     _ErrormsginfoService.UpdateErrorMsg(ex.Message, 3);
                 }
             }

--
Gitblit v1.9.3