From fdf7bb595ee00e5fef7b4e110fbe32f637c069f6 Mon Sep 17 00:00:00 2001 From: wangxinhui <wangxinhui@hnkhzn.com> Date: 星期一, 18 八月 2025 08:38:46 +0800 Subject: [PATCH] 1 --- 项目代码/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs | 318 +++++++++++++++++++++++++++++++++------------------- 1 files changed, 203 insertions(+), 115 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs" index bd50d60..16142da 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs" @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Reflection.Metadata; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -189,15 +190,15 @@ } string roadwayNo = ""; - if (stockInfo.MaterielWide < 2200 && stockInfo.MaterielThickness > 800) + if (stockInfo.MaterielThickness > 800) { - List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationType == LocationTypeEnum.Undefined.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("SC01_YL")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList(); - roadwayNo = locationCounts.OrderBy(x => x.Count).FirstOrDefault()?.RoadwayNo ?? ""; - } - else if (stockInfo.MaterielWide>2200 && stockInfo.MaterielThickness>800) - { - List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationType == LocationTypeEnum.Undefined.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && !x.RoadwayNo.Contains("SC01_YL")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList(); - roadwayNo = locationCounts.OrderBy(x => x.Count).FirstOrDefault()?.RoadwayNo ?? ""; + List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationType == LocationTypeEnum.Undefined.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("YL")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList(); + roadwayNo = locationCounts.OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? ""; + if (stockInfo.MaterielWide > 2200) + { + locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationType == LocationTypeEnum.Undefined.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && !x.RoadwayNo.Contains("SC01_YL")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList(); + roadwayNo = locationCounts.OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? ""; + } } return !string.IsNullOrEmpty(roadwayNo) ? (roadwayNo) : throw new Exception("鏈壘鍒板彲鍒嗛厤宸烽亾"); } @@ -207,6 +208,80 @@ throw new Exception(ex.Message); } } + /// <summary> + /// 鍏ュ簱瀹屾垚 + /// </summary> + public WebResponseContent InboundTaskCompleted(Dt_Task task) + { + try + { + Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == task.WarehouseId); + if (warehouse.WarehouseCode == WarehouseEnum.LLDCP.ToString()) //鎴愬搧瀹屾垚 + { + Dt_LocationInfo locationInfoEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); + if (locationInfoEnd == null) + { + return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅"); + } + Dt_AGVStationInfo agvstation = _agvStationInfoRepository.QueryFirst(x => x.AGVStationCode == task.SourceAddress && x.StationArea == AGVStationAreaEnum.AreaA.ObjToInt()); + if (agvstation != null) + { + agvstation.IsOccupied = WhetherEnum.False.ObjToInt(); + } + Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode); + if (proStockInfo != null && proStockInfo.StockStatus == StockStatusEmun.MES绌烘墭閫�搴�.ObjToInt()) + { + task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); + _unitOfWorkManage.BeginTran(); + if (agvstation != null) + { + _agvStationInfoRepository.UpdateData(agvstation); + } + proStockInfo.LocationCode = locationInfoEnd.LocationCode; + proStockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt(); + _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo); + _basicService.LocationInfoService.UpdateLocationStatus(locationInfoEnd, proStockInfo.PalletType, LocationStatusEnum.InStock, proStockInfo.WarehouseId); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.浜哄伐瀹屾垚 : WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚); + _unitOfWorkManage.CommitTran(); + } + else + { + return WebResponseContent.Instance.Error($"鏈壘鍒板搴斿簱瀛樹俊鎭�"); + } + } + else//鍘熸枡搴撳畬鎴� + { + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode); + if (stockInfo == null) + { + return WebResponseContent.Instance.Error($"鏈壘鍒板搴斿簱瀛樹俊鎭�"); + } + Dt_LocationInfo locationInfoEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); + if (locationInfoEnd == null) + { + return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅"); + } + task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); + _unitOfWorkManage.BeginTran(); + stockInfo.LocationCode = locationInfoEnd.LocationCode; + stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt(); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + _basicService.LocationInfoService.UpdateLocationStatus(locationInfoEnd, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.浜哄伐瀹屾垚 : WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚); + _unitOfWorkManage.CommitTran(); + } + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } + } + /// <summary> + /// 鍒嗛厤鎴愬搧宸烽亾 + /// </summary> + /// <returns></returns> public string AssignCPRoadwayNo() { try @@ -219,7 +294,20 @@ string roadwayNo = ""; List<LocationCount> locationCounts = Db.Queryable<Dt_LocationInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId && x.LocationType == LocationTypeEnum.Undefined.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && x.RoadwayNo.Contains("CP")).GroupBy(x => x.RoadwayNo).Select(x => new LocationCount { RoadwayNo = x.RoadwayNo, Count = SqlFunc.AggregateCount(x) }).ToList(); - roadwayNo = locationCounts.OrderBy(x => x.Count).FirstOrDefault()?.RoadwayNo ?? ""; + + //鑾峰彇褰撳墠鍏ュ簱浠诲姟涓凡鍒嗛厤宸烽亾浠诲姟鏁伴噺 + List<LocationCount> useLocationCounts = Db.Queryable<Dt_Task>().Where(x => x.WarehouseId == warehouse.WarehouseId + && locationCounts.Select(j=>j.RoadwayNo).Contains(x.Roadway) + && TaskInboundTypes.Contains(x.TaskType)).GroupBy(x => x.Roadway).Select(x => new LocationCount { RoadwayNo = x.Roadway, Count = SqlFunc.AggregateCount(x) }).ToList(); + foreach (var item in locationCounts) + { + LocationCount? count = useLocationCounts.FirstOrDefault(x => x.RoadwayNo == item.RoadwayNo); + if (count!=null) + { + item.Count -= count.Count; + } + } + roadwayNo = locationCounts.OrderByDescending(x => x.Count).FirstOrDefault()?.RoadwayNo ?? ""; return !string.IsNullOrEmpty(roadwayNo) ? (roadwayNo) : throw new Exception("鏈壘鍒板彲鍒嗛厤宸烽亾"); } catch (Exception ex) @@ -337,112 +425,112 @@ /// <param name="barCode"></param> /// <param name="startPoint"></param> /// <returns></returns> - public WebResponseContent BackProductTask(string barCode, string startPoint) - { - WebResponseContent content = new WebResponseContent(); - try - { - string palletCode = @"^C\d{5}$"; // 姝e垯琛ㄨ揪寮� - bool isValid = Regex.IsMatch(barCode, palletCode); - if (!isValid) - { - return content.Error($"妗嗙爜鏍煎紡閿欒{barCode}"); - } - if (!OutStartPonits.Contains(startPoint)) - { - return content.Error($"璧风偣閿欒{startPoint}"); - } - //鍒ゆ柇褰撳墠鐐逛綅鏄惁閲嶅 - Dt_Task taskOldPoint = BaseDal.QueryFirst(x=>x.SourceAddress==startPoint && (x.TaskStatus == TaskStatusEnum.New.ObjToInt()||x.TaskStatus==TaskStatusEnum.Line_Execute.ObjToInt()|| x.TaskStatus == TaskStatusEnum.Line_Executing.ObjToInt() || x.TaskStatus == TaskStatusEnum.AGV_Takeing.ObjToInt())); - if (taskOldPoint != null) - { - return content.Error($"绔欑偣{startPoint}宸插瓨鍦ㄤ换鍔�"); - } - Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == barCode); - if (taskOld != null) - { - return content.Error($"鑳舵{barCode}浠诲姟宸插瓨鍦�"); - } - //鑾峰彇鑳舵浣欐枡 - Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x=>x.PalletCode== barCode).Includes(x=>x.proStockInfoDetails).First(); - if (proStockInfo==null) - { - return content.Error($"鏈壘鍒皗barCode}鑳舵淇℃伅"); - } - if (proStockInfo.proStockInfoDetails==null || proStockInfo.proStockInfoDetails.Count<=0) - { - return content.Error($"{barCode}鑳舵淇℃伅涓虹┖"); - } - if (proStockInfo.StockStatus!=StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt()) - { - return content.Error($"{barCode}鑳舵淇℃伅鐘舵�佸紓甯�"); - } - //鑾峰彇鎴愬搧骞冲簱 - Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString()); - if (proStockInfo.WarehouseId != warehouse.WarehouseId && proStockInfo.LocationCode!= "鎴愬搧鍖呰鎷h揣鍖�") - { - return content.Error($"{barCode}鑳舵淇℃伅涓嶅湪鎷h揣鍖�"); - } - //鑾峰彇褰撳墠鐨勫簱瀛樺睘鎬� - Dt_Warehouse? warePoint = null; - switch (proStockInfo.ProStockAttribute) - { - case (int)ProStockAttributeEnum.鎴愬搧: - warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString()); - break; - case (int)ProStockAttributeEnum.灏炬暟: - warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA72.ToString()); - break; - case (int)ProStockAttributeEnum.鐮斿彂: - warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA73.ToString()); - break; - default: - throw new Exception($"鏈壘鍒皗barCode}鑳舵淇℃伅搴撳瓨灞炴��"); - } - Dt_Warehouse warehouseLocation = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString()); - Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseLocation.WarehouseId); - if (locationInfo == null) - { - return content.Error($"鏈壘鍒皗warehouse.WarehouseCode}璐т綅淇℃伅"); - } - proStockInfo.StockStatus = StockStatusEmun.鎴愬搧浣欐枡鍥炲簱.ObjToInt(); - proStockInfo.proStockInfoDetails.ForEach(x => - { - x.ProOutDetailStatus = StockStatusEmun.鎴愬搧浣欐枡鍥炲簱.ObjToInt(); - }); - Dt_Task newTask = new Dt_Task() - { - CurrentAddress = startPoint, - Grade = 0, - NextAddress = "", - PalletCode = proStockInfo.PalletCode, - Roadway = locationInfo.RoadwayNo, - SourceAddress = startPoint, - TargetAddress = "", - TaskType = TaskTypeEnum.InProductBack.ObjToInt(), - TaskStatus = TaskStatusEnum.New.ObjToInt(), - WarehouseId = warePoint.WarehouseId, - PalletType = proStockInfo.PalletType, - MaterielCode = proStockInfo.proStockInfoDetails.Where(x => x.ProStockId == proStockInfo.Id).FirstOrDefault()?.ProductCode, - Quantity = (float)proStockInfo.proStockInfoDetails.Where(x => x.ProStockId == proStockInfo.Id).Sum(x => x.StockPcsQty) - }; - _unitOfWorkManage.BeginTran(); - int taskId = BaseDal.AddData(newTask); - newTask.TaskId = taskId; - _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo); - _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfo.proStockInfoDetails); - _unitOfWorkManage.CommitTran(); - //鎺ㄩ�佷换鍔� - PushTasksToWCS(new List<Dt_Task> { newTask }); - content.OK("鍙戦�佹垚鍔�"); - } - catch (Exception ex) - { - _unitOfWorkManage.RollbackTran(); - content.Error(ex.Message); - } - return content; - } + //public WebResponseContent BackProductTask(string barCode, string startPoint) + //{ + // WebResponseContent content = new WebResponseContent(); + // try + // { + // string palletCode = @"^C\d{5}$"; // 姝e垯琛ㄨ揪寮� + // bool isValid = Regex.IsMatch(barCode, palletCode); + // if (!isValid) + // { + // return content.Error($"妗嗙爜鏍煎紡閿欒{barCode}"); + // } + // if (!OutStartPonits.Contains(startPoint)) + // { + // return content.Error($"璧风偣閿欒{startPoint}"); + // } + // //鍒ゆ柇褰撳墠鐐逛綅鏄惁閲嶅 + // Dt_Task taskOldPoint = BaseDal.QueryFirst(x=>x.SourceAddress==startPoint && (x.TaskStatus == TaskStatusEnum.New.ObjToInt()||x.TaskStatus==TaskStatusEnum.Line_Execute.ObjToInt()|| x.TaskStatus == TaskStatusEnum.Line_Executing.ObjToInt() || x.TaskStatus == TaskStatusEnum.AGV_Takeing.ObjToInt())); + // if (taskOldPoint != null) + // { + // return content.Error($"绔欑偣{startPoint}宸插瓨鍦ㄤ换鍔�"); + // } + // Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == barCode); + // if (taskOld != null) + // { + // return content.Error($"鑳舵{barCode}浠诲姟宸插瓨鍦�"); + // } + // //鑾峰彇鑳舵浣欐枡 + // Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x=>x.PalletCode== barCode).Includes(x=>x.proStockInfoDetails).First(); + // if (proStockInfo==null) + // { + // return content.Error($"鏈壘鍒皗barCode}鑳舵淇℃伅"); + // } + // if (proStockInfo.proStockInfoDetails==null || proStockInfo.proStockInfoDetails.Count<=0) + // { + // return content.Error($"{barCode}鑳舵淇℃伅涓虹┖"); + // } + // if (proStockInfo.StockStatus!=StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt()) + // { + // return content.Error($"{barCode}鑳舵淇℃伅鐘舵�佸紓甯�"); + // } + // //鑾峰彇鎴愬搧骞冲簱 + // Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString()); + // if (proStockInfo.WarehouseId != warehouse.WarehouseId && proStockInfo.LocationCode!= "鎴愬搧鍖呰鎷h揣鍖�") + // { + // return content.Error($"{barCode}鑳舵淇℃伅涓嶅湪鎷h揣鍖�"); + // } + // //鑾峰彇褰撳墠鐨勫簱瀛樺睘鎬� + // Dt_Warehouse? warePoint = null; + // switch (proStockInfo.ProStockAttribute) + // { + // case (int)ProStockAttributeEnum.鎴愬搧: + // warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString()); + // break; + // case (int)ProStockAttributeEnum.灏炬暟: + // warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA72.ToString()); + // break; + // case (int)ProStockAttributeEnum.鐮斿彂: + // warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA73.ToString()); + // break; + // default: + // throw new Exception($"鏈壘鍒皗barCode}鑳舵淇℃伅搴撳瓨灞炴��"); + // } + // Dt_Warehouse warehouseLocation = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString()); + // Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseLocation.WarehouseId); + // if (locationInfo == null) + // { + // return content.Error($"鏈壘鍒皗warehouse.WarehouseCode}璐т綅淇℃伅"); + // } + // proStockInfo.StockStatus = StockStatusEmun.鎴愬搧浣欐枡鍥炲簱.ObjToInt(); + // proStockInfo.proStockInfoDetails.ForEach(x => + // { + // x.ProOutDetailStatus = StockStatusEmun.鎴愬搧浣欐枡鍥炲簱.ObjToInt(); + // }); + // Dt_Task newTask = new Dt_Task() + // { + // CurrentAddress = startPoint, + // Grade = 0, + // NextAddress = "", + // PalletCode = proStockInfo.PalletCode, + // Roadway = locationInfo.RoadwayNo, + // SourceAddress = startPoint, + // TargetAddress = "", + // TaskType = TaskTypeEnum.InProductBack.ObjToInt(), + // TaskStatus = TaskStatusEnum.New.ObjToInt(), + // WarehouseId = warePoint.WarehouseId, + // PalletType = proStockInfo.PalletType, + // MaterielCode = proStockInfo.proStockInfoDetails.Where(x => x.ProStockId == proStockInfo.Id).FirstOrDefault()?.ProductCode, + // Quantity = (float)proStockInfo.proStockInfoDetails.Where(x => x.ProStockId == proStockInfo.Id).Sum(x => x.StockPcsQty) + // }; + // _unitOfWorkManage.BeginTran(); + // int taskId = BaseDal.AddData(newTask); + // newTask.TaskId = taskId; + // _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo); + // _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfo.proStockInfoDetails); + // _unitOfWorkManage.CommitTran(); + // //鎺ㄩ�佷换鍔� + // PushTasksToWCS(new List<Dt_Task> { newTask }); + // content.OK("鍙戦�佹垚鍔�"); + // } + // catch (Exception ex) + // { + // _unitOfWorkManage.RollbackTran(); + // content.Error(ex.Message); + // } + // return content; + //} /// <summary> /// 绌烘鍥炲簱 /// </summary> -- Gitblit v1.9.3