From e3aaaa22a7cee2b7c7a33e98f843abc0cd15fb1b Mon Sep 17 00:00:00 2001
From: 刘磊 <1161824510@qq.com>
Date: 星期二, 05 八月 2025 13:36:12 +0800
Subject: [PATCH] 同步

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs |  173 +++++++++++++++++++++++++++++++++------------------------
 1 files changed, 99 insertions(+), 74 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs"
index 7340ca3..10fd331 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs"
@@ -1,11 +1,15 @@
 锘縰sing log4net.Core;
 using Masuit.Tools;
 using System.Collections.Generic;
+using WIDESEA_Comm.AGVTask;
+using WIDESEA_Comm.WCSInterface.Requst;
 using WIDESEA_Common;
 using WIDESEA_Core.Const;
 using WIDESEA_DTO.WMS;
+using WIDESEA_IStorageBasicRepository;
 using WIDESEA_StorageBasicRepository;
 using WIDESEA_StorageTaskRepository;
+using WIDESEA_StoragIntegrationServices;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob.Models;
 
@@ -19,83 +23,104 @@
     /// </summary>
     /// <param name="input">璇锋眰妯″瀷</param>
     /// <returns>鍖呭惈浠诲姟淇℃伅鐨勫搷搴斿唴瀹�</returns>
-    public async Task<WebResponseContent> RequestInTask(RequestTaskDto input)
+    public async Task<WebResponseContent> RequestInTask(SaveModel saveModel)
     {
         // 鍒涘缓涓�涓猈ebResponseContent瀵硅薄
         WebResponseContent content = new WebResponseContent();
         try
         {
+            string palletCode = saveModel.MainData["palletCode"].ToString();
+            string station = saveModel.MainData["station"].ToString();
+
             // 璋冪敤BaseDal.QueryFirstAsync鏂规硶锛屾煡璇换鍔�
-            var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == input.PalletCode);
+            var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode);
             if (task != null)
             {
-                {
-                    WMSTaskDTO taskDTO = CreateTaskDTO(task);
-                    return content.OK(data: taskDTO);
-                }
+                throw new Exception($"鎵樼洏{palletCode}宸插瓨鍦ㄤ换鍔�");
             }
 
-            //鏌ヨ鍒涘缓鐨勮溅杞俊鎭�
-            //var inWheelsInfo = _InWheels_MesRepository.QueryFirst(x => x.Wheels_CurrentStatue == "0");
+            var stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == station);
+            if (stationInfo == null)
+            {
+                throw new Exception($"绔欏彴{station}涓嶅瓨鍦�");
+            }
 
-            //鏌ヨ鍒涘缓鐨勫埗鍔ㄧ洏淇℃伅
-            //var inBrakeInfo = _InWheels_MesRepository.QueryFirst(x => x.Wheels_CurrentStatue == "0");
-            //if (inBrakeInfo == null) throw new Exception("褰撳墠鏃犺溅杞垨鍒跺姩鐩樺叆搴撲俊鎭�");
+            var boxingInfo = _boxingInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
+            if (boxingInfo == null)
+            {
+                throw new Exception($"鎵樼洏{palletCode}缁勭洏淇℃伅涓嶅瓨鍦�");
+            }
+            if (boxingInfo.CurrentStatue != 1)
+            {
+                throw new Exception($"鎵樼洏{palletCode}褰撳墠鐘舵�佷笉鍏佽鍏ュ簱");
+            }
+            // 鑾峰彇搴撲綅
+            var location = RequestLocation(stationInfo.Roadway);
+            if (location == null)
+            {
+                return content.Error("鏃犳硶鑾峰彇璐т綅淇℃伅鎴栧簱浣嶅凡婊�");
+            }
 
-            //if (inWheelsInfo == null /*&& inBrakeInfo == null*/) throw new Exception("褰撳墠鏃犺溅杞垨鍒跺姩鐩樺叆搴撲俊鎭�");
-
+            string agvId = Guid.NewGuid().ToString().Replace("-", "").Take(16);
             var newtask = new Dt_Task
             {
-                CurrentAddress = input.Position,
+                CurrentAddress = station,
                 Grade = 1,
-                Roadway = input.Roadways,
-                TargetAddress = input.Roadways,
+                Roadway = stationInfo.Roadway,
+                TargetAddress = location.LocationCode,
                 Dispatchertime = DateTime.Now,
                 MaterialNo = "",
-                NextAddress = input.Roadways,
+                NextAddress = stationInfo.Roadway,
                 OrderNo = null,
-                PalletCode = "",
-                SourceAddress = input.Position,
+                PalletCode = palletCode,
+                SourceAddress = stationInfo.stationLocation,
                 TaskState = (int)TaskInStatusEnum.InNew,
-                TaskType = (int)TaskInboundTypeEnum.InWheels,  //inWheelsInfo == null ? (int)TaskInboundTypeEnum.InBrake :
+                TaskType = (int)TaskInboundTypeEnum.Inbound,
                 TaskNum = await BaseDal.GetTaskNo(),
-                Creater = "Systeam"
+                Creater = "Systeam",
+                AGVtaskId = agvId,
             };
 
             // 灏濊瘯娣诲姞鏂颁换鍔�
-            if (newtask == null) return content.Error();
-            var taskId = await BaseDal.AddDataAsync(newtask);
-            bool isResult = taskId > 0;
-            if (isResult)
+            addtask schedulingTask = new addtask
             {
-                // 鍒涘缓WMS浠诲姟
-                WMSTaskDTO taskDTO = new WMSTaskDTO()
-                {
-                    TaskNum = newtask.TaskNum.Value,
-                    Grade = newtask.Grade.Value,
-                    PalletCode = newtask.PalletCode,
-                    RoadWay = newtask.Roadway,
-                    SourceAddress = newtask.SourceAddress,
-                    TargetAddress = newtask.TargetAddress,
-                    TaskState = newtask.TaskState.Value,
-                    Id = 0,
-                    TaskType = newtask.TaskType,
-                };
+                task_id = newtask.AGVtaskId,
+                task_type = newtask.TaskType == (int)TaskTypeEnum.Inbound ? "push" : "pop",
+                work_begin = newtask.SourceAddress,
+                work_end = newtask.TargetAddress
+            };
 
