From eb72ad7c5ec8f4f0cd8b291d16534a10e9eb113c Mon Sep 17 00:00:00 2001
From: Zhang-Hong-Lin <a3219986988@163.com>
Date: 星期一, 10 三月 2025 14:50:01 +0800
Subject: [PATCH] 后端

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/GZJ/GZJJob.cs |  549 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 470 insertions(+), 79 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 507f500..b6c9f94 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"
@@ -5,6 +5,7 @@
 using Microsoft.Extensions.Hosting;
 using Microsoft.VisualBasic.FileIO;
 using Newtonsoft.Json;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
 using Quartz;
 using SixLabors.ImageSharp.PixelFormats;
 using System;
@@ -15,14 +16,21 @@
 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;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_ISystemServices;
 using WIDESEAWCS_ITaskInfoService;
+using WIDESEAWCS_IWMSPart;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.DeviceBase;
 using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
+using WIDESEAWCS_TaskInfoService;
 using WIDESEAWCS_Tasks.OHT;
+using static System.Collections.Specialized.BitVector32;
 
 namespace WIDESEAWCS_Tasks
 {
@@ -30,106 +38,489 @@
     public class GZJJob : JobBase, IJob
     {
         private readonly ITaskService _taskService;
+        private readonly Idt_ErrormsginfoService _ErrormsginfoService;
+        private readonly IRepository<dt_stationInfo> _dt_stationInfoRepository;
+        private readonly IRepository<Dt_Task> _dt_taskRepositiry;
+        private readonly ILocationInfoService _locationInfoService;
+        private readonly IRepository<dt_storagemode> _storagemodeRepository;
+        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)
+        public GZJJob(ITaskService taskService, WebSocketServer webSocketServer, Idt_ErrormsginfoService errormsginfoService,
+            Idt_StationinfoService stationinfoService,
+            IRepository<dt_stationInfo> dt_stationInfoRepository,
+            IRepository<Dt_Task> dt_taskRepositiry,
+            ILocationInfoService locationInfoService,
+            IRepository<dt_outstockinfo> outStockRepository,
+            IRepository<dt_storagemode> storagemodeRepository,
+            IRepository<dt_batchInfo> batchInfoRepository,
+            IRepository<Dt_StockInfo> StockInfoRepository,
+            IRepository<Dt_LocationInfo> LocationInfoRepository,
+            IUnitOfWorkManage unitOfWorkManage)
         {
             _taskService = taskService;//娉ㄥ叆
             _webSocketServer = webSocketServer;
+            _ErrormsginfoService = errormsginfoService;
+            _dt_stationInfoRepository = dt_stationInfoRepository;
+            _dt_taskRepositiry = dt_taskRepositiry;
+            _locationInfoService = locationInfoService;
+            _storagemodeRepository = storagemodeRepository;
+            _outStockRepository = outStockRepository;
+            _batchInfoRepository = batchInfoRepository;
+            _StockInfoRepository = StockInfoRepository;
+            _LocationInfoRepository = LocationInfoRepository;
+            _unitOfWorkManage = unitOfWorkManage;
         }
 
         public Task Execute(IJobExecutionContext context)
         {
-           
+            //return Task.CompletedTask;
             bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
             if (flag && value != null)
             {
                 OtherDevice device = (OtherDevice)value;
+
                 try
                 {
-                    //Example
-                    //device.GetValue  璇诲彇
-                    //device.SetValue  鍐欏叆
-                    //_taskService.Repository; //浠撳偍灞傦紝杩涜鏁版嵁搴撹闂�
-                    OHTReadData oHTReadData = new OHTReadData();
-                    //todo:璇诲彇璁惧鏁版嵁锛�
+                    #region 鐢熸垚鍓旈櫎璐т綅鍏ュ簱浠诲姟
+                    //鍒ゆ柇鏁村舰鏈轰俊鍙�
+                    if(!OHTJob.oHTReadData.R_ZXJ_TC_isready&& !OHTJob.oHTReadData.R_TCMode_TC)
+                    {
+                        throw new Exception($"鏁村舰鏈烘姇鍏ヤ娇鐢ㄤ俊鍙蜂负false");
+                    }
+                    Dt_Task task = new Dt_Task();
+                    var station = _dt_stationInfoRepository.QueryFirst(v => v.msg == "鍓旈櫎鏋�");
+                    task.SourceAddress = station.Row + "-" + station.Column + "-1";
+                    var oldhtytask = _dt_taskRepositiry.QueryFirst(v => v.SourceAddress == task.SourceAddress);
+                    if (oldhtytask == null)
+                    {
+                        task.TargetAddress = _locationInfoService.GetInLocation(6).LocationCode;
+                        task.Grade = 1;
+                        task.Remark = (int)MateTypeEnum.ZiChan;
+                        task.NextAddress = "text";
+                        task.Roadway = "TC01";
+                        task.TaskType = (int)TaskInboundTypeEnum.Inbound;
+                        task.TaskState = (int)TaskInStatusEnum.InNew;
+                        task.PalletCode = "text";
+                        task.CurrentAddress = "text";
+                        task.WMSId = 2;
+                        _dt_taskRepositiry.AddData(task);
+                    }
 
-
-                    //todo:璁惧鐘舵�佹暟鎹彂閫佺粰鍓嶇
-                  
-
-                    
-                    //WriteInfo(device.DeviceName, "infoLog");
-
-                    //WriteDebug(device.DeviceName, "debugLog");
+                    #endregion
                 }
                 catch (Exception ex)
                 {
-                    WriteError(device.DeviceName, "閿欒", ex);
+                    _ErrormsginfoService.UpdateErrorMsg(ex.Message, 5);
+                }
+
+                try
+                {
+                    #region 鐢熸垚鍓旈櫎璐т綅鍑哄簱浠诲姟
+                    if (!OHTJob.oHTReadData.R_TCMode && !OHTJob.oHTReadData.R_TC_isready)
+                    {
+                        throw new Exception($"瑙勬暣鏈哄墧闄ゆ灦瀛愬彲鏀炬澘鎴栧墧闄や笂鏂欐ā寮忎俊鍙蜂负false");
+                    }
+                    //鏌ヨ褰撳墠浠诲姟姹犱腑鏄惁瀛樺湪鍑哄簱浠诲姟锛屽嚭搴撲换鍔″彧鑳藉瓨鍦ㄤ竴鏉�
+                    var oldtask = _dt_taskRepositiry.QueryFirst(v => v.TaskType == (int)TaskOutboundTypeEnum.Outbound);
+                    if (oldtask != null)
+                    {
+                        throw new Exception($"褰撳墠浠诲姟姹犱腑宸插瓨鍦ㄤ竴鏉″嚭搴撲换鍔�");
+                    }
+                    //鏌ヨ褰撳墠闇�瑕佸嚭搴撶殑鎵规鍙凤紝浠ュ強鍑哄簱鐗╂枡绫诲瀷
+                    var batch = _batchInfoRepository.QueryFirst(v => v.Id == 1);
+                    //鏌ヨ搴撳瓨鐗╂枡搴撳瓨淇℃伅
+                    var stocks = _StockInfoRepository.QueryData(v => v.Remark == 3 && 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);
+                    locaOne.LocationStatus = (int)LocationStatusEnum.Lock;
+                    stocks[0].StockStatus = 1;
+                    //鏌ヨ缁堢偣绔欏彴淇℃伅
+                    var station = _dt_stationInfoRepository.QueryFirst(v => v.msg == "瑗胯法鏋跺瓙");
+                    //寮�濮嬪垱寤轰换鍔�
+                    Dt_Task outtask = new Dt_Task();
+                    outtask.Roadway = "TC01";
+                    outtask.TaskType = (int)TaskOutboundTypeEnum.Outbound;
+                    outtask.TaskState = (int)TaskOutStatusEnum.OutNew;
+                    outtask.SourceAddress = stocks[0].LocationCode;
+                    outtask.TargetAddress = station.Row + "-" + station.Column + "-1";
+                    outtask.NextAddress = "text";
+                    outtask.Grade = 1;
+                    outtask.WMSId = 2;
+                    outtask.Remark = 3;
+                    outtask.PalletCode = "text";
+                    outtask.CurrentAddress = "text";
+
+                    _unitOfWorkManage.BeginTran();
+                    _LocationInfoRepository.UpdateData(locaOne);
+                    _dt_taskRepositiry.AddData(outtask);
+                    _StockInfoRepository.UpdateData(stocks[0]);
+                    _unitOfWorkManage.CommitTran();
+                    #endregion
+                }
+                catch (Exception ex)
+                {
+                    _ErrormsginfoService.UpdateErrorMsg(ex.Message, 6);
+                }
+
+                try
+                {
+                    #region 鐢熸垚鍏ュ簱浠诲姟
+                    
+
+                    //if (!OHTJob.oHTReadData.R_GZJ_isWork)
+                    //{
+                    //    throw new Exception($"瑙勬暣鏈烘姇鍏ヤ娇鐢ㄤ俊鍙蜂负false");
+                    //}
+                    var Inisout = _outStockRepository.QueryFirst(v => v.Id == 1);
+                    //鍏ュ簱
+                    if (Inisout.InOut==1)
+                    {
+                        Dt_Task task = new Dt_Task();
+                        var storagemode = _storagemodeRepository.QueryFirst(v => v.Id == 1);
+                        if (OHTJob.oHTReadData.R_RGVMode && OHTJob.oHTReadData.R_XK_isready)//RGV涓婃枡妯″紡锛屼笖涓滆法鏋跺瓙鏈変笂鏂欎俊鍙�
+                        {
+                            
+                            var station = _dt_stationInfoRepository.QueryFirst(v => v.msg == "瑗胯法鏋跺瓙");
+                            task.SourceAddress = station.Row + "-" + station.Column + "-1";
+                            var oldhtytask = _dt_taskRepositiry.QueryFirst(v => v.SourceAddress == task.SourceAddress);
+                            if (oldhtytask ==null) 
+                            {
+                                task.TargetAddress = _locationInfoService.GetInLocation(storagemode.storagemode).LocationCode;
+                                if (OHTJob.oHTReadData.R_DK_isready)
+                                {
+                                    task.Grade = 2;
+                                }
+                                else
+                                {
+                                    task.Grade = 1;
+                                }
+                                task.Remark = (int)MateTypeEnum.ZiChan;
+                                //鏌ユ壘鐩搁偦鐨勫簱浣�
+                                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";
+                                task.WMSId = 3;
+                                _dt_taskRepositiry.AddData(task);
+                            }
+                        }
+                        if (OHTJob.oHTReadData.R_RGVMode && OHTJob.oHTReadData.R_DK_isready)//RGV涓婃枡妯″紡锛屼笖瑗胯法鏋跺瓙鏈変笂鏂欎俊鍙�
+                        {
+                            var station = _dt_stationInfoRepository.QueryFirst(v => v.msg == "涓滆法鏋跺瓙");
+                            task.SourceAddress = station.Row + "-" + station.Column + "-1";
+                            var oldhtytask = _dt_taskRepositiry.QueryFirst(v => v.SourceAddress == task.SourceAddress);
+                            if (oldhtytask==null)
+                            {
+                                task.TargetAddress = _locationInfoService.GetInLocation(storagemode.storagemode).LocationCode;
+                                
+                                task.Grade = 1;
+                                task.Remark = (int)MateTypeEnum.ZiChan;
+                                //鏌ユ壘鐩搁偦鐨勫簱浣�
+                                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";
+                                task.WMSId = 3;
+                                _dt_taskRepositiry.AddData(task);
+                            }
+                        }
+                        if (OHTJob.oHTReadData.R_CCMode && OHTJob.oHTReadData.R_DK_isready)
+                        {
+                            var station = _dt_stationInfoRepository.QueryFirst(v => v.msg == "涓滆法鏋跺瓙");
+                            task.SourceAddress = station.Row + "-" + station.Column + "-1";
+                            var oldhtytask = _dt_taskRepositiry.QueryFirst(v => v.SourceAddress == task.SourceAddress);
+                            if (oldhtytask == null)
+                            {
+                                task.TargetAddress = _locationInfoService.GetInLocation(storagemode.storagemode).LocationCode;
+                                if (OHTJob.oHTReadData.R_XK_isready)
+                                {
+                                    task.Grade = 2;
+                                }
+                                else
+                                {
+                                    task.Grade = 1;
+                                }
+                                task.Remark = (int)MateTypeEnum.WaiGou;
+                                //鏌ユ壘鐩搁偦鐨勫簱浣�
+                                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";
+                                task.WMSId = 3;
+                                _dt_taskRepositiry.AddData(task);
+                            }
+                        }
+                        if (OHTJob.oHTReadData.R_CCMode && OHTJob.oHTReadData.R_XK_isready)
+                        {
+                            var station = _dt_stationInfoRepository.QueryFirst(v => v.msg == "瑗胯法鏋跺瓙");
+                            task.SourceAddress = station.Row + "-" + station.Column + "-1";
+                            var oldhtytask = _dt_taskRepositiry.QueryFirst(v => v.SourceAddress == task.SourceAddress);
+                            if (oldhtytask == null)
+                            {
+                                task.TargetAddress = _locationInfoService.GetInLocation(storagemode.storagemode).LocationCode;
+                                //var XKstation = _dt_stationInfoRepository.QueryFirst(v => v.msg == "涓滆法鏋跺瓙");
+                                //string address = XKstation.Row + "-" + XKstation.Column + "-1";
+                                //var oldtask = _dt_taskRepositiry.QueryFirst(v => v.SourceAddress == address);
+                                //if (oldtask != null && oldtask.TaskState == (int)TaskInStatusEnum.InNew)
+                                //{
+                                //    task.Grade = 2;
+                                //}
+                                //else
+                                //{
+                                //    task.Grade = 1;
+                                //}
+                                task.Grade = 1;
+                                task.Remark = (int)MateTypeEnum.WaiGou;
+                                //鏌ユ壘鐩搁偦鐨勫簱浣�
+                                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";
+                                task.WMSId = 3;
+                                _dt_taskRepositiry.AddData(task);
+                            }
+                        }
+                    }
+                    //鐩存帴鍑哄簱
+                    else if(Inisout.InOut == 2)
+                    {
+                        if (!OHTJob.oHTReadData.R_ZXJ_TCMode)
+                        {
+                            throw new Exception($"鏁村舰鏈轰笉灞炰簬澶╄溅涓婃枡妯″紡鎴栧ぉ杞︽斁鏉夸俊鍙蜂负false");
+                        }
+                        if (!OHTJob.oHTReadData.R_HC_isReadyWork)
+                        {
+                            throw new Exception($"鏁村舰鏈哄ぉ杞︽斁鏉夸俊鍙蜂负false");
+                        }
+                        Dt_Task outtask = new Dt_Task();
+                        //灏忚溅涓婃枡
+                        if (OHTJob.oHTReadData.R_RGVMode && OHTJob.oHTReadData.R_XK_isready )
+                        {
+                            var Stastation = _dt_stationInfoRepository.QueryFirst(v => v.msg == "瑗胯法鏋跺瓙");
+                            outtask.SourceAddress = Stastation.Row + "-" + Stastation.Column + "-1";
+
+                        }
+                        else if (OHTJob.oHTReadData.R_RGVMode && OHTJob.oHTReadData.R_DK_isready)
+                        {
+                            var Stastation = _dt_stationInfoRepository.QueryFirst(v => v.msg == "涓滆法鏋跺瓙");
+                            outtask.SourceAddress = Stastation.Row + "-" + Stastation.Column + "-1";
+                        }
+                        //浜哄伐涓婃枡
+                        else if (OHTJob.oHTReadData.R_CCMode && OHTJob.oHTReadData.R_DK_isready)
+                        {
+                            var Stastation = _dt_stationInfoRepository.QueryFirst(v => v.msg == "涓滆法鏋跺瓙");
+                            outtask.SourceAddress = Stastation.Row + "-" + Stastation.Column + "-1";
+                        }
+                        else if (OHTJob.oHTReadData.R_CCMode && OHTJob.oHTReadData.R_XK_isready)
+                        {
+                            var Stastation = _dt_stationInfoRepository.QueryFirst(v => v.msg == "瑗胯法鏋跺瓙");
+                            outtask.SourceAddress = Stastation.Row + "-" + Stastation.Column + "-1";
+                        }
+                        
+                        var Endstation = _dt_stationInfoRepository.QueryFirst(v => v.msg == "鏁村舰鏈烘斁鏂欎綅");
+                        //娣诲姞浠诲姟淇℃伅
+                        outtask.TargetAddress = Endstation.Row + "-" + Endstation.Column + "-1";
+                        outtask.Grade = 1;
+                        outtask.NextAddress = Endstation.Row + "-" + Endstation.Column + "-1";
+                        outtask.Roadway = "TC01";
+                        outtask.TaskType = (int)TaskOutboundTypeEnum.OutInventory;
+                        outtask.TaskState = (int)TaskOutStatusEnum.OutNew;
+                        outtask.WMSId = 3;
+                        outtask.PalletCode = "text";
+                        outtask.CurrentAddress = "text";
+                        //闃叉閲嶅浠诲姟
+                        var oldtask = _dt_taskRepositiry.QueryFirst(v => v.SourceAddress == outtask.SourceAddress &&v.TargetAddress== outtask.TargetAddress);
+                        if (oldtask == null) 
+                        {
+                            //鐢熸垚浠诲姟
+                            _dt_taskRepositiry.AddData(outtask);
+                        }
+                    }
+                    #endregion
+                }
+                catch (Exception ex)
+                {
+                    _ErrormsginfoService.UpdateErrorMsg(ex.Message, 2);
+                }
+
+                try
+                {
+                    #region 鐢熸垚鍑哄簱浠诲姟
+                    //if (!OHTJob.oHTReadData.R_ZXJ_isWork)
+                    //{
+                    //    throw new Exception($"鏁村舰鏈烘姇鍏ヤ娇鐢ㄤ俊鍙蜂负false");
+                    //}
+                    var isout = _outStockRepository.QueryFirst(v => v.Id == 1);
+                    if (isout.isout == 1)
+                    {
+                        if (!OHTJob.oHTReadData.R_ZXJ_TCMode )
+                        {
+                            throw new Exception($"鏁村舰鏈轰笉灞炰簬澶╄溅涓婃枡妯″紡鎴栧ぉ杞︽斁鏉夸俊鍙蜂负false");
+                        }
+                        if (!OHTJob.oHTReadData.R_HC_isReadyWork)
+                        {
+                            throw new Exception($"鏁村舰鏈哄ぉ杞︽斁鏉夸俊鍙蜂负false");
+                        }
+                        //鏌ヨ褰撳墠浠诲姟姹犱腑鏄惁瀛樺湪鍑哄簱浠诲姟锛屽嚭搴撲换鍔″彧鑳藉瓨鍦ㄤ竴鏉�
+                        var oldtask = _dt_taskRepositiry.QueryFirst(v => v.TaskType == (int)TaskOutboundTypeEnum.Outbound);
+                        if (oldtask != null)
+                        {
+                            throw new Exception($"褰撳墠浠诲姟姹犱腑宸插瓨鍦ㄤ竴鏉″嚭搴撲换鍔�");
+                        }
+                        //鏌ヨ褰撳墠闇�瑕佸嚭搴撶殑鎵规鍙凤紝浠ュ強鍑哄簱鐗╂枡绫诲瀷
+                        var batch = _batchInfoRepository.QueryFirst(v => v.Id == 1);
+                        //鏌ヨ搴撳瓨鐗╂枡搴撳瓨淇℃伅
+                        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 == "鏁村舰鏈烘斁鏂欎綅");
+                        //寮�濮嬪垱寤轰换鍔�
+                        Dt_Task outtask = new Dt_Task();
+                        outtask.Roadway = "TC01";
+                        outtask.TaskType = (int)TaskOutboundTypeEnum.Outbound;
+                        outtask.TaskState = (int)TaskOutStatusEnum.OutNew;
+                        outtask.SourceAddress = stocks[0].LocationCode;
+                        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);
+                }
+
+                
+                try
+                {
+                    #region 鐢熸垚澶╄溅绉诲姩浠诲姟
+                    if (!OHTJob.oHTReadData.R_ZXJ_isWork || !OHTJob.oHTReadData.R_HC_isReady)
+                    {
+                        throw new Exception($"鏁村舰鏈烘姇鍏ヤ娇鐢ㄤ俊鍙蜂负false鎴栬�呰杞﹀彲鍑嗗鍙栨澘涓篺alse");
+                    }
+                    //鏌ヨ褰撳墠闇�瑕佸嚭搴撶殑鎵规鍙凤紝浠ュ強鍑哄簱鐗╂枡绫诲瀷
+                    var batch = _batchInfoRepository.QueryFirst(v => v.Id == 1);
+                    //鏌ヨ搴撳瓨鐗╂枡搴撳瓨淇℃伅
+                    var stocks = _StockInfoRepository.QueryData(v => v.Remark == batch.materType && v.BatchNo == batch.OutBatch && v.StockStatus == 0)
+                        .OrderBy(v => v.CreateDate).ToList();
+                    
+                    //寮�濮嬪垱寤轰换鍔�
+                    Dt_Task outtask = new Dt_Task();
+                    outtask.Roadway = "TC01";
+                    outtask.TaskType = (int)TaskMoveEnum.Mowe;
+                    outtask.TaskState = (int)TaskMoveStatusEnum.OutNewMove;
+                    outtask.SourceAddress = "text";
+                    outtask.TargetAddress = stocks[0].LocationCode;
+                    outtask.NextAddress = "text";
+                    outtask.Grade = 1;
+                    outtask.WMSId = 3;
+                    outtask.Remark = batch.materType;
+                    outtask.PalletCode = "text";
+                    outtask.CurrentAddress = "text";
+                    _dt_taskRepositiry.AddData(outtask);
+                    #endregion
+                }
+                catch (Exception ex)
+                {
+                    _ErrormsginfoService.UpdateErrorMsg(ex.Message, 4);
                 }
             }
-
-
             return Task.CompletedTask;
         }
