From 53db158b8018fba144a937cf1749cce050855c7a Mon Sep 17 00:00:00 2001
From: 刘磊 <1161824510@qq.com>
Date: 星期二, 10 十二月 2024 14:49:32 +0800
Subject: [PATCH] 同步

---
 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/RequestChangeLocation.cs |  313 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 254 insertions(+), 59 deletions(-)

diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/RequestChangeLocation.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/RequestChangeLocation.cs
index 7efa91a..fde21c1 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/RequestChangeLocation.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/RequestChangeLocation.cs
@@ -1,4 +1,7 @@
-锘縰sing Newtonsoft.Json;
+锘縰sing AngleSharp.Dom;
+using log4net.Core;
+using Masuit.Tools;
+using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -6,7 +9,9 @@
 using System.Threading.Tasks;
 using WIDESEA_Common;
 using WIDESEA_Core;
+using WIDESEA_Core.Const;
 using WIDESEA_Core.Enums;
+using WIDESEA_Core.Helper;
 using WIDESEA_DTO;
 using WIDESEA_DTO.WMS;
 using WIDESEA_Model.Models;
@@ -25,7 +30,7 @@
             WebResponseContent content = new WebResponseContent();
             try
             {
-                if (string.IsNullOrEmpty(json.ToString())) throw new Exception("涓婁紶鍙傛暟涓虹┖");
+                if (string.IsNullOrEmpty(json.ToString())) throw new Exception("璇锋眰鍙傛暟涓虹┖");
 
                 var result = JsonConvert.DeserializeObject<RequestReMove>(json.ToString());
 
@@ -33,72 +38,262 @@
 
                 if (location == null) throw new Exception("鏈煡搴撲綅");
 
-                if (result.MoveType == 5)
+                if (_taskRepository.QueryFirst(x => x.SourceAddress == result.LocationID && x.Roadway == location.RoadwayNo) != null)
                 {
-                    Console.WriteLine($"鍒嗗妫�娴嬫煖鐏瑙﹀彂:搴撲綅{result.LocationID}");
-
-                    //鏌ユ壘娑堥槻绔欏彴
-                    var station = _stationManagerRepository.QueryFirst(t => t.Roadway == location.RoadwayNo
-                         && t.stationType == (int)StationManager.FireStation
-                         /*&& t. == "Enable"*/);
-                    if (station == null)
-                    {
-                        throw new Exception("娑堥槻绔欏彴鏈厤缃�!");
-                    }
-                    //鏌ユ壘搴撳瓨淇℃伅
-                    var barcodeData = _stockInfoRepository.QueryFirst(t => t.LocationCode == location.LocationCode);
-                    //鎵樼洏鐮�
-                    string barcode = string.Empty;
-                    if (barcodeData != null)
-                    {
-                        barcode = barcodeData.PalletCode;
-                    }
-                    else
-                    {
-                        //鏃犲簱瀛樹俊鎭紝鐢熸垚闅忔満鎵樼洏鐮�
-                        barcode = "M" + DateTime.Now.ToString("MMddHHmmss") + "-" + new Random().Next(100, 1000);
-                    }
-                    int taskNum = _taskRepository.GetTaskNo().Result;
-                    Dt_Task task = new Dt_Task
-                    {
-                        CreateDate = DateTime.Now,
-                        Creater = "HK",
-                        CurrentAddress = result.LocationID,
-                        Grade = 1,
-                        Dispatchertime = DateTime.Now,
-                        PalletCode = result.PalletBarcode,
-                        Roadway = location.RoadwayNo,
-                        SourceAddress = result.LocationID,
-                        TaskState = (int)TaskOutStatusEnum.OutNew,
-                        TaskType = 500,
-                        TargetAddress = station.stationLocation,
-                        NextAddress = station.stationChildCode,
-                        TaskNum = taskNum, //_taskRepository.GetTaskNo().Result,
-                        TaskId = 0,
-                    };
-
-                    // 灏濊瘯娣诲姞鏂颁换鍔�
-                    WMSTaskDTO taskDTO = new WMSTaskDTO()
-                    {
-                        TaskNum = task.TaskNum.Value,
-                        Grade = 1,
-                        PalletCode = task.PalletCode,
-                        RoadWay = task.Roadway,
-                        SourceAddress = task.SourceAddress,
-                        TargetAddress = task.TargetAddress,
-                        TaskState = task.TaskState.Value,
-                        Id = 0,
-                        TaskType = 500,
-                    };
+                    throw new Exception("褰撳墠搴撲綅宸插瓨鍦ㄤ换鍔�");
                 }
+
+                switch (result.MoveType)
+                {
+                    case 1:
+                        CreateMoveTask(location);
+                        break;
+                    case 5:
+                        CreateFireTask(location);
+                        break;
+                    default:
+                        throw new Exception("鏃犳晥鐨勭Щ搴撶敵璇风被鍨�");
+                }
+
+                #region 鐏鍑哄簱
+                //if (result.MoveType == 5)
+                //{
+                //    Console.WriteLine($"鍒嗗妫�娴嬫煖鐏瑙﹀彂:搴撲綅{result.LocationID}");
+
+                //    //鏌ユ壘娑堥槻绔欏彴
+                //    var station = _stationManagerRepository.QueryFirst(t => t.Roadway == location.RoadwayNo
+                //         && t.stationType == (int)StationManager.FireStation
+                //         /*&& t. == "Enable"*/);
+                //    if (station == null)
+                //    {
+                //        throw new Exception("娑堥槻绔欏彴鏈厤缃�!");
+                //    }
+                //    //鏌ユ壘搴撳瓨淇℃伅
+                //    var barcodeData = _stockInfoRepository.QueryFirst(t => t.LocationCode == location.LocationCode);
+                //    //鎵樼洏鐮�
+                //    string barcode = string.Empty;
+                //    if (barcodeData != null)
+                //    {
+                //        barcode = barcodeData.PalletCode;
+                //    }
+                //    else
+                //    {
+                //        //鏃犲簱瀛樹俊鎭紝鐢熸垚闅忔満鎵樼洏鐮�
+                //        barcode = "M" + DateTime.Now.ToString("MMddHHmmss") + "-" + new Random().Next(100, 1000);
+                //    }
+                //    int taskNum = _taskRepository.GetTaskNo().Result;
+                //    Dt_Task task = new Dt_Task
+                //    {
+                //        CreateDate = DateTime.Now,
+                //        Creater = "HK",
+                //        CurrentAddress = result.LocationID,
+                //        Grade = 1,
+                //        Dispatchertime = DateTime.Now,
+                //        PalletCode = barcode,
+                //        Roadway = location.RoadwayNo,
+                //        SourceAddress = result.LocationID,
+                //        TaskState = (int)TaskOutStatusEnum.OutNew,
+                //        TaskType = 500,
+                //        TargetAddress = station.stationLocation,
+                //        NextAddress = station.stationChildCode,
+                //        TaskNum = taskNum, //_taskRepository.GetTaskNo().Result,
+                //        TaskId = 0,
+                //    };
+
+                //    // 灏濊瘯娣诲姞鏂颁换鍔�
+                //    WMSTaskDTO taskDTO = new WMSTaskDTO()
+                //    {
+                //        TaskNum = task.TaskNum.Value,
+                //        Grade = 1,
+                //        PalletCode = task.PalletCode,
+                //        RoadWay = task.Roadway,
+                //        SourceAddress = task.SourceAddress,
+                //        TargetAddress = task.TargetAddress,
+                //        TaskState = task.TaskState.Value,
+                //        Id = 0,
+                //        TaskType = 500,
+                //    };
+                //} 
+                #endregion
+
                 LogFactory.GetLog("鍒嗗绉诲簱鐢宠").Info(true, $"\r\r--------------------------------------");
-                LogFactory.GetLog("鍒嗗绉诲簱鐢宠").Info(true, result);
+                LogFactory.GetLog("鍒嗗绉诲簱鐢宠").Info(true, result.ToJsonString());
                 return content.OK();
             }
             catch (Exception ex)
             {
+                LogFactory.GetLog("鍒嗗绉诲簱鐢宠").Info(true, $"\r\r--------------------------------------");
+                LogFactory.GetLog("鍒嗗绉诲簱鐢宠").Info(true, ex.Message);
                 return content.Error(ex.Message);
             }
         }