-                //inWheelsInfo.Wheels_CurrentStatue = "1";
-                //_InWheels_MesRepository.UpdateData(inWheelsInfo);
+            string address = AGV_Interface + "add_task";
 
-                content.OK(data: taskDTO);
+            string result = HttpsClient.PostAsync(address, schedulingTask.ToDictionary()).Result;
+
+            content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+
+            if (content.ack != 0)
+            {
+                Console.WriteLine($"璇锋眰RCS寮傚父锛歿content.msg}");
+                LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"\r\r--------------------------------------");
+                LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"璇锋眰鍙傛暟锛歿schedulingTask.ToJsonString()}");
+                LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"鍝嶅簲鍙傛暟锛歿content.ToJsonString()}");
+                throw new Exception(content.msg);
             }
-            else
-                content.Error("娣诲姞浠诲姟澶辫触");
-            return content;
+            _unitOfWorkManage.BeginTran();
+
+            BaseDal.AddData(newtask);
+            location.LocationStatus = (int)LocationEnum.InStockDisable;
+            _locationRepository.UpdateData(location);
+            boxingInfo.CurrentStatue = 3;
+            _boxingInfoRepository.UpdateData(boxingInfo);
+            _unitOfWorkManage.CommitTran();
+
+            content.OK("鐢宠鍏ュ簱鎴愬姛锛氳绛夊緟AGV鍙栨枡");
         }
-        catch (Exception err)
+        catch (Exception er)
         {
+            _unitOfWorkManage.RollbackTran();
             // 濡傛灉鍙戠敓寮傚父锛屽垯璋冪敤content.Error鏂规硶锛岃褰曢敊璇俊鎭紝骞惰緭鍑洪敊璇俊鎭�
-            content.Error(err.Message);
-            Console.WriteLine(err.Message);
+            content.Error($"鍏ュ簱鐢宠澶辫触锛歿er.Message}");
+            Console.WriteLine(er.Message);
         }
         // 杩斿洖content
         return content;
@@ -111,40 +136,19 @@
     /// <param name="requestTask"></param>
     /// <param name="locationInfos"></param>
     /// <returns></returns>
-    public DtLocationInfo RequestLocation(RequestTaskDto requestTask, List<DtLocationInfo> locationInfos = null)
+    public DtLocationInfo RequestLocation(string roadwayNo)
     {
         lock (objLOCK)
         {
             try
             {
-                //List<DtLocationInfo> locations = new List<DtLocationInfo>();
-                if (locationInfos == null || locationInfos.Count == 0)
-                {
-                    locationInfos = _locationRepository.QueryData(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == "SC1" && x.EnalbeStatus == 1 && x.LocationType == 1);
-                }
+                List<DtLocationInfo> locations = new List<DtLocationInfo>();
+                locations = _locationRepository.QueryData(x => x.RoadwayNo == roadwayNo && x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1);   //&& x.LocationType == 1
 
-                var location = GetEmptyLocation(locationInfos);
-
-                if (location != null)
-                {
-                    if (location.Depth == 2)
-                    {
-                        int row = location.Row;
-                        int relativeLine = row % 2 == 1 ? row + 1 : row - 1;
-
-                        var insideLocation = _locationRepository.QueryFirst(x => x.Row == relativeLine && x.Layer == location.Layer && x.Column == location.Column);
-
-                        if (insideLocation.LocationStatus != (int)LocationEnum.Free /*|| insideLocation.EnalbeStatus ==*/ )
-                        {
-                            locationInfos.Remove(location);
-                            if (locationInfos.Count == 0) return null;
-                            RequestLocation(requestTask, locationInfos);
-                        }
-                    }
-                }
+                var location = GetEmptyLocation(locations);
                 if (location == null)
                 {
-                    return null;
+                    throw new Exception("搴撲綅宸叉弧");
                 }
                 return location;
             }
@@ -159,7 +163,7 @@
 
     private DtLocationInfo GetEmptyLocation(List<DtLocationInfo> dtLocationInfos)
     {
-        var locationinfo = dtLocationInfos.Where(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == "SC1" && x.EnalbeStatus == 1 && x.LocationType == 1).OrderBy(x => x.Layer).ThenByDescending(x => x.Depth).ThenBy(x => x.Row).ThenBy(x => x.Column).FirstOrDefault();
+        var locationinfo = dtLocationInfos.Where(x => x.LocationStatus == (int)LocationEnum.Free && x.EnalbeStatus == 1).OrderBy(x => x.Layer).ThenByDescending(x => x.Depth).ThenBy(x => x.Row).ThenBy(x => x.Column).FirstOrDefault();
 
         return locationinfo;
     }
@@ -167,4 +171,25 @@
     #endregion 鑾峰彇璐т綅
     #endregion 搴撲綅鍒嗛厤
 
+    public WebResponseContent confirmTask(int taskNum)
+    {
+        WebResponseContent content = new WebResponseContent();
+        try
+        {
+            var taskInfo = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+            if (taskInfo != null)
+            {
+                BaseDal.DeleteData(taskInfo);
+            }
+
+            content.OK("纭瀹屾垚");
+        }
+        catch (Exception ex)
+        {
+            content.Error($"纭寮傚父:{ex.Message}");
+        }
+
+        return content;
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3