From 9190b1eabf080af4e0d4d76d6e4ef127a12b1074 Mon Sep 17 00:00:00 2001 From: 肖洋 <cathay_xy@163.com> Date: 星期二, 10 十二月 2024 15:44:29 +0800 Subject: [PATCH] 12312312 --- Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs | 162 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 146 insertions(+), 16 deletions(-) diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs index 3caf61c..9e9e3ef 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs @@ -1,12 +1,16 @@ 锘� using AngleSharp.Io; +using log4net.Core; using Mapster; using Masuit.Tools; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; +using SixLabors.Fonts.Tables.AdvancedTypographic; using WIDESEA_Core.Const; using WIDESEA_DTO.MOM; using WIDESEA_DTO.WMS; using WIDESEA_IServices; using WIDESEA_IStoragIntegrationServices; +using WIDESEA_Model.Models; using WIDESEA_Services; using WIDESEA_StorageBasicRepository; using WIDESEAWCS_BasicInfoRepository; @@ -98,15 +102,20 @@ // 鏇存柊搴撳瓨鐘舵�佸拰浠诲姟鐘舵�� (var loc, var tas) = UpdateStockAndTaskStatus(stock, task); + var taskHty = task.Adapt<Dt_Task_Hty>(); // 浜嬪姟澶勭悊 await _unitOfWorkManage.UseTranAsync(async () => { + if (task.TaskType != (int)TaskOutboundTypeEnum.OutQuality) + { + await DeleteStockInfoAsync(stock.Id); + await DeleteStockInfoDetailsAsync(stock.StockInfoDetails); + } await UpdateLocationAsync(loc); - await DeleteStockInfoAsync(stock.Id); - await DeleteStockInfoDetailsAsync(stock.StockInfoDetails); //if (task.Roadway.Contains("FR") || task.Roadway.Contains("GW") || task.TaskType == (int)TaskOutboundTypeEnum.OutTray) //濡傛灉鏄垎瀹规垨楂樻俯鍑哄簱 灏嗕换鍔″垹闄� await DeleteTaskAsync(task.TaskId); + await AddTaskHtyAsync(taskHty); }); return content.OK("浠诲姟瀹屾垚鎴愬姛", task.Remark); @@ -165,7 +174,8 @@ TargetValue = parameterInfo.TargetValue, LowerLomit = parameterInfo.LowerSpecificationsLimit, UpperLimit = parameterInfo.UpperSpecificationsLimit, - DefectCode = defectCode + DefectCode = defectCode, + UOMCode = parameterInfo.UOMCode, } } }).ToList() @@ -225,6 +235,15 @@ if (!isTaskUpdated) { throw new Exception("浠诲姟淇℃伅鏇存柊澶辫触"); + } + } + + private async Task AddTaskHtyAsync(Dt_Task_Hty taskHty) + { + var isTaskAdd = await _task_HtyRepository.AddDataAsync(taskHty) > 0; + if (!isTaskAdd) + { + throw new Exception("鍘嗗彶浠诲姟淇℃伅娣诲姞澶辫触"); } } @@ -762,11 +781,32 @@ var stock = await QueryStockInfo(input.PalletCode); if (stock != null) { + Dt_Task taskNew = new Dt_Task + { + Grade = 1, + Roadway = stock.LocationInfo.RoadwayNo, + TargetAddress = stock.LocationInfo.RoadwayNo, + Dispatchertime = DateTime.Now, + MaterialNo = "", + NextAddress = stock.LocationInfo.RoadwayNo, + OrderNo = null, + PalletCode = stock.PalletCode, + SourceAddress = input.Position, + CurrentAddress = input.Position, + TaskState = (int)TaskInStatusEnum.InNew, + TaskType = (int)TaskInboundTypeEnum.InQuality, + TaskNum = BaseDal.GetTaskNo().Result, + Creater = "System", // 淇鎷煎啓閿欒 + CreateDate = DateTime.Now, + TaskId = 0, + }; + + var taskDTO = CreateTaskDTO(task); // TODO璐ㄦ鍥炲簱 } // 鏍规嵁浣嶇疆鏌ヨ鍖哄煙淇℃伅 - var area = await QueryAreaInfoByPosition(input.Position); + var area = await QueryAreaInfoByPosition(input.Position.Replace("-1", "")); if (area == null) { return content.Error("璇ョ偣浣嶄笉鍦ㄥ尯鍩熷垪琛ㄤ腑瀛樺湪"); @@ -780,7 +820,13 @@ var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString()); if (!result.Success) { - return content.Error(result.MOMMessage); + if (result.SerialNos.Count <= 0) + { + // 绌烘墭鐩樺叆搴撻�昏緫 + return await RequestTrayInTaskAsync(input); + } + else + return content.Error(result.MOMMessage); } // 澶勭悊寮傚父鐢佃姱鎯呭喌 @@ -790,11 +836,6 @@ return await HandleErrorCells(input, area, serialNosError); } - if (result.SerialNos.Count <= 0) - { - // 绌烘墭鐩樺叆搴撻�昏緫 - return await RequestTrayInTaskAsync(input); - } var boxing = CreateBoxingInfo(result, input.PalletCode); if (boxing == null) return content.Error("缁勭洏澶辫触"); @@ -937,15 +978,15 @@ /// <param name="areaCode">鍖哄煙缂栫爜</param> /// <param name="roadways">宸烽亾缂栫爜闆嗗悎</param> /// <returns>杩斿洖缁撴灉闆�</returns> - public async Task<WebResponseContent> RequestTrayOutTaskAsync(string position, int tag, string areaCode, List<string> roadways) + public async Task<WebResponseContent> RequestTrayOutTaskAsync(string position, int tag, string areaCode, string productionLine) { WebResponseContent content = new WebResponseContent(); try { // 鏍规嵁鎵樼洏绫诲瀷鏌ヨ搴撳瓨淇℃伅 DtStockInfo stockInfo = tag == (int)TaskOutboundTypeEnum.Outbound - ? QueryStockInfoForRealTrayAsync(areaCode, roadways).Result - : QueryStockInfoForEmptyTrayAsync(areaCode, roadways).Result; + ? QueryStockInfoForRealTrayAsync(areaCode, productionLine).Result + : QueryStockInfoForEmptyTrayAsync(areaCode).Result; if (stockInfo == null) { @@ -992,7 +1033,7 @@ /// <summary> /// 鏌ヨ瀹炵洏搴撳瓨淇℃伅 /// </summary> - private async Task<DtStockInfo> QueryStockInfoForRealTrayAsync(string areaCode, List<string> roadways) + private async Task<DtStockInfo> QueryStockInfoForRealTrayAsync(string areaCode, string productionLine) { var area = await _areaInfoRepository.QueryFirstAsync(x => x.AreaCode == areaCode); @@ -1000,6 +1041,7 @@ .Includes(x => x.LocationInfo) // 棰勫姞杞絃ocationInfo .Includes(x => x.StockInfoDetails) // 棰勫姞杞絊tockInfoDetails .Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) // 杩囨护鏉′欢 + .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID) // 杩囨护鏉′欢 .OrderBy(x => x.OutboundTime) // 鎺掑簭 .FirstAsync(); // 鑾峰彇绗竴涓厓绱� @@ -1013,7 +1055,7 @@ /// <summary> /// 鏌ヨ绌虹洏搴撳瓨淇℃伅 /// </summary> - private async Task<DtStockInfo> QueryStockInfoForEmptyTrayAsync(string areaCode, List<string> roadways) + private async Task<DtStockInfo> QueryStockInfoForEmptyTrayAsync(string areaCode) { var area = await _areaInfoRepository.QueryFirstAsync(x => x.AreaCode == areaCode); @@ -1049,7 +1091,7 @@ SourceAddress = stockInfo.LocationCode, CurrentAddress = stockInfo.LocationCode, TaskState = (int)TaskOutStatusEnum.OutNew, - TaskType = tag == (int)TaskOutboundTypeEnum.Outbound ? (int)TaskOutboundTypeEnum.Outbound : (int)TaskOutboundTypeEnum.OutTray, + TaskType = tag, TaskNum = BaseDal.GetTaskNo().Result, Creater = "System", // 淇鎷煎啓閿欒 CreateDate = DateTime.Now, @@ -1151,6 +1193,84 @@ content.Error(ex.Message); } return content; + } + + #endregion + + #region 鎸囧畾浠诲姟鍑哄簱 + + public async Task<WebResponseContent> CreateAndSendOutboundTask(string locationCode, string palletCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + // 鏌ヨ搴撳瓨淇℃伅 + var stockInfo = await _stockInfoRepository.QueryFirstNavAsync(x => x.LocationCode == locationCode && x.PalletCode == palletCode); + if (stockInfo == null) + { + return content.Error("鏈煡璇㈠埌瀵瑰簲鐨勫簱瀛樹俊鎭�"); + } + + var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode); + if (task != null) + { + return content.Error($"銆恵palletCode}銆戝凡瀛樺湪浠诲姟"); + } + + int taskType = 0; + if (stockInfo.IsFull) + taskType = (int)TaskOutboundTypeEnum.OutQuality; + else + taskType = (int)TaskOutboundTypeEnum.OutTray; + // 鍒涘缓骞舵坊鍔犱换鍔″埌鏁版嵁搴� + task = CreateTask(stockInfo, "1020-1", taskType); + //var taskId = await BaseDal.AddDataAsync(task); + //if (taskId <= 0) + //{ + // return content.Error("浠诲姟鍒涘缓澶辫触"); + //} + + // 鍒涘缓浠诲姟浼犺緭鐢ㄧ殑DTO瀵硅薄 + var taskDTO = CreateTaskDTO(task); + + // 鑾峰彇WMS IP鍦板潃鐢ㄤ簬鍙戦�佷换鍔¤姹� + var wmsIpAddress = GetWCSIpReceiveTask(); + if (wmsIpAddress == null) + { + throw new InvalidOperationException("WMS IP 鏈厤缃�"); + } + + var tasks = new List<WMSTaskDTO>() { taskDTO }; + // 鍙戦�佷换鍔¤姹傚埌WMS + var result = await HttpHelper.PostAsync(wmsIpAddress, tasks.ToJsonString()); + content = JsonConvert.DeserializeObject<WebResponseContent>(result); + if (content.Status) + { + // 娣诲姞浠诲姟鍒版暟鎹簱 + await BaseDal.AddDataAsync(task); + // 鏇存柊搴撳瓨浣嶇疆鐘舵�佷负涓嶅彲鐢� + stockInfo.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable; + await _locationRepository.UpdateDataAsync(stockInfo.LocationInfo); + } + } + catch (Exception ex) + { + Console.WriteLine($"鍙戠敓寮傚父: {ex.Message}"); + content.Error(ex.Message); + } + + return content; + } + private string GetWCSIpReceiveTask() + { + var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); + var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue; + var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveTask)?.ConfigValue; + if (wmsBase == null || ipAddress == null) + { + return null; + } + return wmsBase + ipAddress; } #endregion @@ -1448,6 +1568,16 @@ bool isResult = await BaseDal.UpdateDataAsync(task); return content.OK(data: task); } + else if (task.TaskType == (int)TaskInboundTypeEnum.InQuality) + { + var stockInfo = _stockInfoRepository.QueryFirst(x => x.PalletCode == input.PalletCode); + task.CurrentAddress = input.Position; + task.TargetAddress = stockInfo.LocationInfo.LocationCode; + task.NextAddress = stockInfo.LocationInfo.LocationCode; + task.TaskState = (int)TaskInStatusEnum.Line_InFinish; + bool isResult = await BaseDal.UpdateDataAsync(task); + return content.OK(data: task); + } else { var location = await GetLocationDistributeAsync(task.Roadway); -- Gitblit v1.9.3