+
+        private void CreateMoveTask(DtLocationInfo location)
+        {
+            Console.WriteLine($"鍒嗗鐢宠绉诲簱:搴撲綅{location.LocationCode}");
+
+            //鏌ユ壘鍙敤搴撲綅
+            DtLocationInfo CanRelocation = _locationRepository.QueryFirst(x => x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo == location.RoadwayNo && x.EnalbeStatus == 1 && x.LocationType == 2 && x.Remark == "1");
+
+            if (CanRelocation == null) throw new Exception("鐢宠绉诲簱澶辫触锛氭棤鍙敤搴撲綅");
+
+            //鏌ユ壘搴撳瓨淇℃伅
+            var stockInfo = _stockInfoRepository.QueryFirst(t => t.LocationCode == location.LocationCode);
+
+            if (stockInfo == null) throw new Exception("鐢宠绉诲簱澶辫触锛氭棤搴撳瓨璁板綍");
+
+            //淇敼绉诲簱鐩爣搴撲綅鐘舵��
+            CanRelocation.LocationStatus = (int)LocationEnum.FreeDisable;
+
+            int taskNum = _taskRepository.GetTaskNo().Result;
+            Dt_Task task = new Dt_Task
+            {
+                CreateDate = DateTime.Now,
+                Creater = "HK",
+                CurrentAddress = location.LocationCode,
+                Grade = 1,
+                Dispatchertime = DateTime.Now,
+                PalletCode = stockInfo.PalletCode,
+                Roadway = location.RoadwayNo,
+                SourceAddress = location.LocationCode,
+                TaskState = (int)TaskStatus.Created,
+                TaskType = (int)TaskRelocationTypeEnum.Relocation,
+                TargetAddress = CanRelocation.LocationCode,
+                NextAddress = CanRelocation.LocationCode,
+                TaskNum = taskNum, //_taskRepository.GetTaskNo().Result,
+                TaskId = 0,
+            };
+
+            // 灏濊瘯娣诲姞鏂颁换鍔�
+            WMSTaskDTO taskDTO = new WMSTaskDTO()
+            {
+                TaskNum = task.TaskNum.Value,
+                Grade = 1,
+                PalletCode = task.PalletCode,
+                RoadWay = task.Roadway,
+                SourceAddress = task.SourceAddress,
+                TargetAddress = task.TargetAddress,
+                TaskState = task.TaskState.Value,
+                Id = 0,
+                TaskType = task.TaskType,
+            };
+
+            var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
+            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue;
+            var ReceiveByWMSTask = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveByWMSTask)?.ConfigValue;
+            if (ReceiveByWMSTask == null || ipAddress == null)
+            {
+                throw new Exception("WMS IP 鏈厤缃�");
+            }
+            var wmsIpAddrss = ipAddress + ReceiveByWMSTask;
+
+            var respon = HttpHelper.Post(wmsIpAddrss, JsonConvert.SerializeObject(taskDTO));   //http://localhost:9291/api/Task/ReceiveTask,
+            if (respon != null)
+            {
+                WebResponseContent respone = JsonConvert.DeserializeObject<WebResponseContent>(respon.ToString());
+                if (respone.Status)
+                {
+                    //娣诲姞WMS浠诲姟 骞朵慨鏀瑰簱浣嶇姸鎬�
+                    var taskId = _taskRepository.AddData(task);
+                    _locationRepository.UpdateData(CanRelocation);
+                }
+                else
+                {
+                    throw new Exception("WCS澶勭悊澶辫触:" + respone.Message);
+                }
+            }
+            else
+            {
+                throw new Exception("WCS澶勭悊澶辫触");
+            }
+        }
+
+
+        private void CreateFireTask(DtLocationInfo location)
+        {
+            Console.WriteLine($"鍒嗗妫�娴嬫煖鐏瑙﹀彂:搴撲綅{location.LocationCode}");
+
+            //鏌ユ壘娑堥槻绔欏彴
+            var station = _stationManagerRepository.QueryFirst(t => t.Roadway == location.RoadwayNo
+                 && t.stationType == (int)StationManager.FireStation
+                 /*&& t. == "Enable"*/);
+            if (station == null)
+            {
+                throw new Exception("娑堥槻绔欏彴鏈厤缃�!");
+            }
+            //鏌ユ壘搴撳瓨淇℃伅
+            var barcodeData = _stockInfoRepository.QueryFirst(t => t.LocationCode == location.LocationCode);
+            //鎵樼洏鐮�
+            string barcode = string.Empty;
+            if (barcodeData != null)
+            {
+                barcode = barcodeData.PalletCode;
+            }
+            else
+            {
+                //鏃犲簱瀛樹俊鎭紝鐢熸垚闅忔満鎵樼洏鐮�
+                barcode = "M" + DateTime.Now.ToString("MMddHHmmss") + "-" + new Random().Next(100, 1000);
+            }
+            int taskNum = _taskRepository.GetTaskNo().Result;
+            Dt_Task task = new Dt_Task
+            {
+                CreateDate = DateTime.Now,
+                Creater = "HK",
+                CurrentAddress = location.LocationCode,
+                Grade = 1,
+                Dispatchertime = DateTime.Now,
+                PalletCode = barcode,
+                Roadway = location.RoadwayNo,
+                SourceAddress = location.LocationCode,
+                TaskState = (int)TaskOutStatusEnum.OutNew,
+                TaskType = 500,
+                TargetAddress = station.stationLocation,
+                NextAddress = station.stationChildCode,
+                TaskNum = taskNum, //_taskRepository.GetTaskNo().Result,
+                TaskId = 0,
+            };
+
+            // 灏濊瘯娣诲姞鏂颁换鍔�
+            WMSTaskDTO taskDTO = new WMSTaskDTO()
+            {
+                TaskNum = task.TaskNum.Value,
+                Grade = 1,
+                PalletCode = task.PalletCode,
+                RoadWay = task.Roadway,
+                SourceAddress = task.SourceAddress,
+                TargetAddress = task.TargetAddress,
+                TaskState = task.TaskState.Value,
+                Id = 0,
+                TaskType = 500,
+            };
+
+            var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
+            var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue;
+            var ReceiveByWMSTask = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveByWMSTask)?.ConfigValue;
+            if (ReceiveByWMSTask == null || ipAddress == null)
+            {
+                throw new Exception("WMS IP 鏈厤缃�");
+            }
+            var wmsIpAddrss = ipAddress + ReceiveByWMSTask;
+
+            var respon = HttpHelper.Post(wmsIpAddrss, JsonConvert.SerializeObject(taskDTO));   //http://localhost:9291/api/Task/ReceiveTask,
+            if (respon != null)
+            {
+                WebResponseContent respone = JsonConvert.DeserializeObject<WebResponseContent>(respon.ToString());
+                if (respone.Status)
+                {
+                    var taskId = _taskRepository.AddData(task);
+                }
+
+                else
+                {
+                    throw new Exception("WCS澶勭悊澶辫触:" + respone.Message);
+                }
+            }
+            else
+            {
+                throw new Exception("WCS澶勭悊澶辫触");
+            }
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3