-
-
-        /// <summary>
-        /// 浠诲姟瀹炰綋杞崲鎴愬懡浠odel
-        /// </summary>
-        /// <param name="task">浠诲姟瀹炰綋</param>
-        /// <returns></returns>
-        /// <exception cref="Exception"></exception>
-        public OHTTaskCommand? ConvertToOHTTaskCommand([NotNull] Dt_Task task)
-        {
-            OHTTaskCommand oHtTaskCommand = new OHTTaskCommand();
-
-            oHtTaskCommand.W_Task_Type = 1;
-            oHtTaskCommand.W_Load_Layer = 0;
-            oHtTaskCommand.W_Pick_Line = 1;
-           
-            string[] SourceCodes = task.SourceAddress.Split("-");
-            if (SourceCodes.Length == 3)
-            {
-                oHtTaskCommand.W_Pick_Line = Convert.ToInt16(SourceCodes[1]);
-                oHtTaskCommand.W_Put_Column = Convert.ToInt16(SourceCodes[2]);
-                oHtTaskCommand.W_Put_Layer = Convert.ToInt16(SourceCodes[3]);
-            }
-            else
-            {
-                //鏁版嵁閰嶇疆閿欒
-                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"浠诲姟婧愬湴鍧�閰嶇疆閿欒锛�");
-                return null;
-            }
-            string[] targetCodes = task.TargetAddress.Split("-");
-            if (targetCodes.Length == 3)
-            {
-                oHtTaskCommand.W_Put_Line = Convert.ToInt16(targetCodes[1]);
-                oHtTaskCommand.W_Put_Column = Convert.ToInt16(targetCodes[2]);
-                oHtTaskCommand.W_Put_Layer = Convert.ToInt16(targetCodes[3]);
-            }
-            else
-            {
-                //鏁版嵁閰嶇疆閿欒
-                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"浠诲姟鐩爣鍦板潃閰嶇疆閿欒");
-                return null;
-            }
-            return oHtTaskCommand;
-        }
-
-
-        /// <summary>
-        /// 鑾峰彇浠诲姟
-        /// </summary>
-        /// <returns></returns>
-        private Dt_Task? GetTask()
-        {
-            Dt_Task task;
-            task = _taskService.QueryStackerCraneTask("R01");
-            return task;
-        }
-
-
     }
-
-
 }

--
Gitblit v1.9.3